@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/room.mjs
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
// SPDX-License-Identifier: BUSL-1.1
|
|
2
2
|
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
3
3
|
import { invokeCodex, buildCodexArgs } from './adapters/codex.mjs';
|
|
4
|
+
import { codexRoute } from './codex-route.mjs';
|
|
4
5
|
import { t } from './i18n.mjs';
|
|
5
6
|
import { invokeClaude, buildClaudeArgs } from './adapters/claude.mjs';
|
|
6
7
|
import { keptSubagents } from './adapters/subagents.mjs';
|
|
7
8
|
import { invokeGemini, buildGeminiArgs } from './adapters/gemini.mjs';
|
|
9
|
+
import { invokeGeminiRest } from './adapters/gemini-rest.mjs';
|
|
8
10
|
import { invokeOpenCode, buildOpenCodeArgs } from './adapters/opencode.mjs';
|
|
9
11
|
import { invokeCursor, buildCursorArgs } from './adapters/cursor.mjs';
|
|
12
|
+
import { invokeGrok, buildGrokArgs } from './adapters/grok.mjs';
|
|
10
13
|
import { parseMessage } from './router.mjs';
|
|
11
14
|
import { randomUUID } from 'node:crypto';
|
|
12
15
|
import { basename } from 'node:path';
|
|
@@ -15,19 +18,22 @@ import { UsageSentinel } from './usage-sentinel.mjs';
|
|
|
15
18
|
import { BLOCK_SOURCES, buildPrompt, promptParts, sparedChars, wantsModule } from './room/prompt.mjs';
|
|
16
19
|
import { turnCost, observedRate } from './room/economy.mjs';
|
|
17
20
|
import { contextFor } from './room/context.mjs';
|
|
18
|
-
import { VERDICTS, travels } from './memory.mjs';
|
|
21
|
+
import { VERDICTS, travels, unsourced } from './memory.mjs';
|
|
19
22
|
import { coldNotes, coldReading } from './cold.mjs';
|
|
20
23
|
import { questionsFor } from './asking.mjs';
|
|
21
24
|
import { coverageExam, consistencyExam, matchExam, exchanges, MATCH_SAMPLE, saysFor } from './exam.mjs';
|
|
22
25
|
import { MADRE_ADAPTER, MADRE_AGENT_ID } from './adapters/madre.mjs';
|
|
23
26
|
import { ControlDesk } from './room/control.mjs';
|
|
27
|
+
import { takeChangeSummary, takeModuleNeeds, turnChanges } from './room/changes.mjs';
|
|
24
28
|
import { RunDesk } from './room/runs.mjs';
|
|
25
29
|
import { Attachments } from './room/attachments.mjs';
|
|
26
30
|
import { GhostLedger } from './room/ghost.mjs';
|
|
27
31
|
import { Escalation } from './room/escalation.mjs';
|
|
32
|
+
import { noteOpenCodeModel } from './quota-sources.mjs';
|
|
28
33
|
import { Budget, budgetTokens } from './room/budget.mjs';
|
|
29
34
|
import { VectorWorker } from './room/vectors.mjs';
|
|
30
|
-
import { Archivist, distillDefaults } from './room/archivist.mjs';
|
|
35
|
+
import { Archivist, distillDefaults, LOCAL_DISTILL_MS } from './room/archivist.mjs';
|
|
36
|
+
import { machineBusy } from './room/busy.mjs';
|
|
31
37
|
import { OLLAMA_ARCHIVIST } from './distiller.mjs';
|
|
32
38
|
import { memoryServerForTurn } from './memory-tools.mjs';
|
|
33
39
|
import { CODE000_STRIKES } from './mother.mjs';
|
|
@@ -41,14 +47,15 @@ import { stat as statFile, readdir, copyFile, mkdir as mkdirPath, readFile as re
|
|
|
41
47
|
import { basename as baseName, join as joinPath } from 'node:path';
|
|
42
48
|
import { declaredTypeFor, filesChangedSince } from './files.mjs';
|
|
43
49
|
import { isModuleFile, sdkPaths } from './modules/index.mjs';
|
|
50
|
+
import { isSkillFile, skillGuide, skillIdOf } from './skills.mjs';
|
|
44
51
|
import { validateAshReply } from './modules/ash-policy.mjs';
|
|
45
52
|
import { PHONE_MAX_MODE } from './bridge/policy.mjs';
|
|
46
53
|
import { parseChoice, withoutChoice } from './choices.mjs';
|
|
47
|
-
import { parseRunRequest, withoutRunRequest, whyText, expandHome } from './runs.mjs';
|
|
54
|
+
import { parseRunRequest, withoutRunRequest, whyText, expandHome, attachCommandScripts } from './runs.mjs';
|
|
48
55
|
import { runSettlement, returnedBlock } from './room/returns.mjs';
|
|
49
56
|
import { copilotSafe, copilotBrief, COPILOT_MAX_ROUNDS } from './room/copilot.mjs';
|
|
50
57
|
import { imageStudioFor } from './image-studio.mjs';
|
|
51
|
-
import { CAPABILITIES, imageModuleState } from './capabilities.mjs';
|
|
58
|
+
import { CAPABILITIES, capabilityOf, imageModuleState } from './capabilities.mjs';
|
|
52
59
|
import { resolveReferences } from './files.mjs';
|
|
53
60
|
|
|
54
61
|
const VIA_KINDS = new Set(['iphone', 'ipad', 'android', 'android-tablet', 'other']);
|
|
@@ -62,12 +69,17 @@ export function failureMessage(error, maxLength = 500) {
|
|
|
62
69
|
return line.length > maxLength ? `${line.slice(0, maxLength - 1)}…` : line;
|
|
63
70
|
}
|
|
64
71
|
|
|
65
|
-
const defaultInvokers = {
|
|
72
|
+
export const defaultInvokers = {
|
|
66
73
|
'codex-readonly': invokeCodex,
|
|
67
74
|
'claude-readonly': invokeClaude,
|
|
68
75
|
'gemini-readonly': invokeGemini,
|
|
69
76
|
'opencode-readonly': invokeOpenCode,
|
|
70
77
|
'cursor-readonly': invokeCursor,
|
|
78
|
+
// Grok (adapters/grok.mjs): the message, the model, the effort and the turn's lease, nothing else.
|
|
79
|
+
'grok-readonly': ({ executable, projectRoot, prompt, timeoutMs, signal, model, effort, lease, scopes, onProgress }) => invokeGrok({ executable, projectRoot, prompt, timeoutMs, signal, model, effort, lease, scopes, onProgress }),
|
|
80
|
+
// Gemini with a key and no CLI (runtime-detection.mjs): only what an API call can take. The
|
|
81
|
+
// project, attachments, a lease and tool servers are the CLI's; capabilities.mjs keeps it at #1.
|
|
82
|
+
'gemini-rest': ({ prompt, model, signal, timeoutMs, onProgress, json }) => invokeGeminiRest({ prompt, model, signal, timeoutMs, onProgress, json }),
|
|
71
83
|
};
|
|
72
84
|
|
|
73
85
|
// What a turn costs against MADRE's local budget. Cache reads are close to
|
|
@@ -133,6 +145,7 @@ export class Room {
|
|
|
133
145
|
#examProgress = null;
|
|
134
146
|
#examStop = false;
|
|
135
147
|
#archivist; // room/archivist: who distils, when, and the bench
|
|
148
|
+
#sessions = {}; // what the server last learned of each agent's session (sessions.updated)
|
|
136
149
|
#vectors; // room/vectors: embeddings filled in the background
|
|
137
150
|
#escalation; // room/escalation: plan steps waiting for the human
|
|
138
151
|
#ghost = new GhostLedger();
|
|
@@ -163,8 +176,10 @@ export class Room {
|
|
|
163
176
|
#attachments = new Attachments();
|
|
164
177
|
#scopeConfig = {};
|
|
165
178
|
#delegation;
|
|
179
|
+
#plansAllowed;
|
|
166
180
|
#privacy = null;
|
|
167
181
|
#toolsForTurn = null;
|
|
182
|
+
#skillsForTurn = null;
|
|
168
183
|
#bishopForTurn = null;
|
|
169
184
|
#linkedForTurn = null;
|
|
170
185
|
// The turns running now, by the id of the answer they will write: which agent, at which mode.
|
|
@@ -178,6 +193,11 @@ export class Room {
|
|
|
178
193
|
#runsEnabled = false;
|
|
179
194
|
#runDesk = new RunDesk();
|
|
180
195
|
#runBusy = false;
|
|
196
|
+
// Lines pressed while another AI held the project or another command ran (2026-11-14, the author:
|
|
197
|
+
// «I could not run the commands because Codex held the project»): they wait their turn, in the
|
|
198
|
+
// order pressed, and run on their own when the project is free.
|
|
199
|
+
#runQueue = [];
|
|
200
|
+
#runQueueTimer = null;
|
|
181
201
|
|
|
182
202
|
constructor({
|
|
183
203
|
store,
|
|
@@ -193,6 +213,7 @@ export class Room {
|
|
|
193
213
|
mother = null,
|
|
194
214
|
privacy = null,
|
|
195
215
|
toolsForTurn = null, // async ({ agent, mode, lease, scratchDir }) => MCP server specs from the modules
|
|
216
|
+
skillsForTurn = null, // async ({ agent, mode, text }) => the project's skills this turn carries (src/skills.mjs)
|
|
196
217
|
bishopForTurn = null, // async ({ agent, mode, text, preview, turn }) => bounded BISHOP context in Salas
|
|
197
218
|
linkedForTurn = null, // async ({ agent, mode, text, preview, turn }) => { text, dynamic } notes a link recalls (3e)
|
|
198
219
|
copilot = null, // () => { until } while the human's copilot window is open (src/room/copilot.mjs)
|
|
@@ -201,6 +222,7 @@ export class Room {
|
|
|
201
222
|
agentTimeouts = {},
|
|
202
223
|
maxMessageChars = 20000,
|
|
203
224
|
delegation = true,
|
|
225
|
+
plansAllowed = null,
|
|
204
226
|
maxPlanSteps = 4,
|
|
205
227
|
maxConcurrentTurns = 3,
|
|
206
228
|
planMaxAgeMs = 300000,
|
|
@@ -226,12 +248,14 @@ export class Room {
|
|
|
226
248
|
this.#mother = mother;
|
|
227
249
|
this.#privacy = privacy;
|
|
228
250
|
this.#toolsForTurn = toolsForTurn;
|
|
251
|
+
this.#skillsForTurn = skillsForTurn;
|
|
229
252
|
this.#bishopForTurn = bishopForTurn;
|
|
230
253
|
this.#linkedForTurn = linkedForTurn;
|
|
231
254
|
this.#invokers = invokers;
|
|
232
255
|
this.#agentTimeouts = agentTimeouts;
|
|
233
256
|
this.#maxMessageChars = maxMessageChars;
|
|
234
257
|
this.#delegation = delegation;
|
|
258
|
+
this.#plansAllowed = typeof plansAllowed === 'function' ? plansAllowed : () => true;
|
|
235
259
|
this.#maxPlanSteps = maxPlanSteps;
|
|
236
260
|
this.#maxConcurrentTurns = maxConcurrentTurns;
|
|
237
261
|
this.#planMaxAgeMs = planMaxAgeMs;
|
|
@@ -242,7 +266,7 @@ export class Room {
|
|
|
242
266
|
this.#budget.seed(historicalEvents, this.#sentinel);
|
|
243
267
|
// What this room has been charged per character, from its own past turns.
|
|
244
268
|
this.#rate = observedRate(historicalEvents);
|
|
245
|
-
this.#vectors = new VectorWorker({ memory, stopped: () => this.#shuttingDown });
|
|
269
|
+
this.#vectors = new VectorWorker({ memory, stopped: () => this.#shuttingDown, busy: () => machineBusy() });
|
|
246
270
|
this.#archivist = new Archivist({
|
|
247
271
|
memory,
|
|
248
272
|
settings: distillDefaults(distill),
|
|
@@ -252,12 +276,15 @@ export class Room {
|
|
|
252
276
|
busyAgents: () => new Set([...this.#turns.values()].map((turn) => turn.agent).filter(Boolean)),
|
|
253
277
|
turnsInFlight: () => this.#turns.size,
|
|
254
278
|
timeoutFor: (id) => this.timeoutFor(id),
|
|
255
|
-
localTimeoutMs: () => this.#agentTimeouts.ollama ??
|
|
279
|
+
localTimeoutMs: () => this.#agentTimeouts.ollama ?? LOCAL_DISTILL_MS,
|
|
256
280
|
projectName: () => basename(this.#projectRoot),
|
|
257
281
|
projectRoot: () => this.#projectRoot,
|
|
258
282
|
emit: (type, payload) => this.#emit(type, payload),
|
|
259
283
|
recordUsage: (agent, usage) => this.#recordUsage(agent, usage),
|
|
260
284
|
stopped: () => this.#shuttingDown,
|
|
285
|
+
// Who MADRE already knows cannot answer: no session, or not installed (L-9).
|
|
286
|
+
machineBusy: () => machineBusy(),
|
|
287
|
+
noSession: () => new Set(Object.entries(this.#sessions).filter(([, one]) => ['signed-out', 'not-installed'].includes(one?.state)).map(([id]) => id)),
|
|
261
288
|
failureMessage,
|
|
262
289
|
},
|
|
263
290
|
});
|
|
@@ -357,6 +384,8 @@ export class Room {
|
|
|
357
384
|
// agents have a session, once the probe that runs at start comes back (QA 1.1.0, NUE-11).
|
|
358
385
|
announce(type, payload) {
|
|
359
386
|
if (!['sessions.updated'].includes(type)) throw new Error(`Not a live announcement: ${type}`);
|
|
387
|
+
// The archivist reads it too: it does not hand a summary to an agent with no session (L-9).
|
|
388
|
+
if (type === 'sessions.updated' && payload?.sessions && typeof payload.sessions === 'object') this.#sessions = { ...payload.sessions };
|
|
360
389
|
return this.#say(type, payload);
|
|
361
390
|
}
|
|
362
391
|
|
|
@@ -447,16 +476,14 @@ export class Room {
|
|
|
447
476
|
}
|
|
448
477
|
|
|
449
478
|
// Called once at start when the channel file was found deleted or altered.
|
|
450
|
-
// She tells the room in code
|
|
451
|
-
//
|
|
479
|
+
// She tells the room in code; each agent reads her words in clear inside its next turn (the
|
|
480
|
+
// <mother> block). Q-31 (2026-11-18): she used to open a turn per agent and each one answered an
|
|
481
|
+
// acknowledgement nobody asked for — seven turns on the person's quota, one of them failing.
|
|
452
482
|
async motherTampered(outcome) {
|
|
453
483
|
if (!this.#mother) return null;
|
|
454
484
|
const alert = await this.#mother.alert('tamper', { project: basename(this.#projectRoot) });
|
|
455
485
|
const crew = this.#agents.filter((agent) => agent.detected && agent.ready && this.#invokers[agent.adapter]).map((agent) => agent.id);
|
|
456
|
-
await this.#emit('mother.alert', { kind: 'tamper', outcome, n: alert.n, at: alert.at, code: alert.code, tampers: this.#mother.tampers, crew, message: `MY CHANNEL WAS ${outcome === 'deleted' ? 'DELETED' : 'ALTERED'}. I HAVE FORGED A NEW SEAL. ${crew.length ? `
|
|
457
|
-
for (const id of crew) {
|
|
458
|
-
await this.#track(this.#dispatch({ messageId: randomUUID(), targetId: id, text: alert.text, requester: 'mother', depth: 1, allowDelegation: false, mode: 1 })).catch((error) => console.error(`MADRE: @${id} did not hear MOTHER: ${error.message}`));
|
|
459
|
-
}
|
|
486
|
+
await this.#emit('mother.alert', { kind: 'tamper', outcome, n: alert.n, at: alert.at, code: alert.code, tampers: this.#mother.tampers, crew, message: `MY CHANNEL WAS ${outcome === 'deleted' ? 'DELETED' : 'ALTERED'}. I HAVE FORGED A NEW SEAL. ${crew.length ? `THE CREW HEARS IT ON ITS NEXT TURN: ${crew.map((id) => `@${id}`).join(', ')}.` : 'NO CREW TO TELL.'}` });
|
|
460
487
|
return { ...alert, crew };
|
|
461
488
|
}
|
|
462
489
|
|
|
@@ -577,13 +604,13 @@ export class Room {
|
|
|
577
604
|
progress: this.#examProgress,
|
|
578
605
|
last,
|
|
579
606
|
can: {
|
|
580
|
-
coverage: { ok: Boolean(this.#memory) && cases.length > 0, why: !this.#memory ? 'the room has no memory' : cases.length ? null : 'no exchange here is long enough to test with yet', method: embedder ? 'meaning' : 'words' },
|
|
581
|
-
consistency: { ok: Boolean(this.#memory), why: this.#memory ? null : 'the room has no memory' },
|
|
607
|
+
coverage: { ok: Boolean(this.#memory) && cases.length > 0, why: !this.#memory ? t('the room has no memory') : cases.length ? null : t('no exchange here is long enough to test with yet'), method: embedder ? 'meaning' : 'words' },
|
|
608
|
+
consistency: { ok: Boolean(this.#memory), why: this.#memory ? null : t('the room has no memory') },
|
|
582
609
|
match: {
|
|
583
610
|
ok: Boolean(this.#memory) && localModel && Boolean(embedder) && cases.some((one) => !one.local),
|
|
584
|
-
why: !localModel ? 'the local model is not running: open MODULES → OLLAMA'
|
|
585
|
-
: !embedder ? 'this test needs embeddings, which are off'
|
|
586
|
-
: cases.some((one) => !one.local) ? null : 'nothing here was answered by an agent other than the local one',
|
|
611
|
+
why: !localModel ? t('the local model is not running: open MODULES → OLLAMA')
|
|
612
|
+
: !embedder ? t('this test needs embeddings, which are off')
|
|
613
|
+
: cases.some((one) => !one.local) ? null : t('nothing here was answered by an agent other than the local one'),
|
|
587
614
|
sample: Math.min(MATCH_SAMPLE, cases.filter((one) => !one.local).length),
|
|
588
615
|
},
|
|
589
616
|
},
|
|
@@ -675,6 +702,10 @@ export class Room {
|
|
|
675
702
|
|
|
676
703
|
stopExam() { if (this.#examRunning === 'match') this.#examStop = true; return { stopping: this.#examRunning }; }
|
|
677
704
|
|
|
705
|
+
// How many real questions agents other than @madre answered in this conversation: what the local
|
|
706
|
+
// model's test (matchExam) has to compare its answers with.
|
|
707
|
+
async answeredByAgents() { return exchanges(await this.#store.readAll()).filter((one) => !one.local).length; }
|
|
708
|
+
|
|
678
709
|
#keepExam(result) {
|
|
679
710
|
let last = {};
|
|
680
711
|
try { last = JSON.parse(this.#memory?.metaGet('exams') ?? '{}'); } catch { last = {}; }
|
|
@@ -765,7 +796,7 @@ export class Room {
|
|
|
765
796
|
// is the human's own #3 for a while: it reaches any agent whose CLI can write.
|
|
766
797
|
const byCopilot = copilot === true && wanted === 3 && this.copilotOn() && Boolean(scopes.write?.capable);
|
|
767
798
|
if (scopes.maxMode < wanted && !byCopilot) return { ok: false, status: 403, mode: wanted, maxMode: scopes.maxMode, error: `@${parsed.target} is capped at #${scopes.maxMode} ${MODES[scopes.maxMode].label}; raise its max mode to #${wanted} in Settings › Permissions to unlock ${MODES[wanted].label}.` };
|
|
768
|
-
if (this.#controlDesk.holder) return { ok: false, status: 409, mode: wanted, maxMode: scopes.maxMode, error: `@${this.#controlDesk.holder.agent} already
|
|
799
|
+
if (this.#controlDesk.holder) return { ok: false, status: 409, mode: wanted, maxMode: scopes.maxMode, error: `@${this.#controlDesk.holder.agent} is already using #${this.#controlDesk.holder.mode ?? 3} ${(this.#controlDesk.holder.mode ?? 3) === 4 ? 'Full access' : 'Can edit'} in this project, and only one AI can at a time. Wait for it to finish, or press Stop all to take it back.` };
|
|
769
800
|
return { ok: true, mode: wanted, maxMode: scopes.maxMode, agent };
|
|
770
801
|
}
|
|
771
802
|
// #2 above the agent's ceiling still goes out: the room answers read-only
|
|
@@ -843,6 +874,7 @@ export class Room {
|
|
|
843
874
|
if (agentId === 'codex') return (await readCodexEfforts({ home: this.#codexHome }).catch(() => null))?.model ?? null;
|
|
844
875
|
if (agentId === 'opencode') return process.env.PULSE_OPENCODE_MODEL || null;
|
|
845
876
|
if (agentId === 'cursor') return process.env.PULSE_CURSOR_MODEL || null;
|
|
877
|
+
if (agentId === 'grok') return process.env.PULSE_GROK_MODEL || null;
|
|
846
878
|
return null;
|
|
847
879
|
}
|
|
848
880
|
|
|
@@ -905,15 +937,21 @@ export class Room {
|
|
|
905
937
|
// The human pressed one line of a ```pulse-run an agent wrote. The client names the request and
|
|
906
938
|
// the line, never the command: what runs is read back from the room's own record of what the
|
|
907
939
|
// agent asked, so a page cannot run anything that was not shown to the human as a button.
|
|
908
|
-
async runRequested({ responseMessageId, index, returnCap = 3, auto = false }) {
|
|
940
|
+
async runRequested({ responseMessageId, index, returnCap = 3, auto = false, fromQueue = false }) {
|
|
909
941
|
if (!this.#runsEnabled) return { ok: false, status: 412, error: t('Command requests are off. Enable them in MODULES.') };
|
|
910
942
|
const events = await this.#store.readAll();
|
|
911
943
|
const request = events.find((event) => event.type === 'run.requested' && event.payload.responseMessageId === responseMessageId)?.payload;
|
|
912
944
|
const command = request?.commands?.[index];
|
|
913
945
|
if (!command) return { ok: false, status: 404, error: t('That command request is not in this project.') };
|
|
914
946
|
if (!command.argv) return { ok: false, status: 422, error: `That line does not run: it ${whyText(command)}.` };
|
|
915
|
-
|
|
916
|
-
if (this.#
|
|
947
|
+
// Busy: the line waits in line and runs by itself when its turn comes; the press is the yes.
|
|
948
|
+
if (this.#runBusy || this.#runDesk.busy || this.#controlDesk.holder || (this.#runQueue.length && !fromQueue)) {
|
|
949
|
+
if (!auto && !this.#runQueue.some((one) => one.responseMessageId === responseMessageId && one.index === index)) {
|
|
950
|
+
this.#runQueue.push({ responseMessageId, index, returnCap });
|
|
951
|
+
this.#drainRunsSoon();
|
|
952
|
+
}
|
|
953
|
+
return { ok: true, status: 202, result: { queued: true, behind: this.#controlDesk.holder?.agent ?? null, ahead: this.#runQueue.length - 1 } };
|
|
954
|
+
}
|
|
917
955
|
// A line pressed from a phone hands its results back at #2 at most, the phone's own ceiling.
|
|
918
956
|
this.#returnCap.set(responseMessageId, Math.min(this.#returnCap.get(responseMessageId) ?? 3, Number(returnCap) || 1));
|
|
919
957
|
// Taken before the first await below: two presses in a row must not both get through.
|
|
@@ -921,6 +959,23 @@ export class Room {
|
|
|
921
959
|
try { return await this.#runCommand({ request, command, responseMessageId, index, auto }); } finally { this.#runBusy = false; }
|
|
922
960
|
}
|
|
923
961
|
|
|
962
|
+
// The waiting lines, one after another, as soon as nobody holds the project and nothing runs.
|
|
963
|
+
#drainRunsSoon() {
|
|
964
|
+
if (this.#runQueueTimer || !this.#runQueue.length) return;
|
|
965
|
+
this.#runQueueTimer = setInterval(() => {
|
|
966
|
+
if (!this.#runQueue.length) { clearInterval(this.#runQueueTimer); this.#runQueueTimer = null; return; }
|
|
967
|
+
if (this.#runBusy || this.#runDesk.busy || this.#controlDesk.holder || this.#shuttingDown) return;
|
|
968
|
+
const next = this.#runQueue.shift();
|
|
969
|
+
void this.runRequested({ ...next, fromQueue: true }).catch((error) => console.error(`MADRE could not run a waiting command: ${error.message}`));
|
|
970
|
+
}, 1500);
|
|
971
|
+
this.#runQueueTimer.unref?.();
|
|
972
|
+
}
|
|
973
|
+
// STOP ALL empties the line too: nothing pressed before it runs after it.
|
|
974
|
+
#dropRunQueue() {
|
|
975
|
+
this.#runQueue = [];
|
|
976
|
+
if (this.#runQueueTimer) { clearInterval(this.#runQueueTimer); this.#runQueueTimer = null; }
|
|
977
|
+
}
|
|
978
|
+
|
|
924
979
|
async #runCommand({ request, command, responseMessageId, index, auto = false }) {
|
|
925
980
|
// `auto`: the copilot ran it, nobody pressed it; the card says so.
|
|
926
981
|
const run = { responseMessageId, index, agent: request.agent, line: command.line, ...(auto ? { auto: 'copilot' } : {}) };
|
|
@@ -1034,7 +1089,8 @@ export class Room {
|
|
|
1034
1089
|
const said = settlement.done
|
|
1035
1090
|
? n === 1 ? t('The command you asked for ran. Go on with what you proposed.') : t('The {n} commands you asked for ran. Go on with what you proposed.', { n })
|
|
1036
1091
|
: t('{n} of the {total} commands you asked for ran. Go on with what you proposed.', { n, total });
|
|
1037
|
-
|
|
1092
|
+
// No message number: beside the modes #0–#4 it read as one (Q-14).
|
|
1093
|
+
const text = `↩ @${agentId}: “${quoted.length > 120 ? `${quoted.slice(0, 119)}…` : quoted}”\n${said}`;
|
|
1038
1094
|
const returned = returnedBlock({ settlement, asking: asked?.text ?? null, said: reply?.payload?.text ?? null, replySequence: reply?.sequence ?? null });
|
|
1039
1095
|
await this.#accept({
|
|
1040
1096
|
text, target: agentId, mode,
|
|
@@ -1335,8 +1391,11 @@ export class Room {
|
|
|
1335
1391
|
return { messageId, responseMessageId: null };
|
|
1336
1392
|
}
|
|
1337
1393
|
// An order never delegates, so a plan already running here has nothing to warn about.
|
|
1338
|
-
|
|
1339
|
-
|
|
1394
|
+
// The same question to several AIs at once (`together`): each answers for itself. Left free to
|
|
1395
|
+
// hand out steps, one of them read «one idea each» as a job for the whole crew and brought in an
|
|
1396
|
+
// AI nobody named (2026-11-12, the author on the «two AIs» first step).
|
|
1397
|
+
let allowDelegation = !order && !(typeof together === 'string' && together);
|
|
1398
|
+
if (!order && allowDelegation && this.#plans.size > 0) {
|
|
1340
1399
|
allowDelegation = false;
|
|
1341
1400
|
await this.#alert('plan-active', `A plan by @${[...this.#plans.values()][0].orchestrator} is still running. Your message will be answered, but no second plan will start. Type STOPALL to halt every agent.`, `plan-active:${messageId}`);
|
|
1342
1401
|
}
|
|
@@ -1457,7 +1516,7 @@ export class Room {
|
|
|
1457
1516
|
}));
|
|
1458
1517
|
const plans = [...this.#plans.values()].map((plan) => ({
|
|
1459
1518
|
kind: 'plan', planId: plan.planId, orchestrator: plan.orchestrator, step: plan.step, total: plan.steps.length + (plan.closing ? 1 : 0),
|
|
1460
|
-
startedAt: plan.startedAt, steps: plan.steps.map((one) => ({ agent: one.agent, text: clip(one.text, 160) })),
|
|
1519
|
+
startedAt: plan.startedAt, steps: plan.steps.map((one) => ({ agent: one.agent, text: clip(one.text, 160), ...(Number.isInteger(one.mode) ? { mode: one.mode } : {}) })),
|
|
1461
1520
|
}));
|
|
1462
1521
|
const runs = this.#runDesk.live().map((one) => ({ kind: 'run', ...one }));
|
|
1463
1522
|
return [...plans, ...turns, ...runs];
|
|
@@ -1469,10 +1528,13 @@ export class Room {
|
|
|
1469
1528
|
const turns = this.#turns.size;
|
|
1470
1529
|
for (const plan of this.#plans.values()) plan.stopped = reason;
|
|
1471
1530
|
this.#escalation.settleAll(null, 'stopped');
|
|
1531
|
+
this.#dropRunQueue();
|
|
1472
1532
|
// Results waiting to go back stay with the human: STOP ALL means nothing starts by itself.
|
|
1473
1533
|
for (const id of [...this.#returns.keys(), ...this.#returning.keys()]) this.#dropped.add(id);
|
|
1474
1534
|
this.#returns.clear();
|
|
1475
|
-
|
|
1535
|
+
// Marked as stopTurn marks its one turn: a turn the human braked is not a failure to diagnose,
|
|
1536
|
+
// and every turn STOP ALL cut reached the diagnostics as one (D-7, 2026-11-03).
|
|
1537
|
+
for (const turn of this.#turns.values()) { turn.stoppedByHuman = true; turn.controller.abort(reason); }
|
|
1476
1538
|
this.#runDesk.stop('STOPALL');
|
|
1477
1539
|
await this.#emit('room.stopped', { reason, plans, turns, agents: [...new Set([...this.#turns.values()].map((turn) => turn.agent))] });
|
|
1478
1540
|
await Promise.allSettled([...this.#turns.values()].map((turn) => turn.promise));
|
|
@@ -1516,7 +1578,7 @@ export class Room {
|
|
|
1516
1578
|
plan.stopped = reason;
|
|
1517
1579
|
this.#escalation.settleAll(planId, 'stopped');
|
|
1518
1580
|
for (const turn of this.#turns.values()) {
|
|
1519
|
-
if (turn.planId === planId) turn.controller.abort(reason);
|
|
1581
|
+
if (turn.planId === planId) { turn.stoppedByHuman = true; turn.controller.abort(reason); }
|
|
1520
1582
|
}
|
|
1521
1583
|
return true;
|
|
1522
1584
|
}
|
|
@@ -1539,15 +1601,22 @@ export class Room {
|
|
|
1539
1601
|
await this.#emit('message.failed', { messageId, target: targetId, planId, error: `${agent.label} was detected, but its MADRE adapter is not enabled yet.` });
|
|
1540
1602
|
return null;
|
|
1541
1603
|
}
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1604
|
+
// Codex can change its provider in config.toml while this room is open. Recheck before
|
|
1605
|
+
// reading any conversation or memory, then keep the roster's route current as well.
|
|
1606
|
+
const route = agent.id === 'codex' && agent.route ? await codexRoute() : agent.route;
|
|
1607
|
+
if (agent.id === 'codex' && agent.route) agent.route = route;
|
|
1608
|
+
if (route?.custom && !route.allowed) {
|
|
1609
|
+
const destination = route.host ?? 'an unrecognised host';
|
|
1610
|
+
const source = route.source ?? 'a custom endpoint setting';
|
|
1545
1611
|
const official = agent.id === 'codex' ? 'OpenAI' : agent.id === 'claude' ? 'Anthropic' : 'the agent\'s official service';
|
|
1612
|
+
const advice = route.host
|
|
1613
|
+
? `Remove that override to use the official service, or set PULSE_ALLOW_CUSTOM_AGENT_ENDPOINTS=${agent.id} only if you trust that endpoint.`
|
|
1614
|
+
: 'Remove that override to use the official service.';
|
|
1546
1615
|
await this.#emit('message.failed', {
|
|
1547
1616
|
messageId,
|
|
1548
1617
|
target: targetId,
|
|
1549
1618
|
planId,
|
|
1550
|
-
error: `MADRE blocked @${agent.id} before sending the briefing: ${source} points to ${destination}, not ${official}.
|
|
1619
|
+
error: `MADRE blocked @${agent.id} before sending the briefing: ${source} points to ${destination}, not ${official}. ${advice}`,
|
|
1551
1620
|
});
|
|
1552
1621
|
return null;
|
|
1553
1622
|
}
|
|
@@ -1639,6 +1708,7 @@ export class Room {
|
|
|
1639
1708
|
? await this.#toolsForTurn({ agent: agent.id, mode, lease: null, scratchDir: null }).catch(() => [])
|
|
1640
1709
|
: [];
|
|
1641
1710
|
const bishop = this.#bishopForTurn ? await this.#bishopForTurn({ agent: agent.id, mode, text, preview: true }).catch(() => null) : null;
|
|
1711
|
+
const skills = this.#skillsForTurn && agent.adapter !== 'madre-local' ? await this.#skillsForTurn({ agent: agent.id, mode, text, preview: true }).catch(() => []) : [];
|
|
1642
1712
|
// Recall from links reads the other room when the turn runs; the preview only says it will.
|
|
1643
1713
|
const linkedPreview = this.#linkedForTurn && agent.adapter !== 'madre-local' && mode !== 0 ? await this.#linkedForTurn({ agent: agent.id, mode, text, preview: true }).catch(() => null) : null;
|
|
1644
1714
|
const scopes = this.scopesFor(agent.id);
|
|
@@ -1663,7 +1733,7 @@ export class Room {
|
|
|
1663
1733
|
context: built.context, recall: built.recall, memories: built.memories,
|
|
1664
1734
|
attachments: [], references: [], lease,
|
|
1665
1735
|
scopes: { web: scopes.web.enabled && scopes.web.wired, imageGen: scopes.imageGen.enabled && scopes.imageGen.wired },
|
|
1666
|
-
ash: ash === true && this.ashEnabled(), choices: this.#choicesEnabled && mode !== 0, runs: this.#runsEnabled && mode !== 0 && mode < 4, mode, escalation: null, mcpServers, bishop,
|
|
1736
|
+
ash: ash === true && this.ashEnabled(), choices: this.#choicesEnabled && mode !== 0, runs: this.#runsEnabled && mode !== 0 && mode < 4, mode, escalation: null, mcpServers, bishop, skills,
|
|
1667
1737
|
});
|
|
1668
1738
|
// Each block with what put it here and what would take it away, so "read, never written" can
|
|
1669
1739
|
// be checked one block at a time instead of believed.
|
|
@@ -1697,7 +1767,14 @@ export class Room {
|
|
|
1697
1767
|
if (agent.local || agent.adapter === 'madre-local') {
|
|
1698
1768
|
return {
|
|
1699
1769
|
agent: agent.id, label: agent.label, local: true,
|
|
1700
|
-
says: 'No
|
|
1770
|
+
says: t('No program is opened for @madre: it is the AI on your computer, and it answers inside MADRE through Ollama.'),
|
|
1771
|
+
mcpServers: [], env: [], isolation: [],
|
|
1772
|
+
};
|
|
1773
|
+
}
|
|
1774
|
+
if (agent.adapter === 'gemini-rest') {
|
|
1775
|
+
return {
|
|
1776
|
+
agent: agent.id, label: agent.label, local: false,
|
|
1777
|
+
says: t('No process is started for @gemini: the Gemini CLI is not installed, so MADRE sends the briefing to Google\'s Gemini API with your key and shows the answer. It cannot read the project, see attachments or write; install the Gemini CLI for that.'),
|
|
1701
1778
|
mcpServers: [], env: [], isolation: [],
|
|
1702
1779
|
};
|
|
1703
1780
|
}
|
|
@@ -1711,7 +1788,8 @@ export class Room {
|
|
|
1711
1788
|
: agent.id === 'gemini' ? buildGeminiArgs({ ...shared, policyPath: t('<written for this turn, deleted after it>'), attachmentsDir: null })
|
|
1712
1789
|
: agent.id === 'opencode' ? buildOpenCodeArgs(shared)
|
|
1713
1790
|
: agent.id === 'cursor' ? buildCursorArgs(shared)
|
|
1714
|
-
:
|
|
1791
|
+
: agent.id === 'grok' ? buildGrokArgs({ ...shared, promptFile: t('<the briefing, in a file written for this turn and deleted after it>') })
|
|
1792
|
+
: null;
|
|
1715
1793
|
if (!args) return { agent: agent.id, label: agent.label, local: false, says: t('MADRE has no adapter for @{agent}.', { agent: agent.id }), mcpServers: [], env: [], isolation: [] };
|
|
1716
1794
|
const isolation = {
|
|
1717
1795
|
codex: [t('--ephemeral: the run keeps no session of its own, so nothing said here reaches another project.')],
|
|
@@ -1719,10 +1797,12 @@ export class Room {
|
|
|
1719
1797
|
gemini: [t('GEMINI_CLI_HOME points at a temporary home made for this turn and removed after it, so settings, hooks and extensions come from there and not from yours.'), t('GEMINI_CLI_NO_RELAUNCH keeps the launcher from spawning a second process MADRE could not stop.')],
|
|
1720
1798
|
opencode: [t('The run is given the model you chose and nothing else of your session.')],
|
|
1721
1799
|
cursor: [t('#0 and #1: --mode ask, Cursor\'s read-only mode, whatever its own settings say; no edits and no commands. #2 and #3: its agent mode with --force, writing allowed and every command denied. #4: commands allowed too. The places nobody writes stay denied at every mode, and MADRE locks and puts them back itself.'), t('CURSOR_CONFIG_DIR points at a configuration made for this turn and removed after it, with only what the mode you chose allows. The sign-in stays in the system keychain.')],
|
|
1800
|
+
grok: [t('#0 and #1: only the tools that read (--tools read_file,list_dir,grep) and --sandbox read-only. #2 and #3: its edit and write tools under --permission-mode dontAsk, writing allowed and the terminal denied, inside --sandbox workspace. #4: the terminal too, with --always-approve. At every mode the places nobody writes are denied one rule at a time.'), t('The folder is not trusted for the turn, and hooks, skills and servers from Claude and Cursor are not loaded. Grok keeps the conversation in its own history.')],
|
|
1722
1801
|
}[agent.id] ?? [];
|
|
1723
1802
|
const env = {
|
|
1724
1803
|
gemini: [{ name: 'GEMINI_CLI_HOME', note: t('the temporary home for this turn') }, { name: 'GEMINI_CLI_NO_RELAUNCH', note: t('so the launcher stays killable') }],
|
|
1725
1804
|
cursor: [{ name: 'CURSOR_CONFIG_DIR', note: t('the configuration for this turn, from the mode you chose') }, { name: 'NO_OPEN_BROWSER', note: t('a turn never opens a page') }],
|
|
1805
|
+
grok: [{ name: 'GROK_CLAUDE_*_ENABLED, GROK_CURSOR_*_ENABLED', note: t('false: nothing of Claude\'s or Cursor\'s is loaded') }, { name: 'GROK_MEMORY', note: t('0: Grok\'s own memory stays off; the project\'s is MADRE\'s') }, { name: 'GROK_DISABLE_AUTOUPDATER', note: t('1: a turn never updates the CLI') }],
|
|
1726
1806
|
}[agent.id] ?? [];
|
|
1727
1807
|
return {
|
|
1728
1808
|
agent: agent.id, label: agent.label, local: false,
|
|
@@ -1762,6 +1842,7 @@ export class Room {
|
|
|
1762
1842
|
controlHolder: this.#controlDesk.holder?.agent ?? null,
|
|
1763
1843
|
privacyMarker: this.#privacy?.marker ?? '[ENTIDAD-ORG]',
|
|
1764
1844
|
sdk: input.lease?.sdk ?? sdkPaths(),
|
|
1845
|
+
skillGuide: skillGuide(),
|
|
1765
1846
|
madreModel: this.#agents.find((agent) => agent.id === 'madre' && agent.ready)?.version ?? null,
|
|
1766
1847
|
});
|
|
1767
1848
|
}
|
|
@@ -1771,7 +1852,12 @@ export class Room {
|
|
|
1771
1852
|
// try that reports failures, with the room showing «writing…» until MADRE was closed.
|
|
1772
1853
|
async #couldNotSeat({ messageId, agent, planId, error }) {
|
|
1773
1854
|
const said = String(error?.message ?? error ?? '').split('\n').filter(Boolean).slice(0, 2).join(' ').slice(0, 300);
|
|
1774
|
-
|
|
1855
|
+
// No git on this computer at all (D-5, Linux copies of 1.1.2): said as what to install, not as
|
|
1856
|
+
// «spawn git ENOENT».
|
|
1857
|
+
const noGit = error?.code === 'ENOENT' && /\bgit\b/.test(`${error?.path ?? ''} ${error?.syscall ?? ''}`);
|
|
1858
|
+
const text = noGit
|
|
1859
|
+
? t('This computer does not have git, which MADRE needs to take the restore point before @{agent} writes, so nothing was changed. Install git and send it again.', { agent: agent.id })
|
|
1860
|
+
: t('MADRE could not take the restore point before @{agent} writes, so nothing was changed: {error}', { agent: agent.id, error: said });
|
|
1775
1861
|
await this.#emit('message.failed', { messageId, target: agent.id, planId, error: this.#privacy ? this.#privacy.redact(text).text : text });
|
|
1776
1862
|
return null;
|
|
1777
1863
|
}
|
|
@@ -1780,6 +1866,8 @@ export class Room {
|
|
|
1780
1866
|
// The lease is the human's; what each agent may do inside it is that
|
|
1781
1867
|
// agent's own enabled scopes. A delegate without file creation runs
|
|
1782
1868
|
// read-only even while the plan holds a lease.
|
|
1869
|
+
// Whose quota is OpenCode's: the provider of the model it answers with (quota-sources.mjs).
|
|
1870
|
+
if (agent.id === 'opencode') noteOpenCodeModel(model ?? process.env.PULSE_OPENCODE_MODEL);
|
|
1783
1871
|
const agentScopes = this.scopesFor(agent.id);
|
|
1784
1872
|
const enabled = Object.fromEntries(SCOPES.map((scope) => [scope, agentScopes[scope].enabled && agentScopes[scope].wired]));
|
|
1785
1873
|
// Web access is a standing scope the human switched on for this agent;
|
|
@@ -1789,15 +1877,21 @@ export class Room {
|
|
|
1789
1877
|
let controlRun = null;
|
|
1790
1878
|
let createRun = null;
|
|
1791
1879
|
let responseMessageId = null;
|
|
1792
|
-
// The copilot's #3 reaches past an agent's max mode, never past what its CLI can write.
|
|
1793
|
-
|
|
1880
|
+
// The copilot's #3 reaches past an agent's max mode, never past what its CLI can write. The
|
|
1881
|
+
// window is read once, here: the turn may wait for the project before its prompt is written,
|
|
1882
|
+
// and a window that closed in that wait read as null there and failed the turn (D-16, a copy
|
|
1883
|
+
// in WSL, 2026-11-05). A turn that started under the window ends under it, as one running does.
|
|
1884
|
+
const copilotWindow = copilot === true && mode === 3 ? this.#copilotNow() : null;
|
|
1885
|
+
const asCopilot = Boolean(copilotWindow) && Boolean(agentScopes.write?.capable);
|
|
1794
1886
|
if (mode >= 3 && (requester === 'you' || planId) && depth <= 1 && (agentScopes.maxMode >= mode || asCopilot) && (enabled.write || asCopilot)) {
|
|
1795
1887
|
// CONTROL: the project itself is the writable root, and a checkpoint
|
|
1796
1888
|
// taken now makes every change of this turn reversible. A plan step gets
|
|
1797
1889
|
// it when the orchestrator, itself in #3, named #3 for that step.
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1890
|
+
// Another AI holds the project: this turn waits its turn for it (2026-11-14, the author: a plan
|
|
1891
|
+
// step that needed #4 answered read-only and «could not run» what it was asked). The wait is
|
|
1892
|
+
// said in the room (write.waiting), STOP ALL ends it, and a plan starts only after the turn
|
|
1893
|
+
// that made it let go of the project, so a step never waits on its own orchestrator.
|
|
1894
|
+
{
|
|
1801
1895
|
await this.#sayWaitingToWrite({ messageId, agent });
|
|
1802
1896
|
const seat = await this.#controlDesk.begin({ agent, messageId, enabledScopes: enabled, mode, signal }).catch((error) => (error?.code === 'ABORT_ERR' ? null : { failed: error }));
|
|
1803
1897
|
if (!seat) { await this.#emit('message.failed', { messageId, target: agent.id, planId, error: `Stopped while waiting for the project: another turn was writing in it.`, stopped: true }); return null; }
|
|
@@ -1847,7 +1941,8 @@ export class Room {
|
|
|
1847
1941
|
turnScopes.imageGen = Boolean(lease?.scopes?.imageGen);
|
|
1848
1942
|
// The step asks for files but nobody granted a lease: say so now, with a
|
|
1849
1943
|
// way out, instead of letting the agent's refusal be the only signal.
|
|
1850
|
-
|
|
1944
|
+
// Only for an agent that could have created it: one that reads at every mode has no «Create» to turn on.
|
|
1945
|
+
if (!lease && !sharedLease && !escalation && capabilityOf(agent.id).write && looksLikeCreation(text)) {
|
|
1851
1946
|
await this.#emit('lease.missing', {
|
|
1852
1947
|
messageId,
|
|
1853
1948
|
agent: agent.id,
|
|
@@ -1862,7 +1957,7 @@ export class Room {
|
|
|
1862
1957
|
const native = Boolean(CAPABILITIES[agent.id]?.imageGen);
|
|
1863
1958
|
const studio = imageModuleState();
|
|
1864
1959
|
const imageStudio = lease?.scopes?.imageGen && enabled.imageGen && !native && studio.enabled
|
|
1865
|
-
? imageStudioFor({ enabled: true, model: studio.model, outDir: lease.scratchDir ? joinPath(this.#projectRoot, lease.scratchDir) : lease.outDir })
|
|
1960
|
+
? imageStudioFor({ enabled: true, model: studio.model, stateRoot: studio.stateRoot, home: studio.home, outDir: lease.scratchDir ? joinPath(this.#projectRoot, lease.scratchDir) : lease.outDir })
|
|
1866
1961
|
: null;
|
|
1867
1962
|
// The turn's effective mode: #0 for ghosts, #3 in control, #2 only while it holds a lease.
|
|
1868
1963
|
const turnMode = mode === 0 ? 0 : controlRun ? controlRun.mode : lease ? 2 : 1;
|
|
@@ -1880,12 +1975,17 @@ export class Room {
|
|
|
1880
1975
|
this.#liveTurns.set(responseMessageId, { agent: agent.id, mode: turnMode });
|
|
1881
1976
|
const notesBefore = this.#memory ? this.#memory.maxMemoryId() : 0;
|
|
1882
1977
|
const others = this.delegatesFor(agent.id);
|
|
1883
|
-
const mayDelegate = allowDelegation && this.#delegation && depth === 0;
|
|
1978
|
+
const mayDelegate = allowDelegation && this.#delegation && depth === 0 && this.#plansAllowed();
|
|
1884
1979
|
// Tools the modules hand to this turn (a browser, say), attached to the CLI for this run only.
|
|
1885
1980
|
const mcpServers = this.#toolsForTurn && agent.adapter !== 'madre-local'
|
|
1886
1981
|
? await this.#toolsForTurn({ agent: agent.id, mode: turnMode, text, turn: responseMessageId, lease, scratchDir: lease?.scratchDir ? joinPath(this.#projectRoot, lease.scratchDir) : null, servers: this.#runDesk.serving().filter((one) => !one.network).map((one) => one.port) }).catch(() => [])
|
|
1887
1982
|
: [];
|
|
1888
1983
|
const bishop = this.#bishopForTurn ? await this.#bishopForTurn({ agent: agent.id, mode: turnMode, text, turn: responseMessageId }).catch(() => null) : null;
|
|
1984
|
+
// Ways of working the human keeps for this project (H-2). Not for @madre: its briefing is its
|
|
1985
|
+
// own. A skill that fails to be read hands nothing and the turn goes on without it.
|
|
1986
|
+
const skills = this.#skillsForTurn && agent.adapter !== 'madre-local'
|
|
1987
|
+
? await this.#skillsForTurn({ agent: agent.id, mode: turnMode, text, turn: responseMessageId }).catch(() => [])
|
|
1988
|
+
: [];
|
|
1889
1989
|
// Notes a link with automatic recall brings to this turn (fase 3e): never in GHOST, never for
|
|
1890
1990
|
// @madre (its briefing is its own), bounded by the module and counted as readings.
|
|
1891
1991
|
const linked = this.#linkedForTurn && agent.adapter !== 'madre-local' && turnMode !== 0
|
|
@@ -1893,7 +1993,10 @@ export class Room {
|
|
|
1893
1993
|
: null;
|
|
1894
1994
|
// The prompt and the shape it was built from: one is sent, the other is kept until the CLI
|
|
1895
1995
|
// says what it cost, so the bill can be attributed to the blocks that caused it.
|
|
1896
|
-
|
|
1996
|
+
// Said in the room while the turn works: which way of working went in, and why. A skill the
|
|
1997
|
+
// person never sees is a skill they cannot switch off when it was the wrong one.
|
|
1998
|
+
if (skills.length) this.#say('turn.skills', { messageId, agent: agent.id, skills: skills.map(({ id, name, state, why }) => ({ id, name, state, why })) });
|
|
1999
|
+
const shaped = this.#promptFor({ agent, text, requester, depth, allowDelegation, context, recall, memories, attachments, references, lease, scopes: turnScopes, imageStudio, ash, skills, choices: this.#choicesEnabled && turnMode !== 0, runs: this.#runsEnabled && turnMode !== 0 && turnMode < 4, mode: turnMode, escalation, mcpServers, bishop, linked, returned, copilot: asCopilot && controlRun ? copilotBrief(copilotWindow) : null, sharedLeaseHint: sharedLease && !lease ? 'A creation lease is active for this plan, but file creation is not enabled for you: answer without creating files and say so if asked to create one.' : null });
|
|
1897
2000
|
this.#promptShape.set(responseMessageId, { parts: shaped.parts, spared: shaped.spared, servers: [this.#memoryServer?.name, ...mcpServers.map((server) => server.name)].filter(Boolean) });
|
|
1898
2001
|
// What this turn is about to read, said while it is still reading it. The size is exact;
|
|
1899
2002
|
// only the conversion to tokens is an estimate, and it is made at this room's own rate.
|
|
@@ -1907,7 +2010,18 @@ export class Room {
|
|
|
1907
2010
|
// when what they are doing changes, through the same privacy guard as the answer.
|
|
1908
2011
|
let helpersSaid = '';
|
|
1909
2012
|
const keepHelpers = (list) => keptSubagents(list, { redact: (said) => (this.#privacy ? this.#privacy.redact(said).text : said) });
|
|
1910
|
-
|
|
2013
|
+
// And its steps, as the CLI says them (src/adapters/steps.mjs): what it reads, searches,
|
|
2014
|
+
// changes and runs, said again only when there is a new one, through the privacy guard.
|
|
2015
|
+
let stepsSaid = '';
|
|
2016
|
+
const onProgress = ({ chars, subagents, steps }) => {
|
|
2017
|
+
if (Array.isArray(steps) && steps.length) {
|
|
2018
|
+
const kept = steps.slice(-12).map(({ kind, what }) => ({ kind, what: what && this.#privacy ? this.#privacy.redact(what).text : what }));
|
|
2019
|
+
const key = JSON.stringify(kept);
|
|
2020
|
+
if (key !== stepsSaid) {
|
|
2021
|
+
stepsSaid = key;
|
|
2022
|
+
this.#say('turn.steps', { messageId, agent: agent.id, steps: kept, count: steps.length });
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
1911
2025
|
if (Array.isArray(subagents) && subagents.length) {
|
|
1912
2026
|
const kept = keepHelpers(subagents);
|
|
1913
2027
|
const key = JSON.stringify(kept);
|
|
@@ -1955,6 +2069,13 @@ export class Room {
|
|
|
1955
2069
|
// the archivist or any other agent can see it. The reply says how many, not which.
|
|
1956
2070
|
const guarded = this.#privacy?.redact(result.text ?? '') ?? { text: result.text, hits: 0 };
|
|
1957
2071
|
if (guarded.hits) result.text = guarded.text;
|
|
2072
|
+
// «What changed»: the closing line a writing turn was asked for leaves the reply here, before
|
|
2073
|
+
// anything reads it (the plan parser, the buttons, the archivist), and travels beside it.
|
|
2074
|
+
const toldChanges = takeChangeSummary(result.text);
|
|
2075
|
+
if (toldChanges.text !== String(result.text ?? '')) result.text = toldChanges.text;
|
|
2076
|
+
// The modules it says it needs leave the reply too, and ride beside it for the page to offer.
|
|
2077
|
+
const toldNeeds = takeModuleNeeds(result.text);
|
|
2078
|
+
if (toldNeeds.text !== String(result.text ?? '')) result.text = toldNeeds.text;
|
|
1958
2079
|
// CREATE: what appeared stays and is shown; what existed before is put back and said.
|
|
1959
2080
|
const createChanges = createRun ? await this.#controlDesk.settleOrSay(createRun) : null;
|
|
1960
2081
|
// Images an agent's own tool made outside the project (Codex keeps them under its home) come
|
|
@@ -2035,6 +2156,10 @@ export class Room {
|
|
|
2035
2156
|
copilot: asCopilot && controlRun ? true : undefined,
|
|
2036
2157
|
leaseId: lease?.leaseId,
|
|
2037
2158
|
artifacts: artifacts.length ? artifacts : undefined,
|
|
2159
|
+
// What the turn changed, said for the card under the reply: its restore point, and the
|
|
2160
|
+
// agent's own sentence when nothing it did was put back (src/room/changes.mjs).
|
|
2161
|
+
changes: turnChanges({ summary: toldChanges.summary, created: artifacts, create: createChanges, control: controlChanges }) ?? undefined,
|
|
2162
|
+
needsModules: toldNeeds.needs.length ? toldNeeds.needs : undefined,
|
|
2038
2163
|
delegates: directives.steps.length ? directives.steps.map((step) => step.agent) : undefined,
|
|
2039
2164
|
// Who helped, from the CLI's own subagents: folded under the answer («Helped by…»).
|
|
2040
2165
|
subagents: keepHelpers(result.subagents),
|
|
@@ -2045,16 +2170,23 @@ export class Room {
|
|
|
2045
2170
|
}
|
|
2046
2171
|
if (asked) await this.#emit('choice.offered', { messageId, responseMessageId, agent: agent.id, question: asked.question, options: asked.options, recommended: asked.recommended ?? undefined, modes: asked.modes ?? undefined });
|
|
2047
2172
|
if (requested) {
|
|
2173
|
+
await attachCommandScripts(requested.commands, { projectRoot: this.#projectRoot });
|
|
2048
2174
|
await this.#emit('run.requested', { messageId, responseMessageId, agent: agent.id, reason: requested.reason, commands: requested.commands, mode: turnMode, copilot: asCopilot && controlRun ? true : undefined });
|
|
2049
2175
|
if (asCopilot && controlRun) this.#copilotRuns.push(responseMessageId);
|
|
2050
2176
|
}
|
|
2051
2177
|
if (guarded.hits) await this.#emit('privacy.redacted', { agent: agent.id, messageId, responseMessageId, hits: guarded.hits, kinds: guarded.kinds, marker: this.#privacy.marker });
|
|
2052
2178
|
if (artifacts.length) {
|
|
2053
|
-
|
|
2179
|
+
// A CREATE turn's restore point goes with what it made: UNDO takes it away again (2026-11-11).
|
|
2180
|
+
await this.#emit('artifacts.created', { leaseId: lease.leaseId, messageId, responseMessageId, agent: agent.id, outDir: lease.relativeDir, files: artifacts, checkpointId: createChanges?.checkpointId ?? undefined });
|
|
2054
2181
|
// A <id>.module.mjs is an agent proposing a module: the human installs it from the room, or not.
|
|
2055
2182
|
for (const file of artifacts.filter((item) => isModuleFile(item.path))) {
|
|
2056
2183
|
await this.#emit('module.proposed', { agent: agent.id, messageId, responseMessageId, path: file.path, name: file.name });
|
|
2057
2184
|
}
|
|
2185
|
+
// And a <id>.habilidad.md is one proposing a way of working (H-6). Same rule: it writes, the
|
|
2186
|
+
// person installs.
|
|
2187
|
+
for (const file of artifacts.filter((item) => isSkillFile(item.path))) {
|
|
2188
|
+
await this.#emit('skill.proposed', { agent: agent.id, messageId, responseMessageId, path: file.path, name: file.name, id: skillIdOf(file.path) });
|
|
2189
|
+
}
|
|
2058
2190
|
}
|
|
2059
2191
|
if (createChanges && (createChanges.existingReverted.length || createChanges.forbiddenReverted.length)) {
|
|
2060
2192
|
await this.#emit('create.reverted', { checkpointId: createChanges.checkpointId, agent: agent.id, messageId, responseMessageId, existing: createChanges.existingReverted, forbidden: createChanges.forbiddenReverted, message: createChanges.message });
|
|
@@ -2063,7 +2195,7 @@ export class Room {
|
|
|
2063
2195
|
if (this.#memory && turnMode !== 0) {
|
|
2064
2196
|
const noted = this.#memory.notesSince(notesBefore, { agent: agent.id });
|
|
2065
2197
|
if (noted.length) {
|
|
2066
|
-
await this.#emit('memory.noted', { agent: agent.id, messageId, responseMessageId, notes: noted.map((note) => ({ id: note.id, kind: note.kind, text: note.text, fromSequence: note.fromSequence, throughSequence: note.throughSequence })), total: this.#memory.memoryCount() });
|
|
2198
|
+
await this.#emit('memory.noted', { agent: agent.id, messageId, responseMessageId, notes: noted.map((note) => ({ id: note.id, kind: note.kind, text: note.text, fromSequence: note.fromSequence, throughSequence: note.throughSequence, unsourced: unsourced(note) })), total: this.#memory.memoryCount() });
|
|
2067
2199
|
this.#vectors.schedule();
|
|
2068
2200
|
}
|
|
2069
2201
|
}
|
|
@@ -2083,7 +2215,7 @@ export class Room {
|
|
|
2083
2215
|
this.#liveTurns.delete(responseMessageId);
|
|
2084
2216
|
// Which model the turn ran on, when the room knows it (the one asked for, or the agent's
|
|
2085
2217
|
// default): what answered is what MADRE can offer again when another model fails.
|
|
2086
|
-
const ranOn = await this.#pricedModel(agent.id, model).catch(() => null);
|
|
2218
|
+
const ranOn = result.model ?? await this.#pricedModel(agent.id, model).catch(() => null);
|
|
2087
2219
|
await this.#emit('agent.completed', { messageId, agent: agent.id, handoffId, planId, ...(ranOn ? { ranOn } : {}) });
|
|
2088
2220
|
return { responseMessageId, directives };
|
|
2089
2221
|
} catch (error) {
|