@jossuealcala/madre 1.0.4 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ADDITIONAL-TERMS.md +7 -2
- package/CHANGELOG.en.md +152 -1
- package/CHANGELOG.md +152 -1
- package/CONTRIBUTING.md +2 -2
- package/LICENSE +111 -661
- package/NOTICE +59 -24
- package/README.en.md +36 -204
- package/README.md +36 -210
- package/SECURITY.md +1 -0
- package/TRADEMARKS.en.md +13 -14
- package/TRADEMARKS.md +42 -26
- package/bin/madre.cjs +2 -2
- package/bin/madre.mjs +114 -42
- package/docs/REFERENCE.md +53 -6
- package/docs/SDK.md +44 -5
- package/docs/en/REFERENCE.md +53 -6
- package/docs/en/SDK.md +43 -4
- package/docs/madre-banner.png +0 -0
- package/docs/sdk/hello-module.mjs +3 -0
- package/package.json +3 -2
- package/public/abduction.js +6 -6
- package/public/activity.js +425 -0
- package/public/app.js +3519 -647
- package/public/assets/abduction-cat-blink.webp +0 -0
- package/public/assets/abduction-cat-control-left.webp +0 -0
- package/public/assets/abduction-cat-control-right.webp +0 -0
- package/public/assets/abduction-cat.webp +0 -0
- package/public/assets/manual/shots/en-agents.webp +0 -0
- package/public/assets/manual/shots/en-chats.webp +0 -0
- package/public/assets/manual/shots/en-code.webp +0 -0
- package/public/assets/manual/shots/en-composer.webp +0 -0
- package/public/assets/manual/shots/en-connectors.webp +0 -0
- package/public/assets/manual/shots/en-continuity.webp +0 -0
- package/public/assets/manual/shots/en-coordinator.webp +0 -0
- package/public/assets/manual/shots/en-copilot.webp +0 -0
- package/public/assets/manual/shots/en-diagnostics.webp +0 -0
- package/public/assets/manual/shots/en-home.webp +0 -0
- package/public/assets/manual/shots/en-local.webp +0 -0
- package/public/assets/manual/shots/en-market.webp +0 -0
- package/public/assets/manual/shots/en-memory.webp +0 -0
- package/public/assets/manual/shots/en-modes.webp +0 -0
- package/public/assets/manual/shots/en-notes.webp +0 -0
- package/public/assets/manual/shots/en-settings.webp +0 -0
- package/public/assets/manual/shots/en-welcome.webp +0 -0
- package/public/assets/manual/shots/en-windows.webp +0 -0
- package/public/assets/manual/shots/es-agents.webp +0 -0
- package/public/assets/manual/shots/es-chats.webp +0 -0
- package/public/assets/manual/shots/es-code.webp +0 -0
- package/public/assets/manual/shots/es-composer.webp +0 -0
- package/public/assets/manual/shots/es-connectors.webp +0 -0
- package/public/assets/manual/shots/es-continuity.webp +0 -0
- package/public/assets/manual/shots/es-coordinator.webp +0 -0
- package/public/assets/manual/shots/es-copilot.webp +0 -0
- package/public/assets/manual/shots/es-diagnostics.webp +0 -0
- package/public/assets/manual/shots/es-home.webp +0 -0
- package/public/assets/manual/shots/es-local.webp +0 -0
- package/public/assets/manual/shots/es-market.webp +0 -0
- package/public/assets/manual/shots/es-memory.webp +0 -0
- package/public/assets/manual/shots/es-modes.webp +0 -0
- package/public/assets/manual/shots/es-notes.webp +0 -0
- package/public/assets/manual/shots/es-settings.webp +0 -0
- package/public/assets/manual/shots/es-welcome.webp +0 -0
- package/public/assets/manual/shots/es-windows.webp +0 -0
- package/public/assets/news/1.1/en/chats.webp +0 -0
- package/public/assets/news/1.1/en/home.webp +0 -0
- package/public/assets/news/1.1/en/maps.webp +0 -0
- package/public/assets/news/1.1/en/market.webp +0 -0
- package/public/assets/news/1.1/en/permissions.webp +0 -0
- package/public/assets/news/1.1/en/privacy.webp +0 -0
- package/public/assets/news/1.1/en/welcome.webp +0 -0
- package/public/assets/news/1.1/es/chats.webp +0 -0
- package/public/assets/news/1.1/es/home.webp +0 -0
- package/public/assets/news/1.1/es/maps.webp +0 -0
- package/public/assets/news/1.1/es/market.webp +0 -0
- package/public/assets/news/1.1/es/permissions.webp +0 -0
- package/public/assets/news/1.1/es/privacy.webp +0 -0
- package/public/assets/news/1.1/es/welcome.webp +0 -0
- package/public/attribution.js +15 -16
- package/public/brands.js +2 -2
- package/public/code-tools.js +2 -2
- package/public/editor.js +13 -13
- package/public/en.js +483 -0
- package/public/es.js +1817 -598
- package/public/hardware.js +2 -2
- package/public/i18n.js +47 -9
- package/public/icons.js +158 -0
- package/public/index.html +68 -51
- package/public/inquiry.js +2 -2
- package/public/loader.js +271 -2
- package/public/macroverso.js +60 -21
- package/public/manual-content.js +900 -0
- package/public/manual-shots.js +47 -0
- package/public/manual.css +246 -0
- package/public/manual.html +15 -0
- package/public/manual.js +427 -0
- package/public/market-art.js +99 -41
- package/public/market-view.js +243 -47
- package/public/market.js +139 -26
- package/public/mcp-catalog.js +62 -0
- package/public/neural.js +64 -8
- package/public/nostromo-engine.js +709 -40
- package/public/page-errors.js +29 -0
- package/public/power.js +350 -11
- package/public/remedy.js +89 -0
- package/public/resay.js +4 -2
- package/public/review-ask.js +12 -7
- package/public/routing.js +3 -3
- package/public/salas-mac.css +875 -48
- package/public/salas-mac.html +27 -15
- package/public/salas-mac.js +1668 -338
- package/public/salas.css +2 -2
- package/public/salas.html +3 -3
- package/public/salas.js +3 -3
- package/public/styles.css +2694 -323
- package/public/syntax.js +2 -2
- package/public/terms.js +152 -0
- package/public/touch.js +2 -2
- package/public/tour-chapters.js +100 -92
- package/public/tour.js +118 -28
- package/public/troubleshooting.js +327 -21
- package/public/wallpaper.js +4 -3
- package/public/welcome.js +923 -0
- package/src/activity.mjs +85 -0
- package/src/adapters/claude.mjs +61 -35
- package/src/adapters/codex.mjs +18 -5
- package/src/adapters/cursor.mjs +60 -9
- package/src/adapters/gemini.mjs +17 -4
- package/src/adapters/madre.mjs +30 -9
- package/src/adapters/opencode.mjs +73 -10
- package/src/adapters/process.mjs +19 -15
- package/src/adapters/subagents.mjs +159 -0
- package/src/asking.mjs +8 -2
- package/src/auth-probe.mjs +47 -11
- package/src/bridge/devices.mjs +2 -2
- package/src/bridge/handoff.mjs +2 -2
- package/src/bridge/host.mjs +2 -2
- package/src/bridge/network.mjs +2 -2
- package/src/bridge/policy.mjs +3 -3
- package/src/bridge/qr.mjs +2 -2
- package/src/bridge/server.mjs +3 -3
- package/src/builtin-updates.mjs +87 -0
- package/src/capabilities.mjs +5 -5
- package/src/chats.mjs +51 -2
- package/src/checkpoint.mjs +67 -9
- package/src/choices.mjs +2 -2
- package/src/cli-args.mjs +2 -2
- package/src/cold.mjs +2 -2
- package/src/commands.mjs +2 -2
- package/src/config.mjs +2 -2
- package/src/conversation-context.mjs +2 -2
- package/src/credentials.mjs +80 -18
- package/src/dataset.mjs +2 -2
- package/src/directives.mjs +2 -2
- package/src/distiller.mjs +2 -2
- package/src/embeddings.mjs +2 -2
- package/src/enlaces.mjs +2 -2
- package/src/environment.mjs +147 -0
- package/src/event-store.mjs +2 -2
- package/src/exam.mjs +2 -2
- package/src/extensions.mjs +2 -2
- package/src/eyecat-watch.mjs +2 -2
- package/src/eyecat.mjs +2 -2
- package/src/file-ops.mjs +2 -2
- package/src/files.mjs +2 -2
- package/src/github.mjs +2 -2
- package/src/heartbeat.mjs +2 -2
- package/src/history.mjs +76 -0
- package/src/i18n.mjs +32 -3
- package/src/image-studio.mjs +2 -2
- package/src/install-metrics.mjs +109 -0
- package/src/json-file.mjs +2 -2
- package/src/launch.mjs +2 -2
- package/src/lease.mjs +15 -4
- package/src/lobby-work.mjs +11 -4
- package/src/local-ai.mjs +12 -4
- package/src/looks.mjs +19 -7
- package/src/market-check.mjs +165 -0
- package/src/market-key.mjs +10 -2
- package/src/market-license.mjs +104 -0
- package/src/market-remote.mjs +71 -13
- package/src/maturity.mjs +2 -2
- package/src/mcp/connect.mjs +2 -2
- package/src/mcp/github-server.mjs +2 -2
- package/src/mcp/image-server.mjs +2 -2
- package/src/mcp/memory-server.mjs +2 -2
- package/src/mcp/proxy.mjs +16 -5
- package/src/mcp/smtp-server.mjs +2 -2
- package/src/memory-dashboard.mjs +2 -2
- package/src/memory-tools.mjs +2 -2
- package/src/memory.mjs +2 -2
- package/src/models.mjs +115 -12
- package/src/module-scope.mjs +2 -2
- package/src/modules/ahp.mjs +2 -2
- package/src/modules/ash-policy.mjs +2 -2
- package/src/modules/ash.mjs +2 -2
- package/src/modules/bishop-exam.mjs +2 -2
- package/src/modules/bishop-plan.mjs +2 -2
- package/src/modules/bishop.mjs +9 -3
- package/src/modules/choices.mjs +2 -2
- package/src/modules/correo.mjs +2 -2
- package/src/modules/enlaces.mjs +2 -2
- package/src/modules/git-pulse.mjs +2 -2
- package/src/modules/github.mjs +2 -2
- package/src/modules/helpers.mjs +2 -2
- package/src/modules/image-studio.mjs +2 -2
- package/src/modules/index.mjs +92 -5
- package/src/modules/intents-calibration.mjs +2 -2
- package/src/modules/intents-desk.mjs +4 -3
- package/src/modules/intents-observe.mjs +2 -2
- package/src/modules/intents-policy.mjs +2 -2
- package/src/modules/intents-try.mjs +2 -2
- package/src/modules/intents.mjs +2 -2
- package/src/modules/local-models.mjs +41 -10
- package/src/modules/mcp-connect.mjs +2 -2
- package/src/modules/notes.mjs +281 -0
- package/src/modules/ollama.mjs +48 -13
- package/src/modules/playwright.mjs +16 -5
- package/src/modules/reminders.mjs +664 -0
- package/src/modules/ripley.mjs +3 -3
- package/src/modules/runs.mjs +2 -2
- package/src/modules/sdk.mjs +57 -9
- package/src/modules/updates.mjs +2 -2
- package/src/mother.mjs +13 -3
- package/src/npm-launch.mjs +2 -2
- package/src/ollama.mjs +8 -6
- package/src/opencode-health.mjs +83 -0
- package/src/outbound.mjs +35 -3
- package/src/override.mjs +27 -22
- package/src/ports.mjs +2 -2
- package/src/prices.mjs +2 -2
- package/src/privacy.mjs +2 -2
- package/src/quota-monitor.mjs +2 -2
- package/src/quota-sources.mjs +2 -2
- package/src/request-guard.mjs +2 -2
- package/src/review-ask.mjs +4 -3
- package/src/room/archivist.mjs +2 -2
- package/src/room/attachments.mjs +2 -2
- package/src/room/budget.mjs +2 -2
- package/src/room/context.mjs +2 -2
- package/src/room/control.mjs +2 -2
- package/src/room/copilot.mjs +2 -2
- package/src/room/economy.mjs +2 -2
- package/src/room/escalation.mjs +2 -2
- package/src/room/ghost.mjs +2 -2
- package/src/room/guard.mjs +6 -4
- package/src/room/prompt.mjs +3 -3
- package/src/room/returns.mjs +2 -2
- package/src/room/runs.mjs +6 -4
- package/src/room/vectors.mjs +2 -2
- package/src/room.mjs +144 -36
- package/src/router.mjs +2 -2
- package/src/runs.mjs +2 -2
- package/src/runtime-detection.mjs +36 -6
- package/src/salas.mjs +31 -6
- package/src/sentinel-errors.mjs +17 -7
- package/src/server-sentinel.mjs +2 -2
- package/src/server.mjs +980 -139
- package/src/setup-trouble.mjs +33 -0
- package/src/setup.mjs +4 -4
- package/src/smtp.mjs +2 -2
- package/src/telemetry.mjs +266 -0
- package/src/terms.mjs +43 -0
- package/src/tour.mjs +60 -7
- package/src/uninstall.mjs +225 -0
- package/src/updates.mjs +2 -2
- package/src/usage-sentinel.mjs +2 -2
- package/src/vault.mjs +2 -2
- package/src/verdict.mjs +13 -10
- package/src/whats-new.mjs +97 -3
- package/public/assets/abduction-cat-blink.png +0 -0
- package/public/assets/abduction-cat-control-left.png +0 -0
- package/public/assets/abduction-cat-control-right.png +0 -0
- package/public/assets/abduction-cat.png +0 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
3
|
+
// MADRE'S OWN MODULES, KEPT UP TO DATE BY THE MARKET (2026-10-25, R-2 of the 1.1 road map).
|
|
4
|
+
//
|
|
5
|
+
// Notes, Reminders and the rest come with MADRE and work from the first day, without internet. A
|
|
6
|
+
// fix to one of them used to wait for a new MADRE on npm. Now the signed catalog can carry a newer
|
|
7
|
+
// file for it (`builtins`, src/market-remote.mjs), and MADRE runs that one instead of its own.
|
|
8
|
+
//
|
|
9
|
+
// Because such a file reaches every MADRE on its own — nobody chose to install it — it must pass
|
|
10
|
+
// more than a Market module does:
|
|
11
|
+
// · the catalog is signed with the Market's key, as always;
|
|
12
|
+
// · the file is the one the catalog pins (sha256), and
|
|
13
|
+
// · the file itself is signed with the FACTORY key (src/market-key.mjs), a second key kept apart
|
|
14
|
+
// from the Market's: whoever got the Market's key could still not replace Reminders anywhere;
|
|
15
|
+
// · it is written for a contract of the SDK this MADRE understands (`sdk`), says it is the same
|
|
16
|
+
// module, and is newer than the one MADRE came with.
|
|
17
|
+
// It is checked again every time it is loaded (src/modules/index.mjs, adoptBuiltinUpdates), and a
|
|
18
|
+
// file that fails to load leaves MADRE's own in place. A catalog that takes a version back
|
|
19
|
+
// (`revoked`) sends MADRE back to its own. Turning off «Look for new versions» does too.
|
|
20
|
+
//
|
|
21
|
+
// ~/.pulse/market/builtin/<id>.mjs the newer file
|
|
22
|
+
// ~/.pulse/market/builtin/builtin.json what each one is: version, sha256, factory signature
|
|
23
|
+
|
|
24
|
+
import { mkdir, rm } from 'node:fs/promises';
|
|
25
|
+
import { join } from 'node:path';
|
|
26
|
+
import { FACTORY_PUBLIC_KEY } from './market-key.mjs';
|
|
27
|
+
import { bytesFrom, fitsVersion, MAX_MODULE, marketNews, readJson, sha256, verifySigned, writeAtomic } from './market-remote.mjs';
|
|
28
|
+
|
|
29
|
+
export const builtinFolder = (stateRoot) => join(stateRoot, 'market', 'builtin');
|
|
30
|
+
const recordFile = (stateRoot) => join(builtinFolder(stateRoot), 'builtin.json');
|
|
31
|
+
export const builtinFile = (stateRoot, id) => join(builtinFolder(stateRoot), `${id}.mjs`);
|
|
32
|
+
export const readBuiltinRecord = async (stateRoot) => (await readJson(recordFile(stateRoot))) ?? {};
|
|
33
|
+
|
|
34
|
+
// «0.2.0» is newer than «0.1.0»; the same version is not.
|
|
35
|
+
export const newer = (have, than) => fitsVersion(have, than) && !fitsVersion(than, have);
|
|
36
|
+
|
|
37
|
+
// What the catalog offers for MADRE's own modules, fetched and kept when it passes. `packaged` is
|
|
38
|
+
// { id: version } of the modules this MADRE came with; `understands(sdk)` says whether a contract
|
|
39
|
+
// is one this MADRE speaks. Answers what changed: updated (with what the author wrote) and taken back.
|
|
40
|
+
export async function updateBuiltins({ stateRoot, catalog, packaged = {}, understands = () => false, fetchImpl = globalThis.fetch, factoryKey = FACTORY_PUBLIC_KEY, names = {}, now = () => new Date() }) {
|
|
41
|
+
if (!catalog || !factoryKey) return { updated: [], revoked: [] };
|
|
42
|
+
const record = await readBuiltinRecord(stateRoot);
|
|
43
|
+
const updated = [];
|
|
44
|
+
const revoked = [];
|
|
45
|
+
await mkdir(builtinFolder(stateRoot), { recursive: true });
|
|
46
|
+
|
|
47
|
+
for (const [id, have] of Object.entries(record)) {
|
|
48
|
+
const taken = (catalog.revoked ?? []).find((one) => one.id === id && (!one.version || one.version === have.version));
|
|
49
|
+
if (!taken) continue;
|
|
50
|
+
await rm(builtinFile(stateRoot, id), { force: true });
|
|
51
|
+
delete record[id];
|
|
52
|
+
revoked.push({ id, name: names[id] ?? id, kind: 'returned', version: have.version, why: taken.why ?? null, at: now().toISOString() });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
for (const entry of catalog.builtins ?? []) {
|
|
56
|
+
const mine = packaged[entry.id];
|
|
57
|
+
if (!mine || !understands(entry.sdk) || !newer(entry.version, mine)) continue;
|
|
58
|
+
if ((catalog.revoked ?? []).some((one) => one.id === entry.id && (!one.version || one.version === entry.version))) continue;
|
|
59
|
+
if (record[entry.id]?.sha256 === entry.file.sha256) continue;
|
|
60
|
+
if (record[entry.id] && !newer(entry.version, record[entry.id].version)) continue;
|
|
61
|
+
try {
|
|
62
|
+
const bytes = await bytesFrom(entry.file.url, { fetchImpl, max: MAX_MODULE });
|
|
63
|
+
if (sha256(bytes) !== entry.file.sha256) continue;
|
|
64
|
+
if (!verifySigned(bytes, entry.file.factory, factoryKey)) continue;
|
|
65
|
+
await writeAtomic(builtinFile(stateRoot, entry.id), bytes);
|
|
66
|
+
const from = record[entry.id]?.version ?? mine;
|
|
67
|
+
record[entry.id] = { version: entry.version, sdk: entry.sdk, sha256: entry.file.sha256, factory: entry.file.factory, at: now().toISOString() };
|
|
68
|
+
updated.push({ id: entry.id, name: names[entry.id] ?? entry.id, from, to: entry.version, changes: entry.changes ?? null, at: now().toISOString() });
|
|
69
|
+
} catch { /* tried again the next time MADRE opens */ }
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (updated.length || revoked.length) {
|
|
73
|
+
await writeAtomic(recordFile(stateRoot), JSON.stringify(record, null, 2));
|
|
74
|
+
// Said once, the way a Market module's update is (market/updates.json): what came, and what
|
|
75
|
+
// went back to the one MADRE came with, and why.
|
|
76
|
+
const told = [...updated, ...revoked];
|
|
77
|
+
const news = [...(await marketNews(stateRoot)).filter((one) => !told.some((fresh) => fresh.id === one.id)), ...told];
|
|
78
|
+
await writeAtomic(join(stateRoot, 'market', 'updates.json'), JSON.stringify(news, null, 2));
|
|
79
|
+
}
|
|
80
|
+
return { updated, revoked };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// The file kept for one of MADRE's own modules, if it is still the one that was signed: its bytes
|
|
84
|
+
// against the sha256 and the factory signature recorded when it came. Anything else is not run.
|
|
85
|
+
export function trustedBytes(bytes, kept, factoryKey = FACTORY_PUBLIC_KEY) {
|
|
86
|
+
return Boolean(bytes && kept && factoryKey && sha256(bytes) === kept.sha256 && verifySigned(bytes, kept.factory, factoryKey));
|
|
87
|
+
}
|
package/src/capabilities.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
2
|
-
// MADRE · © 2026 Jossue Alcalá ·
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
3
3
|
// What each CLI can do from MADRE, verified against the installed versions on
|
|
4
4
|
// 2026-09-16 (Codex 0.153, Claude Code 2.1, Gemini CLI 0.60, OpenCode 1.18).
|
|
5
5
|
// The room shows this so a human knows whom to ask for what, and an
|
|
@@ -35,12 +35,12 @@ export const CAPABILITIES = {
|
|
|
35
35
|
imageGen: false,
|
|
36
36
|
web: { how: 'policy: allow google_web_search, web_fetch', note: 'Off until turned on in Settings › Agents › Web access.' },
|
|
37
37
|
},
|
|
38
|
-
// Cursor
|
|
39
|
-
//
|
|
38
|
+
// Cursor reads in its own ask mode and, from 2026-10-21, writes and runs commands at the modes
|
|
39
|
+
// that allow it (adapters/cursor.mjs). Attachments are named in the briefing.
|
|
40
40
|
cursor: {
|
|
41
41
|
read: true,
|
|
42
42
|
imageIn: false,
|
|
43
|
-
write:
|
|
43
|
+
write: { how: 'agent mode with --force under a configuration made for the turn', note: 'Writes where the turn allows; commands only at #4. MADRE locks and puts back .env, .git and its own folders, and at #2 what existed.' },
|
|
44
44
|
imageGen: false,
|
|
45
45
|
web: false,
|
|
46
46
|
},
|
package/src/chats.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
2
|
-
// MADRE · © 2026 Jossue Alcalá ·
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
3
3
|
// A project has one memory and many conversations.
|
|
4
4
|
//
|
|
5
5
|
// The archive, the crew, the modules and the privacy list belong to the project: they are what
|
|
@@ -230,3 +230,52 @@ export async function projectFloor(roomDir, { except = null } = {}) {
|
|
|
230
230
|
}
|
|
231
231
|
return floor;
|
|
232
232
|
}
|
|
233
|
+
|
|
234
|
+
// SEARCH (2026-10-30): the conversations of a project, by their name and by what was said in them,
|
|
235
|
+
// without regard to accents or capitals, so «envio» finds «Envío». Each record is read from its
|
|
236
|
+
// end, a few megabytes at most: what a person looks for is almost always recent.
|
|
237
|
+
const SEARCH_READ = 4 * 1024 * 1024;
|
|
238
|
+
export const searchWords = (text) => String(text ?? '').normalize('NFD').replace(/[\u0300-\u036f]/g, '').toLowerCase();
|
|
239
|
+
// The end of one record, `bytes` at most, from a whole line on (also «En marcha», src/activity.mjs).
|
|
240
|
+
export async function tailOf(file, bytes = SEARCH_READ) {
|
|
241
|
+
const found = await stat(file).catch(() => null);
|
|
242
|
+
if (!found?.isFile()) return '';
|
|
243
|
+
const start = Math.max(0, found.size - bytes);
|
|
244
|
+
const handle = await open(file, 'r');
|
|
245
|
+
try {
|
|
246
|
+
const buffer = Buffer.alloc(found.size - start);
|
|
247
|
+
await handle.read(buffer, 0, buffer.length, start);
|
|
248
|
+
const text = buffer.toString('utf8');
|
|
249
|
+
return start ? text.slice(text.indexOf('\n') + 1) : text;
|
|
250
|
+
} finally { await handle.close(); }
|
|
251
|
+
}
|
|
252
|
+
function snippetAround(text, at, length) {
|
|
253
|
+
const from = Math.max(0, at - 50);
|
|
254
|
+
const to = Math.min(text.length, at + length + 90);
|
|
255
|
+
return { text: `${from ? '…' : ''}${text.slice(from, to).replace(/\s+/g, ' ')}${to < text.length ? '…' : ''}`, mark: [at - from + (from ? 1 : 0), length] };
|
|
256
|
+
}
|
|
257
|
+
export async function searchChats(roomDir, query, { limit = 40, perChat = 3 } = {}) {
|
|
258
|
+
const wanted = searchWords(query).trim();
|
|
259
|
+
if (wanted.length < 2) return { query: String(query ?? ''), results: [] };
|
|
260
|
+
const { chats } = await listChats(roomDir);
|
|
261
|
+
const results = [];
|
|
262
|
+
for (const chat of chats) {
|
|
263
|
+
const hits = [];
|
|
264
|
+
const titleAt = searchWords(chat.title).indexOf(wanted);
|
|
265
|
+
for (const line of (await tailOf(chatLedger(roomDir, chat.id))).split('\n').reverse()) {
|
|
266
|
+
if (hits.length >= perChat) break;
|
|
267
|
+
if (!line.includes('"message.created"')) continue;
|
|
268
|
+
let event;
|
|
269
|
+
try { event = JSON.parse(line); } catch { continue; }
|
|
270
|
+
const payload = event?.payload ?? {};
|
|
271
|
+
const said = typeof payload.text === 'string' ? payload.text : '';
|
|
272
|
+
const at = searchWords(said).indexOf(wanted);
|
|
273
|
+
if (at < 0) continue;
|
|
274
|
+
hits.push({ messageId: payload.messageId ?? null, sequence: event.sequence ?? null, who: payload.role === 'user' ? 'you' : String(payload.sender ?? ''), at: event.timestamp ?? null, ...snippetAround(said, at, wanted.length) });
|
|
275
|
+
}
|
|
276
|
+
if (titleAt < 0 && !hits.length) continue;
|
|
277
|
+
results.push({ id: chat.id, title: chat.title, updatedAt: chat.updatedAt ?? null, titleMatch: titleAt >= 0, hits });
|
|
278
|
+
if (results.length >= limit) break;
|
|
279
|
+
}
|
|
280
|
+
return { query: String(query ?? ''), results };
|
|
281
|
+
}
|
package/src/checkpoint.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
2
|
-
// MADRE · © 2026 Jossue Alcalá ·
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
3
3
|
import { execFile } from 'node:child_process';
|
|
4
|
-
import {
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
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
|
|
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:
|
|
2
|
-
// MADRE · © 2026 Jossue Alcalá ·
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
3
3
|
// 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:
|
|
2
|
-
// MADRE · © 2026 Jossue Alcalá ·
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
3
3
|
// 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:
|
|
2
|
-
// MADRE · © 2026 Jossue Alcalá ·
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
3
3
|
// 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:
|
|
2
|
-
// MADRE · © 2026 Jossue Alcalá ·
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
3
3
|
import { 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:
|
|
2
|
-
// MADRE · © 2026 Jossue Alcalá ·
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
3
3
|
import { 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:
|
|
2
|
-
// MADRE · © 2026 Jossue Alcalá ·
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
3
3
|
// 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
|
package/src/credentials.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
2
|
-
// MADRE · © 2026 Jossue Alcalá ·
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
3
3
|
// 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
|
|
|
@@ -54,10 +55,32 @@ export async function readOpenCodeCatalog({ home = homedir(), env = process.env
|
|
|
54
55
|
}
|
|
55
56
|
return out;
|
|
56
57
|
}
|
|
58
|
+
// OpenCode writes its catalogue the first time it runs. A person who has just installed it has none
|
|
59
|
+
// yet, and was offered only MADRE's four (2026-10-20): until the catalogue is there, the popular
|
|
60
|
+
// ones a single key opens are offered from this copy of it (models.dev, 2026-10-20), each with the
|
|
61
|
+
// page of its own documentation the catalogue gives.
|
|
62
|
+
export const OPENCODE_BUNDLED = [
|
|
63
|
+
{ id: 'groq', label: 'Groq', docUrl: 'https://console.groq.com/docs/models' },
|
|
64
|
+
{ id: 'deepseek', label: 'DeepSeek', docUrl: 'https://api-docs.deepseek.com/quick_start/pricing' },
|
|
65
|
+
{ id: 'mistral', label: 'Mistral', docUrl: 'https://docs.mistral.ai/getting-started/models/' },
|
|
66
|
+
{ id: 'xai', label: 'xAI', docUrl: 'https://docs.x.ai/docs/models' },
|
|
67
|
+
{ id: 'togetherai', label: 'Together AI', docUrl: 'https://docs.together.ai/docs/serverless-models' },
|
|
68
|
+
{ id: 'fireworks-ai', label: 'Fireworks AI', docUrl: 'https://fireworks.ai/docs/' },
|
|
69
|
+
{ id: 'cerebras', label: 'Cerebras', docUrl: 'https://inference-docs.cerebras.ai/models/overview' },
|
|
70
|
+
{ id: 'perplexity', label: 'Perplexity', docUrl: 'https://docs.perplexity.ai' },
|
|
71
|
+
{ id: 'huggingface', label: 'Hugging Face', docUrl: 'https://huggingface.co/docs/inference-providers' },
|
|
72
|
+
{ id: 'deepinfra', label: 'Deep Infra', docUrl: 'https://deepinfra.com/models' },
|
|
73
|
+
{ id: 'moonshotai', label: 'Moonshot AI', docUrl: 'https://platform.moonshot.ai/docs/api/chat' },
|
|
74
|
+
{ id: 'zai', label: 'Z.AI', docUrl: 'https://docs.z.ai/guides/overview/pricing' },
|
|
75
|
+
{ id: 'cohere', label: 'Cohere', docUrl: 'https://docs.cohere.com/docs/models' },
|
|
76
|
+
{ id: 'vercel', label: 'Vercel AI Gateway', docUrl: null },
|
|
77
|
+
];
|
|
57
78
|
// Every provider a key can be pasted for: MADRE's own four first (their key pages), then the
|
|
58
|
-
// catalogue's, each once, the popular ones
|
|
79
|
+
// catalogue's — or, before OpenCode has written one, the copy above — each once, the popular ones
|
|
80
|
+
// marked.
|
|
59
81
|
export async function openCodeKeyProviders({ home = homedir(), env = process.env } = {}) {
|
|
60
|
-
const
|
|
82
|
+
const read = await readOpenCodeCatalog({ home, env });
|
|
83
|
+
const catalog = read.length ? read : OPENCODE_BUNDLED;
|
|
61
84
|
const byId = new Map(OPENCODE_PROVIDERS.map((one) => [one.id, { ...one, featured: true }]));
|
|
62
85
|
for (const one of catalog) if (!byId.has(one.id)) byId.set(one.id, { id: one.id, label: one.label, keyUrl: one.docUrl, featured: OPENCODE_FEATURED.includes(one.id) });
|
|
63
86
|
const rank = (one) => { const at = OPENCODE_FEATURED.indexOf(one.id); return at < 0 ? Infinity : at; };
|
|
@@ -66,6 +89,18 @@ export async function openCodeKeyProviders({ home = homedir(), env = process.env
|
|
|
66
89
|
|
|
67
90
|
// What the room offers for each agent that cannot be signed in with a click.
|
|
68
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
|
+
}
|
|
69
104
|
if (id === 'claude') {
|
|
70
105
|
return {
|
|
71
106
|
agent: 'claude',
|
|
@@ -132,13 +167,13 @@ async function applyGeminiKey(key, { home, probe }) {
|
|
|
132
167
|
if (state?.state !== 'signed-in') {
|
|
133
168
|
await restore(envFile, beforeEnv);
|
|
134
169
|
await restore(settingsFile, beforeSettings);
|
|
135
|
-
return { ok: false, error:
|
|
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})` : ''}` }) };
|
|
136
171
|
}
|
|
137
172
|
return { ok: true, detail: state.detail ?? 'via API key' };
|
|
138
173
|
} catch (error) {
|
|
139
174
|
await restore(envFile, beforeEnv);
|
|
140
175
|
await restore(settingsFile, beforeSettings);
|
|
141
|
-
return { ok: false, error:
|
|
176
|
+
return { ok: false, error: t('The key could not be written: {error}', { error: error.message }) };
|
|
142
177
|
}
|
|
143
178
|
}
|
|
144
179
|
|
|
@@ -160,19 +195,45 @@ async function applyClaudeKey(key, { home, probe }) {
|
|
|
160
195
|
const state = await probe();
|
|
161
196
|
if (state?.state !== 'signed-in') {
|
|
162
197
|
await restore(file, before);
|
|
163
|
-
return { ok: false, error:
|
|
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})` : ''}` }) };
|
|
164
199
|
}
|
|
165
200
|
return { ok: true, detail: state.detail ?? 'via API key' };
|
|
166
201
|
} catch (error) {
|
|
167
202
|
await restore(file, before);
|
|
168
|
-
return { ok: false, error:
|
|
203
|
+
return { ok: false, error: t('The key could not be written: {error}', { error: error.message }) };
|
|
169
204
|
}
|
|
170
205
|
}
|
|
171
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
|
+
|
|
172
233
|
// ---- OpenCode: an entry in its auth.json, confirmed by asking `opencode auth list`.
|
|
173
234
|
async function applyOpenCodeKey(key, { home, provider, executable, run }) {
|
|
174
235
|
const known = typeof provider === 'string' ? (await openCodeKeyProviders({ home })).find((item) => item.id === provider) : null;
|
|
175
|
-
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.') };
|
|
176
237
|
const file = join(home, '.local', 'share', 'opencode', 'auth.json');
|
|
177
238
|
await mkdir(join(home, '.local', 'share', 'opencode'), { recursive: true });
|
|
178
239
|
const before = await readIfThere(file);
|
|
@@ -188,12 +249,12 @@ async function applyOpenCodeKey(key, { home, provider, executable, run }) {
|
|
|
188
249
|
const listed = String(await run(executable, ['auth', 'list'])).toLowerCase();
|
|
189
250
|
if (!listed.includes(provider.toLowerCase()) && !listed.includes(String(known.label).toLowerCase())) {
|
|
190
251
|
await restore(file, before);
|
|
191
|
-
return { ok: false, error:
|
|
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 }) };
|
|
192
253
|
}
|
|
193
254
|
return { ok: true, detail: `${provider} (api)` };
|
|
194
255
|
} catch (error) {
|
|
195
256
|
await restore(file, before);
|
|
196
|
-
return { ok: false, error:
|
|
257
|
+
return { ok: false, error: t('The key could not be written: {error}', { error: error.message }) };
|
|
197
258
|
}
|
|
198
259
|
}
|
|
199
260
|
|
|
@@ -207,13 +268,14 @@ const runOpenCode = async (executable, args) => {
|
|
|
207
268
|
};
|
|
208
269
|
|
|
209
270
|
// Writes the key for one agent and answers whether that agent is signed in now.
|
|
210
|
-
export async function applyKey({ agent, key, provider = null, home = homedir(), probe, executable =
|
|
271
|
+
export async function applyKey({ agent, key, provider = null, home = homedir(), probe, executable = null, run = null }) {
|
|
211
272
|
const checked = normalizeKey(key);
|
|
212
273
|
if (!checked.ok) return checked;
|
|
274
|
+
if (agent === 'codex') return applyCodexKey(checked.key, { home, probe, executable: executable ?? 'codex', run: run ?? runWithInput });
|
|
213
275
|
if (agent === 'claude') return applyClaudeKey(checked.key, { home, probe });
|
|
214
276
|
if (agent === 'gemini') return applyGeminiKey(checked.key, { home, probe });
|
|
215
|
-
if (agent === 'opencode') return applyOpenCodeKey(checked.key, { home, provider, executable, run });
|
|
216
|
-
return { ok: false, error:
|
|
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 }) };
|
|
217
279
|
}
|
|
218
280
|
|
|
219
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:
|
|
2
|
-
// MADRE · © 2026 Jossue Alcalá ·
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
3
3
|
// The 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
|
package/src/directives.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
2
|
-
// MADRE · © 2026 Jossue Alcalá ·
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
3
3
|
// 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:
|
|
2
|
-
// MADRE · © 2026 Jossue Alcalá ·
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
3
3
|
// The 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
|
package/src/embeddings.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
2
|
-
// MADRE · © 2026 Jossue Alcalá ·
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
3
3
|
// 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:
|
|
2
|
-
// MADRE · © 2026 Jossue Alcalá ·
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
3
3
|
// 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.
|