@jossuealcala/madre 1.1.2 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.en.md +40 -1
- package/CHANGELOG.md +40 -1
- package/README.en.md +3 -3
- package/README.md +3 -3
- package/SECURITY.md +11 -6
- package/TRADEMARKS.md +6 -2
- package/bin/madre.mjs +76 -11
- package/docs/REFERENCE.md +16 -10
- package/docs/SDK.md +36 -9
- package/docs/en/REFERENCE.md +12 -8
- package/docs/en/SDK.md +34 -8
- package/docs/en/training/README.md +1 -1
- package/docs/sdk/connector-module.mjs +1 -1
- package/docs/sdk/hello-module.mjs +39 -4
- package/docs/training/README.md +1 -1
- package/docs/training/train.sh +3 -0
- package/habilidades/explicamelo-facil/HABILIDAD.md +19 -0
- package/habilidades/hojas-de-calculo/HABILIDAD.md +18 -0
- package/habilidades/mensajes-a-clientes/HABILIDAD.md +19 -0
- package/habilidades/publicaciones-para-redes/HABILIDAD.md +19 -0
- package/habilidades/resumen-y-pendientes/HABILIDAD.md +18 -0
- package/habilidades/tu-pagina-paso-a-paso/HABILIDAD.md +19 -0
- package/package.json +7 -4
- package/public/activity.js +66 -22
- package/public/app.js +4947 -894
- package/public/assets/brand/OFL-SpaceGrotesk.txt +93 -0
- package/public/assets/brand/SpaceGrotesk-latin-ext.woff2 +0 -0
- package/public/assets/brand/SpaceGrotesk-latin.woff2 +0 -0
- package/public/assets/brand/madre-app-180.png +0 -0
- package/public/assets/brand/madre-app-192.png +0 -0
- package/public/assets/brand/madre-app-512.png +0 -0
- package/public/assets/brand/madre-app.svg +1 -1
- package/public/assets/brand/madre-favicon.svg +1 -1
- package/public/attribution.js +29 -19
- package/public/auto-open.js +102 -0
- package/public/brands.js +36 -19
- package/public/changes.js +63 -0
- package/public/en.js +1085 -102
- package/public/es.js +2940 -1656
- package/public/i18n.js +11 -0
- package/public/index.html +31 -27
- package/public/loader.js +322 -117
- package/public/macroverso.js +57 -355
- package/public/manual-content.js +69 -9
- package/public/manual.js +21 -6
- package/public/market-view.js +298 -84
- package/public/market.js +25 -2
- package/public/mcp-catalog.js +7 -2
- package/public/missions.js +169 -0
- package/public/news-scenes.js +292 -0
- package/public/nostromo-engine.js +935 -654
- package/public/notices.js +78 -0
- package/public/notifications.js +119 -0
- package/public/power.js +1 -1
- package/public/provider-marks.js +170 -0
- package/public/provider-pick.js +147 -0
- package/public/resay.js +4 -0
- package/public/review-ask.js +16 -13
- package/public/routing.js +29 -3
- package/public/salas-mac.css +467 -47
- package/public/salas-mac.html +8 -5
- package/public/salas-mac.js +805 -109
- package/public/salas.css +2 -2
- package/public/salas.html +2 -2
- package/public/salas.js +1 -1
- package/public/starters.js +128 -0
- package/public/styles.css +3036 -340
- package/public/subscription.js +303 -0
- package/public/terms-field.js +170 -0
- package/public/terms.js +117 -19
- package/public/tips.js +158 -0
- package/public/tour-chapters.js +88 -88
- package/public/tour.js +364 -46
- package/public/troubleshooting.js +313 -27
- package/public/welcome-scene.js +446 -0
- package/public/welcome.js +827 -282
- package/src/adapters/claude.mjs +2 -1
- package/src/adapters/codex.mjs +2 -1
- package/src/adapters/cursor.mjs +9 -6
- package/src/adapters/gemini-rest.mjs +236 -0
- package/src/adapters/gemini.mjs +13 -7
- package/src/adapters/grok.mjs +290 -0
- package/src/adapters/madre.mjs +71 -23
- package/src/adapters/opencode.mjs +15 -2
- package/src/adapters/process.mjs +14 -3
- package/src/adapters/steps.mjs +176 -0
- package/src/app-invite.mjs +90 -0
- package/src/auth-probe.mjs +32 -0
- package/src/billing-key.mjs +8 -0
- package/src/billing.mjs +317 -0
- package/src/bridge/policy.mjs +1 -1
- package/src/capabilities.mjs +46 -10
- package/src/chats.mjs +44 -2
- package/src/checkpoint.mjs +119 -1
- package/src/codex-route.mjs +113 -0
- package/src/commands.mjs +5 -2
- package/src/credentials.mjs +46 -8
- package/src/dataset.mjs +18 -7
- package/src/directives.mjs +1 -0
- package/src/event-store.mjs +25 -2
- package/src/extensions.mjs +5 -1
- package/src/ficha.mjs +158 -0
- package/src/files.mjs +36 -2
- package/src/image-studio.mjs +13 -3
- package/src/install-metrics.mjs +9 -3
- package/src/lease.mjs +6 -1
- package/src/looks.mjs +4 -1
- package/src/market-check.mjs +1 -1
- package/src/market-remote.mjs +135 -1
- package/src/mcp/image-server.mjs +59 -90
- package/src/mcp/memory-server.mjs +10 -0
- package/src/memory-tools.mjs +3 -0
- package/src/memory.mjs +29 -4
- package/src/models.mjs +21 -3
- package/src/modules/ahp.mjs +10 -4
- package/src/modules/bishop-exam.mjs +41 -12
- package/src/modules/bishop.mjs +2 -2
- package/src/modules/choices.mjs +12 -10
- package/src/modules/fetch-alone.mjs +7 -0
- package/src/modules/github.mjs +6 -2
- package/src/modules/helpers.mjs +23 -5
- package/src/modules/image-providers.mjs +281 -0
- package/src/modules/image-studio.mjs +106 -39
- package/src/modules/index.mjs +61 -12
- package/src/modules/intents-observe.mjs +3 -1
- package/src/modules/isolated.mjs +160 -0
- package/src/modules/ollama.mjs +35 -6
- package/src/modules/playwright.mjs +78 -20
- package/src/modules/reminders.mjs +42 -2
- package/src/modules/ripley.mjs +2 -1
- package/src/modules/run-alone.mjs +122 -0
- package/src/modules/runs.mjs +11 -8
- package/src/modules/sdk.mjs +10 -3
- package/src/notices-key.mjs +8 -0
- package/src/notices.mjs +185 -0
- package/src/ollama.mjs +57 -15
- package/src/opencode-health.mjs +1 -1
- package/src/outbound.mjs +124 -13
- package/src/quota-sources.mjs +148 -3
- package/src/review-ask.mjs +55 -31
- package/src/room/archivist.mjs +30 -5
- package/src/room/busy.mjs +16 -0
- package/src/room/changes.mjs +79 -0
- package/src/room/control.mjs +36 -6
- package/src/room/economy.mjs +1 -1
- package/src/room/guard.mjs +39 -2
- package/src/room/prompt.mjs +49 -6
- package/src/room/vectors.mjs +7 -1
- package/src/room.mjs +181 -49
- package/src/router.mjs +1 -1
- package/src/runs.mjs +39 -0
- package/src/runtime-detection.mjs +46 -6
- package/src/salas.mjs +181 -18
- package/src/server.mjs +1101 -118
- package/src/service.mjs +116 -0
- package/src/setup-trouble.mjs +20 -1
- package/src/setup.mjs +1 -1
- package/src/skill-check.mjs +269 -0
- package/src/skills-import.mjs +128 -0
- package/src/skills.mjs +502 -0
- package/src/terms.mjs +23 -5
- package/src/tour.mjs +31 -5
- package/src/updates.mjs +47 -4
- package/src/web-preview.mjs +181 -0
- package/src/whats-new.mjs +121 -1
- package/src/rumbo.mjs +0 -337
package/src/checkpoint.mjs
CHANGED
|
@@ -240,6 +240,44 @@ async function checkpointOne(root, { id, label, exclude = [] }) {
|
|
|
240
240
|
return { commit, tree, head, via };
|
|
241
241
|
}
|
|
242
242
|
|
|
243
|
+
// Ignored folders skipped when walking user data (L-5, L-5b).
|
|
244
|
+
const HEAVY = new Set(['node_modules', '.git', '.venv', 'venv', '__pycache__', 'dist', 'build', '.next', '.nuxt', 'target', '.cache', '.turbo', 'coverage', '.gradle', 'Pods', 'vendor']);
|
|
245
|
+
|
|
246
|
+
// What exists in light ignored folders (Carlos's `pacientes/`) before a turn begins (L-5b), each file
|
|
247
|
+
// with what identifies it (inode, size, modification time). `complete` is false when the walk stopped
|
|
248
|
+
// at its bounds: then a file missing from the list may still have been there, and nothing may be taken
|
|
249
|
+
// for new (review of 2026-11-06: past 500 files a patient record the agent edited was deleted by UNDO).
|
|
250
|
+
// Nested repositories are left out: their own restore point holds them.
|
|
251
|
+
export async function listIgnored(root, { via = undefined, exclude = [], limit = 5000, budget = 20000 } = {}) {
|
|
252
|
+
const listed = await git(root, ['ls-files', '--others', '--ignored', '--exclude-standard', '--directory', '-z'], { via }).catch(() => '');
|
|
253
|
+
const files = new Map();
|
|
254
|
+
const folders = [];
|
|
255
|
+
const nested = exclude.map((dir) => dir.replace(/\/$/, ''));
|
|
256
|
+
let visits = 0;
|
|
257
|
+
let complete = true;
|
|
258
|
+
const walk = async (path) => {
|
|
259
|
+
if (files.size >= limit || visits >= budget) { complete = false; return; }
|
|
260
|
+
visits += 1;
|
|
261
|
+
const bare = path.replace(/\/$/, '');
|
|
262
|
+
if (HEAVY.has(bare.split('/').pop()) || isForbidden(bare) || nested.some((dir) => bare === dir || bare.startsWith(`${dir}/`))) return;
|
|
263
|
+
const info = await lstat(join(root, bare)).catch(() => null);
|
|
264
|
+
if (info?.isDirectory()) {
|
|
265
|
+
folders.push(bare);
|
|
266
|
+
for (const entry of (await readdir(join(root, bare)).catch(() => [])).sort()) await walk(`${bare}/${entry}`);
|
|
267
|
+
} else if (info?.isFile()) files.set(bare, fileMark(info));
|
|
268
|
+
};
|
|
269
|
+
for (const path of listed.split('\0').filter(Boolean)) await walk(path);
|
|
270
|
+
return { files, folders, complete };
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// What tells one file from another, and a file from itself after a write.
|
|
274
|
+
function fileMark(info) {
|
|
275
|
+
return { ino: info.ino, size: info.size, mtimeMs: info.mtimeMs };
|
|
276
|
+
}
|
|
277
|
+
function sameMark(a, b) {
|
|
278
|
+
return Boolean(a && b) && a.ino === b.ino && a.size === b.size && a.mtimeMs === b.mtimeMs;
|
|
279
|
+
}
|
|
280
|
+
|
|
243
281
|
export async function createCheckpoint(root, { id, label = 'MADRE checkpoint' } = {}) {
|
|
244
282
|
const dirs = await nestedRepos(root);
|
|
245
283
|
const outer = await checkpointOne(root, { id, label, exclude: dirs });
|
|
@@ -249,7 +287,9 @@ export async function createCheckpoint(root, { id, label = 'MADRE checkpoint' }
|
|
|
249
287
|
}
|
|
250
288
|
const controls = [await photographControls(root, outer.via, outer.via ? 'MADRE · ' : '.git/')];
|
|
251
289
|
for (const part of nested) controls.push(await photographControls(join(root, part.dir), part.via, `${part.dir}/.git/`));
|
|
252
|
-
|
|
290
|
+
const createdAt = new Date().toISOString();
|
|
291
|
+
const ignoredBefore = await listIgnored(root, { via: outer.via, exclude: dirs });
|
|
292
|
+
return { id, ...outer, nested, exclude: dirs, controls: controls.filter(Boolean), ignoredExisting: ignoredBefore.files, ignoredComplete: ignoredBefore.complete, createdAt };
|
|
253
293
|
}
|
|
254
294
|
|
|
255
295
|
// After a turn that could write, before git runs again: the repositories' own settings, hooks and
|
|
@@ -289,6 +329,69 @@ async function diffOne(root, before, prefix = '', exclude = []) {
|
|
|
289
329
|
return { files, afterTree: after, stat: prefix && stat ? stat.split('\n').map((line) => (line.startsWith(' ') ? ` ${prefix}${line.trimStart()}` : line)).join('\n') : stat };
|
|
290
330
|
}
|
|
291
331
|
|
|
332
|
+
// What a turn wrote where git does not look (L-5, Carlos's server, 2026-11-04: patient records
|
|
333
|
+
// under an ignored `pacientes/`, and the card said the agent «changed nothing»). A restore point
|
|
334
|
+
// never holds ignored files, so these are named as outside it. Read by modification time from git's
|
|
335
|
+
// own list of what it ignores, without walking what is ignored for its size (dependencies, builds,
|
|
336
|
+
// caches), MADRE's own folders or the .env files the guard already puts back; bounded, because it
|
|
337
|
+
// is a note on the card and not a record.
|
|
338
|
+
// Linux stamps a file with a coarse clock that can run a few milliseconds behind Date.now(): a file
|
|
339
|
+
// written right as the turn began looked older than the turn (CI, 2026-11-09). Its margin is small,
|
|
340
|
+
// and a file that was there before and did not change is told apart afterwards (sortIgnoredWrites).
|
|
341
|
+
const MTIME_SLACK_MS = 50;
|
|
342
|
+
export async function ignoredWrittenSince(root, checkpoint, since, { limit = 500, budget = 20000 } = {}) {
|
|
343
|
+
const listed = await git(root, ['ls-files', '--others', '--ignored', '--exclude-standard', '--directory', '-z'], { via: checkpoint?.via }).catch(() => '');
|
|
344
|
+
const nested = (checkpoint?.exclude ?? []).map((dir) => dir.replace(/\/$/, ''));
|
|
345
|
+
const found = [];
|
|
346
|
+
let visits = 0;
|
|
347
|
+
const walk = async (path) => {
|
|
348
|
+
if (found.length >= limit || visits >= budget) return;
|
|
349
|
+
visits += 1;
|
|
350
|
+
const bare = path.replace(/\/$/, '');
|
|
351
|
+
if (HEAVY.has(bare.split('/').pop()) || isForbidden(bare) || nested.some((dir) => bare === dir || bare.startsWith(`${dir}/`))) return;
|
|
352
|
+
const info = await lstat(join(root, bare)).catch(() => null);
|
|
353
|
+
if (info?.isDirectory()) {
|
|
354
|
+
for (const entry of (await readdir(join(root, bare)).catch(() => [])).sort()) await walk(`${bare}/${entry}`);
|
|
355
|
+
} else if (info?.isFile() && info.mtimeMs >= since - MTIME_SLACK_MS) found.push(bare);
|
|
356
|
+
};
|
|
357
|
+
for (const path of listed.split('\0').filter(Boolean)) await walk(path);
|
|
358
|
+
return found;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// What a turn wrote where git does not look, sorted by what UNDO may do with it (L-5b). `created`:
|
|
362
|
+
// not in the photograph taken before the turn, and that photograph was whole; those, with how each
|
|
363
|
+
// looked when the turn ended, are what UNDO may remove. `modified`: there before and changed.
|
|
364
|
+
// `unknown`: written, but the photograph stopped at its bounds, so it cannot be told new from old,
|
|
365
|
+
// and UNDO leaves it. A file that was there before and is exactly as it was (a future modification
|
|
366
|
+
// time from an unpacked archive) is not reported at all.
|
|
367
|
+
export async function sortIgnoredWrites(root, checkpoint, paths) {
|
|
368
|
+
const existing = checkpoint?.ignoredExisting instanceof Map ? checkpoint.ignoredExisting : new Map();
|
|
369
|
+
const whole = checkpoint?.ignoredComplete === true;
|
|
370
|
+
const since = Date.parse(checkpoint?.createdAt ?? '');
|
|
371
|
+
const created = [];
|
|
372
|
+
const modified = [];
|
|
373
|
+
const unknown = [];
|
|
374
|
+
const marks = new Map();
|
|
375
|
+
for (const path of paths) {
|
|
376
|
+
const info = await lstat(join(root, path)).catch(() => null);
|
|
377
|
+
if (!info?.isFile()) continue;
|
|
378
|
+
const before = existing.get(path);
|
|
379
|
+
if (before) {
|
|
380
|
+
if (!sameMark(before, fileMark(info))) modified.push(path);
|
|
381
|
+
continue;
|
|
382
|
+
}
|
|
383
|
+
// Where the system says when a file was born, one born before the turn is not new, whatever
|
|
384
|
+
// the list says. Where it does not (birthtime 0), the whole photograph is the only word.
|
|
385
|
+
const born = info.birthtimeMs;
|
|
386
|
+
const bornBefore = born > 0 && Number.isFinite(since) && born < since;
|
|
387
|
+
if (whole && !bornBefore) {
|
|
388
|
+
created.push(path);
|
|
389
|
+
marks.set(path, fileMark(info));
|
|
390
|
+
} else unknown.push(path);
|
|
391
|
+
}
|
|
392
|
+
return { created, modified, unknown, marks };
|
|
393
|
+
}
|
|
394
|
+
|
|
292
395
|
// What changed since the checkpoint, in the project and in every nested repository, paths
|
|
293
396
|
// relative to the project. Forbidden zones are judged on the path inside each repository too.
|
|
294
397
|
export async function diffCheckpoint(root, checkpoint) {
|
|
@@ -353,6 +456,21 @@ export async function restoreCheckpoint(root, checkpoint, { paths = null } = {})
|
|
|
353
456
|
restored.push(file.path);
|
|
354
457
|
}
|
|
355
458
|
}
|
|
459
|
+
// When restoring the full checkpoint on UNDO (paths === null), also remove the files the turn
|
|
460
|
+
// created in light ignored folders (e.g. Carlos's pacientes/) (L-5b), but only each one still as
|
|
461
|
+
// the turn left it: one written again since (by the person, by another turn) is theirs now and stays.
|
|
462
|
+
if (!paths && Array.isArray(checkpoint?.ignoredCreated)) {
|
|
463
|
+
const marks = checkpoint.ignoredCreatedMarks instanceof Map ? checkpoint.ignoredCreatedMarks : new Map();
|
|
464
|
+
for (const path of checkpoint.ignoredCreated) {
|
|
465
|
+
const absolute = resolve(root, path);
|
|
466
|
+
if (!absolute.startsWith(canonicalRoot + sep)) continue;
|
|
467
|
+
if (isForbidden(path)) continue;
|
|
468
|
+
const info = await lstat(absolute).catch(() => null);
|
|
469
|
+
if (!info?.isFile() || !sameMark(marks.get(path), fileMark(info))) continue;
|
|
470
|
+
const done = await unlink(absolute).then(() => true, () => false);
|
|
471
|
+
if (done) removed.push(path);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
356
474
|
await dropFoldersBornAfter(root, removed, Date.parse(checkpoint.createdAt));
|
|
357
475
|
return { removed, restored };
|
|
358
476
|
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
3
|
+
import { readFile } from 'node:fs/promises';
|
|
4
|
+
import { homedir } from 'node:os';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { agentRouteFromEnvironment } from './runtime-detection.mjs';
|
|
7
|
+
|
|
8
|
+
// Only the routing fields matter here. Other TOML values can contain credentials, so neither
|
|
9
|
+
// their contents nor the base URL's path, query or user information ever leave this module.
|
|
10
|
+
function tomlString(value) {
|
|
11
|
+
const raw = String(value ?? '').trim();
|
|
12
|
+
if (raw.startsWith('"')) {
|
|
13
|
+
const match = raw.match(/^"(?:\\.|[^"\\])*"/);
|
|
14
|
+
if (!match) return null;
|
|
15
|
+
try { return JSON.parse(match[0]); } catch { return null; }
|
|
16
|
+
}
|
|
17
|
+
if (raw.startsWith("'")) return raw.match(/^'([^']*)'/)?.[1] ?? null;
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function withoutComment(line) {
|
|
22
|
+
let quote = null;
|
|
23
|
+
let escaped = false;
|
|
24
|
+
for (let i = 0; i < line.length; i++) {
|
|
25
|
+
const char = line[i];
|
|
26
|
+
if (escaped) { escaped = false; continue; }
|
|
27
|
+
if (quote === '"' && char === '\\') { escaped = true; continue; }
|
|
28
|
+
if (char === quote) { quote = null; continue; }
|
|
29
|
+
if (!quote && (char === '"' || char === "'")) { quote = char; continue; }
|
|
30
|
+
if (!quote && char === '#') return line.slice(0, i);
|
|
31
|
+
}
|
|
32
|
+
return line;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function codexConfigDestination(toml) {
|
|
36
|
+
let section = '';
|
|
37
|
+
let provider = 'openai';
|
|
38
|
+
let openaiUrl = null;
|
|
39
|
+
let unknown = false;
|
|
40
|
+
const urls = new Map();
|
|
41
|
+
for (const original of String(toml ?? '').split(/\r?\n/)) {
|
|
42
|
+
const line = withoutComment(original);
|
|
43
|
+
if (!line.trim()) continue;
|
|
44
|
+
const table = line.match(/^\s*\[([^\]]+)\]\s*(?:#.*)?$/);
|
|
45
|
+
if (table) { section = table[1].trim(); continue; }
|
|
46
|
+
const assignment = line.match(/^\s*([A-Za-z_][A-Za-z0-9_.-]*)\s*=\s*(.+)$/);
|
|
47
|
+
const mentionsRoute = /\b(?:model_provider|model_providers|openai_base_url)\b/.test(line);
|
|
48
|
+
if (!assignment) { if (mentionsRoute) unknown = true; continue; }
|
|
49
|
+
const [, key, value] = assignment;
|
|
50
|
+
let handled = false;
|
|
51
|
+
if (!section && key === 'model_provider') {
|
|
52
|
+
handled = true;
|
|
53
|
+
const parsed = tomlString(value);
|
|
54
|
+
if (parsed) provider = parsed; else unknown = true;
|
|
55
|
+
} else if (!section && key === 'openai_base_url') {
|
|
56
|
+
handled = true;
|
|
57
|
+
openaiUrl = tomlString(value);
|
|
58
|
+
if (!openaiUrl) unknown = true;
|
|
59
|
+
} else if (!section && key === 'model_providers') {
|
|
60
|
+
handled = true;
|
|
61
|
+
// An inline table could select another base URL. Hold it until it can be inspected.
|
|
62
|
+
unknown = true;
|
|
63
|
+
} else {
|
|
64
|
+
const dotted = !section && key.match(/^model_providers\.([A-Za-z0-9_-]+)\.base_url$/);
|
|
65
|
+
const tableProvider = section.match(/^model_providers\.(?:"([^"]+)"|'([^']+)'|([A-Za-z0-9_-]+))$/);
|
|
66
|
+
if ((dotted || tableProvider) && (dotted || key === 'base_url')) {
|
|
67
|
+
handled = true;
|
|
68
|
+
const parsed = tomlString(value);
|
|
69
|
+
if (parsed) urls.set(dotted?.[1] ?? tableProvider?.[1] ?? tableProvider?.[2] ?? tableProvider?.[3], parsed);
|
|
70
|
+
else unknown = true;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (!handled && mentionsRoute) unknown = true;
|
|
74
|
+
}
|
|
75
|
+
if (unknown) return { source: 'Codex config.toml', url: null, unknown: true };
|
|
76
|
+
if (provider !== 'openai') return { source: 'Codex config.toml', url: urls.get(provider) ?? null, unknown: !urls.has(provider) };
|
|
77
|
+
return openaiUrl ? { source: 'Codex config.toml', url: openaiUrl, unknown: false } : null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function routeForUrl(url, source, env) {
|
|
81
|
+
let parsed = null;
|
|
82
|
+
try { parsed = new URL(url); } catch { /* An invalid override is not an official destination. */ }
|
|
83
|
+
const host = parsed?.hostname.toLowerCase() ?? null;
|
|
84
|
+
const official = parsed?.protocol === 'https:'
|
|
85
|
+
&& (!parsed.port || parsed.port === '443')
|
|
86
|
+
&& !parsed.username && !parsed.password
|
|
87
|
+
&& (host === 'api.openai.com' || host?.endsWith('.api.openai.com'));
|
|
88
|
+
if (official) return { kind: 'official', destination: 'OpenAI', source, host, custom: false, allowed: true };
|
|
89
|
+
// Let the existing route rule decide whether the person explicitly trusted Codex.
|
|
90
|
+
const allowed = Boolean(host) && agentRouteFromEnvironment('codex', { ...env, OPENAI_BASE_URL: 'not-a-url' }).allowed;
|
|
91
|
+
return { kind: 'custom', destination: host ? `custom endpoint · ${host}` : 'custom endpoint', source, host, custom: true, allowed };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Recheck at dispatch, not just at room startup: the user can edit config.toml while MADRE is open.
|
|
95
|
+
// A missing file means the CLI's default; a file we cannot inspect never counts as official.
|
|
96
|
+
export async function codexRoute({ env = process.env } = {}) {
|
|
97
|
+
const environmentRoute = agentRouteFromEnvironment('codex', env);
|
|
98
|
+
const rawEnvironmentUrl = String(env.OPENAI_BASE_URL ?? '').trim();
|
|
99
|
+
if (rawEnvironmentUrl) {
|
|
100
|
+
const checked = routeForUrl(rawEnvironmentUrl, 'OPENAI_BASE_URL', env);
|
|
101
|
+
if (checked.custom) return checked;
|
|
102
|
+
}
|
|
103
|
+
const home = env.CODEX_HOME || join(homedir(), '.codex');
|
|
104
|
+
let config;
|
|
105
|
+
try { config = await readFile(join(home, 'config.toml'), 'utf8'); }
|
|
106
|
+
catch (error) {
|
|
107
|
+
if (error?.code === 'ENOENT') return environmentRoute;
|
|
108
|
+
return routeForUrl(null, 'Codex config.toml', env);
|
|
109
|
+
}
|
|
110
|
+
const destination = codexConfigDestination(config);
|
|
111
|
+
if (!destination) return environmentRoute;
|
|
112
|
+
return routeForUrl(destination.url, destination.source, env);
|
|
113
|
+
}
|
package/src/commands.mjs
CHANGED
|
@@ -33,7 +33,8 @@ export const COMMANDS = [
|
|
|
33
33
|
return exists(join(projectRoot, '.git'));
|
|
34
34
|
},
|
|
35
35
|
async execute({ projectRoot, args }) {
|
|
36
|
-
|
|
36
|
+
// Said in Spanish too (2026-11-11): «/git estado», «/git guardar "…"», «/git subir confirmar».
|
|
37
|
+
const what = GIT_WORDS[(args[0] ?? 'status').toLowerCase()] ?? (args[0] ?? 'status').toLowerCase();
|
|
37
38
|
const sections = [];
|
|
38
39
|
const add = async (title, gitArgs) => {
|
|
39
40
|
const result = await run('git', gitArgs, projectRoot);
|
|
@@ -73,7 +74,7 @@ export const COMMANDS = [
|
|
|
73
74
|
const ahead = await run('git', ['-c', 'color.ui=never', 'log', '--oneline', '@{u}..HEAD'], projectRoot);
|
|
74
75
|
const commits = ahead.text ? ahead.text.split('\n').filter(Boolean) : [];
|
|
75
76
|
if (!commits.length) return { ok: true, title: 'Git · push', text: `Nothing to push: ${upstream.text} already has everything.` };
|
|
76
|
-
if ((args[1] ?? '').toLowerCase()
|
|
77
|
+
if (!['confirm', 'confirmar'].includes((args[1] ?? '').toLowerCase())) {
|
|
77
78
|
return { ok: true, title: 'Git · push · preview', text: `## would leave for ${upstream.text}\n${commits.join('\n')}\n\nThis leaves the machine and cannot be undone by MADRE. Send it with: /git push confirm` };
|
|
78
79
|
}
|
|
79
80
|
const pushed = await run('git', ['-c', 'color.ui=never', 'push'], projectRoot, 120000);
|
|
@@ -107,6 +108,8 @@ export const COMMANDS = [
|
|
|
107
108
|
},
|
|
108
109
|
];
|
|
109
110
|
|
|
111
|
+
export const GIT_WORDS = { estado: 'status', historial: 'log', cambios: 'diff', ramas: 'branches', guardar: 'commit', subir: 'push' };
|
|
112
|
+
|
|
110
113
|
export const commandByName = (name) => COMMANDS.find((command) => command.name === String(name ?? '').toLowerCase()) ?? null;
|
|
111
114
|
|
|
112
115
|
export async function listCommands({ projectRoot }) {
|
package/src/credentials.mjs
CHANGED
|
@@ -123,6 +123,7 @@ export function keyPlanFor(id) {
|
|
|
123
123
|
providers: null,
|
|
124
124
|
// The way in, ahead of the Google account: Google refuses free personal accounts on this
|
|
125
125
|
// CLI (IneligibleTierError, 2026-10-17), and a key from AI Studio is what works for anyone.
|
|
126
|
+
// Taken out in 12b400b and put back (review of 2026-11-06): nothing else stood in its place.
|
|
126
127
|
first: true,
|
|
127
128
|
};
|
|
128
129
|
}
|
|
@@ -148,7 +149,11 @@ async function restore(path, previous) {
|
|
|
148
149
|
}
|
|
149
150
|
|
|
150
151
|
// ---- Gemini: a line in ~/.gemini/.env, plus the auth type its settings must select.
|
|
151
|
-
async function applyGeminiKey(key, { home, probe }) {
|
|
152
|
+
async function applyGeminiKey(key, { home, probe, verify = geminiTakesKey }) {
|
|
153
|
+
// Asked of Google first (review of 2026-11-06): without the CLI nothing else checks the key, and
|
|
154
|
+
// any text pasted here read as «connected» until the first turn failed.
|
|
155
|
+
const taken = await verify(key);
|
|
156
|
+
if (taken.ok === false) return { ok: false, error: t('Google did not accept this Gemini key (HTTP {status}): check you copied all of it, or make a new one at aistudio.google.com/app/apikey. Nothing was changed.', { status: taken.status }) };
|
|
152
157
|
const dir = join(home, '.gemini');
|
|
153
158
|
const envFile = join(dir, '.env');
|
|
154
159
|
const settingsFile = join(dir, 'settings.json');
|
|
@@ -177,10 +182,38 @@ async function applyGeminiKey(key, { home, probe }) {
|
|
|
177
182
|
}
|
|
178
183
|
}
|
|
179
184
|
|
|
180
|
-
//
|
|
181
|
-
//
|
|
182
|
-
//
|
|
183
|
-
|
|
185
|
+
// Whether Anthropic takes a key (MR-R92AWX, a copy on Ubuntu over SSH, 2026-11-03): `claude auth
|
|
186
|
+
// status` answers «logged in» for any key it finds, a made-up one too, so MADRE said Claude was
|
|
187
|
+
// connected and the first message failed with «Invalid API key». Listing the models spends no
|
|
188
|
+
// credit. `ok: null` when Anthropic said nothing about the key (offline, its own trouble): that is
|
|
189
|
+
// not the key's fault, and the CLI's status decides as before. A key with no credit left passes
|
|
190
|
+
// here; its first turn says so (MU-059).
|
|
191
|
+
export async function anthropicTakesKey(key, { fetchImpl = globalThis.fetch, base = process.env.PULSE_ANTHROPIC_URL ?? 'https://api.anthropic.com', timeoutMs = 8000 } = {}) {
|
|
192
|
+
try {
|
|
193
|
+
const answer = await fetchImpl(`${base}/v1/models`, { headers: { 'x-api-key': key, 'anthropic-version': '2023-06-01' }, signal: AbortSignal.timeout(timeoutMs) });
|
|
194
|
+
if (answer.ok) return { ok: true };
|
|
195
|
+
return { ok: answer.status === 401 || answer.status === 403 ? false : null, status: answer.status };
|
|
196
|
+
} catch {
|
|
197
|
+
return { ok: null, status: null };
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Whether Google takes a Gemini key: listing one model spends nothing. A bad key is a 400 there
|
|
202
|
+
// (API_KEY_INVALID). `ok: null` when Google said nothing about it (offline, its own trouble).
|
|
203
|
+
export async function geminiTakesKey(key, { fetchImpl = globalThis.fetch, base = process.env.PULSE_GEMINI_API_URL ?? 'https://generativelanguage.googleapis.com', timeoutMs = 8000 } = {}) {
|
|
204
|
+
try {
|
|
205
|
+
const answer = await fetchImpl(`${base.replace(/\/$/, '')}/v1beta/models?pageSize=1`, { headers: { 'x-goog-api-key': key }, signal: AbortSignal.timeout(timeoutMs) });
|
|
206
|
+
if (answer.ok) return { ok: true };
|
|
207
|
+
return { ok: [400, 401, 403].includes(answer.status) ? false : null, status: answer.status };
|
|
208
|
+
} catch {
|
|
209
|
+
return { ok: null, status: null };
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// ---- Claude: `env.ANTHROPIC_API_KEY` in its own settings, confirmed by Anthropic and by
|
|
214
|
+
// `claude auth status`. The CLI reads that env block before it runs, which is why a key there is a
|
|
215
|
+
// session: its own status answers `api_key` afterwards. Everything else in the file is left as it was.
|
|
216
|
+
async function applyClaudeKey(key, { home, probe, verify = anthropicTakesKey }) {
|
|
184
217
|
const dir = join(home, '.claude');
|
|
185
218
|
const file = join(dir, 'settings.json');
|
|
186
219
|
await mkdir(dir, { recursive: true });
|
|
@@ -189,6 +222,11 @@ async function applyClaudeKey(key, { home, probe }) {
|
|
|
189
222
|
let settings = {};
|
|
190
223
|
try { settings = JSON.parse(before ?? '{}') ?? {}; } catch { settings = {}; }
|
|
191
224
|
if (typeof settings !== 'object' || Array.isArray(settings)) settings = {};
|
|
225
|
+
// A Claude pointed at another address (a gateway of its own) takes keys Anthropic never sees.
|
|
226
|
+
if (!(settings.env?.ANTHROPIC_BASE_URL || process.env.ANTHROPIC_BASE_URL)) {
|
|
227
|
+
const taken = await verify(key);
|
|
228
|
+
if (taken.ok === false) return { ok: false, error: t('Anthropic did not accept this key (HTTP {status}): check you copied all of it, or make a new one at console.anthropic.com. Nothing was changed.', { status: taken.status }) };
|
|
229
|
+
}
|
|
192
230
|
settings.env = { ...(settings.env ?? {}), ANTHROPIC_API_KEY: key };
|
|
193
231
|
await writeFile(file, `${JSON.stringify(settings, null, 2)}\n`, { mode: OWNER_ONLY });
|
|
194
232
|
await chmod(file, OWNER_ONLY).catch(() => {});
|
|
@@ -268,12 +306,12 @@ const runOpenCode = async (executable, args) => {
|
|
|
268
306
|
};
|
|
269
307
|
|
|
270
308
|
// Writes the key for one agent and answers whether that agent is signed in now.
|
|
271
|
-
export async function applyKey({ agent, key, provider = null, home = homedir(), probe, executable = null, run = null }) {
|
|
309
|
+
export async function applyKey({ agent, key, provider = null, home = homedir(), probe, executable = null, run = null, verify = anthropicTakesKey, verifyGemini = geminiTakesKey }) {
|
|
272
310
|
const checked = normalizeKey(key);
|
|
273
311
|
if (!checked.ok) return checked;
|
|
274
312
|
if (agent === 'codex') return applyCodexKey(checked.key, { home, probe, executable: executable ?? 'codex', run: run ?? runWithInput });
|
|
275
|
-
if (agent === 'claude') return applyClaudeKey(checked.key, { home, probe });
|
|
276
|
-
if (agent === 'gemini') return applyGeminiKey(checked.key, { home, probe });
|
|
313
|
+
if (agent === 'claude') return applyClaudeKey(checked.key, { home, probe, verify });
|
|
314
|
+
if (agent === 'gemini') return applyGeminiKey(checked.key, { home, probe, verify: verifyGemini });
|
|
277
315
|
if (agent === 'opencode') return applyOpenCodeKey(checked.key, { home, provider, executable: executable ?? 'opencode', run: run ?? runOpenCode });
|
|
278
316
|
return { ok: false, error: t('{agent} does not take a key here: it signs in with a click.', { agent }) };
|
|
279
317
|
}
|
package/src/dataset.mjs
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
import { mkdir, readFile, readdir, rm, writeFile } from 'node:fs/promises';
|
|
11
11
|
import { join } from 'node:path';
|
|
12
12
|
import { redact } from './sentinel-errors.mjs';
|
|
13
|
-
import { ABERRATION, VERDICTS, NEGATIVE_VERDICTS, POSITIVE_VERDICTS, travels } from './memory.mjs';
|
|
13
|
+
import { ABERRATION, VERDICTS, NEGATIVE_VERDICTS, POSITIVE_VERDICTS, travels, unsourced } from './memory.mjs';
|
|
14
14
|
|
|
15
15
|
const MIN_ANSWER_CHARS = 40;
|
|
16
16
|
|
|
@@ -118,7 +118,8 @@ export function pairsFromNotes(notes, { project = 'project', home, user, privacy
|
|
|
118
118
|
messages: [
|
|
119
119
|
{ role: 'system', content: `You are @madre, the memory of the MADRE room of the project "${project}". Answer only from what the room decided and recorded.` },
|
|
120
120
|
{ role: 'user', content: `What does the room remember about this? Kind: ${note.kind}. Topic: ${clean(redact(note.text, { home, user })).split(/[.;:]/)[0].slice(0, 80)}` },
|
|
121
|
-
|
|
121
|
+
// A note with no source is not taught with a citation it does not have (external review #15).
|
|
122
|
+
{ role: 'assistant', content: `${clean(redact(note.text, { home, user }))}${unsourced(note) ? '' : ` [#${note.fromSequence}${note.throughSequence !== note.fromSequence ? `–#${note.throughSequence}` : ''}]`}` },
|
|
122
123
|
],
|
|
123
124
|
}));
|
|
124
125
|
}
|
|
@@ -234,29 +235,39 @@ export function preferencesFromAberrations(notes, { project = 'project', home, u
|
|
|
234
235
|
return pairs;
|
|
235
236
|
}
|
|
236
237
|
|
|
237
|
-
// Deterministic split: the sequence decides, so re-exports keep lines on the same side.
|
|
238
|
+
// Deterministic split: the sequence decides, so re-exports keep lines on the same side. One in ten
|
|
239
|
+
// checks training as it goes (valid); another one in ten is never trained on, for the test after it
|
|
240
|
+
// (RX-30): `mlx_lm.lora --test` reads test.jsonl and stops without it, so train.sh ended in an error
|
|
241
|
+
// after training. A pair that was held out for checking stays where it was.
|
|
238
242
|
export function split(pairs, { validEvery = 10 } = {}) {
|
|
239
243
|
const train = [];
|
|
240
244
|
const valid = [];
|
|
241
|
-
|
|
245
|
+
const test = [];
|
|
246
|
+
const half = Math.floor(validEvery / 2);
|
|
247
|
+
for (const pair of pairs) {
|
|
248
|
+
const at = pair.sequence % validEvery;
|
|
249
|
+
(at === 0 ? valid : at === half ? test : train).push(pair);
|
|
250
|
+
}
|
|
242
251
|
if (!valid.length && train.length > 1) valid.push(train.pop());
|
|
243
|
-
|
|
252
|
+
if (!test.length && train.length > 1) test.push(train.pop());
|
|
253
|
+
return { train, valid, test };
|
|
244
254
|
}
|
|
245
255
|
|
|
246
256
|
export async function exportDataset({ events, notes = [], dir, project = 'project', home, user, privacy = null, linked = [] }) {
|
|
247
257
|
const pairs = [...pairsFromEvents(events, { project, home, user, privacy }), ...pairsFromNotes(notes, { project, home, user, privacy }), ...pairsFromLinked(linked, { home, user, privacy })].sort((a, b) => a.sequence - b.sequence);
|
|
248
258
|
const preferences = preferencesFromAberrations(notes, { project, home, user, privacy });
|
|
249
|
-
const { train, valid } = split(pairs);
|
|
259
|
+
const { train, valid, test } = split(pairs);
|
|
250
260
|
await mkdir(dir, { recursive: true });
|
|
251
261
|
const line = (pair) => JSON.stringify({ messages: pair.messages });
|
|
252
262
|
await writeFile(join(dir, 'train.jsonl'), train.map(line).join('\n') + (train.length ? '\n' : ''));
|
|
253
263
|
await writeFile(join(dir, 'valid.jsonl'), valid.map(line).join('\n') + (valid.length ? '\n' : ''));
|
|
264
|
+
await writeFile(join(dir, 'test.jsonl'), test.map(line).join('\n') + (test.length ? '\n' : ''));
|
|
254
265
|
// Kept in a file of its own: it is a different shape and a different kind of training, and
|
|
255
266
|
// nothing that reads the chat files should ever pick it up by accident.
|
|
256
267
|
await writeFile(join(dir, 'preferences.jsonl'), preferences.map((pair) => JSON.stringify({ prompt: pair.prompt, chosen: pair.chosen, rejected: pair.rejected })).join('\n') + (preferences.length ? '\n' : ''));
|
|
257
268
|
const byAgent = {};
|
|
258
269
|
for (const pair of pairs) byAgent[pair.agent] = (byAgent[pair.agent] ?? 0) + 1;
|
|
259
|
-
const manifest = { project, exportedAt: new Date().toISOString(), pairs: pairs.length, turns: pairs.filter((p) => p.kind === 'turn').length, delegated: pairs.filter((p) => p.kind === 'delegated').length, good: pairs.filter((p) => POSITIVE_VERDICTS.includes(p.rating)).length, notes: pairs.filter((p) => p.kind === 'note').length, linked: (linked ?? []).map((one) => ({ room: one.from, name: one.name, notes: pairs.filter((p) => p.kind === 'linked' && p.from === one.from).length, source: one.source ?? 'live', at: one.at ?? null })), aberrations: preferences.length, train: train.length, valid: valid.length, byAgent, files: ['train.jsonl', 'valid.jsonl', 'preferences.jsonl'], format: 'chat · {"messages":[{role,content}]} · mlx-lm / llama-factory / axolotl', preferenceFormat: 'preference · {"prompt","chosen","rejected"} · DPO / ORPO' };
|
|
270
|
+
const manifest = { project, exportedAt: new Date().toISOString(), pairs: pairs.length, turns: pairs.filter((p) => p.kind === 'turn').length, delegated: pairs.filter((p) => p.kind === 'delegated').length, good: pairs.filter((p) => POSITIVE_VERDICTS.includes(p.rating)).length, notes: pairs.filter((p) => p.kind === 'note').length, linked: (linked ?? []).map((one) => ({ room: one.from, name: one.name, notes: pairs.filter((p) => p.kind === 'linked' && p.from === one.from).length, source: one.source ?? 'live', at: one.at ?? null })), aberrations: preferences.length, train: train.length, valid: valid.length, test: test.length, byAgent, files: ['train.jsonl', 'valid.jsonl', 'test.jsonl', 'preferences.jsonl'], format: 'chat · {"messages":[{role,content}]} · mlx-lm / llama-factory / axolotl', preferenceFormat: 'preference · {"prompt","chosen","rejected"} · DPO / ORPO' };
|
|
260
271
|
await writeFile(join(dir, 'manifest.json'), `${JSON.stringify(manifest, null, 2)}\n`);
|
|
261
272
|
return { dir, ...manifest };
|
|
262
273
|
}
|
package/src/directives.mjs
CHANGED
|
@@ -24,6 +24,7 @@ export const DELEGATION_HELP = (self, others, maxSteps) => [
|
|
|
24
24
|
`@${self}: <what you will do with their answers, optional closing turn for you>`,
|
|
25
25
|
'```',
|
|
26
26
|
'A step may name the mode it needs, "@codex #2: create the page" or "@claude #3: fix the router"; MADRE uses the human permission for this turn as the ceiling. A higher mode pauses for the human to unlock it for that agent, and #4 always does. Without a number a step only reads, or creates files when the plan may create; ask for #3 by name.',
|
|
27
|
+
'Only one agent at a time can hold #3 or #4 in the project: a step that needs one waits until the agent holding it finishes, so give #3 or #4 to as few steps as you can. A step at #1 or #2 cannot run commands: when one must run, give that one step #4, or leave it out of the plan and ask the human for the command in a ```pulse-run block in a later reply.',
|
|
27
28
|
`MADRE runs the steps in order (at most ${maxSteps}), shows every answer in the room, then hands you a closing turn to review progress. If work remains within the human permission, you may end that turn with another pulse plan; at most three waves run from one request.`,
|
|
28
29
|
'The plan block must be the very last thing in your reply: nothing after it, not even a closing sentence. Say everything else before it.',
|
|
29
30
|
'Address each agent once. Do not delegate what you can answer yourself.',
|
package/src/event-store.mjs
CHANGED
|
@@ -27,8 +27,20 @@ function parseLines(text) {
|
|
|
27
27
|
return { events, damaged };
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
// How long a write or a read waits for another to let go of the ledger. It was 500 tries, about
|
|
31
|
+
// ten seconds: on a server with every core taken by local models (Carlos's, L-4, 2026-11-04) a
|
|
32
|
+
// write that fsyncs took longer, and the page's reader gave up with «Timed out waiting for event
|
|
33
|
+
// store lock». Thirty seconds of clock, however slow each try is.
|
|
34
|
+
export const LOCK_WAIT_MS = 30_000;
|
|
35
|
+
// A lock older than any write ever takes was left behind (D-48, 1.1.3, WSL, 2026-11-16): a MADRE
|
|
36
|
+
// that ended abruptly left its lock naming a process number the system later gave to another
|
|
37
|
+
// program, which looked alive forever. A write holds the lock for milliseconds, seconds on a server
|
|
38
|
+
// with every core taken; two minutes is none of them.
|
|
39
|
+
export const STALE_LOCK_MS = 120_000;
|
|
40
|
+
|
|
30
41
|
export class EventStore {
|
|
31
42
|
#file;
|
|
43
|
+
#lockWaitMs;
|
|
32
44
|
#damaged = 0;
|
|
33
45
|
#nextSequence = 1;
|
|
34
46
|
#writeQueue = Promise.resolve();
|
|
@@ -42,8 +54,9 @@ export class EventStore {
|
|
|
42
54
|
// It may be a function, read at every append, when other conversations of the project are
|
|
43
55
|
// writing at the same time as this one: a number fixed when the ledger opened would hand out
|
|
44
56
|
// a sequence another conversation has taken since.
|
|
45
|
-
constructor(file, { floor = 0 } = {}) {
|
|
57
|
+
constructor(file, { floor = 0, lockWaitMs = LOCK_WAIT_MS } = {}) {
|
|
46
58
|
this.#file = file;
|
|
59
|
+
this.#lockWaitMs = lockWaitMs;
|
|
47
60
|
this.#floor = typeof floor === 'function' || Number.isFinite(floor) ? floor : 0;
|
|
48
61
|
this.#lockDirectory = `${file}.lock`;
|
|
49
62
|
}
|
|
@@ -121,7 +134,7 @@ export class EventStore {
|
|
|
121
134
|
async #acquireLock() {
|
|
122
135
|
const token = randomUUID();
|
|
123
136
|
const ownerFile = join(this.#lockDirectory, 'owner.json');
|
|
124
|
-
for (
|
|
137
|
+
for (const deadline = Date.now() + this.#lockWaitMs; Date.now() < deadline;) {
|
|
125
138
|
let created = false;
|
|
126
139
|
try {
|
|
127
140
|
await mkdir(this.#lockDirectory);
|
|
@@ -140,6 +153,9 @@ export class EventStore {
|
|
|
140
153
|
await rm(this.#lockDirectory, { recursive: true, force: true, maxRetries: 6, retryDelay: 60 });
|
|
141
154
|
throw error;
|
|
142
155
|
}
|
|
156
|
+
// The room's own folder was gone (D-34, 1.1.3: «mkdir '….lock'» ENOENT, two copies): the
|
|
157
|
+
// record comes back in a folder made again, instead of every later write failing.
|
|
158
|
+
if (error.code === 'ENOENT') { await mkdir(dirname(this.#lockDirectory), { recursive: true }); continue; }
|
|
143
159
|
if (error.code !== 'EEXIST') throw error;
|
|
144
160
|
try {
|
|
145
161
|
const owner = JSON.parse(await readFile(ownerFile, 'utf8'));
|
|
@@ -151,6 +167,13 @@ export class EventStore {
|
|
|
151
167
|
continue;
|
|
152
168
|
}
|
|
153
169
|
}
|
|
170
|
+
// Its number answers, but it has held the ledger longer than any write does: the number
|
|
171
|
+
// belongs to someone else now (STALE_LOCK_MS).
|
|
172
|
+
const lock = await stat(this.#lockDirectory).catch(() => null);
|
|
173
|
+
if (lock && Date.now() - lock.mtimeMs > STALE_LOCK_MS) {
|
|
174
|
+
await rm(this.#lockDirectory, { recursive: true, force: true, maxRetries: 6, retryDelay: 60 });
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
154
177
|
} catch (ownerError) {
|
|
155
178
|
if (ownerError.code !== 'ENOENT' && !(ownerError instanceof SyntaxError)) throw ownerError;
|
|
156
179
|
const lock = await stat(this.#lockDirectory).catch(() => null);
|
package/src/extensions.mjs
CHANGED
|
@@ -42,7 +42,11 @@ const redrawn = (text) => { const at = text.lastIndexOf(REDRAW); return at < 0 ?
|
|
|
42
42
|
|
|
43
43
|
export function runInstaller({ command, args, projectRoot, onLine, timeoutMs = 600000, heartbeatMs = 8000, env = process.env, stdin = 'ignore', onChild = null, flushIdleMs = 0, ci = true, quietNote = 'installer is quiet (npm install or git status can take a while)' }) {
|
|
44
44
|
return new Promise((resolve) => {
|
|
45
|
-
|
|
45
|
+
// A program that cannot be run at all (ENOEXEC, a file with no interpreter) makes spawn throw at
|
|
46
|
+
// once, inside this promise: it was an unhandledRejection and the install never answered (S-7).
|
|
47
|
+
let child;
|
|
48
|
+
try { child = spawn(command, args, { cwd: projectRoot, env: { ...env, NO_COLOR: '1', ...(ci ? { CI: '1' } : {}) }, stdio: [stdin, 'pipe', 'pipe'], shell: process.platform === 'win32', windowsHide: true }); }
|
|
49
|
+
catch (error) { resolve({ code: 1, error: error.code === 'ENOEXEC' ? `${command} cannot be run on this computer (${error.code}): it is not a program for this system, or it has no interpreter line` : error.message }); return; }
|
|
46
50
|
const started = Date.now();
|
|
47
51
|
let lastOutput = started;
|
|
48
52
|
let buffer = '';
|