@ureck/alexandria 0.5.3 → 0.5.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/README.md +6 -4
- package/dist/{chunk-3ETM6PKR.js → chunk-MEL3BE65.js} +26 -1
- package/dist/cli.js +111 -39
- package/dist/hooks/on-prompt.js +1 -1
- package/dist/mcp/server.js +60 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
[](./LICENSE)
|
|
7
7
|
[](https://buymeacoffee.com/ureck)
|
|
8
8
|
|
|
9
|
+
[](https://ureckchan.github.io/alexandria/) **[Documentation / Documentación](https://ureckchan.github.io/alexandria/)**
|
|
10
|
+
|
|
9
11
|
Alexandria automatically captures your AI prompts and sessions, searches that knowledge **before** spending tokens, and connects everything in an Obsidian-style graph. **100% local**: no database, no API keys, no telemetry, no cost.
|
|
10
12
|
|
|
11
13
|
Works with the most popular agents via MCP: **Claude Code · Cursor · OpenCode · Windsurf · Cline · Codex CLI · Gemini CLI · VS Code (Copilot) · OpenClaw · Hermes Agent**.
|
|
@@ -32,7 +34,7 @@ It lives in the MCP tools themselves — their names and descriptions carry the
|
|
|
32
34
|
| MCP tool | What the agent does with it | Token payoff |
|
|
33
35
|
|---|---|---|
|
|
34
36
|
| `plan_create(title, goal, dod, tasks)` | Writes a plan note with a **Definition of Done** and numbered tasks before touching code | No wandering; open plans are re-injected next session so work is resumed, not repeated |
|
|
35
|
-
| `task_verify(plan, task, passed,
|
|
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 |
|
|
36
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 |
|
|
37
39
|
|
|
38
40
|
Lessons and solutions get a ranking boost in search, so the most valuable knowledge always surfaces first. The protocol is **on by default**; toggle it anytime:
|
|
@@ -61,7 +63,7 @@ Verify:
|
|
|
61
63
|
|
|
62
64
|
```bash
|
|
63
65
|
$ ale --version
|
|
64
|
-
0.5.
|
|
66
|
+
0.5.4
|
|
65
67
|
```
|
|
66
68
|
|
|
67
69
|
## Getting started
|
|
@@ -258,14 +260,14 @@ AI agent session
|
|
|
258
260
|
|---|---|
|
|
259
261
|
| `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 |
|
|
260
262
|
| `ale agents [ids] [--project]` | List agents / register the MCP server |
|
|
261
|
-
| `ale search <query> [-k n] [--expand]` | Hybrid search; `--expand` pulls graph neighbors |
|
|
263
|
+
| `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 |
|
|
262
264
|
| `ale add <title> [-c text] [--file <path>] [-t tags]` | Save a note (inline, from file, or stdin) |
|
|
263
265
|
| `ale plan <file> [--title t]` | Create a Protocol plan from a .md/.txt file (checkboxes → Definition of Done) |
|
|
264
266
|
| `ale graph [--out file.html] [--no-open]` | Live local graph viewer |
|
|
265
267
|
| `ale audit` | Protocol health: plans without DoD, failures without lessons, orphan notes |
|
|
266
268
|
| `ale stats` | Notes, connections, protocol metrics, estimated tokens saved |
|
|
267
269
|
| `ale config <get\|set> <key> [value]` | Configuration (e.g. `protocol` true/false) |
|
|
268
|
-
| `ale skills [-y] [--project]` | Recommends & installs Claude skills
|
|
270
|
+
| `ale skills [-y] [--project]` | Recommends & installs Claude skills — semantic (e5) + keyword detection over your vault. Local source configurable with `ale config set skills.repo <path>`; otherwise installs from skills.sh |
|
|
269
271
|
| `ale reindex [--force]` | Reindex (incremental by default) |
|
|
270
272
|
| `ale consolidate [--days n] [--dry]` | Archive old unused prompts — never deletes |
|
|
271
273
|
| `ale doctor [--project]` | Check & repair: model, hooks, MCP, index |
|
|
@@ -118,7 +118,32 @@ async function hybridSearch(vault, query, k = 6, opts = {}) {
|
|
|
118
118
|
}
|
|
119
119
|
return results;
|
|
120
120
|
}
|
|
121
|
+
function protocolChain(vault, rel, maxNotes = 6) {
|
|
122
|
+
const idx = VaultIndex.load(vault);
|
|
123
|
+
if (!idx.meta.notes[rel]) return [];
|
|
124
|
+
const wanted = /* @__PURE__ */ new Set(["plan", "task", "verification", "lesson", "solution"]);
|
|
125
|
+
const seen = /* @__PURE__ */ new Set([rel]);
|
|
126
|
+
const out = [];
|
|
127
|
+
let frontier = [rel];
|
|
128
|
+
for (let depth = 0; depth < 2 && out.length < maxNotes; depth++) {
|
|
129
|
+
const next = [];
|
|
130
|
+
for (const r of frontier) {
|
|
131
|
+
for (const nb of idx.neighbors(r)) {
|
|
132
|
+
if (seen.has(nb.note.rel)) continue;
|
|
133
|
+
seen.add(nb.note.rel);
|
|
134
|
+
next.push(nb.note.rel);
|
|
135
|
+
if (wanted.has(nb.note.type)) out.push(nb.note);
|
|
136
|
+
if (out.length >= maxNotes) break;
|
|
137
|
+
}
|
|
138
|
+
if (out.length >= maxNotes) break;
|
|
139
|
+
}
|
|
140
|
+
frontier = next;
|
|
141
|
+
}
|
|
142
|
+
const rank = { plan: 0, verification: 1, lesson: 2, solution: 3, task: 4 };
|
|
143
|
+
return out.sort((a, b) => (rank[a.type] ?? 9) - (rank[b.type] ?? 9));
|
|
144
|
+
}
|
|
121
145
|
|
|
122
146
|
export {
|
|
123
|
-
hybridSearch
|
|
147
|
+
hybridSearch,
|
|
148
|
+
protocolChain
|
|
124
149
|
};
|
package/dist/cli.js
CHANGED
|
@@ -15,13 +15,15 @@ import {
|
|
|
15
15
|
unregisterHooks
|
|
16
16
|
} from "./chunk-IQM5S5N4.js";
|
|
17
17
|
import {
|
|
18
|
-
hybridSearch
|
|
19
|
-
|
|
18
|
+
hybridSearch,
|
|
19
|
+
protocolChain
|
|
20
|
+
} from "./chunk-MEL3BE65.js";
|
|
20
21
|
import {
|
|
21
22
|
defaultVaultPath,
|
|
22
23
|
ensureVaultStructure,
|
|
23
24
|
getConfigKey,
|
|
24
25
|
globalConfigPath,
|
|
26
|
+
protocolEnabled,
|
|
25
27
|
resolveVault,
|
|
26
28
|
setConfigKey,
|
|
27
29
|
vaultExists,
|
|
@@ -41,6 +43,8 @@ import {
|
|
|
41
43
|
} from "./chunk-XWR74BQ2.js";
|
|
42
44
|
import {
|
|
43
45
|
MODEL_ID,
|
|
46
|
+
dot,
|
|
47
|
+
embed,
|
|
44
48
|
getEmbedder,
|
|
45
49
|
modelPresent
|
|
46
50
|
} from "./chunk-EDYBSJSS.js";
|
|
@@ -58,27 +62,35 @@ import os from "os";
|
|
|
58
62
|
import path from "path";
|
|
59
63
|
import { execFileSync } from "child_process";
|
|
60
64
|
var RULES = [
|
|
61
|
-
{ skill: "pdf-report-gen", keywords: ["pdf", "reporte pdf", "membrete"] },
|
|
62
|
-
{ skill: "excel-report-gen", keywords: ["excel", "xlsx", "spreadsheet", "hoja de calculo", "hoja de c\xE1lculo"] },
|
|
63
|
-
{ skill: "qr-checkin", keywords: ["qr", "codigo qr", "c\xF3digo qr", "check-in", "checkin"] },
|
|
64
|
-
{ skill: "auth-standard", keywords: ["auth", "login", "jwt", "sesion", "autenticacion", "autenticaci\xF3n"] },
|
|
65
|
-
{ skill: "prisma-workflow", keywords: ["prisma", "migracion", "migraci\xF3n", "orm"] },
|
|
66
|
-
{ skill: "flutter-offline-scaffold", keywords: ["flutter", "dart", "riverpod", "drift"] },
|
|
67
|
-
{ skill: "mapbox-geo", keywords: ["mapbox", "geolocalizacion", "geolocalizaci\xF3n", "geocode", "leaflet"] },
|
|
68
|
-
{ skill: "spanish-form-validation", keywords: ["curp", "rfc", "zod", "validacion", "validaci\xF3n", "formulario"] },
|
|
69
|
-
{ skill: "testing-ci-setup", keywords: ["vitest", "playwright", "test", "ci", "github actions"] },
|
|
70
|
-
{ skill: "tiptap-rich-text", keywords: ["tiptap", "editor de texto", "wysiwyg", "rich text"] },
|
|
71
|
-
{ skill: "signature-upload-optimizer", keywords: ["firma", "signature", "compress", "upload", "subir foto"] },
|
|
72
|
-
{ skill: "security-headers-baseline", keywords: ["csp", "security headers", "hsts", "seguridad web"] },
|
|
73
|
-
{ skill: "server-state-standard", keywords: ["react-query", "tanstack", "zustand", "estado"] },
|
|
74
|
-
{ skill: "nextjs-folder-structure", keywords: ["next.js", "nextjs", "app router"] }
|
|
65
|
+
{ skill: "pdf-report-gen", desc: "generar documentos y reportes PDF con membrete", keywords: ["pdf", "reporte pdf", "membrete"] },
|
|
66
|
+
{ skill: "excel-report-gen", desc: "exportar e importar hojas de c\xE1lculo Excel xlsx", keywords: ["excel", "xlsx", "spreadsheet", "hoja de calculo", "hoja de c\xE1lculo"] },
|
|
67
|
+
{ skill: "qr-checkin", desc: "generar y escanear c\xF3digos QR para check-in y tickets", keywords: ["qr", "codigo qr", "c\xF3digo qr", "check-in", "checkin"] },
|
|
68
|
+
{ skill: "auth-standard", desc: "autenticaci\xF3n con login, JWT y sesiones seguras", keywords: ["auth", "login", "jwt", "sesion", "autenticacion", "autenticaci\xF3n"] },
|
|
69
|
+
{ skill: "prisma-workflow", desc: "ORM Prisma, modelos, migraciones y seed de base de datos", keywords: ["prisma", "migracion", "migraci\xF3n", "orm"] },
|
|
70
|
+
{ skill: "flutter-offline-scaffold", desc: "app Flutter offline-first con riverpod y base de datos local", keywords: ["flutter", "dart", "riverpod", "drift"] },
|
|
71
|
+
{ skill: "mapbox-geo", desc: "mapas, marcadores y geolocalizaci\xF3n con Mapbox", keywords: ["mapbox", "geolocalizacion", "geolocalizaci\xF3n", "geocode", "leaflet"] },
|
|
72
|
+
{ skill: "spanish-form-validation", desc: "validaci\xF3n de formularios con Zod, CURP, RFC y tel\xE9fono mexicano", keywords: ["curp", "rfc", "zod", "validacion", "validaci\xF3n", "formulario"] },
|
|
73
|
+
{ skill: "testing-ci-setup", desc: "pruebas automatizadas con vitest, Playwright y CI en GitHub Actions", keywords: ["vitest", "playwright", "test", "ci", "github actions"] },
|
|
74
|
+
{ skill: "tiptap-rich-text", desc: "editor de texto enriquecido WYSIWYG con tiptap y plantillas", keywords: ["tiptap", "editor de texto", "wysiwyg", "rich text"] },
|
|
75
|
+
{ skill: "signature-upload-optimizer", desc: "captura de firma en canvas y compresi\xF3n de im\xE1genes antes de subir", keywords: ["firma", "signature", "compress", "upload", "subir foto"] },
|
|
76
|
+
{ skill: "security-headers-baseline", desc: "cabeceras de seguridad web CSP, HSTS y X-Frame-Options", keywords: ["csp", "security headers", "hsts", "seguridad web"] },
|
|
77
|
+
{ skill: "server-state-standard", desc: "estado del servidor con react-query TanStack y zustand para UI", keywords: ["react-query", "tanstack", "zustand", "estado"] },
|
|
78
|
+
{ skill: "nextjs-folder-structure", desc: "estructura de carpetas y organizaci\xF3n de un proyecto Next.js App Router", keywords: ["next.js", "nextjs", "app router"] }
|
|
75
79
|
];
|
|
76
80
|
var MIN_MENTIONS = 3;
|
|
81
|
+
var SEM_Z_STRONG = 1.5;
|
|
82
|
+
var SEM_Z_WEAK = 1;
|
|
77
83
|
function localSkillsRepo() {
|
|
78
|
-
|
|
84
|
+
const configured = getConfigKey("skills.repo");
|
|
85
|
+
if (typeof configured === "string" && configured.trim()) {
|
|
86
|
+
return configured.trim().replace(/^~(?=$|[/\\])/, os.homedir());
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
79
89
|
}
|
|
80
|
-
function recommendSkills(vault, installedDirs) {
|
|
90
|
+
async function recommendSkills(vault, installedDirs) {
|
|
81
91
|
const idx = VaultIndex.load(vault);
|
|
92
|
+
await idx.refresh().catch(() => {
|
|
93
|
+
});
|
|
82
94
|
const corpus = (idx.meta.chunks.map((c) => c.text).join("\n") + "\n" + Object.values(idx.meta.notes).map((n) => `${n.title} ${n.tags.join(" ")}`).join("\n")).toLowerCase();
|
|
83
95
|
const installed = /* @__PURE__ */ new Set();
|
|
84
96
|
for (const dir of installedDirs) {
|
|
@@ -87,9 +99,30 @@ function recommendSkills(vault, installedDirs) {
|
|
|
87
99
|
} catch {
|
|
88
100
|
}
|
|
89
101
|
}
|
|
102
|
+
let semZByRule = null;
|
|
103
|
+
if (idx.emb && idx.meta.chunks.length > 0 && modelPresent()) {
|
|
104
|
+
try {
|
|
105
|
+
const profiles = RULES.map((r) => `${r.skill.replace(/-/g, " ")}. ${r.desc} ${r.keywords.join(" ")}`);
|
|
106
|
+
const vecs = await embed(profiles, "query");
|
|
107
|
+
const best = vecs.map((v) => {
|
|
108
|
+
let m = 0;
|
|
109
|
+
for (let i = 0; i < idx.meta.chunks.length; i++) {
|
|
110
|
+
const s = dot(v, idx.row(i));
|
|
111
|
+
if (s > m) m = s;
|
|
112
|
+
}
|
|
113
|
+
return m;
|
|
114
|
+
});
|
|
115
|
+
const mean = best.reduce((a, b) => a + b, 0) / best.length;
|
|
116
|
+
const std = Math.sqrt(best.reduce((a, b) => a + (b - mean) ** 2, 0) / best.length);
|
|
117
|
+
semZByRule = std > 1e-6 ? best.map((b) => (b - mean) / std) : null;
|
|
118
|
+
} catch {
|
|
119
|
+
semZByRule = null;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const repo = localSkillsRepo();
|
|
90
123
|
const out = [];
|
|
91
|
-
|
|
92
|
-
if (installed.has(rule.skill))
|
|
124
|
+
RULES.forEach((rule, ri) => {
|
|
125
|
+
if (installed.has(rule.skill)) return;
|
|
93
126
|
let mentions = 0;
|
|
94
127
|
const found = [];
|
|
95
128
|
for (const kw of rule.keywords) {
|
|
@@ -98,26 +131,36 @@ function recommendSkills(vault, installedDirs) {
|
|
|
98
131
|
if (count > 0) found.push(kw);
|
|
99
132
|
mentions += count;
|
|
100
133
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
134
|
+
const semZ = semZByRule ? semZByRule[ri] : 0;
|
|
135
|
+
const semStrong = semZ >= SEM_Z_WEAK;
|
|
136
|
+
const qualifies = mentions >= MIN_MENTIONS || mentions >= 1 && semZ >= SEM_Z_WEAK || semZ >= SEM_Z_STRONG;
|
|
137
|
+
if (!qualifies) return;
|
|
138
|
+
const local = repo ? fs.existsSync(path.join(repo, rule.skill)) : false;
|
|
139
|
+
const parts = [];
|
|
140
|
+
if (found.length) parts.push(`${mentions} menciones de ${found.slice(0, 3).join(", ")}`);
|
|
141
|
+
if (semStrong) parts.push(`afinidad sem\xE1ntica alta (z=${semZ.toFixed(1)})`);
|
|
142
|
+
out.push({
|
|
143
|
+
skill: rule.skill,
|
|
144
|
+
mentions,
|
|
145
|
+
// el z-score reordena: una skill que sobresale semánticamente sube aunque
|
|
146
|
+
// tenga pocas menciones literales
|
|
147
|
+
score: mentions + (semStrong ? Math.min(semZ, 4) * 1.5 : 0),
|
|
148
|
+
reason: parts.length ? `detect\xE9 ${parts.join(" + ")} en la b\xF3veda` : `afinidad sem\xE1ntica (z=${semZ.toFixed(1)})`,
|
|
149
|
+
source: local ? "local" : "skills.sh"
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
return out.sort((a, b) => b.score - a.score);
|
|
112
153
|
}
|
|
113
154
|
function installSkill(rec, targetDir) {
|
|
114
155
|
fs.mkdirSync(targetDir, { recursive: true });
|
|
115
156
|
const dest = path.join(targetDir, rec.skill);
|
|
116
157
|
if (fs.existsSync(dest)) return { ok: true, detail: "ya instalada" };
|
|
117
158
|
if (rec.source === "local") {
|
|
159
|
+
const repo = localSkillsRepo();
|
|
160
|
+
if (!repo) return { ok: false, detail: "repo local no configurado (ale config set skills.repo <ruta>)" };
|
|
118
161
|
try {
|
|
119
|
-
fs.cpSync(path.join(
|
|
120
|
-
return { ok: true, detail: `copiada desde ${
|
|
162
|
+
fs.cpSync(path.join(repo, rec.skill), dest, { recursive: true });
|
|
163
|
+
return { ok: true, detail: `copiada desde ${repo}` };
|
|
121
164
|
} catch (e) {
|
|
122
165
|
return { ok: false, detail: `error copiando: ${e.message}` };
|
|
123
166
|
}
|
|
@@ -742,7 +785,7 @@ program.command("plan").description("Crear un plan del Protocolo desde un archiv
|
|
|
742
785
|
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)'}`));
|
|
743
786
|
console.log(pc.dim(" El agente lo ver\xE1 como plan abierto al iniciar sesi\xF3n y lo retomar\xE1 con task_verify."));
|
|
744
787
|
});
|
|
745
|
-
program.command("audit").description("Auditor\xEDa del Protocolo: planes sin DoD, planes abiertos, fallos sin lecci\xF3n, notas sueltas").action(async () => {
|
|
788
|
+
program.command("audit").description("Auditor\xEDa del Protocolo: planes sin DoD, planes abiertos, fallos sin lecci\xF3n, verificaciones auto-reportadas, notas sueltas").action(async () => {
|
|
746
789
|
const { vault, idx } = await ensureReady();
|
|
747
790
|
const notes = Object.values(idx.meta.notes).filter((n) => !n.rel.split("/").includes("archive"));
|
|
748
791
|
const plans = notes.filter((n) => n.type === "plan");
|
|
@@ -758,19 +801,25 @@ program.command("audit").description("Auditor\xEDa del Protocolo: planes sin DoD
|
|
|
758
801
|
console.log(pc.yellow(` \u26A0 Planes sin Definition of Done: ${noDod.length}`));
|
|
759
802
|
for (const p of noDod.slice(0, 5)) console.log(pc.dim(` - ${p.title}`));
|
|
760
803
|
}
|
|
761
|
-
const
|
|
804
|
+
const verifs = notes.filter((n) => n.type === "verification");
|
|
805
|
+
const fails = verifs.filter((n) => n.status === "failed");
|
|
762
806
|
const lessons = notes.filter((n) => n.type === "lesson");
|
|
763
|
-
console.log(` Verificaciones: ${
|
|
807
|
+
console.log(` Verificaciones: ${verifs.length} (${pc.red(`${fails.length} fallos`)}) \xB7 Lecciones: ${pc.green(String(lessons.length))}`);
|
|
764
808
|
if (fails.length > lessons.length) {
|
|
765
809
|
console.log(pc.yellow(` \u26A0 Hay m\xE1s fallos (${fails.length}) que lecciones (${lessons.length}) \u2014 fallos resueltos sin destilar aprendizaje.`));
|
|
766
810
|
}
|
|
811
|
+
const selfReported = verifs.filter((n) => n.tags.includes("auto-reportado"));
|
|
812
|
+
if (selfReported.length > 0) {
|
|
813
|
+
console.log(pc.yellow(` \u26A0 Verificaciones auto-reportadas (sin ejecutar \u2014 no comprobadas): ${selfReported.length} \u2014 re-verifica con task_verify + verify_command.`));
|
|
814
|
+
for (const v of selfReported.slice(0, 5)) console.log(pc.dim(` - ${v.title}`));
|
|
815
|
+
}
|
|
767
816
|
const loose = notes.filter((n) => n.type !== "prompt" && n.type !== "session" && !linked.has(n.rel));
|
|
768
817
|
if (loose.length > 0) {
|
|
769
818
|
console.log(pc.yellow(` \u26A0 Notas sin conexiones (invisibles para vault_related): ${loose.length}`));
|
|
770
819
|
for (const n of loose.slice(0, 5)) console.log(pc.dim(` - ${n.title} \u2192 con\xE9ctala con vault_link o [[wikilinks]]`));
|
|
771
820
|
}
|
|
772
|
-
if (noDod.length === 0 && loose.length === 0 && fails.length <= lessons.length) {
|
|
773
|
-
console.log(pc.green("\n \u2713 B\xF3veda sana: planes con DoD, conocimiento conectado, fallos con lecci\xF3n."));
|
|
821
|
+
if (noDod.length === 0 && loose.length === 0 && fails.length <= lessons.length && selfReported.length === 0) {
|
|
822
|
+
console.log(pc.green("\n \u2713 B\xF3veda sana: planes con DoD, verificaciones reales, conocimiento conectado, fallos con lecci\xF3n."));
|
|
774
823
|
}
|
|
775
824
|
console.log();
|
|
776
825
|
});
|
|
@@ -884,6 +933,23 @@ ${pc.bold(pc.cyan(r.note.title))} ${pc.dim(`(${r.note.rel}, ${r.note.type})`)}${
|
|
|
884
933
|
console.log(pc.dim(" " + e.replace(/\n+/g, " ").slice(0, 220)));
|
|
885
934
|
}
|
|
886
935
|
}
|
|
936
|
+
if (protocolEnabled()) {
|
|
937
|
+
const chain = protocolChain(vault, results[0].note.rel);
|
|
938
|
+
if (chain.length > 0) {
|
|
939
|
+
const label = {
|
|
940
|
+
plan: "Plan",
|
|
941
|
+
verification: "Verificaci\xF3n",
|
|
942
|
+
lesson: "Lecci\xF3n",
|
|
943
|
+
solution: "Soluci\xF3n",
|
|
944
|
+
task: "Tarea"
|
|
945
|
+
};
|
|
946
|
+
console.log(pc.bold("\n \u{1F517} Cadena del Protocolo (hilo conectado al mejor resultado):"));
|
|
947
|
+
for (const n of chain) {
|
|
948
|
+
const mark = n.type === "verification" ? n.status === "failed" ? pc.red(" \u2717") : n.status === "completed" ? pc.green(" \u2713") : "" : "";
|
|
949
|
+
console.log(` ${pc.dim((label[n.type] ?? n.type) + ":")} ${n.title}${mark} ${pc.dim(`(${n.rel})`)}`);
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
}
|
|
887
953
|
console.log();
|
|
888
954
|
});
|
|
889
955
|
program.command("reindex").description("Reindexar la b\xF3veda (incremental; --force para todo)").option("--force", "reindexar todo desde cero").action(async (opts) => {
|
|
@@ -943,7 +1009,7 @@ async function runSkills(opts) {
|
|
|
943
1009
|
const { vault } = await ensureReady();
|
|
944
1010
|
const cwd = process.cwd();
|
|
945
1011
|
const targetDir = opts.project ? path4.join(cwd, ".claude", "skills") : path4.join(process.env.HOME ?? process.env.USERPROFILE ?? cwd, ".claude", "skills");
|
|
946
|
-
const recs = recommendSkills(vault, [targetDir]);
|
|
1012
|
+
const recs = await recommendSkills(vault, [targetDir]);
|
|
947
1013
|
if (recs.length === 0) {
|
|
948
1014
|
console.log(pc.dim("Sin recomendaciones nuevas: la b\xF3veda a\xFAn no tiene suficientes patrones (o ya est\xE1 todo instalado)."));
|
|
949
1015
|
return;
|
|
@@ -954,6 +1020,12 @@ async function runSkills(opts) {
|
|
|
954
1020
|
for (const r of recs) {
|
|
955
1021
|
console.log(` ${pc.cyan(r.skill)} ${pc.dim(`[${r.source}]`)} \u2014 ${r.reason}`);
|
|
956
1022
|
}
|
|
1023
|
+
const skillsRepo = localSkillsRepo();
|
|
1024
|
+
console.log(pc.dim(
|
|
1025
|
+
skillsRepo ? `
|
|
1026
|
+
Repo local de skills: ${skillsRepo} (c\xE1mbialo con: ale config set skills.repo <ruta>)` : `
|
|
1027
|
+
Origen: registro p\xFAblico skills.sh. \xBFRepo local propio? ale config set skills.repo <ruta>`
|
|
1028
|
+
));
|
|
957
1029
|
let selected = recs;
|
|
958
1030
|
if (!opts.yes) {
|
|
959
1031
|
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
package/dist/hooks/on-prompt.js
CHANGED
package/dist/mcp/server.js
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
} from "../chunk-IQM5S5N4.js";
|
|
5
5
|
import {
|
|
6
6
|
hybridSearch
|
|
7
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-MEL3BE65.js";
|
|
8
8
|
import {
|
|
9
9
|
ensureVaultStructure,
|
|
10
10
|
resolveVault
|
|
@@ -23,12 +23,14 @@ import "../chunk-EDYBSJSS.js";
|
|
|
23
23
|
// src/mcp/server.ts
|
|
24
24
|
import path from "path";
|
|
25
25
|
import fs from "fs";
|
|
26
|
+
import { execSync } from "child_process";
|
|
26
27
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
27
28
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
28
29
|
import { z } from "zod";
|
|
29
30
|
var vault = resolveVault({ cwd: process.cwd() });
|
|
30
31
|
var server = new McpServer({ name: "alexandria", version: pkgVersion() });
|
|
31
32
|
var text = (t) => ({ content: [{ type: "text", text: t }] });
|
|
33
|
+
var tail = (s, n) => s.length > n ? "\u2026\n" + s.slice(-n) : s;
|
|
32
34
|
function findMap(idx) {
|
|
33
35
|
return Object.values(idx.meta.notes).find((n) => n.type === "map" || n.title.startsWith("Mapa - "));
|
|
34
36
|
}
|
|
@@ -167,55 +169,97 @@ ${tasks.map((t, i) => `${i + 1}. ${t}`).join("\n")}`,
|
|
|
167
169
|
);
|
|
168
170
|
server.tool(
|
|
169
171
|
"task_verify",
|
|
170
|
-
|
|
172
|
+
'PROTOCOLO paso 2: verifica una tarea con EVIDENCIA REAL, no con tu palabra. Pasa verify_command (ej. "npm test", "npm run build", "curl -sf localhost:3000") y Alexandria lo EJECUTA \u2014 el veredicto sale del exit code real. Si no puedes correr un comando, pasa evidence textual, pero se marca como auto-reportado (m\xE1s d\xE9bil). Si falla, busca lecciones previas antes de improvisar.',
|
|
171
173
|
{
|
|
172
174
|
plan: z.string().describe('T\xEDtulo del plan al que pertenece (ej. "Plan - Login con Google")'),
|
|
173
175
|
task: z.string().describe("Qu\xE9 tarea se verific\xF3"),
|
|
174
|
-
passed: z.boolean().describe("
|
|
175
|
-
|
|
176
|
+
passed: z.boolean().describe("Lo que T\xDA crees que pas\xF3 (se compara contra el resultado real del comando)"),
|
|
177
|
+
verify_command: z.string().optional().describe('Comando a EJECUTAR para verificar de verdad; exit 0 = pas\xF3. Ej. "npm test", "npm run build". Preferido sobre evidence.'),
|
|
178
|
+
evidence: z.string().optional().describe("Solo si NO hay comando: evidencia textual (queda marcada como auto-reportada, sin verificar)."),
|
|
176
179
|
completes_plan: z.boolean().optional().describe("true si esta era la \xFAltima tarea y el plan queda completado")
|
|
177
180
|
},
|
|
178
|
-
async ({ plan, task, passed, evidence, completes_plan }) => {
|
|
181
|
+
async ({ plan, task, passed, verify_command, evidence, completes_plan }) => {
|
|
179
182
|
ensureVaultStructure(vault);
|
|
180
183
|
const idx = VaultIndex.load(vault);
|
|
181
184
|
const planNote = findByTitle(idx, plan);
|
|
185
|
+
let realPassed = passed;
|
|
186
|
+
let realEvidence;
|
|
187
|
+
let verified = false;
|
|
188
|
+
let discrepancy = "";
|
|
189
|
+
if (verify_command && verify_command.trim()) {
|
|
190
|
+
verified = true;
|
|
191
|
+
try {
|
|
192
|
+
const out = execSync(verify_command, {
|
|
193
|
+
cwd: process.cwd(),
|
|
194
|
+
timeout: 18e4,
|
|
195
|
+
encoding: "utf8",
|
|
196
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
197
|
+
maxBuffer: 10 * 1024 * 1024
|
|
198
|
+
});
|
|
199
|
+
realPassed = true;
|
|
200
|
+
realEvidence = `$ ${verify_command}
|
|
201
|
+
(exit 0)
|
|
202
|
+
${tail(out, 1500)}`;
|
|
203
|
+
} catch (e) {
|
|
204
|
+
const err = e;
|
|
205
|
+
realPassed = false;
|
|
206
|
+
const output = ((err.stdout ?? "") + "\n" + (err.stderr ?? "")).trim() || err.message;
|
|
207
|
+
realEvidence = `$ ${verify_command}
|
|
208
|
+
(exit ${err.status ?? "\u22600"})
|
|
209
|
+
${tail(output, 1500)}`;
|
|
210
|
+
}
|
|
211
|
+
if (passed !== realPassed) {
|
|
212
|
+
discrepancy = `
|
|
213
|
+
|
|
214
|
+
\u26A0 DISCREPANCIA: afirmaste passed=${passed}, pero el comando dio ${realPassed ? "\xC9XITO" : "FALLO"}. Alexandria registr\xF3 el resultado REAL (${realPassed}). Revisa lo que hiciste \u2014 no des por hecho lo que no corriste.`;
|
|
215
|
+
}
|
|
216
|
+
} else {
|
|
217
|
+
realEvidence = `(auto-reportado, SIN comando de verificaci\xF3n \u2014 no ejecutado)
|
|
218
|
+
${tail(evidence ?? "sin evidencia", 1500)}`;
|
|
219
|
+
}
|
|
182
220
|
const file = createNote(vault.managed, {
|
|
183
|
-
title: `${
|
|
221
|
+
title: `${realPassed ? "OK" : "FALLO"} - ${task.slice(0, 60)}`,
|
|
184
222
|
type: "verification",
|
|
185
|
-
status:
|
|
186
|
-
tags: ["verificacion"],
|
|
223
|
+
status: realPassed ? "completed" : "failed",
|
|
224
|
+
tags: verified ? ["verificacion", "verificado"] : ["verificacion", "auto-reportado"],
|
|
187
225
|
dir: "notes",
|
|
188
226
|
content: `**Tarea:** ${task}
|
|
189
227
|
|
|
190
|
-
**Veredicto:** ${
|
|
228
|
+
**Veredicto:** ${realPassed ? "\u2705 pas\xF3" : "\u274C fall\xF3"} ${verified ? "(verificado ejecutando el comando)" : "(\u26A0 auto-reportado, sin ejecutar)"}
|
|
191
229
|
|
|
192
230
|
**Evidencia:**
|
|
193
231
|
\`\`\`
|
|
194
|
-
${
|
|
232
|
+
${realEvidence}
|
|
195
233
|
\`\`\`
|
|
196
234
|
|
|
197
235
|
${planNote ? `Plan: [[${planNote.title}]]` : ""}`
|
|
198
236
|
});
|
|
199
237
|
if (completes_plan && planNote) {
|
|
200
238
|
try {
|
|
201
|
-
setNoteStatus(path.join(vault.root, planNote.rel),
|
|
239
|
+
setNoteStatus(path.join(vault.root, planNote.rel), realPassed ? "completed" : "failed");
|
|
202
240
|
} catch {
|
|
203
241
|
}
|
|
204
242
|
}
|
|
205
243
|
await VaultIndex.load(vault).refresh().catch(() => {
|
|
206
244
|
});
|
|
207
|
-
if (!
|
|
208
|
-
const lessons = await hybridSearch(vault, `${task} ${
|
|
245
|
+
if (!realPassed) {
|
|
246
|
+
const lessons = await hybridSearch(vault, `${task} ${realEvidence.slice(0, 200)}`, 3);
|
|
209
247
|
const useful = lessons.filter((l) => l.note.type === "lesson" || l.note.type === "solution");
|
|
248
|
+
const head = `Fallo ${verified ? "CONFIRMADO por el comando" : "registrado (auto-reportado)"} (${path.relative(vault.root, file)}).${discrepancy}`;
|
|
210
249
|
if (useful.length > 0) {
|
|
211
250
|
return text(
|
|
212
|
-
|
|
251
|
+
`${head}
|
|
252
|
+
LECCIONES PREVIAS que podr\xEDan aplicar \u2014 \xFAsalas antes de improvisar:
|
|
213
253
|
` + useful.map((l) => `- \xAB${l.note.title}\xBB: ${l.excerpts[0]?.slice(0, 300) ?? ""}`).join("\n")
|
|
214
254
|
);
|
|
215
255
|
}
|
|
216
|
-
return text(
|
|
256
|
+
return text(`${head}
|
|
257
|
+
Sin lecciones previas \u2014 cuando lo resuelvas, gu\xE1rdala con lesson_extract.`);
|
|
217
258
|
}
|
|
218
|
-
|
|
259
|
+
const verdictHint = verified ? "Verificaci\xF3n REAL guardada (comando ejecutado, exit 0)." : "\u26A0 Verificaci\xF3n auto-reportada guardada \u2014 sin comando, no se comprob\xF3 de verdad. Pasa verify_command la pr\xF3xima.";
|
|
260
|
+
return text(
|
|
261
|
+
`${verdictHint}${completes_plan ? " Plan marcado como completado." : ""}${discrepancy} ${completes_plan ? "Cierra con lesson_extract si hubo aprendizaje." : "Siguiente tarea."}`
|
|
262
|
+
);
|
|
219
263
|
}
|
|
220
264
|
);
|
|
221
265
|
server.tool(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ureck/alexandria",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
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",
|