@ureck/alexandria 1.6.2 → 1.6.3
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 +3 -1
- package/dist/cli.js +82 -12
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -112,7 +112,7 @@ Verify:
|
|
|
112
112
|
|
|
113
113
|
```bash
|
|
114
114
|
$ ale --version
|
|
115
|
-
1.6.
|
|
115
|
+
1.6.3
|
|
116
116
|
```
|
|
117
117
|
|
|
118
118
|
One command installs everything (embedding model ~130MB downloaded once, hooks, MCP registration, index):
|
|
@@ -395,6 +395,8 @@ ale uninstall # removes hooks + MCP from every agent; your notes
|
|
|
395
395
|
|
|
396
396
|
Every command self-repairs before running: missing model → downloads it; stale index → updates it.
|
|
397
397
|
|
|
398
|
+
**Background reindex is single-flight.** If the index loses its vectors, the session-close hook rebuilds it in a detached, low-priority (`nice 10`) process — at most one at a time, guarded by `<vault>/.vault/reindex.lock` (holder pid; a dead or 3h-old holder is replaced). `ale reindex` and `ale doctor` respect the same lock, so two manual reindexes never run together. Notes indexed without the model (e.g. at session start) keep the existing vectors and are embedded incrementally later — no full rebuild. A full reindex of ~5,300 chunks takes ~6 min (e5-small q8, length-sorted batches).
|
|
399
|
+
|
|
398
400
|
</details>
|
|
399
401
|
|
|
400
402
|
<details>
|
package/dist/cli.js
CHANGED
|
@@ -860,8 +860,83 @@ function run(script, payload, timeoutMs) {
|
|
|
860
860
|
});
|
|
861
861
|
}
|
|
862
862
|
|
|
863
|
-
//
|
|
864
|
-
|
|
863
|
+
// Pliega una salida grande de shell; devuelve '' si no conviene o falla.
|
|
864
|
+
function fold(output, command, exit, cwd) {
|
|
865
|
+
if (typeof output !== 'string' || output.length <= 2048) return Promise.resolve('');
|
|
866
|
+
return new Promise((resolve) => {
|
|
867
|
+
const child = execFile('node', [CLI, 'run', '--stdin', '--command', command, '--exit', String(exit)], { cwd, timeout: 8000, windowsHide: true, maxBuffer: 1 << 20 }, (_e, stdout) => {
|
|
868
|
+
const folded = typeof stdout === 'string' ? stdout.trim() : '';
|
|
869
|
+
resolve(folded && folded.length < output.length ? folded : '');
|
|
870
|
+
});
|
|
871
|
+
child.stdin?.end(output);
|
|
872
|
+
});
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
// \u2500\u2500 OpenCode 2 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
876
|
+
async function setup(ctx) {
|
|
877
|
+
const cwd = ctx.location.directory;
|
|
878
|
+
const digest = new Map(); // sessionID \u2192 contexto de inicio
|
|
879
|
+
const turn = new Map(); // sessionID \u2192 contexto del prompt actual
|
|
880
|
+
const lastPrompt = new Map();
|
|
881
|
+
|
|
882
|
+
// V2 no tiene hook de inicio de sesi\xF3n: el digest se pide en el primer prompt.
|
|
883
|
+
await ctx.session.hook('prompt', async (event) => {
|
|
884
|
+
try {
|
|
885
|
+
const id = event.sessionID;
|
|
886
|
+
const prompt = String(event.prompt?.text ?? '').trim();
|
|
887
|
+
if (!prompt) return;
|
|
888
|
+
lastPrompt.set(id, prompt);
|
|
889
|
+
if (!digest.has(id)) digest.set(id, await run(SCRIPTS.session, { session_id: id, cwd, source: 'startup' }, 15000));
|
|
890
|
+
turn.set(id, await run(SCRIPTS.prompt, { session_id: id, cwd, prompt }, 8000));
|
|
891
|
+
} catch {
|
|
892
|
+
/* Alexandria jam\xE1s rompe la sesi\xF3n */
|
|
893
|
+
}
|
|
894
|
+
});
|
|
895
|
+
|
|
896
|
+
await ctx.session.hook('context', (event) => {
|
|
897
|
+
for (const text of [digest.get(event.sessionID), turn.get(event.sessionID)]) {
|
|
898
|
+
if (text) event.system.push({ type: 'text', text });
|
|
899
|
+
}
|
|
900
|
+
});
|
|
901
|
+
|
|
902
|
+
await ctx.tool.hook('execute.after', async (event) => {
|
|
903
|
+
try {
|
|
904
|
+
if (event.tool !== 'shell' && event.tool !== 'bash') return;
|
|
905
|
+
const result = event.result;
|
|
906
|
+
const output = result?.output?.output;
|
|
907
|
+
const exit = Number(result?.output?.exitCode ?? result?.metadata?.exit ?? 0) || 0;
|
|
908
|
+
const folded = await fold(output, String(event.input?.command ?? ''), exit, cwd);
|
|
909
|
+
if (!folded) return;
|
|
910
|
+
result.output.output = folded;
|
|
911
|
+
for (const part of result.content ?? []) {
|
|
912
|
+
if (part?.type === 'text' && part.text === output) part.text = folded;
|
|
913
|
+
}
|
|
914
|
+
} catch {
|
|
915
|
+
/* sin plegado: la salida original sigue intacta */
|
|
916
|
+
}
|
|
917
|
+
});
|
|
918
|
+
|
|
919
|
+
const abort = new AbortController();
|
|
920
|
+
void (async () => {
|
|
921
|
+
for await (const event of ctx.event.subscribe({ signal: abort.signal })) {
|
|
922
|
+
const sessionID = event.data?.sessionID;
|
|
923
|
+
// solo las sesiones que pasaron por esta instancia (los eventos son globales)
|
|
924
|
+
if (event.type !== 'session.execution.succeeded' || !lastPrompt.has(sessionID)) continue;
|
|
925
|
+
try {
|
|
926
|
+
const messages = await ctx.session.context({ sessionID });
|
|
927
|
+
const last = [...messages].reverse().find((m) => m.type === 'assistant' && m.content?.some((c) => c.type === 'text' && c.text));
|
|
928
|
+
const answer = last?.content.filter((c) => c.type === 'text').map((c) => c.text).join('\\n').trim();
|
|
929
|
+
if (answer) await run(SCRIPTS.stop, { session_id: sessionID, cwd, prompt: lastPrompt.get(sessionID), last_assistant_message: answer }, 25000);
|
|
930
|
+
} catch {
|
|
931
|
+
/* sin captura este turno */
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
})().catch(() => {});
|
|
935
|
+
return () => abort.abort();
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
// \u2500\u2500 OpenCode 1.x \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
939
|
+
const server = async ({ directory }) => {
|
|
865
940
|
const digest = new Map(); // sessionID \u2192 contexto de inicio
|
|
866
941
|
const turn = new Map(); // sessionID \u2192 contexto del prompt actual
|
|
867
942
|
const lastPrompt = new Map();
|
|
@@ -906,16 +981,10 @@ const AlexandriaPlugin = async ({ directory }) => {
|
|
|
906
981
|
// Aqu\xED s\xED cubre comandos que fallan: OpenCode deja reescribir output.output.
|
|
907
982
|
'tool.execute.after': async (input, output) => {
|
|
908
983
|
try {
|
|
909
|
-
if (input?.tool !== 'bash'
|
|
910
|
-
const command = String(input.args?.command ?? '');
|
|
984
|
+
if (input?.tool !== 'bash') return;
|
|
911
985
|
const exit = Number(output.metadata?.exit ?? output.metadata?.exitCode ?? 0) || 0;
|
|
912
|
-
const folded = await
|
|
913
|
-
|
|
914
|
-
resolve(typeof stdout === 'string' ? stdout.trim() : '')
|
|
915
|
-
);
|
|
916
|
-
child.stdin?.end(output.output);
|
|
917
|
-
});
|
|
918
|
-
if (folded && folded.length < output.output.length) output.output = folded;
|
|
986
|
+
const folded = await fold(output.output, String(input.args?.command ?? ''), exit, directory);
|
|
987
|
+
if (folded) output.output = folded;
|
|
919
988
|
} catch {
|
|
920
989
|
/* sin plegado: la salida original sigue intacta */
|
|
921
990
|
}
|
|
@@ -930,7 +999,8 @@ const AlexandriaPlugin = async ({ directory }) => {
|
|
|
930
999
|
};
|
|
931
1000
|
};
|
|
932
1001
|
|
|
933
|
-
export default
|
|
1002
|
+
// Solo export default: OpenCode registra CADA funci\xF3n exportada como plugin.
|
|
1003
|
+
export default { id: 'alexandria', setup, server };
|
|
934
1004
|
`;
|
|
935
1005
|
}
|
|
936
1006
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ureck/alexandria",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.3",
|
|
4
4
|
"description": "Alexandria — bóveda de conocimiento local para agentes de IA (Claude Code, Codex, Gemini CLI, Cursor, OpenCode y más): captura automática por hooks, búsqueda semántica offline y grafo estilo Obsidian. Ahorra tokens inyectando solo el contexto relevante.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -47,13 +47,13 @@
|
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@huggingface/transformers": "^4.3.2",
|
|
49
49
|
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
50
|
-
"commander": "^15.
|
|
50
|
+
"commander": "^15.1.0",
|
|
51
51
|
"gray-matter": "^4.0.3",
|
|
52
52
|
"jszip": "^3.10.2",
|
|
53
53
|
"mammoth": "^1.13.0",
|
|
54
54
|
"minisearch": "^7.1.2",
|
|
55
55
|
"picocolors": "^1.1.1",
|
|
56
|
-
"turndown": "^7.2.
|
|
56
|
+
"turndown": "^7.2.5",
|
|
57
57
|
"unpdf": "^1.9.1",
|
|
58
58
|
"zod": "^4.6.7"
|
|
59
59
|
},
|
|
@@ -62,12 +62,12 @@
|
|
|
62
62
|
"uuid": "^11.1.1"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@types/node": "^22.20.
|
|
65
|
+
"@types/node": "^22.20.7",
|
|
66
66
|
"@types/turndown": "^5.0.6",
|
|
67
67
|
"exceljs": "^4.4.0",
|
|
68
68
|
"tsup": "^9.0.0",
|
|
69
69
|
"typescript": "^5.7.3",
|
|
70
|
-
"vitest": "^5.
|
|
70
|
+
"vitest": "^5.1.2"
|
|
71
71
|
},
|
|
72
72
|
"author": "Ureck <urielgomezbecerril@gmail.com>",
|
|
73
73
|
"publishConfig": {
|