@ureck/alexandria 0.5.4 → 1.0.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 +23 -3
- package/dist/{chunk-7G3NPKDO.js → chunk-D5ROL42O.js} +26 -5
- package/dist/{chunk-UTXUGXDB.js → chunk-DCKYTO4O.js} +1 -1
- package/dist/{chunk-IQM5S5N4.js → chunk-DHXL36RG.js} +59 -0
- package/dist/{chunk-MEL3BE65.js → chunk-RZI7TYAG.js} +1 -1
- package/dist/cli.js +313 -27
- package/dist/hooks/on-prompt.js +2 -2
- package/dist/hooks/on-session-start.js +7 -1
- package/dist/mcp/server.js +20 -9
- package/dist/{viewer-G3N57646.js → viewer-73ZWPIDC.js} +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ It lives in the MCP tools themselves — their names and descriptions carry the
|
|
|
33
33
|
|
|
34
34
|
| MCP tool | What the agent does with it | Token payoff |
|
|
35
35
|
|---|---|---|
|
|
36
|
-
| `plan_create(title, goal, dod, tasks)` |
|
|
36
|
+
| `plan_create(title, goal, dod, tasks, design?)` | Plans like an **architect**: clarifies vague goals first, optionally records the architecture (`design` → a `## Design` section), and the response surfaces **similar past plans + relevant lessons** plus quality hints (verifiable DoD, small tasks) — suggestions, never a gate | No wandering; open plans are re-injected next session so work is resumed, not repeated |
|
|
37
37
|
| `task_verify(plan, task, passed, verify_command)` | **Runs** `verify_command` (e.g. `npm test`) and takes the verdict from the real exit code — not from the agent's word. Flags a **discrepancy** if the agent claimed otherwise; without a command the note is tagged `self-reported` and `ale audit` calls it out | "✅ 12/12 passed" (5 tokens) instead of a 500-line log; on failure it automatically surfaces **past lessons** that match |
|
|
38
38
|
| `lesson_extract(title, lesson, links)` | Distills the root cause + fix after solving something non-obvious | ~200 tokens today replace ~20,000 tokens of re-debugging next month |
|
|
39
39
|
|
|
@@ -63,7 +63,7 @@ Verify:
|
|
|
63
63
|
|
|
64
64
|
```bash
|
|
65
65
|
$ ale --version
|
|
66
|
-
0.
|
|
66
|
+
1.0.0
|
|
67
67
|
```
|
|
68
68
|
|
|
69
69
|
## Getting started
|
|
@@ -132,6 +132,24 @@ ale add "Vercel deploy" -c "Region cdg1, see [[Prisma setup]]" -t deploy
|
|
|
132
132
|
|
|
133
133
|
(Automatic capture via hooks already does this in every Claude Code session — `add` is for extra knowledge.)
|
|
134
134
|
|
|
135
|
+
### Deep project context (`ale scan`)
|
|
136
|
+
|
|
137
|
+
`ale init --project` already runs it; re-run anytime the project changes:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
$ ale scan
|
|
141
|
+
✓ API: 12 rutas · Env: 8 vars (solo nombres) · Datos: 5 · Convenciones: 4 · .gitignore ✓
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Four read-only scanners write compact notes (one line per entry) that the agent receives **only when relevant** (per-prompt semantic search — the session digest doesn't grow):
|
|
145
|
+
|
|
146
|
+
- **`API - <project>`** — App Router routes with HTTP methods, Pages Router handlers, `"use server"` actions, Express/Hono routes.
|
|
147
|
+
- **`Env - <project>`** — environment variable **NAMES only, never values** (from `.env.example` / `.env` / `.env.local`).
|
|
148
|
+
- **`Datos - <project>`** — data schema parsed from files (prisma models, drizzle tables, `CREATE TABLE` in migrations) — no DB connection.
|
|
149
|
+
- **`Convenciones - <project>`** — package manager, monorepo, TS strict, import aliases, framework.
|
|
150
|
+
|
|
151
|
+
It never touches your source code, and it guarantees the vault (and personal configs) are gitignored before writing — your notes never reach a shared repo, even if you never ran `ale init`.
|
|
152
|
+
|
|
135
153
|
### Create a plan from a file
|
|
136
154
|
|
|
137
155
|
Instead of typing a whole plan into the terminal, keep it as markdown in your repo:
|
|
@@ -259,10 +277,11 @@ AI agent session
|
|
|
259
277
|
| Command | What it does |
|
|
260
278
|
|---|---|
|
|
261
279
|
| `ale init [--project] [--path <dir>] [--agents <ids>] [--auto\|--manual] [--no-protocol] [--portable]` | Installs everything: vault, hooks, MCP, .gitignore, project scan, CLAUDE.md. `--portable` writes an npx-based MCP command safe to commit for teams |
|
|
280
|
+
| `ale scan` | Deep project context: API routes, env var **names**, data schema (file parse), conventions → compact notes. Read-only; ensures .gitignore |
|
|
262
281
|
| `ale agents [ids] [--project]` | List agents / register the MCP server |
|
|
263
282
|
| `ale search <query> [-k n] [--expand]` | Hybrid search; `--expand` pulls graph neighbors. With the Protocol on, appends the **chain** (plan + verification + lesson) connected to the top hit |
|
|
264
283
|
| `ale add <title> [-c text] [--file <path>] [-t tags]` | Save a note (inline, from file, or stdin) |
|
|
265
|
-
| `ale plan <file> [--title t]` | Create a Protocol plan from a .md/.txt file (checkboxes → Definition of Done) |
|
|
284
|
+
| `ale plan <file> [--title t]` | Create a Protocol plan from a .md/.txt file (checkboxes → Definition of Done); surfaces similar past plans + quality hints |
|
|
266
285
|
| `ale graph [--out file.html] [--no-open]` | Live local graph viewer |
|
|
267
286
|
| `ale audit` | Protocol health: plans without DoD, failures without lessons, orphan notes |
|
|
268
287
|
| `ale stats` | Notes, connections, protocol metrics, estimated tokens saved |
|
|
@@ -280,6 +299,7 @@ AI agent session
|
|
|
280
299
|
|
|
281
300
|
- **Everything runs on your machine**: the embedding model is downloaded once (Hugging Face) and then works offline. Your notes never leave your disk. No telemetry.
|
|
282
301
|
- **No API keys, no accounts, no cost.**
|
|
302
|
+
- **`ale scan` never reads secrets**: it extracts environment variable **names** only (values are never copied), parses schema **files** (no live DB connection), and guarantees the vault is gitignored before writing — your notes never reach a shared repo.
|
|
283
303
|
- Dependency scanners (Socket, etc.) flag *network/shell/env access* in the dependency tree: those come from the ML runtime (`onnxruntime`/`transformers.js`, which needs filesystem access and the one-time model download) and the official MCP SDK — not from Alexandria's code. The published package runs no install scripts of its own.
|
|
284
304
|
- Generated per-project configs (`.mcp.json`, `.vault.json`, etc.) point at your machine's install path, so `ale init --project` automatically gitignores them (and untracks any already committed) — they never leak to a shared repo. For a team that *wants* a shared MCP config, run `ale init --project --portable`, which writes an npx-based command that works on any machine.
|
|
285
305
|
|
|
@@ -50,20 +50,41 @@ var VaultIndex = class _VaultIndex {
|
|
|
50
50
|
try {
|
|
51
51
|
const buf = fs.readFileSync(idx.embPath);
|
|
52
52
|
const arr = new Float32Array(buf.buffer, buf.byteOffset, buf.byteLength / 4);
|
|
53
|
-
if (arr.length === meta.chunks.length * meta.dim)
|
|
53
|
+
if (arr.length === meta.chunks.length * meta.dim) {
|
|
54
|
+
idx.emb = arr.slice();
|
|
55
|
+
} else {
|
|
56
|
+
idx.emb = null;
|
|
57
|
+
try {
|
|
58
|
+
fs.rmSync(idx.embPath, { force: true });
|
|
59
|
+
} catch {
|
|
60
|
+
}
|
|
61
|
+
}
|
|
54
62
|
} catch {
|
|
55
63
|
idx.emb = null;
|
|
56
64
|
}
|
|
57
65
|
}
|
|
58
|
-
} catch {
|
|
66
|
+
} catch (e) {
|
|
67
|
+
if (fs.existsSync(idx.metaPath)) {
|
|
68
|
+
try {
|
|
69
|
+
fs.rmSync(idx.metaPath, { force: true });
|
|
70
|
+
fs.rmSync(idx.embPath, { force: true });
|
|
71
|
+
} catch {
|
|
72
|
+
}
|
|
73
|
+
}
|
|
59
74
|
}
|
|
60
75
|
return idx;
|
|
61
76
|
}
|
|
77
|
+
/** Escritura atómica: tmp + rename — un hook y un comando concurrentes nunca dejan el archivo a medias. */
|
|
78
|
+
writeAtomic(file, data) {
|
|
79
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
80
|
+
fs.writeFileSync(tmp, data);
|
|
81
|
+
fs.renameSync(tmp, file);
|
|
82
|
+
}
|
|
62
83
|
save() {
|
|
63
84
|
fs.mkdirSync(this.vault.cache, { recursive: true });
|
|
64
|
-
|
|
85
|
+
this.writeAtomic(this.metaPath, JSON.stringify(this.meta));
|
|
65
86
|
if (this.emb) {
|
|
66
|
-
|
|
87
|
+
this.writeAtomic(this.embPath, Buffer.from(this.emb.buffer, this.emb.byteOffset, this.emb.byteLength));
|
|
67
88
|
}
|
|
68
89
|
}
|
|
69
90
|
row(i) {
|
|
@@ -171,7 +192,7 @@ ${c.text}`),
|
|
|
171
192
|
this.rebuildLinks();
|
|
172
193
|
this.save();
|
|
173
194
|
try {
|
|
174
|
-
const { writeStaticGraph } = await import("./viewer-
|
|
195
|
+
const { writeStaticGraph } = await import("./viewer-73ZWPIDC.js");
|
|
175
196
|
writeStaticGraph(this);
|
|
176
197
|
} catch {
|
|
177
198
|
}
|
|
@@ -1,4 +1,60 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
hybridSearch
|
|
4
|
+
} from "./chunk-RZI7TYAG.js";
|
|
5
|
+
|
|
6
|
+
// src/core/planning.ts
|
|
7
|
+
async function planContext(vault, query) {
|
|
8
|
+
const out = { similarPlans: [], lessons: [] };
|
|
9
|
+
try {
|
|
10
|
+
const results = await hybridSearch(vault, query, 8);
|
|
11
|
+
for (const r of results) {
|
|
12
|
+
const excerpt = (r.excerpts[0] ?? "").replace(/\n+/g, " ").slice(0, 300);
|
|
13
|
+
if (r.note.type === "plan" && out.similarPlans.length < 3) {
|
|
14
|
+
out.similarPlans.push(`\xAB${r.note.title}\xBB (${r.note.status ?? "sin status"}): ${excerpt}`);
|
|
15
|
+
} else if ((r.note.type === "lesson" || r.note.type === "solution") && out.lessons.length < 3) {
|
|
16
|
+
out.lessons.push(`\xAB${r.note.title}\xBB: ${excerpt}`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
} catch {
|
|
20
|
+
}
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
var FAT_TASK_CHARS = 140;
|
|
24
|
+
function planQualityHints(dod, tasks, design) {
|
|
25
|
+
const hints = [];
|
|
26
|
+
if (dod.length < 2) {
|
|
27
|
+
hints.push("DoD con menos de 2 criterios \u2014 agrega criterios verificables por comando (tests, build, curl).");
|
|
28
|
+
}
|
|
29
|
+
const vague = dod.filter((d) => /funcione bien|quede bonito|esté listo|sea mejor/i.test(d));
|
|
30
|
+
if (vague.length) {
|
|
31
|
+
hints.push(`Criterios no verificables (${vague.length}): reescr\xEDbelos como algo que un comando pueda confirmar.`);
|
|
32
|
+
}
|
|
33
|
+
const fat = tasks.filter((t) => t.length > FAT_TASK_CHARS);
|
|
34
|
+
if (fat.length) {
|
|
35
|
+
hints.push(`${fat.length} tarea(s) muy grandes (>${FAT_TASK_CHARS} chars) \u2014 div\xEDdelas: una tarea = un task_verify.`);
|
|
36
|
+
}
|
|
37
|
+
if (tasks.length > 5 && !design?.trim()) {
|
|
38
|
+
hints.push("Plan grande sin secci\xF3n de dise\xF1o \u2014 considera pasar `design` (stack/decisiones de arquitectura) para fijar el rumbo antes de ejecutar.");
|
|
39
|
+
}
|
|
40
|
+
return hints;
|
|
41
|
+
}
|
|
42
|
+
function architectBlock(ctx, hints) {
|
|
43
|
+
const parts = [];
|
|
44
|
+
if (ctx.similarPlans.length) {
|
|
45
|
+
parts.push(`PLANES SIMILARES PREVIOS (resume, no dupliques):
|
|
46
|
+
${ctx.similarPlans.map((p) => `- ${p}`).join("\n")}`);
|
|
47
|
+
}
|
|
48
|
+
if (ctx.lessons.length) {
|
|
49
|
+
parts.push(`LECCIONES RELEVANTES (consid\xE9ralas al planear):
|
|
50
|
+
${ctx.lessons.map((l) => `- ${l}`).join("\n")}`);
|
|
51
|
+
}
|
|
52
|
+
if (hints.length) {
|
|
53
|
+
parts.push(`SUGERENCIAS DE CALIDAD (el plan qued\xF3 guardado; mej\xF3ralo si aplican):
|
|
54
|
+
${hints.map((h) => `- ${h}`).join("\n")}`);
|
|
55
|
+
}
|
|
56
|
+
return parts.join("\n\n");
|
|
57
|
+
}
|
|
2
58
|
|
|
3
59
|
// src/core/register.ts
|
|
4
60
|
import fs from "fs";
|
|
@@ -128,6 +184,9 @@ function pkgVersion() {
|
|
|
128
184
|
}
|
|
129
185
|
|
|
130
186
|
export {
|
|
187
|
+
planContext,
|
|
188
|
+
planQualityHints,
|
|
189
|
+
architectBlock,
|
|
131
190
|
distDir,
|
|
132
191
|
registerHooks,
|
|
133
192
|
unregisterHooks,
|
package/dist/cli.js
CHANGED
|
@@ -3,21 +3,24 @@ import {
|
|
|
3
3
|
readStats
|
|
4
4
|
} from "./chunk-XITAQVOZ.js";
|
|
5
5
|
import {
|
|
6
|
+
architectBlock,
|
|
6
7
|
distDir,
|
|
7
8
|
globalSettingsPath,
|
|
8
9
|
hooksRegistered,
|
|
9
10
|
mcpRegisteredProject,
|
|
10
11
|
pkgVersion,
|
|
12
|
+
planContext,
|
|
13
|
+
planQualityHints,
|
|
11
14
|
projectSettingsPath,
|
|
12
15
|
registerHooks,
|
|
13
16
|
registerMcpGlobal,
|
|
14
17
|
registerMcpProject,
|
|
15
18
|
unregisterHooks
|
|
16
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-DHXL36RG.js";
|
|
17
20
|
import {
|
|
18
21
|
hybridSearch,
|
|
19
22
|
protocolChain
|
|
20
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-RZI7TYAG.js";
|
|
21
24
|
import {
|
|
22
25
|
defaultVaultPath,
|
|
23
26
|
ensureVaultStructure,
|
|
@@ -32,10 +35,10 @@ import {
|
|
|
32
35
|
} from "./chunk-DYCARGQR.js";
|
|
33
36
|
import {
|
|
34
37
|
serveGraph
|
|
35
|
-
} from "./chunk-
|
|
38
|
+
} from "./chunk-DCKYTO4O.js";
|
|
36
39
|
import {
|
|
37
40
|
VaultIndex
|
|
38
|
-
} from "./chunk-
|
|
41
|
+
} from "./chunk-D5ROL42O.js";
|
|
39
42
|
import {
|
|
40
43
|
createNote,
|
|
41
44
|
slugify,
|
|
@@ -50,8 +53,8 @@ import {
|
|
|
50
53
|
} from "./chunk-EDYBSJSS.js";
|
|
51
54
|
|
|
52
55
|
// src/cli.ts
|
|
53
|
-
import
|
|
54
|
-
import
|
|
56
|
+
import fs5 from "fs";
|
|
57
|
+
import path5 from "path";
|
|
55
58
|
import readline from "readline/promises";
|
|
56
59
|
import { Command } from "commander";
|
|
57
60
|
import pc from "picocolors";
|
|
@@ -542,6 +545,8 @@ function configureClaudeMd(scope, projectDir) {
|
|
|
542
545
|
"- ANTES de explorar c\xF3digo o re-derivar contexto: busca con la tool MCP `vault_search`; si la b\xF3veda ya lo sabe, \xFAsalo.",
|
|
543
546
|
"- El Protocolo Alexandria es palanca, no l\xEDmite: tareas simples se responden directo, sin ceremonia. En tareas no triviales: `plan_create` (objetivo + Definition of Done) \u2192 ejecutar con toda tu capacidad \u2192 `task_verify` con evidencia real (la evidencia elimina errores, no frena) \u2192 si algo falla, `vault_search` por lecciones previas antes de re-debuggear \u2192 `lesson_extract` al resolver algo no obvio. Soluciones cacheadas se validan contra el c\xF3digo actual antes de reutilizarse.",
|
|
544
547
|
"- Al descubrir arquitectura o decisiones: `vault_save` (con `[[wikilinks]]`; el t\xEDtulo `Mapa - <proyecto>` actualiza el mapa que se inyecta al iniciar sesi\xF3n).",
|
|
548
|
+
"- Enriquece la b\xF3veda cuando el trabajo lo revele (no como tarea aparte): decisiones de arquitectura con su porqu\xE9 (por qu\xE9 X y no Y), qu\xE9 hace cada m\xF3dulo/feature al tocarlo, vocabulario propio del dominio, y errores no obvios con su fix (`lesson_extract`). Notas compactas: el objetivo es ahorrar tokens futuros, no escribir prosa.",
|
|
549
|
+
"- Las notas `API - <proyecto>` / `Env - <proyecto>` / `Datos - <proyecto>` / `Convenciones - <proyecto>` (de `ale scan`) ya traen rutas, variables (solo nombres) y esquema \u2014 cons\xFAltalas por b\xFAsqueda antes de releer esos archivos.",
|
|
545
550
|
"- `vault_related` trae conocimiento conectado sin releer archivos.",
|
|
546
551
|
CLAUDE_MD_END
|
|
547
552
|
].join("\n");
|
|
@@ -634,6 +639,247 @@ ${readme.split("\n").slice(0, 15).join("\n")}`);
|
|
|
634
639
|
});
|
|
635
640
|
}
|
|
636
641
|
|
|
642
|
+
// src/core/scan.ts
|
|
643
|
+
import fs4 from "fs";
|
|
644
|
+
import path4 from "path";
|
|
645
|
+
var SKIP_DIRS2 = /* @__PURE__ */ new Set([
|
|
646
|
+
"node_modules",
|
|
647
|
+
".git",
|
|
648
|
+
".next",
|
|
649
|
+
"dist",
|
|
650
|
+
"build",
|
|
651
|
+
".vault",
|
|
652
|
+
".claude",
|
|
653
|
+
"coverage",
|
|
654
|
+
"Alexandria",
|
|
655
|
+
"KnowledgeVault",
|
|
656
|
+
".turbo",
|
|
657
|
+
".vercel",
|
|
658
|
+
"out",
|
|
659
|
+
"vendor"
|
|
660
|
+
]);
|
|
661
|
+
var SOURCE_EXT = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs"]);
|
|
662
|
+
var MAX_FILES = 400;
|
|
663
|
+
var MAX_FILE_BYTES = 64 * 1024;
|
|
664
|
+
var MAX_ENTRIES = 80;
|
|
665
|
+
function collectSourceFiles(projectDir) {
|
|
666
|
+
const out = [];
|
|
667
|
+
const walk = (dir, depth) => {
|
|
668
|
+
if (depth > 7 || out.length >= MAX_FILES) return;
|
|
669
|
+
let entries = [];
|
|
670
|
+
try {
|
|
671
|
+
entries = fs4.readdirSync(dir, { withFileTypes: true });
|
|
672
|
+
} catch {
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
675
|
+
for (const e of entries) {
|
|
676
|
+
if (out.length >= MAX_FILES) return;
|
|
677
|
+
if (e.name.startsWith(".") || SKIP_DIRS2.has(e.name)) continue;
|
|
678
|
+
const full = path4.join(dir, e.name);
|
|
679
|
+
if (e.isDirectory()) {
|
|
680
|
+
walk(full, depth + 1);
|
|
681
|
+
} else if (e.isFile() && SOURCE_EXT.has(path4.extname(e.name))) {
|
|
682
|
+
try {
|
|
683
|
+
if (fs4.statSync(full).size > MAX_FILE_BYTES) continue;
|
|
684
|
+
out.push({
|
|
685
|
+
rel: path4.relative(projectDir, full).split(path4.sep).join("/"),
|
|
686
|
+
content: fs4.readFileSync(full, "utf8")
|
|
687
|
+
});
|
|
688
|
+
} catch {
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
};
|
|
693
|
+
walk(projectDir, 0);
|
|
694
|
+
return out;
|
|
695
|
+
}
|
|
696
|
+
var HTTP_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"];
|
|
697
|
+
function appRoutePath(rel) {
|
|
698
|
+
const m = rel.match(/(?:^|\/)app\/(.*)route\.[tj]sx?$/);
|
|
699
|
+
if (!m) return "";
|
|
700
|
+
const segs = m[1].split("/").filter((s) => s && !/^\(.*\)$/.test(s));
|
|
701
|
+
return "/" + segs.join("/").replace(/\/$/, "");
|
|
702
|
+
}
|
|
703
|
+
function scanApi(files) {
|
|
704
|
+
const lines = [];
|
|
705
|
+
for (const f of files) {
|
|
706
|
+
if (lines.length >= MAX_ENTRIES) break;
|
|
707
|
+
if (/(^|\/)route\.[tj]sx?$/.test(f.rel) && /(^|\/)app\//.test(f.rel)) {
|
|
708
|
+
const methods = HTTP_METHODS.filter(
|
|
709
|
+
(m) => new RegExp(`export\\s+(?:async\\s+)?(?:function\\s+${m}\\b|const\\s+${m}\\s*=)`).test(f.content)
|
|
710
|
+
);
|
|
711
|
+
if (methods.length) lines.push(`- ${methods.join("/")} ${appRoutePath(f.rel)} \u2014 ${f.rel}`);
|
|
712
|
+
continue;
|
|
713
|
+
}
|
|
714
|
+
const pagesApi = f.rel.match(/(?:^|\/)pages\/api\/(.+)\.[tj]sx?$/);
|
|
715
|
+
if (pagesApi) {
|
|
716
|
+
lines.push(`- handler /api/${pagesApi[1].replace(/\/index$/, "")} \u2014 ${f.rel}`);
|
|
717
|
+
continue;
|
|
718
|
+
}
|
|
719
|
+
if (/^\s*['"]use server['"]/m.test(f.content.slice(0, 400))) {
|
|
720
|
+
const fns = [...f.content.matchAll(/export\s+(?:async\s+)?function\s+(\w+)/g)].map((m) => m[1]);
|
|
721
|
+
if (fns.length) lines.push(`- server actions: ${fns.slice(0, 8).join(", ")} \u2014 ${f.rel}`);
|
|
722
|
+
continue;
|
|
723
|
+
}
|
|
724
|
+
const expressHits = [...f.content.matchAll(/\b(?:app|router|api)\.(get|post|put|patch|delete)\(\s*['"`]([^'"`]+)['"`]/g)];
|
|
725
|
+
for (const h of expressHits.slice(0, 12)) {
|
|
726
|
+
lines.push(`- ${h[1].toUpperCase()} ${h[2]} \u2014 ${f.rel}`);
|
|
727
|
+
if (lines.length >= MAX_ENTRIES) break;
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
return lines.slice(0, MAX_ENTRIES);
|
|
731
|
+
}
|
|
732
|
+
function scanEnvNames(projectDir) {
|
|
733
|
+
const seen = /* @__PURE__ */ new Map();
|
|
734
|
+
for (const file of [".env.example", ".env", ".env.local"]) {
|
|
735
|
+
let text;
|
|
736
|
+
try {
|
|
737
|
+
text = fs4.readFileSync(path4.join(projectDir, file), "utf8");
|
|
738
|
+
} catch {
|
|
739
|
+
continue;
|
|
740
|
+
}
|
|
741
|
+
for (const line of text.split("\n")) {
|
|
742
|
+
const m = line.match(/^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=/);
|
|
743
|
+
if (m && !seen.has(m[1])) seen.set(m[1], file);
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
return [...seen.entries()].slice(0, MAX_ENTRIES).map(([name, src]) => `- ${name} (${src})`);
|
|
747
|
+
}
|
|
748
|
+
function scanDataSchema(projectDir, files) {
|
|
749
|
+
const lines = [];
|
|
750
|
+
try {
|
|
751
|
+
const schema = fs4.readFileSync(path4.join(projectDir, "prisma", "schema.prisma"), "utf8");
|
|
752
|
+
for (const m of schema.matchAll(/model\s+(\w+)\s*\{([^}]*)\}/g)) {
|
|
753
|
+
const fields = m[2].split("\n").map((l) => l.trim()).filter((l) => l && !l.startsWith("@@") && !l.startsWith("//")).map((l) => l.split(/\s+/)[0]);
|
|
754
|
+
const shown = fields.slice(0, 8).join(", ");
|
|
755
|
+
lines.push(`- model ${m[1]}: ${shown}${fields.length > 8 ? ` (+${fields.length - 8})` : ""} \u2014 prisma/schema.prisma`);
|
|
756
|
+
}
|
|
757
|
+
} catch {
|
|
758
|
+
}
|
|
759
|
+
for (const f of files.filter((x) => /schema/i.test(x.rel))) {
|
|
760
|
+
for (const m of f.content.matchAll(/\b(?:pg|mysql|sqlite)Table\(\s*['"`](\w+)['"`]/g)) {
|
|
761
|
+
lines.push(`- table ${m[1]} (drizzle) \u2014 ${f.rel}`);
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
const migDirs = ["migrations", "db/migrations", "drizzle", "supabase/migrations"];
|
|
765
|
+
for (const dir of migDirs) {
|
|
766
|
+
let sqlFiles = [];
|
|
767
|
+
try {
|
|
768
|
+
sqlFiles = fs4.readdirSync(path4.join(projectDir, dir)).filter((f) => f.endsWith(".sql")).slice(0, 30);
|
|
769
|
+
} catch {
|
|
770
|
+
continue;
|
|
771
|
+
}
|
|
772
|
+
const tables = /* @__PURE__ */ new Set();
|
|
773
|
+
for (const f of sqlFiles) {
|
|
774
|
+
try {
|
|
775
|
+
const sql = fs4.readFileSync(path4.join(projectDir, dir, f), "utf8");
|
|
776
|
+
for (const m of sql.matchAll(/CREATE TABLE (?:IF NOT EXISTS )?["'`]?(\w+)/gi)) tables.add(m[1]);
|
|
777
|
+
} catch {
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
if (tables.size) lines.push(`- tablas (${dir}/*.sql): ${[...tables].slice(0, 20).join(", ")}`);
|
|
781
|
+
}
|
|
782
|
+
return lines.slice(0, MAX_ENTRIES);
|
|
783
|
+
}
|
|
784
|
+
function scanConventions(projectDir) {
|
|
785
|
+
const lines = [];
|
|
786
|
+
const has = (f) => fs4.existsSync(path4.join(projectDir, f));
|
|
787
|
+
const pm = has("bun.lockb") || has("bun.lock") ? "bun" : has("pnpm-lock.yaml") ? "pnpm" : has("yarn.lock") ? "yarn" : has("package-lock.json") ? "npm" : null;
|
|
788
|
+
if (pm) lines.push(`- gestor de paquetes: ${pm}`);
|
|
789
|
+
let pkg = {};
|
|
790
|
+
try {
|
|
791
|
+
pkg = JSON.parse(fs4.readFileSync(path4.join(projectDir, "package.json"), "utf8"));
|
|
792
|
+
} catch {
|
|
793
|
+
}
|
|
794
|
+
if (pkg.workspaces || has("pnpm-workspace.yaml") || has("turbo.json")) lines.push("- monorepo: s\xED (workspaces)");
|
|
795
|
+
try {
|
|
796
|
+
const ts = JSON.parse(fs4.readFileSync(path4.join(projectDir, "tsconfig.json"), "utf8"));
|
|
797
|
+
const co = ts.compilerOptions ?? {};
|
|
798
|
+
lines.push(`- TypeScript${co.strict ? " strict" : ""}`);
|
|
799
|
+
const paths = Object.keys(co.paths ?? {}).slice(0, 5);
|
|
800
|
+
if (paths.length) lines.push(`- alias de imports: ${paths.join(", ")}`);
|
|
801
|
+
} catch {
|
|
802
|
+
}
|
|
803
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
804
|
+
const fw = [];
|
|
805
|
+
if (deps?.next) fw.push("Next.js");
|
|
806
|
+
if (deps?.astro) fw.push("Astro");
|
|
807
|
+
if (deps?.expo || deps?.["react-native"]) fw.push("React Native/Expo");
|
|
808
|
+
if (deps?.hono) fw.push("Hono");
|
|
809
|
+
if (deps?.express) fw.push("Express");
|
|
810
|
+
if (deps?.["@nestjs/core"]) fw.push("NestJS");
|
|
811
|
+
if (deps?.vue) fw.push("Vue");
|
|
812
|
+
if (deps?.svelte) fw.push("Svelte");
|
|
813
|
+
if (fw.length) lines.push(`- framework: ${fw.join(", ")}`);
|
|
814
|
+
return lines;
|
|
815
|
+
}
|
|
816
|
+
function linkMapToScans(vault, name, titles) {
|
|
817
|
+
if (titles.length === 0) return;
|
|
818
|
+
const mapFile = path4.join(vault.managed, "notes", `mapa-${slugify(name)}.md`);
|
|
819
|
+
try {
|
|
820
|
+
const text = fs4.readFileSync(mapFile, "utf8");
|
|
821
|
+
if (text.includes("Contexto ampliado:")) return;
|
|
822
|
+
fs4.appendFileSync(mapFile, `
|
|
823
|
+
Contexto ampliado: ${titles.map((t) => `[[${t}]]`).join(" \xB7 ")}
|
|
824
|
+
`);
|
|
825
|
+
} catch {
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
function scanAll(vault, projectDir) {
|
|
829
|
+
const name = path4.basename(projectDir);
|
|
830
|
+
const gitignored = ensureGitignore(projectDir, vault.root) !== null;
|
|
831
|
+
try {
|
|
832
|
+
untrackPersonalConfigs(projectDir);
|
|
833
|
+
} catch {
|
|
834
|
+
}
|
|
835
|
+
try {
|
|
836
|
+
scanProject(vault, projectDir);
|
|
837
|
+
} catch {
|
|
838
|
+
}
|
|
839
|
+
let files = [];
|
|
840
|
+
try {
|
|
841
|
+
files = collectSourceFiles(projectDir);
|
|
842
|
+
} catch {
|
|
843
|
+
}
|
|
844
|
+
const run = (fn) => {
|
|
845
|
+
try {
|
|
846
|
+
return fn();
|
|
847
|
+
} catch {
|
|
848
|
+
return [];
|
|
849
|
+
}
|
|
850
|
+
};
|
|
851
|
+
const api = run(() => scanApi(files));
|
|
852
|
+
const env = run(() => scanEnvNames(projectDir));
|
|
853
|
+
const data = run(() => scanDataSchema(projectDir, files));
|
|
854
|
+
const conventions = run(() => scanConventions(projectDir));
|
|
855
|
+
const notes = [];
|
|
856
|
+
const titles = [];
|
|
857
|
+
const write = (kind, title, header, lines) => {
|
|
858
|
+
if (lines.length === 0) return;
|
|
859
|
+
notes.push(
|
|
860
|
+
upsertNote(vault.managed, {
|
|
861
|
+
fixedName: `${kind}-${slugify(name)}`,
|
|
862
|
+
title,
|
|
863
|
+
type: "map",
|
|
864
|
+
tags: [name, kind],
|
|
865
|
+
dir: "notes",
|
|
866
|
+
content: `${header}
|
|
867
|
+
|
|
868
|
+
${lines.join("\n")}
|
|
869
|
+
|
|
870
|
+
Proyecto: [[Mapa - ${name}]]`
|
|
871
|
+
})
|
|
872
|
+
);
|
|
873
|
+
titles.push(title);
|
|
874
|
+
};
|
|
875
|
+
write("api", `API - ${name}`, `Rutas y server actions detectadas por \`ale scan\` (regenerable).`, api);
|
|
876
|
+
write("env", `Env - ${name}`, `Variables de entorno (SOLO nombres \u2014 los valores nunca se guardan).`, env);
|
|
877
|
+
write("datos", `Datos - ${name}`, `Esquema de datos detectado en archivos (sin conexi\xF3n a BD).`, data);
|
|
878
|
+
write("convenciones", `Convenciones - ${name}`, `Convenciones detectadas por \`ale scan\`.`, conventions);
|
|
879
|
+
linkMapToScans(vault, name, titles);
|
|
880
|
+
return { api: api.length, env: env.length, data: data.length, conventions: conventions.length, notes, gitignored };
|
|
881
|
+
}
|
|
882
|
+
|
|
637
883
|
// src/cli.ts
|
|
638
884
|
function registerAgentsMcp(agents, scope, cwd, portable = false) {
|
|
639
885
|
for (const agent of agents) {
|
|
@@ -696,7 +942,7 @@ program.command("init").description("Crea/conecta la b\xF3veda e instala TODO: m
|
|
|
696
942
|
).action(async (opts) => {
|
|
697
943
|
const isProject = Boolean(opts.project) && !opts.global;
|
|
698
944
|
const cwd = process.cwd();
|
|
699
|
-
const vaultPath =
|
|
945
|
+
const vaultPath = path5.resolve(opts.path ?? (isProject ? path5.join(cwd, "Alexandria") : defaultVaultPath()));
|
|
700
946
|
await showBanner();
|
|
701
947
|
console.log(pc.bold(`Instalaci\xF3n ${isProject ? "por proyecto" : "global"}
|
|
702
948
|
`));
|
|
@@ -754,8 +1000,8 @@ program.command("init").description("Crea/conecta la b\xF3veda e instala TODO: m
|
|
|
754
1000
|
opts.protocol !== false ? pc.green("\u2713 Protocolo Alexandria activo (plan_create \xB7 task_verify \xB7 lesson_extract) \u2014 ap\xE1galo con: ale config set protocol false") : pc.dim(" Protocolo desactivado (b\xF3veda cl\xE1sica) \u2014 act\xEDvalo con: ale config set protocol true")
|
|
755
1001
|
);
|
|
756
1002
|
if (isProject) {
|
|
757
|
-
const
|
|
758
|
-
|
|
1003
|
+
const s = scanAll(vault, cwd);
|
|
1004
|
+
console.log(pc.green(`\u2713 Proyecto escaneado \u2192 API: ${s.api} \xB7 Env: ${s.env} \xB7 Datos: ${s.data} \xB7 Convenciones: ${s.conventions} (re-ejecuta con: ale scan)`));
|
|
759
1005
|
}
|
|
760
1006
|
await downloadModelIfMissing();
|
|
761
1007
|
const idx = VaultIndex.load(vault);
|
|
@@ -768,10 +1014,10 @@ program.command("init").description("Crea/conecta la b\xF3veda e instala TODO: m
|
|
|
768
1014
|
});
|
|
769
1015
|
program.command("plan").description("Crear un plan del Protocolo desde un archivo .md/.txt (en vez de escribirlo en la terminal)").argument("<file>", 'archivo con el plan (los checkboxes "- [ ]" se toman como Definition of Done)').option("--title <t>", "t\xEDtulo del plan (default: nombre del archivo o primer heading)").action(async (file, opts) => {
|
|
770
1016
|
const { vault } = await ensureReady();
|
|
771
|
-
const abs =
|
|
772
|
-
const raw =
|
|
1017
|
+
const abs = path5.resolve(file);
|
|
1018
|
+
const raw = fs5.readFileSync(abs, "utf8");
|
|
773
1019
|
const heading = raw.match(/^#\s+(.+)$/m)?.[1]?.trim();
|
|
774
|
-
const title = opts.title ?? heading ??
|
|
1020
|
+
const title = opts.title ?? heading ?? path5.basename(abs).replace(/\.(md|txt)$/i, "");
|
|
775
1021
|
const dod = [...raw.matchAll(/^[-*]\s*\[[ x]\]\s*(.+)$/gim)].map((m) => m[1].trim());
|
|
776
1022
|
const noteFile = createNote(vault.managed, {
|
|
777
1023
|
title: title.startsWith("Plan - ") ? title : `Plan - ${title}`,
|
|
@@ -781,9 +1027,13 @@ program.command("plan").description("Crear un plan del Protocolo desde un archiv
|
|
|
781
1027
|
content: raw.trim()
|
|
782
1028
|
});
|
|
783
1029
|
await VaultIndex.load(vault).refresh();
|
|
784
|
-
console.log(pc.green(`\u2713 Plan creado: ${
|
|
1030
|
+
console.log(pc.green(`\u2713 Plan creado: ${path5.relative(vault.root, noteFile)}`));
|
|
785
1031
|
console.log(pc.dim(` DoD detectada: ${dod.length} criterios${dod.length ? " \u2014 " + dod.slice(0, 3).join(" \xB7 ") + (dod.length > 3 ? " \u2026" : "") : ' (agrega checkboxes "- [ ]" para criterios verificables)'}`));
|
|
786
1032
|
console.log(pc.dim(" El agente lo ver\xE1 como plan abierto al iniciar sesi\xF3n y lo retomar\xE1 con task_verify."));
|
|
1033
|
+
const tasks = [...raw.matchAll(/^\s*\d+[.)]\s+(.+)$/gm)].map((m) => m[1].trim());
|
|
1034
|
+
const ctx = await planContext(vault, title);
|
|
1035
|
+
const block = architectBlock(ctx, planQualityHints(dod, tasks));
|
|
1036
|
+
if (block) console.log(pc.dim("\n" + block.split("\n").map((l) => " " + l).join("\n")));
|
|
787
1037
|
});
|
|
788
1038
|
program.command("audit").description("Auditor\xEDa del Protocolo: planes sin DoD, planes abiertos, fallos sin lecci\xF3n, verificaciones auto-reportadas, notas sueltas").action(async () => {
|
|
789
1039
|
const { vault, idx } = await ensureReady();
|
|
@@ -848,21 +1098,21 @@ program.command("consolidate").description("Archiva prompts viejos sin reuso: sa
|
|
|
848
1098
|
console.log(pc.dim("Nada que consolidar: sin prompts viejos sin uso."));
|
|
849
1099
|
return;
|
|
850
1100
|
}
|
|
851
|
-
const archiveDir =
|
|
852
|
-
if (!opts.dry)
|
|
1101
|
+
const archiveDir = path5.join(vault.managed, "archive");
|
|
1102
|
+
if (!opts.dry) fs5.mkdirSync(archiveDir, { recursive: true });
|
|
853
1103
|
for (const n of stale) {
|
|
854
1104
|
console.log(
|
|
855
1105
|
`${opts.dry ? pc.yellow("se archivar\xEDa") : pc.cyan("archivado")} ${n.rel} ${pc.dim(`(${(n.created ?? "").slice(0, 10)}, hits ${n.hits})`)}`
|
|
856
1106
|
);
|
|
857
1107
|
if (!opts.dry) {
|
|
858
|
-
|
|
1108
|
+
fs5.renameSync(path5.join(vault.root, n.rel), path5.join(archiveDir, path5.basename(n.rel)));
|
|
859
1109
|
}
|
|
860
1110
|
}
|
|
861
1111
|
if (!opts.dry) {
|
|
862
1112
|
await VaultIndex.load(vault).refresh();
|
|
863
1113
|
console.log(
|
|
864
1114
|
pc.green(`
|
|
865
|
-
\u2713 ${stale.length} prompts archivados en ${
|
|
1115
|
+
\u2713 ${stale.length} prompts archivados en ${path5.relative(vault.root, archiveDir)}/ \u2014 fuera del grafo, siguen buscables. Nada se pierde.`)
|
|
866
1116
|
);
|
|
867
1117
|
} else {
|
|
868
1118
|
console.log(pc.dim(`
|
|
@@ -893,10 +1143,10 @@ program.command("add").description("Guardar una nota manualmente").argument("<ti
|
|
|
893
1143
|
const { vault } = await ensureReady();
|
|
894
1144
|
let content = opts.content;
|
|
895
1145
|
if (!content && opts.file) {
|
|
896
|
-
content =
|
|
1146
|
+
content = fs5.readFileSync(path5.resolve(opts.file), "utf8");
|
|
897
1147
|
}
|
|
898
1148
|
if (!content && !process.stdin.isTTY) {
|
|
899
|
-
content =
|
|
1149
|
+
content = fs5.readFileSync(0, "utf8");
|
|
900
1150
|
}
|
|
901
1151
|
const file = createNote(vault.managed, {
|
|
902
1152
|
title,
|
|
@@ -904,7 +1154,7 @@ program.command("add").description("Guardar una nota manualmente").argument("<ti
|
|
|
904
1154
|
tags: opts.tags ? opts.tags.split(",").map((t) => t.trim()) : []
|
|
905
1155
|
});
|
|
906
1156
|
await VaultIndex.load(vault).refresh();
|
|
907
|
-
console.log(pc.green(`\u2713 ${
|
|
1157
|
+
console.log(pc.green(`\u2713 ${path5.relative(vault.root, file)}`));
|
|
908
1158
|
});
|
|
909
1159
|
program.command("search").description("B\xFAsqueda h\xEDbrida (sem\xE1ntica + keyword) en la b\xF3veda").argument("<query...>", "qu\xE9 buscar").option("-k <n>", "n\xFAmero de resultados", "6").option("--expand", "incluir vecinos del grafo").action(async (query, opts) => {
|
|
910
1160
|
const vault = getVault();
|
|
@@ -952,6 +1202,21 @@ ${pc.bold(pc.cyan(r.note.title))} ${pc.dim(`(${r.note.rel}, ${r.note.type})`)}${
|
|
|
952
1202
|
}
|
|
953
1203
|
console.log();
|
|
954
1204
|
});
|
|
1205
|
+
program.command("scan").description("Escanea el proyecto (API, env-nombres, datos, convenciones) \u2192 notas de contexto en la b\xF3veda. Re-ejecutable; solo-lectura del c\xF3digo; garantiza .gitignore").action(async () => {
|
|
1206
|
+
const vault = getVault();
|
|
1207
|
+
ensureVaultStructure(vault);
|
|
1208
|
+
const cwd = process.cwd();
|
|
1209
|
+
const s = scanAll(vault, cwd);
|
|
1210
|
+
const idx = VaultIndex.load(vault);
|
|
1211
|
+
await idx.refresh().catch(() => {
|
|
1212
|
+
});
|
|
1213
|
+
console.log(pc.green(`\u2713 API: ${s.api} rutas \xB7 Env: ${s.env} vars (solo nombres) \xB7 Datos: ${s.data} \xB7 Convenciones: ${s.conventions}${s.gitignored ? " \xB7 .gitignore \u2713" : ""}`));
|
|
1214
|
+
if (s.notes.length) {
|
|
1215
|
+
for (const n of s.notes) console.log(pc.dim(` ${path5.relative(vault.root, n)}`));
|
|
1216
|
+
} else {
|
|
1217
|
+
console.log(pc.dim(" Nada detectado (\xBFproyecto sin package.json/api/env?)"));
|
|
1218
|
+
}
|
|
1219
|
+
});
|
|
955
1220
|
program.command("reindex").description("Reindexar la b\xF3veda (incremental; --force para todo)").option("--force", "reindexar todo desde cero").action(async (opts) => {
|
|
956
1221
|
const vault = getVault();
|
|
957
1222
|
ensureVaultStructure(vault);
|
|
@@ -1008,7 +1273,7 @@ program.command("stats").description("Estado de la b\xF3veda y tokens ahorrados"
|
|
|
1008
1273
|
async function runSkills(opts) {
|
|
1009
1274
|
const { vault } = await ensureReady();
|
|
1010
1275
|
const cwd = process.cwd();
|
|
1011
|
-
const targetDir = opts.project ?
|
|
1276
|
+
const targetDir = opts.project ? path5.join(cwd, ".claude", "skills") : path5.join(process.env.HOME ?? process.env.USERPROFILE ?? cwd, ".claude", "skills");
|
|
1012
1277
|
const recs = await recommendSkills(vault, [targetDir]);
|
|
1013
1278
|
if (recs.length === 0) {
|
|
1014
1279
|
console.log(pc.dim("Sin recomendaciones nuevas: la b\xF3veda a\xFAn no tiene suficientes patrones (o ya est\xE1 todo instalado)."));
|
|
@@ -1076,8 +1341,29 @@ program.command("doctor").description("Verifica y repara la instalaci\xF3n (mode
|
|
|
1076
1341
|
}
|
|
1077
1342
|
const idx = VaultIndex.load(vault);
|
|
1078
1343
|
const res = await idx.refresh();
|
|
1079
|
-
console.log(`${pc.green("\u2713")} \xCDndice al d\xEDa (${res.changed} reindexadas, ${Object.keys(idx.meta.notes).length} notas)
|
|
1080
|
-
|
|
1344
|
+
console.log(`${pc.green("\u2713")} \xCDndice al d\xEDa (${res.changed} reindexadas, ${Object.keys(idx.meta.notes).length} notas)`);
|
|
1345
|
+
if (idx.emb && idx.emb.length !== idx.meta.chunks.length * idx.meta.dim) {
|
|
1346
|
+
console.log(pc.yellow("\u26A0 Embeddings desalineados con el \xEDndice \u2014 corre `ale reindex --force`"));
|
|
1347
|
+
} else if (idx.emb) {
|
|
1348
|
+
console.log(`${pc.green("\u2713")} Embeddings alineados (${idx.meta.chunks.length} chunks)`);
|
|
1349
|
+
}
|
|
1350
|
+
try {
|
|
1351
|
+
const name = path5.basename(cwd);
|
|
1352
|
+
const mapFile = path5.join(vault.managed, "notes", `mapa-${slugify(name)}.md`);
|
|
1353
|
+
const pkgM = fs5.statSync(path5.join(cwd, "package.json")).mtimeMs;
|
|
1354
|
+
const mapM = fs5.statSync(mapFile).mtimeMs;
|
|
1355
|
+
if (pkgM > mapM) {
|
|
1356
|
+
console.log(pc.yellow("\u26A0 package.json cambi\xF3 despu\xE9s del \xFAltimo escaneo \u2014 corre `ale scan` para refrescar el contexto"));
|
|
1357
|
+
} else {
|
|
1358
|
+
console.log(`${pc.green("\u2713")} Contexto del proyecto al d\xEDa (ale scan)`);
|
|
1359
|
+
}
|
|
1360
|
+
} catch {
|
|
1361
|
+
}
|
|
1362
|
+
const skillsRepoCfg = localSkillsRepo();
|
|
1363
|
+
if (skillsRepoCfg && !fs5.existsSync(skillsRepoCfg)) {
|
|
1364
|
+
console.log(pc.yellow(`\u26A0 skills.repo apunta a ${skillsRepoCfg} y no existe \u2014 corr\xEDgelo: ale config set skills.repo <ruta>`));
|
|
1365
|
+
}
|
|
1366
|
+
console.log();
|
|
1081
1367
|
});
|
|
1082
1368
|
program.command("uninstall").description("Reversi\xF3n limpia: quita hooks, bloque de CLAUDE.md y MCP del proyecto (no borra la b\xF3veda ni las notas)").option("--project", "quitar del proyecto (cwd)").action((opts) => {
|
|
1083
1369
|
const cwd = process.cwd();
|
|
@@ -1088,14 +1374,14 @@ program.command("uninstall").description("Reversi\xF3n limpia: quita hooks, bloq
|
|
|
1088
1374
|
const claudeMd = removeClaudeMd(scope, cwd);
|
|
1089
1375
|
if (claudeMd) console.log(pc.green(`\u2713 Bloque de Alexandria removido de ${claudeMd}`));
|
|
1090
1376
|
if (opts.project) {
|
|
1091
|
-
const mcpFile =
|
|
1377
|
+
const mcpFile = path5.join(cwd, ".mcp.json");
|
|
1092
1378
|
try {
|
|
1093
|
-
const cfg = JSON.parse(
|
|
1379
|
+
const cfg = JSON.parse(fs5.readFileSync(mcpFile, "utf8"));
|
|
1094
1380
|
if (cfg.mcpServers?.alexandria) {
|
|
1095
1381
|
delete cfg.mcpServers.alexandria;
|
|
1096
1382
|
if (Object.keys(cfg.mcpServers).length === 0) delete cfg.mcpServers;
|
|
1097
|
-
if (Object.keys(cfg).length === 0)
|
|
1098
|
-
else
|
|
1383
|
+
if (Object.keys(cfg).length === 0) fs5.rmSync(mcpFile, { force: true });
|
|
1384
|
+
else fs5.writeFileSync(mcpFile, JSON.stringify(cfg, null, 2) + "\n");
|
|
1099
1385
|
console.log(pc.green("\u2713 MCP removido de .mcp.json"));
|
|
1100
1386
|
}
|
|
1101
1387
|
} catch {
|
package/dist/hooks/on-prompt.js
CHANGED
|
@@ -9,12 +9,12 @@ import {
|
|
|
9
9
|
} from "../chunk-DEDAOKAV.js";
|
|
10
10
|
import {
|
|
11
11
|
hybridSearch
|
|
12
|
-
} from "../chunk-
|
|
12
|
+
} from "../chunk-RZI7TYAG.js";
|
|
13
13
|
import {
|
|
14
14
|
resolveVault,
|
|
15
15
|
vaultExists
|
|
16
16
|
} from "../chunk-DYCARGQR.js";
|
|
17
|
-
import "../chunk-
|
|
17
|
+
import "../chunk-D5ROL42O.js";
|
|
18
18
|
import {
|
|
19
19
|
createNote,
|
|
20
20
|
touchNote
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
} from "../chunk-DYCARGQR.js";
|
|
15
15
|
import {
|
|
16
16
|
VaultIndex
|
|
17
|
-
} from "../chunk-
|
|
17
|
+
} from "../chunk-D5ROL42O.js";
|
|
18
18
|
import "../chunk-XWR74BQ2.js";
|
|
19
19
|
import "../chunk-EDYBSJSS.js";
|
|
20
20
|
|
|
@@ -58,6 +58,12 @@ ${truncate(body.trim(), 4e3)}`);
|
|
|
58
58
|
parts.push(`## Sesiones recientes en la b\xF3veda
|
|
59
59
|
${lines.join("\n")}`);
|
|
60
60
|
}
|
|
61
|
+
const distilled = notes.filter((n) => n.type === "note" || n.type === "lesson").length;
|
|
62
|
+
if (map && distilled < 3) {
|
|
63
|
+
parts.push(
|
|
64
|
+
`B\xF3veda joven (${distilled} notas destiladas): al descubrir decisiones, m\xF3dulos o vocabulario del dominio, gu\xE1rdalos compactos con vault_save \u2014 tokens gratis en sesiones futuras.`
|
|
65
|
+
);
|
|
66
|
+
}
|
|
61
67
|
const titles = notes.filter((n) => n.type !== "prompt").sort((a, b) => (b.hits ?? 1) - (a.hits ?? 1)).slice(0, 25).map((n) => n.title);
|
|
62
68
|
if (titles.length > 0) {
|
|
63
69
|
parts.push(`## La b\xF3veda ya tiene conocimiento sobre
|
package/dist/mcp/server.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
architectBlock,
|
|
4
|
+
pkgVersion,
|
|
5
|
+
planContext,
|
|
6
|
+
planQualityHints
|
|
7
|
+
} from "../chunk-DHXL36RG.js";
|
|
5
8
|
import {
|
|
6
9
|
hybridSearch
|
|
7
|
-
} from "../chunk-
|
|
10
|
+
} from "../chunk-RZI7TYAG.js";
|
|
8
11
|
import {
|
|
9
12
|
ensureVaultStructure,
|
|
10
13
|
resolveVault
|
|
11
14
|
} from "../chunk-DYCARGQR.js";
|
|
12
15
|
import {
|
|
13
16
|
VaultIndex
|
|
14
|
-
} from "../chunk-
|
|
17
|
+
} from "../chunk-D5ROL42O.js";
|
|
15
18
|
import {
|
|
16
19
|
createNote,
|
|
17
20
|
setNoteStatus,
|
|
@@ -132,26 +135,31 @@ server.tool(
|
|
|
132
135
|
);
|
|
133
136
|
server.tool(
|
|
134
137
|
"plan_create",
|
|
135
|
-
|
|
138
|
+
"PROTOCOLO paso 1 (solo tareas NO triviales \u2014 las simples resp\xF3ndelas directo, sin ceremonia): crea el plan como un ARQUITECTO. Si el objetivo es vago, haz 2-3 preguntas de aclaraci\xF3n al usuario ANTES de crear el plan (qu\xE9 es \xE9xito, restricciones, alcance). DoD = criterios verificables por comando; tareas chicas y en orden de construcci\xF3n. Para planes grandes pasa `design` (stack/decisiones de arquitectura). La respuesta trae planes similares previos y lecciones \u2014 \xFAsalos para planear mejor. Verifica cada tarea con task_verify.",
|
|
136
139
|
{
|
|
137
140
|
title: z.string().describe('Nombre corto del objetivo, ej. "Login con Google"'),
|
|
138
141
|
goal: z.string().describe("Qu\xE9 se quiere lograr, en una o dos frases"),
|
|
139
142
|
dod: z.array(z.string()).describe("Definition of Done: criterios verificables de \xE9xito"),
|
|
140
|
-
tasks: z.array(z.string()).describe("Tareas numeradas, chicas y verificables")
|
|
143
|
+
tasks: z.array(z.string()).describe("Tareas numeradas, chicas y verificables, en orden de construcci\xF3n"),
|
|
144
|
+
design: z.string().optional().describe('Decisiones de arquitectura/stack del plan (el "blueprint"): qu\xE9 se eligi\xF3 y por qu\xE9. Recomendado en planes de >5 tareas.')
|
|
141
145
|
},
|
|
142
|
-
async ({ title, goal, dod, tasks }) => {
|
|
146
|
+
async ({ title, goal, dod, tasks, design }) => {
|
|
143
147
|
ensureVaultStructure(vault);
|
|
148
|
+
const ctx = await planContext(vault, `${title} ${goal}`);
|
|
149
|
+
const hints = planQualityHints(dod, tasks, design);
|
|
144
150
|
const idx = VaultIndex.load(vault);
|
|
145
151
|
const map = findMap(idx);
|
|
146
152
|
const content = [
|
|
147
153
|
`## Objetivo
|
|
148
154
|
${goal}`,
|
|
155
|
+
design?.trim() ? `## Dise\xF1o
|
|
156
|
+
${design.trim()}` : "",
|
|
149
157
|
`## Definition of Done
|
|
150
158
|
${dod.map((d) => `- [ ] ${d}`).join("\n")}`,
|
|
151
159
|
`## Tareas
|
|
152
160
|
${tasks.map((t, i) => `${i + 1}. ${t}`).join("\n")}`,
|
|
153
161
|
map ? `Proyecto: [[${map.title}]]` : ""
|
|
154
|
-
].join("\n\n");
|
|
162
|
+
].filter(Boolean).join("\n\n");
|
|
155
163
|
const file = createNote(vault.managed, {
|
|
156
164
|
title: `Plan - ${title}`,
|
|
157
165
|
type: "plan",
|
|
@@ -162,8 +170,11 @@ ${tasks.map((t, i) => `${i + 1}. ${t}`).join("\n")}`,
|
|
|
162
170
|
});
|
|
163
171
|
await VaultIndex.load(vault).refresh().catch(() => {
|
|
164
172
|
});
|
|
173
|
+
const extra = architectBlock(ctx, hints);
|
|
165
174
|
return text(
|
|
166
|
-
`Plan guardado en ${path.relative(vault.root, file)}. Ejecuta las tareas UNA por una; tras cada una llama task_verify con evidencia real (salida de tests/build). Al terminar todo, llama lesson_extract.`
|
|
175
|
+
`Plan guardado en ${path.relative(vault.root, file)}. Ejecuta las tareas UNA por una; tras cada una llama task_verify con evidencia real (salida de tests/build). Al terminar todo, llama lesson_extract.` + (extra ? `
|
|
176
|
+
|
|
177
|
+
${extra}` : "")
|
|
167
178
|
);
|
|
168
179
|
}
|
|
169
180
|
);
|
|
@@ -4,8 +4,8 @@ import {
|
|
|
4
4
|
renderGraphHtml,
|
|
5
5
|
serveGraph,
|
|
6
6
|
writeStaticGraph
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-DCKYTO4O.js";
|
|
8
|
+
import "./chunk-D5ROL42O.js";
|
|
9
9
|
import "./chunk-XWR74BQ2.js";
|
|
10
10
|
import "./chunk-EDYBSJSS.js";
|
|
11
11
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ureck/alexandria",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Alexandria — bóveda de conocimiento local para agentes de IA (Claude Code, Cursor, OpenCode, Windsurf y más): captura automática, búsqueda semántica offline y grafo de conexiones estilo Obsidian. Ahorra tokens inyectando solo el contexto relevante.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|