@mainsoft/agent-cms 0.0.0-stage → 0.7.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/CHANGELOG.md +54 -0
- package/LICENSE +21 -0
- package/README.md +359 -2
- package/TODO.md +178 -0
- package/UPGRADE-0.6.md +236 -0
- package/dist/agent.cjs +250 -0
- package/dist/agent.d.cts +88 -0
- package/dist/agent.d.ts +88 -0
- package/dist/agent.js +24 -0
- package/dist/ai.cjs +555 -0
- package/dist/ai.d.cts +48 -0
- package/dist/ai.d.ts +48 -0
- package/dist/ai.js +73 -0
- package/dist/bin.js +1556 -0
- package/dist/chunk-2NTK7H4W.js +10 -0
- package/dist/chunk-52NUUZC7.js +1446 -0
- package/dist/chunk-6K5ZTGHQ.js +30 -0
- package/dist/chunk-AKN7SUXU.js +281 -0
- package/dist/chunk-CRDW6Q72.js +188 -0
- package/dist/chunk-DD56PTZ4.js +78 -0
- package/dist/chunk-DOADAH4L.js +52 -0
- package/dist/chunk-EXV6JNLY.js +251 -0
- package/dist/chunk-IGL2V6US.js +324 -0
- package/dist/chunk-IW3D4I7Q.js +317 -0
- package/dist/chunk-OQ55GEF3.js +6 -0
- package/dist/chunk-QC2M4NZY.js +158 -0
- package/dist/chunk-QQV6VLYJ.js +204 -0
- package/dist/chunk-T66ZKBHF.js +25 -0
- package/dist/chunk-VICZ76TR.js +118 -0
- package/dist/chunk-Y63XQS2J.js +6 -0
- package/dist/cli.cjs +1596 -0
- package/dist/cli.d.cts +89 -0
- package/dist/cli.d.ts +89 -0
- package/dist/cli.js +534 -0
- package/dist/client.cjs +185 -0
- package/dist/client.d.cts +228 -0
- package/dist/client.d.ts +228 -0
- package/dist/client.js +13 -0
- package/dist/cms-BPp01z-8.d.ts +411 -0
- package/dist/cms-D6D89-qZ.d.cts +411 -0
- package/dist/config.cjs +61 -0
- package/dist/config.d.cts +36 -0
- package/dist/config.d.ts +36 -0
- package/dist/config.js +11 -0
- package/dist/diff.cjs +316 -0
- package/dist/diff.d.cts +122 -0
- package/dist/diff.d.ts +122 -0
- package/dist/diff.js +29 -0
- package/dist/drizzle-repo-B1rt7r4j.d.ts +90 -0
- package/dist/drizzle-repo-Cn-kL2FK.d.cts +90 -0
- package/dist/errors.cjs +193 -0
- package/dist/errors.d.cts +109 -0
- package/dist/errors.d.ts +109 -0
- package/dist/errors.js +16 -0
- package/dist/frontmatter.cjs +103 -0
- package/dist/frontmatter.d.cts +32 -0
- package/dist/frontmatter.d.ts +32 -0
- package/dist/frontmatter.js +9 -0
- package/dist/http.cjs +1105 -0
- package/dist/http.d.cts +75 -0
- package/dist/http.d.ts +75 -0
- package/dist/http.js +321 -0
- package/dist/index.cjs +3066 -0
- package/dist/index.d.cts +19 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +263 -0
- package/dist/markdown.cjs +220 -0
- package/dist/markdown.d.cts +88 -0
- package/dist/markdown.d.ts +88 -0
- package/dist/markdown.js +23 -0
- package/dist/mcp.cjs +652 -0
- package/dist/mcp.d.cts +43 -0
- package/dist/mcp.d.ts +43 -0
- package/dist/mcp.js +26 -0
- package/dist/messages/en.cjs +76 -0
- package/dist/messages/en.d.cts +7 -0
- package/dist/messages/en.d.ts +7 -0
- package/dist/messages/en.js +7 -0
- package/dist/messages/ko.cjs +76 -0
- package/dist/messages/ko.d.cts +7 -0
- package/dist/messages/ko.d.ts +7 -0
- package/dist/messages/ko.js +53 -0
- package/dist/registry/cms-audit.json +25 -0
- package/dist/registry/cms-command.json +23 -0
- package/dist/registry/cms-doc-editor.json +36 -0
- package/dist/registry/cms-doc-list.json +29 -0
- package/dist/registry/cms-empty.json +22 -0
- package/dist/registry/cms-keys.json +29 -0
- package/dist/registry/cms-lib.json +33 -0
- package/dist/registry/cms-merge.json +26 -0
- package/dist/registry/cms-shell.json +22 -0
- package/dist/registry/cms-versions.json +26 -0
- package/dist/registry/registry.json +255 -0
- package/dist/repo-BWI2Pkrv.d.ts +162 -0
- package/dist/repo-CeDxUxO6.d.cts +162 -0
- package/dist/tables.cjs +356 -0
- package/dist/tables.d.cts +3515 -0
- package/dist/tables.d.ts +3515 -0
- package/dist/tables.js +35 -0
- package/dist/tools.cjs +420 -0
- package/dist/tools.d.cts +27 -0
- package/dist/tools.d.ts +27 -0
- package/dist/tools.js +18 -0
- package/dist/types.cjs +226 -0
- package/dist/types.d.cts +286 -0
- package/dist/types.d.ts +286 -0
- package/dist/types.js +28 -0
- package/package.json +277 -4
package/dist/diff.cjs
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/diff.ts
|
|
21
|
+
var diff_exports = {};
|
|
22
|
+
__export(diff_exports, {
|
|
23
|
+
diffLines: () => diffLines,
|
|
24
|
+
diffSeq: () => diffSeq,
|
|
25
|
+
diffWords: () => diffWords,
|
|
26
|
+
fieldChanges: () => fieldChanges,
|
|
27
|
+
flattenFields: () => flattenFields,
|
|
28
|
+
hunks: () => hunks,
|
|
29
|
+
merge3: () => merge3,
|
|
30
|
+
mergeDocs: () => mergeDocs,
|
|
31
|
+
resolveDocMerge: () => resolveDocMerge,
|
|
32
|
+
resolveMerge: () => resolveMerge,
|
|
33
|
+
splitLines: () => splitLines,
|
|
34
|
+
unifiedDiff: () => unifiedDiff
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(diff_exports);
|
|
37
|
+
function diffSeq(a, b, eq = Object.is) {
|
|
38
|
+
let start = 0;
|
|
39
|
+
while (start < a.length && start < b.length && eq(a[start], b[start])) start++;
|
|
40
|
+
let endA = a.length;
|
|
41
|
+
let endB = b.length;
|
|
42
|
+
while (endA > start && endB > start && eq(a[endA - 1], b[endB - 1])) {
|
|
43
|
+
endA--;
|
|
44
|
+
endB--;
|
|
45
|
+
}
|
|
46
|
+
const A = a.slice(start, endA);
|
|
47
|
+
const B = b.slice(start, endB);
|
|
48
|
+
const n = A.length;
|
|
49
|
+
const m = B.length;
|
|
50
|
+
const max = n + m;
|
|
51
|
+
const v = /* @__PURE__ */ new Map([[1, 0]]);
|
|
52
|
+
const trace = [];
|
|
53
|
+
outer: for (let d = 0; d <= max; d++) {
|
|
54
|
+
trace.push(new Map(v));
|
|
55
|
+
for (let k = -d; k <= d; k += 2) {
|
|
56
|
+
let x2 = k === -d || k !== d && (v.get(k - 1) ?? -1) < (v.get(k + 1) ?? -1) ? v.get(k + 1) ?? 0 : (v.get(k - 1) ?? 0) + 1;
|
|
57
|
+
let y2 = x2 - k;
|
|
58
|
+
while (x2 < n && y2 < m && eq(A[x2], B[y2])) {
|
|
59
|
+
x2++;
|
|
60
|
+
y2++;
|
|
61
|
+
}
|
|
62
|
+
v.set(k, x2);
|
|
63
|
+
if (x2 >= n && y2 >= m) break outer;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const mid = [];
|
|
67
|
+
let x = n;
|
|
68
|
+
let y = m;
|
|
69
|
+
for (let d = trace.length - 1; d >= 0 && (x > 0 || y > 0); d--) {
|
|
70
|
+
const vd = trace[d];
|
|
71
|
+
const k = x - y;
|
|
72
|
+
const prevK = k === -d || k !== d && (vd.get(k - 1) ?? -1) < (vd.get(k + 1) ?? -1) ? k + 1 : k - 1;
|
|
73
|
+
const prevX = vd.get(prevK) ?? 0;
|
|
74
|
+
const prevY = prevX - prevK;
|
|
75
|
+
while (x > prevX && y > prevY) {
|
|
76
|
+
x--;
|
|
77
|
+
y--;
|
|
78
|
+
mid.push({ t: "eq", a: x, b: y, v: A[x] });
|
|
79
|
+
}
|
|
80
|
+
if (d > 0) {
|
|
81
|
+
if (x === prevX) {
|
|
82
|
+
y--;
|
|
83
|
+
mid.push({ t: "ins", a: x, b: y, v: B[y] });
|
|
84
|
+
} else {
|
|
85
|
+
x--;
|
|
86
|
+
mid.push({ t: "del", a: x, b: y, v: A[x] });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
mid.reverse();
|
|
91
|
+
const out = [];
|
|
92
|
+
for (let i = 0; i < start; i++) out.push({ t: "eq", a: i, b: i, v: a[i] });
|
|
93
|
+
for (const o of mid) out.push({ ...o, a: o.a + start, b: o.b + start });
|
|
94
|
+
for (let i = 0; i < a.length - endA; i++) out.push({ t: "eq", a: endA + i, b: endB + i, v: a[endA + i] });
|
|
95
|
+
return out;
|
|
96
|
+
}
|
|
97
|
+
var splitLines = (s) => s === "" ? [] : s.replace(/\r\n?/g, "\n").split("\n");
|
|
98
|
+
function diffLines(a, b) {
|
|
99
|
+
return diffSeq(splitLines(a), splitLines(b));
|
|
100
|
+
}
|
|
101
|
+
function diffWords(a, b) {
|
|
102
|
+
const tok = (s) => s.match(/\s+|[\p{L}\p{N}_]+|[^\s\p{L}\p{N}_]/gu) ?? [];
|
|
103
|
+
const ops = diffSeq(tok(a), tok(b));
|
|
104
|
+
const out = [];
|
|
105
|
+
for (const o of ops) {
|
|
106
|
+
const last = out[out.length - 1];
|
|
107
|
+
if (last && last.t === o.t) last.v += o.v;
|
|
108
|
+
else out.push({ t: o.t, v: o.v });
|
|
109
|
+
}
|
|
110
|
+
return out;
|
|
111
|
+
}
|
|
112
|
+
function hunks(a, b, context = 3) {
|
|
113
|
+
const ops = diffLines(a, b);
|
|
114
|
+
const changed = ops.map((o, i) => o.t === "eq" ? -1 : i).filter((i) => i >= 0);
|
|
115
|
+
if (!changed.length) return [];
|
|
116
|
+
const groups = [];
|
|
117
|
+
for (const i of changed) {
|
|
118
|
+
const last = groups[groups.length - 1];
|
|
119
|
+
if (last && i - last[1] <= context * 2 + 1) last[1] = i;
|
|
120
|
+
else groups.push([i, i]);
|
|
121
|
+
}
|
|
122
|
+
return groups.map(([from, to]) => {
|
|
123
|
+
const s = Math.max(0, from - context);
|
|
124
|
+
const e = Math.min(ops.length - 1, to + context);
|
|
125
|
+
const lines = [];
|
|
126
|
+
const removed = [];
|
|
127
|
+
const added = [];
|
|
128
|
+
for (let i = s; i <= e; i++) {
|
|
129
|
+
const o = ops[i];
|
|
130
|
+
if (o.t === "eq") lines.push({ t: " ", v: o.v, a: o.a + 1, b: o.b + 1 });
|
|
131
|
+
else if (o.t === "del") {
|
|
132
|
+
lines.push({ t: "-", v: o.v, a: o.a + 1 });
|
|
133
|
+
removed.push(o.v);
|
|
134
|
+
} else {
|
|
135
|
+
lines.push({ t: "+", v: o.v, b: o.b + 1 });
|
|
136
|
+
added.push(o.v);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const first = ops[s];
|
|
140
|
+
const aLines = lines.filter((l) => l.t !== "+").length;
|
|
141
|
+
const bLines = lines.filter((l) => l.t !== "-").length;
|
|
142
|
+
return { aStart: aLines ? first.a + 1 : first.a, aLines, bStart: bLines ? first.b + 1 : first.b, bLines, lines, removed, added };
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
function unifiedDiff(a, b, o = {}) {
|
|
146
|
+
const hs = hunks(a, b, o.context ?? 3);
|
|
147
|
+
if (!hs.length) return "";
|
|
148
|
+
const out = [`--- ${o.from ?? "a"}`, `+++ ${o.to ?? "b"}`];
|
|
149
|
+
for (const h of hs) {
|
|
150
|
+
out.push(`@@ -${h.aStart},${h.aLines} +${h.bStart},${h.bLines} @@`);
|
|
151
|
+
for (const l of h.lines) out.push(l.t + l.v);
|
|
152
|
+
}
|
|
153
|
+
return out.join("\n");
|
|
154
|
+
}
|
|
155
|
+
function matchMap(base, other) {
|
|
156
|
+
const m = new Array(base.length).fill(-1);
|
|
157
|
+
for (const o of diffSeq(base, other)) if (o.t === "eq") m[o.a] = o.b;
|
|
158
|
+
return m;
|
|
159
|
+
}
|
|
160
|
+
var sameLines = (x, y) => x.length === y.length && x.every((l, i) => l === y[i]);
|
|
161
|
+
function merge3(base, mine, theirs) {
|
|
162
|
+
const O = splitLines(base);
|
|
163
|
+
const A = splitLines(mine);
|
|
164
|
+
const B = splitLines(theirs);
|
|
165
|
+
const ma = matchMap(O, A);
|
|
166
|
+
const mb = matchMap(O, B);
|
|
167
|
+
const chunks = [];
|
|
168
|
+
const conflicts = [];
|
|
169
|
+
const pushOk = (lines, from) => {
|
|
170
|
+
if (!lines.length) return;
|
|
171
|
+
const last = chunks[chunks.length - 1];
|
|
172
|
+
if (last && last.t === "ok" && last.from === from) last.lines.push(...lines);
|
|
173
|
+
else chunks.push({ t: "ok", lines: [...lines], from });
|
|
174
|
+
};
|
|
175
|
+
let io = 0;
|
|
176
|
+
let ia = 0;
|
|
177
|
+
let ib = 0;
|
|
178
|
+
while (io < O.length || ia < A.length || ib < B.length) {
|
|
179
|
+
if (io < O.length && ma[io] === ia && mb[io] === ib) {
|
|
180
|
+
pushOk([O[io]], "base");
|
|
181
|
+
io++;
|
|
182
|
+
ia++;
|
|
183
|
+
ib++;
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
let o = io;
|
|
187
|
+
while (o < O.length && !(ma[o] >= ia && mb[o] >= ib)) o++;
|
|
188
|
+
const ea = o < O.length ? ma[o] : A.length;
|
|
189
|
+
const eb = o < O.length ? mb[o] : B.length;
|
|
190
|
+
const oc = O.slice(io, o);
|
|
191
|
+
const ac = A.slice(ia, ea);
|
|
192
|
+
const bc = B.slice(ib, eb);
|
|
193
|
+
if (sameLines(ac, oc)) pushOk(bc, "theirs");
|
|
194
|
+
else if (sameLines(bc, oc)) pushOk(ac, "mine");
|
|
195
|
+
else if (sameLines(ac, bc)) pushOk(ac, "both");
|
|
196
|
+
else {
|
|
197
|
+
const c = { t: "conflict", id: conflicts.length, base: oc, mine: ac, theirs: bc };
|
|
198
|
+
chunks.push(c);
|
|
199
|
+
conflicts.push(c);
|
|
200
|
+
}
|
|
201
|
+
io = o;
|
|
202
|
+
ia = ea;
|
|
203
|
+
ib = eb;
|
|
204
|
+
}
|
|
205
|
+
return { chunks, conflicts, text: conflicts.length ? null : chunks.flatMap((c) => c.t === "ok" ? c.lines : []).join("\n") };
|
|
206
|
+
}
|
|
207
|
+
function resolveMerge(r, choices) {
|
|
208
|
+
const out = [];
|
|
209
|
+
for (const c of r.chunks) {
|
|
210
|
+
if (c.t === "ok") out.push(...c.lines);
|
|
211
|
+
else {
|
|
212
|
+
const pick = choices[c.id];
|
|
213
|
+
if (!pick) throw new Error(`conflict ${c.id} has no choice`);
|
|
214
|
+
if (pick === "theirs") out.push(...c.theirs);
|
|
215
|
+
else if (pick === "mine") out.push(...c.mine);
|
|
216
|
+
else out.push(...c.theirs, ...c.mine);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return out.join("\n");
|
|
220
|
+
}
|
|
221
|
+
var stable = (v) => JSON.stringify(v, (_k, x) => x && typeof x === "object" && !Array.isArray(x) ? Object.fromEntries(Object.keys(x).sort().map((k) => [k, x[k]])) : x);
|
|
222
|
+
function flattenFields(v, prefix = "") {
|
|
223
|
+
const out = {};
|
|
224
|
+
for (const [k, x] of Object.entries(v ?? {})) {
|
|
225
|
+
const p = prefix ? `${prefix}.${k}` : k;
|
|
226
|
+
if (x && typeof x === "object" && !Array.isArray(x) && Object.keys(x).length) Object.assign(out, flattenFields(x, p));
|
|
227
|
+
else out[p] = x;
|
|
228
|
+
}
|
|
229
|
+
return out;
|
|
230
|
+
}
|
|
231
|
+
function unflatten(flat) {
|
|
232
|
+
const out = {};
|
|
233
|
+
for (const [p, v] of Object.entries(flat)) {
|
|
234
|
+
if (v === void 0) continue;
|
|
235
|
+
const parts = p.split(".");
|
|
236
|
+
let cur = out;
|
|
237
|
+
for (const part of parts.slice(0, -1)) cur = cur[part] ??= {};
|
|
238
|
+
cur[parts[parts.length - 1]] = v;
|
|
239
|
+
}
|
|
240
|
+
return out;
|
|
241
|
+
}
|
|
242
|
+
function fieldChanges(a, b) {
|
|
243
|
+
const out = [];
|
|
244
|
+
for (const k of ["slug", "title", "summary", "category", "keywords"]) {
|
|
245
|
+
if (stable(a[k]) !== stable(b[k])) out.push({ path: k, from: a[k], to: b[k] });
|
|
246
|
+
}
|
|
247
|
+
const fa = flattenFields(a.fields);
|
|
248
|
+
const fb = flattenFields(b.fields);
|
|
249
|
+
for (const p of [.../* @__PURE__ */ new Set([...Object.keys(fa), ...Object.keys(fb)])].sort()) {
|
|
250
|
+
if (stable(fa[p]) !== stable(fb[p])) out.push({ path: `fields.${p}`, from: fa[p], to: fb[p] });
|
|
251
|
+
}
|
|
252
|
+
return out;
|
|
253
|
+
}
|
|
254
|
+
function mergeDocs(base, mine, theirs) {
|
|
255
|
+
const fieldConflicts = [];
|
|
256
|
+
const autoMerged = [];
|
|
257
|
+
const pick = (path, o, a, b) => {
|
|
258
|
+
const so = stable(o);
|
|
259
|
+
const sa = stable(a);
|
|
260
|
+
const sb = stable(b);
|
|
261
|
+
if (sa === sb) {
|
|
262
|
+
if (sa !== so) autoMerged.push({ path, from: "both" });
|
|
263
|
+
return a;
|
|
264
|
+
}
|
|
265
|
+
if (sa === so) {
|
|
266
|
+
autoMerged.push({ path, from: "theirs" });
|
|
267
|
+
return b;
|
|
268
|
+
}
|
|
269
|
+
if (sb === so) {
|
|
270
|
+
autoMerged.push({ path, from: "mine" });
|
|
271
|
+
return a;
|
|
272
|
+
}
|
|
273
|
+
fieldConflicts.push({ path, base: o, mine: a, theirs: b });
|
|
274
|
+
return b;
|
|
275
|
+
};
|
|
276
|
+
const merged = { ...theirs };
|
|
277
|
+
for (const k of ["slug", "title", "summary", "category", "keywords"]) merged[k] = pick(k, base[k], mine[k], theirs[k]);
|
|
278
|
+
const fo = flattenFields(base.fields);
|
|
279
|
+
const fa = flattenFields(mine.fields);
|
|
280
|
+
const fb = flattenFields(theirs.fields);
|
|
281
|
+
const flat = {};
|
|
282
|
+
for (const p of [.../* @__PURE__ */ new Set([...Object.keys(fo), ...Object.keys(fa), ...Object.keys(fb)])].sort()) flat[p] = pick(`fields.${p}`, fo[p], fa[p], fb[p]);
|
|
283
|
+
merged.fields = unflatten(flat);
|
|
284
|
+
const body = merge3(base.body, mine.body, theirs.body);
|
|
285
|
+
merged.body = body.text ?? theirs.body;
|
|
286
|
+
for (const c of body.chunks) if (c.t === "ok" && c.from !== "base") autoMerged.push({ path: "body", from: c.from });
|
|
287
|
+
return { merged, body, fieldConflicts, autoMerged };
|
|
288
|
+
}
|
|
289
|
+
function resolveDocMerge(m, choices) {
|
|
290
|
+
const out = { ...m.merged, fields: structuredClone(m.merged.fields) };
|
|
291
|
+
out.body = m.body.conflicts.length ? resolveMerge(m.body, choices.body ?? {}) : m.body.text ?? out.body;
|
|
292
|
+
for (const c of m.fieldConflicts) {
|
|
293
|
+
const v = (choices.fields?.[c.path] ?? "theirs") === "mine" ? c.mine : c.theirs;
|
|
294
|
+
if (c.path.startsWith("fields.")) {
|
|
295
|
+
const flat = flattenFields(out.fields);
|
|
296
|
+
flat[c.path.slice(7)] = v;
|
|
297
|
+
out.fields = unflatten(flat);
|
|
298
|
+
} else out[c.path] = v;
|
|
299
|
+
}
|
|
300
|
+
return out;
|
|
301
|
+
}
|
|
302
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
303
|
+
0 && (module.exports = {
|
|
304
|
+
diffLines,
|
|
305
|
+
diffSeq,
|
|
306
|
+
diffWords,
|
|
307
|
+
fieldChanges,
|
|
308
|
+
flattenFields,
|
|
309
|
+
hunks,
|
|
310
|
+
merge3,
|
|
311
|
+
mergeDocs,
|
|
312
|
+
resolveDocMerge,
|
|
313
|
+
resolveMerge,
|
|
314
|
+
splitLines,
|
|
315
|
+
unifiedDiff
|
|
316
|
+
});
|
package/dist/diff.d.cts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Line and word diffs, hunks, unified diff text and a line-level 3-way merge
|
|
3
|
+
* (diff3). No dependencies and no Node APIs, so the admin UI runs the same
|
|
4
|
+
* code in the browser (`@mainsoft/agent-cms/diff`).
|
|
5
|
+
*/
|
|
6
|
+
type DiffOp<T = string> = {
|
|
7
|
+
t: "eq" | "del" | "ins";
|
|
8
|
+
a: number;
|
|
9
|
+
b: number;
|
|
10
|
+
v: T;
|
|
11
|
+
};
|
|
12
|
+
/** Shortest edit script between two sequences (Myers, O((N+M)D)). */
|
|
13
|
+
declare function diffSeq<T>(a: readonly T[], b: readonly T[], eq?: (x: T, y: T) => boolean): DiffOp<T>[];
|
|
14
|
+
declare const splitLines: (s: string) => string[];
|
|
15
|
+
/** Line diff of two texts. */
|
|
16
|
+
declare function diffLines(a: string, b: string): DiffOp[];
|
|
17
|
+
/** Word diff (words and the spaces between them), for highlighting inside a changed line. */
|
|
18
|
+
declare function diffWords(a: string, b: string): {
|
|
19
|
+
t: "eq" | "del" | "ins";
|
|
20
|
+
v: string;
|
|
21
|
+
}[];
|
|
22
|
+
interface HunkLine {
|
|
23
|
+
t: " " | "-" | "+";
|
|
24
|
+
v: string;
|
|
25
|
+
/** 1-based line in the old text (for " " and "-"). */
|
|
26
|
+
a?: number;
|
|
27
|
+
/** 1-based line in the new text (for " " and "+"). */
|
|
28
|
+
b?: number;
|
|
29
|
+
}
|
|
30
|
+
interface Hunk {
|
|
31
|
+
/** 1-based start and length in the old and new text (unified diff header). */
|
|
32
|
+
aStart: number;
|
|
33
|
+
aLines: number;
|
|
34
|
+
bStart: number;
|
|
35
|
+
bLines: number;
|
|
36
|
+
lines: HunkLine[];
|
|
37
|
+
/** Lines removed and added in this hunk (no context). */
|
|
38
|
+
removed: string[];
|
|
39
|
+
added: string[];
|
|
40
|
+
}
|
|
41
|
+
/** Group a line diff into hunks with `context` unchanged lines around each change. */
|
|
42
|
+
declare function hunks(a: string, b: string, context?: number): Hunk[];
|
|
43
|
+
/** `git diff`-style text. */
|
|
44
|
+
declare function unifiedDiff(a: string, b: string, o?: {
|
|
45
|
+
from?: string;
|
|
46
|
+
to?: string;
|
|
47
|
+
context?: number;
|
|
48
|
+
}): string;
|
|
49
|
+
type MergeChunk = {
|
|
50
|
+
t: "ok";
|
|
51
|
+
lines: string[];
|
|
52
|
+
from: "base" | "mine" | "theirs" | "both";
|
|
53
|
+
} | {
|
|
54
|
+
t: "conflict";
|
|
55
|
+
id: number;
|
|
56
|
+
base: string[];
|
|
57
|
+
mine: string[];
|
|
58
|
+
theirs: string[];
|
|
59
|
+
};
|
|
60
|
+
interface MergeResult {
|
|
61
|
+
chunks: MergeChunk[];
|
|
62
|
+
/** Conflicting chunks only (same objects as in `chunks`). */
|
|
63
|
+
conflicts: Extract<MergeChunk, {
|
|
64
|
+
t: "conflict";
|
|
65
|
+
}>[];
|
|
66
|
+
/** The merged text when there is no conflict, else null. */
|
|
67
|
+
text: string | null;
|
|
68
|
+
}
|
|
69
|
+
type MergeChoice = "mine" | "theirs" | "both";
|
|
70
|
+
/**
|
|
71
|
+
* Line-level diff3. Changes on different lines merge by themselves; a region
|
|
72
|
+
* both sides changed differently is a conflict (unless they made the same
|
|
73
|
+
* change). Two edits to the same line, even different words, conflict.
|
|
74
|
+
*/
|
|
75
|
+
declare function merge3(base: string, mine: string, theirs: string): MergeResult;
|
|
76
|
+
/** Build the text from a merge and a choice per conflict id. "both" = theirs first, then mine. */
|
|
77
|
+
declare function resolveMerge(r: MergeResult, choices: Record<number, MergeChoice>): string;
|
|
78
|
+
interface DocLike {
|
|
79
|
+
slug: string;
|
|
80
|
+
title: string;
|
|
81
|
+
summary: string;
|
|
82
|
+
body: string;
|
|
83
|
+
category: string | null;
|
|
84
|
+
keywords: string[];
|
|
85
|
+
fields: Record<string, unknown>;
|
|
86
|
+
}
|
|
87
|
+
/** Leaf paths of a fields object (`tags`, `seo.title`); arrays are leaves. */
|
|
88
|
+
declare function flattenFields(v: Record<string, unknown>, prefix?: string): Record<string, unknown>;
|
|
89
|
+
interface FieldChange {
|
|
90
|
+
/** `title`, `summary`, `category`, `keywords`, `slug` or `fields.<path>`. */
|
|
91
|
+
path: string;
|
|
92
|
+
from: unknown;
|
|
93
|
+
to: unknown;
|
|
94
|
+
}
|
|
95
|
+
/** Field-by-field changes between two documents (the body is not included; diff it with `hunks`). */
|
|
96
|
+
declare function fieldChanges(a: DocLike, b: DocLike): FieldChange[];
|
|
97
|
+
interface FieldConflict {
|
|
98
|
+
path: string;
|
|
99
|
+
base: unknown;
|
|
100
|
+
mine: unknown;
|
|
101
|
+
theirs: unknown;
|
|
102
|
+
}
|
|
103
|
+
interface DocMerge {
|
|
104
|
+
/** The merged document; conflicting fields hold "theirs" until resolved. */
|
|
105
|
+
merged: DocLike;
|
|
106
|
+
body: MergeResult;
|
|
107
|
+
fieldConflicts: FieldConflict[];
|
|
108
|
+
/** Paths each side changed that merged by themselves. */
|
|
109
|
+
autoMerged: {
|
|
110
|
+
path: string;
|
|
111
|
+
from: "mine" | "theirs" | "both";
|
|
112
|
+
}[];
|
|
113
|
+
}
|
|
114
|
+
/** 3-way merge of whole documents: the body by lines, every other value by field path. */
|
|
115
|
+
declare function mergeDocs(base: DocLike, mine: DocLike, theirs: DocLike): DocMerge;
|
|
116
|
+
/** Apply choices to a `mergeDocs` result: body conflicts by id, field conflicts by path. */
|
|
117
|
+
declare function resolveDocMerge(m: DocMerge, choices: {
|
|
118
|
+
body?: Record<number, MergeChoice>;
|
|
119
|
+
fields?: Record<string, "mine" | "theirs">;
|
|
120
|
+
}): DocLike;
|
|
121
|
+
|
|
122
|
+
export { type DiffOp, type DocLike, type DocMerge, type FieldChange, type FieldConflict, type Hunk, type HunkLine, type MergeChoice, type MergeChunk, type MergeResult, diffLines, diffSeq, diffWords, fieldChanges, flattenFields, hunks, merge3, mergeDocs, resolveDocMerge, resolveMerge, splitLines, unifiedDiff };
|
package/dist/diff.d.ts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Line and word diffs, hunks, unified diff text and a line-level 3-way merge
|
|
3
|
+
* (diff3). No dependencies and no Node APIs, so the admin UI runs the same
|
|
4
|
+
* code in the browser (`@mainsoft/agent-cms/diff`).
|
|
5
|
+
*/
|
|
6
|
+
type DiffOp<T = string> = {
|
|
7
|
+
t: "eq" | "del" | "ins";
|
|
8
|
+
a: number;
|
|
9
|
+
b: number;
|
|
10
|
+
v: T;
|
|
11
|
+
};
|
|
12
|
+
/** Shortest edit script between two sequences (Myers, O((N+M)D)). */
|
|
13
|
+
declare function diffSeq<T>(a: readonly T[], b: readonly T[], eq?: (x: T, y: T) => boolean): DiffOp<T>[];
|
|
14
|
+
declare const splitLines: (s: string) => string[];
|
|
15
|
+
/** Line diff of two texts. */
|
|
16
|
+
declare function diffLines(a: string, b: string): DiffOp[];
|
|
17
|
+
/** Word diff (words and the spaces between them), for highlighting inside a changed line. */
|
|
18
|
+
declare function diffWords(a: string, b: string): {
|
|
19
|
+
t: "eq" | "del" | "ins";
|
|
20
|
+
v: string;
|
|
21
|
+
}[];
|
|
22
|
+
interface HunkLine {
|
|
23
|
+
t: " " | "-" | "+";
|
|
24
|
+
v: string;
|
|
25
|
+
/** 1-based line in the old text (for " " and "-"). */
|
|
26
|
+
a?: number;
|
|
27
|
+
/** 1-based line in the new text (for " " and "+"). */
|
|
28
|
+
b?: number;
|
|
29
|
+
}
|
|
30
|
+
interface Hunk {
|
|
31
|
+
/** 1-based start and length in the old and new text (unified diff header). */
|
|
32
|
+
aStart: number;
|
|
33
|
+
aLines: number;
|
|
34
|
+
bStart: number;
|
|
35
|
+
bLines: number;
|
|
36
|
+
lines: HunkLine[];
|
|
37
|
+
/** Lines removed and added in this hunk (no context). */
|
|
38
|
+
removed: string[];
|
|
39
|
+
added: string[];
|
|
40
|
+
}
|
|
41
|
+
/** Group a line diff into hunks with `context` unchanged lines around each change. */
|
|
42
|
+
declare function hunks(a: string, b: string, context?: number): Hunk[];
|
|
43
|
+
/** `git diff`-style text. */
|
|
44
|
+
declare function unifiedDiff(a: string, b: string, o?: {
|
|
45
|
+
from?: string;
|
|
46
|
+
to?: string;
|
|
47
|
+
context?: number;
|
|
48
|
+
}): string;
|
|
49
|
+
type MergeChunk = {
|
|
50
|
+
t: "ok";
|
|
51
|
+
lines: string[];
|
|
52
|
+
from: "base" | "mine" | "theirs" | "both";
|
|
53
|
+
} | {
|
|
54
|
+
t: "conflict";
|
|
55
|
+
id: number;
|
|
56
|
+
base: string[];
|
|
57
|
+
mine: string[];
|
|
58
|
+
theirs: string[];
|
|
59
|
+
};
|
|
60
|
+
interface MergeResult {
|
|
61
|
+
chunks: MergeChunk[];
|
|
62
|
+
/** Conflicting chunks only (same objects as in `chunks`). */
|
|
63
|
+
conflicts: Extract<MergeChunk, {
|
|
64
|
+
t: "conflict";
|
|
65
|
+
}>[];
|
|
66
|
+
/** The merged text when there is no conflict, else null. */
|
|
67
|
+
text: string | null;
|
|
68
|
+
}
|
|
69
|
+
type MergeChoice = "mine" | "theirs" | "both";
|
|
70
|
+
/**
|
|
71
|
+
* Line-level diff3. Changes on different lines merge by themselves; a region
|
|
72
|
+
* both sides changed differently is a conflict (unless they made the same
|
|
73
|
+
* change). Two edits to the same line, even different words, conflict.
|
|
74
|
+
*/
|
|
75
|
+
declare function merge3(base: string, mine: string, theirs: string): MergeResult;
|
|
76
|
+
/** Build the text from a merge and a choice per conflict id. "both" = theirs first, then mine. */
|
|
77
|
+
declare function resolveMerge(r: MergeResult, choices: Record<number, MergeChoice>): string;
|
|
78
|
+
interface DocLike {
|
|
79
|
+
slug: string;
|
|
80
|
+
title: string;
|
|
81
|
+
summary: string;
|
|
82
|
+
body: string;
|
|
83
|
+
category: string | null;
|
|
84
|
+
keywords: string[];
|
|
85
|
+
fields: Record<string, unknown>;
|
|
86
|
+
}
|
|
87
|
+
/** Leaf paths of a fields object (`tags`, `seo.title`); arrays are leaves. */
|
|
88
|
+
declare function flattenFields(v: Record<string, unknown>, prefix?: string): Record<string, unknown>;
|
|
89
|
+
interface FieldChange {
|
|
90
|
+
/** `title`, `summary`, `category`, `keywords`, `slug` or `fields.<path>`. */
|
|
91
|
+
path: string;
|
|
92
|
+
from: unknown;
|
|
93
|
+
to: unknown;
|
|
94
|
+
}
|
|
95
|
+
/** Field-by-field changes between two documents (the body is not included; diff it with `hunks`). */
|
|
96
|
+
declare function fieldChanges(a: DocLike, b: DocLike): FieldChange[];
|
|
97
|
+
interface FieldConflict {
|
|
98
|
+
path: string;
|
|
99
|
+
base: unknown;
|
|
100
|
+
mine: unknown;
|
|
101
|
+
theirs: unknown;
|
|
102
|
+
}
|
|
103
|
+
interface DocMerge {
|
|
104
|
+
/** The merged document; conflicting fields hold "theirs" until resolved. */
|
|
105
|
+
merged: DocLike;
|
|
106
|
+
body: MergeResult;
|
|
107
|
+
fieldConflicts: FieldConflict[];
|
|
108
|
+
/** Paths each side changed that merged by themselves. */
|
|
109
|
+
autoMerged: {
|
|
110
|
+
path: string;
|
|
111
|
+
from: "mine" | "theirs" | "both";
|
|
112
|
+
}[];
|
|
113
|
+
}
|
|
114
|
+
/** 3-way merge of whole documents: the body by lines, every other value by field path. */
|
|
115
|
+
declare function mergeDocs(base: DocLike, mine: DocLike, theirs: DocLike): DocMerge;
|
|
116
|
+
/** Apply choices to a `mergeDocs` result: body conflicts by id, field conflicts by path. */
|
|
117
|
+
declare function resolveDocMerge(m: DocMerge, choices: {
|
|
118
|
+
body?: Record<number, MergeChoice>;
|
|
119
|
+
fields?: Record<string, "mine" | "theirs">;
|
|
120
|
+
}): DocLike;
|
|
121
|
+
|
|
122
|
+
export { type DiffOp, type DocLike, type DocMerge, type FieldChange, type FieldConflict, type Hunk, type HunkLine, type MergeChoice, type MergeChunk, type MergeResult, diffLines, diffSeq, diffWords, fieldChanges, flattenFields, hunks, merge3, mergeDocs, resolveDocMerge, resolveMerge, splitLines, unifiedDiff };
|
package/dist/diff.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
diffLines,
|
|
3
|
+
diffSeq,
|
|
4
|
+
diffWords,
|
|
5
|
+
fieldChanges,
|
|
6
|
+
flattenFields,
|
|
7
|
+
hunks,
|
|
8
|
+
merge3,
|
|
9
|
+
mergeDocs,
|
|
10
|
+
resolveDocMerge,
|
|
11
|
+
resolveMerge,
|
|
12
|
+
splitLines,
|
|
13
|
+
unifiedDiff
|
|
14
|
+
} from "./chunk-AKN7SUXU.js";
|
|
15
|
+
import "./chunk-2NTK7H4W.js";
|
|
16
|
+
export {
|
|
17
|
+
diffLines,
|
|
18
|
+
diffSeq,
|
|
19
|
+
diffWords,
|
|
20
|
+
fieldChanges,
|
|
21
|
+
flattenFields,
|
|
22
|
+
hunks,
|
|
23
|
+
merge3,
|
|
24
|
+
mergeDocs,
|
|
25
|
+
resolveDocMerge,
|
|
26
|
+
resolveMerge,
|
|
27
|
+
splitLines,
|
|
28
|
+
unifiedDiff
|
|
29
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { PgDatabase } from 'drizzle-orm/pg-core';
|
|
2
|
+
import { C as CmsRepo, N as NewDoc, D as DocPatch, a as NewVersion, S as StoredVersion, K as KeyRow, A as AuditQuery } from './repo-BWI2Pkrv.js';
|
|
3
|
+
import { CmsTables } from './tables.js';
|
|
4
|
+
import { CmsDoc, DocStatus, ReviewMark, KeyScope, AuditEntry } from './types.js';
|
|
5
|
+
|
|
6
|
+
/** `CmsRepo` on Postgres via Drizzle (node-postgres, pglite and other `PgDatabase` drivers with transactions). */
|
|
7
|
+
|
|
8
|
+
type Db = PgDatabase<any, any, any>;
|
|
9
|
+
interface DrizzleRepoOptions {
|
|
10
|
+
/** A table set from `cmsTables({ prefix, schema })`. Default: the `cms_*` tables. */
|
|
11
|
+
tables?: CmsTables;
|
|
12
|
+
}
|
|
13
|
+
declare class DrizzleRepo implements CmsRepo {
|
|
14
|
+
readonly db: Db;
|
|
15
|
+
readonly t: CmsTables;
|
|
16
|
+
constructor(db: Db, o?: DrizzleRepoOptions);
|
|
17
|
+
private toDoc;
|
|
18
|
+
private patchRow;
|
|
19
|
+
private toVersion;
|
|
20
|
+
private toKey;
|
|
21
|
+
tx<T>(fn: (repo: CmsRepo) => Promise<T>): Promise<T>;
|
|
22
|
+
findDoc(collection: string, slug: string): Promise<CmsDoc | null>;
|
|
23
|
+
findDocById(id: string): Promise<CmsDoc | null>;
|
|
24
|
+
listDocs(f: {
|
|
25
|
+
collection?: string;
|
|
26
|
+
statuses?: DocStatus[];
|
|
27
|
+
published?: boolean;
|
|
28
|
+
}): Promise<CmsDoc[]>;
|
|
29
|
+
insertDoc(doc: NewDoc): Promise<CmsDoc>;
|
|
30
|
+
updateDoc(id: string, p: DocPatch, expectedVersion?: number): Promise<CmsDoc | null>;
|
|
31
|
+
deleteDoc(id: string): Promise<void>;
|
|
32
|
+
insertVersion(v: NewVersion): Promise<void>;
|
|
33
|
+
listVersions(documentId: string): Promise<StoredVersion[]>;
|
|
34
|
+
getVersion(documentId: string, version: number): Promise<StoredVersion | null>;
|
|
35
|
+
setVersionReviewed(documentId: string, version: number, reviewed: ReviewMark[]): Promise<void>;
|
|
36
|
+
pruneVersions(documentId: string, keep: number, protect: number[]): Promise<void>;
|
|
37
|
+
insertKey(k: {
|
|
38
|
+
name: string;
|
|
39
|
+
prefix: string;
|
|
40
|
+
hash: string;
|
|
41
|
+
scopes: KeyScope[];
|
|
42
|
+
collections: string[] | null;
|
|
43
|
+
createdBy: string | null;
|
|
44
|
+
expiresAt: string | null;
|
|
45
|
+
}): Promise<KeyRow>;
|
|
46
|
+
listKeys(): Promise<KeyRow[]>;
|
|
47
|
+
findKeyByHash(hash: string): Promise<KeyRow | null>;
|
|
48
|
+
touchKey(id: string, at: string): Promise<void>;
|
|
49
|
+
revokeKey(id: string, at: string): Promise<boolean>;
|
|
50
|
+
addHits(ids: string[], day: string, source: string): Promise<void>;
|
|
51
|
+
hitCounts(sinceDay: string, collection?: string): Promise<Map<string, number>>;
|
|
52
|
+
insertAudit(e: Omit<AuditEntry, "id">): Promise<void>;
|
|
53
|
+
listAudit(q: AuditQuery): Promise<{
|
|
54
|
+
id: string;
|
|
55
|
+
at: string;
|
|
56
|
+
actorKind: AuditEntry["actorKind"];
|
|
57
|
+
actorId: string | null;
|
|
58
|
+
actorLabel: string;
|
|
59
|
+
action: AuditEntry["action"];
|
|
60
|
+
collection: string | null;
|
|
61
|
+
slug: string | null;
|
|
62
|
+
version: number | null;
|
|
63
|
+
outcome: AuditEntry["outcome"];
|
|
64
|
+
via: "rest" | "mcp" | "ai" | "cli" | "app" | null;
|
|
65
|
+
detail: Record<string, unknown>;
|
|
66
|
+
}[]>;
|
|
67
|
+
changeStamp(): Promise<string>;
|
|
68
|
+
getMeta(key: string): Promise<{} | null>;
|
|
69
|
+
setMeta(key: string, value: unknown): Promise<void>;
|
|
70
|
+
/** Raw rows of a SQL query, across drivers (node-postgres returns `{ rows }`, pglite too, postgres.js an array). */
|
|
71
|
+
private rows;
|
|
72
|
+
/** What `agent-cms doctor` checks. Read-only. */
|
|
73
|
+
inspect(): Promise<DoctorReport>;
|
|
74
|
+
}
|
|
75
|
+
interface DoctorReport {
|
|
76
|
+
schemaVersion: number | null;
|
|
77
|
+
expectedSchemaVersion: number;
|
|
78
|
+
missingTables: string[];
|
|
79
|
+
missingColumns: string[];
|
|
80
|
+
/** 0.4.0 columns nothing reads any more. */
|
|
81
|
+
legacyColumns: string[];
|
|
82
|
+
/** A `cms_gaps` table from 0.5.x is still there (move it to the app, then drop it yourself). */
|
|
83
|
+
gapsTable: boolean;
|
|
84
|
+
gapsRows: number | null;
|
|
85
|
+
/** Documents whose published pointer is broken. */
|
|
86
|
+
badPublished: number;
|
|
87
|
+
orphanVersions: number;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { type DoctorReport as D, DrizzleRepo as a, type DrizzleRepoOptions as b };
|