@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
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
3
|
+
// WHAT AN AGENT IS DOING, STEP BY STEP (2026-11-09). While a turn runs, the room showed three dots
|
|
4
|
+
// and phrases taken in turn from a list; the CLIs already say, as they go, every file they read,
|
|
5
|
+
// every search, every change and every command. These readers turn that into one short list the
|
|
6
|
+
// room shows the same way for every agent: a line that says the step in front, and quiet cards for
|
|
7
|
+
// the ones before it (public/app.js, showSteps).
|
|
8
|
+
//
|
|
9
|
+
// One step: { kind, what }. kind is one of read · search · edit · write · run · web · fetch · think ·
|
|
10
|
+
// plan · tool; what is the file (from the project), the search, the command or the address, or null.
|
|
11
|
+
// Nothing is guessed: a CLI that does not say its steps gives none, and the room keeps its phrases.
|
|
12
|
+
// · Claude says each tool it uses, with its input (stream-json, tool_use).
|
|
13
|
+
// · Codex says each command, file change, search and tool as it starts (exec --json, item.started).
|
|
14
|
+
// · Grok writes Claude's stream with tools of its own names (read_file, list_dir, grep…).
|
|
15
|
+
// · Gemini says each tool as it calls it (stream-json, tool_use: tool_name, parameters).
|
|
16
|
+
// · Cursor says each tool as it starts (stream-json, tool_call/started: readToolCall.args…).
|
|
17
|
+
// · OpenCode says each tool once it is done (--format json, tool_use: part.tool, state.input).
|
|
18
|
+
// Their names and fields were read from each CLI on 2026-11-09: Grok 1.0.77 and OpenCode in a real
|
|
19
|
+
// turn, Gemini and Cursor in the code they install (gemini-cli bundle; cursor-agent 2026.10.18).
|
|
20
|
+
// What the room shows still goes through its privacy guard first (src/room.mjs).
|
|
21
|
+
|
|
22
|
+
export const STEPS_KEPT = 40;
|
|
23
|
+
const WHAT_LIMIT = 90;
|
|
24
|
+
|
|
25
|
+
const clip = (text, limit = WHAT_LIMIT) => {
|
|
26
|
+
const said = String(text ?? '').replace(/\s+/g, ' ').trim();
|
|
27
|
+
return said.length > limit ? `${said.slice(0, limit - 1)}…` : said || null;
|
|
28
|
+
};
|
|
29
|
+
const fromProject = (path, root) => {
|
|
30
|
+
const said = String(path ?? '');
|
|
31
|
+
if (!root || !said) return said || null;
|
|
32
|
+
const base = String(root).replace(/\/+$/, '');
|
|
33
|
+
return said.startsWith(`${base}/`) ? said.slice(base.length + 1) : said === base ? '.' : said;
|
|
34
|
+
};
|
|
35
|
+
const host = (url) => { try { return new URL(String(url)).host; } catch { return clip(url, 60); } };
|
|
36
|
+
// Two of the same in a row (reading a file twice, thinking twice) are one step.
|
|
37
|
+
const push = (steps, step) => {
|
|
38
|
+
const last = steps.at(-1);
|
|
39
|
+
if (last && last.kind === step.kind && last.what === step.what) return;
|
|
40
|
+
steps.push(step);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const CLAUDE = {
|
|
44
|
+
Read: (input, root) => ({ kind: 'read', what: clip(fromProject(input?.file_path, root)) }),
|
|
45
|
+
NotebookRead: (input, root) => ({ kind: 'read', what: clip(fromProject(input?.notebook_path, root)) }),
|
|
46
|
+
Grep: (input) => ({ kind: 'search', what: clip(input?.pattern) }),
|
|
47
|
+
Glob: (input) => ({ kind: 'search', what: clip(input?.pattern) }),
|
|
48
|
+
LS: (input, root) => ({ kind: 'read', what: clip(fromProject(input?.path, root)) }),
|
|
49
|
+
Edit: (input, root) => ({ kind: 'edit', what: clip(fromProject(input?.file_path, root)) }),
|
|
50
|
+
MultiEdit: (input, root) => ({ kind: 'edit', what: clip(fromProject(input?.file_path, root)) }),
|
|
51
|
+
NotebookEdit: (input, root) => ({ kind: 'edit', what: clip(fromProject(input?.notebook_path, root)) }),
|
|
52
|
+
Write: (input, root) => ({ kind: 'write', what: clip(fromProject(input?.file_path, root)) }),
|
|
53
|
+
Bash: (input) => ({ kind: 'run', what: clip(input?.command, 70) }),
|
|
54
|
+
WebSearch: (input) => ({ kind: 'web', what: clip(input?.query) }),
|
|
55
|
+
WebFetch: (input) => ({ kind: 'fetch', what: host(input?.url) }),
|
|
56
|
+
TodoWrite: () => ({ kind: 'plan', what: null }),
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// Any other CLI's tool, by its name: the same few kinds whichever agent says them. A tool that
|
|
60
|
+
// hands work to a subagent is the subagent's to show (subagents.mjs), not a step here.
|
|
61
|
+
const SUBAGENT_TOOLS = new Set(['Agent', 'Task', 'task', 'invoke_agent', 'taskToolCall']);
|
|
62
|
+
const pathOf = (input) => input?.file_path ?? input?.filePath ?? input?.target_file ?? input?.path ?? input?.absolute_path ?? input?.dir_path ?? input?.target_directory ?? input?.notebook_path ?? null;
|
|
63
|
+
const KINDS = [
|
|
64
|
+
[/^(read|read_file|read_many_files|readToolCall|list|ls|list_dir|list_directory|lsToolCall)$/i, 'read'],
|
|
65
|
+
[/^(grep|glob|grep_search|search_file_content|codesearch|grepToolCall|globToolCall|semSearchToolCall)$/i, 'search'],
|
|
66
|
+
[/^(edit|replace|search_replace|multiedit|patch|apply_patch|editToolCall|deleteToolCall)$/i, 'edit'],
|
|
67
|
+
[/^(write|write_file|create_file)$/i, 'write'],
|
|
68
|
+
[/^(bash|shell|run_shell_command|run_terminal_cmd|run_terminal_command|shellToolCall)$/i, 'run'],
|
|
69
|
+
[/^(websearch|web_search|google_web_search|webSearchToolCall)$/i, 'web'],
|
|
70
|
+
[/^(webfetch|web_fetch|fetch|webFetchToolCall)$/i, 'fetch'],
|
|
71
|
+
[/^(todowrite|todoread|write_todos|updateTodosToolCall|createPlanToolCall)$/i, 'plan'],
|
|
72
|
+
];
|
|
73
|
+
export function toolStep(name, input, { root = null } = {}) {
|
|
74
|
+
const tool = String(name ?? '');
|
|
75
|
+
if (!tool || SUBAGENT_TOOLS.has(tool)) return null;
|
|
76
|
+
const kind = KINDS.find(([pattern]) => pattern.test(tool))?.[1] ?? 'tool';
|
|
77
|
+
if (kind === 'read' || kind === 'edit' || kind === 'write') {
|
|
78
|
+
const path = pathOf(input) ?? (Array.isArray(input?.paths) ? input.paths[0] : null) ?? (Array.isArray(input?.include) ? input.include[0] : null);
|
|
79
|
+
return { kind, what: clip(fromProject(path, root)) };
|
|
80
|
+
}
|
|
81
|
+
if (kind === 'search') return { kind, what: clip(input?.pattern ?? input?.query ?? input?.globPattern ?? input?.searchTerm) };
|
|
82
|
+
if (kind === 'run') return { kind, what: clip(input?.command, 70) };
|
|
83
|
+
if (kind === 'web') return { kind, what: clip(input?.query ?? input?.searchTerm) };
|
|
84
|
+
if (kind === 'fetch') return { kind, what: input?.url ? host(input.url) : (String(input?.prompt ?? '').match(/https?:\/\/\S+/) ? host(String(input.prompt).match(/https?:\/\/\S+/)[0]) : null) };
|
|
85
|
+
if (kind === 'plan') return { kind, what: null };
|
|
86
|
+
return { kind, what: clip(tool.replace(/^mcp__[^_]+__/, '').replace(/ToolCall$/, '')) };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Claude, from its stream (one JSON object per line, already parsed). A subagent's own steps
|
|
90
|
+
// (parent_tool_use_id) are the subagent's, shown with it, not here.
|
|
91
|
+
export function claudeSteps(events, { root = null } = {}) {
|
|
92
|
+
const steps = [];
|
|
93
|
+
for (const event of events ?? []) {
|
|
94
|
+
if (event?.type !== 'assistant' || event.parent_tool_use_id) continue;
|
|
95
|
+
for (const part of event.message?.content ?? []) {
|
|
96
|
+
if (part?.type === 'thinking' || part?.type === 'redacted_thinking') { push(steps, { kind: 'think', what: null }); continue; }
|
|
97
|
+
if (part?.type !== 'tool_use' || SUBAGENT_TOOLS.has(part.name)) continue;
|
|
98
|
+
const read = CLAUDE[part.name];
|
|
99
|
+
const step = read ? read(part.input, root) : toolStep(part.name, part.input, { root });
|
|
100
|
+
if (step) push(steps, step);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return steps.slice(-STEPS_KEPT);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Codex, from its exec --json output: each item as it starts.
|
|
107
|
+
export function codexSteps(output, { root = null } = {}) {
|
|
108
|
+
const steps = [];
|
|
109
|
+
for (const line of String(output ?? '').split('\n')) {
|
|
110
|
+
if (!line.startsWith('{')) continue;
|
|
111
|
+
let event;
|
|
112
|
+
try { event = JSON.parse(line); } catch { continue; }
|
|
113
|
+
if (event?.type !== 'item.started' && event?.type !== 'item.completed') continue;
|
|
114
|
+
const item = event.item ?? {};
|
|
115
|
+
// A step is said once, when it starts; a completed one that never said it started still counts.
|
|
116
|
+
if (event.type === 'item.completed' && steps.some((step) => step.id === item.id)) continue;
|
|
117
|
+
let step = null;
|
|
118
|
+
if (item.type === 'command_execution') step = { kind: 'run', what: clip(String(item.command ?? '').replace(/^(\/bin\/)?(ba|z)?sh -lc '?|'$/g, ''), 70) };
|
|
119
|
+
else if (item.type === 'file_change') {
|
|
120
|
+
const change = (item.changes ?? [])[0];
|
|
121
|
+
step = { kind: change?.kind === 'add' ? 'write' : 'edit', what: clip(fromProject(change?.path, root)) };
|
|
122
|
+
} else if (item.type === 'web_search') step = { kind: 'web', what: clip(item.query) };
|
|
123
|
+
else if (item.type === 'mcp_tool_call') step = { kind: 'tool', what: clip(item.tool) };
|
|
124
|
+
else if (item.type === 'reasoning') step = { kind: 'think', what: null };
|
|
125
|
+
else if (item.type === 'todo_list') step = { kind: 'plan', what: null };
|
|
126
|
+
if (!step) continue;
|
|
127
|
+
if (item.id) step.id = item.id;
|
|
128
|
+
push(steps, step);
|
|
129
|
+
}
|
|
130
|
+
return steps.slice(-STEPS_KEPT).map(({ kind, what }) => ({ kind, what }));
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Grok writes Claude's stream line for line (adapters/grok.mjs), its tools under names of its own.
|
|
134
|
+
export const grokSteps = claudeSteps;
|
|
135
|
+
|
|
136
|
+
const jsonEvents = (output) => String(output ?? '').split('\n').filter((line) => line.startsWith('{')).flatMap((line) => { try { return [JSON.parse(line)]; } catch { return []; } });
|
|
137
|
+
|
|
138
|
+
// Gemini, from its stream-json: { type: 'tool_use', tool_name, parameters } as it calls each one.
|
|
139
|
+
export function geminiSteps(output, { root = null } = {}) {
|
|
140
|
+
const steps = [];
|
|
141
|
+
for (const event of jsonEvents(output)) {
|
|
142
|
+
if (event?.type !== 'tool_use') continue;
|
|
143
|
+
const step = toolStep(event.tool_name, event.parameters, { root });
|
|
144
|
+
if (step) push(steps, step);
|
|
145
|
+
}
|
|
146
|
+
return steps.slice(-STEPS_KEPT);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Cursor, from its stream-json: { type: 'tool_call', subtype: 'started', tool_call: { readToolCall:
|
|
150
|
+
// { args: { path } } } }, one kind of call per key; its thinking comes as { type: 'thinking' }.
|
|
151
|
+
export function cursorSteps(output, { root = null } = {}) {
|
|
152
|
+
const steps = [];
|
|
153
|
+
for (const event of jsonEvents(output)) {
|
|
154
|
+
if (event?.type === 'thinking') { push(steps, { kind: 'think', what: null }); continue; }
|
|
155
|
+
if (event?.type !== 'tool_call' || event.subtype !== 'started' || !event.tool_call || typeof event.tool_call !== 'object') continue;
|
|
156
|
+
const [name, call] = Object.entries(event.tool_call)[0] ?? [];
|
|
157
|
+
const step = name === 'mcpToolCall'
|
|
158
|
+
? { kind: 'tool', what: clip(call?.args?.toolName ?? call?.args?.name ?? 'MCP') }
|
|
159
|
+
: toolStep(name, call?.args, { root });
|
|
160
|
+
if (step) push(steps, step);
|
|
161
|
+
}
|
|
162
|
+
return steps.slice(-STEPS_KEPT);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// OpenCode, from its --format json: { type: 'tool_use', part: { tool, state: { input } } }, said once
|
|
166
|
+
// the tool is done; its reasoning as { type: 'reasoning' }.
|
|
167
|
+
export function openCodeSteps(output, { root = null } = {}) {
|
|
168
|
+
const steps = [];
|
|
169
|
+
for (const event of jsonEvents(output)) {
|
|
170
|
+
if (event?.type === 'reasoning' && String(event.part?.text ?? '').trim()) { push(steps, { kind: 'think', what: null }); continue; }
|
|
171
|
+
if (event?.type !== 'tool_use') continue;
|
|
172
|
+
const step = toolStep(event.part?.tool, event.part?.state?.input, { root });
|
|
173
|
+
if (step) push(steps, step);
|
|
174
|
+
}
|
|
175
|
+
return steps.slice(-STEPS_KEPT);
|
|
176
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
3
|
+
// THE INVITATION TO THE APP (2026-11-10, asked by the author): whoever updates MADRE and uses
|
|
4
|
+
// it in the browser is asked, once per version, whether to stay in the browser or download the app for
|
|
5
|
+
// their computer — a window on Home after the update (public/salas-mac.js, offerApp; it was a strip
|
|
6
|
+
// until the author asked for the choice, 2026-11-10). Someone new meets the app at madre.run, where
|
|
7
|
+
// they download it; nothing here speaks to them.
|
|
8
|
+
//
|
|
9
|
+
// Not inside the app, not to whoever already has MADRE.app in Applications, and not before the app can
|
|
10
|
+
// be downloaded for that desktop: madre.run/app/latest.json — what the app's own updater reads — has
|
|
11
|
+
// to list it (a Mac only, today). That file is asked for only when everything else says yes, at most
|
|
12
|
+
// once a day, and nothing goes with the request.
|
|
13
|
+
|
|
14
|
+
import { existsSync } from 'node:fs';
|
|
15
|
+
import { readFile, writeFile, mkdir } from 'node:fs/promises';
|
|
16
|
+
import { homedir } from 'node:os';
|
|
17
|
+
import { join } from 'node:path';
|
|
18
|
+
import { cameFromOlder } from './whats-new.mjs';
|
|
19
|
+
import { isVersion } from './updates.mjs';
|
|
20
|
+
|
|
21
|
+
export const APP_PAGE = 'https://madre.run/app/';
|
|
22
|
+
export const APP_MANIFEST = 'https://madre.run/app/latest.json';
|
|
23
|
+
export const APP_INVITE_ANSWERS = ['shown', 'open', 'later'];
|
|
24
|
+
const FILE = 'app-invite.json';
|
|
25
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
26
|
+
|
|
27
|
+
// Where an installed MADRE.app would be: the Applications of the computer or of this person.
|
|
28
|
+
export const appInstalled = ({ home = homedir(), exists = existsSync } = {}) => ['/Applications/MADRE.app', join(home, 'Applications', 'MADRE.app')].some((path) => exists(path));
|
|
29
|
+
|
|
30
|
+
async function readKept(root) {
|
|
31
|
+
try { return JSON.parse(await readFile(join(root, FILE), 'utf8')) ?? {}; } catch { return {}; }
|
|
32
|
+
}
|
|
33
|
+
async function keep(root, change) {
|
|
34
|
+
await mkdir(root, { recursive: true });
|
|
35
|
+
await writeFile(join(root, FILE), `${JSON.stringify({ ...(await readKept(root)), ...change }, null, 2)}\n`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Which desktop the person is at (2026-11-10): a Mac, Windows — also when MADRE runs in WSL, since the
|
|
39
|
+
// person is at Windows and the app they would download is Windows' — or Linux.
|
|
40
|
+
export const DESKTOPS = ['mac', 'windows', 'linux'];
|
|
41
|
+
export const desktopOf = ({ platform = process.platform, wsl = false } = {}) => (platform === 'darwin' ? 'mac' : platform === 'win32' || wsl ? 'windows' : platform === 'linux' ? 'linux' : null);
|
|
42
|
+
// How the app's updater names each desktop in latest.json (`darwin-aarch64`, `windows-x86_64`…).
|
|
43
|
+
const MANIFEST_PREFIX = { mac: 'darwin-', windows: 'windows-', linux: 'linux-' };
|
|
44
|
+
|
|
45
|
+
// The desktops the app can be downloaded for: what madre.run/app/latest.json says, kept for a day. A
|
|
46
|
+
// manifest with a version and no list of platforms is a Mac's (the first app, 2026-11). A failed read
|
|
47
|
+
// is kept too, so a computer without internet does not ask on every visit.
|
|
48
|
+
export async function appDesktops({ root, fetchImpl = globalThis.fetch, url = process.env.PULSE_APP_MANIFEST_URL ?? APP_MANIFEST, now = Date.now() }) {
|
|
49
|
+
const kept = await readKept(root);
|
|
50
|
+
if (kept.checkedAt && now - kept.checkedAt < DAY_MS && Array.isArray(kept.desktops)) return kept.desktops;
|
|
51
|
+
let desktops = [];
|
|
52
|
+
try {
|
|
53
|
+
const response = await fetchImpl(url, { headers: { accept: 'application/json' }, signal: AbortSignal.timeout(5000) });
|
|
54
|
+
const manifest = response.ok ? await response.json().catch(() => null) : null;
|
|
55
|
+
if (isVersion(manifest?.version)) {
|
|
56
|
+
const keys = manifest.platforms && typeof manifest.platforms === 'object' ? Object.keys(manifest.platforms) : null;
|
|
57
|
+
desktops = keys ? DESKTOPS.filter((desktop) => keys.some((key) => key.startsWith(MANIFEST_PREFIX[desktop]))) : ['mac'];
|
|
58
|
+
}
|
|
59
|
+
} catch { /* not reachable: nothing to download today */ }
|
|
60
|
+
await keep(root, { desktops, checkedAt: now }).catch(() => null);
|
|
61
|
+
return desktops;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Everything but the download, without touching the network: a desktop, outside the app, an update,
|
|
65
|
+
// no app installed here, and not yet answered in this version.
|
|
66
|
+
export function appInviteDue({ desktop, env = process.env, novelty, version, answeredFor = null, installed = false }) {
|
|
67
|
+
if (!desktop || env.MADRE_APP === '1') return false;
|
|
68
|
+
if (!cameFromOlder(novelty, version)) return false;
|
|
69
|
+
if (installed) return false;
|
|
70
|
+
return answeredFor !== version;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// What Home asks: whether to show the choice now, for which desktop, and where its link goes. Only
|
|
74
|
+
// for a desktop the app is published for: Windows and Linux see nothing until theirs is.
|
|
75
|
+
export async function appInvite({ root, novelty, version, platform, wsl = false, env, fetchImpl, installed }) {
|
|
76
|
+
const desktop = desktopOf({ platform, wsl });
|
|
77
|
+
const kept = await readKept(root);
|
|
78
|
+
const here = installed ?? (desktop === 'mac' && appInstalled());
|
|
79
|
+
if (!appInviteDue({ desktop, env, novelty, version, answeredFor: kept.answered ?? null, installed: here })) return { show: false, desktop };
|
|
80
|
+
const desktops = await appDesktops({ root, fetchImpl });
|
|
81
|
+
// The page can be another for a test on this computer (PULSE_APP_PAGE_URL), as the manifest can.
|
|
82
|
+
return desktops.includes(desktop) ? { show: true, desktop, url: env?.PULSE_APP_PAGE_URL ?? process.env.PULSE_APP_PAGE_URL ?? APP_PAGE } : { show: false, desktop };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// «Download» or «Stay in the browser» spends it for this version; «shown» only counts.
|
|
86
|
+
export async function answerAppInvite(root, { answer, version }) {
|
|
87
|
+
if (!APP_INVITE_ANSWERS.includes(answer)) return { error: 'answer' };
|
|
88
|
+
if (answer !== 'shown') await keep(root, { answered: version });
|
|
89
|
+
return { ok: true };
|
|
90
|
+
}
|
package/src/auth-probe.mjs
CHANGED
|
@@ -6,6 +6,8 @@ import { access, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
|
6
6
|
import { homedir } from 'node:os';
|
|
7
7
|
import { join } from 'node:path';
|
|
8
8
|
import { promisify } from 'node:util';
|
|
9
|
+
import { geminiApiKeyPresent } from './runtime-detection.mjs';
|
|
10
|
+
import { parseGrokStatus } from './adapters/grok.mjs';
|
|
9
11
|
|
|
10
12
|
const execFileAsync = promisify(execFile);
|
|
11
13
|
const stripAnsi = (text) => String(text ?? '').replace(/\[[0-9;]*[A-Za-z]/g, '');
|
|
@@ -225,6 +227,20 @@ export const AGENT_SETUP = {
|
|
|
225
227
|
account: 'Signs in with your Cursor account and uses its plan. A free plan answers only with Auto, and only while it has use left.',
|
|
226
228
|
paid: true,
|
|
227
229
|
},
|
|
230
|
+
// Grok Build, xAI's own CLI (2026-11-06). Without a terminal, `grok login` already gives a code to
|
|
231
|
+
// confirm on xAI's page (accounts.x.ai/oauth2/device), and `--device-auth` asks for exactly that:
|
|
232
|
+
// the room shows the code, and it works the same when MADRE runs on another computer.
|
|
233
|
+
grok: {
|
|
234
|
+
install: ['npm install -g @xai-official/grok', 'or: curl -fsSL https://x.ai/cli/install.sh | bash'],
|
|
235
|
+
login: ['login', '--device-auth'],
|
|
236
|
+
loginNote: 'Gives you a code to confirm on xAI\'s page with your Grok account.',
|
|
237
|
+
browser: true,
|
|
238
|
+
room: { deviceCode: true },
|
|
239
|
+
terminal: 'grok login',
|
|
240
|
+
vendor: 'xAI',
|
|
241
|
+
account: 'Signs in with your Grok account (SuperGrok or an X subscription) and uses its plan.',
|
|
242
|
+
paid: true,
|
|
243
|
+
},
|
|
228
244
|
};
|
|
229
245
|
|
|
230
246
|
// Installing a CLI from the room itself. npm is the common denominator: every one of these
|
|
@@ -235,6 +251,8 @@ export const AGENT_PACKAGE = {
|
|
|
235
251
|
claude: '@anthropic-ai/claude-code',
|
|
236
252
|
gemini: '@google/gemini-cli',
|
|
237
253
|
opencode: 'opencode-ai',
|
|
254
|
+
// Its install script fetches nothing: the binary comes as an npm dependency for each platform.
|
|
255
|
+
grok: '@xai-official/grok',
|
|
238
256
|
};
|
|
239
257
|
// One honest line per agent about the account it needs, for the bridge and for Settings › Agents.
|
|
240
258
|
// Which agents take a pasted key instead of a browser flow.
|
|
@@ -290,6 +308,8 @@ export function installPlanFor(agent, { prefix = null } = {}) {
|
|
|
290
308
|
// the providers in its `methods`, and its keys are pasted. Every plan also carries `terminal`:
|
|
291
309
|
// the same sign-in typed by hand, for whoever prefers it.
|
|
292
310
|
export function loginPlanFor(agent, { method = null } = {}) {
|
|
311
|
+
// Gemini answering through its API has no CLI to sign in with: its key is its sign-in.
|
|
312
|
+
if (agent?.viaApi) return null;
|
|
293
313
|
const setup = AGENT_SETUP[agent.id];
|
|
294
314
|
if (!setup) return null;
|
|
295
315
|
const headless = Boolean(setup.browser) && setup.login.length > 0;
|
|
@@ -366,7 +386,14 @@ export function geminiSignIn({ env = process.env, verifyMs = 30000 } = {}) {
|
|
|
366
386
|
|
|
367
387
|
export async function probeAgentAuth(agent) {
|
|
368
388
|
if (agent.id === 'madre') return agent.ready ? { state: 'signed-in', detail: `local · ${agent.version ?? 'Ollama'}` } : { state: 'signed-out', detail: 'Ollama is not running or has no chat model' };
|
|
389
|
+
// Gemini without its CLI answers through Google's API with a Gemini key (adapters/gemini-rest.mjs):
|
|
390
|
+
// the key is its whole sign-in, checked against Google when it was pasted (credentials.mjs). The
|
|
391
|
+
// CLI's own files (a Google sign-in left behind, a Vertex setting) say nothing without the CLI.
|
|
392
|
+
if (agent.id === 'gemini' && !agent.path) return await geminiApiKeyPresent() ? { state: 'signed-in', detail: 'via API key · Google AI Studio API' } : { state: 'not-installed', detail: 'not found on this computer' };
|
|
393
|
+
if (agent.id === 'gemini') return probeGemini();
|
|
369
394
|
if (!agent.detected || !agent.path) return { state: 'not-installed', detail: 'not found on this computer' };
|
|
395
|
+
// Another program with the agent's name (runtime-detection.mjs, `foreign`): nothing is asked of it.
|
|
396
|
+
if (agent.foreign) return { state: 'not-installed', detail: `another program is installed as ${agent.id}` };
|
|
370
397
|
const answered = (result, read) => (result.timedOut ? UNANSWERED : read(result));
|
|
371
398
|
switch (agent.id) {
|
|
372
399
|
case 'codex': return answered(await run(agent.path, ['login', 'status']), parseCodexLoginStatus);
|
|
@@ -384,6 +411,11 @@ export async function probeAgentAuth(agent) {
|
|
|
384
411
|
return openCodeOwnModels(own) ?? listed;
|
|
385
412
|
}
|
|
386
413
|
case 'cursor': return answered(await run(agent.path, ['status']), parseCursorStatus);
|
|
414
|
+
// Grok has no status command: `grok models` says whether there is a session (and exits 0 both ways).
|
|
415
|
+
case 'grok': {
|
|
416
|
+
const saved = await exists(join(process.env.GROK_HOME || join(homedir(), '.grok'), 'auth.json'));
|
|
417
|
+
return answered(await run(agent.path, ['models']), ({ stdout = '', stderr = '' }) => parseGrokStatus(stripAnsi(`${stdout}\n${stderr}`), process.env, { saved }));
|
|
418
|
+
}
|
|
387
419
|
case 'gemini': return probeGemini();
|
|
388
420
|
default: return { state: 'unknown', detail: 'no probe for this agent' };
|
|
389
421
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
3
|
+
// The public half of the key madre.run signs subscription keys with (scripts/billing-key.mjs,
|
|
4
|
+
// docs/private/SUSCRIPCION.md). The private half lives only in madre.run's secrets and on the author's
|
|
5
|
+
// computer. Null: no key is ever accepted, and the author's switch refuses to turn the subscription on.
|
|
6
|
+
export const BILLING_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
|
|
7
|
+
MCowBQYDK2VwAyEAb69EhVG3QhRsB7uH6vxgyQYvt8tQ+lkOHTrrxl3RkMY=
|
|
8
|
+
-----END PUBLIC KEY-----`;
|