@jossuealcala/madre 1.1.1 → 1.1.2

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/src/server.mjs CHANGED
@@ -82,9 +82,9 @@ import { applyConfigToEnv, loadConfig as readConfig, updateConfig } from './conf
82
82
  import { Privacy, normalizeTerms, privacySettings } from './privacy.mjs';
83
83
  import { planView, removeMadre, uninstallPlan } from './uninstall.mjs';
84
84
  import { checkForUpdate, detectInstall, updateCommand, releaseUrl, applyCommand, fetchCommand } from './updates.mjs';
85
- import { bootWhatsNew, markSeen, newestNotes, notesFor, whatsNew } from './whats-new.mjs';
85
+ import { INVITE_ANSWERS, bootWhatsNew, cameFromOlder, invitedFor, markInvited, markSeen, newestNotes, notesFor, whatsNew } from './whats-new.mjs';
86
86
  import { answerAsk, tickAsk } from './review-ask.mjs';
87
- import { CHAPTERS, HINTS, NEWS_LEVEL, TOUR_VERSION, cameBefore, changeTour, readTour, recoverProject, roomsWithoutProject } from './tour.mjs';
87
+ import { CHAPTERS, HINTS, NEWS_LEVEL, TOUR_VERSION, WELCOME_STEPS, cameBefore, changeTour, readTour, recoverProject, roomsWithoutProject } from './tour.mjs';
88
88
 
89
89
  // Where a person reads the module contract, in the language the room is speaking.
90
90
  const SDK_PAGE = { es: 'https://madre.run/sdk/', en: 'https://madre.run/en/sdk/' };
@@ -134,9 +134,10 @@ import { forgetFromMarket, installFromMarket, installedFromMarket, keptCatalog,
134
134
  const NOT_BY_PROJECT = new Set(['bishop', 'git-pulse', 'ollama']);
135
135
  import { heartbeat, installId } from './heartbeat.mjs';
136
136
  import { PRESENCE_EVERY_MS, environmentGauges, noteLifecycle, sayPresent } from './install-metrics.mjs';
137
+ import { keepHistory, readGithub, readHistory, readNpm, rumboModel } from './rumbo.mjs';
137
138
  import { TERMS_LINKS, acceptTerms, cameFromBefore, readTerms } from './terms.mjs';
138
139
  import { activateLicense, licensedIds, releaseLicense } from './market-license.mjs';
139
- import { askRoom, associateProject, createProject, defaultProjectsFolder, ensureSalasProject, forgetProject, isSalasRoom, knownRooms, listFolders, markProject, projectRoomId, roomComesUp, salasRoomId, startRoom, suggestProjects, universeOf } from './salas.mjs';
140
+ import { askRoom, associateProject, createProject, createSampleProject, defaultProjectsFolder, ensureSalasProject, forgetProject, isSalasRoom, knownRooms, listFolders, markProject, projectRoomId, roomComesUp, salasRoomId, startRoom, suggestProjects, universeOf } from './salas.mjs';
140
141
  import { parseWork, recentWork, WORK_SYSTEM, workPrompt } from './lobby-work.mjs';
141
142
  import { CHANNEL_HEADER, CORPUS_MAX, CORPUS_PER_HOUR, DELIVER_MAX, MAX_LIMIT as ENLACE_MAX_LIMIT, NO_SUCH_LINK, NOTICES as ENLACE_NOTICES, activeContracts, allowContract, askCorpus, askEnlace, askState, channelKey, countRecent, decideDelivery, deliverable, deliverNotes, deliversTo, linkTraffic, mayServe, noteCrossing, noticeEnlace, readInbox, readsFrom, recallContract, receiveDelivery, revokeContract, sameKey, servingRooms, signContract, trainContract } from './enlaces.mjs';
142
143
  import { readContinuity } from './modules/ahp.mjs';
@@ -153,7 +154,11 @@ const publicDirectory = join(sourceDirectory, '..', 'public');
153
154
  // a client does not take gzip.
154
155
  const assetCache = new Map();
155
156
  async function sendAsset(request, response, file, type) {
156
- const info = await stat(file);
157
+ // Its callers `return sendAsset(…)` without awaiting it, which is outside the handler's try: a file
158
+ // that is not there was an unhandled rejection and a request that never got an answer
159
+ // (diagnostics of 1.1.1, «stat … ENOENT» from sendAsset). It is a 404.
160
+ const info = await stat(file).catch(() => null);
161
+ if (!info?.isFile()) { response.writeHead(404, { 'content-type': 'text/plain; charset=utf-8' }); return response.end('Not found.'); }
157
162
  const tag = `W/"${info.size.toString(36)}-${Math.floor(info.mtimeMs).toString(36)}"`;
158
163
  const headers = { 'content-type': type, 'cache-control': 'no-cache', etag: tag, vary: 'accept-encoding' };
159
164
  if (request.headers['if-none-match'] === tag) { response.writeHead(304, headers); return response.end(); }
@@ -532,6 +537,9 @@ export async function createPulseServer({
532
537
  const widgetReadings = new Map();
533
538
  // This copy's identifier once left out of the author's usage figures (the usage widget, below).
534
539
  const usageExcluded = new Set();
540
+ // The three sources of the author's course (kind «rumbo», below), each with its last good reading.
541
+ const rumboSources = new Map();
542
+ let rumboStatus = 0;
535
543
  let cpuSeen = null;
536
544
  const cpuTimes = () => cpus().reduce((sum, one) => {
537
545
  const times = one.times;
@@ -639,6 +647,34 @@ export async function createPulseServer({
639
647
  reading = body?.ok ? { available: true, ...body } : { available: false, status: answer?.status ?? 0 };
640
648
  widgetReadings.set('metrics', { at: Date.now(), reading });
641
649
  return reading;
650
+ } else if (kind === 'rumbo') {
651
+ // MADRE's course (src/rumbo.mjs, 2026-11-01): the author's model of the variables that decide
652
+ // where the project goes, from madre.run's funnel, GitHub and npm. Each source keeps its own
653
+ // clock — the funnel a minute, GitHub ten (its visits move by the hour), npm thirty (by the
654
+ // day) — and a source that fails keeps its last good reading, said as old.
655
+ const token = FROM_SOURCE ? await readSecret(root, OWNER_VAULT, 'usage') : null;
656
+ if (!token) return null;
657
+ const source = async (name, ttl, read) => {
658
+ const kept = rumboSources.get(name);
659
+ if (kept && Date.now() - (kept.tried ?? kept.at) < ttl) return kept;
660
+ const value = await read().catch(() => null);
661
+ const next = value ? { at: Date.now(), value } : { ...(kept ?? { at: null, value: null }), tried: Date.now(), failed: true };
662
+ rumboSources.set(name, next);
663
+ return next;
664
+ };
665
+ const funnel = await source('madre', 60000, async () => {
666
+ const answer = await reportFetch(process.env.PULSE_RUMBO_URL ?? 'https://madre.run/api/rumbo', { headers: { authorization: `Bearer ${token}` }, signal: AbortSignal.timeout(10000) }).catch(() => null);
667
+ rumboStatus = answer?.status ?? 0;
668
+ const body = answer?.ok ? await answer.json().catch(() => null) : null;
669
+ return body?.ok ? body : null;
670
+ });
671
+ const github = await source('github', 600000, () => readGithub());
672
+ const npm = await source('npm', 1800000, () => readNpm({ name: PACKAGE.name ?? '@jossuealcala/madre', fetchImpl: reportFetch }));
673
+ const history = github.value && !github.failed && github.at > Date.now() - 1000 ? await keepHistory(root, github.value).catch(() => readHistory(root)) : await readHistory(root);
674
+ const said = (one) => ({ at: one.at ? new Date(one.at).toISOString() : null, failed: Boolean(one.failed) });
675
+ reading = funnel.value || github.value || npm.value
676
+ ? { available: true, ...rumboModel({ madre: funnel.value, github: github.value, npm: npm.value, history }), sources: { madre: { ...said(funnel), status: rumboStatus }, github: said(github), npm: said(npm) } }
677
+ : { available: false, status: rumboStatus };
642
678
  } else if (kind === 'coordinator' && !salasRoom) {
643
679
  // Home's page is served by every project too: the Coordinator's record is its own room's.
644
680
  const coordinator = (await knownRooms(root)).find((one) => one.id === salasRoomId(root));
@@ -1582,10 +1618,20 @@ export async function createPulseServer({
1582
1618
  let unsubscribeModules = () => {};
1583
1619
  // What the anonymous diagnostics count of a room (src/telemetry.mjs): which agent got a turn and at
1584
1620
  // which mode, what ran, what failed to install. Names of MADRE's own parts and numbers, never words.
1621
+ // Whether this project was ever written to, in any of its chats: a mark in its room folder, set the
1622
+ // first time (or found true in the chat that opens, for a project from before the mark).
1623
+ const firstMark = join(roomDir, 'first-message');
1624
+ let firstSaid = await access(firstMark).then(() => true, () => false);
1625
+ if (!firstSaid && historicalEvents.some((one) => one.type === 'message.created' && one.payload?.role === 'user')) {
1626
+ firstSaid = true;
1627
+ await writeFile(firstMark, new Date().toISOString()).catch(() => {});
1628
+ }
1585
1629
  function countForDiagnostics(event) {
1586
1630
  const said = event?.payload ?? {};
1587
1631
  if (event?.ghost) return;
1588
1632
  if (event?.type === 'message.created' && said.role === 'user' && !said.auto) {
1633
+ // The first message a project ever got (2026-11-01): the step the welcome exists to reach.
1634
+ if (!salasRoom && !firstSaid) { firstSaid = true; diagnostics.count('project.first'); void writeFile(firstMark, new Date().toISOString()).catch(() => {}); }
1589
1635
  if (said.target) diagnostics.count(`turn.${said.target}`);
1590
1636
  if (Number.isInteger(said.mode)) diagnostics.count(`mode.${said.mode}`);
1591
1637
  if (said.via) diagnostics.count(`via.${said.via}`);
@@ -1598,7 +1644,9 @@ export async function createPulseServer({
1598
1644
  else if (event?.type === 'copilot.started') diagnostics.count('copilot.on');
1599
1645
  else if (event?.type === 'extension.install.finished') {
1600
1646
  if (said.ok) diagnostics.count(`install.${said.id ?? 'module'}`);
1601
- else if (!said.cancelled) diagnostics.error({ kind: said.model ? 'model' : 'install', where: [said.id, said.trouble].filter(Boolean).join(' · ') || null, message: said.detail ?? 'install failed' });
1647
+ // What was installed and how it failed travel in the message too: madre.run keeps the message and
1648
+ // not `where`, and 10 copies of 1.1.x reported only «exit 1».
1649
+ else if (!said.cancelled) diagnostics.error({ kind: said.model ? 'model' : 'install', where: [said.id, said.trouble].filter(Boolean).join(' · ') || null, message: [said.detail ?? 'install failed', said.id, said.trouble].filter(Boolean).join(' · ') });
1602
1650
  }
1603
1651
  }
1604
1652
  function wireRoom() {
@@ -2081,8 +2129,21 @@ export async function createPulseServer({
2081
2129
  const binary = await findOnPath('ollama');
2082
2130
  if (!binary) return { ok: false, error: t('Ollama is not on this computer yet.') };
2083
2131
  await room.record('extension.install.started', { id: 'ollama', name: 'OLLAMA', command: 'ollama serve', platforms: [], alreadyInstalled: true });
2084
- const child = spawn(binary, ['serve'], { detached: process.platform !== 'win32', windowsHide: true, stdio: 'ignore' });
2085
- child.unref();
2132
+ // A binary this user cannot run (EACCES: an install that stopped halfway, a file of another
2133
+ // user's) is said, not thrown: without a listener the error ended MADRE's process as an
2134
+ // uncaught exception (diagnostics of 1.1.1, 3 copies in WSL).
2135
+ const failed = new Promise((settle) => {
2136
+ const child = spawn(binary, ['serve'], { detached: process.platform !== 'win32', windowsHide: true, stdio: 'ignore' });
2137
+ child.on('error', (error) => settle(error));
2138
+ child.on('spawn', () => settle(null));
2139
+ child.unref();
2140
+ });
2141
+ const refused = await failed;
2142
+ if (refused) {
2143
+ const words = refused.code === 'EACCES' ? t('Ollama is at {path}, but this user cannot run it. Install it again, or give it permission to run.', { path: binary }) : t('Ollama did not start: {error}', { error: refused.message });
2144
+ await room.record('extension.install.finished', { id: 'ollama', name: 'OLLAMA', ok: false, installed: true, detail: refused.code === 'EACCES' ? `cannot run ${binary} (EACCES)` : refused.message, trouble: refused.code === 'EACCES' ? 'permission' : 'unknown', ollama });
2145
+ return { ok: false, error: words };
2146
+ }
2086
2147
  // It answers in a moment or it does not: poll its own port rather than guess.
2087
2148
  let status = ollama;
2088
2149
  for (let attempt = 0; attempt < 20 && !status.running; attempt += 1) {
@@ -2604,6 +2665,7 @@ export async function createPulseServer({
2604
2665
  // Where start.log stood before this try: only what this one wrote is read if it fails.
2605
2666
  const logFrom = await stat(join(root, 'rooms', room.id, 'start.log')).then((info) => info.size, () => 0);
2606
2667
  startRoom({ projectRoot: room.root, roomDir: join(root, 'rooms', room.id) });
2668
+ if (room.id !== salasRoomId(root)) diagnostics.count('project.opened');
2607
2669
  const up = await roomComesUp(root, room.id);
2608
2670
  if (!up) {
2609
2671
  // The commonest reason, said as itself: another MADRE (another Home, `madre start`) already
@@ -2703,8 +2765,15 @@ export async function createPulseServer({
2703
2765
  // A project from nothing: a new folder, named by the person, in the folder they were in.
2704
2766
  if (request.method === 'POST' && url.pathname === '/api/salas/new') {
2705
2767
  const payload = await body(request).catch(() => ({}));
2768
+ // A project to try MADRE with (src/salas.mjs, createSampleProject): from the welcome.
2769
+ if (payload.sample === true) {
2770
+ const sample = await createSampleProject({ home, stateRoot: root, language: payload.language === 'en' ? 'en' : 'es' });
2771
+ if (sample.error) return sendJson(response, 422, { error: t('The project to try MADRE could not be made.'), code: sample.error });
2772
+ diagnostics.count('project.sample');
2773
+ return sendJson(response, 200, { added: [sample] });
2774
+ }
2706
2775
  const made = await createProject({ name: typeof payload.name === 'string' ? payload.name : '', parent: typeof payload.parent === 'string' ? payload.parent : null, home, stateRoot: root });
2707
- if (!made.error) return sendJson(response, 200, { added: [made] });
2776
+ if (!made.error) { diagnostics.count('project.created'); return sendJson(response, 200, { added: [made] }); }
2708
2777
  const said = {
2709
2778
  empty: t('Write a name for the project.'),
2710
2779
  long: t('That name is too long.'),
@@ -2726,6 +2795,7 @@ export async function createPulseServer({
2726
2795
  if (result.error) refused.push({ root: one, error: result.error === 'madre' ? t('That folder is MADRE\'s own.') : result.error === 'outside' ? t('Only folders inside your home folder.') : t('That folder is not there.') });
2727
2796
  else added.push(result);
2728
2797
  }
2798
+ if (added.length) diagnostics.count('project.added', added.length);
2729
2799
  return sendJson(response, added.length ? 200 : 422, { added, refused });
2730
2800
  }
2731
2801
  return sendJson(response, 405, { error: 'method' });
@@ -3703,6 +3773,9 @@ export async function createPulseServer({
3703
3773
  pageErrors.push(now);
3704
3774
  const payload = await body(request).catch(() => ({}));
3705
3775
  const page = ['room', 'home', 'manual', 'phone'].includes(payload.page) ? payload.page : 'room';
3776
+ // The browser's resize notice is not a failure (public/page-errors.js drops it), but a tab
3777
+ // opened before that filter keeps its old script and still sends it: 3 copies of 1.1.1 did.
3778
+ if (/^ResizeObserver loop/.test(String(payload.message ?? ''))) return sendJson(response, 202, { kept: false });
3706
3779
  diagnostics.error({ kind: 'page', where: page, message: String(payload.message ?? '').slice(0, 2000), stack: String(payload.stack ?? '').slice(0, 4000) });
3707
3780
  return sendJson(response, 202, { kept: true });
3708
3781
  }
@@ -4014,6 +4087,25 @@ export async function createPulseServer({
4014
4087
  await markSeen(root, PACKAGE.version);
4015
4088
  return sendJson(response, 200, { seen: PACKAGE.version });
4016
4089
  }
4090
+ // The invitation to a first project (src/whats-new.mjs): due on Home to a copy that came from an
4091
+ // older MADRE and has no project, once per version. Never on a phone. Its answers are counted
4092
+ // with the anonymous diagnostics, and «shown» is what spends it.
4093
+ if (url.pathname === '/api/invite/project') {
4094
+ if (viaPhone) return sendJson(response, 200, { show: false });
4095
+ if (request.method === 'GET') {
4096
+ const projects = (await knownRooms(root)).filter((one) => one.id !== salasRoomId(root)).length;
4097
+ const show = cameFromOlder(novelty, PACKAGE.version) && projects === 0 && (await invitedFor(root)) !== PACKAGE.version;
4098
+ return sendJson(response, 200, { show, version: PACKAGE.version });
4099
+ }
4100
+ if (request.method === 'POST') {
4101
+ const payload = await body(request).catch(() => ({}));
4102
+ if (!INVITE_ANSWERS.includes(payload.answer)) return sendJson(response, 422, { error: 'answer' });
4103
+ if (payload.answer === 'shown') await markInvited(root, PACKAGE.version);
4104
+ diagnostics.count(`invite.project.${payload.answer}`);
4105
+ return sendJson(response, 200, { ok: true });
4106
+ }
4107
+ return sendJson(response, 405, { error: 'method' });
4108
+ }
4017
4109
  // Asking for a star or a review (src/review-ask.mjs): a page in view says so once a minute and
4018
4110
  // hears whether a moment is due; the answer ends the asking or lets that moment pass. A phone
4019
4111
  // is never asked.
@@ -4047,8 +4139,18 @@ export async function createPulseServer({
4047
4139
  }
4048
4140
  if (viaPhone || !fromHere || (request.method === 'POST' && request.headers.origin !== `http://${host}`)) return sendJson(response, 403, { error: t('This is done on the Mac.') });
4049
4141
  if (request.method === 'POST' && url.pathname === '/api/tour') {
4050
- const changed = await changeTour(root, await body(request).catch(() => null));
4142
+ const change = await body(request).catch(() => null);
4143
+ const changed = await changeTour(root, change);
4051
4144
  if (changed.error) return sendJson(response, 422, { error: t('That is not a change to the tour.') });
4145
+ // How far people get in the welcome, and what they leave for later (2026-11-01): 90 of 147
4146
+ // copies never opened a project, and nothing said where they stopped. Step ids, nothing else.
4147
+ const step = change?.welcome;
4148
+ if (step && typeof step === 'object') {
4149
+ if (WELCOME_STEPS.includes(step.at)) diagnostics.count(`welcome.at.${step.at}`);
4150
+ if (WELCOME_STEPS.includes(step.done)) diagnostics.count(`welcome.done.${step.done}`);
4151
+ if (WELCOME_STEPS.includes(step.skipped)) diagnostics.count(`welcome.skip.${step.skipped}`);
4152
+ if (step.finished === true) diagnostics.count('welcome.finished');
4153
+ }
4052
4154
  return sendJson(response, 200, { state: changed });
4053
4155
  }
4054
4156
  if (request.method === 'GET' && url.pathname === '/api/tour/projects') {
package/src/tour.mjs CHANGED
@@ -40,7 +40,7 @@ export const HINTS = ['switch', 'links', 'key4',
40
40
  'home-links', 'home-map', 'home-settings', 'home-add', 'new-add-widgets',
41
41
  'w-system', 'w-servers', 'w-memory', 'w-coordinator', 'w-models', 'w-usage', 'w-agenda',
42
42
  // The author's own widgets (2026-10-30): their first-time card came back on every start, never kept.
43
- 'w-errors', 'w-live', 'w-installs', 'w-environments',
43
+ 'w-errors', 'w-live', 'w-installs', 'w-environments', 'w-rumbo',
44
44
  'touch-settings', 'touch-modules', 'touch-market', 'touch-mother', 'touch-memory', 'touch-crew', 'touch-steps', 'touch-browser', 'touch-tree', 'touch-chats', 'touch-code', 'touch-mcp',
45
45
  'new-copilot', 'new-mcp', 'new-finder', 'new-memory-access', 'new-dots',
46
46
  // 1.0.5: the way in for whoever is new (the box, the agent, the permission; Home's first step),
@@ -65,7 +65,7 @@ const BEFORE = ['1.0'];
65
65
  // ready after `npx madre` — agents, local AI, memory, the first project — in their order. Where the
66
66
  // person is, what they finished and what they left for later are kept here too, so closing the page
67
67
  // halfway brings them back to the same step, from whichever project or port they open next.
68
- export const WELCOME_STEPS = ['hello', 'machine', 'agents', 'ai', 'memory', 'project', 'ready'];
68
+ export const WELCOME_STEPS = ['hello', 'machine', 'agents', 'project', 'ai', 'memory', 'ready'];
69
69
  const freshWelcome = () => ({ at: null, done: [], skipped: [], finished: null });
70
70
  const fresh = (before = null) => ({ version: TOUR_VERSION, path: null, bonjourAt: null, done: [], at: null, closed: false, finished: null, hints: {}, held: null, before, met: null, welcome: freshWelcome() });
71
71
  // A tab that shows the bonjour or the chapters says so every few seconds; another tab that finds it
package/src/whats-new.mjs CHANGED
@@ -388,6 +388,29 @@ export async function bootWhatsNew({ root, version }) {
388
388
  return { seen: returning ? null : version, returning };
389
389
  }
390
390
 
391
+ // A copy that ran an older MADRE before this one (2026-11-01): `novelty` as bootWhatsNew read it at
392
+ // start-up. A first install marks its own version as seen, so only an update makes this true; a copy
393
+ // from before the sheet existed has rooms and no mark, and came from an older one too.
394
+ export const cameFromOlder = (novelty, version) => (novelty?.seen ? compareVersions(version, novelty.seen) > 0 : Boolean(novelty?.returning));
395
+
396
+ // THE INVITATION TO A FIRST PROJECT (2026-11-01): whoever updates and has not added a project is
397
+ // asked once, on Home, to add one — 90 of 147 copies never opened a project. Once per version, in
398
+ // ~/.pulse/invites.json, for every port of this computer.
399
+ const INVITES = 'invites.json';
400
+ export async function invitedFor(root) {
401
+ try {
402
+ const value = JSON.parse(await readFile(join(root, INVITES), 'utf8'))?.project;
403
+ return typeof value === 'string' ? value : null;
404
+ } catch {
405
+ return null;
406
+ }
407
+ }
408
+ export async function markInvited(root, version) {
409
+ await mkdir(root, { recursive: true });
410
+ await writeFile(join(root, INVITES), `${JSON.stringify({ project: version }, null, 2)}\n`);
411
+ }
412
+ export const INVITE_ANSWERS = ['shown', 'picked', 'sample', 'later'];
413
+
391
414
  // `any`: the sheet for this version whether or not it was seen, for when it is asked for.
392
415
  export async function whatsNew({ root, version, returning, any = false }) {
393
416
  const seen = await readSeen(root);