@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/CHANGELOG.en.md +22 -1
- package/CHANGELOG.md +22 -1
- package/README.en.md +1 -1
- package/README.md +1 -1
- package/docs/REFERENCE.md +2 -1
- package/docs/en/REFERENCE.md +2 -1
- package/package.json +1 -1
- package/public/app.js +2 -2
- package/public/en.js +1 -1
- package/public/es.js +143 -10
- package/public/manual-content.js +6 -6
- package/public/market.js +13 -2
- package/public/salas-mac.css +69 -0
- package/public/salas-mac.js +306 -1
- package/public/welcome.js +40 -12
- package/src/dataset.mjs +4 -2
- package/src/embeddings.mjs +2 -2
- package/src/file-ops.mjs +9 -3
- package/src/github.mjs +5 -3
- package/src/market-remote.mjs +35 -2
- package/src/mcp/memory-server.mjs +12 -3
- package/src/mcp/proxy.mjs +31 -8
- package/src/memory-tools.mjs +9 -2
- package/src/memory.mjs +16 -0
- package/src/modules/check-alone.mjs +25 -0
- package/src/modules/index.mjs +41 -7
- package/src/mother.mjs +6 -1
- package/src/outbound.mjs +11 -3
- package/src/room/archivist.mjs +7 -1
- package/src/room/context.mjs +6 -3
- package/src/room/copilot.mjs +22 -28
- package/src/room.mjs +4 -4
- package/src/rumbo.mjs +337 -0
- package/src/salas.mjs +103 -1
- package/src/server.mjs +111 -9
- package/src/tour.mjs +2 -2
- package/src/whats-new.mjs +23 -0
package/src/market-remote.mjs
CHANGED
|
@@ -262,12 +262,32 @@ export async function marketAnnounced(stateRoot, keys = []) {
|
|
|
262
262
|
export const marketNews = async (stateRoot) => (await readJson(join(folder(stateRoot), 'updates.json'))) ?? [];
|
|
263
263
|
export async function marketNewsSeen(stateRoot) { await writeAtomic(join(folder(stateRoot), 'updates.json'), '[]').catch(() => {}); }
|
|
264
264
|
|
|
265
|
+
// What a newer file declares that the one the person accepted did not (2026-11-01, external review
|
|
266
|
+
// #10): a place it reaches, a key it asks for, tools for the agents, reading the chats, writing in
|
|
267
|
+
// the project, a command. Empty when it asks for nothing more.
|
|
268
|
+
export function widens(before = {}, after = {}) {
|
|
269
|
+
const more = [];
|
|
270
|
+
const hosts = (said) => new Set((said?.reaches ?? []).map((one) => one.host ?? one.to).filter(Boolean));
|
|
271
|
+
const had = hosts(before);
|
|
272
|
+
for (const host of hosts(after)) if (!had.has(host)) more.push({ what: 'reaches', host });
|
|
273
|
+
const keys = new Set((before?.secrets ?? []).map((one) => one.name));
|
|
274
|
+
for (const secret of after?.secrets ?? []) if (!keys.has(secret.name)) more.push({ what: 'secret', name: secret.label ?? secret.name });
|
|
275
|
+
for (const flag of ['tools', 'reads', 'writes']) if (after?.[flag] && !before?.[flag]) more.push({ what: flag });
|
|
276
|
+
const commands = new Set(before?.commands ?? []);
|
|
277
|
+
for (const command of after?.commands ?? []) if (!commands.has(command)) more.push({ what: 'command', name: command });
|
|
278
|
+
return more;
|
|
279
|
+
}
|
|
280
|
+
|
|
265
281
|
// Every module got from the Market whose signed file changed: the new one, installed, and a line
|
|
266
|
-
// for the person. One that fails stays as it was and is tried again next time.
|
|
282
|
+
// for the person. One that fails stays as it was and is tried again next time. One that declares
|
|
283
|
+
// more than the file the person accepted is not installed on its own: it waits, and the person is
|
|
284
|
+
// told once what it asks for (`held`), because accepting a module once is not accepting whatever
|
|
285
|
+
// it becomes.
|
|
267
286
|
export async function updateFromMarket({ stateRoot, projectRoot, catalog, madre, fetchImpl = globalThis.fetch, verifyText, installText, names = {}, remove = null }) {
|
|
268
287
|
const installed = await installedFromMarket(stateRoot);
|
|
269
288
|
const updated = [];
|
|
270
289
|
const removed = [];
|
|
290
|
+
const held = [];
|
|
271
291
|
// Taken back (2026-10-25): a module, or the version of it this computer has, that the catalog says
|
|
272
292
|
// must not run any more is removed and forgotten here, so no next catalog brings it back.
|
|
273
293
|
for (const [id, have] of Object.entries(installed)) {
|
|
@@ -283,12 +303,25 @@ export async function updateFromMarket({ stateRoot, projectRoot, catalog, madre,
|
|
|
283
303
|
const entry = catalog?.modules.find((one) => one.id === id && one.file);
|
|
284
304
|
if (!entry || entry.file.sha256 === have.sha256 || !fitsVersion(madre, entry.minMadre)) continue;
|
|
285
305
|
try {
|
|
306
|
+
if (have.held === entry.file.sha256) continue;
|
|
307
|
+
const fresh = await installFromMarket({ stateRoot, projectRoot, id, catalog, madre, fetchImpl, verifyText, installText, review: true });
|
|
308
|
+
const kept = await readFile(join(stateRoot, 'modules', `${id}.mjs`), 'utf8').catch(() => null);
|
|
309
|
+
const accepted = kept ? await verifyText({ text: kept, name: `${id}.mjs`, replace: true }).catch(() => null) : null;
|
|
310
|
+
const more = accepted ? widens(accepted.declares, fresh.declares) : [];
|
|
311
|
+
if (more.length) {
|
|
312
|
+
// Read again: an update installed a moment ago in this same pass is already in the file.
|
|
313
|
+
const now = await installedFromMarket(stateRoot);
|
|
314
|
+
now[id] = { ...(now[id] ?? have), held: entry.file.sha256 };
|
|
315
|
+
await writeAtomic(join(folder(stateRoot), 'installed.json'), JSON.stringify(now, null, 2));
|
|
316
|
+
held.push({ id, name: names[id] ?? (typeof entry.name === 'string' ? entry.name : entry.name?.en) ?? id, kind: 'held', from: have.version ?? null, to: entry.version, more, at: new Date().toISOString() });
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
286
319
|
await installFromMarket({ stateRoot, projectRoot, id, catalog, madre, fetchImpl, verifyText, installText, accepted: true });
|
|
287
320
|
updated.push({ id, name: names[id] ?? (typeof entry.name === 'string' ? entry.name : entry.name?.en) ?? id, from: have.version ?? null, to: entry.version, changes: entry.changes ?? null, at: new Date().toISOString() });
|
|
288
321
|
} catch { /* tried again the next time MADRE opens */ }
|
|
289
322
|
}
|
|
290
323
|
// Said once each: what updated itself, and what was taken out of this computer and why.
|
|
291
|
-
const told = [...updated, ...removed];
|
|
324
|
+
const told = [...updated, ...removed, ...held];
|
|
292
325
|
if (told.length) {
|
|
293
326
|
const news = [...(await marketNews(stateRoot)).filter((one) => !told.some((fresh) => fresh.id === one.id)), ...told];
|
|
294
327
|
await writeAtomic(join(folder(stateRoot), 'updates.json'), JSON.stringify(news, null, 2));
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
import { readFile, readdir, stat, realpath } from 'node:fs/promises';
|
|
16
16
|
import { homedir } from 'node:os';
|
|
17
17
|
import { join } from 'node:path';
|
|
18
|
-
import { RoomMemory, formatRecall, formatMemories, MEMORY_KINDS } from '../memory.mjs';
|
|
18
|
+
import { RoomMemory, formatRecall, formatMemories, travels, ABERRATION, MEMORY_KINDS } from '../memory.mjs';
|
|
19
19
|
import { createEmbedder } from '../embeddings.mjs';
|
|
20
20
|
import { loadConfig } from '../config.mjs';
|
|
21
21
|
import { Privacy, privacySettings } from '../privacy.mjs';
|
|
@@ -117,7 +117,10 @@ export async function callTool(name, args = {}, { memory, projectRoot = process.
|
|
|
117
117
|
const text = String(args.text ?? '').replace(/\s+/g, ' ').trim();
|
|
118
118
|
if (!text) return 'Give me the memory as one sentence.';
|
|
119
119
|
if (text.length > 240) return `Too long (${text.length} characters): one sentence of at most 240.`;
|
|
120
|
-
|
|
120
|
+
// An unknown kind is said back, not filed as a fact (2026-11-01, external review #13): the
|
|
121
|
+
// store drops it for the same reason (src/memory.mjs, addMemories).
|
|
122
|
+
if (!MEMORY_KINDS.includes(args.kind)) return `Say what kind of memory it is: one of ${MEMORY_KINDS.join(', ')}.`;
|
|
123
|
+
const kind = args.kind;
|
|
121
124
|
const sources = (Array.isArray(args.sources) ? args.sources : []).map(Number).filter((n) => Number.isInteger(n) && n > 0);
|
|
122
125
|
const last = memory.lastSequence();
|
|
123
126
|
const before = memory.maxMemoryId();
|
|
@@ -154,7 +157,13 @@ export async function callTool(name, args = {}, { memory, projectRoot = process.
|
|
|
154
157
|
return `${lines.join('\n\n')}${truncated ? '\n\n[truncated; ask for a narrower range]' : ''}`;
|
|
155
158
|
}
|
|
156
159
|
case 'memory_notes': {
|
|
157
|
-
|
|
160
|
+
// What still stands, as the recall hands it (2026-11-01, external review #14): a note the
|
|
161
|
+
// human quarantined or one a later note refuted is archive, not knowledge, and listing it
|
|
162
|
+
// here put it back in the turn the recall had kept it out of. Asked by name, aberrations are
|
|
163
|
+
// listed for what they are — claims the room established are false — with what is true.
|
|
164
|
+
const limit = clamp(args.limit, 1, 100, 20);
|
|
165
|
+
const kind = MEMORY_KINDS.includes(args.kind) ? args.kind : null;
|
|
166
|
+
const notes = kind === ABERRATION ? memory.memories({ limit, kind }) : memory.memories({ limit: 500, kind }).filter(travels).slice(0, limit);
|
|
158
167
|
return notes.length ? formatMemories(notes) : 'No distilled notes yet.';
|
|
159
168
|
}
|
|
160
169
|
case 'memory_timeline': {
|
package/src/mcp/proxy.mjs
CHANGED
|
@@ -37,20 +37,42 @@ const say = (text) => process.stderr.write(`MADRE MCP ${serverId ?? '?'}: ${text
|
|
|
37
37
|
// The ids of tools/list requests in flight, so their answers can be filtered on the way back.
|
|
38
38
|
const listing = new Set();
|
|
39
39
|
function filterOutbound(message) {
|
|
40
|
+
if (Array.isArray(message)) return message.map(filterOutbound);
|
|
40
41
|
if (!allowed || !message || message.id === undefined || !listing.has(message.id)) return message;
|
|
41
42
|
listing.delete(message.id);
|
|
42
43
|
const tools = message.result?.tools;
|
|
43
44
|
if (!Array.isArray(tools)) return message;
|
|
44
45
|
return { ...message, result: { ...message.result, tools: tools.filter((tool) => allowed.has(tool?.name)) } };
|
|
45
46
|
}
|
|
46
|
-
//
|
|
47
|
+
// What a CLI may ask a server for in a turn, besides tools/call (2026-11-01, external review #61):
|
|
48
|
+
// the handshake and the protocol's reads. Anything else — a method this list does not know, from
|
|
49
|
+
// a newer protocol or from nobody — is answered here and never reaches the server, so a tool kept
|
|
50
|
+
// out of the turn cannot come in through a door the filter did not name. Notifications and the
|
|
51
|
+
// CLI's answers to the server's own questions pass as they are.
|
|
52
|
+
const CLIENT_METHODS = new Set([
|
|
53
|
+
'initialize', 'ping', 'tools/list', 'tools/call',
|
|
54
|
+
'resources/list', 'resources/templates/list', 'resources/read', 'resources/subscribe', 'resources/unsubscribe',
|
|
55
|
+
'prompts/list', 'prompts/get', 'completion/complete', 'logging/setLevel',
|
|
56
|
+
]);
|
|
57
|
+
// A message from the CLI: answered here when it asks for something it may not use; passed on
|
|
58
|
+
// otherwise. Answers what to send on, or null. A batch (an array) is each of its messages.
|
|
47
59
|
function admit(message) {
|
|
48
|
-
if (
|
|
49
|
-
|
|
60
|
+
if (Array.isArray(message)) {
|
|
61
|
+
const kept = message.map(admit).filter(Boolean);
|
|
62
|
+
return kept.length ? kept : null;
|
|
63
|
+
}
|
|
64
|
+
if (!message || typeof message !== 'object') return null;
|
|
65
|
+
if (typeof message.method !== 'string') return message; // the CLI's answer to the server
|
|
66
|
+
if (allowed && !message.method.startsWith('notifications/') && !CLIENT_METHODS.has(message.method)) {
|
|
67
|
+
fail(message.id, `MADRE does not pass ${message.method} to this server.`, -32601);
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
if (message.method === 'tools/list' && message.id !== undefined) listing.add(message.id);
|
|
71
|
+
if (message.method === 'tools/call' && allowed && !allowed.has(message.params?.name)) {
|
|
50
72
|
write({ jsonrpc: '2.0', id: message.id, result: { isError: true, content: [{ type: 'text', text: `MADRE does not allow ${message.params?.name ?? 'that tool'} in this turn.` }] } });
|
|
51
|
-
return
|
|
73
|
+
return null;
|
|
52
74
|
}
|
|
53
|
-
return
|
|
75
|
+
return message;
|
|
54
76
|
}
|
|
55
77
|
|
|
56
78
|
function lines(stream, onMessage) {
|
|
@@ -79,7 +101,7 @@ async function viaStdio(server) {
|
|
|
79
101
|
child.stderr.on('data', (chunk) => process.stderr.write(chunk));
|
|
80
102
|
child.stdin.on('error', () => {});
|
|
81
103
|
lines(child.stdout, (message) => write(filterOutbound(message)));
|
|
82
|
-
lines(process.stdin, (message) => {
|
|
104
|
+
lines(process.stdin, (message) => { const passed = admit(message); if (passed) child.stdin.write(`${JSON.stringify(passed)}\n`); });
|
|
83
105
|
process.stdin.on('end', () => { child.stdin.end(); setTimeout(() => child.kill('SIGTERM'), 2000).unref(); });
|
|
84
106
|
}
|
|
85
107
|
|
|
@@ -148,9 +170,10 @@ async function viaHttp(server) {
|
|
|
148
170
|
};
|
|
149
171
|
let queue = Promise.resolve();
|
|
150
172
|
lines(process.stdin, (message) => {
|
|
151
|
-
|
|
173
|
+
const passed = admit(message);
|
|
174
|
+
if (!passed) return;
|
|
152
175
|
// In order, as a stdio server would read them: the handshake has to land before the rest.
|
|
153
|
-
queue = queue.then(() => send(
|
|
176
|
+
queue = queue.then(() => send(passed)).catch((error) => { say(error.message); fail(passed.id, `could not reach the server: ${error.message}`); });
|
|
154
177
|
});
|
|
155
178
|
process.stdin.on('end', () => { void queue.finally(() => process.exit(0)); });
|
|
156
179
|
}
|
package/src/memory-tools.mjs
CHANGED
|
@@ -11,9 +11,16 @@ export const MEMORY_TOOLS = ['memory_search', 'memory_recall', 'memory_notes', '
|
|
|
11
11
|
|
|
12
12
|
// The same server, told who is calling: memory_note signs its notes with the
|
|
13
13
|
// agent and the turn, and a GHOST turn is refused any write.
|
|
14
|
-
|
|
14
|
+
// It embeds the agent's searches the way the room embeds its own, or not at all (2026-11-01,
|
|
15
|
+
// external review #20): `embedder` is the room's. Before, the server built its own from the Gemini
|
|
16
|
+
// key in the keychain, so «Memory › off» or «Ollama» in Settings still sent each search to Google,
|
|
17
|
+
// and an INCOGNITO search with them. Gemini only when the room uses Gemini; a room on Ollama or with
|
|
18
|
+
// no embedder searches by words here (the server has no Ollama of its own), and #0 always does.
|
|
19
|
+
export function memoryServerForTurn(server, { agent, messageId, mode = 1, embedder = null }) {
|
|
15
20
|
if (!server) return null;
|
|
16
|
-
|
|
21
|
+
const same = Number(mode) !== 0 && (embedder?.provider === 'gemini' || embedder?.provider === 'fake');
|
|
22
|
+
const embed = same ? (embedder.provider === 'gemini' ? { PULSE_EMBED_PROVIDER: 'gemini' } : {}) : { PULSE_EMBED: '0' };
|
|
23
|
+
return { ...server, env: { ...server.env, ...embed, PULSE_MEMORY_AGENT: agent, PULSE_MEMORY_MESSAGE: messageId, PULSE_MEMORY_MODE: String(mode) } };
|
|
17
24
|
}
|
|
18
25
|
|
|
19
26
|
export function memoryServerFor({ dbFile, projectRoot, env = process.env }) {
|
package/src/memory.mjs
CHANGED
|
@@ -577,12 +577,17 @@ export class RoomMemory {
|
|
|
577
577
|
// The bar is high on purpose: almost every distinctive word of one has to be in the other.
|
|
578
578
|
// A merely related note is not the same claim, and taking down the wrong one is worse than
|
|
579
579
|
// taking down none.
|
|
580
|
+
// The words are not the whole claim, though: «we do not deploy on Fridays» and «we deploy on
|
|
581
|
+
// Fridays» share every long word and say opposite things (2026-11-01, external review #17). A note
|
|
582
|
+
// whose sense is the negation of the claim is never the claim, so it is never the one taken down.
|
|
580
583
|
#refutedBy(text) {
|
|
581
584
|
const terms = new Set(normalizeMemory(text).split(' ').filter((word) => word.length > 2));
|
|
582
585
|
if (terms.size < 3) return null;
|
|
586
|
+
const denies = negates(text);
|
|
583
587
|
let best = null;
|
|
584
588
|
const standing = this.#db.prepare(`SELECT id, text FROM memories WHERE ${ZONE_GATE} ORDER BY id DESC LIMIT 200`).all();
|
|
585
589
|
for (const row of standing) {
|
|
590
|
+
if (negates(row.text) !== denies) continue;
|
|
586
591
|
const other = new Set(normalizeMemory(row.text).split(' ').filter((word) => word.length > 2));
|
|
587
592
|
if (other.size < 3) continue;
|
|
588
593
|
let shared = 0;
|
|
@@ -1117,6 +1122,16 @@ export class RoomMemory {
|
|
|
1117
1122
|
}
|
|
1118
1123
|
}
|
|
1119
1124
|
|
|
1125
|
+
// Whether a note says that something is not so, in Spanish or English: the short words the
|
|
1126
|
+
// matching above drops for being short are the ones that turn a claim around. Read in the first
|
|
1127
|
+
// clause only, where the claim is: «on port 7100 by default, not another» still says port 7100.
|
|
1128
|
+
const NEGATIONS = new Set(['no', 'not', 'never', 'nunca', 'jamas', 'sin', 'without', 'ni', 'nor', 'none', 'nadie', 'nada', 'nothing', 'nobody', 'tampoco', 'cannot']);
|
|
1129
|
+
export function negates(text) {
|
|
1130
|
+
const words = normalizeMemory(String(text).split(/[,;:.()\u2013\u2014]/)[0]).split(' ');
|
|
1131
|
+
// «don't», «isn't»: the apostrophe became a space, so the word ends in n and a lone t follows.
|
|
1132
|
+
return words.some((word, index) => NEGATIONS.has(word) || (word === 't' && /n$/.test(words[index - 1] ?? '')));
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1120
1135
|
export function normalizeMemory(text) {
|
|
1121
1136
|
return String(text).toLowerCase().normalize('NFKD').replace(/[\u0300-\u036f]/g, '').replace(/[^\p{L}\p{N}]+/gu, ' ').trim();
|
|
1122
1137
|
}
|
|
@@ -1126,6 +1141,7 @@ export function formatMemories(list) {
|
|
|
1126
1141
|
if (!list?.length) return '';
|
|
1127
1142
|
return list.map((memory) => {
|
|
1128
1143
|
const span = memory.fromSequence === memory.throughSequence ? `#${memory.fromSequence}` : `#${memory.fromSequence}–#${memory.throughSequence}`;
|
|
1144
|
+
if (memory.kind === ABERRATION) return `- [${memory.kind} · ${span}] FALSE: ${memory.text}${memory.correction ? ` — what is true: ${memory.correction}` : ''}`;
|
|
1129
1145
|
return `- [${memory.kind} · ${span}] ${memory.text}`;
|
|
1130
1146
|
}).join('\n');
|
|
1131
1147
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
3
|
+
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
4
|
+
// What a module is, asked in a process of its own (2026-11-01, external review #1).
|
|
5
|
+
//
|
|
6
|
+
// node --permission --allow-fs-read=<its folder> --allow-fs-read=<MADRE> check-alone.mjs <file>
|
|
7
|
+
//
|
|
8
|
+
// A module says what it is only by loading, and loading runs its code. Checking used to load it
|
|
9
|
+
// inside MADRE, before the person had read what it does and accepted it: a file from the Market,
|
|
10
|
+
// a newer copy from a module's own address, ran with all of MADRE's rights just to be described.
|
|
11
|
+
// Here it loads in a node of its own that src/modules/index.mjs starts (verifyModuleText) with
|
|
12
|
+
// Node's permission model: it reads only its folder and MADRE's code, writes nothing, starts no
|
|
13
|
+
// process or thread, gets no environment, and is stopped if it does not finish. On Node 25 and
|
|
14
|
+
// later the network is closed as well. What comes back is words, never the module.
|
|
15
|
+
import { writeSync } from 'node:fs';
|
|
16
|
+
import { inspectModuleFile } from './index.mjs';
|
|
17
|
+
|
|
18
|
+
// Written whole before the process ends: on a pipe, process.stdout may still be writing.
|
|
19
|
+
const say = (answer) => writeSync(1, `\n${JSON.stringify(answer)}\n`);
|
|
20
|
+
try {
|
|
21
|
+
say({ ok: true, module: JSON.parse(JSON.stringify(await inspectModuleFile(process.argv[2]))) });
|
|
22
|
+
} catch (error) {
|
|
23
|
+
say({ ok: false, error: String(error?.message ?? error), code: error?.code ?? null });
|
|
24
|
+
}
|
|
25
|
+
process.exit(0);
|
package/src/modules/index.mjs
CHANGED
|
@@ -6,9 +6,10 @@
|
|
|
6
6
|
// (defineModule is applied here), a module already built with defineModule, or a function
|
|
7
7
|
// receiving { defineModule } and returning either. Agents cannot write those folders: .madre/
|
|
8
8
|
// is a forbidden zone, and ~/.pulse lives outside every project.
|
|
9
|
-
import { readdir, readFile, writeFile, mkdir, unlink, mkdtemp, rm } from 'node:fs/promises';
|
|
9
|
+
import { readdir, readFile, writeFile, mkdir, unlink, mkdtemp, realpath, rm } from 'node:fs/promises';
|
|
10
|
+
import { execFile } from 'node:child_process';
|
|
10
11
|
import { translate } from '../i18n.mjs';
|
|
11
|
-
import { join, basename, resolve, sep } from 'node:path';
|
|
12
|
+
import { join, basename, dirname, resolve, sep } from 'node:path';
|
|
12
13
|
import { tmpdir } from 'node:os';
|
|
13
14
|
import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
14
15
|
import { clearDeclaredDestinations, declareDestinations } from '../outbound.mjs';
|
|
@@ -86,6 +87,37 @@ async function importModuleFile(file) {
|
|
|
86
87
|
return typeof spec.describe === 'function' ? spec : defineModule(spec);
|
|
87
88
|
}
|
|
88
89
|
|
|
90
|
+
// The same file, described in words that cross a process: what the check and the person need,
|
|
91
|
+
// never the module itself. src/modules/check-alone.mjs answers with it.
|
|
92
|
+
export async function inspectModuleFile(file) {
|
|
93
|
+
const module = await importModuleFile(file);
|
|
94
|
+
return {
|
|
95
|
+
id: module.id, name: module.name, vendor: module.vendor, version: module.version ?? null, summary: module.summary ?? '', words: module.words ?? null, credit: module.credit ?? null, updates: module.updates ?? null, unknown: module.unknown ?? [], declares: declaredBy(module),
|
|
96
|
+
routes: (module.routes ?? []).map((route) => ({ path: typeof route.path === 'string' ? route.path : { source: route.path?.source ?? '' } })),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Loads a candidate in a node of its own, fenced by Node's permission model (check-alone.mjs says
|
|
101
|
+
// what it may and may not do), so that asking what a file is never runs it inside MADRE.
|
|
102
|
+
const CHECK_ALONE = fileURLToPath(new URL('./check-alone.mjs', import.meta.url));
|
|
103
|
+
const PACKAGE_ROOT = fileURLToPath(new URL('../..', import.meta.url));
|
|
104
|
+
export const CHECK_MS = 15000;
|
|
105
|
+
const FENCE = ['--permission', '--experimental-permission'].find((flag) => process.allowedNodeEnvironmentFlags.has(flag)) ?? null;
|
|
106
|
+
async function inspectAlone(probe) {
|
|
107
|
+
const [folder, root] = await Promise.all([realpath(dirname(probe)), realpath(PACKAGE_ROOT)]);
|
|
108
|
+
const fence = FENCE ? [FENCE, `--allow-fs-read=${folder}`, `--allow-fs-read=${root}`] : [];
|
|
109
|
+
return new Promise((done, fail) => {
|
|
110
|
+
execFile(process.execPath, [...fence, CHECK_ALONE, join(folder, basename(probe))], { env: {}, cwd: folder, timeout: CHECK_MS, maxBuffer: 1 << 20, windowsHide: true }, (error, stdout, stderr) => {
|
|
111
|
+
if (error?.killed) return fail(new Error(`it did not finish loading in ${CHECK_MS / 1000} s, so MADRE stopped it: a module only declares what it is, and loading it must not wait on anything`));
|
|
112
|
+
const said = String(stdout ?? '').split('\n').reverse().map((line) => { try { return JSON.parse(line); } catch { return null; } }).find((one) => one && typeof one.ok === 'boolean');
|
|
113
|
+
if (!said) return fail(new Error(String(stderr ?? '').trim().split('\n').at(-1) || error?.message || 'it ended before saying what it is'));
|
|
114
|
+
if (!said.ok) return fail(Object.assign(new Error(said.error), { code: said.code ?? undefined }));
|
|
115
|
+
if (!said.module || typeof said.module.id !== 'string' || !/^[a-z][a-z0-9-]*$/.test(said.module.id)) return fail(new Error('it did not say a module id MADRE can use'));
|
|
116
|
+
return done(said.module);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
89
121
|
export async function loadExternalModules({ stateRoot, projectRoot }) {
|
|
90
122
|
for (let index = MODULES.length - 1; index >= 0; index -= 1) if (MODULES[index].external) MODULES.splice(index, 1);
|
|
91
123
|
loadFailures.length = 0;
|
|
@@ -153,9 +185,11 @@ export async function adoptBuiltinUpdates({ stateRoot, enabled = true, factoryKe
|
|
|
153
185
|
}
|
|
154
186
|
|
|
155
187
|
// The one door every module comes through, whoever wrote it and wherever the text came from: it
|
|
156
|
-
// is written to a scratch copy,
|
|
157
|
-
// inside MADRE with the human's own permissions,
|
|
158
|
-
//
|
|
188
|
+
// is written to a scratch copy, loaded there in a fenced node of its own (inspectAlone) and checked
|
|
189
|
+
// against the house rules. An installed module runs inside MADRE with the human's own permissions,
|
|
190
|
+
// so the check is the point — and checking runs nothing in MADRE (2026-11-01, external review #1).
|
|
191
|
+
// Checking installs nothing and touches no registry — asking what a file is must never change
|
|
192
|
+
// what is loaded.
|
|
159
193
|
export async function verifyModuleText({ text, name = null, replace = true }) {
|
|
160
194
|
const scratch = await mkdtemp(join(tmpdir(), 'madre-module-check-'));
|
|
161
195
|
try {
|
|
@@ -163,7 +197,7 @@ export async function verifyModuleText({ text, name = null, replace = true }) {
|
|
|
163
197
|
await writeFile(probe, text);
|
|
164
198
|
let module;
|
|
165
199
|
try {
|
|
166
|
-
module = checkExternal(await
|
|
200
|
+
module = checkExternal(await inspectAlone(probe), { replace });
|
|
167
201
|
} catch (error) {
|
|
168
202
|
// The one mistake that looks right and never works: MADRE's own modules import the SDK by
|
|
169
203
|
// relative path because they live inside the package, and anyone — an agent most of all —
|
|
@@ -174,7 +208,7 @@ export async function verifyModuleText({ text, name = null, replace = true }) {
|
|
|
174
208
|
}
|
|
175
209
|
throw error;
|
|
176
210
|
}
|
|
177
|
-
return { id: module.id, name: module.name, vendor: module.vendor, version: module.version ?? null, summary: module.summary ?? '', words: module.words ?? null, credit: module.credit ?? null, updates: module.updates ?? null, unknown: module.unknown ?? [], declares:
|
|
211
|
+
return { id: module.id, name: module.name, vendor: module.vendor, version: module.version ?? null, summary: module.summary ?? '', words: module.words ?? null, credit: module.credit ?? null, updates: module.updates ?? null, unknown: module.unknown ?? [], declares: module.declares };
|
|
178
212
|
} finally { await rm(scratch, { recursive: true, force: true, maxRetries: 6, retryDelay: 60 }); }
|
|
179
213
|
}
|
|
180
214
|
|
package/src/mother.mjs
CHANGED
|
@@ -158,12 +158,17 @@ export class MotherChannel {
|
|
|
158
158
|
|
|
159
159
|
lockedFor() { return Math.max(0, this.#lockUntil - Date.now()); }
|
|
160
160
|
|
|
161
|
-
// What the children read: the recent alerts, decoded, newest last.
|
|
161
|
+
// What the children read: the recent alerts, decoded, newest last. An intrusion alert travels
|
|
162
|
+
// only while the archive is sealed (2026-11-01, external review #21): it tells every agent to
|
|
163
|
+
// refuse any request to delete or rewrite a memory, and for a day after a ten-minute seal that
|
|
164
|
+
// turned down the human's own requests. A tampered seal is still said for the day.
|
|
162
165
|
recent({ withinMs = 24 * 3600 * 1000, limit = 3 } = {}) {
|
|
163
166
|
const since = Date.now() - withinMs;
|
|
167
|
+
const sealed = this.lockedFor() > 0;
|
|
164
168
|
const out = [];
|
|
165
169
|
for (const alert of this.#alerts) {
|
|
166
170
|
if (new Date(alert.at).getTime() < since) continue;
|
|
171
|
+
if (alert.kind === 'intrusion' && !sealed) continue;
|
|
167
172
|
try { out.push({ ...alert, text: decodeMessage(this.#seal, alert.code) }); } catch { /* sealed under an older key */ }
|
|
168
173
|
}
|
|
169
174
|
return out.slice(-limit);
|
package/src/outbound.mjs
CHANGED
|
@@ -121,9 +121,17 @@ export const DESTINATIONS = [
|
|
|
121
121
|
inside: true,
|
|
122
122
|
},
|
|
123
123
|
{
|
|
124
|
-
id: 'usage', host: 'madre.run', match: (url) => url.pathname === '/api/usage', to: "madre.run · the author's usage figures",
|
|
125
|
-
what: "The author's token, to read how many copies are on. Only in the author's own copy, run from source.",
|
|
126
|
-
when: 'while the «MADRE usage» widget is on Home',
|
|
124
|
+
id: 'usage', host: 'madre.run', match: (url) => url.pathname === '/api/usage' || url.pathname === '/api/rumbo', to: "madre.run · the author's usage figures",
|
|
125
|
+
what: "The author's token, to read how many copies are on and how far new ones get. Only in the author's own copy, run from source.",
|
|
126
|
+
when: 'while the «MADRE usage» or «MADRE\'s course» widget is on Home',
|
|
127
|
+
where: "Only in the author's copy",
|
|
128
|
+
inside: true,
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
// MADRE's course (src/rumbo.mjs, 2026-11-01): npm's public download counts of the package.
|
|
132
|
+
id: 'npm-stats', host: 'api.npmjs.org', to: "npm · the package's download counts",
|
|
133
|
+
what: 'Nothing but the name of MADRE\'s package, to read how many times it was downloaded. Only in the author\'s own copy, run from source.',
|
|
134
|
+
when: 'while the «MADRE\'s course» widget is on Home, every half hour at most',
|
|
127
135
|
where: "Only in the author's copy",
|
|
128
136
|
inside: true,
|
|
129
137
|
},
|
package/src/room/archivist.mjs
CHANGED
|
@@ -8,6 +8,12 @@
|
|
|
8
8
|
import { pickDistiller, distillPrompt, parseDistillation, OLLAMA_ARCHIVIST } from '../distiller.mjs';
|
|
9
9
|
|
|
10
10
|
export const BENCH_MS = 30 * 60 * 1000;
|
|
11
|
+
// A failure that says nothing about the batch: no network, a provider's limit or a timeout
|
|
12
|
+
// (2026-11-01, external review #18). Before, three of those in a row — a day offline — set the
|
|
13
|
+
// batch aside for good, as if it could never be distilled, and its notes were never written. Those
|
|
14
|
+
// stay in the queue and are tried again; only a batch that keeps failing for itself is skipped.
|
|
15
|
+
const PASSING = /ETIMEDOUT|ECONNRESET|ECONNREFUSED|ENOTFOUND|EAI_AGAIN|ENETUNREACH|fetch failed|network|timed? ?out|\b(429|502|503|504)\b|rate.?limit|quota|usage limit|overloaded|unavailable/i;
|
|
16
|
+
export const passingFailure = (error) => PASSING.test(`${error?.code ?? ''} ${error?.message ?? error ?? ''}`);
|
|
11
17
|
|
|
12
18
|
export function distillDefaults(distill = {}, env = process.env) {
|
|
13
19
|
return {
|
|
@@ -134,7 +140,7 @@ export class Archivist {
|
|
|
134
140
|
} catch (error) {
|
|
135
141
|
const attempts = (this.#failures.get(batch.fromSequence) ?? 0) + 1;
|
|
136
142
|
this.#failures.set(batch.fromSequence, attempts);
|
|
137
|
-
const skipped = attempts >= 3;
|
|
143
|
+
const skipped = attempts >= 3 && !passingFailure(error);
|
|
138
144
|
if (skipped) { this.#memory.markDistilled(batch.sequences); this.#failures.delete(batch.fromSequence); }
|
|
139
145
|
this.#bench.set(agent.id, Date.now() + BENCH_MS);
|
|
140
146
|
const next = pickDistiller(candidates, { preferred: this.#settings.agent, busy: new Set(), invokers, benched: new Set(this.#bench.keys()) });
|
package/src/room/context.mjs
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import { buildConversationContext } from '../conversation-context.mjs';
|
|
8
8
|
|
|
9
|
-
export async function contextFor({ memory, priorEvents, messageId, text, contextMaxChars, recallShare, remember = () => {}, omitSynthetic = false, anchor = null, by = null, cascade = true, track = true }) {
|
|
9
|
+
export async function contextFor({ memory, priorEvents, messageId, text, contextMaxChars, recallShare, remember = () => {}, omitSynthetic = false, anchor = null, by = null, cascade = true, track = true, ghost = false }) {
|
|
10
10
|
const full = buildConversationContext(priorEvents, { excludeMessageId: messageId, maxChars: contextMaxChars, omitSynthetic, anchor });
|
|
11
11
|
const none = { context: full, recall: null, memories: null };
|
|
12
12
|
if (!memory || !full.omittedMessages || recallShare <= 0) return none;
|
|
@@ -20,9 +20,12 @@ export async function contextFor({ memory, priorEvents, messageId, text, context
|
|
|
20
20
|
let recall = null;
|
|
21
21
|
try {
|
|
22
22
|
// One embedding of the request lets both lookups match meaning; without it they match words.
|
|
23
|
-
|
|
23
|
+
// An INCOGNITO turn (#0) matches words only (2026-11-01, external review #20): embedding its
|
|
24
|
+
// request would send it to the embedder's provider, and tracking it would write down a turn
|
|
25
|
+
// that is off the record.
|
|
26
|
+
const queryVector = ghost ? null : await memory.embedQuery(text);
|
|
24
27
|
// Distilled notes first (dense, cheap), exact quotes with what is left.
|
|
25
|
-
memories = memory.recallMemories(text, { beforeSequence: before, maxChars: Math.floor(recallBudget * 0.4), queryVector, by, cascade, track });
|
|
28
|
+
memories = memory.recallMemories(text, { beforeSequence: before, maxChars: Math.floor(recallBudget * 0.4), queryVector, by, cascade, track: track && !ghost });
|
|
26
29
|
const spent = memories.reduce((sum, item) => sum + item.text.length + 24, 0);
|
|
27
30
|
recall = memory.recall(text, { beforeSequence: before, excludeMessageId: messageId, maxChars: recallBudget - spent, queryVector });
|
|
28
31
|
} catch (error) {
|
package/src/room/copilot.mjs
CHANGED
|
@@ -18,48 +18,42 @@ export const COPILOT_WINDOWS = Object.freeze([30, 60, 240, 480, 1440]);
|
|
|
18
18
|
// human: a copilot that loops is a bill, not help.
|
|
19
19
|
export const COPILOT_MAX_ROUNDS = 8;
|
|
20
20
|
|
|
21
|
-
// The commands a copilot may run without the human pressing: reading,
|
|
22
|
-
//
|
|
23
|
-
//
|
|
21
|
+
// The commands a copilot may run without the human pressing: reading, and reading git. Narrow on
|
|
22
|
+
// purpose — a list of what is allowed, never of what is not — so a command nobody thought of waits
|
|
23
|
+
// for the human instead of running.
|
|
24
|
+
//
|
|
25
|
+
// Tests, builds, linters and commits used to run by themselves too, and wait for the human since
|
|
26
|
+
// 2026-11-01 (external review #3, the person's decision): each runs code the project defines — a
|
|
27
|
+
// script in package.json, a test file, a config in JS, build.rs, a hook in .husky — and the copilot
|
|
28
|
+
// edits the project. What it wrote in its turn then ran with the person's rights and the network,
|
|
29
|
+
// which is what #4 and its own key are for. Reading runs nothing of the project's; git reads after
|
|
30
|
+
// the turn let go of the project, when .git/config and its hooks are already back as they were.
|
|
24
31
|
const READERS = new Set(['ls', 'cat', 'head', 'tail', 'wc', 'pwd', 'file', 'stat', 'du', 'tree', 'which', 'diff', 'grep', 'rg', 'echo', 'date']);
|
|
25
32
|
const GIT_READ = new Set(['status', 'log', 'diff', 'show', 'rev-parse', 'ls-files', 'blame', 'shortlog', 'describe']);
|
|
26
|
-
const GIT_LOCAL = new Set(['add', 'commit']);
|
|
27
|
-
const SCRIPTS = new Set(['test', 'build', 'lint', 'check', 'typecheck', 'format:check']);
|
|
28
|
-
const NPX_TOOLS = new Set(['tsc', 'vitest', 'jest', 'eslint']);
|
|
29
33
|
|
|
30
34
|
export function copilotSafe(argv = []) {
|
|
31
35
|
const [program, ...rest] = (Array.isArray(argv) ? argv : []).map(String);
|
|
32
36
|
const name = String(program ?? '').split('/').pop();
|
|
33
37
|
if (!name) return false;
|
|
38
|
+
// Readers that can still run or write something with one flag: rg's --pre runs a program on each
|
|
39
|
+
// file, tree -o writes its output wherever it is told.
|
|
40
|
+
if (name === 'rg' && rest.some((word) => /^--pre(-glob)?(=|$)/.test(word))) return false;
|
|
41
|
+
if (name === 'tree' && rest.some((word) => /^(-o|--output)/.test(word))) return false;
|
|
34
42
|
if (READERS.has(name)) return true;
|
|
35
43
|
if (name === 'find') return !rest.some((word) => /^-(delete|exec|execdir|ok|okdir|fprint|fprint0|fprintf|fls)$/.test(word));
|
|
36
44
|
if (name === 'git') {
|
|
37
|
-
|
|
45
|
+
// The subcommand first, with no options before it: `--git-dir`, `-c` or `--exec-path` would
|
|
46
|
+
// point git at settings the project holds, and those can name a program to run. And no
|
|
47
|
+
// --output, which writes a file.
|
|
48
|
+
const sub = rest[0];
|
|
49
|
+
if (rest.some((word) => /^--output(=|$)/.test(word))) return false;
|
|
38
50
|
if (GIT_READ.has(sub)) return true;
|
|
39
51
|
if (sub === 'branch') return !rest.some((word) => /^-(d|D|m|M|c|C|-delete|-move|-copy|f|-force)$/.test(word)) && rest.filter((word) => !word.startsWith('-')).length === 1;
|
|
40
52
|
if (sub === 'stash') return rest.includes('list');
|
|
41
|
-
if (GIT_LOCAL.has(sub)) return true;
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
if (['npm', 'pnpm', 'yarn', 'bun'].includes(name)) {
|
|
45
|
-
const [first, second] = rest.filter((word) => !word.startsWith('-'));
|
|
46
|
-
if (first === 'test' || first === 't') return true;
|
|
47
|
-
if (first === 'run' || (name !== 'npm' && SCRIPTS.has(first))) return SCRIPTS.has(first === 'run' ? second : first);
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
if (name === 'npx') {
|
|
51
|
-
const tool = rest.find((word) => !word.startsWith('-'));
|
|
52
|
-
if (NPX_TOOLS.has(tool)) return true;
|
|
53
|
-
if (tool === 'prettier') return rest.includes('--check');
|
|
54
|
-
if (tool === 'playwright') return rest[rest.indexOf('playwright') + 1] === 'test';
|
|
55
53
|
return false;
|
|
56
54
|
}
|
|
57
|
-
|
|
58
|
-
if (name === '
|
|
59
|
-
if (name === 'pytest') return true;
|
|
60
|
-
if (/^python3?$/.test(name)) return rest[0] === '-m' && ['pytest', 'unittest', 'compileall'].includes(rest[1]);
|
|
61
|
-
if (name === 'go') return ['test', 'vet', 'build'].includes(rest[0]);
|
|
62
|
-
if (name === 'cargo') return ['test', 'build', 'check', 'clippy', 'fmt'].includes(rest[0]) && !(rest[0] === 'fmt' && !rest.includes('--check'));
|
|
55
|
+
// Parsing a file runs none of it.
|
|
56
|
+
if (name === 'node') return rest[0] === '--check';
|
|
63
57
|
return false;
|
|
64
58
|
}
|
|
65
59
|
|
|
@@ -69,7 +63,7 @@ const clock = (until) => new Date(until).toISOString().slice(11, 16);
|
|
|
69
63
|
export function copilotBrief({ until }) {
|
|
70
64
|
return [
|
|
71
65
|
`COPILOT: the human made you their copilot for this project until ${clock(until)} UTC. Drive the work to done without asking at every step.`,
|
|
72
|
-
'You may create, write and edit the project\'s files; you may end a reply with a pulse plan for the other agents and give each step the mode it needs, up to #3; and you may ask for the commands you need with a ```pulse-run block: MADRE runs the
|
|
66
|
+
'You may create, write and edit the project\'s files; you may end a reply with a pulse plan for the other agents and give each step the mode it needs, up to #3; and you may ask for the commands you need with a ```pulse-run block: MADRE runs the ones that only read by itself (ls, cat, rg, git status, diff and log) and hands you their output in a new turn; tests, builds, linters, commits and any other line wait for the human to press them, so ask for them once, together, when the work is ready to check.',
|
|
73
67
|
'What stays with the human: never delete files (MADRE puts them back after your turn), never touch .git, .pulse, .madre, .env files or credentials, and never push, publish, deploy or send anything off this machine — say what would need to go out and stop there.',
|
|
74
68
|
'When the task is done, end with what changed, what you checked, and what is left for the human.',
|
|
75
69
|
].join('\n');
|
package/src/room.mjs
CHANGED
|
@@ -390,8 +390,8 @@ export class Room {
|
|
|
390
390
|
// Characters per input token, as this room's own turns have shown. Null until it has one.
|
|
391
391
|
#rate = null;
|
|
392
392
|
|
|
393
|
-
async #contextFor(priorEvents, { messageId, text, omitSynthetic = false, by = null }) {
|
|
394
|
-
const built = await contextFor({ memory: this.#memory, priorEvents, messageId, text, contextMaxChars: this.#contextMaxChars, recallShare: this.#recallShare, remember: (events) => this.#remember(events), omitSynthetic, anchor: this.#contextAnchor, by, cascade: this.#cascade });
|
|
393
|
+
async #contextFor(priorEvents, { messageId, text, omitSynthetic = false, by = null, ghost = false }) {
|
|
394
|
+
const built = await contextFor({ memory: this.#memory, priorEvents, messageId, text, contextMaxChars: this.#contextMaxChars, recallShare: this.#recallShare, remember: (events) => this.#remember(events), omitSynthetic, anchor: this.#contextAnchor, by, cascade: this.#cascade, ghost });
|
|
395
395
|
// @madre reads a different transcript to everyone else, so it never sets where the room's
|
|
396
396
|
// window begins; it only borrows it.
|
|
397
397
|
if (!omitSynthetic && Number.isInteger(built.context?.anchor)) this.#contextAnchor = built.context.anchor;
|
|
@@ -1554,7 +1554,7 @@ export class Room {
|
|
|
1554
1554
|
|
|
1555
1555
|
const priorEvents = await this.#store.readAll();
|
|
1556
1556
|
// @madre never reads its own canned replies back: a small model would echo them.
|
|
1557
|
-
const { context, recall, memories } = await this.#contextFor(priorEvents, { messageId, text, omitSynthetic: Boolean(agent.local), by: { agent: targetId, turn: messageId } });
|
|
1557
|
+
const { context, recall, memories } = await this.#contextFor(priorEvents, { messageId, text, omitSynthetic: Boolean(agent.local), by: { agent: targetId, turn: messageId }, ghost: mode === 0 });
|
|
1558
1558
|
let handoffId = null;
|
|
1559
1559
|
if (context.previousAgent && context.previousAgent !== targetId) {
|
|
1560
1560
|
handoffId = randomUUID();
|
|
@@ -1937,7 +1937,7 @@ export class Room {
|
|
|
1937
1937
|
lease,
|
|
1938
1938
|
scopes: turnScopes,
|
|
1939
1939
|
imageStudio,
|
|
1940
|
-
memoryServer: memoryServerForTurn(this.#memoryServer, { agent: agent.id, messageId: responseMessageId, mode: turnMode }),
|
|
1940
|
+
memoryServer: memoryServerForTurn(this.#memoryServer, { agent: agent.id, messageId: responseMessageId, mode: turnMode, embedder: this.#memory?.embedder ?? null }),
|
|
1941
1941
|
mcpServers,
|
|
1942
1942
|
bishop,
|
|
1943
1943
|
// For @madre: who asks, who it may convene, and whether a plan would run at all.
|