@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
package/src/outbound.mjs CHANGED
@@ -14,10 +14,10 @@
14
14
  // there, what puts it on and where you turn it off. It is written by hand because it says what a
15
15
  // request MEANS, and no wrapper can know that.
16
16
  //
17
- // The log is the check on the declaration. Every fetch the room's process makes goes through one
18
- // wrapper — MADRE's own calls and any a module makes, because a module installed tomorrow runs
19
- // inside this process and cannot opt out of it — and lands in a line saying where it went and
20
- // when. An address nobody declared shows up as one nobody declared, which is the whole point.
17
+ // The log is the check on the declaration. The room wraps its fetch calls; an installed module's
18
+ // separate process reports its fetch calls through the restricted bridge, and its one-file MCP
19
+ // server installs the same wrapper. Calls made through other protocols or an agent CLI do not
20
+ // pass through this wrapper. An address nobody declared shows up as one nobody declared.
21
21
  //
22
22
  // What is never recorded: bodies, headers, and the values of query parameters. The names stay.
23
23
  // The Gemini embedding endpoint takes the key in the URL, and a log of what left this machine
@@ -26,6 +26,7 @@
26
26
  import { appendFile, mkdir, open, stat, writeFile } from 'node:fs/promises';
27
27
  import { t } from './i18n.mjs';
28
28
  import { dirname } from 'node:path';
29
+ import { askedByPerson } from './web-preview.mjs';
29
30
 
30
31
  export const KEEP = 200; // lines held for the screen
31
32
  export const MAX_BYTES = 512 * 1024; // the file is trimmed to the last KEEP lines past this
@@ -65,6 +66,15 @@ export const DESTINATIONS = [
65
66
  where: 'Settings › Agents › Gemini · without a key it is never asked',
66
67
  inside: true,
67
68
  },
69
+ {
70
+ // Gemini without its CLI (adapters/gemini-rest.mjs): MADRE's own process carries the turn, so it
71
+ // is declared here and not left to `crew`. The key travels in a header, never in the address.
72
+ id: 'gemini-answer', host: 'generativelanguage.googleapis.com', match: (url) => /:streamGenerateContent$/.test(url.pathname), to: 'Google · Gemini, through its API',
73
+ what: 'The briefing — the document above, your question, the memories it summoned and the transcript it carries — with your Gemini API key, to be answered by the model you chose.',
74
+ when: 'every turn you send to @gemini while Gemini answers through its API (a Gemini key and no Gemini CLI)',
75
+ where: 'you choose it every time you send a turn to @gemini; installing the Gemini CLI hands its turns back to the CLI',
76
+ inside: true,
77
+ },
68
78
  {
69
79
  id: 'image', host: 'generativelanguage.googleapis.com', match: (url) => /generateContent/.test(url.pathname), to: 'Google · Gemini image model',
70
80
  what: 'The prompt an agent wrote for an image.',
@@ -73,19 +83,50 @@ export const DESTINATIONS = [
73
83
  // It runs in a process of its own and writes its own line into this same log, so it is here.
74
84
  inside: true,
75
85
  },
86
+ {
87
+ // The other two providers Images draws with (2026-11-14, src/modules/image-providers.mjs). Same
88
+ // process of its own as Google's, same line in this log; the key travels in a header.
89
+ id: 'image-openai', host: 'api.openai.com', match: (url) => url.pathname.startsWith('/v1/images/'), to: 'OpenAI · GPT Image model',
90
+ what: 'The prompt an AI wrote for an image, with your OpenAI API key, to be drawn by the model you chose.',
91
+ when: 'an AI uses the image tool during a permission to create, while Images draws with OpenAI',
92
+ where: 'Modules › Images · choose another provider, or forget the key there',
93
+ inside: true,
94
+ },
95
+ {
96
+ id: 'image-xai', host: 'api.x.ai', match: (url) => url.pathname.startsWith('/v1/images/'), to: 'xAI · Grok Imagine image model',
97
+ what: 'The prompt an AI wrote for an image, with your xAI API key, to be drawn by the model you chose.',
98
+ when: 'an AI uses the image tool during a permission to create, while Images draws with Grok',
99
+ where: 'Modules › Images · choose another provider, or forget the key there',
100
+ inside: true,
101
+ },
102
+ {
103
+ // Whether the provider takes a key pasted in Modules › Images: listing the models spends nothing.
104
+ id: 'image-key', host: 'api.openai.com', match: (url) => /^\/v1\/models\/?$/.test(url.pathname), to: 'OpenAI · whether it takes your key',
105
+ what: 'The OpenAI API key you paste in Modules › Images, so OpenAI says whether it takes it. It lists models and spends no credit. Nothing about you or your project.',
106
+ when: 'once, when you save an OpenAI key in Modules › Images',
107
+ where: 'Modules › Images · without a pasted key it is never asked',
108
+ inside: true,
109
+ },
110
+ {
111
+ id: 'image-key-xai', host: 'api.x.ai', match: (url) => /^\/v1\/models\/?$/.test(url.pathname), to: 'xAI · whether it takes your key',
112
+ what: 'The xAI API key you paste in Modules › Images, so xAI says whether it takes it. It lists models and spends no credit. Nothing about you or your project.',
113
+ when: 'once, when you save an xAI key in Modules › Images',
114
+ where: 'Modules › Images · without a pasted key it is never asked',
115
+ inside: true,
116
+ },
76
117
  {
77
118
  id: 'npm', host: 'registry.npmjs.org', to: 'the npm registry',
78
119
  what: 'The name of a package, to read the version of its latest release. Nothing about you or your project.',
79
- when: 'at most once a day per package, while Look for new versions is on',
80
- where: 'Settings › Version and reports › Look for new versions · or PULSE_UPDATE_CHECK=0',
120
+ when: 'at most once a day per package, to tell you a new version is out',
121
+ where: 'Settings › Updates and errors',
81
122
  inside: true,
82
123
  },
83
124
  {
84
125
  // Only the release read: the rest of api.github.com is the GitHub module's, and says so itself.
85
126
  id: 'github', host: 'api.github.com', match: (url) => /\/releases\/latest$/.test(url.pathname), to: 'GitHub',
86
127
  what: 'The name of a repository, to read the tag of its latest release. Nothing about you or your project.',
87
- when: 'at most once a day per repository, while Look for new versions is on',
88
- where: 'Settings › Version and reports › Look for new versions · or PULSE_UPDATE_CHECK=0',
128
+ when: 'at most once a day per repository, to tell you a new version is out',
129
+ where: 'Settings › Updates and errors',
89
130
  inside: true,
90
131
  },
91
132
  {
@@ -96,6 +137,25 @@ export const DESTINATIONS = [
96
137
  where: 'Always on: it is how the author knows how many people use MADRE',
97
138
  inside: true,
98
139
  },
140
+ {
141
+ // The author's notices (Q-11, src/notices.mjs): asked of madre.run with nothing about the person.
142
+ // Whatever the diagnostics say. In the author's own copy, the same address takes the notices the
143
+ // author writes, already signed on this computer.
144
+ id: 'notices', host: 'madre.run', match: (url) => url.pathname === '/api/avisos', to: 'madre.run · notices from MADRE\'s author',
145
+ what: 'Nothing about you: it asks for the notices MADRE\'s author wrote for every copy, not even with this copy\'s version. Each one is checked against the author\'s signature before it shows.',
146
+ when: 'when MADRE opens, and at most every 15 minutes while it is open',
147
+ where: 'Always, so every copy hears of a new version or a fix · PULSE_NOTICES=0 for development',
148
+ inside: true,
149
+ },
150
+ {
151
+ // MADRE App's subscription (src/billing.mjs, 2026-11-17): only inside the app, and only once the
152
+ // author turns it on. In the author's own copy, the same address takes the switch, signed here.
153
+ id: 'subscription', host: 'madre.run', match: (url) => url.pathname === '/api/cobro' || url.pathname.startsWith('/api/suscripcion/'), to: 'madre.run · MADRE App subscription',
154
+ what: 'Whether the author turned the subscription on, with nothing about you; once you subscribe, your subscription key, to keep it current. Never what you write or your projects.',
155
+ when: 'inside the app: when MADRE opens, every half hour, and every 12 hours once you subscribe',
156
+ where: 'Only in MADRE App; MADRE from npm or from source never asks',
157
+ inside: true,
158
+ },
99
159
  {
100
160
  // Anonymous diagnostics (src/telemetry.mjs, 2026-10-28): on unless turned off.
101
161
  id: 'diagnostics', host: 'madre.run', match: (url) => url.pathname === '/api/telemetry', to: 'madre.run · anonymous diagnostics',
@@ -104,12 +164,21 @@ export const DESTINATIONS = [
104
164
  where: 'Settings › Version and reports › Send anonymous diagnostics · or PULSE_TELEMETRY=0',
105
165
  inside: true,
106
166
  },
167
+ {
168
+ // On right now (src/install-metrics.mjs): part of the diagnostics and off with them. Without its
169
+ // own line it fell to the collector, and the log said it went to the error reports.
170
+ id: 'presence', host: 'madre.run', match: (url) => url.pathname === '/api/presence', to: 'madre.run · on right now',
171
+ what: 'This copy\'s random identifier, the MADRE version and the system, so the author knows how many copies are open now. Nothing from your projects.',
172
+ when: 'every five minutes while MADRE is open',
173
+ where: 'Off with the anonymous diagnostics: Settings › Version and reports › Send anonymous diagnostics · or PULSE_TELEMETRY=0',
174
+ inside: true,
175
+ },
107
176
  {
108
177
  // The Market (src/market-remote.mjs): a signed catalog, and the file of a module you get from it.
109
178
  id: 'market', host: 'madre.run', match: (url) => url.pathname.startsWith('/mercado/'), to: "madre.run · the Market",
110
179
  what: 'Nothing about you: it asks for the catalog of modules, and for the file of a module you got or that has a newer version. Every file is checked against the author\'s signature before it is used.',
111
180
  when: 'when MADRE opens, at most every ten minutes, and when you get a module',
112
- where: 'Settings › Version and reports › Look for new versions · or PULSE_MARKET=0',
181
+ where: 'Settings › Updates and errors · or PULSE_MARKET=0',
113
182
  inside: true,
114
183
  },
115
184
  {
@@ -142,6 +211,15 @@ export const DESTINATIONS = [
142
211
  where: 'Settings › Version and reports › Report automatically · or PULSE_REPORT_URL',
143
212
  inside: true,
144
213
  },
214
+ {
215
+ // Whether Anthropic takes the Claude key a person pastes (credentials.mjs, MR-R92AWX): Claude's
216
+ // own status says «logged in» for any key it finds, even a made-up one.
217
+ id: 'anthropic-key', host: 'api.anthropic.com', match: (url) => /^\/v1\/models\/?$/.test(url.pathname), to: 'Anthropic · whether it takes your Claude key',
218
+ what: 'The API key you paste for Claude, so Anthropic says whether it takes it. It lists models and spends no credit. Nothing about you or your project.',
219
+ when: 'once, when you save a Claude API key in Settings › Agents',
220
+ where: 'Settings › Agents › Claude · without a pasted key it is never asked',
221
+ inside: true,
222
+ },
145
223
  {
146
224
  id: 'anthropic', host: 'api.anthropic.com', to: 'Anthropic',
147
225
  what: 'Your Claude Code token, to read how much of your plan is left. It is read from where Claude keeps it and never stored by MADRE.',
@@ -149,6 +227,38 @@ export const DESTINATIONS = [
149
227
  where: 'Settings › Agents › Claude',
150
228
  inside: true,
151
229
  },
230
+ {
231
+ // Gemini CLI's quota (src/quota-sources.mjs, 2026-11-10): only signed in with Google.
232
+ id: 'gemini-quota', host: 'cloudcode-pa.googleapis.com', to: 'Google · how much of your Gemini plan is left',
233
+ what: 'The token Gemini CLI keeps when you sign in with Google, to read how much of each model your account has left. Read from where Gemini keeps it, while it is fresh; never stored nor renewed by MADRE.',
234
+ when: 'every minute while MADRE is open, only when Gemini signs in with Google (never with an API key)',
235
+ where: 'Settings › Agents › Gemini · or PULSE_GEMINI_QUOTA=0',
236
+ inside: true,
237
+ },
238
+ {
239
+ // OpenCode's quota by provider (src/quota-sources.mjs, 2026-11-10).
240
+ id: 'copilot-quota', host: 'api.github.com', match: (url) => url.pathname === '/copilot_internal/user', to: 'GitHub · how many Copilot requests are left',
241
+ what: 'The GitHub token OpenCode keeps when you sign in to Copilot with it, to read how many premium requests are left this month. Read from OpenCode\'s own file; never stored by MADRE.',
242
+ when: 'every minute while MADRE is open, only when OpenCode is signed in to GitHub Copilot',
243
+ where: 'Settings › Agents › OpenCode · or PULSE_OPENCODE_QUOTA=0',
244
+ inside: true,
245
+ },
246
+ {
247
+ id: 'openrouter-quota', host: 'openrouter.ai', match: (url) => /^\/api\/v1\/(key|credits)$/.test(url.pathname), to: 'OpenRouter · how much of your credit is spent',
248
+ what: 'The OpenRouter key OpenCode keeps, to read how much of its limit or of your credits is spent. Read from OpenCode\'s own file; never stored by MADRE.',
249
+ when: 'every minute while MADRE is open, only when OpenCode has an OpenRouter key',
250
+ where: 'Settings › Agents › OpenCode · or PULSE_OPENCODE_QUOTA=0',
251
+ inside: true,
252
+ },
253
+ {
254
+ // The cards of an answer's links (web-preview.mjs, 2026-11-14): any site, so no host here; the
255
+ // addresses come from the person's press, and classify() knows them by that.
256
+ id: 'web-page', host: null, to: 'the sites of the links in an answer',
257
+ what: 'A request for the page of each link an agent gave, and for its photo, to show them as cards. Only the address of that page; nothing about you, your project or the conversation.',
258
+ when: 'only when you press «Show photos» under an answer with links',
259
+ where: 'never without that press · the links still open in your browser without it',
260
+ inside: true,
261
+ },
152
262
  {
153
263
  id: 'ollama', host: null, local: true, to: 'Ollama, on this computer',
154
264
  what: 'Memories to embed, exchanges to distil, and whatever you ask @madre. It goes to a port on this machine and stops there.',
@@ -208,6 +318,7 @@ export function classify(rawUrl, { reportHost = null } = {}) {
208
318
  // and a module's are both honest; they are not the same promise.
209
319
  return { id: one.id, to: one.to, local: false, ...(one.module ? { module: one.module } : {}) };
210
320
  }
321
+ if (askedByPerson(url.href)) return { id: 'web-page', to: host, local: false };
211
322
  return { id: 'unknown', to: host, local: false };
212
323
  }
213
324
 
@@ -344,7 +455,7 @@ export class OutboundLog {
344
455
  return watched;
345
456
  }
346
457
 
347
- // Everything in this process, including whatever a module calls. Returns the undo.
458
+ // Fetch in this process. An external module is logged through its own bridge. Returns the undo.
348
459
  install(target = globalThis) {
349
460
  if (this.#restore) return this.#restore;
350
461
  const original = target.fetch;
@@ -371,7 +482,7 @@ export class OutboundLog {
371
482
  export function outboundView({ log = null, state = {}, agents = [] } = {}) {
372
483
  const counts = log?.counts() ?? {};
373
484
  // Said in the room's language (2026-10-12): the list read in English inside a Spanish room.
374
- const vendors = { codex: 'OpenAI', claude: 'Anthropic', gemini: 'Google', opencode: t('the provider OpenCode is signed in to'), cursor: 'Cursor' };
485
+ const vendors = { codex: 'OpenAI', claude: 'Anthropic', gemini: 'Google', opencode: t('the provider OpenCode is signed in to'), cursor: 'Cursor', grok: 'xAI' };
375
486
  const crew = agents.filter((agent) => agent.detected && !agent.local).map((agent) => `@${agent.id} → ${agent.route?.destination ?? vendors[agent.id] ?? t('its own provider')}`);
376
487
  const destinations = DESTINATIONS.map((one) => ({
377
488
  id: one.id,
@@ -380,8 +491,8 @@ export function outboundView({ log = null, state = {}, agents = [] } = {}) {
380
491
  when: t(one.when),
381
492
  where: t(one.where),
382
493
  local: Boolean(one.local),
383
- // Whether the call lands in the log at all. Everything MADRE starts does, the image studio
384
- // from its own process included; the crew's own conversation with its provider does not.
494
+ // Whether MADRE's fetch call lands in the log. The image studio and one-file module servers
495
+ // install their own wrapper; other protocols and agent CLI traffic do not pass through it.
385
496
  inside: Boolean(one.inside),
386
497
  on: state[one.id] ?? null,
387
498
  calls: counts[one.id]?.calls ?? 0,
@@ -19,8 +19,19 @@ const execFileAsync = promisify(execFile);
19
19
  // already keeps in the keychain (macOS) or ~/.claude/.credentials.json.
20
20
  // Read-only; the token never leaves this machine except toward
21
21
  // api.anthropic.com, which is where the CLI sends it anyway.
22
- // gemini, opencode Nothing published locally: the room's own rolling
23
- // window stands in.
22
+ // gemini Signed in with a Google account (2026-11-10), Gemini CLI asks Code
23
+ // Assist for the account's quota (v1internal:retrieveUserQuota, one
24
+ // bucket per model with the fraction left and when it resets). MADRE
25
+ // asks the same, with the token the CLI keeps in ~/.gemini, only while
26
+ // that token is fresh: it never refreshes nor writes it. With an API
27
+ // key Google publishes nothing: the room's window stands in.
28
+ // opencode By its provider (2026-11-10), from OpenCode's own auth.json: a GitHub Copilot sign-in
29
+ // asks GitHub how many premium requests are left this month (the same endpoint the
30
+ // editors use, copilot_internal/user); an OpenRouter key asks OpenRouter how much of its
31
+ // limit or of the account's credits is spent (/api/v1/key, /api/v1/credits). Only the
32
+ // provider of the model OpenCode is answering with counts (2026-11-11: a Copilot sign-in
33
+ // out of premium requests marked OpenCode as spent while it answered with an OpenAI key).
34
+ // Others publish nothing: the room's window.
24
35
  //
25
36
  // A window whose resets_at is already in the past is reported as fresh
26
37
  // (0 % used, stale: true): the CLI only rewrites the file when it runs again,
@@ -143,12 +154,146 @@ export const claudeUsageSource = (options = {}) => ({
143
154
  read: () => readClaudeUsage(options),
144
155
  });
145
156
 
157
+ // Gemini CLI's own Google sign-in, as it keeps it: the token only while it is fresh, and only when
158
+ // the CLI is set to sign in with Google (an API key has no quota to ask about).
159
+ export async function readGeminiOauth({ home = homedir(), now = Date.now(), env = process.env } = {}) {
160
+ const dir = join(home, '.gemini');
161
+ let settings = {};
162
+ try { settings = JSON.parse(await readFile(join(dir, 'settings.json'), 'utf8')); } catch { settings = {}; }
163
+ const kind = settings.security?.auth?.selectedType ?? settings.selectedAuthType ?? settings.selectedType ?? null;
164
+ if (kind && kind !== 'oauth-personal') return null;
165
+ let creds = null;
166
+ try { creds = JSON.parse(await readFile(join(dir, 'oauth_creds.json'), 'utf8')); } catch { return null; }
167
+ const expires = Number(creds?.expiry_date);
168
+ if (!creds?.access_token || !Number.isFinite(expires) || expires - now < 60_000) return null;
169
+ return { token: creds.access_token, project: env.GOOGLE_CLOUD_PROJECT || env.GOOGLE_CLOUD_PROJECT_ID || null };
170
+ }
171
+
172
+ const CODE_ASSIST = 'https://cloudcode-pa.googleapis.com/v1internal';
173
+ let geminiProject = null;
174
+ export async function readGeminiQuota({ fetchImpl = fetch, oauthReader = readGeminiOauth, now = Date.now() } = {}) {
175
+ const auth = await oauthReader({ now });
176
+ if (!auth) return null;
177
+ const post = async (method, body) => {
178
+ const response = await fetchImpl(`${CODE_ASSIST}:${method}`, { method: 'POST', headers: { authorization: `Bearer ${auth.token}`, 'content-type': 'application/json', accept: 'application/json' }, body: JSON.stringify(body) });
179
+ if (response.status === 401 || response.status === 403) throw new Error(`Google rejected Gemini CLI's sign-in (HTTP ${response.status}); sign in again with gemini.`);
180
+ if (!response.ok) throw new Error(`Gemini's quota endpoint answered HTTP ${response.status}.`);
181
+ return response.json();
182
+ };
183
+ // The account's Code Assist project, as the CLI finds it; asked once.
184
+ let project = auth.project ?? geminiProject;
185
+ if (!project) {
186
+ const loaded = await post('loadCodeAssist', { metadata: { ideType: 'IDE_UNSPECIFIED', platform: 'PLATFORM_UNSPECIFIED', pluginType: 'GEMINI' } });
187
+ project = loaded?.cloudaicompanionProject?.id ?? loaded?.cloudaicompanionProject ?? null;
188
+ if (typeof project !== 'string' || !project) return null;
189
+ geminiProject = project;
190
+ }
191
+ const quota = await post('retrieveUserQuota', { project });
192
+ // The tightest of its models: the one that runs out first is the one that stops a turn.
193
+ const buckets = (quota?.buckets ?? []).filter((one) => one?.modelId && Number.isFinite(Number(one.remainingFraction)));
194
+ if (!buckets.length) return null;
195
+ const tightest = buckets.reduce((low, one) => (Number(one.remainingFraction) < Number(low.remainingFraction) ? one : low));
196
+ const primary = interpretWindow({ usedPercent: (1 - Number(tightest.remainingFraction)) * 100, resetAt: tightest.resetTime ?? null, windowMinutes: 1440 }, now);
197
+ return {
198
+ agent: 'gemini',
199
+ usedPercent: primary.usedPercent,
200
+ resetAt: primary.resetAt,
201
+ stale: primary.stale,
202
+ windows: { primary, secondary: null },
203
+ model: tightest.modelId,
204
+ observedAt: new Date(now).toISOString(),
205
+ };
206
+ }
207
+
208
+ export const geminiQuotaSource = (options = {}) => ({
209
+ id: 'gemini-quota',
210
+ agent: 'gemini',
211
+ read: () => readGeminiQuota(options),
212
+ });
213
+
214
+ // OpenCode's providers as its auth.json keeps them (src/credentials.mjs writes the same file).
215
+ export async function readOpenCodeAuth({ home = homedir(), env = process.env } = {}) {
216
+ const file = join(env.XDG_DATA_HOME || join(home, '.local', 'share'), 'opencode', 'auth.json');
217
+ try {
218
+ const auth = JSON.parse(await readFile(file, 'utf8'));
219
+ return auth && typeof auth === 'object' && !Array.isArray(auth) ? auth : {};
220
+ } catch { return {}; }
221
+ }
222
+
223
+ // GitHub Copilot: the premium requests of the month, with the GitHub token OpenCode signed in with.
224
+ export async function readCopilotQuota(entry, { fetchImpl = fetch, now = Date.now() } = {}) {
225
+ const token = entry?.type === 'oauth' ? entry.refresh : null;
226
+ if (typeof token !== 'string' || !token) return null;
227
+ const response = await fetchImpl('https://api.github.com/copilot_internal/user', { headers: { authorization: `token ${token}`, accept: 'application/json', 'x-github-api-version': '2025-04-01' } });
228
+ if (response.status === 401 || response.status === 403) throw new Error(`GitHub rejected OpenCode's Copilot sign-in (HTTP ${response.status}); sign in again with opencode auth login.`);
229
+ if (!response.ok) throw new Error(`GitHub's Copilot endpoint answered HTTP ${response.status}.`);
230
+ const body = await response.json();
231
+ const premium = body?.quota_snapshots?.premium_interactions;
232
+ if (!premium || premium.unlimited || !Number.isFinite(Number(premium.percent_remaining))) return null;
233
+ const resetAt = body.quota_reset_date ? new Date(body.quota_reset_date).toISOString() : null;
234
+ return { provider: 'github-copilot', ...interpretWindow({ usedPercent: 100 - Number(premium.percent_remaining), resetAt, windowMinutes: null }, now) };
235
+ }
236
+
237
+ // OpenRouter: the key's own limit when it has one, the account's credits when it does not.
238
+ export async function readOpenRouterQuota(entry, { fetchImpl = fetch, now = Date.now() } = {}) {
239
+ const key = entry?.type === 'api' ? entry.key : null;
240
+ if (typeof key !== 'string' || !key) return null;
241
+ const ask = async (path) => {
242
+ const response = await fetchImpl(`https://openrouter.ai/api/v1/${path}`, { headers: { authorization: `Bearer ${key}`, accept: 'application/json' } });
243
+ if (response.status === 401 || response.status === 403) throw new Error(`OpenRouter rejected the key OpenCode has for it (HTTP ${response.status}).`);
244
+ if (!response.ok) throw new Error(`OpenRouter answered HTTP ${response.status}.`);
245
+ return (await response.json())?.data ?? null;
246
+ };
247
+ const own = await ask('key');
248
+ if (Number(own?.limit) > 0) return { provider: 'openrouter', ...interpretWindow({ usedPercent: (Number(own.usage ?? 0) / Number(own.limit)) * 100, resetAt: null, windowMinutes: null }, now) };
249
+ const credits = await ask('credits');
250
+ if (!(Number(credits?.total_credits) > 0)) return null;
251
+ return { provider: 'openrouter', ...interpretWindow({ usedPercent: (Number(credits.total_usage ?? 0) / Number(credits.total_credits)) * 100, resetAt: null, windowMinutes: null }, now) };
252
+ }
253
+
254
+ // The model OpenCode answered with last (room.mjs notes it on every OpenCode turn), or the one chosen
255
+ // for every project in Settings.
256
+ let openCodeModel = null;
257
+ export function noteOpenCodeModel(model) { if (typeof model === 'string' && model.includes('/')) openCodeModel = model; }
258
+ const OPENCODE_READERS = { 'github-copilot': readCopilotQuota, openrouter: readOpenRouterQuota };
259
+
260
+ export async function readOpenCodeQuota({ authReader = readOpenCodeAuth, fetchImpl = fetch, now = Date.now(), model = openCodeModel ?? process.env.PULSE_OPENCODE_MODEL ?? null } = {}) {
261
+ const auth = await authReader();
262
+ const measurable = Object.keys(OPENCODE_READERS).filter((provider) => auth[provider]);
263
+ if (!measurable.length) return null;
264
+ const provider = String(model ?? '').split('/')[0];
265
+ const tightest = measurable.includes(provider) ? await OPENCODE_READERS[provider](auth[provider], { fetchImpl, now }).catch(() => null) : null;
266
+ // Answering through a provider that publishes nothing: what another one has left is not
267
+ // OpenCode's. Said as an empty, unmeasured window, so a reading kept from before stops warning.
268
+ if (!tightest) return measurable.includes(provider) ? null : { agent: 'opencode', usedPercent: 0, resetAt: null, stale: true, provider: null, windows: null, observedAt: new Date(now).toISOString() };
269
+ return {
270
+ agent: 'opencode',
271
+ usedPercent: tightest.usedPercent,
272
+ resetAt: tightest.resetAt,
273
+ stale: tightest.stale,
274
+ provider: tightest.provider,
275
+ windows: { primary: tightest, secondary: null },
276
+ observedAt: new Date(now).toISOString(),
277
+ };
278
+ }
279
+
280
+ export const openCodeQuotaSource = (options = {}) => ({
281
+ id: 'opencode-quota',
282
+ agent: 'opencode',
283
+ read: () => readOpenCodeQuota(options),
284
+ });
285
+
146
286
  // Codex is on by default: a local file read. Claude's usage endpoint needs
147
287
  // the CLI's OAuth token from the keychain, which macOS may ask about, so it is
148
- // opt-in: PULSE_CLAUDE_USAGE=1. PULSE_OFFICIAL_QUOTA=0 turns everything off.
288
+ // opt-in: PULSE_CLAUDE_USAGE=1. Gemini's is a file read and a question to Google with the CLI's own
289
+ // fresh token, and OpenCode's a question to GitHub or OpenRouter with what OpenCode signed in with,
290
+ // so they are on (PULSE_GEMINI_QUOTA=0, PULSE_OPENCODE_QUOTA=0 turn them off). PULSE_OFFICIAL_QUOTA=0 turns
291
+ // everything off.
149
292
  export function defaultQuotaSources({ env = process.env } = {}) {
150
293
  if (env.PULSE_OFFICIAL_QUOTA === '0') return [];
151
294
  const sources = [codexRolloutSource()];
295
+ if (env.PULSE_GEMINI_QUOTA !== '0') sources.push(geminiQuotaSource());
296
+ if (env.PULSE_OPENCODE_QUOTA !== '0') sources.push(openCodeQuotaSource());
152
297
  if (env.PULSE_CLAUDE_USAGE === '1') sources.push(claudeUsageSource());
153
298
  return sources;
154
299
  }
@@ -2,17 +2,22 @@
2
2
  // MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
3
3
  // Asking for a star or a review (2026-10-10): three times at most, and never again once answered.
4
4
  //
5
- // After twenty minutes of MADRE in use, and on the second and the seventh day after it was first
6
- // used, the room asks once whether MADRE is being liked: a star on GitHub, or a review on
7
- // madre.run. Whoever answers — a star, a review, or «don't ask again» — is never asked again; «not
8
- // now» only lets that moment pass. A later moment that comes first takes the earlier ones with it,
9
- // so nobody is asked twice in a row, and never twice within a day.
5
+ // After thirty minutes with an AI at work (2026-11-18, the author: «después de unos 30 minutos de
6
+ // que el usuario está usando madre y está usando alguna de sus IAs»), and on the second and the
7
+ // seventh day after it was first used — once those thirty minutes are there too — the room asks
8
+ // once whether MADRE is being liked. Where it sends the person depends on how MADRE came: the
9
+ // desktop app (MADRE_APP=1) to a review on madre.run, a copy from npm or from the source to a star
10
+ // on GitHub, since npm keeps no reviews. Whoever answers — a star, a review, a donation or «don't
11
+ // ask again» — is never asked again; «not now» only lets that moment pass. A later moment that
12
+ // comes first takes the earlier ones with it, so nobody is asked twice in a row, and never twice
13
+ // within a day.
10
14
  //
11
- // Use is counted by the pages themselves: while one is in view it says so once a minute, and the
12
- // minutes are added here, one per minute however many pages are open. What is kept lives in
13
- // ~/.pulse/review-ask.json, not in a browser: each room is its own origin, and the same person on
14
- // another port has been asked already. Nothing here touches the network; the two links are opened
15
- // by the person, in their browser.
15
+ // Use is counted by the pages themselves: while one is in view it says so once a minute, and says
16
+ // whether an AI is at work in it — a turn running, or one that ended a moment ago. Only those
17
+ // minutes count, one per minute however many pages are open; a window left open with nothing going
18
+ // on counts nothing. What is kept lives in ~/.pulse/review-ask.json, not in a browser: each room is
19
+ // its own origin, and the same person on another port has been asked already. Nothing here touches
20
+ // the network; the links are opened by the person, in their browser.
16
21
 
17
22
  import { readFile } from 'node:fs/promises';
18
23
  import { join } from 'node:path';
@@ -20,19 +25,30 @@ import { oneAtATime, writeWhole } from './json-file.mjs';
20
25
 
21
26
  const FILE = 'review-ask.json';
22
27
  const DAY = 24 * 60 * 60 * 1000;
28
+ // Minutes with an AI at work before anything is asked, the days included.
29
+ export const ASK_AFTER_MINUTES = 30;
30
+ const used = (state) => state.aiMinutes >= ASK_AFTER_MINUTES;
23
31
  export const ASK_MOMENTS = [
24
- { id: 'm20', reached: (state) => state.minutes >= 20 },
25
- { id: 'd2', reached: (state, now) => now - Date.parse(state.first) >= 2 * DAY },
26
- { id: 'd7', reached: (state, now) => now - Date.parse(state.first) >= 7 * DAY },
32
+ { id: 'm30', reached: (state) => used(state) },
33
+ { id: 'd2', reached: (state, now) => used(state) && now - Date.parse(state.first) >= 2 * DAY },
34
+ { id: 'd7', reached: (state, now) => used(state) && now - Date.parse(state.first) >= 7 * DAY },
27
35
  ];
36
+ // The first moment was twenty minutes with a page in view until 2026-11-18: whoever was asked
37
+ // then, or answers from a page opened before, was asked at the first moment.
38
+ const MOMENT_BEFORE = { m20: 'm30' };
39
+ const momentNow = (id) => MOMENT_BEFORE[id] ?? id;
40
+ // Where the question sends the person: the desktop app to a review, npm or the source to a star.
41
+ export const askVia = (env = process.env) => (env.MADRE_APP === '1' ? 'app' : 'npm');
28
42
  // A donation on GitHub Sponsors is an answer too (2026-10-30): whoever gave is not asked again.
29
43
  export const ASK_ANSWERS = ['later', 'star', 'review', 'donate', 'never'];
30
- // One minute of use is counted at most once a minute, whichever page says it.
44
+ // One minute with an AI at work is counted at most once a minute, whichever page says it.
31
45
  const TICK_MS = 55 * 1000;
32
46
  // Never asked twice within this long, whatever moments have come.
33
47
  const QUIET_MS = 20 * 60 * 60 * 1000;
34
48
 
35
- const fresh = () => ({ first: null, minutes: 0, lastTick: null, shown: {}, answer: null, offered: null });
49
+ // `aiMinutes` and `lastUse` count only the minutes with an AI at work (2026-11-18); the `minutes`
50
+ // a file from before kept counted any page in view, and are left behind.
51
+ const fresh = () => ({ first: null, aiMinutes: 0, lastUse: null, shown: {}, answer: null, offered: null });
36
52
  // A moment handed to one page is not handed to another for this long (WEB-12 of the 1.0 review):
37
53
  // every page in view ticks — Home, each project, each half of a split view — and each one asked.
38
54
  const OFFER_HOLD_MS = 10 * 60 * 1000;
@@ -42,9 +58,14 @@ export async function readAsk(root) {
42
58
  const raw = JSON.parse(await readFile(join(root, FILE), 'utf8'));
43
59
  const state = fresh();
44
60
  if (typeof raw?.first === 'string' && Number.isFinite(Date.parse(raw.first))) state.first = raw.first;
45
- if (Number.isFinite(raw?.minutes) && raw.minutes >= 0) state.minutes = Math.floor(raw.minutes);
46
- if (typeof raw?.lastTick === 'string' && Number.isFinite(Date.parse(raw.lastTick))) state.lastTick = raw.lastTick;
47
- if (raw?.shown && typeof raw.shown === 'object') for (const { id } of ASK_MOMENTS) if (typeof raw.shown[id] === 'string') state.shown[id] = raw.shown[id];
61
+ if (Number.isFinite(raw?.aiMinutes) && raw.aiMinutes >= 0) state.aiMinutes = Math.floor(raw.aiMinutes);
62
+ if (typeof raw?.lastUse === 'string' && Number.isFinite(Date.parse(raw.lastUse))) state.lastUse = raw.lastUse;
63
+ if (raw?.shown && typeof raw.shown === 'object') {
64
+ for (const [id, at] of Object.entries(raw.shown)) {
65
+ const moment = momentNow(id);
66
+ if (typeof at === 'string' && ASK_MOMENTS.some((one) => one.id === moment)) state.shown[moment] = at;
67
+ }
68
+ }
48
69
  if (ASK_ANSWERS.includes(raw?.answer) && raw.answer !== 'later') state.answer = raw.answer;
49
70
  if (typeof raw?.offered?.moment === 'string' && Number.isFinite(Date.parse(raw.offered.at))) state.offered = { moment: raw.offered.moment, at: raw.offered.at };
50
71
  return state;
@@ -67,31 +88,33 @@ export function dueMoment(state, now = Date.now()) {
67
88
  return reached.at(-1)?.id ?? null;
68
89
  }
69
90
 
70
- // A page in view says so: the first time starts the count, then a minute is added at most once a
71
- // minute. Answers which moment is due, if any.
91
+ // A page in view says so: the first time starts the days; a minute is added, at most once a minute,
92
+ // only when the page says an AI is at work in it (`using`). Answers which moment is due, if any.
72
93
  // `quietSince`: a moment that asks for quiet — the day of the bonjour (src/tour.mjs) — keeps every
73
94
  // ask away for QUIET_MS after it, as an ask itself would. The minutes still count.
74
95
  // One change at a time (src/json-file.mjs): every page in view ticks, from every project.
75
96
  export function tickAsk(root, now = Date.now(), options = {}) {
76
97
  return oneAtATime(join(root, FILE), () => tick(root, now, options));
77
98
  }
78
- async function tick(root, now, { quietSince = null } = {}) {
99
+ async function tick(root, now, { quietSince = null, using = false } = {}) {
79
100
  const state = await readAsk(root);
80
101
  const at = new Date(now).toISOString();
81
- if (!state.first) state.first = at;
82
- const last = state.lastTick ? Date.parse(state.lastTick) : 0;
83
- if (!last || now - last >= TICK_MS) {
84
- if (last) state.minutes += 1;
85
- state.lastTick = at;
86
- await writeAsk(root, state);
102
+ let changed = false;
103
+ if (!state.first) { state.first = at; changed = true; }
104
+ const last = state.lastUse ? Date.parse(state.lastUse) : 0;
105
+ if (using === true && (!last || now - last >= TICK_MS)) {
106
+ state.aiMinutes += 1;
107
+ state.lastUse = at;
108
+ changed = true;
87
109
  }
110
+ if (changed) await writeAsk(root, state);
88
111
  const hushed = quietSince && now - Date.parse(quietSince) < QUIET_MS;
89
112
  const due = hushed ? null : dueMoment(state, now);
90
- if (!due) return { due: null, minutes: state.minutes };
91
- if (state.offered?.moment === due && now - Date.parse(state.offered.at) < OFFER_HOLD_MS) return { due: null, minutes: state.minutes };
113
+ if (!due) return { due: null, aiMinutes: state.aiMinutes };
114
+ if (state.offered?.moment === due && now - Date.parse(state.offered.at) < OFFER_HOLD_MS) return { due: null, aiMinutes: state.aiMinutes };
92
115
  state.offered = { moment: due, at: new Date(now).toISOString() };
93
116
  await writeAsk(root, state);
94
- return { due, minutes: state.minutes };
117
+ return { due, aiMinutes: state.aiMinutes };
95
118
  }
96
119
 
97
120
  // The person answered the moment they were asked at. Every moment reached by then counts as shown,
@@ -99,7 +122,8 @@ async function tick(root, now, { quietSince = null } = {}) {
99
122
  export function answerAsk(root, said, now = Date.now()) {
100
123
  return oneAtATime(join(root, FILE), () => recordAnswer(root, said, now));
101
124
  }
102
- async function recordAnswer(root, { moment, answer }, now) {
125
+ async function recordAnswer(root, { moment: said, answer }, now) {
126
+ const moment = momentNow(said);
103
127
  if (!ASK_ANSWERS.includes(answer)) return { error: 'answer' };
104
128
  if (!ASK_MOMENTS.some(({ id }) => id === moment)) return { error: 'moment' };
105
129
  const state = await readAsk(root);
@@ -6,13 +6,25 @@
6
6
  // room either way. The room hands in what it knows through `deps`.
7
7
 
8
8
  import { pickDistiller, distillPrompt, parseDistillation, OLLAMA_ARCHIVIST } from '../distiller.mjs';
9
+ import { BUSY_WAIT_MS } from './busy.mjs';
9
10
 
10
11
  export const BENCH_MS = 30 * 60 * 1000;
12
+ // The local model distils in the background, where nobody waits for it, on computers that may have
13
+ // no graphics card. On Carlos's server (16 cores, no card, L-1, 2026-11-04) qwen2.5:3b took 235 to
14
+ // 300 s a batch, and the 300 s it was given cut one batch in three: Gemini was paid for it, and the
15
+ // local try came back half an hour later to be cut again, holding every core each time. A
16
+ // cut try throws away its work, so a longer limit spends less of the computer, not more.
17
+ export const LOCAL_DISTILL_MS = 15 * 60 * 1000;
18
+ // One that does not finish even in those sits out for hours rather than half an hour: a computer
19
+ // that slow is not faster thirty minutes later.
20
+ export const SLOW_LOCAL_BENCH_MS = 6 * 60 * 60 * 1000;
11
21
  // A failure that says nothing about the batch: no network, a provider's limit or a timeout
12
22
  // (2026-11-01, external review #18). Before, three of those in a row — a day offline — set the
13
23
  // batch aside for good, as if it could never be distilled, and its notes were never written. Those
14
24
  // stay in the queue and are tried again; only a batch that keeps failing for itself is skipped.
15
- const PASSING = /ETIMEDOUT|ECONNRESET|ECONNREFUSED|ENOTFOUND|EAI_AGAIN|ENETUNREACH|fetch failed|network|timed? ?out|\b(429|502|503|504)\b|rate.?limit|quota|usage limit|overloaded|unavailable/i;
25
+ // A room in Spanish says its own timeouts in Spanish («no contestó antes del tiempo límite», L-1):
26
+ // those read as passing too.
27
+ const PASSING = /ETIMEDOUT|ECONNRESET|ECONNREFUSED|ENOTFOUND|EAI_AGAIN|ENETUNREACH|fetch failed|network|timed? ?out|tiempo l[ií]mite|se qued[oó] callad|\b(429|502|503|504)\b|rate.?limit|quota|usage limit|overloaded|unavailable/i;
16
28
  export const passingFailure = (error) => PASSING.test(`${error?.code ?? ''} ${error?.message ?? error ?? ''}`);
17
29
 
18
30
  export function distillDefaults(distill = {}, env = process.env) {
@@ -42,7 +54,7 @@ export class Archivist {
42
54
  #failures = new Map(); // fromSequence -> failed attempts on that batch
43
55
  #bench = new Map(); // agent -> until (ms)
44
56
 
45
- // deps: agents(), invokers(), busyAgents(), turnsInFlight(), timeoutFor(id), localTimeoutMs(), projectName(), emit(type, payload), recordUsage(agent, usage), stopped(), failureMessage(error)
57
+ // deps: agents(), invokers(), busyAgents(), turnsInFlight(), timeoutFor(id), localTimeoutMs(), projectName(), emit(type, payload), recordUsage(agent, usage), stopped(), noSession(), machineBusy(), failureMessage(error)
46
58
  constructor({ memory, settings, deps }) {
47
59
  this.#memory = memory;
48
60
  this.#settings = settings;
@@ -82,8 +94,12 @@ export class Archivist {
82
94
 
83
95
  #candidates() {
84
96
  const invokers = this.#deps.invokers();
85
- // @madre answers questions; the archive is written by the Ollama archivist itself.
86
- const agents = this.#deps.agents().filter((agent) => agent.adapter !== 'madre-local');
97
+ // @madre answers questions; the archive is written by the Ollama archivist itself. An agent
98
+ // MADRE knows has no session is not a candidate (L-9, Carlos's server, 2026-11-05): Codex
99
+ // installed but signed out was named «takes the next run» twice, and each try spent one of
100
+ // the batch's attempts on a summary it could not write.
101
+ const noSession = this.#deps.noSession?.() ?? new Set();
102
+ const agents = this.#deps.agents().filter((agent) => agent.adapter !== 'madre-local' && !noSession.has(agent.id));
87
103
  const everyone = invokers.ollama ? [OLLAMA_ARCHIVIST, ...agents] : agents;
88
104
  return this.#settings.allowed ? everyone.filter((agent) => this.#settings.allowed.includes(agent.id)) : everyone;
89
105
  }
@@ -120,6 +136,14 @@ export class Archivist {
120
136
  let agent = pickDistiller(candidates, { preferred: this.#settings.agent, busy, invokers, benched });
121
137
  if (!agent && benched.size) { this.#bench.clear(); agent = pickDistiller(candidates, { preferred: this.#settings.agent, busy, invokers }); }
122
138
  if (!agent) return null;
139
+ // The local model waits for a computer that is not already full (L-11, src/room/busy.mjs): tried
140
+ // again in a few minutes, not handed to a paid agent, and not counted as a failure.
141
+ if (agent.adapter === 'ollama' && this.#deps.machineBusy?.()) {
142
+ clearTimeout(this.#timer);
143
+ this.#timer = setTimeout(() => { this.#timer = null; if (!this.#deps.stopped()) void this.runNow(); }, BUSY_WAIT_MS);
144
+ this.#timer.unref?.();
145
+ return { agent: agent.id, local: true, postponed: true };
146
+ }
123
147
  const started = Date.now();
124
148
  try {
125
149
  const local = agent.adapter === 'ollama';
@@ -142,7 +166,8 @@ export class Archivist {
142
166
  this.#failures.set(batch.fromSequence, attempts);
143
167
  const skipped = attempts >= 3 && !passingFailure(error);
144
168
  if (skipped) { this.#memory.markDistilled(batch.sequences); this.#failures.delete(batch.fromSequence); }
145
- this.#bench.set(agent.id, Date.now() + BENCH_MS);
169
+ const slowLocal = agent.adapter === 'ollama' && error?.code === 'ETIMEDOUT';
170
+ this.#bench.set(agent.id, Date.now() + (slowLocal ? SLOW_LOCAL_BENCH_MS : BENCH_MS));
146
171
  const next = pickDistiller(candidates, { preferred: this.#settings.agent, busy: new Set(), invokers, benched: new Set(this.#bench.keys()) });
147
172
  const report = { agent: agent.id, error: this.#deps.failureMessage(error), attempts, skipped, next: next?.id ?? null, fromSequence: batch.fromSequence, throughSequence: batch.throughSequence, considered: batch.entries.length, remaining: batch.remaining };
148
173
  await this.#deps.emit('memory.distilled', report);