seerepo 1.0.0 → 1.2.0
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/README.md +1 -0
- package/bin/seerepo.js +222 -21
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,6 +4,7 @@ Your project's map from the terminal: a world as a tree with what each part does
|
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
6
|
npx seerepo login # paste a key from Settings → API / MCP
|
|
7
|
+
npx seerepo connect # your agents (Claude Code, Codex, Cursor) ask SeeRepo first
|
|
7
8
|
npx seerepo map # your project's first level
|
|
8
9
|
npx seerepo map /checkout # a world inside
|
|
9
10
|
npx seerepo changes # the last 24 hours (or --since 2026-10-19)
|
package/bin/seerepo.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// SeeRepo's CLI (api-cli-mcp 3.1): your project's map from the terminal, through the API with your key.
|
|
3
3
|
// seerepo login save your API key
|
|
4
|
+
// seerepo connect connect your agent (Claude Code, Codex, Cursor): its MCP, and the rule in the project's file
|
|
5
|
+
// seerepo mcp SeeRepo's MCP over stdio, with the saved key: what an agent runs, never a person
|
|
4
6
|
// seerepo map [path] a world as a tree, with what each part does and the path to go inside
|
|
5
7
|
// seerepo changes what changed (the last 24 hours, or --since a date)
|
|
6
8
|
// seerepo pages every page of the app: who gets in and what it handles or misses
|
|
@@ -21,6 +23,7 @@ import { homedir } from "node:os";
|
|
|
21
23
|
import { dirname, join } from "node:path";
|
|
22
24
|
import { createInterface } from "node:readline/promises";
|
|
23
25
|
import { createInterface as lineReader } from "node:readline";
|
|
26
|
+
import * as zlib from "node:zlib";
|
|
24
27
|
import { fileURLToPath } from "node:url";
|
|
25
28
|
|
|
26
29
|
const VERSION = JSON.parse(readFileSync(join(dirname(fileURLToPath(import.meta.url)), "..", "package.json"), "utf8")).version;
|
|
@@ -31,6 +34,8 @@ const HELP = `seerepo ${VERSION}: your project's map from the terminal
|
|
|
31
34
|
|
|
32
35
|
Usage:
|
|
33
36
|
seerepo login Save your API key (create one in Settings → API)
|
|
37
|
+
seerepo connect Connect your agent to SeeRepo: its MCP server, and the rule in the project's file
|
|
38
|
+
(--agent claude,codex,cursor to choose; --yes to answer yes to every step)
|
|
34
39
|
seerepo map [path] A world of the map, like / or /checkout
|
|
35
40
|
seerepo changes [--since] What changed: the last 24 hours, or since a date (2026-10-19)
|
|
36
41
|
seerepo impact <file> What depends on a file: who names it, how many, which pages and processes (--name x, --to file)
|
|
@@ -91,8 +96,9 @@ async function get(path, key = readConfig().key) {
|
|
|
91
96
|
return body.data;
|
|
92
97
|
}
|
|
93
98
|
|
|
94
|
-
// A change (conector-escribe 2.4): POST with the same key, said to come from the CLI
|
|
95
|
-
|
|
99
|
+
// A change (conector-escribe 2.4): POST with the same key, said to come from the CLI. `quiet`: the refusals the caller takes
|
|
100
|
+
// as «nothing to do» instead of an error (their codes)
|
|
101
|
+
async function post(path, body, key = readConfig().key, quiet = []) {
|
|
96
102
|
if (!key) die(`You're not logged in. Run: seerepo login`);
|
|
97
103
|
let res;
|
|
98
104
|
try {
|
|
@@ -102,6 +108,7 @@ async function post(path, body, key = readConfig().key) {
|
|
|
102
108
|
}
|
|
103
109
|
const data = await res.json().catch(() => null);
|
|
104
110
|
if (res.status === 401) die("Your key doesn't work (revoked or mistyped). Run: seerepo login");
|
|
111
|
+
if (quiet.includes(data?.error?.code)) return null;
|
|
105
112
|
if (!res.ok || data?.status !== "success") die(data?.error?.message || `SeeRepo answered ${res.status}.`);
|
|
106
113
|
return data.data;
|
|
107
114
|
}
|
|
@@ -152,6 +159,8 @@ async function map() {
|
|
|
152
159
|
const w = await get(`/repos/${repo.id}/world?path=${encodeURIComponent(path)}`);
|
|
153
160
|
const lines = [w.path === "/" ? w.repo.fullName : `${w.name} (${w.path}) · ${w.repo.fullName}`];
|
|
154
161
|
if (w.phrase) lines.push(w.phrase);
|
|
162
|
+
// A map with more than its ceiling of filler says it's half made (E8)
|
|
163
|
+
if (w.halfMade) lines.push(`Half made: ${w.halfMade.share} % of its ${w.halfMade.files} files sit in boxes the map didn't design.`);
|
|
155
164
|
lines.push("");
|
|
156
165
|
w.parts.forEach((p, i) => {
|
|
157
166
|
const last = i === w.parts.length - 1;
|
|
@@ -196,20 +205,25 @@ async function impact() {
|
|
|
196
205
|
}
|
|
197
206
|
|
|
198
207
|
// Every page as the Pages folder lists it (pedidos-del-contrato 7.1): by the map's top-level worlds
|
|
199
|
-
const WHO = { anyone: "anyone", "with-link": "with its link", "signed-in": "signed in", member: "members", owner: "the owner", operator: "admins" };
|
|
208
|
+
const WHO = { anyone: "anyone", people: "door not seen", "with-link": "with its link", "signed-in": "signed in", member: "members", owner: "the owner", operator: "admins" };
|
|
200
209
|
async function pages() {
|
|
201
210
|
const repo = await whichRepo();
|
|
202
211
|
const v = await get(`/repos/${repo.id}/pages`);
|
|
203
|
-
|
|
212
|
+
// Python has no Pages yet (decision 123): its views are read by file, so who gets in to each isn't known
|
|
213
|
+
if (!v.screens.length) return console.log(v.unread === "python" ? `${repo.fullName} has no Pages yet: SeeRepo doesn't read Python's views one by one.` : `${repo.fullName} has no pages SeeRepo has read yet: they come with its next push.`);
|
|
204
214
|
const by = new Map(v.screens.map((s) => [s.path, s]));
|
|
205
|
-
|
|
215
|
+
// What the page says on top (paginas-tu-producto 3.1): its screens and how many are ready, as its Arreglos ring counts them
|
|
216
|
+
const lines = [`${v.summary.screens} screens in ${repo.fullName}, ${v.summary.ready ?? 0} ready (each handles every state it shows).`];
|
|
217
|
+
if (v.unread === "python") lines.push("Python has no Pages yet: SeeRepo reads its views by file, so who gets in to each one isn't known.");
|
|
206
218
|
for (const c of v.columns) {
|
|
207
219
|
lines.push("", c.name);
|
|
208
220
|
for (const path of c.screens) {
|
|
209
221
|
const s = by.get(path);
|
|
210
222
|
const missing = s.states.filter((x) => x.status === "missing");
|
|
211
223
|
const states = !s.statesRead ? "states not read yet" : v.locked ? `${s.states.length} states, ${missing.length} missing` : missing.length ? `missing: ${missing.map((x) => x.name).join(", ")}` : "every state handled";
|
|
212
|
-
|
|
224
|
+
// A page that only takes you somewhere else says so, with the line that does it, as the MCP (M-190)
|
|
225
|
+
const away = s.redirects ? ` · takes you ${s.redirects.to ? `to ${s.redirects.to}` : "somewhere else"} (${s.redirects.path}:${s.redirects.line})` : "";
|
|
226
|
+
lines.push(` ${s.name.padEnd(24)} ${(s.route || "no web route").padEnd(28)} ${(WHO[s.who] || s.who).padEnd(14)} ${states}${away}`);
|
|
213
227
|
}
|
|
214
228
|
}
|
|
215
229
|
if (v.locked) lines.push("", `Which states are missing, and their prompts, come with a plan: ${BASE}/pricing`);
|
|
@@ -221,7 +235,9 @@ async function found() {
|
|
|
221
235
|
const repo = await whichRepo();
|
|
222
236
|
const v = await get(`/repos/${repo.id}/found`);
|
|
223
237
|
if (!v.summary) return console.log(`${repo.fullName}'s pages haven't been read for search yet: they are at its next push.`);
|
|
224
|
-
|
|
238
|
+
// As Visibilidad's ring says it (paginas-tu-producto 3.1): of the public pages that want Google, how many can be found; a free repo, as before
|
|
239
|
+
const seen = v.summary.findable;
|
|
240
|
+
const lines = [seen ? `${seen.n} of ${seen.of} public pages in ${repo.fullName} can be found by Google${seen.hidden ? `; ${seen.hidden} more ${seen.hidden === 1 ? "is" : "are"} hidden on purpose and ${seen.hidden === 1 ? "doesn't" : "don't"} count` : ""}.` : `${v.summary.public} public pages in ${repo.fullName}, ${v.summary.needWork} need work${v.summary.blocked !== undefined ? `, ${v.summary.blocked} blocked` : ""}.`];
|
|
225
241
|
if (v.locked) lines.push("", `Which ones, and what each needs, come with a plan: ${BASE}/pricing`);
|
|
226
242
|
for (const p of v.pages) {
|
|
227
243
|
const worth = p.signals.filter((s) => ["BLOCK", "WARN", "UNKNOWN"].includes(s.label));
|
|
@@ -268,14 +284,17 @@ function said(name, p, title) {
|
|
|
268
284
|
if (p.kind === "false") return `This will mark ${p.files ? `${p.files.join(", ")} of ${task}` : task} false, because "${p.why}": ${p.files ? "those files leave it" : "it leaves the list"} and takes no points.`;
|
|
269
285
|
if (p.kind === "snooze") return `This will put off ${task} until ${p.until.slice(0, 10)}: it leaves the list and takes no points until then.`;
|
|
270
286
|
if (p.kind === "claim") {
|
|
271
|
-
const kept = [p.signed ? `${p.signed} already ${p.signed === 1 ? "carries" : "carry"} a signature, which wins` : "", p.older ? `${p.older} ${p.older === 1 ? "is" : "are"} older than the 90 days SeeRepo keeps and ${p.older === 1 ? "counts" : "count"} at the next reading` : "", p.claimed ? `${p.claimed} ${p.claimed === 1 ? "was" : "were"} claimed already` : ""].filter(Boolean);
|
|
272
|
-
return `This will count ${p.commits} ${p.commits === 1 ? "commit" : "commits"} of ${name} as made by ${p.agent}${kept.length ? `; ${kept.join("; ")}` : ""}. SeeRepo reads the repo again to count them
|
|
287
|
+
const kept = [p.corrects ? `${p.corrects === p.commits ? (p.corrects === 1 ? "it is" : "they are") : `${p.corrects} of them ${p.corrects === 1 ? "is" : "are"}`} signed by ${(p.from || []).join(" and ")} and will count for ${p.agent} instead, by its session's proof (what each signature says is kept)` : "", p.signed ? (p.corrects ? `${p.signed} more already ${p.signed === 1 ? "carries" : "carry"} ${p.agent}'s signature and ${p.signed === 1 ? "stays" : "stay"} as ${p.signed === 1 ? "it is" : "they are"}` : `${p.signed} already ${p.signed === 1 ? "carries" : "carry"} a signature, which wins`) : "", p.older ? (p.corrects ? `${p.older} more ${p.older === 1 ? "is" : "are"} older than the 90 days SeeRepo keeps and ${p.older === 1 ? "stays" : "stay"} out: it can't see ${p.older === 1 ? "its signature" : "their signatures"}` : `${p.older} ${p.older === 1 ? "is" : "are"} older than the 90 days SeeRepo keeps and ${p.older === 1 ? "counts" : "count"} at the next reading`) : "", p.claimed ? `${p.claimed} ${p.claimed === 1 ? "was" : "were"} claimed already` : ""].filter(Boolean);
|
|
288
|
+
return `This will count ${p.commits} ${p.commits === 1 ? "commit" : "commits"} of ${name} as made by ${p.agent}${kept.length ? `; ${kept.join("; ")}` : ""}. SeeRepo reads the repo again to count them.${p.corrects ? ` Say no if ${p.agent} only moved or amended ${p.corrects === 1 ? "a commit" : "commits"} another agent wrote.` : ""}`;
|
|
273
289
|
}
|
|
274
290
|
return `This will accept ${task}, because "${p.why}": it leaves the list and takes no points until it's undone.`;
|
|
275
291
|
}
|
|
276
|
-
async function change(repo, ask) {
|
|
277
|
-
const prepared = await post(`/repos/${repo.id}/changes`, ask);
|
|
292
|
+
async function change(repo, ask, quiet = []) {
|
|
293
|
+
const prepared = await post(`/repos/${repo.id}/changes`, ask, undefined, quiet);
|
|
294
|
+
if (!prepared) return null;
|
|
278
295
|
const p = prepared.preview;
|
|
296
|
+
// A correction asked of a SeeRepo that doesn't know them yet, or with nothing to correct: nothing is asked
|
|
297
|
+
if (ask.correct && !p.corrects) return;
|
|
279
298
|
let title = null;
|
|
280
299
|
if (p.task) {
|
|
281
300
|
const h = await get(`/repos/${repo.id}/health`);
|
|
@@ -319,6 +338,9 @@ async function accept() {
|
|
|
319
338
|
// what each `git commit` answered: «[branch hash] subject». A commit of this folder's repo found there, with the same subject,
|
|
320
339
|
// was made by that agent. Only Codex's day folders inside the window are read (its sessions weigh gigabytes), and Claude
|
|
321
340
|
// Code's sessions changed inside it. Nothing of a session leaves the machine: only the commit and the agent
|
|
341
|
+
// Codex compresses its older sessions (.jsonl.zst): measured on 2026-11-08, 528 of 789 on one machine, the 17 commits of
|
|
342
|
+
// decision 47 among them, and claim found none. Read with Node's zstd (22.15 and later); an older Node skips them and says so
|
|
343
|
+
const ZSTD = typeof zlib.createZstdDecompress === "function";
|
|
322
344
|
const SESSIONS = [
|
|
323
345
|
{ agent: "Codex", root: join(homedir(), ".codex", "sessions"), byDay: true },
|
|
324
346
|
{ agent: "Claude", root: join(homedir(), ".claude", "projects"), byDay: false },
|
|
@@ -335,7 +357,7 @@ function sessionFiles(root, byDay, since) {
|
|
|
335
357
|
// Codex's folders are year/month/day: a day before the window is skipped whole
|
|
336
358
|
if (byDay && depth === 2 && `${dir.slice(-7).replace("/", "-")}-${name}` < since) continue;
|
|
337
359
|
walk(at, depth + 1);
|
|
338
|
-
} else if (name.endsWith(".jsonl") && st.mtimeMs >= Date.parse(since)) out.push(at);
|
|
360
|
+
} else if ((name.endsWith(".jsonl") || name.endsWith(".jsonl.zst")) && st.mtimeMs >= Date.parse(since)) out.push(at);
|
|
339
361
|
}
|
|
340
362
|
};
|
|
341
363
|
walk(root, 0);
|
|
@@ -355,10 +377,16 @@ async function localClaims(days) {
|
|
|
355
377
|
commits.set(sha.slice(0, 7), { sha, subject, day, signed: /co-authored-by:|assisted-by:|made-with:/i.test(body || "") });
|
|
356
378
|
}
|
|
357
379
|
const found = new Map();
|
|
380
|
+
let skipped = 0;
|
|
358
381
|
for (const { agent, root, byDay } of SESSIONS) {
|
|
359
382
|
for (const file of sessionFiles(root, byDay, since)) {
|
|
360
383
|
// Line by line: one session can weigh more than a string holds
|
|
361
|
-
|
|
384
|
+
if (file.endsWith(".zst") && !ZSTD) {
|
|
385
|
+
skipped++;
|
|
386
|
+
continue;
|
|
387
|
+
}
|
|
388
|
+
const input = file.endsWith(".zst") ? createReadStream(file).pipe(zlib.createZstdDecompress()) : createReadStream(file, "utf8");
|
|
389
|
+
for await (const line of lineReader({ input, crlfDelay: Infinity })) {
|
|
362
390
|
if (!line.includes("] ")) continue;
|
|
363
391
|
for (const m of line.matchAll(R_COMMITTED)) {
|
|
364
392
|
const c = commits.get(m[2].slice(0, 7));
|
|
@@ -370,6 +398,7 @@ async function localClaims(days) {
|
|
|
370
398
|
}
|
|
371
399
|
}
|
|
372
400
|
}
|
|
401
|
+
if (skipped) process.stderr.write(`${skipped} compressed ${skipped === 1 ? "session" : "sessions"} of Codex need Node 22.15 or later to be read: they were left out.\n`);
|
|
373
402
|
return [...found.values()];
|
|
374
403
|
}
|
|
375
404
|
async function claim() {
|
|
@@ -385,18 +414,23 @@ async function claim() {
|
|
|
385
414
|
const daysOf = list.map((c) => c.day).sort();
|
|
386
415
|
lines.push(` ${agent.padEnd(8)} ${String(list.length).padStart(4)} ${list.length === 1 ? "commit " : "commits"} without its signature (${daysOf[0] === daysOf.at(-1) ? daysOf[0] : `${daysOf[0]} to ${daysOf.at(-1)}`})`);
|
|
387
416
|
}
|
|
388
|
-
const signed = claims.
|
|
389
|
-
if (signed) lines.push(` ${signed} more already carry an agent's signature: SeeRepo counts them already.`);
|
|
417
|
+
const signed = claims.filter((c) => c.signed);
|
|
418
|
+
if (signed.length) lines.push(` ${signed.length} more already carry an agent's signature: SeeRepo counts them already, and asks below about any that names another agent than the session's.`);
|
|
390
419
|
if (!unsigned.length) lines.push("", "Nothing to claim: every one is signed.");
|
|
391
420
|
else lines.push("", "Only each commit's hash and its agent leave this machine.");
|
|
392
421
|
console.log(lines.join("\n"));
|
|
393
422
|
// Then each agent's, as a change (atribucion-por-sesion 1.2): what will count, a question, and only then the claim
|
|
394
|
-
if (!unsigned.length) return;
|
|
395
423
|
const repo = await whichRepo();
|
|
396
|
-
for (const [agent, list] of by) await change(repo, { kind: "claim", agent, shas: list.map((c) => c.sha) });
|
|
424
|
+
for (const [agent, list] of by) if ((await change(repo, { kind: "claim", agent, shas: list.map((c) => c.sha) }, ["claimed"])) === null) console.log(`${agent}'s ${list.length === 1 ? "was" : "were"} claimed already.`);
|
|
425
|
+
// And the signed ones whose signature names another agent (decision 185, atribucion-por-sesion 1.7): a skill made for one
|
|
426
|
+
// agent has any other sign with its name, and the session is who ran the commit. SeeRepo says which they are; a question of
|
|
427
|
+
// its own, apart from the claim above
|
|
428
|
+
const bySigned = new Map();
|
|
429
|
+
for (const c of signed) bySigned.set(c.agent, [...(bySigned.get(c.agent) || []), c]);
|
|
430
|
+
for (const [agent, list] of bySigned) await change(repo, { kind: "claim", agent, shas: list.map((c) => c.sha), correct: true }, ["nothing_to_correct", "claimed"]);
|
|
397
431
|
}
|
|
398
432
|
|
|
399
|
-
// Trayectoria (historia-completa 6.5.8): the week in a few lines, its pace against its usual, and its moments,
|
|
433
|
+
// Trayectoria (historia-completa 6.5.8): the week in a few lines, its pace against its usual, and its moments, the biggest first
|
|
400
434
|
async function history() {
|
|
401
435
|
const repo = await whichRepo();
|
|
402
436
|
const v = await get(`/repos/${repo.id}/history`);
|
|
@@ -415,8 +449,8 @@ async function history() {
|
|
|
415
449
|
if (!v.log) lines.push("", `Who wrote the week, where, and its moments come with a plan: ${BASE}/pricing`);
|
|
416
450
|
else if (v.log.length) {
|
|
417
451
|
lines.push("", "Moments");
|
|
418
|
-
for (const c of v.log.slice(0, 15)) lines.push(` ${c.date} ${c.title}`);
|
|
419
|
-
if (v.log.length > 15) lines.push(` … ${v.log.length - 15}
|
|
452
|
+
for (const c of v.log.slice(0, 15)) lines.push(` ${c.month ? `${c.date.slice(0, 7)} ` : c.date} ${c.title}`);
|
|
453
|
+
if (v.log.length > 15) lines.push(` … ${v.log.length - 15} more`);
|
|
420
454
|
}
|
|
421
455
|
console.log(lines.join("\n"));
|
|
422
456
|
}
|
|
@@ -472,7 +506,174 @@ async function docs() {
|
|
|
472
506
|
console.log(lines.join("\n"));
|
|
473
507
|
}
|
|
474
508
|
|
|
475
|
-
|
|
509
|
+
// `seerepo mcp` (conectar-guiado; the director chose it on 2026-11-14): SeeRepo's MCP over stdio, for any agent, with the key
|
|
510
|
+
// `seerepo login` saved. The agent's config carries one line and no key (`npx -y seerepo mcp`), so it can be committed, and a
|
|
511
|
+
// new key touches no agent. A bridge and nothing else: each JSON-RPC line from the agent is posted to SeeRepo's MCP as it is,
|
|
512
|
+
// and the answer goes back as it came. It speaks what every agent speaks over stdio, the 2025 protocol with its initialize;
|
|
513
|
+
// the probe of a newer one (server/discover) is told the method doesn't exist, which is what any server of that era answers
|
|
514
|
+
// and how a client knows to fall back. What goes wrong is said to the agent in words it can pass on to the person
|
|
515
|
+
async function forward(message, state) {
|
|
516
|
+
const asked = Boolean(message) && typeof message === "object" && !Array.isArray(message) && "id" in message && "method" in message;
|
|
517
|
+
const refuse = (code, text) => (asked ? [{ jsonrpc: "2.0", id: message.id, error: { code, message: text } }] : []);
|
|
518
|
+
if (asked && message.method === "server/discover") return refuse(-32601, "Method not found");
|
|
519
|
+
const key = readConfig().key;
|
|
520
|
+
if (!key) return refuse(-32001, "SeeRepo isn't connected on this machine yet. Ask the person to run: npx seerepo login");
|
|
521
|
+
let res;
|
|
522
|
+
try {
|
|
523
|
+
res = await fetch(`${BASE}/api/mcp`, { method: "POST", headers: { authorization: `Bearer ${key}`, "content-type": "application/json", accept: "application/json, text/event-stream", "user-agent": `seerepo-cli/${VERSION} mcp`, ...(state.version ? { "mcp-protocol-version": state.version } : {}) }, body: JSON.stringify(message) });
|
|
524
|
+
} catch {
|
|
525
|
+
return refuse(-32000, `Can't reach ${BASE}. Check the connection and try again.`);
|
|
526
|
+
}
|
|
527
|
+
const text = await res.text().catch(() => "");
|
|
528
|
+
// One JSON body; or, should the server ever stream, each event's
|
|
529
|
+
const bodies = (res.headers.get("content-type") || "").includes("text/event-stream") ? text.split(/\r?\n/).filter((l) => l.startsWith("data:")).map((l) => l.slice(5).trim()) : [text];
|
|
530
|
+
const out = bodies.flatMap((b) => {
|
|
531
|
+
try {
|
|
532
|
+
return b ? [JSON.parse(b)] : [];
|
|
533
|
+
} catch {
|
|
534
|
+
return [];
|
|
535
|
+
}
|
|
536
|
+
});
|
|
537
|
+
if (res.status === 401) return refuse(-32001, "SeeRepo's key on this machine doesn't work (revoked or mistyped). Ask the person to run: npx seerepo login");
|
|
538
|
+
// A refusal of the protocol's own comes back as it is; one of SeeRepo's (the limit per minute), in its words
|
|
539
|
+
if (!res.ok) return out[0]?.jsonrpc ? out : refuse(-32000, out[0]?.error?.message || `SeeRepo answered ${res.status}.`);
|
|
540
|
+
if (asked && message.method === "initialize" && out[0]?.result?.protocolVersion) state.version = out[0].result.protocolVersion;
|
|
541
|
+
return out;
|
|
542
|
+
}
|
|
543
|
+
async function mcp() {
|
|
544
|
+
const state = { version: null };
|
|
545
|
+
const say = (lines) => {
|
|
546
|
+
for (const o of lines) process.stdout.write(`${JSON.stringify(o)}\n`);
|
|
547
|
+
};
|
|
548
|
+
const pending = new Set();
|
|
549
|
+
for await (const line of lineReader({ input: process.stdin, crlfDelay: Infinity })) {
|
|
550
|
+
if (!line.trim()) continue;
|
|
551
|
+
let message;
|
|
552
|
+
try {
|
|
553
|
+
message = JSON.parse(line);
|
|
554
|
+
} catch {
|
|
555
|
+
say([{ jsonrpc: "2.0", id: null, error: { code: -32700, message: "Parse error" } }]);
|
|
556
|
+
continue;
|
|
557
|
+
}
|
|
558
|
+
const p = forward(message, state).then(say).finally(() => pending.delete(p));
|
|
559
|
+
pending.add(p);
|
|
560
|
+
// The first exchange alone: the version it settles goes with every request after it
|
|
561
|
+
if (message?.method === "initialize") await p;
|
|
562
|
+
}
|
|
563
|
+
await Promise.all(pending);
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
// `seerepo connect` (conectar-guiado 2.1): the agent's MCP and the project's rule, each step said and asked before it's done
|
|
567
|
+
// (D-8), ending with a real call through the same bridge the agent will use. Nothing here carries the key: the agent's config
|
|
568
|
+
// gets the bridge's line. Claude Code and Codex by their own commands, for all the person's projects; Cursor by its file
|
|
569
|
+
const BRIDGE = ["npx", "-y", "seerepo", "mcp"];
|
|
570
|
+
const RULE_START = "<!-- seerepo:start -->";
|
|
571
|
+
const RULE_END = "<!-- seerepo:end -->";
|
|
572
|
+
// The words, the marks, the bridge and the three questions are app/libs/agent-rule.ts's: scripts/check-agent-rule.ts fails when they differ
|
|
573
|
+
const RULE = `${RULE_START}\n## SeeRepo\n\nSeeRepo (the MCP server named seerepo) has this repo mapped. Ask it first, before searching or opening files, and then read only what you need to confirm what it says.\n${RULE_END}\n`;
|
|
574
|
+
const AGENTS = {
|
|
575
|
+
claude: { name: "Claude Code", bin: "claude", add: ["mcp", "add", "--scope", "user", "seerepo", "--", ...BRIDGE] },
|
|
576
|
+
codex: { name: "Codex", bin: "codex", add: ["mcp", "add", "seerepo", "--", ...BRIDGE] },
|
|
577
|
+
cursor: { name: "Cursor", file: () => join(homedir(), ".cursor", "mcp.json") },
|
|
578
|
+
};
|
|
579
|
+
const runs = (bin, args) => {
|
|
580
|
+
try {
|
|
581
|
+
return execFileSync(bin, args, { stdio: ["ignore", "pipe", "ignore"] }).toString();
|
|
582
|
+
} catch {
|
|
583
|
+
return null;
|
|
584
|
+
}
|
|
585
|
+
};
|
|
586
|
+
// The file's text with the rule between its marks: put in place of an older one, or added at the end
|
|
587
|
+
const withRule = (text) => {
|
|
588
|
+
const a = text.indexOf(RULE_START);
|
|
589
|
+
const b = text.indexOf(RULE_END);
|
|
590
|
+
if (a >= 0 && b > a) return text.slice(0, a) + RULE.trimEnd() + text.slice(b + RULE_END.length);
|
|
591
|
+
return `${text}${text && !text.endsWith("\n") ? "\n" : ""}${text ? "\n" : ""}${RULE}`;
|
|
592
|
+
};
|
|
593
|
+
// Which of the project's files take the rule: the one each agent already reads. Claude Code reads its CLAUDE.md, and only when
|
|
594
|
+
// there's none an AGENTS.md (since 2.1.277): a CLAUDE.md made beside an AGENTS.md would hide that AGENTS.md from it, so none is
|
|
595
|
+
// made. Codex and Cursor read AGENTS.md
|
|
596
|
+
function ruleFiles(root, agents) {
|
|
597
|
+
const claudeFile = ["CLAUDE.md", ".claude/CLAUDE.md"].find((f) => existsSync(join(root, f)));
|
|
598
|
+
const files = [];
|
|
599
|
+
if (agents.includes("claude") && claudeFile) files.push(claudeFile);
|
|
600
|
+
if (agents.some((a) => a !== "claude") || (agents.includes("claude") && !claudeFile)) files.push("AGENTS.md");
|
|
601
|
+
return files;
|
|
602
|
+
}
|
|
603
|
+
async function connect() {
|
|
604
|
+
const all = rest.includes("--yes") && Boolean(rest.splice(rest.indexOf("--yes"), 1));
|
|
605
|
+
const wanted = flag("agent")?.split(",").map((a) => a.trim().toLowerCase()).filter(Boolean);
|
|
606
|
+
for (const a of wanted || []) if (!AGENTS[a]) die(`SeeRepo connects Claude Code, Codex and Cursor: --agent ${Object.keys(AGENTS).join(",")}`);
|
|
607
|
+
// The rule goes in the folder's project: with --repo there's no folder to write it in
|
|
608
|
+
const elsewhere = rest.includes("--repo");
|
|
609
|
+
const repo = await whichRepo();
|
|
610
|
+
const root = elsewhere ? null : runs("git", ["rev-parse", "--show-toplevel"])?.trim() || null;
|
|
611
|
+
const found = Object.keys(AGENTS).filter((a) => (AGENTS[a].bin ? runs(AGENTS[a].bin, ["--version"]) !== null : existsSync(join(homedir(), ".cursor"))));
|
|
612
|
+
const agents = wanted || found;
|
|
613
|
+
if (!agents.length) die(`No agent found on this machine (Claude Code, Codex or Cursor). Install one, or name it: seerepo connect --agent claude\nBy hand: ${BASE}/docs/mcp`);
|
|
614
|
+
const yes = async (question) => {
|
|
615
|
+
if (all) return true;
|
|
616
|
+
if (!process.stdin.isTTY) die("Nothing changed: run it in a terminal to answer each step, or add --yes to do them all.");
|
|
617
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
618
|
+
const answer = (await rl.question(`${question} (y/N) `)).trim().toLowerCase();
|
|
619
|
+
rl.close();
|
|
620
|
+
return answer === "y" || answer === "yes";
|
|
621
|
+
};
|
|
622
|
+
console.log(`Connecting ${agents.map((a) => AGENTS[a].name).join(", ")} to SeeRepo for ${repo.fullName}. The key stays in ${CONFIG}: nothing written here carries it.`);
|
|
623
|
+
const did = [];
|
|
624
|
+
for (const a of agents) {
|
|
625
|
+
const agent = AGENTS[a];
|
|
626
|
+
if (agent.bin) {
|
|
627
|
+
if (runs(agent.bin, ["--version"]) === null) did.push(`- ${agent.name}: it isn't installed on this machine, nothing done`);
|
|
628
|
+
else if (runs(agent.bin, ["mcp", "get", "seerepo"]) !== null) did.push(`= ${agent.name}: it already has a server named seerepo, left as it is`);
|
|
629
|
+
else if (!(await yes(`Add SeeRepo to ${agent.name}, for all your projects? It runs: ${agent.bin} ${agent.add.join(" ")}`))) did.push(`- ${agent.name}: you said no, nothing done`);
|
|
630
|
+
else did.push(runs(agent.bin, agent.add) === null ? `! ${agent.name}: its own command failed. Run it yourself: ${agent.bin} ${agent.add.join(" ")}` : `+ ${agent.name}: the server seerepo (${BRIDGE.join(" ")}), for all your projects`);
|
|
631
|
+
continue;
|
|
632
|
+
}
|
|
633
|
+
const file = agent.file();
|
|
634
|
+
const before = existsSync(file) ? readFileSync(file, "utf8") : "";
|
|
635
|
+
let config;
|
|
636
|
+
try {
|
|
637
|
+
config = before.trim() ? JSON.parse(before) : {};
|
|
638
|
+
} catch {
|
|
639
|
+
did.push(`! ${agent.name}: ${file} isn't valid JSON, so it wasn't touched. Add to its mcpServers: "seerepo": { "command": "npx", "args": ["-y", "seerepo", "mcp"] }`);
|
|
640
|
+
continue;
|
|
641
|
+
}
|
|
642
|
+
if (config.mcpServers?.seerepo) did.push(`= ${agent.name}: ${file} already has a server named seerepo, left as it is`);
|
|
643
|
+
else if (!(await yes(`Add SeeRepo to ${agent.name}? It adds the server seerepo (${BRIDGE.join(" ")}) to ${file}`))) did.push(`- ${agent.name}: you said no, nothing done`);
|
|
644
|
+
else {
|
|
645
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
646
|
+
writeFileSync(file, `${JSON.stringify({ ...config, mcpServers: { ...(config.mcpServers || {}), seerepo: { command: BRIDGE[0], args: BRIDGE.slice(1) } } }, null, 2)}\n`);
|
|
647
|
+
did.push(`+ ${agent.name}: the server seerepo in ${file}`);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
// The rule, in the project's own file
|
|
651
|
+
if (!root) did.push("- The rule: run seerepo connect inside the project's folder to write it in its file");
|
|
652
|
+
else
|
|
653
|
+
for (const name of ruleFiles(root, agents)) {
|
|
654
|
+
const file = join(root, name);
|
|
655
|
+
const before = existsSync(file) ? readFileSync(file, "utf8") : "";
|
|
656
|
+
const after = withRule(before);
|
|
657
|
+
if (after === before) did.push(`= ${name}: the rule is already there`);
|
|
658
|
+
else if (!(await yes(`${before ? (before.includes(RULE_START) ? "Update the rule in" : "Add the rule to") : "Create"} ${name}? It tells your agent to ask SeeRepo first, between two marks, and touches nothing else in the file`))) did.push(`- ${name}: you said no, nothing done`);
|
|
659
|
+
else {
|
|
660
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
661
|
+
writeFileSync(file, after);
|
|
662
|
+
did.push(`+ ${name}: the rule, between ${RULE_START} and ${RULE_END}`);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
// A real call, by the way the agent will make it
|
|
666
|
+
const state = { version: null };
|
|
667
|
+
await forward({ jsonrpc: "2.0", id: 1, method: "initialize", params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "seerepo-connect", version: VERSION } } }, state);
|
|
668
|
+
// list_projects: it answers while a repo's first read is still going, which explain wouldn't
|
|
669
|
+
const [answer] = await forward({ jsonrpc: "2.0", id: 2, method: "tools/call", params: { name: "list_projects", arguments: {} } }, state);
|
|
670
|
+
const said = answer?.result?.content?.[0]?.text;
|
|
671
|
+
const works = Boolean(said) && !answer.result.isError;
|
|
672
|
+
console.log(["", ...did.map((d) => ` ${d}`), "", works ? `SeeRepo answers through the bridge: «${said.split("\n")[0].slice(0, 120)}»` : `SeeRepo didn't answer through the bridge: ${answer?.error?.message || said || "no answer"}`, ...(works ? ["", "Now open your agent in this folder (a new session, so it loads the server) and ask it:", " What does this project do, module by module?", " What breaks if I change one of its files?", " What changed since yesterday?", `Settings shows it connected after its first call: ${BASE}/dashboard/settings?tab=api`] : [])].join("\n"));
|
|
673
|
+
if (!works) process.exit(1);
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
const commands = { login, connect, mcp, map, changes, impact, pages, found, health, history, docs, open, ignore, false: markFalse, snooze, accept, claim };
|
|
476
677
|
if (!command || command === "--help" || command === "-h" || command === "help") console.log(HELP);
|
|
477
678
|
else if (command === "--version" || command === "-v") console.log(VERSION);
|
|
478
679
|
else if (commands[command]) await commands[command]();
|