@marcozvd/basics-core 1.2.0 → 1.4.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 +3 -2
- package/dist/api.d.ts +75 -2
- package/dist/api.d.ts.map +1 -1
- package/dist/embeddings.d.ts +17 -0
- package/dist/embeddings.d.ts.map +1 -1
- package/dist/embeddings.js +18 -1
- package/dist/embeddings.js.map +1 -1
- package/dist/eval.d.ts +3 -0
- package/dist/eval.d.ts.map +1 -1
- package/dist/eval.js +1 -0
- package/dist/eval.js.map +1 -1
- package/dist/query.d.ts +25 -2
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +216 -40
- package/dist/query.js.map +1 -1
- package/dist/schema.d.ts +1 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +3 -0
- package/dist/schema.js.map +1 -1
- package/dist/synonyms.d.ts +8 -0
- package/dist/synonyms.d.ts.map +1 -0
- package/dist/synonyms.js +137 -0
- package/dist/synonyms.js.map +1 -0
- package/dist/tokens.d.ts +13 -0
- package/dist/tokens.d.ts.map +1 -0
- package/dist/tokens.js +120 -0
- package/dist/tokens.js.map +1 -0
- package/dist/vault.d.ts +36 -2
- package/dist/vault.d.ts.map +1 -1
- package/dist/vault.js +142 -14
- package/dist/vault.js.map +1 -1
- package/package.json +1 -1
package/dist/synonyms.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { stem } from "./tokens.js";
|
|
2
|
+
/**
|
|
3
|
+
* Curated ES/EN synonym map for keyword matching. Every group is a set of real, general-purpose
|
|
4
|
+
* equivalences a dictionary would agree with (mostly translations of common technology words);
|
|
5
|
+
* none is derived from any test sentence. Groups are written with raw words and stemmed at load,
|
|
6
|
+
* so they keep working with the light stemmer. Max 80 groups; keep it small so precision stays high.
|
|
7
|
+
*/
|
|
8
|
+
const GROUPS = [
|
|
9
|
+
["prueba", "pruebas", "test", "tests", "testing", "check", "comprobacion", "chequeo"],
|
|
10
|
+
["carga", "load"],
|
|
11
|
+
["base de datos", "database", "db", "datos", "data", "dato"],
|
|
12
|
+
["cifrado", "cifrar", "encryption", "encrypt", "encrypted"],
|
|
13
|
+
["secreto", "secret", "secrets"],
|
|
14
|
+
["despliegue", "desplegar", "deploy", "deployment"],
|
|
15
|
+
["local", "locally", "localmente"],
|
|
16
|
+
["movil", "mobile", "telefono", "phone"],
|
|
17
|
+
["escritorio", "desktop"],
|
|
18
|
+
["rastreo", "traza", "trazas", "tracing", "trace"],
|
|
19
|
+
["error", "excepcion", "exception", "fallo"],
|
|
20
|
+
["cola", "queue"],
|
|
21
|
+
["realtime", "tiempo real", "real time"],
|
|
22
|
+
["autenticacion", "authentication", "auth", "login", "signup", "registro", "acceso", "alta"],
|
|
23
|
+
["sesion", "session"],
|
|
24
|
+
["autorizacion", "authorization", "permisos", "permissions", "rbac"],
|
|
25
|
+
["usuario", "user"],
|
|
26
|
+
["contrasena", "password"],
|
|
27
|
+
["identidad", "identity"],
|
|
28
|
+
["consulta", "query"],
|
|
29
|
+
["busqueda", "search", "buscador", "seo", "posicionamiento", "ranking"],
|
|
30
|
+
["almacenamiento", "storage"],
|
|
31
|
+
["cache"],
|
|
32
|
+
["servidor", "server"],
|
|
33
|
+
["cliente", "client"],
|
|
34
|
+
["interfaz", "interface", "ui", "componente", "component", "widget", "pantalla"],
|
|
35
|
+
["aplicacion", "application", "app"],
|
|
36
|
+
["sitio", "site", "website", "web"],
|
|
37
|
+
["pagina", "page"],
|
|
38
|
+
["navegador", "browser"],
|
|
39
|
+
["nube", "cloud"],
|
|
40
|
+
["contenedor", "container"],
|
|
41
|
+
["orquestacion", "orchestration", "orquestar", "orchestrate"],
|
|
42
|
+
["monitorizacion", "monitoring", "monitoreo"],
|
|
43
|
+
["metrica", "metric", "metrics"],
|
|
44
|
+
["log", "logs", "logging"],
|
|
45
|
+
["grafico", "chart", "plot"],
|
|
46
|
+
["panel", "dashboard"],
|
|
47
|
+
["estado", "state"],
|
|
48
|
+
["evento", "event"],
|
|
49
|
+
["mensaje", "message"],
|
|
50
|
+
["mensajeria", "messaging"],
|
|
51
|
+
["trabajo", "job"],
|
|
52
|
+
["rendimiento", "performance", "velocidad", "speed", "rapido", "fast", "quick", "millisecond", "milliseconds"],
|
|
53
|
+
["latencia", "latency"],
|
|
54
|
+
["disponibilidad", "availability"],
|
|
55
|
+
["escalabilidad", "scalability", "escalable", "scalable", "escalado", "escalar", "scaling", "scale", "autoscaling", "autoescalado"],
|
|
56
|
+
["seguridad", "security"],
|
|
57
|
+
["vulnerabilidad", "vulnerability"],
|
|
58
|
+
["clave", "key"],
|
|
59
|
+
["certificado", "certificate"],
|
|
60
|
+
["dependencia", "dependency"],
|
|
61
|
+
["modelo", "model"],
|
|
62
|
+
["prediccion", "prediction"],
|
|
63
|
+
["informe", "report"],
|
|
64
|
+
[
|
|
65
|
+
"pago",
|
|
66
|
+
"payment",
|
|
67
|
+
"cobro",
|
|
68
|
+
"dinero",
|
|
69
|
+
"money",
|
|
70
|
+
"ecommerce",
|
|
71
|
+
"comercio",
|
|
72
|
+
"carrito",
|
|
73
|
+
"tienda",
|
|
74
|
+
"shop",
|
|
75
|
+
"store",
|
|
76
|
+
"pedido",
|
|
77
|
+
"order",
|
|
78
|
+
"venta",
|
|
79
|
+
"sale",
|
|
80
|
+
"sales",
|
|
81
|
+
"factura",
|
|
82
|
+
"invoice",
|
|
83
|
+
"precio",
|
|
84
|
+
"price",
|
|
85
|
+
],
|
|
86
|
+
["transaccion", "transaction", "acid", "atomic"],
|
|
87
|
+
["tabla", "table", "relacion", "relational", "relacional"],
|
|
88
|
+
["indice", "index"],
|
|
89
|
+
["documento", "document"],
|
|
90
|
+
["fichero", "archivo", "file"],
|
|
91
|
+
["correo", "email"],
|
|
92
|
+
["notificacion", "notification"],
|
|
93
|
+
[
|
|
94
|
+
"sincronizacion",
|
|
95
|
+
"sincronizar",
|
|
96
|
+
"desincronizar",
|
|
97
|
+
"sync",
|
|
98
|
+
"synchronization",
|
|
99
|
+
"consistent",
|
|
100
|
+
"consistencia",
|
|
101
|
+
"consistency",
|
|
102
|
+
"integridad",
|
|
103
|
+
"integrity",
|
|
104
|
+
],
|
|
105
|
+
["flujo", "flow", "journey", "recorrido", "recorrer"],
|
|
106
|
+
["proveedor", "provider"],
|
|
107
|
+
];
|
|
108
|
+
/** token -> every token that should count as a hit for it (including itself). */
|
|
109
|
+
const EXPANSION = new Map();
|
|
110
|
+
for (const group of GROUPS) {
|
|
111
|
+
const members = [...new Set(group.flatMap((word) => word.split(/\s+/).map(stem)).filter(Boolean))];
|
|
112
|
+
for (const member of members) {
|
|
113
|
+
const current = EXPANSION.get(member) ?? [];
|
|
114
|
+
EXPANSION.set(member, [...new Set([...current, ...members])]);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Expand a query's tokens with the synonym map. Returns only the tokens that were
|
|
119
|
+
* actually added, so callers can score synonym-only matches in `score_breakdown.synonyms`.
|
|
120
|
+
*/
|
|
121
|
+
export function expandSynonyms(query) {
|
|
122
|
+
const extra = new Set();
|
|
123
|
+
for (const raw of query) {
|
|
124
|
+
for (const key of [raw, stem(raw)]) {
|
|
125
|
+
for (const synonym of EXPANSION.get(key) ?? []) {
|
|
126
|
+
if (!query.has(synonym))
|
|
127
|
+
extra.add(synonym);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return extra;
|
|
132
|
+
}
|
|
133
|
+
/** Number of curated groups, for the report and tests. */
|
|
134
|
+
export function synonymGroupCount() {
|
|
135
|
+
return GROUPS.length;
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=synonyms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"synonyms.js","sourceRoot":"","sources":["../src/synonyms.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEnC;;;;;GAKG;AACH,MAAM,MAAM,GAAe;IACzB,CAAC,Q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allow, repeat-until-stable suffix stripping so inflections of a word share one stem. */
|
|
2
|
+
export declare function stem(token: string): string;
|
|
3
|
+
/** Lowercase, strip accents, split on every non-word separator, drop stopwords, then stem. */
|
|
4
|
+
export declare function tokens(text: string): string[];
|
|
5
|
+
/**
|
|
6
|
+
* Inverse document frequency over a text corpus. A token that appears in many documents
|
|
7
|
+
* ("app", "web", "datos") counts less than a rare one ("ssr", "playwright"). Unknown tokens
|
|
8
|
+
* are treated as common-by-default (weight 1) so a query still ranks on words the vault lacks.
|
|
9
|
+
*/
|
|
10
|
+
export declare function idf(corpus: string[][]): Map<string, number>;
|
|
11
|
+
/** The first paragraph of a note body: consecutive lines until the first blank line. */
|
|
12
|
+
export declare function firstParagraph(body: string): string;
|
|
13
|
+
//# sourceMappingURL=tokens.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAyDA,6FAA6F;AAC7F,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAgB1C;AAED,8FAA8F;AAC9F,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAQ7C;AAED;;;;GAIG;AACH,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAY3D;AAED,wFAAwF;AACxF,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAYnD"}
|
package/dist/tokens.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// Fuller ES/EN stopword lists so function words never contribute to a score. Kept to function
|
|
2
|
+
// words only: content words that name situations ("base", "web", "api", "local", "estado") stay.
|
|
3
|
+
const ENGLISH = `a about above across after again against all along among an and any are around as at be
|
|
4
|
+
because been before behind being below beside between beyond both but by can cannot could did do does
|
|
5
|
+
doing down during each either except few for from further had has have having he her here hers herself
|
|
6
|
+
him himself his how i if in inside into is it its itself just me more most my myself near no nor not now
|
|
7
|
+
of off on once only onto or other our ours out over own same she should since so some such than that the
|
|
8
|
+
their theirs them themselves then there these they this those through to too toward under until up upon
|
|
9
|
+
us very via was we were what when where which while who whom why will with within without would you your
|
|
10
|
+
yours yourself yourselves`;
|
|
11
|
+
const SPANISH = `a al algo algunos ante antes aunque cada como con contra cual cuales cuando cuanto cuantos de del
|
|
12
|
+
desde donde dos e el ella ellas ellos en entonces entre era eran eras eres es esa esas ese eso esos esta
|
|
13
|
+
estaba estaban estan estar estas este esto estos fue fueron ha habia hacia han hasta hay la las le les lo los
|
|
14
|
+
mas me mediante mi mientras misma mismo mismas mismos muy nada ni ningun ninguna ninguno no nos nosotros
|
|
15
|
+
nuestra nuestro o os otra otras otro otros para pero poco por porque que quien se sea segun ser si sin sobre
|
|
16
|
+
son su sus tal tales tambien tanto te tiene tienen todo todos tras tu tus u un una uno unos vosotros y ya yo`;
|
|
17
|
+
const STOPWORDS = new Set([...ENGLISH.split(/\s+/), ...SPANISH.split(/\s+/)].filter(Boolean));
|
|
18
|
+
/**
|
|
19
|
+
* One light stemmer for both languages: a small ordered set of suffix rules, applied repeatedly
|
|
20
|
+
* until none matches. It is deliberately shallow (no dictionaries): it only needs to make
|
|
21
|
+
* inflection variants of the same word meet ("transacciones" ~ "transacción",
|
|
22
|
+
* "concurrentes" ~ "concurrencia", "locales" ~ "localmente" ~ "local", "cifrada" ~ "cifrado",
|
|
23
|
+
* "rendering" ~ "render"). Suffix sets from both languages coexist because a token only ever
|
|
24
|
+
* passes one matching rule per round; final double consonants are collapsed ("transacc" ~ "transac").
|
|
25
|
+
*/
|
|
26
|
+
const RULES = [
|
|
27
|
+
// adverbial / abstract-noun endings
|
|
28
|
+
{ re: /(mente)$/, drop: 5, min: 4 },
|
|
29
|
+
{ re: /(encias)$/, drop: 6, min: 4 },
|
|
30
|
+
{ re: /(encia)$/, drop: 5, min: 4 },
|
|
31
|
+
{ re: /(ancias)$/, drop: 6, min: 4 },
|
|
32
|
+
{ re: /(ancia)$/, drop: 5, min: 4 },
|
|
33
|
+
{ re: /(idades)$/, drop: 6, min: 4 },
|
|
34
|
+
{ re: /(idad)$/, drop: 4, min: 4 },
|
|
35
|
+
{ re: /(ities)$/, drop: 5, min: 4 },
|
|
36
|
+
{ re: /(ity)$/, drop: 3, min: 4 },
|
|
37
|
+
{ re: /(ciones)$/, drop: 6, min: 4 },
|
|
38
|
+
{ re: /(siones)$/, drop: 6, min: 4 },
|
|
39
|
+
{ re: /(cion|sion|tion)$/, drop: 4, min: 4 },
|
|
40
|
+
// participles / adjectives (ES and EN)
|
|
41
|
+
{ re: /(entes|antes)$/, drop: 5, min: 4 },
|
|
42
|
+
{ re: /(ente|ante)$/, drop: 4, min: 4 },
|
|
43
|
+
{ re: /(ados|adas|idos|idas)$/, drop: 4, min: 4 },
|
|
44
|
+
{ re: /(ado|ada|ido|ida)$/, drop: 3, min: 4 },
|
|
45
|
+
{ re: /(ando|endo)$/, drop: 4, min: 4 },
|
|
46
|
+
{ re: /(ing)$/, drop: 3, min: 4 },
|
|
47
|
+
{ re: /(ed)$/, drop: 2, min: 4 },
|
|
48
|
+
// plurals, then infinitive/vowel endings
|
|
49
|
+
{ re: /(es)$/, drop: 2, min: 4 },
|
|
50
|
+
{ re: /(s)$/, drop: 1, min: 3 },
|
|
51
|
+
{ re: /(ar|er|ir)$/, drop: 2, min: 4 },
|
|
52
|
+
{ re: /(e|o|a)$/, drop: 1, min: 5 },
|
|
53
|
+
];
|
|
54
|
+
/** Shallow, repeat-until-stable suffix stripping so inflections of a word share one stem. */
|
|
55
|
+
export function stem(token) {
|
|
56
|
+
let current = token;
|
|
57
|
+
for (let round = 0; round < 4; round++) {
|
|
58
|
+
let changed = false;
|
|
59
|
+
for (const { re, drop, min } of RULES) {
|
|
60
|
+
if (!re.test(current) || current.length - drop < min)
|
|
61
|
+
continue;
|
|
62
|
+
// Keep "class"/"access"-style endings intact.
|
|
63
|
+
if (drop === 1 && /(ss|us|is)$/.test(current))
|
|
64
|
+
continue;
|
|
65
|
+
current = current.slice(0, -drop);
|
|
66
|
+
changed = true;
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
if (!changed)
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
// "transacc" (transacción) and "transac" (transacciones) meet.
|
|
73
|
+
return current.replace(/([bcdfglmnprstz])\1$/, "$1");
|
|
74
|
+
}
|
|
75
|
+
/** Lowercase, strip accents, split on every non-word separator, drop stopwords, then stem. */
|
|
76
|
+
export function tokens(text) {
|
|
77
|
+
return text
|
|
78
|
+
.normalize("NFD")
|
|
79
|
+
.replace(/[\u0300-\u036f]/g, "")
|
|
80
|
+
.toLowerCase()
|
|
81
|
+
.split(/[^a-z0-9+#]+/)
|
|
82
|
+
.filter((t) => t.length > 1 && !STOPWORDS.has(t))
|
|
83
|
+
.map(stem);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Inverse document frequency over a text corpus. A token that appears in many documents
|
|
87
|
+
* ("app", "web", "datos") counts less than a rare one ("ssr", "playwright"). Unknown tokens
|
|
88
|
+
* are treated as common-by-default (weight 1) so a query still ranks on words the vault lacks.
|
|
89
|
+
*/
|
|
90
|
+
export function idf(corpus) {
|
|
91
|
+
const df = new Map();
|
|
92
|
+
for (const doc of corpus) {
|
|
93
|
+
for (const token of new Set(doc))
|
|
94
|
+
df.set(token, (df.get(token) ?? 0) + 1);
|
|
95
|
+
}
|
|
96
|
+
const total = Math.max(1, corpus.length);
|
|
97
|
+
const weights = new Map();
|
|
98
|
+
for (const [token, count] of df) {
|
|
99
|
+
// floor at 0.35 so a very common word never counts for nothing.
|
|
100
|
+
weights.set(token, Math.max(0.35, Math.log(total / count)));
|
|
101
|
+
}
|
|
102
|
+
return weights;
|
|
103
|
+
}
|
|
104
|
+
/** The first paragraph of a note body: consecutive lines until the first blank line. */
|
|
105
|
+
export function firstParagraph(body) {
|
|
106
|
+
const lines = [];
|
|
107
|
+
for (const raw of body.split(/\r?\n/)) {
|
|
108
|
+
const line = raw.trim();
|
|
109
|
+
if (!line) {
|
|
110
|
+
if (lines.length)
|
|
111
|
+
break;
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (line.startsWith("#"))
|
|
115
|
+
continue;
|
|
116
|
+
lines.push(line.replace(/^([-*+]|\d+\.)\s+/, "").replace(/^>\s*/, ""));
|
|
117
|
+
}
|
|
118
|
+
return lines.join(" ");
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=tokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,iGAAiG;AACjG,MAAM,OAAO,GAAG;;;;;;;0BAOU,CAAC;AAE3B,MAAM,OAAO,GAAG;;;;;6GAK6F,CAAC;AAE9G,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;AAE9F;;;;;;;GAOG;AACH,MAAM,KAAK,GAAgD;IACzD,oCAAoC;IACpC,EAAE,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE;IACnC,EAAE,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE;IACpC,EAAE,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE;IACnC,EAAE,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE;IACpC,EAAE,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE,CAA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AG,CAAC,IAAI,EAAE,CAAC;QACxB,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,IAAI,KAAK,CAAC,MAAM;gBAAE,MAAM;YACxB,SAAS;QACX,CAAC;QACD,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,SAAS;QACnC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IACzE,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC"}
|
package/dist/vault.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export declare class ConflictError extends Error {
|
|
|
11
11
|
readonly path: string;
|
|
12
12
|
readonly expectedHash: string;
|
|
13
13
|
readonly actualHash: string;
|
|
14
|
-
constructor(path: string, expectedHash: string, actualHash: string);
|
|
14
|
+
constructor(path: string, expectedHash: string, actualHash: string, message?: string);
|
|
15
15
|
}
|
|
16
16
|
/** Thrown when a note does not exist. */
|
|
17
17
|
export declare class NotFoundError extends Error {
|
|
@@ -23,6 +23,29 @@ export declare class VaultNotFoundError extends Error {
|
|
|
23
23
|
readonly root: string;
|
|
24
24
|
constructor(root: string);
|
|
25
25
|
}
|
|
26
|
+
/** Optional narrowing for a bulk approval or rejection. With no fields, every proposal is included. */
|
|
27
|
+
export interface ApproveAllFilter {
|
|
28
|
+
pack?: string;
|
|
29
|
+
version?: string;
|
|
30
|
+
agent?: string;
|
|
31
|
+
action?: "create" | "update";
|
|
32
|
+
/** Only these proposal ids; ids that are not pending are reported in `failed`. */
|
|
33
|
+
ids?: string[];
|
|
34
|
+
}
|
|
35
|
+
export interface ApproveAllResult {
|
|
36
|
+
approved: string[];
|
|
37
|
+
failed: {
|
|
38
|
+
id: string;
|
|
39
|
+
error: string;
|
|
40
|
+
}[];
|
|
41
|
+
}
|
|
42
|
+
export interface RejectAllResult {
|
|
43
|
+
rejected: string[];
|
|
44
|
+
failed: {
|
|
45
|
+
id: string;
|
|
46
|
+
error: string;
|
|
47
|
+
}[];
|
|
48
|
+
}
|
|
26
49
|
export declare class Vault {
|
|
27
50
|
readonly root: string;
|
|
28
51
|
readonly notes: Map<string, Note>;
|
|
@@ -47,7 +70,9 @@ export declare class Vault {
|
|
|
47
70
|
deleteNote(id: string, opts?: {
|
|
48
71
|
expectedHash?: string;
|
|
49
72
|
}): void;
|
|
50
|
-
propose(id: string, data: NoteData, body: string, meta: Omit<ProposalMeta, "action" | "created">): Proposal;
|
|
73
|
+
propose(id: string, data: NoteData, body: string, meta: Omit<ProposalMeta, "action" | "created" | "base_hash">): Proposal;
|
|
74
|
+
/** Read every inbox file, keeping invalid frontmatter as a reported failure. */
|
|
75
|
+
private inboxEntries;
|
|
51
76
|
listProposals(): Proposal[];
|
|
52
77
|
getProposal(id: string): Proposal | undefined;
|
|
53
78
|
private acceptProposal;
|
|
@@ -55,10 +80,19 @@ export declare class Vault {
|
|
|
55
80
|
data?: NoteData;
|
|
56
81
|
body?: string;
|
|
57
82
|
}): string;
|
|
83
|
+
/**
|
|
84
|
+
* Approve every proposal from a pack (optionally a single version).
|
|
85
|
+
* @deprecated Use {@link approveMany} to get per-proposal successes and failures.
|
|
86
|
+
*/
|
|
58
87
|
approveAll(filter: {
|
|
59
88
|
pack: string;
|
|
60
89
|
version?: string;
|
|
61
90
|
}): string[];
|
|
91
|
+
approveMany(filter?: ApproveAllFilter): ApproveAllResult;
|
|
92
|
+
/** Keep only the proposals whose id is in `ids`; report ids that are not pending. */
|
|
93
|
+
private selectByIds;
|
|
94
|
+
/** Reject every proposal that matches the filter; rejected files are deleted from the inbox. */
|
|
95
|
+
rejectMany(filter?: ApproveAllFilter): RejectAllResult;
|
|
62
96
|
reject(id: string): void;
|
|
63
97
|
}
|
|
64
98
|
/** Serialize a note to Markdown with frontmatter, dropping empty fields. */
|
package/dist/vault.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vault.d.ts","sourceRoot":"","sources":["../src/vault.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"vault.d.ts","sourceRoot":"","sources":["../src/vault.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,IAAI,EACT,KAAK,QAAQ,EACb,KAAK,QAAQ,EAEb,KAAK,QAAQ,EACb,KAAK,YAAY,EAGlB,MAAM,aAAa,CAAC;AAKrB,2DAA2D;AAC3D,wBAAgB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAExC;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAQzC;AA2DD,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,yFAAyF;AACzF,qBAAa,aAAc,SAAQ,KAAK;IAEpC,QAAQ,CAAC,IAAI,EAAE,MAAM;IACrB,QAAQ,CAAC,YAAY,EAAE,MAAM;IAC7B,QAAQ,CAAC,UAAU,EAAE,MAAM;gBAFlB,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,EAC3B,OAAO,SAAoD;CAK9D;AAED,yCAAyC;AACzC,qBAAa,aAAc,SAAQ,KAAK;IAC1B,QAAQ,CAAC,EAAE,EAAE,MAAM;gBAAV,EAAE,EAAE,MAAM;CAIhC;AAED,sDAAsD;AACtD,qBAAa,kBAAmB,SAAQ,KAAK;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM;gBAAZ,IAAI,EAAE,MAAM;CAIlC;AAED,uGAAuG;AACvG,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC7B,kFAAkF;IAClF,G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,MAAM,EAAE,IAAI,GAAE;QAAE,YAAY,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,IAAI;IAUlE,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,YAAY,EAAE,QAAQ,GAAG,SAAS,GAAG,WAAW,CAAC,GAAG,QAAQ;IAiBzH,gFAAgF;IAChF,OAAO,CAAC,YAAY;IA0BpB,aAAa,IAAI,QAAQ,EAAE;IAI3B,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS;IAK7C,OAAO,CAAC,cAAc;IAqBtB,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,GAAE;QAAE,IAAI,CAAC,EAAE,QAAQ,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,MAAM;IAM9E;;;OAGG;IACH,UAAU,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,EAAE;IAWhE,WAAW,CAAC,MAAM,GAAE,gBAAqB,GAAG,gBAAgB;IAgC5D,qFAAqF;IACrF,OAAO,CAAC,WAAW;IASnB,gGAAgG;IAChG,UAAU,CAAC,MAAM,GAAE,gBAAqB,GAAG,eAAe;IA+B1D,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;CAKzB;AAED,4EAA4E;AAC5E,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAEjF"}
|
package/dist/vault.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import matter from "gray-matter";
|
|
4
|
+
import { ZodError } from "zod";
|
|
4
5
|
import { atomicWrite, sha256 } from "./fsutil.js";
|
|
5
6
|
import { noteSchema, proposalMetaSchema, TYPE_DIRS, } from "./schema.js";
|
|
6
7
|
const INBOX_DIR = "inbox";
|
|
@@ -28,6 +29,12 @@ function walk(dir) {
|
|
|
28
29
|
return e.name.endsWith(".md") ? [full] : [];
|
|
29
30
|
});
|
|
30
31
|
}
|
|
32
|
+
function describeError(error) {
|
|
33
|
+
if (error instanceof ZodError) {
|
|
34
|
+
return error.issues.map((issue) => `${issue.path.join(".") || "frontmatter"}: ${issue.message}`).join("; ");
|
|
35
|
+
}
|
|
36
|
+
return error instanceof Error ? error.message : String(error);
|
|
37
|
+
}
|
|
31
38
|
function frontmatterRefs(data) {
|
|
32
39
|
const refs = [];
|
|
33
40
|
const push = (v) => {
|
|
@@ -75,8 +82,8 @@ export class ConflictError extends Error {
|
|
|
75
82
|
path;
|
|
76
83
|
expectedHash;
|
|
77
84
|
actualHash;
|
|
78
|
-
constructor(path, expectedHash, actualHash) {
|
|
79
|
-
super(
|
|
85
|
+
constructor(path, expectedHash, actualHash, message = `note changed on disk since it was read: ${path}`) {
|
|
86
|
+
super(message);
|
|
80
87
|
this.path = path;
|
|
81
88
|
this.expectedHash = expectedHash;
|
|
82
89
|
this.actualHash = actualHash;
|
|
@@ -211,23 +218,48 @@ export class Vault {
|
|
|
211
218
|
propose(id, data, body, meta) {
|
|
212
219
|
const parsed = noteSchema.parse(data);
|
|
213
220
|
const slug = slugify(id);
|
|
214
|
-
const
|
|
215
|
-
const
|
|
221
|
+
const existing = this.get(slug);
|
|
222
|
+
const action = existing ? "update" : "create";
|
|
223
|
+
const proposal = {
|
|
224
|
+
...meta,
|
|
225
|
+
...(existing ? { base_hash: existing.hash } : {}),
|
|
226
|
+
action,
|
|
227
|
+
created: new Date().toISOString(),
|
|
228
|
+
};
|
|
216
229
|
const file = path.join(this.root, INBOX_DIR, `${slug}.md`);
|
|
217
230
|
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
218
231
|
atomicWrite(file, serializeNote({ ...parsed, proposal }, body));
|
|
219
232
|
return { id: slug, path: file, meta: proposal, data: parsed, body };
|
|
220
233
|
}
|
|
234
|
+
/** Read every inbox file, keeping invalid frontmatter as a reported failure. */
|
|
235
|
+
inboxEntries() {
|
|
236
|
+
const proposals = [];
|
|
237
|
+
const invalid = [];
|
|
238
|
+
for (const file of walk(path.join(this.root, INBOX_DIR))) {
|
|
239
|
+
const id = slugify(path.basename(file, ".md"));
|
|
240
|
+
try {
|
|
241
|
+
const { data, content } = matter(fs.readFileSync(file, "utf8"));
|
|
242
|
+
const { proposal, ...rest } = data;
|
|
243
|
+
const meta = proposalMetaSchema.safeParse(proposal);
|
|
244
|
+
if (!meta.success) {
|
|
245
|
+
invalid.push({ id, error: `invalid proposal frontmatter: ${describeError(meta.error)}` });
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
const note = noteSchema.safeParse(rest);
|
|
249
|
+
if (!note.success) {
|
|
250
|
+
invalid.push({ id, error: `invalid note frontmatter: ${describeError(note.error)}` });
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
proposals.push({ id, path: file, meta: meta.data, data: note.data, body: content.trim() });
|
|
254
|
+
}
|
|
255
|
+
catch (error) {
|
|
256
|
+
invalid.push({ id, error: `unreadable proposal: ${describeError(error)}` });
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return { proposals, invalid };
|
|
260
|
+
}
|
|
221
261
|
listProposals() {
|
|
222
|
-
return
|
|
223
|
-
const { data, content } = matter(fs.readFileSync(file, "utf8"));
|
|
224
|
-
const { proposal, ...rest } = data;
|
|
225
|
-
const meta = proposalMetaSchema.safeParse(proposal);
|
|
226
|
-
const note = noteSchema.safeParse(rest);
|
|
227
|
-
if (!meta.success || !note.success)
|
|
228
|
-
return [];
|
|
229
|
-
return [{ id: slugify(path.basename(file, ".md")), path: file, meta: meta.data, data: note.data, body: content.trim() }];
|
|
230
|
-
});
|
|
262
|
+
return this.inboxEntries().proposals;
|
|
231
263
|
}
|
|
232
264
|
getProposal(id) {
|
|
233
265
|
const slug = slugify(id);
|
|
@@ -236,7 +268,16 @@ export class Vault {
|
|
|
236
268
|
acceptProposal(p, override = {}, reload = true) {
|
|
237
269
|
const source = p.meta.proposed_by.startsWith("pack:") ? p.meta.proposed_by : `agent:${p.meta.proposed_by}`;
|
|
238
270
|
const data = { ...(override.data ?? p.data), source };
|
|
239
|
-
|
|
271
|
+
let file;
|
|
272
|
+
try {
|
|
273
|
+
file = this.writeNote(p.id, data, override.body ?? p.body, { expectedHash: p.meta.base_hash, reload });
|
|
274
|
+
}
|
|
275
|
+
catch (error) {
|
|
276
|
+
if (error instanceof ConflictError) {
|
|
277
|
+
throw new ConflictError(error.path, error.expectedHash, error.actualHash, `note "${p.id}" changed since this proposal was created; review the note and try again`);
|
|
278
|
+
}
|
|
279
|
+
throw error;
|
|
280
|
+
}
|
|
240
281
|
fs.rmSync(p.path);
|
|
241
282
|
return file;
|
|
242
283
|
}
|
|
@@ -246,6 +287,10 @@ export class Vault {
|
|
|
246
287
|
throw new Error(`no proposal "${id}" in inbox`);
|
|
247
288
|
return this.acceptProposal(p, override);
|
|
248
289
|
}
|
|
290
|
+
/**
|
|
291
|
+
* Approve every proposal from a pack (optionally a single version).
|
|
292
|
+
* @deprecated Use {@link approveMany} to get per-proposal successes and failures.
|
|
293
|
+
*/
|
|
249
294
|
approveAll(filter) {
|
|
250
295
|
const prefix = `pack:${filter.pack}@`;
|
|
251
296
|
const exact = filter.version === undefined ? undefined : `${prefix}${filter.version}`;
|
|
@@ -256,6 +301,89 @@ export class Vault {
|
|
|
256
301
|
this.reload();
|
|
257
302
|
return proposals.map((p) => p.id);
|
|
258
303
|
}
|
|
304
|
+
approveMany(filter = {}) {
|
|
305
|
+
if (filter.version && !filter.pack)
|
|
306
|
+
throw new Error("a version filter requires a pack");
|
|
307
|
+
if (filter.pack && filter.agent)
|
|
308
|
+
throw new Error("pack and agent filters are mutually exclusive");
|
|
309
|
+
const { proposals, invalid } = this.inboxEntries();
|
|
310
|
+
let selected = proposals;
|
|
311
|
+
if (filter.pack) {
|
|
312
|
+
const prefix = `pack:${filter.pack}@`;
|
|
313
|
+
const exact = filter.version === undefined ? undefined : `${prefix}${filter.version}`;
|
|
314
|
+
selected = selected.filter((p) => (exact === undefined ? p.meta.proposed_by.startsWith(prefix) : p.meta.proposed_by === exact));
|
|
315
|
+
}
|
|
316
|
+
if (filter.agent)
|
|
317
|
+
selected = selected.filter((p) => p.meta.proposed_by === filter.agent);
|
|
318
|
+
if (filter.action)
|
|
319
|
+
selected = selected.filter((p) => p.meta.action === filter.action);
|
|
320
|
+
const result = {
|
|
321
|
+
approved: [],
|
|
322
|
+
// Unfiltered approval owns the whole inbox, including files that cannot
|
|
323
|
+
// be parsed. A filtered approval only reports the proposals it selected.
|
|
324
|
+
failed: filter.pack || filter.agent || filter.action || filter.ids ? [] : invalid,
|
|
325
|
+
};
|
|
326
|
+
if (filter.ids)
|
|
327
|
+
selected = this.selectByIds(proposals, selected, filter.ids, result.failed);
|
|
328
|
+
for (const p of selected) {
|
|
329
|
+
try {
|
|
330
|
+
this.acceptProposal(p, {}, false);
|
|
331
|
+
result.approved.push(p.id);
|
|
332
|
+
}
|
|
333
|
+
catch (error) {
|
|
334
|
+
result.failed.push({ id: p.id, error: describeError(error) });
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
if (selected.length)
|
|
338
|
+
this.reload();
|
|
339
|
+
return result;
|
|
340
|
+
}
|
|
341
|
+
/** Keep only the proposals whose id is in `ids`; report ids that are not pending. */
|
|
342
|
+
selectByIds(all, selected, ids, failed) {
|
|
343
|
+
const present = new Set(all.map((p) => p.id));
|
|
344
|
+
const wanted = new Set(ids.map((id) => slugify(id)));
|
|
345
|
+
for (const id of wanted) {
|
|
346
|
+
if (!present.has(id))
|
|
347
|
+
failed.push({ id, error: `no proposal "${id}" in inbox` });
|
|
348
|
+
}
|
|
349
|
+
return selected.filter((p) => wanted.has(p.id));
|
|
350
|
+
}
|
|
351
|
+
/** Reject every proposal that matches the filter; rejected files are deleted from the inbox. */
|
|
352
|
+
rejectMany(filter = {}) {
|
|
353
|
+
if (filter.version && !filter.pack)
|
|
354
|
+
throw new Error("a version filter requires a pack");
|
|
355
|
+
if (filter.pack && filter.agent)
|
|
356
|
+
throw new Error("pack and agent filters are mutually exclusive");
|
|
357
|
+
const { proposals, invalid } = this.inboxEntries();
|
|
358
|
+
let selected = proposals;
|
|
359
|
+
if (filter.pack) {
|
|
360
|
+
const prefix = `pack:${filter.pack}@`;
|
|
361
|
+
const exact = filter.version === undefined ? undefined : `${prefix}${filter.version}`;
|
|
362
|
+
selected = selected.filter((p) => (exact === undefined ? p.meta.proposed_by.startsWith(prefix) : p.meta.proposed_by === exact));
|
|
363
|
+
}
|
|
364
|
+
if (filter.agent)
|
|
365
|
+
selected = selected.filter((p) => p.meta.proposed_by === filter.agent);
|
|
366
|
+
if (filter.action)
|
|
367
|
+
selected = selected.filter((p) => p.meta.action === filter.action);
|
|
368
|
+
const result = {
|
|
369
|
+
rejected: [],
|
|
370
|
+
// Like approveMany: an unfiltered rejection owns the whole inbox, including
|
|
371
|
+
// files that cannot be parsed; a filtered one reports only what it selected.
|
|
372
|
+
failed: filter.pack || filter.agent || filter.action || filter.ids ? [] : invalid,
|
|
373
|
+
};
|
|
374
|
+
if (filter.ids)
|
|
375
|
+
selected = this.selectByIds(proposals, selected, filter.ids, result.failed);
|
|
376
|
+
for (const p of selected) {
|
|
377
|
+
try {
|
|
378
|
+
fs.rmSync(p.path);
|
|
379
|
+
result.rejected.push(p.id);
|
|
380
|
+
}
|
|
381
|
+
catch (error) {
|
|
382
|
+
result.failed.push({ id: p.id, error: describeError(error) });
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
return result;
|
|
386
|
+
}
|
|
259
387
|
reject(id) {
|
|
260
388
|
const p = this.getProposal(id);
|
|
261
389
|
if (!p)
|