@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/router.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// SPDX-License-Identifier: BUSL-1.1
|
|
2
2
|
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
3
|
-
const supported = new Set(['codex', 'claude', 'gemini', 'opencode', 'cursor']);
|
|
3
|
+
const supported = new Set(['codex', 'claude', 'gemini', 'opencode', 'cursor', 'grok']);
|
|
4
4
|
|
|
5
5
|
export function parseMessage(text, fallbackTarget = null) {
|
|
6
6
|
const value = String(text ?? '').trim();
|
package/src/runs.mjs
CHANGED
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
|
|
27
27
|
import { homedir } from 'node:os';
|
|
28
28
|
import { join } from 'node:path';
|
|
29
|
+
import { readFile } from 'node:fs/promises';
|
|
29
30
|
|
|
30
31
|
export const MAX_COMMANDS = 5;
|
|
31
32
|
const MAX_REASON = 300;
|
|
@@ -140,3 +141,41 @@ export function withoutRunRequest(text) {
|
|
|
140
141
|
const last = [...source.matchAll(/```pulse-run\s*\n[\s\S]*?```/gi)].at(-1);
|
|
141
142
|
return source.slice(0, last.index).trimEnd();
|
|
142
143
|
}
|
|
144
|
+
|
|
145
|
+
// Resolves what script package.json defines for a package-manager command (RX-3).
|
|
146
|
+
// Returns the raw script string if defined, or null. Only where the manager really runs that script:
|
|
147
|
+
// npm runs one by its name alone only for test, start, stop and restart (`npm build` is «Unknown
|
|
148
|
+
// command»), and `bun test` and `bun build` are Bun's own test runner and bundler, not the scripts.
|
|
149
|
+
export function resolveScript(argv, packageJson) {
|
|
150
|
+
if (!Array.isArray(argv) || !packageJson || typeof packageJson !== 'object') return null;
|
|
151
|
+
const scripts = packageJson.scripts;
|
|
152
|
+
if (!scripts || typeof scripts !== 'object') return null;
|
|
153
|
+
const [pkg, sub, ...rest] = argv;
|
|
154
|
+
const name = String(pkg ?? '').toLowerCase();
|
|
155
|
+
if (!['npm', 'pnpm', 'yarn', 'bun'].includes(name)) return null;
|
|
156
|
+
const script = (key) => (key && typeof scripts[key] === 'string' ? scripts[key] : null);
|
|
157
|
+
if (sub === 'run' || sub === 'run-script') return script(rest[0]);
|
|
158
|
+
if (name === 'bun') return null;
|
|
159
|
+
if (sub === 'test' || (name !== 'yarn' && (sub === 't' || sub === 'tst'))) return script('test');
|
|
160
|
+
if (name === 'npm') return ['start', 'stop', 'restart'].includes(sub) ? script(sub) : null;
|
|
161
|
+
return script(sub);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Attaches the real script from package.json to each command when available (RX-3).
|
|
165
|
+
export async function attachCommandScripts(commands, { projectRoot, readFile: read = readFile } = {}) {
|
|
166
|
+
if (!projectRoot || !Array.isArray(commands) || !commands.length) return commands;
|
|
167
|
+
let pkg = null;
|
|
168
|
+
try {
|
|
169
|
+
const raw = await read(join(projectRoot, 'package.json'), 'utf8');
|
|
170
|
+
pkg = JSON.parse(raw);
|
|
171
|
+
} catch {
|
|
172
|
+
return commands;
|
|
173
|
+
}
|
|
174
|
+
for (const command of commands) {
|
|
175
|
+
if (command?.argv && !command.script) {
|
|
176
|
+
const script = resolveScript(command.argv, pkg);
|
|
177
|
+
if (script) command.script = script;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return commands;
|
|
181
|
+
}
|
|
@@ -6,6 +6,7 @@ import { homedir, tmpdir, userInfo } from 'node:os';
|
|
|
6
6
|
import { delimiter, join } from 'node:path';
|
|
7
7
|
import { execFile } from 'node:child_process';
|
|
8
8
|
import { promisify } from 'node:util';
|
|
9
|
+
import { keyFromGeminiEnvFile } from './mcp/image-server.mjs';
|
|
9
10
|
|
|
10
11
|
const accountHome = () => { try { return userInfo().homedir || homedir(); } catch { return homedir(); } };
|
|
11
12
|
|
|
@@ -51,6 +52,17 @@ const definitions = [
|
|
|
51
52
|
versionArgs: ['--version'],
|
|
52
53
|
adapter: 'cursor-readonly',
|
|
53
54
|
},
|
|
55
|
+
{
|
|
56
|
+
// Grok Build, xAI's own CLI (2026-11-06): npm puts it beside node, its own installer in
|
|
57
|
+
// ~/.grok/bin. Another program is called `grok` too (the community's grok-dev, which writes to
|
|
58
|
+
// ~/.grok as well), so only the one that says «grok <version> (<build>)» is spoken to.
|
|
59
|
+
id: 'grok',
|
|
60
|
+
label: 'Grok',
|
|
61
|
+
candidates: [...new Set(['grok', '/opt/homebrew/bin/grok', join(homedir(), '.grok', 'bin', 'grok'), join(accountHome(), '.grok', 'bin', 'grok')])],
|
|
62
|
+
versionArgs: ['--version'],
|
|
63
|
+
versionPattern: /^grok\s+\d+\.\d+\.\d+\s+\(/,
|
|
64
|
+
adapter: 'grok-readonly',
|
|
65
|
+
},
|
|
54
66
|
];
|
|
55
67
|
|
|
56
68
|
const OFFICIAL_DESTINATIONS = {
|
|
@@ -176,19 +188,47 @@ async function readVersion(path, args) {
|
|
|
176
188
|
export const toolsPrefix = (env = process.env) => join(env.PULSE_HOME ?? join(homedir(), '.pulse'), 'tools');
|
|
177
189
|
export const toolsBin = (env = process.env) => (process.platform === 'win32' ? toolsPrefix(env) : join(toolsPrefix(env), 'bin'));
|
|
178
190
|
|
|
179
|
-
|
|
191
|
+
// Gemini without its CLI (a575180, reviewed 2026-11-06): a Gemini API key the CLI's own places hold
|
|
192
|
+
// (GEMINI_API_KEY, or ~/.gemini/.env, where MADRE writes a pasted key) is enough to answer through
|
|
193
|
+
// Google's API. Only those: GOOGLE_API_KEY is any Google key (Maps, say), and the keychain is asked
|
|
194
|
+
// only when a turn needs the key, never on every look, where it could raise the system's prompt.
|
|
195
|
+
// PULSE_GEMINI_ADAPTER=rest takes the API even with the CLI there.
|
|
196
|
+
export async function geminiApiKeyPresent(env = process.env, fromFile = keyFromGeminiEnvFile) {
|
|
197
|
+
return Boolean(env.GEMINI_API_KEY) || Boolean(await fromFile(env).catch(() => null));
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export async function detectAgents({ env = process.env, keyPresent = geminiApiKeyPresent, finder = findExecutable } = {}) {
|
|
180
201
|
const searchPath = [env.PATH ?? '', toolsBin(env)].filter(Boolean).join(delimiter);
|
|
181
202
|
return Promise.all(definitions.map(async (definition) => {
|
|
182
|
-
|
|
183
|
-
|
|
203
|
+
let path = await finder(definition.candidates, searchPath, env);
|
|
204
|
+
let detected = Boolean(path);
|
|
205
|
+
let ready = detected && Boolean(definition.adapter);
|
|
206
|
+
let version = path ? await readVersion(path, definition.versionArgs) : null;
|
|
207
|
+
let adapter = definition.adapter ?? null;
|
|
208
|
+
let viaApi = false;
|
|
209
|
+
// A program with the right name that is not the right program is found, never spoken to.
|
|
210
|
+
const foreign = Boolean(path && definition.versionPattern && version && !definition.versionPattern.test(version));
|
|
211
|
+
if (foreign) ready = false;
|
|
212
|
+
|
|
213
|
+
if (definition.id === 'gemini' && (!detected || env.PULSE_GEMINI_ADAPTER === 'rest') && await keyPresent(env)) {
|
|
214
|
+
detected = true;
|
|
215
|
+
ready = true;
|
|
216
|
+
adapter = 'gemini-rest';
|
|
217
|
+
viaApi = true;
|
|
218
|
+
path = null;
|
|
219
|
+
version = 'Google AI Studio API';
|
|
220
|
+
}
|
|
221
|
+
|
|
184
222
|
return {
|
|
185
223
|
id: definition.id,
|
|
186
224
|
label: definition.label,
|
|
187
225
|
detected,
|
|
188
|
-
ready
|
|
189
|
-
adapter
|
|
226
|
+
ready,
|
|
227
|
+
adapter,
|
|
190
228
|
path,
|
|
191
|
-
version
|
|
229
|
+
version,
|
|
230
|
+
...(viaApi ? { viaApi: true } : {}),
|
|
231
|
+
...(foreign ? { foreign: true } : {}),
|
|
192
232
|
route: agentRouteFromEnvironment(definition.id, env),
|
|
193
233
|
};
|
|
194
234
|
}));
|
package/src/salas.mjs
CHANGED
|
@@ -12,12 +12,13 @@
|
|
|
12
12
|
|
|
13
13
|
import { spawn } from 'node:child_process';
|
|
14
14
|
import { createHash } from 'node:crypto';
|
|
15
|
-
import { closeSync,
|
|
16
|
-
import { mkdir, readdir, readFile, rename, stat, writeFile } from 'node:fs/promises';
|
|
15
|
+
import { closeSync, realpathSync } from 'node:fs';
|
|
16
|
+
import { mkdir, open, readdir, readFile, rename, stat, writeFile } from 'node:fs/promises';
|
|
17
17
|
import * as nodePath from 'node:path';
|
|
18
18
|
import { basename, dirname, join, resolve } from 'node:path';
|
|
19
19
|
import { fileURLToPath } from 'node:url';
|
|
20
20
|
import { oneAtATime, writeWhole } from './json-file.mjs';
|
|
21
|
+
import { defaultStateRoot, fichaHeaders, openPrivateLog } from './ficha.mjs';
|
|
21
22
|
|
|
22
23
|
const MADRE_BIN = fileURLToPath(new URL('../bin/madre.mjs', import.meta.url));
|
|
23
24
|
|
|
@@ -89,11 +90,55 @@ export function projectRootFor({ command, named = true, project, cwd, home, stat
|
|
|
89
90
|
|
|
90
91
|
// Where the project is, kept beside its record (S-002): the room's id is a hash of the path and
|
|
91
92
|
// cannot be turned back into it, and a room that is closed has to be found to be opened again.
|
|
92
|
-
// Written whole or not at all.
|
|
93
|
-
export async function markProject(roomDir, projectRoot, { now = new Date() } = {}) {
|
|
93
|
+
// Written whole or not at all. With the port it opened on (L-6): what else the record holds stays.
|
|
94
|
+
export async function markProject(roomDir, projectRoot, { now = new Date(), port = null, keepOpen = null } = {}) {
|
|
94
95
|
await mkdir(roomDir, { recursive: true });
|
|
95
96
|
const file = join(roomDir, 'project.json');
|
|
96
|
-
await oneAtATime(file, () =>
|
|
97
|
+
await oneAtATime(file, async () => {
|
|
98
|
+
const was = await readJson(file);
|
|
99
|
+
await writeWhole(file, `${JSON.stringify({ ...(was ?? {}), root: projectRoot, name: basename(projectRoot), lastOpened: now.toISOString(), ...(Number.isInteger(port) ? { port } : {}), ...(typeof keepOpen === 'boolean' ? { keepOpen } : {}) })}\n`);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Whether a project comes back when MADRE starts as a service (L-3): set when it opens, taken away
|
|
104
|
+
// only when the person closes it. A restart of the computer or a fall of MADRE leaves it on.
|
|
105
|
+
export async function keepOpenProject(stateRoot, id, keepOpen) {
|
|
106
|
+
if (typeof id !== 'string' || !/^[^/\\]+$/.test(id) || id === '.' || id === '..') return false;
|
|
107
|
+
const file = join(stateRoot, 'rooms', id, 'project.json');
|
|
108
|
+
return oneAtATime(file, async () => {
|
|
109
|
+
const was = await readJson(file);
|
|
110
|
+
if (!was) return false;
|
|
111
|
+
await writeWhole(file, `${JSON.stringify({ ...was, keepOpen: Boolean(keepOpen) })}\n`);
|
|
112
|
+
return true;
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Each project keeps its port (L-6, Carlos's server, 2026-11-04). A project opened from Home took
|
|
117
|
+
// the first free port from 4317, so its number depended on the order things were opened in and
|
|
118
|
+
// changed after a restart; on a server reached through a tunnel the new one fell outside the
|
|
119
|
+
// tunnel, and links between projects need the same number on both ends. What a project opened on
|
|
120
|
+
// is kept in its record; the next time it asks for that one first, and a project with none skips
|
|
121
|
+
// the ports other projects already keep.
|
|
122
|
+
export async function keptPorts(stateRoot, projectRoot) {
|
|
123
|
+
const mine = projectRoomId(projectRoot);
|
|
124
|
+
const dir = join(stateRoot, 'rooms');
|
|
125
|
+
const others = new Set();
|
|
126
|
+
let own = null;
|
|
127
|
+
for (const id of await readdir(dir).catch(() => [])) {
|
|
128
|
+
const port = (await readJson(join(dir, id, 'project.json')))?.port;
|
|
129
|
+
if (!Number.isInteger(port)) continue;
|
|
130
|
+
if (id === mine) own = port; else others.add(port);
|
|
131
|
+
}
|
|
132
|
+
return { mine: own, others };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// The port to try: its own when it has one and it is free, else the first free one from `base`
|
|
136
|
+
// that no other project keeps. `taken(port)` says whether something is listening there.
|
|
137
|
+
export async function choosePort({ base, mine = null, others = new Set(), taken }) {
|
|
138
|
+
if (Number.isInteger(mine) && !(await taken(mine))) return mine;
|
|
139
|
+
let port = base;
|
|
140
|
+
while (others.has(port) || await taken(port)) port += 1;
|
|
141
|
+
return port;
|
|
97
142
|
}
|
|
98
143
|
|
|
99
144
|
// ---- The lobby: adding projects (2026-10-10). A browser cannot hand MADRE the path of a folder,
|
|
@@ -155,12 +200,30 @@ export async function listFolders({ path = null, home, stateRoot }) {
|
|
|
155
200
|
}
|
|
156
201
|
|
|
157
202
|
// Folders that look like projects in the places people keep them, newest first, none already here.
|
|
158
|
-
|
|
203
|
+
// Since 1.1 (the welcome of 2026-11-08, docs/private/BIENVENIDA-1.1.md) also the folders the
|
|
204
|
+
// person already opened with another tool, each saying which: like moving to a new phone, what was
|
|
205
|
+
// there comes along. Only the folder paths those tools keep are read, never a conversation, a key or
|
|
206
|
+
// a setting (see foldersFromTools).
|
|
207
|
+
export async function suggestProjects({ home, stateRoot, limit = 24, tools = true, platform = process.platform }) {
|
|
159
208
|
const top = realFolder(home);
|
|
160
209
|
const known = await knownRoots(stateRoot);
|
|
161
210
|
const state = realFolder(stateRoot);
|
|
162
211
|
const seen = new Map();
|
|
163
212
|
const places = new Set(); // `Projects` and `projects` are one folder on a Mac: read it once
|
|
213
|
+
const keep = async (full, from = null) => {
|
|
214
|
+
const real = realFolder(full);
|
|
215
|
+
if (known.has(real) || inside(real, state)) return;
|
|
216
|
+
const had = seen.get(real);
|
|
217
|
+
if (had) { if (from && !had.from.includes(from)) had.from.push(from); return; }
|
|
218
|
+
const info = await stat(real).catch(() => null);
|
|
219
|
+
if (!info?.isDirectory()) return;
|
|
220
|
+
seen.set(real, { name: basename(real), path: real, when: info.mtimeMs ?? 0, from: from ? [from] : [] });
|
|
221
|
+
};
|
|
222
|
+
if (tools) for (const { path, from } of await foldersFromTools({ home: top, platform })) {
|
|
223
|
+
const real = realFolder(path);
|
|
224
|
+
if (!toolFolderFits(real, top)) continue;
|
|
225
|
+
await keep(real, from);
|
|
226
|
+
}
|
|
164
227
|
for (const place of PROJECT_HOMES) {
|
|
165
228
|
const base = join(top, place);
|
|
166
229
|
const info = await stat(base).catch(() => null);
|
|
@@ -170,12 +233,83 @@ export async function suggestProjects({ home, stateRoot, limit = 24 }) {
|
|
|
170
233
|
for (const entry of names) {
|
|
171
234
|
if (!entry.isDirectory() || entry.name.startsWith('.') || NOT_PROJECTS.has(entry.name)) continue;
|
|
172
235
|
const full = join(base, entry.name);
|
|
173
|
-
if (seen.has(
|
|
174
|
-
|
|
175
|
-
seen.set(full, { name: entry.name, path: full, when });
|
|
236
|
+
if (seen.has(realFolder(full)) || !(await looksLikeProject(full))) continue;
|
|
237
|
+
await keep(full);
|
|
176
238
|
}
|
|
177
239
|
}
|
|
178
|
-
|
|
240
|
+
// What another tool already knows comes first, then the rest; the newest first in each.
|
|
241
|
+
return [...seen.values()]
|
|
242
|
+
.sort((a, b) => Number(b.from.length > 0) - Number(a.from.length > 0) || b.when - a.when)
|
|
243
|
+
.slice(0, limit)
|
|
244
|
+
.map(({ name, path, when, from }) => ({ name, path, when: when ? new Date(when).toISOString() : null, from }));
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// A folder another tool knows is offered only inside the home, never the home itself, a folder
|
|
248
|
+
// hidden anywhere on its way (a worktree under .claude/, a tool's own state) or one of the places
|
|
249
|
+
// that hold everything (Documents, Desktop…): those are where projects live, not projects.
|
|
250
|
+
const HOLDERS = new Set(['documents', 'documentos', 'desktop', 'escritorio', 'downloads', 'descargas', ...PROJECT_HOMES.filter(Boolean).map((one) => one.toLowerCase())]);
|
|
251
|
+
export function toolFolderFits(folder, home, path = nodePath) {
|
|
252
|
+
if (!insideFolder(folder, home, path) || sameFolder(folder, home, path)) return false;
|
|
253
|
+
const parts = path.relative(home, folder).split(path.sep);
|
|
254
|
+
if (parts.some((part) => part.startsWith('.') || NOT_PROJECTS.has(part))) return false;
|
|
255
|
+
return !(parts.length === 1 && HOLDERS.has(parts[0].toLowerCase()));
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// The folders other tools on this computer already worked in, by tool. Each one is read for paths
|
|
259
|
+
// and nothing else, and a tool that is not there, or writes its file differently, simply adds none:
|
|
260
|
+
// claude ~/.claude.json, the names of its `projects` (Claude Code keeps one entry per folder)
|
|
261
|
+
// codex ~/.codex/sessions, the `cwd` on the first line of the newest sessions
|
|
262
|
+
// gemini ~/.gemini/projects.json, the names of its `projects`
|
|
263
|
+
// cursor Cursor's storage.json, the folders of its recent windows
|
|
264
|
+
// vscode the same file of Visual Studio Code
|
|
265
|
+
// In WSL, Cursor and VS Code keep theirs on the Windows side: only Linux's own are read.
|
|
266
|
+
export const TOOL_NAMES = { claude: 'Claude Code', codex: 'Codex', gemini: 'Gemini', cursor: 'Cursor', vscode: 'VS Code' };
|
|
267
|
+
const CODEX_SESSIONS_READ = 300;
|
|
268
|
+
export async function foldersFromTools({ home, platform = process.platform }) {
|
|
269
|
+
const found = [];
|
|
270
|
+
const add = (path, from) => { if (typeof path === 'string' && nodePath.isAbsolute(path)) found.push({ path, from }); };
|
|
271
|
+
const claude = await readJson(join(home, '.claude.json'));
|
|
272
|
+
for (const path of Object.keys(claude?.projects ?? {})) add(path, 'claude');
|
|
273
|
+
const gemini = await readJson(join(home, '.gemini', 'projects.json'));
|
|
274
|
+
for (const path of Object.keys(gemini?.projects ?? {})) add(path, 'gemini');
|
|
275
|
+
for (const path of await codexFolders(join(home, '.codex', 'sessions'))) add(path, 'codex');
|
|
276
|
+
const appData = platform === 'darwin' ? join(home, 'Library', 'Application Support') : join(home, '.config');
|
|
277
|
+
for (const [from, app] of [['cursor', 'Cursor'], ['vscode', 'Code']]) {
|
|
278
|
+
const storage = await readJson(join(appData, app, 'User', 'globalStorage', 'storage.json'));
|
|
279
|
+
const uris = [...Object.keys(storage?.profileAssociations?.workspaces ?? {}), ...(storage?.backupWorkspaces?.folders ?? []).map((one) => one?.folderUri)];
|
|
280
|
+
for (const uri of uris) { if (typeof uri === 'string' && uri.startsWith('file://')) { try { add(fileURLToPath(uri), from); } catch { /* not a local folder */ } } }
|
|
281
|
+
}
|
|
282
|
+
return found;
|
|
283
|
+
}
|
|
284
|
+
// Codex writes one file per session under year/month/day; the newest are read, and of each only its
|
|
285
|
+
// first line, the one that says where the session ran.
|
|
286
|
+
async function codexFolders(root) {
|
|
287
|
+
const files = [];
|
|
288
|
+
const walk = async (dir, depth) => {
|
|
289
|
+
const entries = await readdir(dir, { withFileTypes: true }).catch(() => []);
|
|
290
|
+
for (const entry of entries.sort((a, b) => b.name.localeCompare(a.name))) {
|
|
291
|
+
if (files.length >= CODEX_SESSIONS_READ) return;
|
|
292
|
+
const full = join(dir, entry.name);
|
|
293
|
+
if (entry.isDirectory() && depth < 3) await walk(full, depth + 1);
|
|
294
|
+
else if (entry.isFile() && entry.name.endsWith('.jsonl')) files.push(full);
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
await walk(root, 0);
|
|
298
|
+
const folders = new Set();
|
|
299
|
+
for (const file of files) {
|
|
300
|
+
// The first line may be longer than what is read: then the `cwd` is taken from the text itself.
|
|
301
|
+
const said = /"cwd":"((?:[^"\\]|\\.)*)"/.exec(await firstLine(file));
|
|
302
|
+
try { const cwd = said ? JSON.parse(`"${said[1]}"`) : null; if (cwd) folders.add(cwd); } catch { /* not a session */ }
|
|
303
|
+
}
|
|
304
|
+
return [...folders];
|
|
305
|
+
}
|
|
306
|
+
async function firstLine(file) {
|
|
307
|
+
const handle = await open(file, 'r').catch(() => null);
|
|
308
|
+
if (!handle) return '';
|
|
309
|
+
try {
|
|
310
|
+
const { buffer, bytesRead } = await handle.read(Buffer.alloc(16384), 0, 16384, 0);
|
|
311
|
+
return buffer.subarray(0, bytesRead).toString('utf8').split('\n')[0];
|
|
312
|
+
} finally { await handle.close(); }
|
|
179
313
|
}
|
|
180
314
|
|
|
181
315
|
// Associates one folder with the lobby: a project inside the home, not the home itself and not
|
|
@@ -194,7 +328,7 @@ export async function associateProject({ root, home, stateRoot, now = new Date()
|
|
|
194
328
|
const file = join(roomDir, 'project.json');
|
|
195
329
|
const before = await oneAtATime(file, async () => {
|
|
196
330
|
const was = await readJson(file);
|
|
197
|
-
await writeWhole(file, `${JSON.stringify({ root: folder, name: basename(folder), lastOpened: was?.lastOpened ?? null, added: was?.added ?? now.toISOString() })}\n`);
|
|
331
|
+
await writeWhole(file, `${JSON.stringify({ ...(was ?? {}), root: folder, name: basename(folder), lastOpened: was?.lastOpened ?? null, added: was?.added ?? now.toISOString() })}\n`);
|
|
198
332
|
return was;
|
|
199
333
|
});
|
|
200
334
|
return { id, name: basename(folder), root: folder, already: Boolean(before) };
|
|
@@ -353,6 +487,28 @@ export async function forgetProject({ stateRoot, id }) {
|
|
|
353
487
|
return { id, name: typeof record.name === 'string' ? record.name : id, root: typeof record.root === 'string' ? record.root : null };
|
|
354
488
|
}
|
|
355
489
|
|
|
490
|
+
// A name of the person's own for a project (2026-11-13, the author: «rename it from Home»). Only
|
|
491
|
+
// what MADRE shows changes: the folder keeps its name and its place, so nothing that points at it
|
|
492
|
+
// breaks. An empty name takes the folder's back.
|
|
493
|
+
export const PROJECT_TITLE_MAX = 80;
|
|
494
|
+
export async function renameProject({ stateRoot, id, title }) {
|
|
495
|
+
if (typeof id !== 'string' || !/^[^/\\]+$/.test(id) || id === '.' || id === '..') return { error: 'unknown' };
|
|
496
|
+
const file = join(stateRoot, 'rooms', id, 'project.json');
|
|
497
|
+
const said = String(title ?? '').replace(/\s+/g, ' ').trim().slice(0, PROJECT_TITLE_MAX);
|
|
498
|
+
return oneAtATime(file, async () => {
|
|
499
|
+
const was = await readJson(file);
|
|
500
|
+
if (!was) return { error: 'unknown' };
|
|
501
|
+
const { title: _old, ...rest } = was;
|
|
502
|
+
await writeWhole(file, `${JSON.stringify(said ? { ...rest, title: said } : rest)}\n`);
|
|
503
|
+
return { id, name: said || (typeof was.name === 'string' ? was.name : id), title: said || null };
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
// The name MADRE shows for a project: the person's own, else its folder's.
|
|
507
|
+
export async function projectTitle(roomDir) {
|
|
508
|
+
const record = await readJson(join(roomDir, 'project.json'));
|
|
509
|
+
return typeof record?.title === 'string' && record.title.trim() ? record.title : null;
|
|
510
|
+
}
|
|
511
|
+
|
|
356
512
|
// Every room: the ones open now, and the ones asleep whose project is still on disk. A folder
|
|
357
513
|
// with neither (a test's, a temporary one, a room from before MADRE kept the path) is not
|
|
358
514
|
// offered: there is nothing to open (S-004).
|
|
@@ -371,9 +527,11 @@ export async function knownRooms(stateRoot) {
|
|
|
371
527
|
if (!open && !there) continue;
|
|
372
528
|
out.push({
|
|
373
529
|
id,
|
|
374
|
-
name: typeof where?.name === 'string' ? where.name : typeof mark?.project === 'string' ? mark.project : id.replace(/-[0-9a-f]{16}$/, ''),
|
|
530
|
+
name: typeof where?.title === 'string' && where.title.trim() ? where.title : typeof where?.name === 'string' ? where.name : typeof mark?.project === 'string' ? mark.project : id.replace(/-[0-9a-f]{16}$/, ''),
|
|
531
|
+
folderName: typeof where?.name === 'string' ? where.name : null,
|
|
375
532
|
root: there ? root : null,
|
|
376
533
|
lastOpened: where?.lastOpened ?? mark?.at ?? null,
|
|
534
|
+
keepOpen: where?.keepOpen === true,
|
|
377
535
|
open,
|
|
378
536
|
});
|
|
379
537
|
}
|
|
@@ -382,14 +540,18 @@ export async function knownRooms(stateRoot) {
|
|
|
382
540
|
|
|
383
541
|
// Opens a room for a project, as `madre start --project <root> --no-open` would. What it says on
|
|
384
542
|
// the way up lands in start.log beside its record: if it never comes up, that file says why.
|
|
385
|
-
|
|
543
|
+
// An update bringing the rest of MADRE along (L-13) opens each on the port it had, and Home too
|
|
544
|
+
// (`home`, as `madre lobby` does); a port that got taken meanwhile is an error, not another number.
|
|
545
|
+
export function startRoom({ projectRoot, roomDir, env = process.env, spawnImpl = spawn, bin = MADRE_BIN, port = null, home = false }) {
|
|
386
546
|
let log = 'ignore';
|
|
387
|
-
try { log =
|
|
547
|
+
try { log = openPrivateLog(join(roomDir, 'start.log')); } catch { /* no witness, still start */ }
|
|
388
548
|
// The new room is its own: what this room set for itself on the way up is not handed on.
|
|
389
549
|
const own = { ...env };
|
|
390
550
|
for (const name of ['PULSE_UPDATE_RESTART', 'PULSE_OUTBOUND_LOG']) delete own[name];
|
|
391
551
|
try {
|
|
392
|
-
const
|
|
552
|
+
const what = home ? ['lobby'] : ['start', '--project', projectRoot];
|
|
553
|
+
const where = Number.isInteger(port) && port > 0 && port < 65536 ? ['--port', String(port)] : [];
|
|
554
|
+
const child = spawnImpl(process.execPath, [bin, ...what, ...where, '--no-open'], {
|
|
393
555
|
cwd: projectRoot,
|
|
394
556
|
detached: process.platform !== 'win32',
|
|
395
557
|
windowsHide: true,
|
|
@@ -450,12 +612,13 @@ export function universeOf(research, { full = false } = {}) {
|
|
|
450
612
|
}
|
|
451
613
|
|
|
452
614
|
// What a room says about itself, read from its own page's address. A room on an older MADRE
|
|
453
|
-
// answers 404 to the routes it does not have yet, and is said to be outdated (S-005).
|
|
454
|
-
|
|
615
|
+
// answers 404 to the routes it does not have yet, and is said to be outdated (S-005). It goes with
|
|
616
|
+
// the ficha of this computer (src/ficha.mjs), as the page's own requests do.
|
|
617
|
+
export async function askRoom(port, path, { method = 'GET', body = null, fetchImpl = globalThis.fetch, timeoutMs = 1500, stateRoot = defaultStateRoot() } = {}) {
|
|
455
618
|
try {
|
|
456
619
|
const response = await fetchImpl(`http://127.0.0.1:${port}${path}`, {
|
|
457
620
|
method,
|
|
458
|
-
headers: body ? { 'content-type': 'application/json' } : {},
|
|
621
|
+
headers: { ...(await fichaHeaders(stateRoot)), ...(body ? { 'content-type': 'application/json' } : {}) },
|
|
459
622
|
body: body ? JSON.stringify(body) : undefined,
|
|
460
623
|
signal: AbortSignal.timeout(timeoutMs),
|
|
461
624
|
});
|