@jossuealcala/madre 1.0.5 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (278) hide show
  1. package/ADDITIONAL-TERMS.md +7 -2
  2. package/CHANGELOG.en.md +47 -1
  3. package/CHANGELOG.md +47 -1
  4. package/CONTRIBUTING.md +2 -2
  5. package/LICENSE +111 -661
  6. package/NOTICE +28 -23
  7. package/README.en.md +30 -101
  8. package/README.md +30 -103
  9. package/SECURITY.md +1 -0
  10. package/TRADEMARKS.en.md +13 -14
  11. package/TRADEMARKS.md +24 -26
  12. package/bin/madre.cjs +2 -2
  13. package/bin/madre.mjs +112 -40
  14. package/docs/REFERENCE.md +52 -5
  15. package/docs/SDK.md +21 -3
  16. package/docs/en/REFERENCE.md +52 -5
  17. package/docs/en/SDK.md +22 -3
  18. package/docs/sdk/hello-module.mjs +3 -0
  19. package/package.json +3 -2
  20. package/public/abduction.js +6 -6
  21. package/public/activity.js +425 -0
  22. package/public/app.js +2468 -435
  23. package/public/assets/abduction-cat-blink.webp +0 -0
  24. package/public/assets/abduction-cat-control-left.webp +0 -0
  25. package/public/assets/abduction-cat-control-right.webp +0 -0
  26. package/public/assets/abduction-cat.webp +0 -0
  27. package/public/assets/manual/shots/en-agents.webp +0 -0
  28. package/public/assets/manual/shots/en-chats.webp +0 -0
  29. package/public/assets/manual/shots/en-code.webp +0 -0
  30. package/public/assets/manual/shots/en-composer.webp +0 -0
  31. package/public/assets/manual/shots/en-connectors.webp +0 -0
  32. package/public/assets/manual/shots/en-continuity.webp +0 -0
  33. package/public/assets/manual/shots/en-coordinator.webp +0 -0
  34. package/public/assets/manual/shots/en-copilot.webp +0 -0
  35. package/public/assets/manual/shots/en-diagnostics.webp +0 -0
  36. package/public/assets/manual/shots/en-home.webp +0 -0
  37. package/public/assets/manual/shots/en-local.webp +0 -0
  38. package/public/assets/manual/shots/en-market.webp +0 -0
  39. package/public/assets/manual/shots/en-memory.webp +0 -0
  40. package/public/assets/manual/shots/en-modes.webp +0 -0
  41. package/public/assets/manual/shots/en-notes.webp +0 -0
  42. package/public/assets/manual/shots/en-settings.webp +0 -0
  43. package/public/assets/manual/shots/en-welcome.webp +0 -0
  44. package/public/assets/manual/shots/en-windows.webp +0 -0
  45. package/public/assets/manual/shots/es-agents.webp +0 -0
  46. package/public/assets/manual/shots/es-chats.webp +0 -0
  47. package/public/assets/manual/shots/es-code.webp +0 -0
  48. package/public/assets/manual/shots/es-composer.webp +0 -0
  49. package/public/assets/manual/shots/es-connectors.webp +0 -0
  50. package/public/assets/manual/shots/es-continuity.webp +0 -0
  51. package/public/assets/manual/shots/es-coordinator.webp +0 -0
  52. package/public/assets/manual/shots/es-copilot.webp +0 -0
  53. package/public/assets/manual/shots/es-diagnostics.webp +0 -0
  54. package/public/assets/manual/shots/es-home.webp +0 -0
  55. package/public/assets/manual/shots/es-local.webp +0 -0
  56. package/public/assets/manual/shots/es-market.webp +0 -0
  57. package/public/assets/manual/shots/es-memory.webp +0 -0
  58. package/public/assets/manual/shots/es-modes.webp +0 -0
  59. package/public/assets/manual/shots/es-notes.webp +0 -0
  60. package/public/assets/manual/shots/es-settings.webp +0 -0
  61. package/public/assets/manual/shots/es-welcome.webp +0 -0
  62. package/public/assets/manual/shots/es-windows.webp +0 -0
  63. package/public/assets/news/1.1/en/chats.webp +0 -0
  64. package/public/assets/news/1.1/en/home.webp +0 -0
  65. package/public/assets/news/1.1/en/maps.webp +0 -0
  66. package/public/assets/news/1.1/en/market.webp +0 -0
  67. package/public/assets/news/1.1/en/permissions.webp +0 -0
  68. package/public/assets/news/1.1/en/privacy.webp +0 -0
  69. package/public/assets/news/1.1/en/welcome.webp +0 -0
  70. package/public/assets/news/1.1/es/chats.webp +0 -0
  71. package/public/assets/news/1.1/es/home.webp +0 -0
  72. package/public/assets/news/1.1/es/maps.webp +0 -0
  73. package/public/assets/news/1.1/es/market.webp +0 -0
  74. package/public/assets/news/1.1/es/permissions.webp +0 -0
  75. package/public/assets/news/1.1/es/privacy.webp +0 -0
  76. package/public/assets/news/1.1/es/welcome.webp +0 -0
  77. package/public/attribution.js +15 -16
  78. package/public/brands.js +2 -2
  79. package/public/code-tools.js +2 -2
  80. package/public/editor.js +13 -13
  81. package/public/en.js +413 -4
  82. package/public/es.js +1345 -483
  83. package/public/hardware.js +2 -2
  84. package/public/i18n.js +2 -2
  85. package/public/icons.js +158 -0
  86. package/public/index.html +66 -48
  87. package/public/inquiry.js +2 -2
  88. package/public/loader.js +271 -2
  89. package/public/macroverso.js +60 -21
  90. package/public/manual-content.js +412 -169
  91. package/public/manual-shots.js +38 -34
  92. package/public/manual.css +20 -2
  93. package/public/manual.html +1 -1
  94. package/public/manual.js +54 -25
  95. package/public/market-art.js +47 -45
  96. package/public/market-view.js +111 -33
  97. package/public/market.js +132 -30
  98. package/public/mcp-catalog.js +2 -2
  99. package/public/neural.js +64 -8
  100. package/public/nostromo-engine.js +709 -40
  101. package/public/page-errors.js +29 -0
  102. package/public/power.js +350 -11
  103. package/public/remedy.js +89 -0
  104. package/public/resay.js +3 -2
  105. package/public/review-ask.js +12 -7
  106. package/public/routing.js +3 -3
  107. package/public/salas-mac.css +703 -24
  108. package/public/salas-mac.html +26 -14
  109. package/public/salas-mac.js +1254 -289
  110. package/public/salas.css +2 -2
  111. package/public/salas.html +3 -3
  112. package/public/salas.js +3 -3
  113. package/public/styles.css +2404 -291
  114. package/public/syntax.js +2 -2
  115. package/public/terms.js +152 -0
  116. package/public/touch.js +2 -2
  117. package/public/tour-chapters.js +10 -10
  118. package/public/tour.js +56 -8
  119. package/public/troubleshooting.js +182 -11
  120. package/public/wallpaper.js +4 -3
  121. package/public/welcome.js +923 -0
  122. package/src/activity.mjs +85 -0
  123. package/src/adapters/claude.mjs +61 -35
  124. package/src/adapters/codex.mjs +18 -5
  125. package/src/adapters/cursor.mjs +5 -3
  126. package/src/adapters/gemini.mjs +5 -3
  127. package/src/adapters/madre.mjs +3 -3
  128. package/src/adapters/opencode.mjs +73 -10
  129. package/src/adapters/process.mjs +14 -13
  130. package/src/adapters/subagents.mjs +159 -0
  131. package/src/asking.mjs +8 -2
  132. package/src/auth-probe.mjs +27 -10
  133. package/src/bridge/devices.mjs +2 -2
  134. package/src/bridge/handoff.mjs +2 -2
  135. package/src/bridge/host.mjs +2 -2
  136. package/src/bridge/network.mjs +2 -2
  137. package/src/bridge/policy.mjs +3 -3
  138. package/src/bridge/qr.mjs +2 -2
  139. package/src/bridge/server.mjs +2 -2
  140. package/src/builtin-updates.mjs +87 -0
  141. package/src/capabilities.mjs +2 -2
  142. package/src/chats.mjs +51 -2
  143. package/src/checkpoint.mjs +67 -9
  144. package/src/choices.mjs +2 -2
  145. package/src/cli-args.mjs +2 -2
  146. package/src/cold.mjs +2 -2
  147. package/src/commands.mjs +2 -2
  148. package/src/config.mjs +2 -2
  149. package/src/conversation-context.mjs +2 -2
  150. package/src/credentials.mjs +56 -16
  151. package/src/dataset.mjs +2 -2
  152. package/src/directives.mjs +2 -2
  153. package/src/distiller.mjs +2 -2
  154. package/src/embeddings.mjs +2 -2
  155. package/src/enlaces.mjs +2 -2
  156. package/src/environment.mjs +147 -0
  157. package/src/event-store.mjs +2 -2
  158. package/src/exam.mjs +2 -2
  159. package/src/extensions.mjs +2 -2
  160. package/src/eyecat-watch.mjs +2 -2
  161. package/src/eyecat.mjs +2 -2
  162. package/src/file-ops.mjs +2 -2
  163. package/src/files.mjs +2 -2
  164. package/src/github.mjs +2 -2
  165. package/src/heartbeat.mjs +2 -2
  166. package/src/history.mjs +2 -2
  167. package/src/i18n.mjs +9 -2
  168. package/src/image-studio.mjs +2 -2
  169. package/src/install-metrics.mjs +109 -0
  170. package/src/json-file.mjs +2 -2
  171. package/src/launch.mjs +2 -2
  172. package/src/lease.mjs +15 -4
  173. package/src/lobby-work.mjs +11 -4
  174. package/src/local-ai.mjs +2 -2
  175. package/src/looks.mjs +2 -2
  176. package/src/market-check.mjs +165 -0
  177. package/src/market-key.mjs +10 -2
  178. package/src/market-license.mjs +4 -4
  179. package/src/market-remote.mjs +54 -12
  180. package/src/maturity.mjs +2 -2
  181. package/src/mcp/connect.mjs +2 -2
  182. package/src/mcp/github-server.mjs +2 -2
  183. package/src/mcp/image-server.mjs +2 -2
  184. package/src/mcp/memory-server.mjs +2 -2
  185. package/src/mcp/proxy.mjs +2 -2
  186. package/src/mcp/smtp-server.mjs +2 -2
  187. package/src/memory-dashboard.mjs +2 -2
  188. package/src/memory-tools.mjs +2 -2
  189. package/src/memory.mjs +2 -2
  190. package/src/models.mjs +33 -3
  191. package/src/module-scope.mjs +2 -2
  192. package/src/modules/ahp.mjs +2 -2
  193. package/src/modules/ash-policy.mjs +2 -2
  194. package/src/modules/ash.mjs +2 -2
  195. package/src/modules/bishop-exam.mjs +2 -2
  196. package/src/modules/bishop-plan.mjs +2 -2
  197. package/src/modules/bishop.mjs +9 -3
  198. package/src/modules/choices.mjs +2 -2
  199. package/src/modules/correo.mjs +2 -2
  200. package/src/modules/enlaces.mjs +2 -2
  201. package/src/modules/git-pulse.mjs +2 -2
  202. package/src/modules/github.mjs +2 -2
  203. package/src/modules/helpers.mjs +2 -2
  204. package/src/modules/image-studio.mjs +2 -2
  205. package/src/modules/index.mjs +90 -5
  206. package/src/modules/intents-calibration.mjs +2 -2
  207. package/src/modules/intents-desk.mjs +4 -3
  208. package/src/modules/intents-observe.mjs +2 -2
  209. package/src/modules/intents-policy.mjs +2 -2
  210. package/src/modules/intents-try.mjs +2 -2
  211. package/src/modules/intents.mjs +2 -2
  212. package/src/modules/local-models.mjs +14 -11
  213. package/src/modules/mcp-connect.mjs +2 -2
  214. package/src/modules/notes.mjs +159 -20
  215. package/src/modules/ollama.mjs +9 -3
  216. package/src/modules/playwright.mjs +2 -2
  217. package/src/modules/reminders.mjs +356 -37
  218. package/src/modules/ripley.mjs +3 -3
  219. package/src/modules/runs.mjs +2 -2
  220. package/src/modules/sdk.mjs +38 -6
  221. package/src/modules/updates.mjs +2 -2
  222. package/src/mother.mjs +2 -2
  223. package/src/npm-launch.mjs +2 -2
  224. package/src/ollama.mjs +6 -4
  225. package/src/opencode-health.mjs +26 -6
  226. package/src/outbound.mjs +10 -2
  227. package/src/override.mjs +27 -22
  228. package/src/ports.mjs +2 -2
  229. package/src/prices.mjs +2 -2
  230. package/src/privacy.mjs +2 -2
  231. package/src/quota-monitor.mjs +2 -2
  232. package/src/quota-sources.mjs +2 -2
  233. package/src/request-guard.mjs +2 -2
  234. package/src/review-ask.mjs +4 -3
  235. package/src/room/archivist.mjs +2 -2
  236. package/src/room/attachments.mjs +2 -2
  237. package/src/room/budget.mjs +2 -2
  238. package/src/room/context.mjs +2 -2
  239. package/src/room/control.mjs +2 -2
  240. package/src/room/copilot.mjs +2 -2
  241. package/src/room/economy.mjs +2 -2
  242. package/src/room/escalation.mjs +2 -2
  243. package/src/room/ghost.mjs +2 -2
  244. package/src/room/guard.mjs +6 -4
  245. package/src/room/prompt.mjs +3 -3
  246. package/src/room/returns.mjs +2 -2
  247. package/src/room/runs.mjs +6 -4
  248. package/src/room/vectors.mjs +2 -2
  249. package/src/room.mjs +127 -31
  250. package/src/router.mjs +2 -2
  251. package/src/runs.mjs +2 -2
  252. package/src/runtime-detection.mjs +31 -5
  253. package/src/salas.mjs +31 -6
  254. package/src/sentinel-errors.mjs +13 -4
  255. package/src/server-sentinel.mjs +2 -2
  256. package/src/server.mjs +689 -80
  257. package/src/setup-trouble.mjs +33 -0
  258. package/src/setup.mjs +4 -4
  259. package/src/smtp.mjs +2 -2
  260. package/src/telemetry.mjs +266 -0
  261. package/src/terms.mjs +43 -0
  262. package/src/tour.mjs +39 -5
  263. package/src/uninstall.mjs +225 -0
  264. package/src/updates.mjs +2 -2
  265. package/src/usage-sentinel.mjs +2 -2
  266. package/src/vault.mjs +2 -2
  267. package/src/verdict.mjs +13 -10
  268. package/src/whats-new.mjs +97 -3
  269. package/public/assets/abduction-cat-blink.png +0 -0
  270. package/public/assets/abduction-cat-control-left.png +0 -0
  271. package/public/assets/abduction-cat-control-right.png +0 -0
  272. package/public/assets/abduction-cat.png +0 -0
  273. package/public/assets/manual/madre-manual-en.pdf +0 -0
  274. package/public/assets/manual/madre-manual-es.pdf +0 -0
  275. package/public/assets/manual/shots/en-modules.webp +0 -0
  276. package/public/assets/manual/shots/es-modules.webp +0 -0
  277. package/src/mcp/notes-server.mjs +0 -120
  278. package/src/reminder-time.mjs +0 -127
@@ -1,7 +1,8 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
2
- // MADRE · © 2026 Jossue Alcalá · GNU AGPL v3 with additional terms (Section 7): ADDITIONAL-TERMS.md
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+ // MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
3
3
  import { execFile } from 'node:child_process';
4
- import { access, mkdir, mkdtemp, readFile, readdir, rm, rmdir, stat, unlink, writeFile } from 'node:fs/promises';
4
+ import { constants as fsConstants } from 'node:fs';
5
+ import { access, chmod, cp, lstat, mkdir, mkdtemp, readFile, readdir, rename, rm, rmdir, stat, unlink, writeFile } from 'node:fs/promises';
5
6
  import { tmpdir } from 'node:os';
6
7
  import { dirname, join, resolve, sep } from 'node:path';
7
8
  import { createHash } from 'node:crypto';
@@ -24,24 +25,77 @@ export const CHECKPOINT_REF = 'refs/madre/checkpoints';
24
25
  export const FORBIDDEN = [
25
26
  /^\.git(\/|$)/i,
26
27
  /^\.pulse(\/|$)/i,
27
- /(^|\/)\.env(\.|$)/i,
28
+ // A template that documents the variables and holds no secret is not one (QA 1.1.0, NUE-21):
29
+ // .env.example, .env.sample, .env.template and .env.dist are meant to be written and shared.
30
+ /(^|\/)\.env(?:$|\.(?!(?:example|sample|template|dist)$))/i,
28
31
  /(^|\/)\.madre(\/|$)/i,
29
32
  /(^|\/)\.claude\/settings\.local\.json$/i,
30
33
  ];
34
+ // The same rule said as globs, for the CLIs that take a list of paths (src/adapters/*): every
35
+ // secret-bearing variant by name, since a deny there cannot be undone by an allow.
36
+ export const ENV_TEMPLATES = ['.env.example', '.env.sample', '.env.template', '.env.dist'];
37
+ export const ENV_SECRETS = ['.env', '.env.local', '.env.*.local', '.env.development', '.env.dev', '.env.production', '.env.prod', '.env.staging', '.env.test', '.env.preview'];
31
38
  export const isForbidden = (path) => FORBIDDEN.some((pattern) => pattern.test(path));
32
39
 
40
+ // A repository is a `.git` file (a worktree, a submodule) or a `.git` folder with its HEAD. A
41
+ // `.git` folder left half-made (2026-10-28, a copied project: hooks, objects and no HEAD) is not
42
+ // one: git refuses it, so the project is photographed with a shadow like any other.
33
43
  export async function isGitRepo(root) {
34
- return access(join(root, '.git')).then(() => true, () => false);
44
+ const found = await stat(join(root, '.git')).catch(() => null);
45
+ if (!found) return false;
46
+ if (found.isFile()) return true;
47
+ return access(join(root, '.git', 'HEAD')).then(() => true, () => false);
35
48
  }
36
49
 
37
50
  // A project that is not a git repository still gets photographs: MADRE keeps a shadow
38
51
  // repository of its own outside the project (one per project path) and runs git with the
39
52
  // project as work tree. Nothing appears inside the project; UNDO and diffs work the same.
40
53
  const shadows = new Map();
54
+ // The shadows hold a copy of the project, .env included: on Linux the temporary folder is shared by
55
+ // every user of the computer (a lent server, a VM), so they live in a folder only this user can open
56
+ // (0700, theirs, not a link). One that someone else made first is never used: a fresh one is.
57
+ let shadowBase = null;
58
+ async function shadowHome() {
59
+ if (shadowBase) return shadowBase;
60
+ const uid = process.getuid?.();
61
+ const base = join(tmpdir(), uid === undefined ? 'madre-shadow' : `madre-shadow-${uid}`);
62
+ await mkdir(base, { recursive: true, mode: 0o700 });
63
+ const found = await lstat(base).catch(() => null);
64
+ const ours = found?.isDirectory() && !found.isSymbolicLink() && (uid === undefined || found.uid === uid);
65
+ if (ours && (found.mode & 0o077)) await chmod(base, 0o700).catch(() => null);
66
+ shadowBase = ours ? base : await mkdtemp(join(tmpdir(), 'madre-shadow-'));
67
+ return shadowBase;
68
+ }
69
+ // Where a project's shadow would be, without making it (src/uninstall.mjs takes it away). Only the
70
+ // folder of this user's own: a fresh one made beside someone else's lasts as long as the process.
71
+ export function shadowFolderFor(root) {
72
+ const uid = process.getuid?.();
73
+ return join(tmpdir(), uid === undefined ? 'madre-shadow' : `madre-shadow-${uid}`, createHash('sha1').update(resolve(root)).digest('hex').slice(0, 16));
74
+ }
75
+ // Where 1.0.x kept it (QA 1.1.0, ACT-04): one folder for everyone, madre-shadow/<hash>. Read so an
76
+ // update keeps the restore points made before it, and so uninstalling takes it away too.
77
+ export function legacyShadowFolderFor(root) {
78
+ if (process.getuid?.() === undefined) return null;
79
+ return join(tmpdir(), 'madre-shadow', createHash('sha1').update(resolve(root)).digest('hex').slice(0, 16));
80
+ }
81
+ // The first time a project is photographed after the update, its old shadow moves into this user's
82
+ // own folder, if it is this user's and nothing is there yet; the old one, a copy of the project
83
+ // with its .env in a folder others can open, does not stay behind.
84
+ async function adoptLegacyShadow(root, dir) {
85
+ const old = legacyShadowFolderFor(root);
86
+ if (!old || resolve(old) === resolve(dir)) return;
87
+ const found = await lstat(old).catch(() => null);
88
+ if (!found?.isDirectory() || found.isSymbolicLink() || found.uid !== process.getuid?.()) return;
89
+ if (await access(join(dir, 'HEAD')).then(() => true, () => false)) return;
90
+ await rm(dir, { recursive: true, force: true }).catch(() => {});
91
+ await rename(old, dir).catch(async () => { await cp(old, dir, { recursive: true }); await rm(old, { recursive: true, force: true }); });
92
+ await chmod(dir, 0o700).catch(() => null);
93
+ }
41
94
  async function shadowFor(root) {
42
95
  const canonical = resolve(root);
43
96
  if (!shadows.has(canonical)) {
44
- const dir = join(tmpdir(), 'madre-shadow', createHash('sha1').update(canonical).digest('hex').slice(0, 16));
97
+ const dir = join(await shadowHome(), createHash('sha1').update(canonical).digest('hex').slice(0, 16));
98
+ await adoptLegacyShadow(canonical, dir).catch(() => {});
45
99
  await mkdir(dir, { recursive: true });
46
100
  const isRepo = await access(join(dir, 'HEAD')).then(() => true, () => false);
47
101
  if (!isRepo) await execFileAsync('git', ['init', '-q', '--bare', dir]);
@@ -69,8 +123,9 @@ async function gitArgs(root, via) {
69
123
  // next time MADRE photographed the project. Hooks, external diffs and text conversions are named
70
124
  // the same way; none of them is needed to take or compare a photograph.
71
125
  const SAFE = ['-c', 'core.quotepath=off', '-c', 'core.fsmonitor=false', '-c', 'core.hooksPath=/dev/null', '-c', 'diff.external='];
126
+ // Paths are paths, never patterns: restoring «app/[id]/page.tsx» restored «app/i/page.tsx» too.
72
127
  async function git(root, args, { env = {}, via } = {}) {
73
- const { stdout } = await execFileAsync('git', [...SAFE, ...(await gitArgs(root, via)), ...args], { cwd: root, env: { ...process.env, GIT_PAGER: 'cat', ...env }, maxBuffer: 16 * 1024 * 1024 });
128
+ const { stdout } = await execFileAsync('git', [...SAFE, ...(await gitArgs(root, via)), ...args], { cwd: root, env: { ...process.env, GIT_PAGER: 'cat', GIT_LITERAL_PATHSPECS: '1', ...env }, maxBuffer: 16 * 1024 * 1024 });
74
129
  return stdout;
75
130
  }
76
131
 
@@ -137,12 +192,15 @@ export async function worktreeTree(root, { exclude = [], via } = {}) {
137
192
  // --remove: a file that vanished since the listing is dropped instead of aborting the photograph.
138
193
  const index_ = (list) => new Promise((resolvePromise, reject) => {
139
194
  const child = execFile('git', [...SAFE, ...extra, 'update-index', '--add', '--remove', '-z', '--stdin'], { cwd: root, env: { ...process.env, GIT_PAGER: 'cat', ...env }, maxBuffer: 64 * 1024 * 1024 }, (error) => (error ? reject(error) : resolvePromise()));
195
+ // git may stop reading before the list ends (a path it refuses): that is its error, not a crash.
196
+ child.stdin.on('error', () => {});
140
197
  child.stdin.end(list.join('\0') + '\0');
141
198
  });
142
199
  try { await index_(files); } catch {
143
- // Something still raced us: photograph what exists right now.
200
+ // Something still raced us, or a file cannot be read by this user (one a container left owned
201
+ // by root): photograph what exists and can be read right now.
144
202
  const alive = [];
145
- for (const path of files) if (await access(join(root, path)).then(() => true, () => false)) alive.push(path);
203
+ for (const path of files) if (await access(join(root, path), fsConstants.R_OK).then(() => true, () => false)) alive.push(path);
146
204
  if (alive.length) await index_(alive);
147
205
  }
148
206
  }
package/src/choices.mjs CHANGED
@@ -1,5 +1,5 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
2
- // MADRE · © 2026 Jossue Alcalá · GNU AGPL v3 with additional terms (Section 7): ADDITIONAL-TERMS.md
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+ // MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
3
3
  // An agent asking the human to choose.
4
4
  //
5
5
  // The room already has one fenced channel, ```pulse, and it puts other agents to work. This is
package/src/cli-args.mjs CHANGED
@@ -1,5 +1,5 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
2
- // MADRE · © 2026 Jossue Alcalá · GNU AGPL v3 with additional terms (Section 7): ADDITIONAL-TERMS.md
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+ // MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
3
3
  // Tiny argv reader for the MADRE CLI. Accepts `--name value` and
4
4
  // `--name=value`, and remembers which options the user set explicitly so the
5
5
  // room can choose sensible defaults (like the next free port) only when they
package/src/cold.mjs CHANGED
@@ -1,5 +1,5 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
2
- // MADRE · © 2026 Jossue Alcalá · GNU AGPL v3 with additional terms (Section 7): ADDITIONAL-TERMS.md
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+ // MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
3
3
  // Cold zones: the part of the archive nothing has ever reached for.
4
4
  //
5
5
  // A memory is cold when three things are true at once, and the three together are what make the
package/src/commands.mjs CHANGED
@@ -1,5 +1,5 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
2
- // MADRE · © 2026 Jossue Alcalá · GNU AGPL v3 with additional terms (Section 7): ADDITIONAL-TERMS.md
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+ // MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
3
3
  import { execFile } from 'node:child_process';
4
4
  import { access } from 'node:fs/promises';
5
5
  import { join } from 'node:path';
package/src/config.mjs CHANGED
@@ -1,5 +1,5 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
2
- // MADRE · © 2026 Jossue Alcalá · GNU AGPL v3 with additional terms (Section 7): ADDITIONAL-TERMS.md
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+ // MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
3
3
  import { randomUUID } from 'node:crypto';
4
4
  import { copyFile, mkdir, open, readFile, rename, rm, stat, writeFile } from 'node:fs/promises';
5
5
  import { homedir } from 'node:os';
@@ -1,5 +1,5 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
2
- // MADRE · © 2026 Jossue Alcalá · GNU AGPL v3 with additional terms (Section 7): ADDITIONAL-TERMS.md
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+ // MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
3
3
  // What a command's output may weigh in the shared window, and which part of it. It used to be the
4
4
  // first 6000 characters: five outputs filled the 16 000 of the window, the request that asked for
5
5
  // them went out of it, and the agent lost the thread (2026-10-14). Now it is the start and the end
@@ -1,5 +1,5 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
2
- // MADRE · © 2026 Jossue Alcalá · GNU AGPL v3 with additional terms (Section 7): ADDITIONAL-TERMS.md
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+ // MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
3
3
  // Handing a provider key to a CLI that signs in from its own prompt.
4
4
  //
5
5
  // MADRE keeps its promise: it never stores a credential of its own. The key the human pastes is
@@ -11,11 +11,12 @@
11
11
  // signed in now. If it is not, the previous files are put back, so a format MADRE guessed wrong
12
12
  // leaves nothing behind.
13
13
 
14
- import { execFile } from 'node:child_process';
14
+ import { execFile, spawn } from 'node:child_process';
15
15
  import { chmod, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
16
16
  import { homedir } from 'node:os';
17
17
  import { join } from 'node:path';
18
18
  import { promisify } from 'node:util';
19
+ import { t } from './i18n.mjs';
19
20
 
20
21
  const execFileAsync = promisify(execFile);
21
22
  const OWNER_ONLY = 0o600;
@@ -23,9 +24,9 @@ const OWNER_ONLY = 0o600;
23
24
  // A key is one opaque token: no spaces, no newlines, and long enough to be one.
24
25
  export function normalizeKey(value) {
25
26
  const key = String(value ?? '').trim();
26
- if (!key) return { ok: false, error: 'Paste the key first.' };
27
- if (/\s/.test(key)) return { ok: false, error: 'That does not look like a key: it has spaces or line breaks.' };
28
- if (key.length < 12 || key.length > 400) return { ok: false, error: 'That does not look like a key: check you copied all of it and nothing else.' };
27
+ if (!key) return { ok: false, error: t('Paste the key first.') };
28
+ if (/\s/.test(key)) return { ok: false, error: t('That does not look like a key: it has spaces or line breaks.') };
29
+ if (key.length < 12 || key.length > 400) return { ok: false, error: t('That does not look like a key: check you copied all of it and nothing else.') };
29
30
  return { ok: true, key };
30
31
  }
31
32
 
@@ -88,6 +89,18 @@ export async function openCodeKeyProviders({ home = homedir(), env = process.env
88
89
 
89
90
  // What the room offers for each agent that cannot be signed in with a click.
90
91
  export function keyPlanFor(id) {
92
+ // Codex takes its key through its own login (2026-10-28): `codex login --with-api-key`, the key on
93
+ // its input, so the file it lands in is Codex's own and written by Codex.
94
+ if (id === 'codex') {
95
+ return {
96
+ agent: 'codex',
97
+ label: 'OpenAI API key',
98
+ keyUrl: 'https://platform.openai.com/api-keys',
99
+ writesTo: '~/.codex/auth.json',
100
+ note: 'The key is handed to Codex itself, which keeps it in its own file, readable only by you. MADRE keeps no copy. It replaces the account Codex was signed in with, here and in your own terminal.',
101
+ providers: null,
102
+ };
103
+ }
91
104
  if (id === 'claude') {
92
105
  return {
93
106
  agent: 'claude',
@@ -154,13 +167,13 @@ async function applyGeminiKey(key, { home, probe }) {
154
167
  if (state?.state !== 'signed-in') {
155
168
  await restore(envFile, beforeEnv);
156
169
  await restore(settingsFile, beforeSettings);
157
- return { ok: false, error: `The key was written but Gemini still reads as ${state?.state ?? 'unknown'}${state?.detail ? ` (${state.detail})` : ''}. Nothing was changed.` };
170
+ return { ok: false, error: t('The key was written but {agent} still reads as {state}. Nothing was changed.', { agent: 'Gemini', state: `${state?.state ?? 'unknown'}${state?.detail ? ` (${state.detail})` : ''}` }) };
158
171
  }
159
172
  return { ok: true, detail: state.detail ?? 'via API key' };
160
173
  } catch (error) {
161
174
  await restore(envFile, beforeEnv);
162
175
  await restore(settingsFile, beforeSettings);
163
- return { ok: false, error: `The key could not be written: ${error.message}` };
176
+ return { ok: false, error: t('The key could not be written: {error}', { error: error.message }) };
164
177
  }
165
178
  }
166
179
 
@@ -182,19 +195,45 @@ async function applyClaudeKey(key, { home, probe }) {
182
195
  const state = await probe();
183
196
  if (state?.state !== 'signed-in') {
184
197
  await restore(file, before);
185
- return { ok: false, error: `The key was written but Claude still reads as ${state?.state ?? 'unknown'}${state?.detail ? ` (${state.detail})` : ''}. Nothing was changed.` };
198
+ return { ok: false, error: t('The key was written but {agent} still reads as {state}. Nothing was changed.', { agent: 'Claude', state: `${state?.state ?? 'unknown'}${state?.detail ? ` (${state.detail})` : ''}` }) };
186
199
  }
187
200
  return { ok: true, detail: state.detail ?? 'via API key' };
188
201
  } catch (error) {
189
202
  await restore(file, before);
190
- return { ok: false, error: `The key could not be written: ${error.message}` };
203
+ return { ok: false, error: t('The key could not be written: {error}', { error: error.message }) };
191
204
  }
192
205
  }
193
206
 
207
+ // ---- Codex: its own login, with the key on its input (never in its arguments, where `ps` shows
208
+ // them), confirmed by asking Codex again. Its sign-in file is kept first and put back if the key is
209
+ // refused, so a wrong key never signs out an account that worked.
210
+ const runWithInput = (command, args, input, { timeoutMs = 30000 } = {}) => new Promise((resolve) => {
211
+ let child;
212
+ try { child = spawn(command, args, { stdio: ['pipe', 'pipe', 'pipe'], windowsHide: true, env: { ...process.env, NO_COLOR: '1' } }); } catch (error) { resolve({ code: null, out: error.message }); return; }
213
+ let out = '';
214
+ child.stdout.on('data', (chunk) => { out += chunk; });
215
+ child.stderr.on('data', (chunk) => { out += chunk; });
216
+ const timer = setTimeout(() => child.kill('SIGTERM'), timeoutMs);
217
+ child.on('error', (error) => { clearTimeout(timer); resolve({ code: null, out: error.message }); });
218
+ child.on('close', (code) => { clearTimeout(timer); resolve({ code, out }); });
219
+ child.stdin.on('error', () => {});
220
+ child.stdin.end(`${input}\n`);
221
+ });
222
+ async function applyCodexKey(key, { home, probe, executable = 'codex', run = runWithInput }) {
223
+ const file = join(process.env.CODEX_HOME || join(home, '.codex'), 'auth.json');
224
+ const before = await readIfThere(file);
225
+ const said = await run(executable, ['login', '--with-api-key'], key);
226
+ const state = said.code === 0 ? await probe() : null;
227
+ if (state?.state === 'signed-in') return { ok: true, detail: state.detail ?? 'via API key' };
228
+ await restore(file, before);
229
+ const why = String(said.out ?? '').trim().split('\n').filter(Boolean).at(-1);
230
+ return { ok: false, error: why ? t('Codex did not take the key ({why}). Nothing was changed.', { why: why.slice(0, 160) }) : t('Codex did not take the key. Nothing was changed.') };
231
+ }
232
+
194
233
  // ---- OpenCode: an entry in its auth.json, confirmed by asking `opencode auth list`.
195
234
  async function applyOpenCodeKey(key, { home, provider, executable, run }) {
196
235
  const known = typeof provider === 'string' ? (await openCodeKeyProviders({ home })).find((item) => item.id === provider) : null;
197
- if (!known) return { ok: false, error: 'Pick the provider this key belongs to.' };
236
+ if (!known) return { ok: false, error: t('Pick the provider this key belongs to.') };
198
237
  const file = join(home, '.local', 'share', 'opencode', 'auth.json');
199
238
  await mkdir(join(home, '.local', 'share', 'opencode'), { recursive: true });
200
239
  const before = await readIfThere(file);
@@ -210,12 +249,12 @@ async function applyOpenCodeKey(key, { home, provider, executable, run }) {
210
249
  const listed = String(await run(executable, ['auth', 'list'])).toLowerCase();
211
250
  if (!listed.includes(provider.toLowerCase()) && !listed.includes(String(known.label).toLowerCase())) {
212
251
  await restore(file, before);
213
- return { ok: false, error: `OpenCode does not list ${provider} after the key was written, so MADRE put the file back. Run \`opencode auth login\` in a terminal for this one.` };
252
+ return { ok: false, error: t('OpenCode does not list {provider} after the key was written, so MADRE put the file back. Run `opencode auth login` in a terminal for this one.', { provider }) };
214
253
  }
215
254
  return { ok: true, detail: `${provider} (api)` };
216
255
  } catch (error) {
217
256
  await restore(file, before);
218
- return { ok: false, error: `The key could not be written: ${error.message}` };
257
+ return { ok: false, error: t('The key could not be written: {error}', { error: error.message }) };
219
258
  }
220
259
  }
221
260
 
@@ -229,13 +268,14 @@ const runOpenCode = async (executable, args) => {
229
268
  };
230
269
 
231
270
  // Writes the key for one agent and answers whether that agent is signed in now.
232
- export async function applyKey({ agent, key, provider = null, home = homedir(), probe, executable = 'opencode', run = runOpenCode }) {
271
+ export async function applyKey({ agent, key, provider = null, home = homedir(), probe, executable = null, run = null }) {
233
272
  const checked = normalizeKey(key);
234
273
  if (!checked.ok) return checked;
274
+ if (agent === 'codex') return applyCodexKey(checked.key, { home, probe, executable: executable ?? 'codex', run: run ?? runWithInput });
235
275
  if (agent === 'claude') return applyClaudeKey(checked.key, { home, probe });
236
276
  if (agent === 'gemini') return applyGeminiKey(checked.key, { home, probe });
237
- if (agent === 'opencode') return applyOpenCodeKey(checked.key, { home, provider, executable, run });
238
- return { ok: false, error: `${agent} does not take a key here: it signs in with a click.` };
277
+ if (agent === 'opencode') return applyOpenCodeKey(checked.key, { home, provider, executable: executable ?? 'opencode', run: run ?? runOpenCode });
278
+ return { ok: false, error: t('{agent} does not take a key here: it signs in with a click.', { agent }) };
239
279
  }
240
280
 
241
281
  // ---- OpenCode's providers, as its auth.json says them: who is signed in and how, never the key.
package/src/dataset.mjs CHANGED
@@ -1,5 +1,5 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
2
- // MADRE · © 2026 Jossue Alcalá · GNU AGPL v3 with additional terms (Section 7): ADDITIONAL-TERMS.md
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+ // MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
3
3
  // The dataset behind MADRE AI: every exchange the room kept (never GHOST),
4
4
  // redacted, as chat pairs a small model can learn from, plus the distilled
5
5
  // notes. Written next to the room's ledger in the format mlx-lm and most
@@ -1,5 +1,5 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
2
- // MADRE · © 2026 Jossue Alcalá · GNU AGPL v3 with additional terms (Section 7): ADDITIONAL-TERMS.md
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+ // MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
3
3
  // Agent-to-agent delegation. An agent answering in the room may end its reply
4
4
  // with a fenced block that puts other agents to work, in order:
5
5
  //
package/src/distiller.mjs CHANGED
@@ -1,5 +1,5 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
2
- // MADRE · © 2026 Jossue Alcalá · GNU AGPL v3 with additional terms (Section 7): ADDITIONAL-TERMS.md
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+ // MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
3
3
  // The archivist's turn: every so often the cheapest agent in the room reads
4
4
  // the exchanges nobody has distilled yet and writes the few notes worth
5
5
  // keeping for every later turn. Pure functions here; the room schedules and
@@ -1,5 +1,5 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
2
- // MADRE · © 2026 Jossue Alcalá · GNU AGPL v3 with additional terms (Section 7): ADDITIONAL-TERMS.md
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+ // MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
3
3
  // Embeddings for the room memory: meaning-aware recall on top of the lexical
4
4
  // index. Gemini's embedding model through the user's own key (the same key
5
5
  // Image Studio and the Gemini CLI use); no key, no embeddings, and recall stays
package/src/enlaces.mjs CHANGED
@@ -1,5 +1,5 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
2
- // MADRE · © 2026 Jossue Alcalá · GNU AGPL v3 with additional terms (Section 7): ADDITIONAL-TERMS.md
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+ // MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
3
3
  // Links between rooms (docs/MACROVERSO.md, phase 3b): the contract two rooms sign, the key that
4
4
  // proves a caller is a MADRE process on this Mac, the side that asks, and the counters of what
5
5
  // crossed. A link reads; nothing here writes in another room.
@@ -0,0 +1,147 @@
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+ // MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
3
+ // Where MADRE runs (2026-10-28, docs/private/BIENVENIDA-1.0.6.md). `process.platform` was all MADRE
4
+ // knew of its place, and three real places were not what it assumed: Linux inside Windows (WSL), a
5
+ // virtual machine, and a computer reached from another one over SSH. In each, the browser did not
6
+ // open and nothing said why; a virtual machine ran the local AI slowly without a word. What is read
7
+ // here is what the system says of itself — files, variables, its own tools —, never guessed, and
8
+ // each reading that fails leaves its answer empty rather than wrong. The welcome adapts its steps to
9
+ // it, and the terminal says what to do when the browser cannot be opened from here.
10
+
11
+ import { execFile } from 'node:child_process';
12
+ import { access, readFile, statfs } from 'node:fs/promises';
13
+ import { homedir, userInfo } from 'node:os';
14
+
15
+ const quiet = (command, args, { timeout = 2500, cwd } = {}) => new Promise((resolve) => {
16
+ try { execFile(command, args, { timeout, cwd, windowsHide: true }, (error, stdout) => resolve(error ? null : String(stdout))); } catch { resolve(null); }
17
+ });
18
+ const exists = (file) => access(file).then(() => true, () => false);
19
+ const gb = (bytes) => Math.round((bytes / 1e9) * 10) / 10;
20
+
21
+ // The names a virtual machine gives itself, as the firmware or systemd write them.
22
+ const VM_NAMES = [
23
+ [/virtualbox|innotek/i, 'VirtualBox'], [/vmware/i, 'VMware'], [/parallels/i, 'Parallels'], [/qemu|kvm|bochs/i, 'QEMU/KVM'],
24
+ [/utm/i, 'UTM'], [/xen/i, 'Xen'], [/hyper-v|virtual machine/i, 'Hyper-V'], [/amazon ec2|google compute|droplet|openstack/i, 'Cloud'],
25
+ ];
26
+ const VIRT_WORDS = { oracle: 'VirtualBox', vmware: 'VMware', parallels: 'Parallels', kvm: 'QEMU/KVM', qemu: 'QEMU/KVM', microsoft: 'Hyper-V', xen: 'Xen', bochs: 'QEMU/KVM', amazon: 'Cloud', apple: 'Apple' };
27
+
28
+ export async function detectEnvironment({ platform = process.platform, env = process.env, read = (file) => readFile(file, 'utf8'), run = quiet, has = exists, space = statfs, home = homedir() } = {}) {
29
+ const os = platform === 'darwin' ? 'macos' : platform === 'win32' ? 'windows' : platform === 'linux' ? 'linux' : platform;
30
+ // Linux inside Windows: the kernel says so, and WSL names its distribution.
31
+ let wsl = null;
32
+ if (platform === 'linux') {
33
+ const kernel = await read('/proc/version').catch(() => '');
34
+ if (env.WSL_DISTRO_NAME || /microsoft/i.test(kernel)) wsl = { distro: env.WSL_DISTRO_NAME || null, version: /wsl2|microsoft-standard/i.test(kernel) ? 2 : 1 };
35
+ // Where Windows answers from inside WSL 2 (NAT, the default): the way out of the virtual network,
36
+ // read from the routing table. The nameserver WSL writes was the same address until DNS tunneling
37
+ // (WSL 2.2) made it 10.255.255.254, which is not Windows; it is only the fallback now. The welcome
38
+ // offers this as the address of an Ollama installed in Windows.
39
+ if (wsl) {
40
+ const route = String(await read('/proc/net/route').catch(() => ''));
41
+ const hex = route.split('\n').map((line) => line.trim().split(/\s+/)).find((cols) => cols[1] === '00000000' && /^[0-9A-F]{8}$/i.test(cols[2] ?? '') && cols[2] !== '00000000')?.[2];
42
+ const gateway = hex ? hex.match(/../g).reverse().map((byte) => parseInt(byte, 16)).join('.') : null;
43
+ const nameserver = String(await read('/etc/resolv.conf').catch(() => '')).match(/^nameserver\s+(\d+\.\d+\.\d+\.\d+)\s*$/m)?.[1] ?? null;
44
+ wsl.windowsHost = gateway ?? (nameserver && nameserver !== '10.255.255.254' ? nameserver : null);
45
+ }
46
+ }
47
+ // The system's own name for itself, as a person would read it: «Ubuntu 24.04.1 LTS», «macOS 26.0».
48
+ let name = null;
49
+ if (platform === 'linux') name = String(await read('/etc/os-release').catch(() => '')).match(/^PRETTY_NAME="?([^"\n]+)"?$/m)?.[1] ?? null;
50
+ else if (platform === 'darwin') { const version = (await run('sw_vers', ['-productVersion']))?.trim(); name = version ? `macOS ${version}` : 'macOS'; }
51
+ // Reached from another computer: the variables sshd leaves in every session.
52
+ const pair = String(env.SSH_CONNECTION ?? '').trim().split(/\s+/);
53
+ let user = null;
54
+ try { user = userInfo().username; } catch { /* no user to name */ }
55
+ const ssh = env.SSH_CONNECTION || env.SSH_CLIENT || env.SSH_TTY ? { from: pair[0] || String(env.SSH_CLIENT ?? '').split(/\s+/)[0] || null, host: pair[2] || null, user } : null;
56
+ // A virtual machine, by what systemd or the firmware call it; WSL is not counted as one here.
57
+ let vm = null;
58
+ if (platform === 'linux' && !wsl) {
59
+ const virt = (await run('systemd-detect-virt', ['--vm']))?.trim();
60
+ if (virt && virt !== 'none') vm = VIRT_WORDS[virt] ?? virt;
61
+ else {
62
+ const firmware = `${await read('/sys/class/dmi/id/product_name').catch(() => '')} ${await read('/sys/class/dmi/id/sys_vendor').catch(() => '')}`;
63
+ vm = VM_NAMES.find(([pattern]) => pattern.test(firmware))?.[1] ?? null;
64
+ }
65
+ } else if (platform === 'darwin') {
66
+ if ((await run('sysctl', ['-n', 'kern.hv_vmm_present']))?.trim() === '1') vm = 'macOS';
67
+ }
68
+ const container = platform === 'linux' && !wsl && (await has('/.dockerenv') || /docker|containerd|kubepods|lxc/.test(await read('/proc/1/cgroup').catch(() => '')));
69
+ // A screen to open a browser on: a Linux without one, or anything reached over SSH, has none here.
70
+ // WSL has Windows' own.
71
+ const display = platform === 'linux' ? Boolean(wsl || env.DISPLAY || env.WAYLAND_DISPLAY) : true;
72
+ const disk = await space(home).then((info) => ({ freeGb: gb(Number(info.bavail) * Number(info.bsize)), totalGb: gb(Number(info.blocks) * Number(info.bsize)) })).catch(() => null);
73
+ // One word for the place, the one that changes most what the person has to do.
74
+ const place = ssh ? 'ssh' : wsl ? 'wsl' : container ? 'container' : vm ? 'vm' : 'local';
75
+ return { os, platform, name, place, wsl, vm, container: Boolean(container), ssh, display: ssh ? false : display, disk };
76
+ }
77
+
78
+ let measured = null;
79
+ // Read once per process for what does not change under a running MADRE; the free space is read again.
80
+ export async function environmentOnce(options) {
81
+ measured ??= detectEnvironment(options).catch(() => null);
82
+ const once = await measured;
83
+ if (!once) return null;
84
+ const disk = await statfs(homedir()).then((info) => ({ freeGb: gb(Number(info.bavail) * Number(info.bsize)), totalGb: gb(Number(info.blocks) * Number(info.bsize)) })).catch(() => once.disk);
85
+ return { ...once, disk };
86
+ }
87
+
88
+ // How this computer opens a page in its browser, or null when it cannot from here: over SSH the
89
+ // browser is on the other computer; a Linux with no screen has none. In WSL, Windows' own browser,
90
+ // by wslview when it is installed or by Windows' `cmd.exe` (run from a Windows folder, which it asks for).
91
+ export function browserWays(environment, { platform = process.platform } = {}) {
92
+ if (environment?.place === 'ssh') return [];
93
+ if (platform === 'darwin') return [{ command: 'open', args: (url) => [url] }];
94
+ if (platform === 'win32') return [{ command: 'cmd', args: (url) => ['/c', 'start', '', url] }];
95
+ if (environment?.wsl) return [
96
+ { command: 'wslview', args: (url) => [url] },
97
+ { command: 'cmd.exe', args: (url) => ['/c', 'start', '', url], cwd: '/mnt/c', windows: true },
98
+ { command: 'explorer.exe', args: (url) => [url], anyExit: true, windows: true },
99
+ ];
100
+ if (environment && !environment.display) return [];
101
+ return [{ command: 'xdg-open', args: (url) => [url] }];
102
+ }
103
+
104
+ // Opens the page, trying each way in turn. Answers whether one of them did: a missing program or one
105
+ // that failed moves on to the next, and none left is said by the caller, in the terminal.
106
+ export async function openBrowser(url, environment, { run = execFile, platform = process.platform } = {}) {
107
+ // A folder, not a page, handed to Windows from WSL goes by its Windows name (\\wsl.localhost\…):
108
+ // its Linux path meant nothing to cmd.exe or explorer.exe. wslpath says it; wslview needs no help.
109
+ let windowsName = null;
110
+ const asWindows = async () => {
111
+ if (windowsName !== null || /^[a-z][a-z0-9+.-]*:\/\//i.test(url)) return windowsName ?? url;
112
+ windowsName = await new Promise((resolve) => {
113
+ try { run('wslpath', ['-w', url], { timeout: 3000 }, (error, stdout) => resolve(error ? url : String(stdout ?? '').trim() || url)); } catch { resolve(url); }
114
+ });
115
+ return windowsName;
116
+ };
117
+ for (const way of browserWays(environment, { platform })) {
118
+ const target = way.windows ? await asWindows() : url;
119
+ const opened = await new Promise((resolve) => {
120
+ try {
121
+ run(way.command, way.args(target), { timeout: 8000, windowsHide: true, ...(way.cwd ? { cwd: way.cwd } : {}) }, (error) => resolve(!error || (way.anyExit && error.code !== 'ENOENT')));
122
+ } catch { resolve(false); }
123
+ });
124
+ if (opened) return true;
125
+ }
126
+ return false;
127
+ }
128
+
129
+ // What the terminal says when no browser opened: where to open MADRE, and over SSH the one command
130
+ // to run on the person's own computer, with this session's own user, address and ports.
131
+ export function tunnelCommand(environment, ports, { user = environment?.ssh?.user, host = environment?.ssh?.host } = {}) {
132
+ const forwards = [...new Set(ports.filter((port) => Number.isInteger(port) && port > 0))].map((port) => `-L ${port}:127.0.0.1:${port}`).join(' ');
133
+ return `ssh ${forwards} ${user ? `${user}@` : ''}${host ?? 'your-server'}`;
134
+ }
135
+ export function browserAdvice(environment, address, { t = (text, vars = {}) => text.replace(/\{(\w+)\}/g, (_, key) => vars[key] ?? '') } = {}) {
136
+ const port = Number(new URL(address).port) || 80;
137
+ if (environment?.place === 'ssh') {
138
+ return [
139
+ t('You are connected to this computer from another one (SSH), so the browser is over there.'),
140
+ t('On your own computer, open another terminal and paste:'),
141
+ ` ${tunnelCommand(environment, [port])}`,
142
+ t('Then open {address} in your browser.', { address }),
143
+ ];
144
+ }
145
+ if (environment?.wsl) return [t('Open this address in your Windows browser:'), ` ${address.replace('127.0.0.1', 'localhost')}`];
146
+ return [t('Open this address in a browser on this computer:'), ` ${address}`];
147
+ }
@@ -1,5 +1,5 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
2
- // MADRE · © 2026 Jossue Alcalá · GNU AGPL v3 with additional terms (Section 7): ADDITIONAL-TERMS.md
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+ // MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
3
3
  import { mkdir, open, readFile, rename, rm, stat, writeFile } from 'node:fs/promises';
4
4
  import { dirname, join } from 'node:path';
5
5
  import { randomUUID } from 'node:crypto';
package/src/exam.mjs CHANGED
@@ -1,5 +1,5 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
2
- // MADRE · © 2026 Jossue Alcalá · GNU AGPL v3 with additional terms (Section 7): ADDITIONAL-TERMS.md
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+ // MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
3
3
  // The three tests that answer "is this room ready to be developed with?"
4
4
  //
5
5
  // The maturity reading counts what the archive is made of. It cannot tell you whether the archive
@@ -1,5 +1,5 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
2
- // MADRE · © 2026 Jossue Alcalá · GNU AGPL v3 with additional terms (Section 7): ADDITIONAL-TERMS.md
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+ // MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
3
3
  import { spawn } from 'node:child_process';
4
4
  import { MODULES, moduleById, describeModules } from './modules/index.mjs';
5
5
  export { gitToplevel, findOnPath } from './modules/helpers.mjs';
@@ -1,5 +1,5 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
2
- // MADRE · © 2026 Jossue Alcalá · GNU AGPL v3 with additional terms (Section 7): ADDITIONAL-TERMS.md
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+ // MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
3
3
  // EYECAT, as the room runs it. The judgement lives in eyecat.mjs; this schedules it, picks who
4
4
  // may answer, and puts what comes back in front of the human.
5
5
  //
package/src/eyecat.mjs CHANGED
@@ -1,5 +1,5 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
2
- // MADRE · © 2026 Jossue Alcalá · GNU AGPL v3 with additional terms (Section 7): ADDITIONAL-TERMS.md
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+ // MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
3
3
  // EYECAT: the watcher that asks whether the room still believes what it wrote down.
4
4
  //
5
5
  // Pure functions here. Nothing in this file talks to a model, reads a file or touches the room;
package/src/file-ops.mjs CHANGED
@@ -1,5 +1,5 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
2
- // MADRE · © 2026 Jossue Alcalá · GNU AGPL v3 with additional terms (Section 7): ADDITIONAL-TERMS.md
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+ // MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
3
3
  // Copying and moving a file, from the human's own hands.
4
4
  //
5
5
  // Everything else in MADRE that writes into a project is an agent under a permission mode. This
package/src/files.mjs CHANGED
@@ -1,5 +1,5 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
2
- // MADRE · © 2026 Jossue Alcalá · GNU AGPL v3 with additional terms (Section 7): ADDITIONAL-TERMS.md
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+ // MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
3
3
  import { createHash, randomUUID } from 'node:crypto';
4
4
  import { mkdir, readdir, readFile, realpath, stat, writeFile } from 'node:fs/promises';
5
5
  import { dirname, extname, join, resolve, sep } from 'node:path';
package/src/github.mjs CHANGED
@@ -1,5 +1,5 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
2
- // MADRE · © 2026 Jossue Alcalá · GNU AGPL v3 with additional terms (Section 7): ADDITIONAL-TERMS.md
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+ // MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
3
3
  // GitHub, as the GITHUB module and its MCP server both speak to it.
4
4
  //
5
5
  // Two ways in, and the order matters. First the `gh` CLI, if this computer has it and it is
package/src/heartbeat.mjs CHANGED
@@ -1,5 +1,5 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
2
- // MADRE · © 2026 Jossue Alcalá · GNU AGPL v3 with additional terms (Section 7): ADDITIONAL-TERMS.md
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+ // MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
3
3
  // «Still in use»: once a day, every copy of MADRE tells madre.run it is on (2026-10-13).
4
4
  //
5
5
  // What goes, and nothing else: a random identifier this copy made for itself once