@jossuealcala/madre 1.1.3 → 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 +20 -1
- package/CHANGELOG.md +20 -1
- package/TRADEMARKS.md +6 -2
- package/bin/madre.mjs +4 -2
- package/docs/REFERENCE.md +3 -3
- package/docs/SDK.md +28 -1
- package/docs/en/REFERENCE.md +2 -2
- package/docs/en/SDK.md +26 -0
- package/docs/sdk/hello-module.mjs +38 -3
- 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 +4 -3
- package/public/activity.js +57 -22
- package/public/app.js +3998 -762
- 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 +28 -27
- package/public/auto-open.js +102 -0
- package/public/brands.js +9 -6
- package/public/changes.js +63 -0
- package/public/en.js +1085 -101
- package/public/es.js +2395 -1688
- package/public/i18n.js +11 -0
- package/public/index.html +28 -27
- package/public/loader.js +322 -117
- package/public/macroverso.js +33 -350
- package/public/manual-content.js +37 -7
- package/public/manual.js +21 -6
- package/public/market-view.js +212 -105
- package/public/market.js +10 -2
- package/public/mcp-catalog.js +7 -2
- package/public/missions.js +169 -0
- package/public/news-scenes.js +110 -3
- package/public/nostromo-engine.js +935 -654
- package/public/notices.js +14 -2
- package/public/notifications.js +119 -0
- package/public/provider-marks.js +170 -0
- package/public/provider-pick.js +147 -0
- package/public/resay.js +1 -0
- package/public/review-ask.js +16 -13
- package/public/routing.js +29 -3
- package/public/salas-mac.css +257 -40
- package/public/salas-mac.html +5 -5
- package/public/salas-mac.js +376 -97
- 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 +2656 -336
- package/public/subscription.js +303 -0
- package/public/terms-field.js +170 -0
- package/public/terms.js +117 -19
- package/public/tips.js +41 -7
- package/public/tour-chapters.js +35 -35
- package/public/tour.js +333 -43
- package/public/troubleshooting.js +100 -7
- package/public/welcome-scene.js +117 -29
- package/public/welcome.js +364 -60
- 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.mjs +4 -0
- package/src/adapters/grok.mjs +6 -4
- package/src/adapters/madre.mjs +71 -23
- package/src/adapters/opencode.mjs +15 -2
- package/src/adapters/steps.mjs +176 -0
- package/src/app-invite.mjs +90 -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 +17 -11
- package/src/chats.mjs +44 -2
- package/src/checkpoint.mjs +5 -1
- package/src/commands.mjs +5 -2
- package/src/directives.mjs +1 -0
- package/src/event-store.mjs +15 -0
- package/src/extensions.mjs +5 -1
- package/src/ficha.mjs +16 -0
- package/src/image-studio.mjs +13 -3
- package/src/install-metrics.mjs +9 -3
- package/src/lease.mjs +1 -1
- package/src/looks.mjs +4 -1
- package/src/mcp/image-server.mjs +59 -90
- package/src/modules/ahp.mjs +2 -1
- package/src/modules/github.mjs +6 -2
- package/src/modules/image-providers.mjs +281 -0
- package/src/modules/image-studio.mjs +100 -19
- package/src/modules/index.mjs +7 -1
- package/src/modules/intents-observe.mjs +3 -1
- package/src/modules/playwright.mjs +33 -4
- package/src/modules/reminders.mjs +42 -2
- package/src/modules/ripley.mjs +2 -1
- package/src/modules/sdk.mjs +6 -1
- package/src/opencode-health.mjs +1 -1
- package/src/outbound.mjs +80 -6
- package/src/quota-sources.mjs +148 -3
- package/src/review-ask.mjs +55 -31
- package/src/room/changes.mjs +79 -0
- package/src/room/economy.mjs +1 -1
- package/src/room/guard.mjs +8 -1
- package/src/room/prompt.mjs +20 -4
- package/src/room.mjs +87 -21
- package/src/salas.mjs +30 -3
- package/src/server.mjs +545 -59
- package/src/setup.mjs +1 -1
- package/src/skills.mjs +10 -0
- package/src/terms.mjs +23 -5
- package/src/tour.mjs +18 -3
- package/src/updates.mjs +47 -4
- package/src/web-preview.mjs +181 -0
- package/src/whats-new.mjs +76 -4
package/src/modules/sdk.mjs
CHANGED
|
@@ -91,7 +91,7 @@ export const MODULE_FIELDS = new Set([
|
|
|
91
91
|
'requires', 'models', 'commands', 'card', 'configKey', 'settings', 'controls', 'routes', 'reaches',
|
|
92
92
|
'conditions', 'slash', 'status', 'preflight', 'detect', 'confirm', 'installCommand', 'secrets',
|
|
93
93
|
'updatePlan', 'toolsForTurn', 'toggle', 'onToggle', 'onSettings', 'onEvent', 'toggledEvent',
|
|
94
|
-
'toggledBody', 'describe', 'ready', 'footer', 'credit', 'sdk', 'icon',
|
|
94
|
+
'toggledBody', 'describe', 'ready', 'footer', 'credit', 'sdk', 'icon', 'notifies',
|
|
95
95
|
]);
|
|
96
96
|
export const unknownFields = (spec) => Object.keys(spec ?? {}).filter((key) => !MODULE_FIELDS.has(key));
|
|
97
97
|
|
|
@@ -159,6 +159,11 @@ export function defineModule(spec) {
|
|
|
159
159
|
icon: moduleIconOf(spec),
|
|
160
160
|
// Whose idea it was (2026-10-20, Reminders): said on its card and in the Market.
|
|
161
161
|
credit: typeof spec.credit === 'string' && spec.credit.trim() ? spec.credit.trim().slice(0, 80) : null,
|
|
162
|
+
// Its permission to speak through MADRE's notifications of the system (2026-11-10): what it says,
|
|
163
|
+
// in a line, and when. Without it a module has no way to the system at all (public/notifications.js).
|
|
164
|
+
notifies: spec.notifies && typeof spec.notifies.label === 'string' && spec.notifies.label.trim()
|
|
165
|
+
? { label: spec.notifies.label.trim().slice(0, 120), note: typeof spec.notifies.note === 'string' ? spec.notifies.note.trim().slice(0, 200) : null }
|
|
166
|
+
: null,
|
|
162
167
|
summary: oneWord(spec.summary) ?? '', creates: spec.creates ?? [], requires: spec.requires ?? [], models: spec.models ?? [], commands: spec.commands ?? (spec.slash?.length ? spec.slash.map((command) => command.usage ?? `/${command.name}`) : undefined),
|
|
163
168
|
card: spec.card ?? (kind === 'builtin' ? 'switch' : 'installer'),
|
|
164
169
|
// The settings floor of the card, declared instead of drawn: MADRE renders these and saves
|
package/src/opencode-health.mjs
CHANGED
|
@@ -45,7 +45,7 @@ const OPENCODE_PICK = 'opencode/big-pickle';
|
|
|
45
45
|
export const providerOf = (model) => (typeof model === 'string' && model.includes('/') ? model.split('/')[0] : null);
|
|
46
46
|
|
|
47
47
|
// Which of MADRE's known conditions this failure is, said as what the provider needs.
|
|
48
|
-
const KINDS = { 'provider-credit-exhausted': 'no-credit', 'opencode-default-provider': 'bad-key' };
|
|
48
|
+
const KINDS = { 'provider-credit-exhausted': 'no-credit', 'opencode-default-provider': 'bad-key', 'opencode-default-model-missing': 'no-model' };
|
|
49
49
|
export function problemOf(error) {
|
|
50
50
|
for (const condition of diagnose(error, 'opencode')) if (KINDS[condition.id]) return KINDS[condition.id];
|
|
51
51
|
return null;
|
package/src/outbound.mjs
CHANGED
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
import { appendFile, mkdir, open, stat, writeFile } from 'node:fs/promises';
|
|
27
27
|
import { t } from './i18n.mjs';
|
|
28
28
|
import { dirname } from 'node:path';
|
|
29
|
+
import { askedByPerson } from './web-preview.mjs';
|
|
29
30
|
|
|
30
31
|
export const KEEP = 200; // lines held for the screen
|
|
31
32
|
export const MAX_BYTES = 512 * 1024; // the file is trimmed to the last KEEP lines past this
|
|
@@ -82,19 +83,50 @@ export const DESTINATIONS = [
|
|
|
82
83
|
// It runs in a process of its own and writes its own line into this same log, so it is here.
|
|
83
84
|
inside: true,
|
|
84
85
|
},
|
|
86
|
+
{
|
|
87
|
+
// The other two providers Images draws with (2026-11-14, src/modules/image-providers.mjs). Same
|
|
88
|
+
// process of its own as Google's, same line in this log; the key travels in a header.
|
|
89
|
+
id: 'image-openai', host: 'api.openai.com', match: (url) => url.pathname.startsWith('/v1/images/'), to: 'OpenAI · GPT Image model',
|
|
90
|
+
what: 'The prompt an AI wrote for an image, with your OpenAI API key, to be drawn by the model you chose.',
|
|
91
|
+
when: 'an AI uses the image tool during a permission to create, while Images draws with OpenAI',
|
|
92
|
+
where: 'Modules › Images · choose another provider, or forget the key there',
|
|
93
|
+
inside: true,
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
id: 'image-xai', host: 'api.x.ai', match: (url) => url.pathname.startsWith('/v1/images/'), to: 'xAI · Grok Imagine image model',
|
|
97
|
+
what: 'The prompt an AI wrote for an image, with your xAI API key, to be drawn by the model you chose.',
|
|
98
|
+
when: 'an AI uses the image tool during a permission to create, while Images draws with Grok',
|
|
99
|
+
where: 'Modules › Images · choose another provider, or forget the key there',
|
|
100
|
+
inside: true,
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
// Whether the provider takes a key pasted in Modules › Images: listing the models spends nothing.
|
|
104
|
+
id: 'image-key', host: 'api.openai.com', match: (url) => /^\/v1\/models\/?$/.test(url.pathname), to: 'OpenAI · whether it takes your key',
|
|
105
|
+
what: 'The OpenAI API key you paste in Modules › Images, so OpenAI says whether it takes it. It lists models and spends no credit. Nothing about you or your project.',
|
|
106
|
+
when: 'once, when you save an OpenAI key in Modules › Images',
|
|
107
|
+
where: 'Modules › Images · without a pasted key it is never asked',
|
|
108
|
+
inside: true,
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
id: 'image-key-xai', host: 'api.x.ai', match: (url) => /^\/v1\/models\/?$/.test(url.pathname), to: 'xAI · whether it takes your key',
|
|
112
|
+
what: 'The xAI API key you paste in Modules › Images, so xAI says whether it takes it. It lists models and spends no credit. Nothing about you or your project.',
|
|
113
|
+
when: 'once, when you save an xAI key in Modules › Images',
|
|
114
|
+
where: 'Modules › Images · without a pasted key it is never asked',
|
|
115
|
+
inside: true,
|
|
116
|
+
},
|
|
85
117
|
{
|
|
86
118
|
id: 'npm', host: 'registry.npmjs.org', to: 'the npm registry',
|
|
87
119
|
what: 'The name of a package, to read the version of its latest release. Nothing about you or your project.',
|
|
88
|
-
when: 'at most once a day per package,
|
|
89
|
-
where: 'Settings ›
|
|
120
|
+
when: 'at most once a day per package, to tell you a new version is out',
|
|
121
|
+
where: 'Settings › Updates and errors',
|
|
90
122
|
inside: true,
|
|
91
123
|
},
|
|
92
124
|
{
|
|
93
125
|
// Only the release read: the rest of api.github.com is the GitHub module's, and says so itself.
|
|
94
126
|
id: 'github', host: 'api.github.com', match: (url) => /\/releases\/latest$/.test(url.pathname), to: 'GitHub',
|
|
95
127
|
what: 'The name of a repository, to read the tag of its latest release. Nothing about you or your project.',
|
|
96
|
-
when: 'at most once a day per repository,
|
|
97
|
-
where: 'Settings ›
|
|
128
|
+
when: 'at most once a day per repository, to tell you a new version is out',
|
|
129
|
+
where: 'Settings › Updates and errors',
|
|
98
130
|
inside: true,
|
|
99
131
|
},
|
|
100
132
|
{
|
|
@@ -112,7 +144,16 @@ export const DESTINATIONS = [
|
|
|
112
144
|
id: 'notices', host: 'madre.run', match: (url) => url.pathname === '/api/avisos', to: 'madre.run · notices from MADRE\'s author',
|
|
113
145
|
what: 'Nothing about you: it asks for the notices MADRE\'s author wrote for every copy, not even with this copy\'s version. Each one is checked against the author\'s signature before it shows.',
|
|
114
146
|
when: 'when MADRE opens, and at most every 15 minutes while it is open',
|
|
115
|
-
where: '
|
|
147
|
+
where: 'Always, so every copy hears of a new version or a fix · PULSE_NOTICES=0 for development',
|
|
148
|
+
inside: true,
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
// MADRE App's subscription (src/billing.mjs, 2026-11-17): only inside the app, and only once the
|
|
152
|
+
// author turns it on. In the author's own copy, the same address takes the switch, signed here.
|
|
153
|
+
id: 'subscription', host: 'madre.run', match: (url) => url.pathname === '/api/cobro' || url.pathname.startsWith('/api/suscripcion/'), to: 'madre.run · MADRE App subscription',
|
|
154
|
+
what: 'Whether the author turned the subscription on, with nothing about you; once you subscribe, your subscription key, to keep it current. Never what you write or your projects.',
|
|
155
|
+
when: 'inside the app: when MADRE opens, every half hour, and every 12 hours once you subscribe',
|
|
156
|
+
where: 'Only in MADRE App; MADRE from npm or from source never asks',
|
|
116
157
|
inside: true,
|
|
117
158
|
},
|
|
118
159
|
{
|
|
@@ -137,7 +178,7 @@ export const DESTINATIONS = [
|
|
|
137
178
|
id: 'market', host: 'madre.run', match: (url) => url.pathname.startsWith('/mercado/'), to: "madre.run · the Market",
|
|
138
179
|
what: 'Nothing about you: it asks for the catalog of modules, and for the file of a module you got or that has a newer version. Every file is checked against the author\'s signature before it is used.',
|
|
139
180
|
when: 'when MADRE opens, at most every ten minutes, and when you get a module',
|
|
140
|
-
where: 'Settings ›
|
|
181
|
+
where: 'Settings › Updates and errors · or PULSE_MARKET=0',
|
|
141
182
|
inside: true,
|
|
142
183
|
},
|
|
143
184
|
{
|
|
@@ -186,6 +227,38 @@ export const DESTINATIONS = [
|
|
|
186
227
|
where: 'Settings › Agents › Claude',
|
|
187
228
|
inside: true,
|
|
188
229
|
},
|
|
230
|
+
{
|
|
231
|
+
// Gemini CLI's quota (src/quota-sources.mjs, 2026-11-10): only signed in with Google.
|
|
232
|
+
id: 'gemini-quota', host: 'cloudcode-pa.googleapis.com', to: 'Google · how much of your Gemini plan is left',
|
|
233
|
+
what: 'The token Gemini CLI keeps when you sign in with Google, to read how much of each model your account has left. Read from where Gemini keeps it, while it is fresh; never stored nor renewed by MADRE.',
|
|
234
|
+
when: 'every minute while MADRE is open, only when Gemini signs in with Google (never with an API key)',
|
|
235
|
+
where: 'Settings › Agents › Gemini · or PULSE_GEMINI_QUOTA=0',
|
|
236
|
+
inside: true,
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
// OpenCode's quota by provider (src/quota-sources.mjs, 2026-11-10).
|
|
240
|
+
id: 'copilot-quota', host: 'api.github.com', match: (url) => url.pathname === '/copilot_internal/user', to: 'GitHub · how many Copilot requests are left',
|
|
241
|
+
what: 'The GitHub token OpenCode keeps when you sign in to Copilot with it, to read how many premium requests are left this month. Read from OpenCode\'s own file; never stored by MADRE.',
|
|
242
|
+
when: 'every minute while MADRE is open, only when OpenCode is signed in to GitHub Copilot',
|
|
243
|
+
where: 'Settings › Agents › OpenCode · or PULSE_OPENCODE_QUOTA=0',
|
|
244
|
+
inside: true,
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
id: 'openrouter-quota', host: 'openrouter.ai', match: (url) => /^\/api\/v1\/(key|credits)$/.test(url.pathname), to: 'OpenRouter · how much of your credit is spent',
|
|
248
|
+
what: 'The OpenRouter key OpenCode keeps, to read how much of its limit or of your credits is spent. Read from OpenCode\'s own file; never stored by MADRE.',
|
|
249
|
+
when: 'every minute while MADRE is open, only when OpenCode has an OpenRouter key',
|
|
250
|
+
where: 'Settings › Agents › OpenCode · or PULSE_OPENCODE_QUOTA=0',
|
|
251
|
+
inside: true,
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
// The cards of an answer's links (web-preview.mjs, 2026-11-14): any site, so no host here; the
|
|
255
|
+
// addresses come from the person's press, and classify() knows them by that.
|
|
256
|
+
id: 'web-page', host: null, to: 'the sites of the links in an answer',
|
|
257
|
+
what: 'A request for the page of each link an agent gave, and for its photo, to show them as cards. Only the address of that page; nothing about you, your project or the conversation.',
|
|
258
|
+
when: 'only when you press «Show photos» under an answer with links',
|
|
259
|
+
where: 'never without that press · the links still open in your browser without it',
|
|
260
|
+
inside: true,
|
|
261
|
+
},
|
|
189
262
|
{
|
|
190
263
|
id: 'ollama', host: null, local: true, to: 'Ollama, on this computer',
|
|
191
264
|
what: 'Memories to embed, exchanges to distil, and whatever you ask @madre. It goes to a port on this machine and stops there.',
|
|
@@ -245,6 +318,7 @@ export function classify(rawUrl, { reportHost = null } = {}) {
|
|
|
245
318
|
// and a module's are both honest; they are not the same promise.
|
|
246
319
|
return { id: one.id, to: one.to, local: false, ...(one.module ? { module: one.module } : {}) };
|
|
247
320
|
}
|
|
321
|
+
if (askedByPerson(url.href)) return { id: 'web-page', to: host, local: false };
|
|
248
322
|
return { id: 'unknown', to: host, local: false };
|
|
249
323
|
}
|
|
250
324
|
|
package/src/quota-sources.mjs
CHANGED
|
@@ -19,8 +19,19 @@ const execFileAsync = promisify(execFile);
|
|
|
19
19
|
// already keeps in the keychain (macOS) or ~/.claude/.credentials.json.
|
|
20
20
|
// Read-only; the token never leaves this machine except toward
|
|
21
21
|
// api.anthropic.com, which is where the CLI sends it anyway.
|
|
22
|
-
// gemini
|
|
23
|
-
//
|
|
22
|
+
// gemini Signed in with a Google account (2026-11-10), Gemini CLI asks Code
|
|
23
|
+
// Assist for the account's quota (v1internal:retrieveUserQuota, one
|
|
24
|
+
// bucket per model with the fraction left and when it resets). MADRE
|
|
25
|
+
// asks the same, with the token the CLI keeps in ~/.gemini, only while
|
|
26
|
+
// that token is fresh: it never refreshes nor writes it. With an API
|
|
27
|
+
// key Google publishes nothing: the room's window stands in.
|
|
28
|
+
// opencode By its provider (2026-11-10), from OpenCode's own auth.json: a GitHub Copilot sign-in
|
|
29
|
+
// asks GitHub how many premium requests are left this month (the same endpoint the
|
|
30
|
+
// editors use, copilot_internal/user); an OpenRouter key asks OpenRouter how much of its
|
|
31
|
+
// limit or of the account's credits is spent (/api/v1/key, /api/v1/credits). Only the
|
|
32
|
+
// provider of the model OpenCode is answering with counts (2026-11-11: a Copilot sign-in
|
|
33
|
+
// out of premium requests marked OpenCode as spent while it answered with an OpenAI key).
|
|
34
|
+
// Others publish nothing: the room's window.
|
|
24
35
|
//
|
|
25
36
|
// A window whose resets_at is already in the past is reported as fresh
|
|
26
37
|
// (0 % used, stale: true): the CLI only rewrites the file when it runs again,
|
|
@@ -143,12 +154,146 @@ export const claudeUsageSource = (options = {}) => ({
|
|
|
143
154
|
read: () => readClaudeUsage(options),
|
|
144
155
|
});
|
|
145
156
|
|
|
157
|
+
// Gemini CLI's own Google sign-in, as it keeps it: the token only while it is fresh, and only when
|
|
158
|
+
// the CLI is set to sign in with Google (an API key has no quota to ask about).
|
|
159
|
+
export async function readGeminiOauth({ home = homedir(), now = Date.now(), env = process.env } = {}) {
|
|
160
|
+
const dir = join(home, '.gemini');
|
|
161
|
+
let settings = {};
|
|
162
|
+
try { settings = JSON.parse(await readFile(join(dir, 'settings.json'), 'utf8')); } catch { settings = {}; }
|
|
163
|
+
const kind = settings.security?.auth?.selectedType ?? settings.selectedAuthType ?? settings.selectedType ?? null;
|
|
164
|
+
if (kind && kind !== 'oauth-personal') return null;
|
|
165
|
+
let creds = null;
|
|
166
|
+
try { creds = JSON.parse(await readFile(join(dir, 'oauth_creds.json'), 'utf8')); } catch { return null; }
|
|
167
|
+
const expires = Number(creds?.expiry_date);
|
|
168
|
+
if (!creds?.access_token || !Number.isFinite(expires) || expires - now < 60_000) return null;
|
|
169
|
+
return { token: creds.access_token, project: env.GOOGLE_CLOUD_PROJECT || env.GOOGLE_CLOUD_PROJECT_ID || null };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const CODE_ASSIST = 'https://cloudcode-pa.googleapis.com/v1internal';
|
|
173
|
+
let geminiProject = null;
|
|
174
|
+
export async function readGeminiQuota({ fetchImpl = fetch, oauthReader = readGeminiOauth, now = Date.now() } = {}) {
|
|
175
|
+
const auth = await oauthReader({ now });
|
|
176
|
+
if (!auth) return null;
|
|
177
|
+
const post = async (method, body) => {
|
|
178
|
+
const response = await fetchImpl(`${CODE_ASSIST}:${method}`, { method: 'POST', headers: { authorization: `Bearer ${auth.token}`, 'content-type': 'application/json', accept: 'application/json' }, body: JSON.stringify(body) });
|
|
179
|
+
if (response.status === 401 || response.status === 403) throw new Error(`Google rejected Gemini CLI's sign-in (HTTP ${response.status}); sign in again with gemini.`);
|
|
180
|
+
if (!response.ok) throw new Error(`Gemini's quota endpoint answered HTTP ${response.status}.`);
|
|
181
|
+
return response.json();
|
|
182
|
+
};
|
|
183
|
+
// The account's Code Assist project, as the CLI finds it; asked once.
|
|
184
|
+
let project = auth.project ?? geminiProject;
|
|
185
|
+
if (!project) {
|
|
186
|
+
const loaded = await post('loadCodeAssist', { metadata: { ideType: 'IDE_UNSPECIFIED', platform: 'PLATFORM_UNSPECIFIED', pluginType: 'GEMINI' } });
|
|
187
|
+
project = loaded?.cloudaicompanionProject?.id ?? loaded?.cloudaicompanionProject ?? null;
|
|
188
|
+
if (typeof project !== 'string' || !project) return null;
|
|
189
|
+
geminiProject = project;
|
|
190
|
+
}
|
|
191
|
+
const quota = await post('retrieveUserQuota', { project });
|
|
192
|
+
// The tightest of its models: the one that runs out first is the one that stops a turn.
|
|
193
|
+
const buckets = (quota?.buckets ?? []).filter((one) => one?.modelId && Number.isFinite(Number(one.remainingFraction)));
|
|
194
|
+
if (!buckets.length) return null;
|
|
195
|
+
const tightest = buckets.reduce((low, one) => (Number(one.remainingFraction) < Number(low.remainingFraction) ? one : low));
|
|
196
|
+
const primary = interpretWindow({ usedPercent: (1 - Number(tightest.remainingFraction)) * 100, resetAt: tightest.resetTime ?? null, windowMinutes: 1440 }, now);
|
|
197
|
+
return {
|
|
198
|
+
agent: 'gemini',
|
|
199
|
+
usedPercent: primary.usedPercent,
|
|
200
|
+
resetAt: primary.resetAt,
|
|
201
|
+
stale: primary.stale,
|
|
202
|
+
windows: { primary, secondary: null },
|
|
203
|
+
model: tightest.modelId,
|
|
204
|
+
observedAt: new Date(now).toISOString(),
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export const geminiQuotaSource = (options = {}) => ({
|
|
209
|
+
id: 'gemini-quota',
|
|
210
|
+
agent: 'gemini',
|
|
211
|
+
read: () => readGeminiQuota(options),
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
// OpenCode's providers as its auth.json keeps them (src/credentials.mjs writes the same file).
|
|
215
|
+
export async function readOpenCodeAuth({ home = homedir(), env = process.env } = {}) {
|
|
216
|
+
const file = join(env.XDG_DATA_HOME || join(home, '.local', 'share'), 'opencode', 'auth.json');
|
|
217
|
+
try {
|
|
218
|
+
const auth = JSON.parse(await readFile(file, 'utf8'));
|
|
219
|
+
return auth && typeof auth === 'object' && !Array.isArray(auth) ? auth : {};
|
|
220
|
+
} catch { return {}; }
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// GitHub Copilot: the premium requests of the month, with the GitHub token OpenCode signed in with.
|
|
224
|
+
export async function readCopilotQuota(entry, { fetchImpl = fetch, now = Date.now() } = {}) {
|
|
225
|
+
const token = entry?.type === 'oauth' ? entry.refresh : null;
|
|
226
|
+
if (typeof token !== 'string' || !token) return null;
|
|
227
|
+
const response = await fetchImpl('https://api.github.com/copilot_internal/user', { headers: { authorization: `token ${token}`, accept: 'application/json', 'x-github-api-version': '2025-04-01' } });
|
|
228
|
+
if (response.status === 401 || response.status === 403) throw new Error(`GitHub rejected OpenCode's Copilot sign-in (HTTP ${response.status}); sign in again with opencode auth login.`);
|
|
229
|
+
if (!response.ok) throw new Error(`GitHub's Copilot endpoint answered HTTP ${response.status}.`);
|
|
230
|
+
const body = await response.json();
|
|
231
|
+
const premium = body?.quota_snapshots?.premium_interactions;
|
|
232
|
+
if (!premium || premium.unlimited || !Number.isFinite(Number(premium.percent_remaining))) return null;
|
|
233
|
+
const resetAt = body.quota_reset_date ? new Date(body.quota_reset_date).toISOString() : null;
|
|
234
|
+
return { provider: 'github-copilot', ...interpretWindow({ usedPercent: 100 - Number(premium.percent_remaining), resetAt, windowMinutes: null }, now) };
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// OpenRouter: the key's own limit when it has one, the account's credits when it does not.
|
|
238
|
+
export async function readOpenRouterQuota(entry, { fetchImpl = fetch, now = Date.now() } = {}) {
|
|
239
|
+
const key = entry?.type === 'api' ? entry.key : null;
|
|
240
|
+
if (typeof key !== 'string' || !key) return null;
|
|
241
|
+
const ask = async (path) => {
|
|
242
|
+
const response = await fetchImpl(`https://openrouter.ai/api/v1/${path}`, { headers: { authorization: `Bearer ${key}`, accept: 'application/json' } });
|
|
243
|
+
if (response.status === 401 || response.status === 403) throw new Error(`OpenRouter rejected the key OpenCode has for it (HTTP ${response.status}).`);
|
|
244
|
+
if (!response.ok) throw new Error(`OpenRouter answered HTTP ${response.status}.`);
|
|
245
|
+
return (await response.json())?.data ?? null;
|
|
246
|
+
};
|
|
247
|
+
const own = await ask('key');
|
|
248
|
+
if (Number(own?.limit) > 0) return { provider: 'openrouter', ...interpretWindow({ usedPercent: (Number(own.usage ?? 0) / Number(own.limit)) * 100, resetAt: null, windowMinutes: null }, now) };
|
|
249
|
+
const credits = await ask('credits');
|
|
250
|
+
if (!(Number(credits?.total_credits) > 0)) return null;
|
|
251
|
+
return { provider: 'openrouter', ...interpretWindow({ usedPercent: (Number(credits.total_usage ?? 0) / Number(credits.total_credits)) * 100, resetAt: null, windowMinutes: null }, now) };
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// The model OpenCode answered with last (room.mjs notes it on every OpenCode turn), or the one chosen
|
|
255
|
+
// for every project in Settings.
|
|
256
|
+
let openCodeModel = null;
|
|
257
|
+
export function noteOpenCodeModel(model) { if (typeof model === 'string' && model.includes('/')) openCodeModel = model; }
|
|
258
|
+
const OPENCODE_READERS = { 'github-copilot': readCopilotQuota, openrouter: readOpenRouterQuota };
|
|
259
|
+
|
|
260
|
+
export async function readOpenCodeQuota({ authReader = readOpenCodeAuth, fetchImpl = fetch, now = Date.now(), model = openCodeModel ?? process.env.PULSE_OPENCODE_MODEL ?? null } = {}) {
|
|
261
|
+
const auth = await authReader();
|
|
262
|
+
const measurable = Object.keys(OPENCODE_READERS).filter((provider) => auth[provider]);
|
|
263
|
+
if (!measurable.length) return null;
|
|
264
|
+
const provider = String(model ?? '').split('/')[0];
|
|
265
|
+
const tightest = measurable.includes(provider) ? await OPENCODE_READERS[provider](auth[provider], { fetchImpl, now }).catch(() => null) : null;
|
|
266
|
+
// Answering through a provider that publishes nothing: what another one has left is not
|
|
267
|
+
// OpenCode's. Said as an empty, unmeasured window, so a reading kept from before stops warning.
|
|
268
|
+
if (!tightest) return measurable.includes(provider) ? null : { agent: 'opencode', usedPercent: 0, resetAt: null, stale: true, provider: null, windows: null, observedAt: new Date(now).toISOString() };
|
|
269
|
+
return {
|
|
270
|
+
agent: 'opencode',
|
|
271
|
+
usedPercent: tightest.usedPercent,
|
|
272
|
+
resetAt: tightest.resetAt,
|
|
273
|
+
stale: tightest.stale,
|
|
274
|
+
provider: tightest.provider,
|
|
275
|
+
windows: { primary: tightest, secondary: null },
|
|
276
|
+
observedAt: new Date(now).toISOString(),
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export const openCodeQuotaSource = (options = {}) => ({
|
|
281
|
+
id: 'opencode-quota',
|
|
282
|
+
agent: 'opencode',
|
|
283
|
+
read: () => readOpenCodeQuota(options),
|
|
284
|
+
});
|
|
285
|
+
|
|
146
286
|
// Codex is on by default: a local file read. Claude's usage endpoint needs
|
|
147
287
|
// the CLI's OAuth token from the keychain, which macOS may ask about, so it is
|
|
148
|
-
// opt-in: PULSE_CLAUDE_USAGE=1.
|
|
288
|
+
// opt-in: PULSE_CLAUDE_USAGE=1. Gemini's is a file read and a question to Google with the CLI's own
|
|
289
|
+
// fresh token, and OpenCode's a question to GitHub or OpenRouter with what OpenCode signed in with,
|
|
290
|
+
// so they are on (PULSE_GEMINI_QUOTA=0, PULSE_OPENCODE_QUOTA=0 turn them off). PULSE_OFFICIAL_QUOTA=0 turns
|
|
291
|
+
// everything off.
|
|
149
292
|
export function defaultQuotaSources({ env = process.env } = {}) {
|
|
150
293
|
if (env.PULSE_OFFICIAL_QUOTA === '0') return [];
|
|
151
294
|
const sources = [codexRolloutSource()];
|
|
295
|
+
if (env.PULSE_GEMINI_QUOTA !== '0') sources.push(geminiQuotaSource());
|
|
296
|
+
if (env.PULSE_OPENCODE_QUOTA !== '0') sources.push(openCodeQuotaSource());
|
|
152
297
|
if (env.PULSE_CLAUDE_USAGE === '1') sources.push(claudeUsageSource());
|
|
153
298
|
return sources;
|
|
154
299
|
}
|
package/src/review-ask.mjs
CHANGED
|
@@ -2,17 +2,22 @@
|
|
|
2
2
|
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
3
3
|
// Asking for a star or a review (2026-10-10): three times at most, and never again once answered.
|
|
4
4
|
//
|
|
5
|
-
// After
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
5
|
+
// After thirty minutes with an AI at work (2026-11-18, the author: «después de unos 30 minutos de
|
|
6
|
+
// que el usuario está usando madre y está usando alguna de sus IAs»), and on the second and the
|
|
7
|
+
// seventh day after it was first used — once those thirty minutes are there too — the room asks
|
|
8
|
+
// once whether MADRE is being liked. Where it sends the person depends on how MADRE came: the
|
|
9
|
+
// desktop app (MADRE_APP=1) to a review on madre.run, a copy from npm or from the source to a star
|
|
10
|
+
// on GitHub, since npm keeps no reviews. Whoever answers — a star, a review, a donation or «don't
|
|
11
|
+
// ask again» — is never asked again; «not now» only lets that moment pass. A later moment that
|
|
12
|
+
// comes first takes the earlier ones with it, so nobody is asked twice in a row, and never twice
|
|
13
|
+
// within a day.
|
|
10
14
|
//
|
|
11
|
-
// Use is counted by the pages themselves: while one is in view it says so once a minute, and
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
15
|
+
// Use is counted by the pages themselves: while one is in view it says so once a minute, and says
|
|
16
|
+
// whether an AI is at work in it — a turn running, or one that ended a moment ago. Only those
|
|
17
|
+
// minutes count, one per minute however many pages are open; a window left open with nothing going
|
|
18
|
+
// on counts nothing. What is kept lives in ~/.pulse/review-ask.json, not in a browser: each room is
|
|
19
|
+
// its own origin, and the same person on another port has been asked already. Nothing here touches
|
|
20
|
+
// the network; the links are opened by the person, in their browser.
|
|
16
21
|
|
|
17
22
|
import { readFile } from 'node:fs/promises';
|
|
18
23
|
import { join } from 'node:path';
|
|
@@ -20,19 +25,30 @@ import { oneAtATime, writeWhole } from './json-file.mjs';
|
|
|
20
25
|
|
|
21
26
|
const FILE = 'review-ask.json';
|
|
22
27
|
const DAY = 24 * 60 * 60 * 1000;
|
|
28
|
+
// Minutes with an AI at work before anything is asked, the days included.
|
|
29
|
+
export const ASK_AFTER_MINUTES = 30;
|
|
30
|
+
const used = (state) => state.aiMinutes >= ASK_AFTER_MINUTES;
|
|
23
31
|
export const ASK_MOMENTS = [
|
|
24
|
-
{ id: '
|
|
25
|
-
{ id: 'd2', reached: (state, now) => now - Date.parse(state.first) >= 2 * DAY },
|
|
26
|
-
{ id: 'd7', reached: (state, now) => now - Date.parse(state.first) >= 7 * DAY },
|
|
32
|
+
{ id: 'm30', reached: (state) => used(state) },
|
|
33
|
+
{ id: 'd2', reached: (state, now) => used(state) && now - Date.parse(state.first) >= 2 * DAY },
|
|
34
|
+
{ id: 'd7', reached: (state, now) => used(state) && now - Date.parse(state.first) >= 7 * DAY },
|
|
27
35
|
];
|
|
36
|
+
// The first moment was twenty minutes with a page in view until 2026-11-18: whoever was asked
|
|
37
|
+
// then, or answers from a page opened before, was asked at the first moment.
|
|
38
|
+
const MOMENT_BEFORE = { m20: 'm30' };
|
|
39
|
+
const momentNow = (id) => MOMENT_BEFORE[id] ?? id;
|
|
40
|
+
// Where the question sends the person: the desktop app to a review, npm or the source to a star.
|
|
41
|
+
export const askVia = (env = process.env) => (env.MADRE_APP === '1' ? 'app' : 'npm');
|
|
28
42
|
// A donation on GitHub Sponsors is an answer too (2026-10-30): whoever gave is not asked again.
|
|
29
43
|
export const ASK_ANSWERS = ['later', 'star', 'review', 'donate', 'never'];
|
|
30
|
-
// One minute
|
|
44
|
+
// One minute with an AI at work is counted at most once a minute, whichever page says it.
|
|
31
45
|
const TICK_MS = 55 * 1000;
|
|
32
46
|
// Never asked twice within this long, whatever moments have come.
|
|
33
47
|
const QUIET_MS = 20 * 60 * 60 * 1000;
|
|
34
48
|
|
|
35
|
-
|
|
49
|
+
// `aiMinutes` and `lastUse` count only the minutes with an AI at work (2026-11-18); the `minutes`
|
|
50
|
+
// a file from before kept counted any page in view, and are left behind.
|
|
51
|
+
const fresh = () => ({ first: null, aiMinutes: 0, lastUse: null, shown: {}, answer: null, offered: null });
|
|
36
52
|
// A moment handed to one page is not handed to another for this long (WEB-12 of the 1.0 review):
|
|
37
53
|
// every page in view ticks — Home, each project, each half of a split view — and each one asked.
|
|
38
54
|
const OFFER_HOLD_MS = 10 * 60 * 1000;
|
|
@@ -42,9 +58,14 @@ export async function readAsk(root) {
|
|
|
42
58
|
const raw = JSON.parse(await readFile(join(root, FILE), 'utf8'));
|
|
43
59
|
const state = fresh();
|
|
44
60
|
if (typeof raw?.first === 'string' && Number.isFinite(Date.parse(raw.first))) state.first = raw.first;
|
|
45
|
-
if (Number.isFinite(raw?.
|
|
46
|
-
if (typeof raw?.
|
|
47
|
-
if (raw?.shown && typeof raw.shown === 'object')
|
|
61
|
+
if (Number.isFinite(raw?.aiMinutes) && raw.aiMinutes >= 0) state.aiMinutes = Math.floor(raw.aiMinutes);
|
|
62
|
+
if (typeof raw?.lastUse === 'string' && Number.isFinite(Date.parse(raw.lastUse))) state.lastUse = raw.lastUse;
|
|
63
|
+
if (raw?.shown && typeof raw.shown === 'object') {
|
|
64
|
+
for (const [id, at] of Object.entries(raw.shown)) {
|
|
65
|
+
const moment = momentNow(id);
|
|
66
|
+
if (typeof at === 'string' && ASK_MOMENTS.some((one) => one.id === moment)) state.shown[moment] = at;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
48
69
|
if (ASK_ANSWERS.includes(raw?.answer) && raw.answer !== 'later') state.answer = raw.answer;
|
|
49
70
|
if (typeof raw?.offered?.moment === 'string' && Number.isFinite(Date.parse(raw.offered.at))) state.offered = { moment: raw.offered.moment, at: raw.offered.at };
|
|
50
71
|
return state;
|
|
@@ -67,31 +88,33 @@ export function dueMoment(state, now = Date.now()) {
|
|
|
67
88
|
return reached.at(-1)?.id ?? null;
|
|
68
89
|
}
|
|
69
90
|
|
|
70
|
-
// A page in view says so: the first time starts the
|
|
71
|
-
//
|
|
91
|
+
// A page in view says so: the first time starts the days; a minute is added, at most once a minute,
|
|
92
|
+
// only when the page says an AI is at work in it (`using`). Answers which moment is due, if any.
|
|
72
93
|
// `quietSince`: a moment that asks for quiet — the day of the bonjour (src/tour.mjs) — keeps every
|
|
73
94
|
// ask away for QUIET_MS after it, as an ask itself would. The minutes still count.
|
|
74
95
|
// One change at a time (src/json-file.mjs): every page in view ticks, from every project.
|
|
75
96
|
export function tickAsk(root, now = Date.now(), options = {}) {
|
|
76
97
|
return oneAtATime(join(root, FILE), () => tick(root, now, options));
|
|
77
98
|
}
|
|
78
|
-
async function tick(root, now, { quietSince = null } = {}) {
|
|
99
|
+
async function tick(root, now, { quietSince = null, using = false } = {}) {
|
|
79
100
|
const state = await readAsk(root);
|
|
80
101
|
const at = new Date(now).toISOString();
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
state.
|
|
86
|
-
|
|
102
|
+
let changed = false;
|
|
103
|
+
if (!state.first) { state.first = at; changed = true; }
|
|
104
|
+
const last = state.lastUse ? Date.parse(state.lastUse) : 0;
|
|
105
|
+
if (using === true && (!last || now - last >= TICK_MS)) {
|
|
106
|
+
state.aiMinutes += 1;
|
|
107
|
+
state.lastUse = at;
|
|
108
|
+
changed = true;
|
|
87
109
|
}
|
|
110
|
+
if (changed) await writeAsk(root, state);
|
|
88
111
|
const hushed = quietSince && now - Date.parse(quietSince) < QUIET_MS;
|
|
89
112
|
const due = hushed ? null : dueMoment(state, now);
|
|
90
|
-
if (!due) return { due: null,
|
|
91
|
-
if (state.offered?.moment === due && now - Date.parse(state.offered.at) < OFFER_HOLD_MS) return { due: null,
|
|
113
|
+
if (!due) return { due: null, aiMinutes: state.aiMinutes };
|
|
114
|
+
if (state.offered?.moment === due && now - Date.parse(state.offered.at) < OFFER_HOLD_MS) return { due: null, aiMinutes: state.aiMinutes };
|
|
92
115
|
state.offered = { moment: due, at: new Date(now).toISOString() };
|
|
93
116
|
await writeAsk(root, state);
|
|
94
|
-
return { due,
|
|
117
|
+
return { due, aiMinutes: state.aiMinutes };
|
|
95
118
|
}
|
|
96
119
|
|
|
97
120
|
// The person answered the moment they were asked at. Every moment reached by then counts as shown,
|
|
@@ -99,7 +122,8 @@ async function tick(root, now, { quietSince = null } = {}) {
|
|
|
99
122
|
export function answerAsk(root, said, now = Date.now()) {
|
|
100
123
|
return oneAtATime(join(root, FILE), () => recordAnswer(root, said, now));
|
|
101
124
|
}
|
|
102
|
-
async function recordAnswer(root, { moment, answer }, now) {
|
|
125
|
+
async function recordAnswer(root, { moment: said, answer }, now) {
|
|
126
|
+
const moment = momentNow(said);
|
|
103
127
|
if (!ASK_ANSWERS.includes(answer)) return { error: 'answer' };
|
|
104
128
|
if (!ASK_MOMENTS.some(({ id }) => id === moment)) return { error: 'moment' };
|
|
105
129
|
const state = await readAsk(root);
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
3
|
+
// «What changed» (2026-11-11): under each reply that touched the project, a card says in the
|
|
4
|
+
// person's words what changed. The agent says it best, so a writing turn asks it for one closing
|
|
5
|
+
// line (src/room/prompt.mjs, block `changes`); MADRE takes that line out of the reply and carries it
|
|
6
|
+
// beside the files the turn really changed. Pure: text in, text and sentence out.
|
|
7
|
+
//
|
|
8
|
+
// The sentence is the agent's, never MADRE's: when the turn wrote nothing it is dropped, and when
|
|
9
|
+
// MADRE put something back (CREATE only adds, forbidden zones, the copilot's deletes) it is dropped
|
|
10
|
+
// too, because it may tell of a change that is no longer there. The page then says it from the
|
|
11
|
+
// files alone («Created gastos.html and changed index.html»).
|
|
12
|
+
|
|
13
|
+
export const CHANGES_MARK = 'MADRE-CHANGES';
|
|
14
|
+
const SUMMARY_MAX = 280;
|
|
15
|
+
// A line of its own, as the agent may dress it: in bold, quoted, in backticks.
|
|
16
|
+
const LINE = /^[ \t>*_`]*MADRE-CHANGES[ \t*_`]*:[ \t]*(.*)$/gim;
|
|
17
|
+
|
|
18
|
+
const peel = (said) => said.trim()
|
|
19
|
+
.replace(/^[*_`]+|[*_`]+$/g, '').trim()
|
|
20
|
+
.replace(/^["«“](.*)["»”]$/, '$1').trim();
|
|
21
|
+
// Until nothing more comes off, because the dressing nests: «**…**», **«…»**.
|
|
22
|
+
const tidy = (said) => {
|
|
23
|
+
let text = String(said ?? '');
|
|
24
|
+
for (let left = 4; left > 0; left -= 1) { const next = peel(text); if (next === text) break; text = next; }
|
|
25
|
+
return text;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// The reply without the line, and the sentence it carried (the last one, when there are several).
|
|
29
|
+
export function takeChangeSummary(text) {
|
|
30
|
+
const source = String(text ?? '');
|
|
31
|
+
if (!source.toUpperCase().includes(CHANGES_MARK)) return { text: source, summary: null };
|
|
32
|
+
let summary = null;
|
|
33
|
+
const rest = source.replace(LINE, (whole, said) => {
|
|
34
|
+
const clean = tidy(said);
|
|
35
|
+
if (clean) summary = clean;
|
|
36
|
+
return '';
|
|
37
|
+
});
|
|
38
|
+
if (rest === source) return { text: source, summary: null };
|
|
39
|
+
const clipped = summary && summary.length > SUMMARY_MAX ? `${summary.slice(0, SUMMARY_MAX - 1).trimEnd()}…` : summary;
|
|
40
|
+
return { text: rest.replace(/\n{3,}/g, '\n\n').trim(), summary: clipped };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// What the reply carries about its changes, or nothing when it changed nothing. `created`: the
|
|
44
|
+
// files a turn made (CREATE, or a draft folder); `create`/`control`: what the turn's restore point
|
|
45
|
+
// settled to (src/room/control.mjs).
|
|
46
|
+
export function turnChanges({ summary = null, created = [], create = null, control = null } = {}) {
|
|
47
|
+
const changed = (control?.files ?? []).length + created.length;
|
|
48
|
+
if (!changed) return null;
|
|
49
|
+
const settled = control ?? create;
|
|
50
|
+
const putBack = Boolean(
|
|
51
|
+
create?.existingReverted?.length
|
|
52
|
+
|| settled?.forbiddenReverted?.length
|
|
53
|
+
|| settled?.deletesReverted?.length,
|
|
54
|
+
);
|
|
55
|
+
return {
|
|
56
|
+
...(settled?.checkpointId ? { checkpointId: settled.checkpointId } : {}),
|
|
57
|
+
...(summary && !putBack ? { summary } : {}),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Modules an answer needs and the person may not have on (2026-11-14, the author: «the test browser
|
|
62
|
+
// and any module that is needed must be announced, and the person guided to turn it on»). The agent
|
|
63
|
+
// ends its reply with «MADRE-MODULE: <id>», one per module (src/room/prompt.mjs, block `modules`);
|
|
64
|
+
// MADRE takes the lines out and the page offers each one that is really off, with a button.
|
|
65
|
+
export const MODULE_MARK = 'MADRE-MODULE';
|
|
66
|
+
export const ASKABLE_MODULES = ['ripley', 'playwright', 'image-studio', 'git-pulse', 'runs', 'reminders', 'notes'];
|
|
67
|
+
const MODULE_LINE = /^[ \t>*_`-]*MADRE-MODULE[ \t*_`]*:[ \t*_`]*([a-z][a-z0-9-]*)[ \t*_`.]*$/gim;
|
|
68
|
+
export function takeModuleNeeds(text) {
|
|
69
|
+
const source = String(text ?? '');
|
|
70
|
+
if (!source.toUpperCase().includes(MODULE_MARK)) return { text: source, needs: [] };
|
|
71
|
+
const needs = [];
|
|
72
|
+
const rest = source.replace(MODULE_LINE, (whole, id) => {
|
|
73
|
+
const known = id.toLowerCase();
|
|
74
|
+
if (ASKABLE_MODULES.includes(known) && !needs.includes(known)) needs.push(known);
|
|
75
|
+
return '';
|
|
76
|
+
});
|
|
77
|
+
if (rest === source) return { text: source, needs: [] };
|
|
78
|
+
return { text: rest.replace(/\n{3,}/g, '\n\n').trim(), needs };
|
|
79
|
+
}
|
package/src/room/economy.mjs
CHANGED
|
@@ -21,7 +21,7 @@ export const ALWAYS = new Set(['room', 'who', 'mode', 'inspect', 'style', 'priva
|
|
|
21
21
|
// at the head of the prompt so the longest possible run of it comes back from the CLI's own
|
|
22
22
|
// cache instead of being charged again. Anything that can change between two turns belongs
|
|
23
23
|
// after them, however short it is: one differing byte early throws away everything after it.
|
|
24
|
-
export const STABLE = ['room', 'who', 'style', 'privacy', 'madre', 'memory-server'];
|
|
24
|
+
export const STABLE = ['room', 'who', 'style', 'shapes', 'modules', 'privacy', 'madre', 'memory-server'];
|
|
25
25
|
|
|
26
26
|
// How much of a prompt could be read back from a cache: the run of unchanging blocks at its
|
|
27
27
|
// head, in the order they were actually built. It stops at the first block that can vary,
|
package/src/room/guard.mjs
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// the checkpoint afterwards. A CLI that respects the filesystem cannot touch
|
|
8
8
|
// them; one that chmods its way through is caught by the checkpoint anyway.
|
|
9
9
|
|
|
10
|
-
import { chmod, lstat, readdir, readFile, rm, stat, writeFile } from 'node:fs/promises';
|
|
10
|
+
import { chmod, lstat, mkdir, readdir, readFile, rm, stat, writeFile } from 'node:fs/promises';
|
|
11
11
|
import { join, relative } from 'node:path';
|
|
12
12
|
import { isForbidden } from '../checkpoint.mjs';
|
|
13
13
|
import { writeWhole } from '../json-file.mjs';
|
|
@@ -51,6 +51,13 @@ const KEEP_AT_MOST = 1024 * 1024;
|
|
|
51
51
|
// back (restoreGuard) and gives them their modes again.
|
|
52
52
|
export async function guardForbidden(projectRoot, { record = null } = {}) {
|
|
53
53
|
const targets = await forbiddenTargets(projectRoot);
|
|
54
|
+
// The folder the other AIs write their work in (.pulse/out, src/lease.mjs LEASE_ROOT) is made before
|
|
55
|
+
// .pulse/ is locked: an AI with #2 asked while another held #3 found .pulse/ read-only and MADRE
|
|
56
|
+
// could not make it (EACCES, 2026-11-13, @gemini while @codex had full access). .pulse/ itself stays
|
|
57
|
+
// locked; out/ inside it keeps its own write bit, as it is meant to be written in.
|
|
58
|
+
if (targets.some((target) => target.kind === 'dir' && relative(projectRoot, target.path) === '.pulse')) {
|
|
59
|
+
await mkdir(join(projectRoot, '.pulse', 'out'), { recursive: true, mode: 0o755 }).catch(() => {});
|
|
60
|
+
}
|
|
54
61
|
const locked = [];
|
|
55
62
|
const kept = [];
|
|
56
63
|
for (const target of targets) {
|