@hasna/instructions 0.7.6 → 0.7.7
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 -0
- package/dist/chunks/{apply-xraar7p0.js → apply-33g17x4y.js} +2 -2
- package/dist/chunks/{apply-1cpkx082.js → apply-f9f2sp7y.js} +2 -2
- package/dist/chunks/{index-16j8x10s.js → index-95xa9crj.js} +1369 -36
- package/dist/chunks/{index-src5t3my.js → index-avd1s9kz.js} +1 -1
- package/dist/chunks/{index-x0v4m19f.js → index-c3s70n0a.js} +1 -1
- package/dist/chunks/{index-6qfy0542.js → index-m2mh1xew.js} +1481 -64
- package/dist/chunks/{index-rvb4znxa.js → index-mfrc04ts.js} +2 -2
- package/dist/chunks/{index-ysnp8y58.js → index-wmwrjr19.js} +2 -2
- package/dist/chunks/{local-66fck74w.js → local-7wqy2ywb.js} +1 -1
- package/dist/chunks/{local-jqfx3kbq.js → local-nbck7fs2.js} +1 -1
- package/dist/chunks/{sync-8763n4sc.js → sync-d3be8nk3.js} +3 -3
- package/dist/chunks/{sync-8ca3ew84.js → sync-gzrb11dj.js} +3 -3
- package/dist/cli/index.js +38 -9
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1617 -186
- package/dist/lib/instruction-graph.d.ts.map +1 -1
- package/dist/lib/session-apply.d.ts.map +1 -1
- package/dist/lib/session-refresh.d.ts.map +1 -1
- package/dist/lib/session-render.d.ts +16 -0
- package/dist/lib/session-render.d.ts.map +1 -1
- package/dist/mcp/index.js +8 -7
- package/dist/server/index.js +1352 -25
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -169,6 +169,1332 @@ function boundedReadPage(items, total, options = {}) {
|
|
|
169
169
|
}
|
|
170
170
|
var init_bounded_read = () => {};
|
|
171
171
|
|
|
172
|
+
// ../../node_modules/.bun/marked@18.0.5/node_modules/marked/lib/marked.esm.js
|
|
173
|
+
function M() {
|
|
174
|
+
return { async: false, breaks: false, extensions: null, gfm: true, hooks: null, pedantic: false, renderer: null, silent: false, tokenizer: null, walkTokens: null };
|
|
175
|
+
}
|
|
176
|
+
function N(l) {
|
|
177
|
+
T = l;
|
|
178
|
+
}
|
|
179
|
+
function E(l) {
|
|
180
|
+
let e = [];
|
|
181
|
+
return (t) => {
|
|
182
|
+
let n = Math.max(0, Math.min(3, t - 1)), s = e[n];
|
|
183
|
+
return s || (s = l(n), e[n] = s), s;
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
function d(l, e = "") {
|
|
187
|
+
let t = typeof l == "string" ? l : l.source, n = { replace: (s, r) => {
|
|
188
|
+
let i = typeof r == "string" ? r : r.source;
|
|
189
|
+
return i = i.replace(m.caret, "$1"), t = t.replace(s, i), n;
|
|
190
|
+
}, getRegex: () => new RegExp(t, e) };
|
|
191
|
+
return n;
|
|
192
|
+
}
|
|
193
|
+
function O(l, e) {
|
|
194
|
+
if (e) {
|
|
195
|
+
if (m.escapeTest.test(l))
|
|
196
|
+
return l.replace(m.escapeReplace, ge);
|
|
197
|
+
} else if (m.escapeTestNoEncode.test(l))
|
|
198
|
+
return l.replace(m.escapeReplaceNoEncode, ge);
|
|
199
|
+
return l;
|
|
200
|
+
}
|
|
201
|
+
function V(l) {
|
|
202
|
+
try {
|
|
203
|
+
l = encodeURI(l).replace(m.percentDecode, "%");
|
|
204
|
+
} catch {
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
return l;
|
|
208
|
+
}
|
|
209
|
+
function Y(l, e) {
|
|
210
|
+
let t = l.replace(m.findPipe, (r, i, o) => {
|
|
211
|
+
let u = false, a = i;
|
|
212
|
+
for (;--a >= 0 && o[a] === "\\"; )
|
|
213
|
+
u = !u;
|
|
214
|
+
return u ? "|" : " |";
|
|
215
|
+
}), n = t.split(m.splitPipe), s = 0;
|
|
216
|
+
if (n[0].trim() || n.shift(), n.length > 0 && !n.at(-1)?.trim() && n.pop(), e)
|
|
217
|
+
if (n.length > e)
|
|
218
|
+
n.splice(e);
|
|
219
|
+
else
|
|
220
|
+
for (;n.length < e; )
|
|
221
|
+
n.push("");
|
|
222
|
+
for (;s < n.length; s++)
|
|
223
|
+
n[s] = n[s].trim().replace(m.slashPipe, "|");
|
|
224
|
+
return n;
|
|
225
|
+
}
|
|
226
|
+
function $(l, e, t) {
|
|
227
|
+
let n = l.length;
|
|
228
|
+
if (n === 0)
|
|
229
|
+
return "";
|
|
230
|
+
let s = 0;
|
|
231
|
+
for (;s < n; ) {
|
|
232
|
+
let r = l.charAt(n - s - 1);
|
|
233
|
+
if (r === e && !t)
|
|
234
|
+
s++;
|
|
235
|
+
else if (r !== e && t)
|
|
236
|
+
s++;
|
|
237
|
+
else
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
return l.slice(0, n - s);
|
|
241
|
+
}
|
|
242
|
+
function ee(l) {
|
|
243
|
+
let e = l.split(`
|
|
244
|
+
`), t = e.length - 1;
|
|
245
|
+
for (;t >= 0 && m.blankLine.test(e[t]); )
|
|
246
|
+
t--;
|
|
247
|
+
return e.length - t <= 2 ? l : e.slice(0, t + 1).join(`
|
|
248
|
+
`);
|
|
249
|
+
}
|
|
250
|
+
function fe(l, e) {
|
|
251
|
+
if (l.indexOf(e[1]) === -1)
|
|
252
|
+
return -1;
|
|
253
|
+
let t = 0;
|
|
254
|
+
for (let n = 0;n < l.length; n++)
|
|
255
|
+
if (l[n] === "\\")
|
|
256
|
+
n++;
|
|
257
|
+
else if (l[n] === e[0])
|
|
258
|
+
t++;
|
|
259
|
+
else if (l[n] === e[1] && (t--, t < 0))
|
|
260
|
+
return n;
|
|
261
|
+
return t > 0 ? -2 : -1;
|
|
262
|
+
}
|
|
263
|
+
function me(l, e = 0) {
|
|
264
|
+
let t = e, n = "";
|
|
265
|
+
for (let s of l)
|
|
266
|
+
if (s === "\t") {
|
|
267
|
+
let r = 4 - t % 4;
|
|
268
|
+
n += " ".repeat(r), t += r;
|
|
269
|
+
} else
|
|
270
|
+
n += s, t++;
|
|
271
|
+
return n;
|
|
272
|
+
}
|
|
273
|
+
function xe(l, e, t, n, s) {
|
|
274
|
+
let r = e.href, i = e.title || null, o = l[1].replace(s.other.outputLinkReplace, "$1");
|
|
275
|
+
n.state.inLink = true;
|
|
276
|
+
let u = { type: l[0].charAt(0) === "!" ? "image" : "link", raw: t, href: r, title: i, text: o, tokens: n.inlineTokens(o) };
|
|
277
|
+
return n.state.inLink = false, u;
|
|
278
|
+
}
|
|
279
|
+
function st(l, e, t) {
|
|
280
|
+
let n = l.match(t.other.indentCodeCompensation);
|
|
281
|
+
if (n === null)
|
|
282
|
+
return e;
|
|
283
|
+
let s = n[1];
|
|
284
|
+
return e.split(`
|
|
285
|
+
`).map((r) => {
|
|
286
|
+
let i = r.match(t.other.beginningSpace);
|
|
287
|
+
if (i === null)
|
|
288
|
+
return r;
|
|
289
|
+
let [o] = i;
|
|
290
|
+
return o.length >= s.length ? r.slice(s.length) : r;
|
|
291
|
+
}).join(`
|
|
292
|
+
`);
|
|
293
|
+
}
|
|
294
|
+
function g(l3, e) {
|
|
295
|
+
return z.parse(l3, e);
|
|
296
|
+
}
|
|
297
|
+
var T, _, Te, m, Oe, we, ye, B, Pe, j, oe, ae, Se, F, $e, U, Le, _e, H = "address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul", K, ze, le, Me, W, se, Ee, Ie, Ae, Ce, ue, Be, I, Z, X, De, pe, qe, ve, He, ce, Ze, Ge, he = "^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)", Ne, Qe, je, Fe, Ue = "^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)", Ke, We, Xe, Je, Ve, v, Ye, ke, de, et, ie, J, tt, Q, nt, D, A, rt, ge = (l) => rt[l], w = class {
|
|
298
|
+
options;
|
|
299
|
+
rules;
|
|
300
|
+
lexer;
|
|
301
|
+
constructor(e) {
|
|
302
|
+
this.options = e || T;
|
|
303
|
+
}
|
|
304
|
+
space(e) {
|
|
305
|
+
let t = this.rules.block.newline.exec(e);
|
|
306
|
+
if (t && t[0].length > 0)
|
|
307
|
+
return { type: "space", raw: t[0] };
|
|
308
|
+
}
|
|
309
|
+
code(e) {
|
|
310
|
+
let t = this.rules.block.code.exec(e);
|
|
311
|
+
if (t) {
|
|
312
|
+
let n = this.options.pedantic ? t[0] : ee(t[0]), s = n.replace(this.rules.other.codeRemoveIndent, "");
|
|
313
|
+
return { type: "code", raw: n, codeBlockStyle: "indented", text: s };
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
fences(e) {
|
|
317
|
+
let t = this.rules.block.fences.exec(e);
|
|
318
|
+
if (t) {
|
|
319
|
+
let n = t[0], s = st(n, t[3] || "", this.rules);
|
|
320
|
+
return { type: "code", raw: n, lang: t[2] ? t[2].trim().replace(this.rules.inline.anyPunctuation, "$1") : t[2], text: s };
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
heading(e) {
|
|
324
|
+
let t = this.rules.block.heading.exec(e);
|
|
325
|
+
if (t) {
|
|
326
|
+
let n = t[2].trim();
|
|
327
|
+
if (this.rules.other.endingHash.test(n)) {
|
|
328
|
+
let s = $(n, "#");
|
|
329
|
+
(this.options.pedantic || !s || this.rules.other.endingSpaceChar.test(s)) && (n = s.trim());
|
|
330
|
+
}
|
|
331
|
+
return { type: "heading", raw: $(t[0], `
|
|
332
|
+
`), depth: t[1].length, text: n, tokens: this.lexer.inline(n) };
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
hr(e) {
|
|
336
|
+
let t = this.rules.block.hr.exec(e);
|
|
337
|
+
if (t)
|
|
338
|
+
return { type: "hr", raw: $(t[0], `
|
|
339
|
+
`) };
|
|
340
|
+
}
|
|
341
|
+
blockquote(e) {
|
|
342
|
+
let t = this.rules.block.blockquote.exec(e);
|
|
343
|
+
if (t) {
|
|
344
|
+
let n = $(t[0], `
|
|
345
|
+
`).split(`
|
|
346
|
+
`), s = "", r = "", i = [];
|
|
347
|
+
for (;n.length > 0; ) {
|
|
348
|
+
let o = false, u = [], a;
|
|
349
|
+
for (a = 0;a < n.length; a++)
|
|
350
|
+
if (this.rules.other.blockquoteStart.test(n[a]))
|
|
351
|
+
u.push(n[a]), o = true;
|
|
352
|
+
else if (!o)
|
|
353
|
+
u.push(n[a]);
|
|
354
|
+
else
|
|
355
|
+
break;
|
|
356
|
+
n = n.slice(a);
|
|
357
|
+
let c = u.join(`
|
|
358
|
+
`), p = c.replace(this.rules.other.blockquoteSetextReplace, `
|
|
359
|
+
$1`).replace(this.rules.other.blockquoteSetextReplace2, "");
|
|
360
|
+
s = s ? `${s}
|
|
361
|
+
${c}` : c, r = r ? `${r}
|
|
362
|
+
${p}` : p;
|
|
363
|
+
let k = this.lexer.state.top;
|
|
364
|
+
if (this.lexer.state.top = true, this.lexer.blockTokens(p, i, true), this.lexer.state.top = k, n.length === 0)
|
|
365
|
+
break;
|
|
366
|
+
let h = i.at(-1);
|
|
367
|
+
if (h?.type === "code")
|
|
368
|
+
break;
|
|
369
|
+
if (h?.type === "blockquote") {
|
|
370
|
+
let R = h, f = R.raw + `
|
|
371
|
+
` + n.join(`
|
|
372
|
+
`), S = this.blockquote(f);
|
|
373
|
+
i[i.length - 1] = S, s = s.substring(0, s.length - R.raw.length) + S.raw, r = r.substring(0, r.length - R.text.length) + S.text;
|
|
374
|
+
break;
|
|
375
|
+
} else if (h?.type === "list") {
|
|
376
|
+
let R = h, f = R.raw + `
|
|
377
|
+
` + n.join(`
|
|
378
|
+
`), S = this.list(f);
|
|
379
|
+
i[i.length - 1] = S, s = s.substring(0, s.length - h.raw.length) + S.raw, r = r.substring(0, r.length - R.raw.length) + S.raw, n = f.substring(i.at(-1).raw.length).split(`
|
|
380
|
+
`);
|
|
381
|
+
continue;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
return { type: "blockquote", raw: s, tokens: i, text: r };
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
list(e) {
|
|
388
|
+
let t = this.rules.block.list.exec(e);
|
|
389
|
+
if (t) {
|
|
390
|
+
let n = t[1].trim(), s = n.length > 1, r = { type: "list", raw: "", ordered: s, start: s ? +n.slice(0, -1) : "", loose: false, items: [] };
|
|
391
|
+
n = s ? `\\d{1,9}\\${n.slice(-1)}` : `\\${n}`, this.options.pedantic && (n = s ? n : "[*+-]");
|
|
392
|
+
let i = this.rules.other.listItemRegex(n), o = false;
|
|
393
|
+
for (;e; ) {
|
|
394
|
+
let a = false, c = "", p = "";
|
|
395
|
+
if (!(t = i.exec(e)) || this.rules.block.hr.test(e))
|
|
396
|
+
break;
|
|
397
|
+
c = t[0], e = e.substring(c.length);
|
|
398
|
+
let k = me(t[2].split(`
|
|
399
|
+
`, 1)[0], t[1].length), h = e.split(`
|
|
400
|
+
`, 1)[0], R = !k.trim(), f = 0;
|
|
401
|
+
if (this.options.pedantic ? (f = 2, p = k.trimStart()) : R ? f = t[1].length + 1 : (f = k.search(this.rules.other.nonSpaceChar), f = f > 4 ? 1 : f, p = k.slice(f), f += t[1].length), R && this.rules.other.blankLine.test(h) && (c += h + `
|
|
402
|
+
`, e = e.substring(h.length + 1), a = true), !a) {
|
|
403
|
+
let S = this.rules.other.nextBulletRegex(f), te = this.rules.other.hrRegex(f), ne = this.rules.other.fencesBeginRegex(f), re = this.rules.other.headingBeginRegex(f), be = this.rules.other.htmlBeginRegex(f), Re = this.rules.other.blockquoteBeginRegex(f);
|
|
404
|
+
for (;e; ) {
|
|
405
|
+
let G = e.split(`
|
|
406
|
+
`, 1)[0], C;
|
|
407
|
+
if (h = G, this.options.pedantic ? (h = h.replace(this.rules.other.listReplaceNesting, " "), C = h) : C = h.replace(this.rules.other.tabCharGlobal, " "), ne.test(h) || re.test(h) || be.test(h) || Re.test(h) || S.test(h) || te.test(h))
|
|
408
|
+
break;
|
|
409
|
+
if (C.search(this.rules.other.nonSpaceChar) >= f || !h.trim())
|
|
410
|
+
p += `
|
|
411
|
+
` + C.slice(f);
|
|
412
|
+
else {
|
|
413
|
+
if (R || k.replace(this.rules.other.tabCharGlobal, " ").search(this.rules.other.nonSpaceChar) >= 4 || ne.test(k) || re.test(k) || te.test(k))
|
|
414
|
+
break;
|
|
415
|
+
p += `
|
|
416
|
+
` + h;
|
|
417
|
+
}
|
|
418
|
+
R = !h.trim(), c += G + `
|
|
419
|
+
`, e = e.substring(G.length + 1), k = C.slice(f);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
r.loose || (o ? r.loose = true : this.rules.other.doubleBlankLine.test(c) && (o = true)), r.items.push({ type: "list_item", raw: c, task: !!this.options.gfm && this.rules.other.listIsTask.test(p), loose: false, text: p, tokens: [] }), r.raw += c;
|
|
423
|
+
}
|
|
424
|
+
let u = r.items.at(-1);
|
|
425
|
+
if (u)
|
|
426
|
+
u.raw = u.raw.trimEnd(), u.text = u.text.trimEnd();
|
|
427
|
+
else
|
|
428
|
+
return;
|
|
429
|
+
r.raw = r.raw.trimEnd();
|
|
430
|
+
for (let a of r.items) {
|
|
431
|
+
this.lexer.state.top = false, a.tokens = this.lexer.blockTokens(a.text, []);
|
|
432
|
+
let c = a.tokens[0];
|
|
433
|
+
if (a.task && (c?.type === "text" || c?.type === "paragraph")) {
|
|
434
|
+
a.text = a.text.replace(this.rules.other.listReplaceTask, ""), c.raw = c.raw.replace(this.rules.other.listReplaceTask, ""), c.text = c.text.replace(this.rules.other.listReplaceTask, "");
|
|
435
|
+
for (let k = this.lexer.inlineQueue.length - 1;k >= 0; k--)
|
|
436
|
+
if (this.rules.other.listIsTask.test(this.lexer.inlineQueue[k].src)) {
|
|
437
|
+
this.lexer.inlineQueue[k].src = this.lexer.inlineQueue[k].src.replace(this.rules.other.listReplaceTask, "");
|
|
438
|
+
break;
|
|
439
|
+
}
|
|
440
|
+
let p = this.rules.other.listTaskCheckbox.exec(a.raw);
|
|
441
|
+
if (p) {
|
|
442
|
+
let k = { type: "checkbox", raw: p[0] + " ", checked: p[0] !== "[ ]" };
|
|
443
|
+
a.checked = k.checked, r.loose ? a.tokens[0] && ["paragraph", "text"].includes(a.tokens[0].type) && "tokens" in a.tokens[0] && a.tokens[0].tokens ? (a.tokens[0].raw = k.raw + a.tokens[0].raw, a.tokens[0].text = k.raw + a.tokens[0].text, a.tokens[0].tokens.unshift(k)) : a.tokens.unshift({ type: "paragraph", raw: k.raw, text: k.raw, tokens: [k] }) : a.tokens.unshift(k);
|
|
444
|
+
}
|
|
445
|
+
} else
|
|
446
|
+
a.task && (a.task = false);
|
|
447
|
+
if (!r.loose) {
|
|
448
|
+
let p = a.tokens.filter((h) => h.type === "space"), k = p.length > 0 && p.some((h) => this.rules.other.anyLine.test(h.raw));
|
|
449
|
+
r.loose = k;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
if (r.loose)
|
|
453
|
+
for (let a of r.items) {
|
|
454
|
+
a.loose = true;
|
|
455
|
+
for (let c of a.tokens)
|
|
456
|
+
c.type === "text" && (c.type = "paragraph");
|
|
457
|
+
}
|
|
458
|
+
return r;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
html(e) {
|
|
462
|
+
let t = this.rules.block.html.exec(e);
|
|
463
|
+
if (t) {
|
|
464
|
+
let n = ee(t[0]);
|
|
465
|
+
return { type: "html", block: true, raw: n, pre: t[1] === "pre" || t[1] === "script" || t[1] === "style", text: n };
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
def(e) {
|
|
469
|
+
let t = this.rules.block.def.exec(e);
|
|
470
|
+
if (t) {
|
|
471
|
+
let n = t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal, " "), s = t[2] ? t[2].replace(this.rules.other.hrefBrackets, "$1").replace(this.rules.inline.anyPunctuation, "$1") : "", r = t[3] ? t[3].substring(1, t[3].length - 1).replace(this.rules.inline.anyPunctuation, "$1") : t[3];
|
|
472
|
+
return { type: "def", tag: n, raw: $(t[0], `
|
|
473
|
+
`), href: s, title: r };
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
table(e) {
|
|
477
|
+
let t = this.rules.block.table.exec(e);
|
|
478
|
+
if (!t || !this.rules.other.tableDelimiter.test(t[2]))
|
|
479
|
+
return;
|
|
480
|
+
let n = Y(t[1]), s = t[2].replace(this.rules.other.tableAlignChars, "").split("|"), r = t[3]?.trim() ? t[3].replace(this.rules.other.tableRowBlankLine, "").split(`
|
|
481
|
+
`) : [], i = { type: "table", raw: $(t[0], `
|
|
482
|
+
`), header: [], align: [], rows: [] };
|
|
483
|
+
if (n.length === s.length) {
|
|
484
|
+
for (let o of s)
|
|
485
|
+
this.rules.other.tableAlignRight.test(o) ? i.align.push("right") : this.rules.other.tableAlignCenter.test(o) ? i.align.push("center") : this.rules.other.tableAlignLeft.test(o) ? i.align.push("left") : i.align.push(null);
|
|
486
|
+
for (let o = 0;o < n.length; o++)
|
|
487
|
+
i.header.push({ text: n[o], tokens: this.lexer.inline(n[o]), header: true, align: i.align[o] });
|
|
488
|
+
for (let o of r)
|
|
489
|
+
i.rows.push(Y(o, i.header.length).map((u, a) => ({ text: u, tokens: this.lexer.inline(u), header: false, align: i.align[a] })));
|
|
490
|
+
return i;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
lheading(e) {
|
|
494
|
+
let t = this.rules.block.lheading.exec(e);
|
|
495
|
+
if (t) {
|
|
496
|
+
let n = t[1].trim();
|
|
497
|
+
return { type: "heading", raw: $(t[0], `
|
|
498
|
+
`), depth: t[2].charAt(0) === "=" ? 1 : 2, text: n, tokens: this.lexer.inline(n) };
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
paragraph(e) {
|
|
502
|
+
let t = this.rules.block.paragraph.exec(e);
|
|
503
|
+
if (t) {
|
|
504
|
+
let n = t[1].charAt(t[1].length - 1) === `
|
|
505
|
+
` ? t[1].slice(0, -1) : t[1];
|
|
506
|
+
return { type: "paragraph", raw: t[0], text: n, tokens: this.lexer.inline(n) };
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
text(e) {
|
|
510
|
+
let t = this.rules.block.text.exec(e);
|
|
511
|
+
if (t)
|
|
512
|
+
return { type: "text", raw: t[0], text: t[0], tokens: this.lexer.inline(t[0]) };
|
|
513
|
+
}
|
|
514
|
+
escape(e) {
|
|
515
|
+
let t = this.rules.inline.escape.exec(e);
|
|
516
|
+
if (t)
|
|
517
|
+
return { type: "escape", raw: t[0], text: t[1] };
|
|
518
|
+
}
|
|
519
|
+
tag(e) {
|
|
520
|
+
let t = this.rules.inline.tag.exec(e);
|
|
521
|
+
if (t)
|
|
522
|
+
return !this.lexer.state.inLink && this.rules.other.startATag.test(t[0]) ? this.lexer.state.inLink = true : this.lexer.state.inLink && this.rules.other.endATag.test(t[0]) && (this.lexer.state.inLink = false), !this.lexer.state.inRawBlock && this.rules.other.startPreScriptTag.test(t[0]) ? this.lexer.state.inRawBlock = true : this.lexer.state.inRawBlock && this.rules.other.endPreScriptTag.test(t[0]) && (this.lexer.state.inRawBlock = false), { type: "html", raw: t[0], inLink: this.lexer.state.inLink, inRawBlock: this.lexer.state.inRawBlock, block: false, text: t[0] };
|
|
523
|
+
}
|
|
524
|
+
link(e) {
|
|
525
|
+
let t = this.rules.inline.link.exec(e);
|
|
526
|
+
if (t) {
|
|
527
|
+
let n = t[2].trim();
|
|
528
|
+
if (!this.options.pedantic && this.rules.other.startAngleBracket.test(n)) {
|
|
529
|
+
if (!this.rules.other.endAngleBracket.test(n))
|
|
530
|
+
return;
|
|
531
|
+
let i = $(n.slice(0, -1), "\\");
|
|
532
|
+
if ((n.length - i.length) % 2 === 0)
|
|
533
|
+
return;
|
|
534
|
+
} else {
|
|
535
|
+
let i = fe(t[2], "()");
|
|
536
|
+
if (i === -2)
|
|
537
|
+
return;
|
|
538
|
+
if (i > -1) {
|
|
539
|
+
let u = (t[0].indexOf("!") === 0 ? 5 : 4) + t[1].length + i;
|
|
540
|
+
t[2] = t[2].substring(0, i), t[0] = t[0].substring(0, u).trim(), t[3] = "";
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
let s = t[2], r = "";
|
|
544
|
+
if (this.options.pedantic) {
|
|
545
|
+
let i = this.rules.other.pedanticHrefTitle.exec(s);
|
|
546
|
+
i && (s = i[1], r = i[3]);
|
|
547
|
+
} else
|
|
548
|
+
r = t[3] ? t[3].slice(1, -1) : "";
|
|
549
|
+
return s = s.trim(), this.rules.other.startAngleBracket.test(s) && (this.options.pedantic && !this.rules.other.endAngleBracket.test(n) ? s = s.slice(1) : s = s.slice(1, -1)), xe(t, { href: s && s.replace(this.rules.inline.anyPunctuation, "$1"), title: r && r.replace(this.rules.inline.anyPunctuation, "$1") }, t[0], this.lexer, this.rules);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
reflink(e, t) {
|
|
553
|
+
let n;
|
|
554
|
+
if ((n = this.rules.inline.reflink.exec(e)) || (n = this.rules.inline.nolink.exec(e))) {
|
|
555
|
+
let s = (n[2] || n[1]).replace(this.rules.other.multipleSpaceGlobal, " "), r = t[s.toLowerCase()];
|
|
556
|
+
if (!r) {
|
|
557
|
+
let i = n[0].charAt(0);
|
|
558
|
+
return { type: "text", raw: i, text: i };
|
|
559
|
+
}
|
|
560
|
+
return xe(n, r, n[0], this.lexer, this.rules);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
emStrong(e, t, n = "") {
|
|
564
|
+
let s = this.rules.inline.emStrongLDelim.exec(e);
|
|
565
|
+
if (!s || !s[1] && !s[2] && !s[3] && !s[4] || s[4] && n.match(this.rules.other.unicodeAlphaNumeric))
|
|
566
|
+
return;
|
|
567
|
+
if (!(s[1] || s[3] || "") || !n || this.rules.inline.punctuation.exec(n)) {
|
|
568
|
+
let i = [...s[0]].length - 1, o, u, a = i, c = 0, p = s[0][0] === "*" ? this.rules.inline.emStrongRDelimAst : this.rules.inline.emStrongRDelimUnd;
|
|
569
|
+
for (p.lastIndex = 0, t = t.slice(-1 * e.length + i);(s = p.exec(t)) !== null; ) {
|
|
570
|
+
if (o = s[1] || s[2] || s[3] || s[4] || s[5] || s[6], !o)
|
|
571
|
+
continue;
|
|
572
|
+
if (u = [...o].length, s[3] || s[4]) {
|
|
573
|
+
a += u;
|
|
574
|
+
continue;
|
|
575
|
+
} else if ((s[5] || s[6]) && i % 3 && !((i + u) % 3)) {
|
|
576
|
+
c += u;
|
|
577
|
+
continue;
|
|
578
|
+
}
|
|
579
|
+
if (a -= u, a > 0)
|
|
580
|
+
continue;
|
|
581
|
+
u = Math.min(u, u + a + c);
|
|
582
|
+
let k = [...s[0]][0].length, h = e.slice(0, i + s.index + k + u);
|
|
583
|
+
if (Math.min(i, u) % 2) {
|
|
584
|
+
let f = h.slice(1, -1);
|
|
585
|
+
return { type: "em", raw: h, text: f, tokens: this.lexer.inlineTokens(f) };
|
|
586
|
+
}
|
|
587
|
+
let R = h.slice(2, -2);
|
|
588
|
+
return { type: "strong", raw: h, text: R, tokens: this.lexer.inlineTokens(R) };
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
codespan(e) {
|
|
593
|
+
let t = this.rules.inline.code.exec(e);
|
|
594
|
+
if (t) {
|
|
595
|
+
let n = t[2].replace(this.rules.other.newLineCharGlobal, " "), s = this.rules.other.nonSpaceChar.test(n), r = this.rules.other.startingSpaceChar.test(n) && this.rules.other.endingSpaceChar.test(n);
|
|
596
|
+
return s && r && (n = n.substring(1, n.length - 1)), { type: "codespan", raw: t[0], text: n };
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
br(e) {
|
|
600
|
+
let t = this.rules.inline.br.exec(e);
|
|
601
|
+
if (t)
|
|
602
|
+
return { type: "br", raw: t[0] };
|
|
603
|
+
}
|
|
604
|
+
del(e, t, n = "") {
|
|
605
|
+
let s = this.rules.inline.delLDelim.exec(e);
|
|
606
|
+
if (!s)
|
|
607
|
+
return;
|
|
608
|
+
if (!(s[1] || "") || !n || this.rules.inline.punctuation.exec(n)) {
|
|
609
|
+
let i = [...s[0]].length - 1, o, u, a = i, c = this.rules.inline.delRDelim;
|
|
610
|
+
for (c.lastIndex = 0, t = t.slice(-1 * e.length + i);(s = c.exec(t)) !== null; ) {
|
|
611
|
+
if (o = s[1] || s[2] || s[3] || s[4] || s[5] || s[6], !o || (u = [...o].length, u !== i))
|
|
612
|
+
continue;
|
|
613
|
+
if (s[3] || s[4]) {
|
|
614
|
+
a += u;
|
|
615
|
+
continue;
|
|
616
|
+
}
|
|
617
|
+
if (a -= u, a > 0)
|
|
618
|
+
continue;
|
|
619
|
+
u = Math.min(u, u + a);
|
|
620
|
+
let p = [...s[0]][0].length, k = e.slice(0, i + s.index + p + u), h = k.slice(i, -i);
|
|
621
|
+
return { type: "del", raw: k, text: h, tokens: this.lexer.inlineTokens(h) };
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
autolink(e) {
|
|
626
|
+
let t = this.rules.inline.autolink.exec(e);
|
|
627
|
+
if (t) {
|
|
628
|
+
let n, s;
|
|
629
|
+
return t[2] === "@" ? (n = t[1], s = "mailto:" + n) : (n = t[1], s = n), { type: "link", raw: t[0], text: n, href: s, tokens: [{ type: "text", raw: n, text: n }] };
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
url(e) {
|
|
633
|
+
let t;
|
|
634
|
+
if (t = this.rules.inline.url.exec(e)) {
|
|
635
|
+
let n, s;
|
|
636
|
+
if (t[2] === "@")
|
|
637
|
+
n = t[0], s = "mailto:" + n;
|
|
638
|
+
else {
|
|
639
|
+
let r;
|
|
640
|
+
do
|
|
641
|
+
r = t[0], t[0] = this.rules.inline._backpedal.exec(t[0])?.[0] ?? "";
|
|
642
|
+
while (r !== t[0]);
|
|
643
|
+
n = t[0], t[1] === "www." ? s = "http://" + t[0] : s = t[0];
|
|
644
|
+
}
|
|
645
|
+
return { type: "link", raw: t[0], text: n, href: s, tokens: [{ type: "text", raw: n, text: n }] };
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
inlineText(e) {
|
|
649
|
+
let t = this.rules.inline.text.exec(e);
|
|
650
|
+
if (t) {
|
|
651
|
+
let n = this.lexer.state.inRawBlock;
|
|
652
|
+
return { type: "text", raw: t[0], text: t[0], escaped: n };
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
}, x = class l {
|
|
656
|
+
tokens;
|
|
657
|
+
options;
|
|
658
|
+
state;
|
|
659
|
+
inlineQueue;
|
|
660
|
+
tokenizer;
|
|
661
|
+
constructor(e) {
|
|
662
|
+
this.tokens = [], this.tokens.links = Object.create(null), this.options = e || T, this.options.tokenizer = this.options.tokenizer || new w, this.tokenizer = this.options.tokenizer, this.tokenizer.options = this.options, this.tokenizer.lexer = this, this.inlineQueue = [], this.state = { inLink: false, inRawBlock: false, top: true };
|
|
663
|
+
let t = { other: m, block: D.normal, inline: A.normal };
|
|
664
|
+
this.options.pedantic ? (t.block = D.pedantic, t.inline = A.pedantic) : this.options.gfm && (t.block = D.gfm, this.options.breaks ? t.inline = A.breaks : t.inline = A.gfm), this.tokenizer.rules = t;
|
|
665
|
+
}
|
|
666
|
+
static get rules() {
|
|
667
|
+
return { block: D, inline: A };
|
|
668
|
+
}
|
|
669
|
+
static lex(e, t) {
|
|
670
|
+
return new l(t).lex(e);
|
|
671
|
+
}
|
|
672
|
+
static lexInline(e, t) {
|
|
673
|
+
return new l(t).inlineTokens(e);
|
|
674
|
+
}
|
|
675
|
+
lex(e) {
|
|
676
|
+
e = e.replace(m.carriageReturn, `
|
|
677
|
+
`), this.blockTokens(e, this.tokens);
|
|
678
|
+
for (let t = 0;t < this.inlineQueue.length; t++) {
|
|
679
|
+
let n = this.inlineQueue[t];
|
|
680
|
+
this.inlineTokens(n.src, n.tokens);
|
|
681
|
+
}
|
|
682
|
+
return this.inlineQueue = [], this.tokens;
|
|
683
|
+
}
|
|
684
|
+
blockTokens(e, t = [], n = false) {
|
|
685
|
+
this.tokenizer.lexer = this, this.options.pedantic && (e = e.replace(m.tabCharGlobal, " ").replace(m.spaceLine, ""));
|
|
686
|
+
let s = 1 / 0;
|
|
687
|
+
for (;e; ) {
|
|
688
|
+
if (e.length < s)
|
|
689
|
+
s = e.length;
|
|
690
|
+
else {
|
|
691
|
+
this.infiniteLoopError(e.charCodeAt(0));
|
|
692
|
+
break;
|
|
693
|
+
}
|
|
694
|
+
let r;
|
|
695
|
+
if (this.options.extensions?.block?.some((o) => (r = o.call({ lexer: this }, e, t)) ? (e = e.substring(r.raw.length), t.push(r), true) : false))
|
|
696
|
+
continue;
|
|
697
|
+
if (r = this.tokenizer.space(e)) {
|
|
698
|
+
e = e.substring(r.raw.length);
|
|
699
|
+
let o = t.at(-1);
|
|
700
|
+
r.raw.length === 1 && o !== undefined ? o.raw += `
|
|
701
|
+
` : t.push(r);
|
|
702
|
+
continue;
|
|
703
|
+
}
|
|
704
|
+
if (r = this.tokenizer.code(e)) {
|
|
705
|
+
e = e.substring(r.raw.length);
|
|
706
|
+
let o = t.at(-1);
|
|
707
|
+
o?.type === "paragraph" || o?.type === "text" ? (o.raw += (o.raw.endsWith(`
|
|
708
|
+
`) ? "" : `
|
|
709
|
+
`) + r.raw, o.text += `
|
|
710
|
+
` + r.text, this.inlineQueue.at(-1).src = o.text) : t.push(r);
|
|
711
|
+
continue;
|
|
712
|
+
}
|
|
713
|
+
if (r = this.tokenizer.fences(e)) {
|
|
714
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
715
|
+
continue;
|
|
716
|
+
}
|
|
717
|
+
if (r = this.tokenizer.heading(e)) {
|
|
718
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
719
|
+
continue;
|
|
720
|
+
}
|
|
721
|
+
if (r = this.tokenizer.hr(e)) {
|
|
722
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
723
|
+
continue;
|
|
724
|
+
}
|
|
725
|
+
if (r = this.tokenizer.blockquote(e)) {
|
|
726
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
727
|
+
continue;
|
|
728
|
+
}
|
|
729
|
+
if (r = this.tokenizer.list(e)) {
|
|
730
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
731
|
+
continue;
|
|
732
|
+
}
|
|
733
|
+
if (r = this.tokenizer.html(e)) {
|
|
734
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
735
|
+
continue;
|
|
736
|
+
}
|
|
737
|
+
if (r = this.tokenizer.def(e)) {
|
|
738
|
+
e = e.substring(r.raw.length);
|
|
739
|
+
let o = t.at(-1);
|
|
740
|
+
o?.type === "paragraph" || o?.type === "text" ? (o.raw += (o.raw.endsWith(`
|
|
741
|
+
`) ? "" : `
|
|
742
|
+
`) + r.raw, o.text += `
|
|
743
|
+
` + r.raw, this.inlineQueue.at(-1).src = o.text) : this.tokens.links[r.tag] || (this.tokens.links[r.tag] = { href: r.href, title: r.title }, t.push(r));
|
|
744
|
+
continue;
|
|
745
|
+
}
|
|
746
|
+
if (r = this.tokenizer.table(e)) {
|
|
747
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
748
|
+
continue;
|
|
749
|
+
}
|
|
750
|
+
if (r = this.tokenizer.lheading(e)) {
|
|
751
|
+
e = e.substring(r.raw.length), t.push(r);
|
|
752
|
+
continue;
|
|
753
|
+
}
|
|
754
|
+
let i = e;
|
|
755
|
+
if (this.options.extensions?.startBlock) {
|
|
756
|
+
let o = 1 / 0, u = e.slice(1), a;
|
|
757
|
+
this.options.extensions.startBlock.forEach((c) => {
|
|
758
|
+
a = c.call({ lexer: this }, u), typeof a == "number" && a >= 0 && (o = Math.min(o, a));
|
|
759
|
+
}), o < 1 / 0 && o >= 0 && (i = e.substring(0, o + 1));
|
|
760
|
+
}
|
|
761
|
+
if (this.state.top && (r = this.tokenizer.paragraph(i))) {
|
|
762
|
+
let o = t.at(-1);
|
|
763
|
+
n && o?.type === "paragraph" ? (o.raw += (o.raw.endsWith(`
|
|
764
|
+
`) ? "" : `
|
|
765
|
+
`) + r.raw, o.text += `
|
|
766
|
+
` + r.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = o.text) : t.push(r), n = i.length !== e.length, e = e.substring(r.raw.length);
|
|
767
|
+
continue;
|
|
768
|
+
}
|
|
769
|
+
if (r = this.tokenizer.text(e)) {
|
|
770
|
+
e = e.substring(r.raw.length);
|
|
771
|
+
let o = t.at(-1);
|
|
772
|
+
o?.type === "text" ? (o.raw += (o.raw.endsWith(`
|
|
773
|
+
`) ? "" : `
|
|
774
|
+
`) + r.raw, o.text += `
|
|
775
|
+
` + r.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = o.text) : t.push(r);
|
|
776
|
+
continue;
|
|
777
|
+
}
|
|
778
|
+
if (e) {
|
|
779
|
+
this.infiniteLoopError(e.charCodeAt(0));
|
|
780
|
+
break;
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
return this.state.top = true, t;
|
|
784
|
+
}
|
|
785
|
+
inline(e, t = []) {
|
|
786
|
+
return this.inlineQueue.push({ src: e, tokens: t }), t;
|
|
787
|
+
}
|
|
788
|
+
inlineTokens(e, t = []) {
|
|
789
|
+
this.tokenizer.lexer = this;
|
|
790
|
+
let n = e, s = null;
|
|
791
|
+
if (this.tokens.links) {
|
|
792
|
+
let a = Object.keys(this.tokens.links);
|
|
793
|
+
if (a.length > 0)
|
|
794
|
+
for (;(s = this.tokenizer.rules.inline.reflinkSearch.exec(n)) !== null; )
|
|
795
|
+
a.includes(s[0].slice(s[0].lastIndexOf("[") + 1, -1)) && (n = n.slice(0, s.index) + "[" + "a".repeat(s[0].length - 2) + "]" + n.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex));
|
|
796
|
+
}
|
|
797
|
+
for (;(s = this.tokenizer.rules.inline.anyPunctuation.exec(n)) !== null; )
|
|
798
|
+
n = n.slice(0, s.index) + "++" + n.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);
|
|
799
|
+
let r;
|
|
800
|
+
for (;(s = this.tokenizer.rules.inline.blockSkip.exec(n)) !== null; )
|
|
801
|
+
r = s[2] ? s[2].length : 0, n = n.slice(0, s.index + r) + "[" + "a".repeat(s[0].length - r - 2) + "]" + n.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
|
|
802
|
+
n = this.options.hooks?.emStrongMask?.call({ lexer: this }, n) ?? n;
|
|
803
|
+
let i = false, o = "", u = 1 / 0;
|
|
804
|
+
for (;e; ) {
|
|
805
|
+
if (e.length < u)
|
|
806
|
+
u = e.length;
|
|
807
|
+
else {
|
|
808
|
+
this.infiniteLoopError(e.charCodeAt(0));
|
|
809
|
+
break;
|
|
810
|
+
}
|
|
811
|
+
i || (o = ""), i = false;
|
|
812
|
+
let a;
|
|
813
|
+
if (this.options.extensions?.inline?.some((p) => (a = p.call({ lexer: this }, e, t)) ? (e = e.substring(a.raw.length), t.push(a), true) : false))
|
|
814
|
+
continue;
|
|
815
|
+
if (a = this.tokenizer.escape(e)) {
|
|
816
|
+
e = e.substring(a.raw.length), t.push(a);
|
|
817
|
+
continue;
|
|
818
|
+
}
|
|
819
|
+
if (a = this.tokenizer.tag(e)) {
|
|
820
|
+
e = e.substring(a.raw.length), t.push(a);
|
|
821
|
+
continue;
|
|
822
|
+
}
|
|
823
|
+
if (a = this.tokenizer.link(e)) {
|
|
824
|
+
e = e.substring(a.raw.length), t.push(a);
|
|
825
|
+
continue;
|
|
826
|
+
}
|
|
827
|
+
if (a = this.tokenizer.reflink(e, this.tokens.links)) {
|
|
828
|
+
e = e.substring(a.raw.length);
|
|
829
|
+
let p = t.at(-1);
|
|
830
|
+
a.type === "text" && p?.type === "text" ? (p.raw += a.raw, p.text += a.text) : t.push(a);
|
|
831
|
+
continue;
|
|
832
|
+
}
|
|
833
|
+
if (a = this.tokenizer.emStrong(e, n, o)) {
|
|
834
|
+
e = e.substring(a.raw.length), t.push(a);
|
|
835
|
+
continue;
|
|
836
|
+
}
|
|
837
|
+
if (a = this.tokenizer.codespan(e)) {
|
|
838
|
+
e = e.substring(a.raw.length), t.push(a);
|
|
839
|
+
continue;
|
|
840
|
+
}
|
|
841
|
+
if (a = this.tokenizer.br(e)) {
|
|
842
|
+
e = e.substring(a.raw.length), t.push(a);
|
|
843
|
+
continue;
|
|
844
|
+
}
|
|
845
|
+
if (a = this.tokenizer.del(e, n, o)) {
|
|
846
|
+
e = e.substring(a.raw.length), t.push(a);
|
|
847
|
+
continue;
|
|
848
|
+
}
|
|
849
|
+
if (a = this.tokenizer.autolink(e)) {
|
|
850
|
+
e = e.substring(a.raw.length), t.push(a);
|
|
851
|
+
continue;
|
|
852
|
+
}
|
|
853
|
+
if (!this.state.inLink && (a = this.tokenizer.url(e))) {
|
|
854
|
+
e = e.substring(a.raw.length), t.push(a);
|
|
855
|
+
continue;
|
|
856
|
+
}
|
|
857
|
+
let c = e;
|
|
858
|
+
if (this.options.extensions?.startInline) {
|
|
859
|
+
let p = 1 / 0, k = e.slice(1), h;
|
|
860
|
+
this.options.extensions.startInline.forEach((R) => {
|
|
861
|
+
h = R.call({ lexer: this }, k), typeof h == "number" && h >= 0 && (p = Math.min(p, h));
|
|
862
|
+
}), p < 1 / 0 && p >= 0 && (c = e.substring(0, p + 1));
|
|
863
|
+
}
|
|
864
|
+
if (a = this.tokenizer.inlineText(c)) {
|
|
865
|
+
e = e.substring(a.raw.length), a.raw.slice(-1) !== "_" && (o = a.raw.slice(-1)), i = true;
|
|
866
|
+
let p = t.at(-1);
|
|
867
|
+
p?.type === "text" ? (p.raw += a.raw, p.text += a.text) : t.push(a);
|
|
868
|
+
continue;
|
|
869
|
+
}
|
|
870
|
+
if (e) {
|
|
871
|
+
this.infiniteLoopError(e.charCodeAt(0));
|
|
872
|
+
break;
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
return t;
|
|
876
|
+
}
|
|
877
|
+
infiniteLoopError(e) {
|
|
878
|
+
let t = "Infinite loop on byte: " + e;
|
|
879
|
+
if (this.options.silent)
|
|
880
|
+
console.error(t);
|
|
881
|
+
else
|
|
882
|
+
throw new Error(t);
|
|
883
|
+
}
|
|
884
|
+
}, y = class {
|
|
885
|
+
options;
|
|
886
|
+
parser;
|
|
887
|
+
constructor(e) {
|
|
888
|
+
this.options = e || T;
|
|
889
|
+
}
|
|
890
|
+
space(e) {
|
|
891
|
+
return "";
|
|
892
|
+
}
|
|
893
|
+
code({ text: e, lang: t, escaped: n }) {
|
|
894
|
+
let s = (t || "").match(m.notSpaceStart)?.[0], r = e.replace(m.endingNewline, "") + `
|
|
895
|
+
`;
|
|
896
|
+
return s ? '<pre><code class="language-' + O(s) + '">' + (n ? r : O(r, true)) + `</code></pre>
|
|
897
|
+
` : "<pre><code>" + (n ? r : O(r, true)) + `</code></pre>
|
|
898
|
+
`;
|
|
899
|
+
}
|
|
900
|
+
blockquote({ tokens: e }) {
|
|
901
|
+
return `<blockquote>
|
|
902
|
+
${this.parser.parse(e)}</blockquote>
|
|
903
|
+
`;
|
|
904
|
+
}
|
|
905
|
+
html({ text: e }) {
|
|
906
|
+
return e;
|
|
907
|
+
}
|
|
908
|
+
def(e) {
|
|
909
|
+
return "";
|
|
910
|
+
}
|
|
911
|
+
heading({ tokens: e, depth: t }) {
|
|
912
|
+
return `<h${t}>${this.parser.parseInline(e)}</h${t}>
|
|
913
|
+
`;
|
|
914
|
+
}
|
|
915
|
+
hr(e) {
|
|
916
|
+
return `<hr>
|
|
917
|
+
`;
|
|
918
|
+
}
|
|
919
|
+
list(e) {
|
|
920
|
+
let { ordered: t, start: n } = e, s = "";
|
|
921
|
+
for (let o = 0;o < e.items.length; o++) {
|
|
922
|
+
let u = e.items[o];
|
|
923
|
+
s += this.listitem(u);
|
|
924
|
+
}
|
|
925
|
+
let r = t ? "ol" : "ul", i = t && n !== 1 ? ' start="' + n + '"' : "";
|
|
926
|
+
return "<" + r + i + `>
|
|
927
|
+
` + s + "</" + r + `>
|
|
928
|
+
`;
|
|
929
|
+
}
|
|
930
|
+
listitem(e) {
|
|
931
|
+
return `<li>${this.parser.parse(e.tokens)}</li>
|
|
932
|
+
`;
|
|
933
|
+
}
|
|
934
|
+
checkbox({ checked: e }) {
|
|
935
|
+
return "<input " + (e ? 'checked="" ' : "") + 'disabled="" type="checkbox"> ';
|
|
936
|
+
}
|
|
937
|
+
paragraph({ tokens: e }) {
|
|
938
|
+
return `<p>${this.parser.parseInline(e)}</p>
|
|
939
|
+
`;
|
|
940
|
+
}
|
|
941
|
+
table(e) {
|
|
942
|
+
let t = "", n = "";
|
|
943
|
+
for (let r = 0;r < e.header.length; r++)
|
|
944
|
+
n += this.tablecell(e.header[r]);
|
|
945
|
+
t += this.tablerow({ text: n });
|
|
946
|
+
let s = "";
|
|
947
|
+
for (let r = 0;r < e.rows.length; r++) {
|
|
948
|
+
let i = e.rows[r];
|
|
949
|
+
n = "";
|
|
950
|
+
for (let o = 0;o < i.length; o++)
|
|
951
|
+
n += this.tablecell(i[o]);
|
|
952
|
+
s += this.tablerow({ text: n });
|
|
953
|
+
}
|
|
954
|
+
return s && (s = `<tbody>${s}</tbody>`), `<table>
|
|
955
|
+
<thead>
|
|
956
|
+
` + t + `</thead>
|
|
957
|
+
` + s + `</table>
|
|
958
|
+
`;
|
|
959
|
+
}
|
|
960
|
+
tablerow({ text: e }) {
|
|
961
|
+
return `<tr>
|
|
962
|
+
${e}</tr>
|
|
963
|
+
`;
|
|
964
|
+
}
|
|
965
|
+
tablecell(e) {
|
|
966
|
+
let t = this.parser.parseInline(e.tokens), n = e.header ? "th" : "td";
|
|
967
|
+
return (e.align ? `<${n} align="${e.align}">` : `<${n}>`) + t + `</${n}>
|
|
968
|
+
`;
|
|
969
|
+
}
|
|
970
|
+
strong({ tokens: e }) {
|
|
971
|
+
return `<strong>${this.parser.parseInline(e)}</strong>`;
|
|
972
|
+
}
|
|
973
|
+
em({ tokens: e }) {
|
|
974
|
+
return `<em>${this.parser.parseInline(e)}</em>`;
|
|
975
|
+
}
|
|
976
|
+
codespan({ text: e }) {
|
|
977
|
+
return `<code>${O(e, true)}</code>`;
|
|
978
|
+
}
|
|
979
|
+
br(e) {
|
|
980
|
+
return "<br>";
|
|
981
|
+
}
|
|
982
|
+
del({ tokens: e }) {
|
|
983
|
+
return `<del>${this.parser.parseInline(e)}</del>`;
|
|
984
|
+
}
|
|
985
|
+
link({ href: e, title: t, tokens: n }) {
|
|
986
|
+
let s = this.parser.parseInline(n), r = V(e);
|
|
987
|
+
if (r === null)
|
|
988
|
+
return s;
|
|
989
|
+
e = r;
|
|
990
|
+
let i = '<a href="' + e + '"';
|
|
991
|
+
return t && (i += ' title="' + O(t) + '"'), i += ">" + s + "</a>", i;
|
|
992
|
+
}
|
|
993
|
+
image({ href: e, title: t, text: n, tokens: s }) {
|
|
994
|
+
s && (n = this.parser.parseInline(s, this.parser.textRenderer));
|
|
995
|
+
let r = V(e);
|
|
996
|
+
if (r === null)
|
|
997
|
+
return O(n);
|
|
998
|
+
e = r;
|
|
999
|
+
let i = `<img src="${e}" alt="${O(n)}"`;
|
|
1000
|
+
return t && (i += ` title="${O(t)}"`), i += ">", i;
|
|
1001
|
+
}
|
|
1002
|
+
text(e) {
|
|
1003
|
+
return "tokens" in e && e.tokens ? this.parser.parseInline(e.tokens) : ("escaped" in e) && e.escaped ? e.text : O(e.text);
|
|
1004
|
+
}
|
|
1005
|
+
}, L = class {
|
|
1006
|
+
strong({ text: e }) {
|
|
1007
|
+
return e;
|
|
1008
|
+
}
|
|
1009
|
+
em({ text: e }) {
|
|
1010
|
+
return e;
|
|
1011
|
+
}
|
|
1012
|
+
codespan({ text: e }) {
|
|
1013
|
+
return e;
|
|
1014
|
+
}
|
|
1015
|
+
del({ text: e }) {
|
|
1016
|
+
return e;
|
|
1017
|
+
}
|
|
1018
|
+
html({ text: e }) {
|
|
1019
|
+
return e;
|
|
1020
|
+
}
|
|
1021
|
+
text({ text: e }) {
|
|
1022
|
+
return e;
|
|
1023
|
+
}
|
|
1024
|
+
link({ text: e }) {
|
|
1025
|
+
return "" + e;
|
|
1026
|
+
}
|
|
1027
|
+
image({ text: e }) {
|
|
1028
|
+
return "" + e;
|
|
1029
|
+
}
|
|
1030
|
+
br() {
|
|
1031
|
+
return "";
|
|
1032
|
+
}
|
|
1033
|
+
checkbox({ raw: e }) {
|
|
1034
|
+
return e;
|
|
1035
|
+
}
|
|
1036
|
+
}, b = class l2 {
|
|
1037
|
+
options;
|
|
1038
|
+
renderer;
|
|
1039
|
+
textRenderer;
|
|
1040
|
+
constructor(e) {
|
|
1041
|
+
this.options = e || T, this.options.renderer = this.options.renderer || new y, this.renderer = this.options.renderer, this.renderer.options = this.options, this.renderer.parser = this, this.textRenderer = new L;
|
|
1042
|
+
}
|
|
1043
|
+
static parse(e, t) {
|
|
1044
|
+
return new l2(t).parse(e);
|
|
1045
|
+
}
|
|
1046
|
+
static parseInline(e, t) {
|
|
1047
|
+
return new l2(t).parseInline(e);
|
|
1048
|
+
}
|
|
1049
|
+
parse(e) {
|
|
1050
|
+
this.renderer.parser = this;
|
|
1051
|
+
let t = "";
|
|
1052
|
+
for (let n = 0;n < e.length; n++) {
|
|
1053
|
+
let s = e[n];
|
|
1054
|
+
if (this.options.extensions?.renderers?.[s.type]) {
|
|
1055
|
+
let i = s, o = this.options.extensions.renderers[i.type].call({ parser: this }, i);
|
|
1056
|
+
if (o !== false || !["space", "hr", "heading", "code", "table", "blockquote", "list", "html", "def", "paragraph", "text"].includes(i.type)) {
|
|
1057
|
+
t += o || "";
|
|
1058
|
+
continue;
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
let r = s;
|
|
1062
|
+
switch (r.type) {
|
|
1063
|
+
case "space": {
|
|
1064
|
+
t += this.renderer.space(r);
|
|
1065
|
+
break;
|
|
1066
|
+
}
|
|
1067
|
+
case "hr": {
|
|
1068
|
+
t += this.renderer.hr(r);
|
|
1069
|
+
break;
|
|
1070
|
+
}
|
|
1071
|
+
case "heading": {
|
|
1072
|
+
t += this.renderer.heading(r);
|
|
1073
|
+
break;
|
|
1074
|
+
}
|
|
1075
|
+
case "code": {
|
|
1076
|
+
t += this.renderer.code(r);
|
|
1077
|
+
break;
|
|
1078
|
+
}
|
|
1079
|
+
case "table": {
|
|
1080
|
+
t += this.renderer.table(r);
|
|
1081
|
+
break;
|
|
1082
|
+
}
|
|
1083
|
+
case "blockquote": {
|
|
1084
|
+
t += this.renderer.blockquote(r);
|
|
1085
|
+
break;
|
|
1086
|
+
}
|
|
1087
|
+
case "list": {
|
|
1088
|
+
t += this.renderer.list(r);
|
|
1089
|
+
break;
|
|
1090
|
+
}
|
|
1091
|
+
case "checkbox": {
|
|
1092
|
+
t += this.renderer.checkbox(r);
|
|
1093
|
+
break;
|
|
1094
|
+
}
|
|
1095
|
+
case "html": {
|
|
1096
|
+
t += this.renderer.html(r);
|
|
1097
|
+
break;
|
|
1098
|
+
}
|
|
1099
|
+
case "def": {
|
|
1100
|
+
t += this.renderer.def(r);
|
|
1101
|
+
break;
|
|
1102
|
+
}
|
|
1103
|
+
case "paragraph": {
|
|
1104
|
+
t += this.renderer.paragraph(r);
|
|
1105
|
+
break;
|
|
1106
|
+
}
|
|
1107
|
+
case "text": {
|
|
1108
|
+
t += this.renderer.text(r);
|
|
1109
|
+
break;
|
|
1110
|
+
}
|
|
1111
|
+
default: {
|
|
1112
|
+
let i = 'Token with "' + r.type + '" type was not found.';
|
|
1113
|
+
if (this.options.silent)
|
|
1114
|
+
return console.error(i), "";
|
|
1115
|
+
throw new Error(i);
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
return t;
|
|
1120
|
+
}
|
|
1121
|
+
parseInline(e, t = this.renderer) {
|
|
1122
|
+
this.renderer.parser = this;
|
|
1123
|
+
let n = "";
|
|
1124
|
+
for (let s = 0;s < e.length; s++) {
|
|
1125
|
+
let r = e[s];
|
|
1126
|
+
if (this.options.extensions?.renderers?.[r.type]) {
|
|
1127
|
+
let o = this.options.extensions.renderers[r.type].call({ parser: this }, r);
|
|
1128
|
+
if (o !== false || !["escape", "html", "link", "image", "strong", "em", "codespan", "br", "del", "text"].includes(r.type)) {
|
|
1129
|
+
n += o || "";
|
|
1130
|
+
continue;
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
let i = r;
|
|
1134
|
+
switch (i.type) {
|
|
1135
|
+
case "escape": {
|
|
1136
|
+
n += t.text(i);
|
|
1137
|
+
break;
|
|
1138
|
+
}
|
|
1139
|
+
case "html": {
|
|
1140
|
+
n += t.html(i);
|
|
1141
|
+
break;
|
|
1142
|
+
}
|
|
1143
|
+
case "link": {
|
|
1144
|
+
n += t.link(i);
|
|
1145
|
+
break;
|
|
1146
|
+
}
|
|
1147
|
+
case "image": {
|
|
1148
|
+
n += t.image(i);
|
|
1149
|
+
break;
|
|
1150
|
+
}
|
|
1151
|
+
case "checkbox": {
|
|
1152
|
+
n += t.checkbox(i);
|
|
1153
|
+
break;
|
|
1154
|
+
}
|
|
1155
|
+
case "strong": {
|
|
1156
|
+
n += t.strong(i);
|
|
1157
|
+
break;
|
|
1158
|
+
}
|
|
1159
|
+
case "em": {
|
|
1160
|
+
n += t.em(i);
|
|
1161
|
+
break;
|
|
1162
|
+
}
|
|
1163
|
+
case "codespan": {
|
|
1164
|
+
n += t.codespan(i);
|
|
1165
|
+
break;
|
|
1166
|
+
}
|
|
1167
|
+
case "br": {
|
|
1168
|
+
n += t.br(i);
|
|
1169
|
+
break;
|
|
1170
|
+
}
|
|
1171
|
+
case "del": {
|
|
1172
|
+
n += t.del(i);
|
|
1173
|
+
break;
|
|
1174
|
+
}
|
|
1175
|
+
case "text": {
|
|
1176
|
+
n += t.text(i);
|
|
1177
|
+
break;
|
|
1178
|
+
}
|
|
1179
|
+
default: {
|
|
1180
|
+
let o = 'Token with "' + i.type + '" type was not found.';
|
|
1181
|
+
if (this.options.silent)
|
|
1182
|
+
return console.error(o), "";
|
|
1183
|
+
throw new Error(o);
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
return n;
|
|
1188
|
+
}
|
|
1189
|
+
}, P, q = class {
|
|
1190
|
+
defaults = M();
|
|
1191
|
+
options = this.setOptions;
|
|
1192
|
+
parse = this.parseMarkdown(true);
|
|
1193
|
+
parseInline = this.parseMarkdown(false);
|
|
1194
|
+
Parser = b;
|
|
1195
|
+
Renderer = y;
|
|
1196
|
+
TextRenderer = L;
|
|
1197
|
+
Lexer = x;
|
|
1198
|
+
Tokenizer = w;
|
|
1199
|
+
Hooks = P;
|
|
1200
|
+
constructor(...e) {
|
|
1201
|
+
this.use(...e);
|
|
1202
|
+
}
|
|
1203
|
+
walkTokens(e, t) {
|
|
1204
|
+
let n = [];
|
|
1205
|
+
for (let s of e)
|
|
1206
|
+
switch (n = n.concat(t.call(this, s)), s.type) {
|
|
1207
|
+
case "table": {
|
|
1208
|
+
let r = s;
|
|
1209
|
+
for (let i of r.header)
|
|
1210
|
+
n = n.concat(this.walkTokens(i.tokens, t));
|
|
1211
|
+
for (let i of r.rows)
|
|
1212
|
+
for (let o of i)
|
|
1213
|
+
n = n.concat(this.walkTokens(o.tokens, t));
|
|
1214
|
+
break;
|
|
1215
|
+
}
|
|
1216
|
+
case "list": {
|
|
1217
|
+
let r = s;
|
|
1218
|
+
n = n.concat(this.walkTokens(r.items, t));
|
|
1219
|
+
break;
|
|
1220
|
+
}
|
|
1221
|
+
default: {
|
|
1222
|
+
let r = s;
|
|
1223
|
+
this.defaults.extensions?.childTokens?.[r.type] ? this.defaults.extensions.childTokens[r.type].forEach((i) => {
|
|
1224
|
+
let o = r[i].flat(1 / 0);
|
|
1225
|
+
n = n.concat(this.walkTokens(o, t));
|
|
1226
|
+
}) : r.tokens && (n = n.concat(this.walkTokens(r.tokens, t)));
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
return n;
|
|
1230
|
+
}
|
|
1231
|
+
use(...e) {
|
|
1232
|
+
let t = this.defaults.extensions || { renderers: {}, childTokens: {} };
|
|
1233
|
+
return e.forEach((n) => {
|
|
1234
|
+
let s = { ...n };
|
|
1235
|
+
if (s.async = this.defaults.async || s.async || false, n.extensions && (n.extensions.forEach((r) => {
|
|
1236
|
+
if (!r.name)
|
|
1237
|
+
throw new Error("extension name required");
|
|
1238
|
+
if ("renderer" in r) {
|
|
1239
|
+
let i = t.renderers[r.name];
|
|
1240
|
+
i ? t.renderers[r.name] = function(...o) {
|
|
1241
|
+
let u = r.renderer.apply(this, o);
|
|
1242
|
+
return u === false && (u = i.apply(this, o)), u;
|
|
1243
|
+
} : t.renderers[r.name] = r.renderer;
|
|
1244
|
+
}
|
|
1245
|
+
if ("tokenizer" in r) {
|
|
1246
|
+
if (!r.level || r.level !== "block" && r.level !== "inline")
|
|
1247
|
+
throw new Error("extension level must be 'block' or 'inline'");
|
|
1248
|
+
let i = t[r.level];
|
|
1249
|
+
i ? i.unshift(r.tokenizer) : t[r.level] = [r.tokenizer], r.start && (r.level === "block" ? t.startBlock ? t.startBlock.push(r.start) : t.startBlock = [r.start] : r.level === "inline" && (t.startInline ? t.startInline.push(r.start) : t.startInline = [r.start]));
|
|
1250
|
+
}
|
|
1251
|
+
"childTokens" in r && r.childTokens && (t.childTokens[r.name] = r.childTokens);
|
|
1252
|
+
}), s.extensions = t), n.renderer) {
|
|
1253
|
+
let r = this.defaults.renderer || new y(this.defaults);
|
|
1254
|
+
for (let i in n.renderer) {
|
|
1255
|
+
if (!(i in r))
|
|
1256
|
+
throw new Error(`renderer '${i}' does not exist`);
|
|
1257
|
+
if (["options", "parser"].includes(i))
|
|
1258
|
+
continue;
|
|
1259
|
+
let o = i, u = n.renderer[o], a = r[o];
|
|
1260
|
+
r[o] = (...c) => {
|
|
1261
|
+
let p = u.apply(r, c);
|
|
1262
|
+
return p === false && (p = a.apply(r, c)), p || "";
|
|
1263
|
+
};
|
|
1264
|
+
}
|
|
1265
|
+
s.renderer = r;
|
|
1266
|
+
}
|
|
1267
|
+
if (n.tokenizer) {
|
|
1268
|
+
let r = this.defaults.tokenizer || new w(this.defaults);
|
|
1269
|
+
for (let i in n.tokenizer) {
|
|
1270
|
+
if (!(i in r))
|
|
1271
|
+
throw new Error(`tokenizer '${i}' does not exist`);
|
|
1272
|
+
if (["options", "rules", "lexer"].includes(i))
|
|
1273
|
+
continue;
|
|
1274
|
+
let o = i, u = n.tokenizer[o], a = r[o];
|
|
1275
|
+
r[o] = (...c) => {
|
|
1276
|
+
let p = u.apply(r, c);
|
|
1277
|
+
return p === false && (p = a.apply(r, c)), p;
|
|
1278
|
+
};
|
|
1279
|
+
}
|
|
1280
|
+
s.tokenizer = r;
|
|
1281
|
+
}
|
|
1282
|
+
if (n.hooks) {
|
|
1283
|
+
let r = this.defaults.hooks || new P;
|
|
1284
|
+
for (let i in n.hooks) {
|
|
1285
|
+
if (!(i in r))
|
|
1286
|
+
throw new Error(`hook '${i}' does not exist`);
|
|
1287
|
+
if (["options", "block"].includes(i))
|
|
1288
|
+
continue;
|
|
1289
|
+
let o = i, u = n.hooks[o], a = r[o];
|
|
1290
|
+
P.passThroughHooks.has(i) ? r[o] = (c) => {
|
|
1291
|
+
if (this.defaults.async && P.passThroughHooksRespectAsync.has(i))
|
|
1292
|
+
return (async () => {
|
|
1293
|
+
let k = await u.call(r, c);
|
|
1294
|
+
return a.call(r, k);
|
|
1295
|
+
})();
|
|
1296
|
+
let p = u.call(r, c);
|
|
1297
|
+
return a.call(r, p);
|
|
1298
|
+
} : r[o] = (...c) => {
|
|
1299
|
+
if (this.defaults.async)
|
|
1300
|
+
return (async () => {
|
|
1301
|
+
let k = await u.apply(r, c);
|
|
1302
|
+
return k === false && (k = await a.apply(r, c)), k;
|
|
1303
|
+
})();
|
|
1304
|
+
let p = u.apply(r, c);
|
|
1305
|
+
return p === false && (p = a.apply(r, c)), p;
|
|
1306
|
+
};
|
|
1307
|
+
}
|
|
1308
|
+
s.hooks = r;
|
|
1309
|
+
}
|
|
1310
|
+
if (n.walkTokens) {
|
|
1311
|
+
let r = this.defaults.walkTokens, i = n.walkTokens;
|
|
1312
|
+
s.walkTokens = function(o) {
|
|
1313
|
+
let u = [];
|
|
1314
|
+
return u.push(i.call(this, o)), r && (u = u.concat(r.call(this, o))), u;
|
|
1315
|
+
};
|
|
1316
|
+
}
|
|
1317
|
+
this.defaults = { ...this.defaults, ...s };
|
|
1318
|
+
}), this;
|
|
1319
|
+
}
|
|
1320
|
+
setOptions(e) {
|
|
1321
|
+
return this.defaults = { ...this.defaults, ...e }, this;
|
|
1322
|
+
}
|
|
1323
|
+
lexer(e, t) {
|
|
1324
|
+
return x.lex(e, t ?? this.defaults);
|
|
1325
|
+
}
|
|
1326
|
+
parser(e, t) {
|
|
1327
|
+
return b.parse(e, t ?? this.defaults);
|
|
1328
|
+
}
|
|
1329
|
+
parseMarkdown(e) {
|
|
1330
|
+
return (n, s) => {
|
|
1331
|
+
let r = { ...s }, i = { ...this.defaults, ...r }, o = this.onError(!!i.silent, !!i.async);
|
|
1332
|
+
if (this.defaults.async === true && r.async === false)
|
|
1333
|
+
return o(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));
|
|
1334
|
+
if (typeof n > "u" || n === null)
|
|
1335
|
+
return o(new Error("marked(): input parameter is undefined or null"));
|
|
1336
|
+
if (typeof n != "string")
|
|
1337
|
+
return o(new Error("marked(): input parameter is of type " + Object.prototype.toString.call(n) + ", string expected"));
|
|
1338
|
+
if (i.hooks && (i.hooks.options = i, i.hooks.block = e), i.async)
|
|
1339
|
+
return (async () => {
|
|
1340
|
+
let u = i.hooks ? await i.hooks.preprocess(n) : n, c = await (i.hooks ? await i.hooks.provideLexer(e) : e ? x.lex : x.lexInline)(u, i), p = i.hooks ? await i.hooks.processAllTokens(c) : c;
|
|
1341
|
+
i.walkTokens && await Promise.all(this.walkTokens(p, i.walkTokens));
|
|
1342
|
+
let h = await (i.hooks ? await i.hooks.provideParser(e) : e ? b.parse : b.parseInline)(p, i);
|
|
1343
|
+
return i.hooks ? await i.hooks.postprocess(h) : h;
|
|
1344
|
+
})().catch(o);
|
|
1345
|
+
try {
|
|
1346
|
+
i.hooks && (n = i.hooks.preprocess(n));
|
|
1347
|
+
let a = (i.hooks ? i.hooks.provideLexer(e) : e ? x.lex : x.lexInline)(n, i);
|
|
1348
|
+
i.hooks && (a = i.hooks.processAllTokens(a)), i.walkTokens && this.walkTokens(a, i.walkTokens);
|
|
1349
|
+
let p = (i.hooks ? i.hooks.provideParser(e) : e ? b.parse : b.parseInline)(a, i);
|
|
1350
|
+
return i.hooks && (p = i.hooks.postprocess(p)), p;
|
|
1351
|
+
} catch (u) {
|
|
1352
|
+
return o(u);
|
|
1353
|
+
}
|
|
1354
|
+
};
|
|
1355
|
+
}
|
|
1356
|
+
onError(e, t) {
|
|
1357
|
+
return (n) => {
|
|
1358
|
+
if (n.message += `
|
|
1359
|
+
Please report this to https://github.com/markedjs/marked.`, e) {
|
|
1360
|
+
let s = "<p>An error occurred:</p><pre>" + O(n.message + "", true) + "</pre>";
|
|
1361
|
+
return t ? Promise.resolve(s) : s;
|
|
1362
|
+
}
|
|
1363
|
+
if (t)
|
|
1364
|
+
return Promise.reject(n);
|
|
1365
|
+
throw n;
|
|
1366
|
+
};
|
|
1367
|
+
}
|
|
1368
|
+
}, z, Ft, Ut, Kt, Wt, Xt, Vt, Yt;
|
|
1369
|
+
var init_marked_esm = __esm(() => {
|
|
1370
|
+
T = M();
|
|
1371
|
+
_ = { exec: () => null };
|
|
1372
|
+
Te = ((l = "") => {
|
|
1373
|
+
try {
|
|
1374
|
+
return !!new RegExp("(?<=1)(?<!1)" + l);
|
|
1375
|
+
} catch {
|
|
1376
|
+
return false;
|
|
1377
|
+
}
|
|
1378
|
+
})();
|
|
1379
|
+
m = { codeRemoveIndent: /^(?: {1,4}| {0,3}\t)/gm, outputLinkReplace: /\\([\[\]])/g, indentCodeCompensation: /^(\s+)(?:```)/, beginningSpace: /^\s+/, endingHash: /#$/, startingSpaceChar: /^ /, endingSpaceChar: / $/, nonSpaceChar: /[^ ]/, newLineCharGlobal: /\n/g, tabCharGlobal: /\t/g, multipleSpaceGlobal: /\s+/g, blankLine: /^[ \t]*$/, doubleBlankLine: /\n[ \t]*\n[ \t]*$/, blockquoteStart: /^ {0,3}>/, blockquoteSetextReplace: /\n {0,3}((?:=+|-+) *)(?=\n|$)/g, blockquoteSetextReplace2: /^ {0,3}>[ \t]?/gm, listReplaceNesting: /^ {1,4}(?=( {4})*[^ ])/g, listIsTask: /^\[[ xX]\] +\S/, listReplaceTask: /^\[[ xX]\] +/, listTaskCheckbox: /\[[ xX]\]/, anyLine: /\n.*\n/, hrefBrackets: /^<(.*)>$/, tableDelimiter: /[:|]/, tableAlignChars: /^\||\| *$/g, tableRowBlankLine: /\n[ \t]*$/, tableAlignRight: /^ *-+: *$/, tableAlignCenter: /^ *:-+: *$/, tableAlignLeft: /^ *:-+ *$/, startATag: /^<a /i, endATag: /^<\/a>/i, startPreScriptTag: /^<(pre|code|kbd|script)(\s|>)/i, endPreScriptTag: /^<\/(pre|code|kbd|script)(\s|>)/i, startAngleBracket: /^</, endAngleBracket: />$/, pedanticHrefTitle: /^([^'"]*[^\s])\s+(['"])(.*)\2/, unicodeAlphaNumeric: /[\p{L}\p{N}]/u, escapeTest: /[&<>"']/, escapeReplace: /[&<>"']/g, escapeTestNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/, escapeReplaceNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g, caret: /(^|[^\[])\^/g, percentDecode: /%25/g, findPipe: /\|/g, splitPipe: / \|/, slashPipe: /\\\|/g, carriageReturn: /\r\n|\r/g, spaceLine: /^ +$/gm, notSpaceStart: /^\S*/, endingNewline: /\n$/, listItemRegex: (l) => new RegExp(`^( {0,3}${l})((?:[ ][^\\n]*)?(?:\\n|$))`), nextBulletRegex: E((l) => new RegExp(`^ {0,${l}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)), hrRegex: E((l) => new RegExp(`^ {0,${l}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`)), fencesBeginRegex: E((l) => new RegExp(`^ {0,${l}}(?:\`\`\`|~~~)`)), headingBeginRegex: E((l) => new RegExp(`^ {0,${l}}#`)), htmlBeginRegex: E((l) => new RegExp(`^ {0,${l}}<(?:[a-z].*>|!--)`, "i")), blockquoteBeginRegex: E((l) => new RegExp(`^ {0,${l}}>`)) };
|
|
1380
|
+
Oe = /^(?:[ \t]*(?:\n|$))+/;
|
|
1381
|
+
we = /^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/;
|
|
1382
|
+
ye = /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/;
|
|
1383
|
+
B = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/;
|
|
1384
|
+
Pe = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/;
|
|
1385
|
+
j = / {0,3}(?:[*+-]|\d{1,9}[.)])/;
|
|
1386
|
+
oe = /^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/;
|
|
1387
|
+
ae = d(oe).replace(/bull/g, j).replace(/blockCode/g, /(?: {4}| {0,3}\t)/).replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g, / {0,3}>/).replace(/heading/g, / {0,3}#{1,6}/).replace(/html/g, / {0,3}<[^\n>]+>\n/).replace(/\|table/g, "").getRegex();
|
|
1388
|
+
Se = d(oe).replace(/bull/g, j).replace(/blockCode/g, /(?: {4}| {0,3}\t)/).replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g, / {0,3}>/).replace(/heading/g, / {0,3}#{1,6}/).replace(/html/g, / {0,3}<[^\n>]+>\n/).replace(/table/g, / {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex();
|
|
1389
|
+
F = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/;
|
|
1390
|
+
$e = /^[^\n]+/;
|
|
1391
|
+
U = /(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/;
|
|
1392
|
+
Le = d(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label", U).replace("title", /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex();
|
|
1393
|
+
_e = d(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g, j).getRegex();
|
|
1394
|
+
K = /<!--(?:-?>|[\s\S]*?(?:-->|$))/;
|
|
1395
|
+
ze = d("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$))", "i").replace("comment", K).replace("tag", H).replace("attribute", / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex();
|
|
1396
|
+
le = d(F).replace("hr", B).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("|table", "").replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", H).getRegex();
|
|
1397
|
+
Me = d(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph", le).getRegex();
|
|
1398
|
+
W = { blockquote: Me, code: we, def: Le, fences: ye, heading: Pe, hr: B, html: ze, lheading: ae, list: _e, newline: Oe, paragraph: le, table: _, text: $e };
|
|
1399
|
+
se = d("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr", B).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("blockquote", " {0,3}>").replace("code", "(?: {4}| {0,3}\t)[^\\n]").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", H).getRegex();
|
|
1400
|
+
Ee = { ...W, lheading: Se, table: se, paragraph: d(F).replace("hr", B).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("table", se).replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", H).getRegex() };
|
|
1401
|
+
Ie = { ...W, html: d(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment", K).replace(/tag/g, "(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(), def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/, heading: /^(#{1,6})(.*)(?:\n+|$)/, fences: _, lheading: /^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/, paragraph: d(F).replace("hr", B).replace("heading", ` *#{1,6} *[^
|
|
1402
|
+
]`).replace("lheading", ae).replace("|table", "").replace("blockquote", " {0,3}>").replace("|fences", "").replace("|list", "").replace("|html", "").replace("|tag", "").getRegex() };
|
|
1403
|
+
Ae = /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/;
|
|
1404
|
+
Ce = /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/;
|
|
1405
|
+
ue = /^( {2,}|\\)\n(?!\s*$)/;
|
|
1406
|
+
Be = /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/;
|
|
1407
|
+
I = /[\p{P}\p{S}]/u;
|
|
1408
|
+
Z = /[\s\p{P}\p{S}]/u;
|
|
1409
|
+
X = /[^\s\p{P}\p{S}]/u;
|
|
1410
|
+
De = d(/^((?![*_])punctSpace)/, "u").replace(/punctSpace/g, Z).getRegex();
|
|
1411
|
+
pe = /(?!~)[\p{P}\p{S}]/u;
|
|
1412
|
+
qe = /(?!~)[\s\p{P}\p{S}]/u;
|
|
1413
|
+
ve = /(?:[^\s\p{P}\p{S}]|~)/u;
|
|
1414
|
+
He = d(/link|precode-code|html/, "g").replace("link", /\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-", Te ? "(?<!`)()" : "(^^|[^`])").replace("code", /(?<b>`+)[^`]+\k<b>(?!`)/).replace("html", /<(?! )[^<>]*?>/).getRegex();
|
|
1415
|
+
ce = /^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/;
|
|
1416
|
+
Ze = d(ce, "u").replace(/punct/g, I).getRegex();
|
|
1417
|
+
Ge = d(ce, "u").replace(/punct/g, pe).getRegex();
|
|
1418
|
+
Ne = d(he, "gu").replace(/notPunctSpace/g, X).replace(/punctSpace/g, Z).replace(/punct/g, I).getRegex();
|
|
1419
|
+
Qe = d(he, "gu").replace(/notPunctSpace/g, ve).replace(/punctSpace/g, qe).replace(/punct/g, pe).getRegex();
|
|
1420
|
+
je = d("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)", "gu").replace(/notPunctSpace/g, X).replace(/punctSpace/g, Z).replace(/punct/g, I).getRegex();
|
|
1421
|
+
Fe = d(/^~~?(?:((?!~)punct)|[^\s~])/, "u").replace(/punct/g, I).getRegex();
|
|
1422
|
+
Ke = d(Ue, "gu").replace(/notPunctSpace/g, X).replace(/punctSpace/g, Z).replace(/punct/g, I).getRegex();
|
|
1423
|
+
We = d(/\\(punct)/, "gu").replace(/punct/g, I).getRegex();
|
|
1424
|
+
Xe = d(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme", /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email", /[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex();
|
|
1425
|
+
Je = d(K).replace("(?:-->|$)", "-->").getRegex();
|
|
1426
|
+
Ve = d("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment", Je).replace("attribute", /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex();
|
|
1427
|
+
v = /(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/;
|
|
1428
|
+
Ye = d(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label", v).replace("href", /<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title", /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex();
|
|
1429
|
+
ke = d(/^!?\[(label)\]\[(ref)\]/).replace("label", v).replace("ref", U).getRegex();
|
|
1430
|
+
de = d(/^!?\[(ref)\](?:\[\])?/).replace("ref", U).getRegex();
|
|
1431
|
+
et = d("reflink|nolink(?!\\()", "g").replace("reflink", ke).replace("nolink", de).getRegex();
|
|
1432
|
+
ie = /[hH][tT][tT][pP][sS]?|[fF][tT][pP]/;
|
|
1433
|
+
J = { _backpedal: _, anyPunctuation: We, autolink: Xe, blockSkip: He, br: ue, code: Ce, del: _, delLDelim: _, delRDelim: _, emStrongLDelim: Ze, emStrongRDelimAst: Ne, emStrongRDelimUnd: je, escape: Ae, link: Ye, nolink: de, punctuation: De, reflink: ke, reflinkSearch: et, tag: Ve, text: Be, url: _ };
|
|
1434
|
+
tt = { ...J, link: d(/^!?\[(label)\]\((.*?)\)/).replace("label", v).getRegex(), reflink: d(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label", v).getRegex() };
|
|
1435
|
+
Q = { ...J, emStrongRDelimAst: Qe, emStrongLDelim: Ge, delLDelim: Fe, delRDelim: Ke, url: d(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol", ie).replace("email", /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(), _backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/, del: /^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/, text: d(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol", ie).getRegex() };
|
|
1436
|
+
nt = { ...Q, br: d(ue).replace("{2,}", "*").getRegex(), text: d(Q.text).replace("\\b_", "\\b_| {2,}\\n").replace(/\{2,\}/g, "*").getRegex() };
|
|
1437
|
+
D = { normal: W, gfm: Ee, pedantic: Ie };
|
|
1438
|
+
A = { normal: J, gfm: Q, breaks: nt, pedantic: tt };
|
|
1439
|
+
rt = { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" };
|
|
1440
|
+
P = class {
|
|
1441
|
+
options;
|
|
1442
|
+
block;
|
|
1443
|
+
constructor(e) {
|
|
1444
|
+
this.options = e || T;
|
|
1445
|
+
}
|
|
1446
|
+
static passThroughHooks = new Set(["preprocess", "postprocess", "processAllTokens", "emStrongMask"]);
|
|
1447
|
+
static passThroughHooksRespectAsync = new Set(["preprocess", "postprocess", "processAllTokens"]);
|
|
1448
|
+
preprocess(e) {
|
|
1449
|
+
return e;
|
|
1450
|
+
}
|
|
1451
|
+
postprocess(e) {
|
|
1452
|
+
return e;
|
|
1453
|
+
}
|
|
1454
|
+
processAllTokens(e) {
|
|
1455
|
+
return e;
|
|
1456
|
+
}
|
|
1457
|
+
emStrongMask(e) {
|
|
1458
|
+
return e;
|
|
1459
|
+
}
|
|
1460
|
+
provideLexer(e = this.block) {
|
|
1461
|
+
return e ? x.lex : x.lexInline;
|
|
1462
|
+
}
|
|
1463
|
+
provideParser(e = this.block) {
|
|
1464
|
+
return e ? b.parse : b.parseInline;
|
|
1465
|
+
}
|
|
1466
|
+
};
|
|
1467
|
+
z = new q;
|
|
1468
|
+
g.options = g.setOptions = function(l3) {
|
|
1469
|
+
return z.setOptions(l3), g.defaults = z.defaults, N(g.defaults), g;
|
|
1470
|
+
};
|
|
1471
|
+
g.getDefaults = M;
|
|
1472
|
+
g.defaults = T;
|
|
1473
|
+
g.use = function(...l3) {
|
|
1474
|
+
return z.use(...l3), g.defaults = z.defaults, N(g.defaults), g;
|
|
1475
|
+
};
|
|
1476
|
+
g.walkTokens = function(l3, e) {
|
|
1477
|
+
return z.walkTokens(l3, e);
|
|
1478
|
+
};
|
|
1479
|
+
g.parseInline = z.parseInline;
|
|
1480
|
+
g.Parser = b;
|
|
1481
|
+
g.parser = b.parse;
|
|
1482
|
+
g.Renderer = y;
|
|
1483
|
+
g.TextRenderer = L;
|
|
1484
|
+
g.Lexer = x;
|
|
1485
|
+
g.lexer = x.lex;
|
|
1486
|
+
g.Tokenizer = w;
|
|
1487
|
+
g.Hooks = P;
|
|
1488
|
+
g.parse = g;
|
|
1489
|
+
Ft = g.options;
|
|
1490
|
+
Ut = g.setOptions;
|
|
1491
|
+
Kt = g.use;
|
|
1492
|
+
Wt = g.walkTokens;
|
|
1493
|
+
Xt = g.parseInline;
|
|
1494
|
+
Vt = b.parse;
|
|
1495
|
+
Yt = x.lex;
|
|
1496
|
+
});
|
|
1497
|
+
|
|
172
1498
|
// src/lib/instruction-source-policy.ts
|
|
173
1499
|
function isRetiredInstructionSource(config) {
|
|
174
1500
|
return config.tags.some((tag) => tag === "retired-global-source" || tag === "retired-instruction-source");
|
|
@@ -545,7 +1871,7 @@ var util, objectUtil, ZodParsedType, getParsedType = (data) => {
|
|
|
545
1871
|
};
|
|
546
1872
|
var init_util = __esm(() => {
|
|
547
1873
|
(function(util2) {
|
|
548
|
-
util2.assertEqual = (
|
|
1874
|
+
util2.assertEqual = (_2) => {};
|
|
549
1875
|
function assertIs(_arg) {}
|
|
550
1876
|
util2.assertIs = assertIs;
|
|
551
1877
|
function assertNever(_x) {
|
|
@@ -593,7 +1919,7 @@ var init_util = __esm(() => {
|
|
|
593
1919
|
return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
|
|
594
1920
|
}
|
|
595
1921
|
util2.joinValues = joinValues;
|
|
596
|
-
util2.jsonStringifyReplacer = (
|
|
1922
|
+
util2.jsonStringifyReplacer = (_2, value) => {
|
|
597
1923
|
if (typeof value === "bigint") {
|
|
598
1924
|
return value.toString();
|
|
599
1925
|
}
|
|
@@ -885,7 +2211,7 @@ function addIssueToContext(ctx, issueData) {
|
|
|
885
2211
|
ctx.schemaErrorMap,
|
|
886
2212
|
overrideMap,
|
|
887
2213
|
overrideMap === en_default ? undefined : en_default
|
|
888
|
-
].filter((
|
|
2214
|
+
].filter((x2) => !!x2)
|
|
889
2215
|
});
|
|
890
2216
|
ctx.common.issues.push(issue);
|
|
891
2217
|
}
|
|
@@ -959,7 +2285,7 @@ var makeIssue = (params) => {
|
|
|
959
2285
|
};
|
|
960
2286
|
}
|
|
961
2287
|
let errorMessage = "";
|
|
962
|
-
const maps = errorMaps.filter((
|
|
2288
|
+
const maps = errorMaps.filter((m2) => !!m2).slice().reverse();
|
|
963
2289
|
for (const map of maps) {
|
|
964
2290
|
errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
|
|
965
2291
|
}
|
|
@@ -968,7 +2294,7 @@ var makeIssue = (params) => {
|
|
|
968
2294
|
path: fullPath,
|
|
969
2295
|
message: errorMessage
|
|
970
2296
|
};
|
|
971
|
-
}, EMPTY_PATH, INVALID, DIRTY = (value) => ({ status: "dirty", value }), OK = (value) => ({ status: "valid", value }), isAborted = (
|
|
2297
|
+
}, EMPTY_PATH, INVALID, DIRTY = (value) => ({ status: "dirty", value }), OK = (value) => ({ status: "valid", value }), isAborted = (x2) => x2.status === "aborted", isDirty = (x2) => x2.status === "dirty", isValid = (x2) => x2.status === "valid", isAsync = (x2) => typeof Promise !== "undefined" && x2 instanceof Promise;
|
|
972
2298
|
var init_parseUtil = __esm(() => {
|
|
973
2299
|
init_errors();
|
|
974
2300
|
init_en();
|
|
@@ -1413,17 +2739,17 @@ function deepPartialify(schema) {
|
|
|
1413
2739
|
return schema;
|
|
1414
2740
|
}
|
|
1415
2741
|
}
|
|
1416
|
-
function mergeValues(a,
|
|
2742
|
+
function mergeValues(a, b2) {
|
|
1417
2743
|
const aType = getParsedType(a);
|
|
1418
|
-
const bType = getParsedType(
|
|
1419
|
-
if (a ===
|
|
2744
|
+
const bType = getParsedType(b2);
|
|
2745
|
+
if (a === b2) {
|
|
1420
2746
|
return { valid: true, data: a };
|
|
1421
2747
|
} else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
|
|
1422
|
-
const bKeys = util.objectKeys(
|
|
2748
|
+
const bKeys = util.objectKeys(b2);
|
|
1423
2749
|
const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
|
|
1424
|
-
const newObj = { ...a, ...
|
|
2750
|
+
const newObj = { ...a, ...b2 };
|
|
1425
2751
|
for (const key of sharedKeys) {
|
|
1426
|
-
const sharedValue = mergeValues(a[key],
|
|
2752
|
+
const sharedValue = mergeValues(a[key], b2[key]);
|
|
1427
2753
|
if (!sharedValue.valid) {
|
|
1428
2754
|
return { valid: false };
|
|
1429
2755
|
}
|
|
@@ -1431,13 +2757,13 @@ function mergeValues(a, b) {
|
|
|
1431
2757
|
}
|
|
1432
2758
|
return { valid: true, data: newObj };
|
|
1433
2759
|
} else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
|
|
1434
|
-
if (a.length !==
|
|
2760
|
+
if (a.length !== b2.length) {
|
|
1435
2761
|
return { valid: false };
|
|
1436
2762
|
}
|
|
1437
2763
|
const newArray = [];
|
|
1438
2764
|
for (let index = 0;index < a.length; index++) {
|
|
1439
2765
|
const itemA = a[index];
|
|
1440
|
-
const itemB =
|
|
2766
|
+
const itemB = b2[index];
|
|
1441
2767
|
const sharedValue = mergeValues(itemA, itemB);
|
|
1442
2768
|
if (!sharedValue.valid) {
|
|
1443
2769
|
return { valid: false };
|
|
@@ -1445,7 +2771,7 @@ function mergeValues(a, b) {
|
|
|
1445
2771
|
newArray.push(sharedValue.data);
|
|
1446
2772
|
}
|
|
1447
2773
|
return { valid: true, data: newArray };
|
|
1448
|
-
} else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +
|
|
2774
|
+
} else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b2) {
|
|
1449
2775
|
return { valid: true, data: a };
|
|
1450
2776
|
} else {
|
|
1451
2777
|
return { valid: false };
|
|
@@ -3372,7 +4698,7 @@ var init_types2 = __esm(() => {
|
|
|
3372
4698
|
if (!schema)
|
|
3373
4699
|
return null;
|
|
3374
4700
|
return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
|
|
3375
|
-
}).filter((
|
|
4701
|
+
}).filter((x2) => !!x2);
|
|
3376
4702
|
if (ctx.common.async) {
|
|
3377
4703
|
return Promise.all(items).then((results) => {
|
|
3378
4704
|
return ParseStatus.mergeArray(status, results);
|
|
@@ -3625,7 +4951,7 @@ var init_types2 = __esm(() => {
|
|
|
3625
4951
|
return makeIssue({
|
|
3626
4952
|
data: args,
|
|
3627
4953
|
path: ctx.path,
|
|
3628
|
-
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((
|
|
4954
|
+
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x2) => !!x2),
|
|
3629
4955
|
issueData: {
|
|
3630
4956
|
code: ZodIssueCode.invalid_arguments,
|
|
3631
4957
|
argumentsError: error
|
|
@@ -3636,7 +4962,7 @@ var init_types2 = __esm(() => {
|
|
|
3636
4962
|
return makeIssue({
|
|
3637
4963
|
data: returns,
|
|
3638
4964
|
path: ctx.path,
|
|
3639
|
-
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((
|
|
4965
|
+
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), en_default].filter((x2) => !!x2),
|
|
3640
4966
|
issueData: {
|
|
3641
4967
|
code: ZodIssueCode.invalid_return_type,
|
|
3642
4968
|
returnTypeError: error
|
|
@@ -3646,29 +4972,29 @@ var init_types2 = __esm(() => {
|
|
|
3646
4972
|
const params = { errorMap: ctx.common.contextualErrorMap };
|
|
3647
4973
|
const fn = ctx.data;
|
|
3648
4974
|
if (this._def.returns instanceof ZodPromise) {
|
|
3649
|
-
const
|
|
4975
|
+
const me2 = this;
|
|
3650
4976
|
return OK(async function(...args) {
|
|
3651
4977
|
const error = new ZodError([]);
|
|
3652
|
-
const parsedArgs = await
|
|
4978
|
+
const parsedArgs = await me2._def.args.parseAsync(args, params).catch((e) => {
|
|
3653
4979
|
error.addIssue(makeArgsIssue(args, e));
|
|
3654
4980
|
throw error;
|
|
3655
4981
|
});
|
|
3656
4982
|
const result = await Reflect.apply(fn, this, parsedArgs);
|
|
3657
|
-
const parsedReturns = await
|
|
4983
|
+
const parsedReturns = await me2._def.returns._def.type.parseAsync(result, params).catch((e) => {
|
|
3658
4984
|
error.addIssue(makeReturnsIssue(result, e));
|
|
3659
4985
|
throw error;
|
|
3660
4986
|
});
|
|
3661
4987
|
return parsedReturns;
|
|
3662
4988
|
});
|
|
3663
4989
|
} else {
|
|
3664
|
-
const
|
|
4990
|
+
const me2 = this;
|
|
3665
4991
|
return OK(function(...args) {
|
|
3666
|
-
const parsedArgs =
|
|
4992
|
+
const parsedArgs = me2._def.args.safeParse(args, params);
|
|
3667
4993
|
if (!parsedArgs.success) {
|
|
3668
4994
|
throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
|
3669
4995
|
}
|
|
3670
4996
|
const result = Reflect.apply(fn, this, parsedArgs.data);
|
|
3671
|
-
const parsedReturns =
|
|
4997
|
+
const parsedReturns = me2._def.returns.safeParse(result, params);
|
|
3672
4998
|
if (!parsedReturns.success) {
|
|
3673
4999
|
throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
|
|
3674
5000
|
}
|
|
@@ -4223,10 +5549,10 @@ var init_types2 = __esm(() => {
|
|
|
4223
5549
|
}
|
|
4224
5550
|
}
|
|
4225
5551
|
}
|
|
4226
|
-
static create(a,
|
|
5552
|
+
static create(a, b2) {
|
|
4227
5553
|
return new ZodPipeline({
|
|
4228
5554
|
in: a,
|
|
4229
|
-
out:
|
|
5555
|
+
out: b2,
|
|
4230
5556
|
typeName: ZodFirstPartyTypeKind.ZodPipeline
|
|
4231
5557
|
});
|
|
4232
5558
|
}
|
|
@@ -4475,9 +5801,9 @@ function redactShell(content) {
|
|
|
4475
5801
|
const out = [];
|
|
4476
5802
|
for (let i = 0;i < lines.length; i++) {
|
|
4477
5803
|
const line = lines[i];
|
|
4478
|
-
const
|
|
4479
|
-
if (
|
|
4480
|
-
const [, prefix, key, eq, quote, value] =
|
|
5804
|
+
const m2 = line.match(/^(\s*(?:export\s+)?)([A-Z][A-Z0-9_]*)(\s*=\s*)(['"]?)(.+?)\4\s*$/);
|
|
5805
|
+
if (m2) {
|
|
5806
|
+
const [, prefix, key, eq, quote, value] = m2;
|
|
4481
5807
|
if (shouldRedactKeyValue(key, value)) {
|
|
4482
5808
|
const reason = reasonFor(key, value);
|
|
4483
5809
|
redacted.push({ varName: key, line: i + 1, reason });
|
|
@@ -4497,9 +5823,9 @@ function redactJson(content) {
|
|
|
4497
5823
|
const out = [];
|
|
4498
5824
|
for (let i = 0;i < lines.length; i++) {
|
|
4499
5825
|
const line = lines[i];
|
|
4500
|
-
const
|
|
4501
|
-
if (
|
|
4502
|
-
const [, prefix, key, value, comma, trail] =
|
|
5826
|
+
const m2 = line.match(/^(\s*"([^"]+)"\s*:\s*)"([^"]+)"(,?)(\s*)$/);
|
|
5827
|
+
if (m2) {
|
|
5828
|
+
const [, prefix, key, value, comma, trail] = m2;
|
|
4503
5829
|
if (shouldRedactKeyValue(key, value)) {
|
|
4504
5830
|
const varName = key.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
4505
5831
|
redacted.push({ varName, line: i + 1, reason: reasonFor(key, value) });
|
|
@@ -4527,9 +5853,9 @@ function redactToml(content) {
|
|
|
4527
5853
|
const out = [];
|
|
4528
5854
|
for (let i = 0;i < lines.length; i++) {
|
|
4529
5855
|
const line = lines[i];
|
|
4530
|
-
const
|
|
4531
|
-
if (
|
|
4532
|
-
const [, indent, key, eq, quote, value] =
|
|
5856
|
+
const m2 = line.match(/^(\s*)([a-zA-Z][a-zA-Z0-9_\-]*)(\s*=\s*)(['"]?)(.+?)\4\s*$/);
|
|
5857
|
+
if (m2) {
|
|
5858
|
+
const [, indent, key, eq, quote, value] = m2;
|
|
4533
5859
|
if (shouldRedactKeyValue(key, value)) {
|
|
4534
5860
|
const varName = key.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
4535
5861
|
redacted.push({ varName, line: i + 1, reason: reasonFor(key, value) });
|
|
@@ -4555,9 +5881,9 @@ function redactIni(content) {
|
|
|
4555
5881
|
out.push(`${authM[1]}\${NPM_TOKEN}`);
|
|
4556
5882
|
continue;
|
|
4557
5883
|
}
|
|
4558
|
-
const
|
|
4559
|
-
if (
|
|
4560
|
-
const [, indent, key, eq, value] =
|
|
5884
|
+
const m2 = line.match(/^(\s*)([a-zA-Z][a-zA-Z0-9_\-]*)(\s*=\s*)(.+?)\s*$/);
|
|
5885
|
+
if (m2) {
|
|
5886
|
+
const [, indent, key, eq, value] = m2;
|
|
4561
5887
|
if (shouldRedactKeyValue(key, value)) {
|
|
4562
5888
|
const varName = key.toUpperCase().replace(/[^A-Z0-9]/g, "_");
|
|
4563
5889
|
redacted.push({ varName, line: i + 1, reason: reasonFor(key, value) });
|
|
@@ -5360,8 +6686,8 @@ function parseManagedBlock(content, force) {
|
|
|
5360
6686
|
const begin = starts[0];
|
|
5361
6687
|
const end = ends[0];
|
|
5362
6688
|
const a = begin.marker;
|
|
5363
|
-
const
|
|
5364
|
-
if (a.id !==
|
|
6689
|
+
const b2 = end.marker;
|
|
6690
|
+
if (a.id !== b2.id || a.revision !== b2.revision || a.hash !== b2.hash) {
|
|
5365
6691
|
if (!force)
|
|
5366
6692
|
throw new ProjectContextError("MANAGED_BLOCK_CONFLICT", "managed project-context marker metadata is inconsistent");
|
|
5367
6693
|
return { block: null, forceRange: { start: begin.start, end: lineContentEnd(end) } };
|
|
@@ -5379,7 +6705,7 @@ function parseManagedBlock(content, force) {
|
|
|
5379
6705
|
id: a.id,
|
|
5380
6706
|
revision: a.revision,
|
|
5381
6707
|
hash: a.hash,
|
|
5382
|
-
legacy: a.legacy ||
|
|
6708
|
+
legacy: a.legacy || b2.legacy
|
|
5383
6709
|
},
|
|
5384
6710
|
forceRange: null
|
|
5385
6711
|
};
|
|
@@ -7188,11 +8514,11 @@ function durableSourcePath(path, workspaceRoot) {
|
|
|
7188
8514
|
}
|
|
7189
8515
|
function compareRevisions(incoming, previous) {
|
|
7190
8516
|
const a = revisionKey(incoming);
|
|
7191
|
-
const
|
|
7192
|
-
if (!a || !
|
|
8517
|
+
const b2 = revisionKey(previous);
|
|
8518
|
+
if (!a || !b2 || a.kind !== b2.kind) {
|
|
7193
8519
|
throw new ProjectContextError("PROJECT_CONTEXT_REVISION_INCOMPARABLE", "project-context revisions use incompatible ordering schemes");
|
|
7194
8520
|
}
|
|
7195
|
-
return a.value <
|
|
8521
|
+
return a.value < b2.value ? -1 : a.value > b2.value ? 1 : 0;
|
|
7196
8522
|
}
|
|
7197
8523
|
function revisionKey(value) {
|
|
7198
8524
|
const sequence = value.match(/^(?:rev-)?([0-9]+)$/);
|
|
@@ -7600,8 +8926,8 @@ function yamlQuote(value) {
|
|
|
7600
8926
|
return `"${value.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}"`;
|
|
7601
8927
|
}
|
|
7602
8928
|
function headingLevel(line) {
|
|
7603
|
-
const
|
|
7604
|
-
return
|
|
8929
|
+
const m2 = line.match(/^(#{1,6})\s+/);
|
|
8930
|
+
return m2 ? m2[1].length : null;
|
|
7605
8931
|
}
|
|
7606
8932
|
function stripClaudeOnlySections(content) {
|
|
7607
8933
|
const withoutMarkedBlocks = content.replace(/<!--\s*claude-only:start\s*-->[\s\S]*?<!--\s*claude-only:end\s*-->/gi, "");
|
|
@@ -7639,7 +8965,7 @@ function ruleLabel(config) {
|
|
|
7639
8965
|
return file.replace(/\.(md|mdc|markdown)$/i, "");
|
|
7640
8966
|
}
|
|
7641
8967
|
function claudeRules(source, context) {
|
|
7642
|
-
return (context.configs ?? []).filter((config) => isClaudeRuleConfig(source, config)).sort((a,
|
|
8968
|
+
return (context.configs ?? []).filter((config) => isClaudeRuleConfig(source, config)).sort((a, b2) => (a.target_path ?? a.name).localeCompare(b2.target_path ?? b2.name));
|
|
7643
8969
|
}
|
|
7644
8970
|
function flattenWithRules(source, context) {
|
|
7645
8971
|
const parts = [stripClaudeOnlySections(source.content)];
|
|
@@ -8140,7 +9466,7 @@ function sha2563(value) {
|
|
|
8140
9466
|
return createHash3("sha256").update(value).digest("hex");
|
|
8141
9467
|
}
|
|
8142
9468
|
function stableJson(value) {
|
|
8143
|
-
const canonical = (entry) => Array.isArray(entry) ? entry.map(canonical) : entry && typeof entry === "object" ? Object.fromEntries(Object.entries(entry).sort(([a], [
|
|
9469
|
+
const canonical = (entry) => Array.isArray(entry) ? entry.map(canonical) : entry && typeof entry === "object" ? Object.fromEntries(Object.entries(entry).sort(([a], [b2]) => a.localeCompare(b2)).map(([key, child]) => [key, canonical(child)])) : entry;
|
|
8144
9470
|
return JSON.stringify(canonical(value));
|
|
8145
9471
|
}
|
|
8146
9472
|
function deepFreeze(value) {
|
|
@@ -8629,8 +9955,8 @@ function adoptResolverStoreHome(resolved, env = process.env) {
|
|
|
8629
9955
|
return existsSync4(join5(resolved, "instructions.db"));
|
|
8630
9956
|
}
|
|
8631
9957
|
function exactStoreHome(env = process.env) {
|
|
8632
|
-
const
|
|
8633
|
-
return
|
|
9958
|
+
const v2 = env[HASNA_CONFIGS_HOME_ENV];
|
|
9959
|
+
return v2 && v2.trim() ? v2.trim() : undefined;
|
|
8634
9960
|
}
|
|
8635
9961
|
function getConfigsStoreHome(env = process.env) {
|
|
8636
9962
|
const exact = exactStoreHome(env);
|
|
@@ -8890,8 +10216,8 @@ function normalizeSources(sources, tool, allowEmptySources) {
|
|
|
8890
10216
|
rejectDuplicateRulePaths(ordered);
|
|
8891
10217
|
return { sources: ordered, skipped: [...providerSkipped, ...deduplicated.skipped] };
|
|
8892
10218
|
}
|
|
8893
|
-
function compareSessionInstructionSources(a,
|
|
8894
|
-
return SESSION_LAYER_RANK[a.resolvedLayer] - SESSION_LAYER_RANK[
|
|
10219
|
+
function compareSessionInstructionSources(a, b2) {
|
|
10220
|
+
return SESSION_LAYER_RANK[a.resolvedLayer] - SESSION_LAYER_RANK[b2.resolvedLayer] || a.resolvedOrder - b2.resolvedOrder || a.id.localeCompare(b2.id);
|
|
8895
10221
|
}
|
|
8896
10222
|
function semanticPolicyIntegrity(body) {
|
|
8897
10223
|
return sha2566(body) === AGENT_OPERATING_RULES_PAYLOAD_SHA256 ? "pinned-digest" : "unverified-self-declared";
|
|
@@ -9767,10 +11093,54 @@ function resolveSessionTargetOwnership(input, target) {
|
|
|
9767
11093
|
};
|
|
9768
11094
|
}
|
|
9769
11095
|
function planSessionRender(input) {
|
|
11096
|
+
if (input.claudeProjectImport)
|
|
11097
|
+
throw new Error("CLAUDE_PROJECT_IMPORT_REQUIRES_PROFILE: use explicit shared profile bindings.");
|
|
11098
|
+
return buildSessionRenderPlan(input);
|
|
11099
|
+
}
|
|
11100
|
+
function planCompiledProfileSessionRender(input, companionSources) {
|
|
11101
|
+
if (input.claudeProjectImport) {
|
|
11102
|
+
if (!companionSources || fingerprint(input.sources) !== fingerprint(companionSources)) {
|
|
11103
|
+
throw new Error("CLAUDE_PROJECT_IMPORT_DIVERGENT: both consumers must compile the same ordered source bodies and activation semantics.");
|
|
11104
|
+
}
|
|
11105
|
+
const normalizedFor = (sources, tool) => composeSources(normalizeSources(sources, tool, input.allowEmptySources === true).sources, tool).sources;
|
|
11106
|
+
if (fingerprint(normalizedFor(input.sources, "sumi")) !== fingerprint(normalizedFor(companionSources, "claude"))) {
|
|
11107
|
+
throw new Error("CLAUDE_PROJECT_IMPORT_DIVERGENT: provider filtering or composition changes the shared canonical policy.");
|
|
11108
|
+
}
|
|
11109
|
+
}
|
|
11110
|
+
return buildSessionRenderPlan(input);
|
|
11111
|
+
}
|
|
11112
|
+
function assertNoUnmanagedClaudeImports(content) {
|
|
11113
|
+
const markdown = new q({ gfm: false, async: false, renderer: {
|
|
11114
|
+
codespan: () => "",
|
|
11115
|
+
def: ({ raw }) => raw,
|
|
11116
|
+
code: ({ raw }) => {
|
|
11117
|
+
const lines = raw.trimEnd().split(`
|
|
11118
|
+
`);
|
|
11119
|
+
const first = lines[0]?.match(/^ {0,3}(`{3,}|~{3,})/);
|
|
11120
|
+
const last = lines.at(-1)?.match(/^ {0,3}(`{3,}|~{3,})\s*$/);
|
|
11121
|
+
return lines.length > 1 && first && last && first[1][0] === last[1][0] && last[1].length >= first[1].length ? "" : raw;
|
|
11122
|
+
}
|
|
11123
|
+
} });
|
|
11124
|
+
const prose = markdown.parse(content.replaceAll(`<!-- ${SESSION_RENDER_MANAGED_MARKER}. Do not edit this generated file directly. -->`, "")).replace(/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}(?=$|[\s<>),.;:])/gi, "");
|
|
11125
|
+
if (prose.includes("@"))
|
|
11126
|
+
throw new Error("CLAUDE_PROJECT_IMPORT_NESTED: shared canonical policy cannot contain native @ imports; quote literal package/path references in Markdown code.");
|
|
11127
|
+
}
|
|
11128
|
+
function buildSessionRenderPlan(input) {
|
|
9770
11129
|
if (!SESSION_RENDER_TOOLS.includes(input.tool))
|
|
9771
11130
|
throw new Error(`Unsupported session render tool: ${input.tool}`);
|
|
9772
11131
|
if (!input.profile.trim())
|
|
9773
11132
|
throw new Error("Session render profile is required.");
|
|
11133
|
+
if (input.claudeProjectImport) {
|
|
11134
|
+
if (input.tool !== "sumi" || !input.projectRoot || input.targetHome && resolveSessionPath(input.targetHome) !== resolveSessionPath(input.projectRoot)) {
|
|
11135
|
+
throw new Error("CLAUDE_PROJECT_IMPORT_TARGET: requires a Sumi project root with one shared manifest owner.");
|
|
11136
|
+
}
|
|
11137
|
+
if (Object.keys(input.claudeProjectImport).some((key) => key !== "providerVersion") || input.claudeProjectImport.providerVersion !== "2.1.278") {
|
|
11138
|
+
throw new Error("CLAUDE_PROJECT_IMPORT_CAPABILITY: only verified Claude 2.1.278 relative project imports are supported.");
|
|
11139
|
+
}
|
|
11140
|
+
}
|
|
11141
|
+
if (JSON.stringify(input.refreshSelector?.claudeProjectImport) !== JSON.stringify(input.claudeProjectImport) && input.refreshSelector) {
|
|
11142
|
+
throw new Error("CLAUDE_PROJECT_IMPORT_SELECTOR: refresh must preserve the exact companion capability.");
|
|
11143
|
+
}
|
|
9774
11144
|
const adapter = adapterFor(input);
|
|
9775
11145
|
const {
|
|
9776
11146
|
targetHome,
|
|
@@ -9831,7 +11201,25 @@ function planSessionRender(input) {
|
|
|
9831
11201
|
if (projectContext && orderedSources.some((source) => source.id === projectContext.source.id)) {
|
|
9832
11202
|
throw new Error(`Session source ${projectContext.source.id} is reserved for the durable Instructions project-context renderer.`);
|
|
9833
11203
|
}
|
|
9834
|
-
const files = projectContext?.files ?? baseFiles;
|
|
11204
|
+
const files = [...projectContext?.files ?? baseFiles];
|
|
11205
|
+
let claudeProjectImport;
|
|
11206
|
+
if (input.claudeProjectImport && !blocked) {
|
|
11207
|
+
const canonical = files.find((file) => file.relativePath === "AGENTS.md");
|
|
11208
|
+
if (!canonical)
|
|
11209
|
+
throw new Error("CLAUDE_PROJECT_IMPORT_CANONICAL: missing canonical project AGENTS.md.");
|
|
11210
|
+
assertNoUnmanagedClaudeImports(canonical.content);
|
|
11211
|
+
claudeProjectImport = {
|
|
11212
|
+
...input.claudeProjectImport,
|
|
11213
|
+
capability: "claude-project-relative-import/v1",
|
|
11214
|
+
canonicalPath: "AGENTS.md",
|
|
11215
|
+
canonicalSha256: canonical.sha256,
|
|
11216
|
+
importPath: "CLAUDE.md"
|
|
11217
|
+
};
|
|
11218
|
+
files.push(makeFile(targetHome, "CLAUDE.md", "index", `<!-- ${SESSION_RENDER_MANAGED_MARKER}. Do not edit this generated file directly. -->
|
|
11219
|
+
|
|
11220
|
+
@./AGENTS.md
|
|
11221
|
+
`, canonical.sourceIds));
|
|
11222
|
+
}
|
|
9835
11223
|
const assetFiles = buildAssetFiles(input, targetHome, blocked);
|
|
9836
11224
|
rejectDuplicateRenderPaths([...files, ...assetFiles]);
|
|
9837
11225
|
const manifest = {
|
|
@@ -9841,6 +11229,7 @@ function planSessionRender(input) {
|
|
|
9841
11229
|
profile: input.profile,
|
|
9842
11230
|
sessionId: input.sessionId ?? null,
|
|
9843
11231
|
...input.refreshSelector ? { refreshSelector: input.refreshSelector } : {},
|
|
11232
|
+
...claudeProjectImport ? { claudeProjectImport } : {},
|
|
9844
11233
|
targetHome,
|
|
9845
11234
|
targetKind,
|
|
9846
11235
|
targetOwner,
|
|
@@ -9856,12 +11245,14 @@ function planSessionRender(input) {
|
|
|
9856
11245
|
providerSurface: input.providerSurface ?? null,
|
|
9857
11246
|
providerConfig: input.providerConfig ? { sourceId: input.providerConfig.sourceId, content: input.providerConfig.content } : null,
|
|
9858
11247
|
projectContext: projectContext.project_context,
|
|
9859
|
-
assetPlanDigest: input.assetPlan?.planDigest ?? null
|
|
11248
|
+
assetPlanDigest: input.assetPlan?.planDigest ?? null,
|
|
11249
|
+
...claudeProjectImport ? { claudeProjectImport } : {}
|
|
9860
11250
|
} : {
|
|
9861
11251
|
sources: orderedSources.map(sourceFingerprint),
|
|
9862
11252
|
providerSurface: input.providerSurface ?? null,
|
|
9863
11253
|
providerConfig: input.providerConfig ? { sourceId: input.providerConfig.sourceId, content: input.providerConfig.content } : null,
|
|
9864
|
-
assetPlanDigest: input.assetPlan?.planDigest ?? null
|
|
11254
|
+
assetPlanDigest: input.assetPlan?.planDigest ?? null,
|
|
11255
|
+
...claudeProjectImport ? { claudeProjectImport } : {}
|
|
9865
11256
|
}),
|
|
9866
11257
|
sources: [
|
|
9867
11258
|
...orderedSources.map((source) => ({
|
|
@@ -10417,6 +11808,7 @@ function asStringArray(value) {
|
|
|
10417
11808
|
}
|
|
10418
11809
|
var ANTIGRAVITY_RULE_FILE_CHAR_LIMIT = 12000, SESSION_RENDERER_OWNER_ID = "instructions-session-renderer", SESSION_RENDER_TOOLS, SESSION_RENDER_PROFILE_ENTRYPOINTS, SESSION_RENDER_OWNED_CONFIG_TARGETS, IDENTITY_EXPORT_AUTHORITY, CODEWITH_PROTECTED_REPLACEMENT_TARGETS, CODEWITH_FLATTENED_ADAPTER, CODEWITH_NATIVE_ADAPTER, SESSION_TOOL_ADAPTERS, SESSION_RENDER_MANAGED_DIRS, SESSION_RENDER_SHARED_MANAGED_DIRS, SESSION_RENDER_EXCLUSIVE_MANAGED_PATHS, SESSION_LAYER_RANK, CLAUDE_PATHS_RULES_VERSION_RANGE = ">=2.1.84", CANONICAL_IDENTITY_EXPORT_PACKAGES;
|
|
10419
11810
|
var init_session_render = __esm(() => {
|
|
11811
|
+
init_marked_esm();
|
|
10420
11812
|
init_global_agent_rules_standard();
|
|
10421
11813
|
init_codewith_shared_todos_storage_standard();
|
|
10422
11814
|
init_project_context();
|
|
@@ -10959,6 +12351,23 @@ function planProfileSessionRender(input) {
|
|
|
10959
12351
|
...nativeProfile ? { provider_variant: "native-profile" } : {}
|
|
10960
12352
|
}
|
|
10961
12353
|
});
|
|
12354
|
+
let companionSources;
|
|
12355
|
+
if (input.claudeProjectImport) {
|
|
12356
|
+
if (input.extra_sources?.length)
|
|
12357
|
+
throw new Error("CLAUDE_PROJECT_IMPORT_UNBOUND: shared project imports cannot include extra sources outside explicit profile bindings.");
|
|
12358
|
+
for (const unit of compiled.plan.units) {
|
|
12359
|
+
const providers = input.bindings.find((row) => row.config_id === unit.config_id && row.profile_id === input.profile_id)?.binding.providers;
|
|
12360
|
+
if (!providers?.some((entry) => entry.provider === "sumi") || !providers.some((entry) => entry.provider === "claude")) {
|
|
12361
|
+
throw new Error(`CLAUDE_PROJECT_IMPORT_BINDING: ${unit.config_id} requires explicit Sumi and Claude provider bindings.`);
|
|
12362
|
+
}
|
|
12363
|
+
}
|
|
12364
|
+
companionSources = compileInstructionGraph({
|
|
12365
|
+
profile_id: input.profile_id,
|
|
12366
|
+
configs: input.configs,
|
|
12367
|
+
bindings: input.bindings,
|
|
12368
|
+
context: { ...input.graph_context, provider: "claude", provider_version: input.claudeProjectImport.providerVersion, provider_variant: undefined }
|
|
12369
|
+
}).sources;
|
|
12370
|
+
}
|
|
10962
12371
|
const assetPlan = compileAssetPlan({
|
|
10963
12372
|
profileId: input.profile_id,
|
|
10964
12373
|
provider: input.tool,
|
|
@@ -10992,13 +12401,13 @@ function planProfileSessionRender(input) {
|
|
|
10992
12401
|
]);
|
|
10993
12402
|
}
|
|
10994
12403
|
return deepFreeze2({
|
|
10995
|
-
...
|
|
12404
|
+
...planCompiledProfileSessionRender({
|
|
10996
12405
|
...renderInput,
|
|
10997
12406
|
...compiled.capability.session_surface ? { providerSurface: compiled.capability.session_surface } : {},
|
|
10998
12407
|
sources: [...compiled.sources, ...input.extra_sources ?? []],
|
|
10999
12408
|
assetPlan,
|
|
11000
12409
|
assetContents: Object.fromEntries((input.asset_configs ?? []).map((config) => [config.id, config.content]))
|
|
11001
|
-
}),
|
|
12410
|
+
}, companionSources),
|
|
11002
12411
|
instructionGraph: compiled.plan
|
|
11003
12412
|
});
|
|
11004
12413
|
}
|
|
@@ -11125,7 +12534,7 @@ function sha2567(value) {
|
|
|
11125
12534
|
return createHash7("sha256").update(value).digest("hex");
|
|
11126
12535
|
}
|
|
11127
12536
|
function stableJson2(value) {
|
|
11128
|
-
const canonical = (entry) => Array.isArray(entry) ? entry.map(canonical) : entry && typeof entry === "object" ? Object.fromEntries(Object.entries(entry).sort(([a], [
|
|
12537
|
+
const canonical = (entry) => Array.isArray(entry) ? entry.map(canonical) : entry && typeof entry === "object" ? Object.fromEntries(Object.entries(entry).sort(([a], [b2]) => a.localeCompare(b2)).map(([key, child]) => [key, canonical(child)])) : entry;
|
|
11129
12538
|
return JSON.stringify(canonical(value));
|
|
11130
12539
|
}
|
|
11131
12540
|
function deepFreeze2(value) {
|
|
@@ -12756,8 +14165,8 @@ function appendQuery(path, query) {
|
|
|
12756
14165
|
if (value === null || value === undefined)
|
|
12757
14166
|
continue;
|
|
12758
14167
|
if (Array.isArray(value)) {
|
|
12759
|
-
for (const
|
|
12760
|
-
params.append(key, String(
|
|
14168
|
+
for (const v2 of value)
|
|
14169
|
+
params.append(key, String(v2));
|
|
12761
14170
|
} else {
|
|
12762
14171
|
params.append(key, String(value));
|
|
12763
14172
|
}
|
|
@@ -12961,9 +14370,9 @@ function entityPath(resource, id) {
|
|
|
12961
14370
|
return `${resourcePath(resource)}/${encodeURIComponent(String(id))}`;
|
|
12962
14371
|
}
|
|
12963
14372
|
function newIdempotencyKey() {
|
|
12964
|
-
const
|
|
12965
|
-
if (
|
|
12966
|
-
return
|
|
14373
|
+
const g2 = globalThis;
|
|
14374
|
+
if (g2.crypto?.randomUUID)
|
|
14375
|
+
return g2.crypto.randomUUID();
|
|
12967
14376
|
return `idmp_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 12)}`;
|
|
12968
14377
|
}
|
|
12969
14378
|
function extractItems(raw) {
|
|
@@ -13392,8 +14801,8 @@ function ensureFeedbackTable(db) {
|
|
|
13392
14801
|
}
|
|
13393
14802
|
}
|
|
13394
14803
|
function insertFeedback(input, db) {
|
|
13395
|
-
const
|
|
13396
|
-
|
|
14804
|
+
const d2 = db || getDatabase();
|
|
14805
|
+
d2.run("INSERT INTO feedback (message, email, category, version) VALUES (?, ?, ?, ?)", [input.message, input.email ?? null, input.category ?? "general", input.version ?? null]);
|
|
13397
14806
|
}
|
|
13398
14807
|
var MIGRATIONS, _db = null;
|
|
13399
14808
|
var init_database = __esm(() => {
|
|
@@ -13486,27 +14895,27 @@ var init_database = __esm(() => {
|
|
|
13486
14895
|
|
|
13487
14896
|
// src/db/snapshots.ts
|
|
13488
14897
|
function createSnapshot(configId, content, version, db) {
|
|
13489
|
-
const
|
|
14898
|
+
const d2 = db || getDatabase();
|
|
13490
14899
|
const id = uuid();
|
|
13491
14900
|
const ts = now();
|
|
13492
|
-
|
|
14901
|
+
d2.run("INSERT INTO config_snapshots (id, config_id, content, version, created_at) VALUES (?, ?, ?, ?, ?)", [id, configId, content, version, ts]);
|
|
13493
14902
|
return { id, config_id: configId, content, version, created_at: ts };
|
|
13494
14903
|
}
|
|
13495
14904
|
function listSnapshots(configId, db) {
|
|
13496
|
-
const
|
|
13497
|
-
return
|
|
14905
|
+
const d2 = db || getDatabase();
|
|
14906
|
+
return d2.query("SELECT * FROM config_snapshots WHERE config_id = ? ORDER BY version DESC").all(configId);
|
|
13498
14907
|
}
|
|
13499
14908
|
function getSnapshot(id, db) {
|
|
13500
|
-
const
|
|
13501
|
-
return
|
|
14909
|
+
const d2 = db || getDatabase();
|
|
14910
|
+
return d2.query("SELECT * FROM config_snapshots WHERE id = ?").get(id);
|
|
13502
14911
|
}
|
|
13503
14912
|
function getSnapshotByVersion(configId, version, db) {
|
|
13504
|
-
const
|
|
13505
|
-
return
|
|
14913
|
+
const d2 = db || getDatabase();
|
|
14914
|
+
return d2.query("SELECT * FROM config_snapshots WHERE config_id = ? AND version = ?").get(configId, version);
|
|
13506
14915
|
}
|
|
13507
14916
|
function pruneSnapshots(configId, keep = 10, db) {
|
|
13508
|
-
const
|
|
13509
|
-
const result =
|
|
14917
|
+
const d2 = db || getDatabase();
|
|
14918
|
+
const result = d2.run(`DELETE FROM config_snapshots WHERE config_id = ? AND id NOT IN (
|
|
13510
14919
|
SELECT id FROM config_snapshots WHERE config_id = ? ORDER BY version DESC LIMIT ?
|
|
13511
14920
|
)`, [configId, configId, keep]);
|
|
13512
14921
|
return result.changes;
|
|
@@ -13547,14 +14956,14 @@ function uniqueSlug(name, db, excludeId) {
|
|
|
13547
14956
|
}
|
|
13548
14957
|
}
|
|
13549
14958
|
function createConfig(input, db) {
|
|
13550
|
-
const
|
|
14959
|
+
const d2 = db || getDatabase();
|
|
13551
14960
|
const id = uuid();
|
|
13552
14961
|
const ts = now();
|
|
13553
|
-
const slug2 = uniqueSlug(input.name,
|
|
14962
|
+
const slug2 = uniqueSlug(input.name, d2);
|
|
13554
14963
|
const tags = JSON.stringify(input.tags || []);
|
|
13555
14964
|
const outputs = JSON.stringify(input.outputs || []);
|
|
13556
|
-
return
|
|
13557
|
-
|
|
14965
|
+
return d2.transaction(() => {
|
|
14966
|
+
d2.run(`INSERT INTO configs (id, name, slug, kind, category, agent, target_path, outputs, format, content, description, tags, is_template, version, created_at, updated_at, synced_at)
|
|
13558
14967
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1, ?, ?, NULL)`, [
|
|
13559
14968
|
id,
|
|
13560
14969
|
input.name,
|
|
@@ -13572,26 +14981,26 @@ function createConfig(input, db) {
|
|
|
13572
14981
|
ts,
|
|
13573
14982
|
ts
|
|
13574
14983
|
]);
|
|
13575
|
-
createSnapshot(id, input.content, 1,
|
|
13576
|
-
return getConfig(id,
|
|
14984
|
+
createSnapshot(id, input.content, 1, d2);
|
|
14985
|
+
return getConfig(id, d2);
|
|
13577
14986
|
})();
|
|
13578
14987
|
}
|
|
13579
14988
|
function getConfig(idOrSlug, db) {
|
|
13580
|
-
const
|
|
13581
|
-
const row =
|
|
14989
|
+
const d2 = db || getDatabase();
|
|
14990
|
+
const row = d2.query("SELECT * FROM configs WHERE id = ? OR slug = ?").get(idOrSlug, idOrSlug);
|
|
13582
14991
|
if (!row)
|
|
13583
14992
|
throw new ConfigNotFoundError(idOrSlug);
|
|
13584
14993
|
return rowToConfig(row);
|
|
13585
14994
|
}
|
|
13586
14995
|
function getConfigById(id, db) {
|
|
13587
|
-
const
|
|
13588
|
-
const row =
|
|
14996
|
+
const d2 = db || getDatabase();
|
|
14997
|
+
const row = d2.query("SELECT * FROM configs WHERE id = ?").get(id);
|
|
13589
14998
|
if (!row)
|
|
13590
14999
|
throw new ConfigNotFoundError(id);
|
|
13591
15000
|
return rowToConfig(row);
|
|
13592
15001
|
}
|
|
13593
15002
|
function listConfigs(filter, db) {
|
|
13594
|
-
const
|
|
15003
|
+
const d2 = db || getDatabase();
|
|
13595
15004
|
const conditions = [];
|
|
13596
15005
|
const params = [];
|
|
13597
15006
|
if (filter?.category) {
|
|
@@ -13612,8 +15021,8 @@ function listConfigs(filter, db) {
|
|
|
13612
15021
|
}
|
|
13613
15022
|
if (filter?.search) {
|
|
13614
15023
|
conditions.push("(name LIKE ? OR description LIKE ? OR content LIKE ?)");
|
|
13615
|
-
const
|
|
13616
|
-
params.push(
|
|
15024
|
+
const q2 = `%${filter.search}%`;
|
|
15025
|
+
params.push(q2, q2, q2);
|
|
13617
15026
|
}
|
|
13618
15027
|
if (filter?.tags && filter.tags.length > 0) {
|
|
13619
15028
|
const tagConditions = filter.tags.map(() => "tags LIKE ?").join(" OR ");
|
|
@@ -13622,11 +15031,11 @@ function listConfigs(filter, db) {
|
|
|
13622
15031
|
params.push(`%"${tag}"%`);
|
|
13623
15032
|
}
|
|
13624
15033
|
const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
13625
|
-
const rows =
|
|
15034
|
+
const rows = d2.query(`SELECT * FROM configs ${where} ORDER BY category, name`).all(...params);
|
|
13626
15035
|
return rows.map(rowToConfig);
|
|
13627
15036
|
}
|
|
13628
15037
|
function listConfigsPage(filter = {}, options = {}, db) {
|
|
13629
|
-
const
|
|
15038
|
+
const d2 = db || getDatabase();
|
|
13630
15039
|
const conditions = [];
|
|
13631
15040
|
const params = [];
|
|
13632
15041
|
if (filter.category) {
|
|
@@ -13647,8 +15056,8 @@ function listConfigsPage(filter = {}, options = {}, db) {
|
|
|
13647
15056
|
}
|
|
13648
15057
|
if (filter.search) {
|
|
13649
15058
|
conditions.push("(name LIKE ? OR description LIKE ? OR content LIKE ?)");
|
|
13650
|
-
const
|
|
13651
|
-
params.push(
|
|
15059
|
+
const q2 = `%${filter.search}%`;
|
|
15060
|
+
params.push(q2, q2, q2);
|
|
13652
15061
|
}
|
|
13653
15062
|
if (filter.tags?.length) {
|
|
13654
15063
|
conditions.push(`(${filter.tags.map(() => "tags LIKE ?").join(" AND ")})`);
|
|
@@ -13657,13 +15066,13 @@ function listConfigsPage(filter = {}, options = {}, db) {
|
|
|
13657
15066
|
}
|
|
13658
15067
|
const where = conditions.length ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
13659
15068
|
const normalized = normalizeBoundedReadOptions(options);
|
|
13660
|
-
const total =
|
|
15069
|
+
const total = d2.query(`SELECT COUNT(*) AS total FROM configs ${where}`).get(...params)?.total ?? 0;
|
|
13661
15070
|
const pageParams = [...params, normalized.limit, normalized.cursor];
|
|
13662
|
-
const rows =
|
|
15071
|
+
const rows = d2.query(`SELECT * FROM configs ${where} ORDER BY id LIMIT ? OFFSET ?`).all(...pageParams);
|
|
13663
15072
|
return boundedReadPage(rows.map(rowToConfig), total, normalized);
|
|
13664
15073
|
}
|
|
13665
15074
|
function listConfigIdentitiesPage(filter = {}, options = {}, db) {
|
|
13666
|
-
const
|
|
15075
|
+
const d2 = db || getDatabase();
|
|
13667
15076
|
const conditions = [];
|
|
13668
15077
|
const params = [];
|
|
13669
15078
|
if (filter.category) {
|
|
@@ -13684,8 +15093,8 @@ function listConfigIdentitiesPage(filter = {}, options = {}, db) {
|
|
|
13684
15093
|
}
|
|
13685
15094
|
if (filter.search) {
|
|
13686
15095
|
conditions.push("(name LIKE ? OR description LIKE ? OR content LIKE ?)");
|
|
13687
|
-
const
|
|
13688
|
-
params.push(
|
|
15096
|
+
const q2 = `%${filter.search}%`;
|
|
15097
|
+
params.push(q2, q2, q2);
|
|
13689
15098
|
}
|
|
13690
15099
|
if (filter.tags?.length) {
|
|
13691
15100
|
conditions.push(`(${filter.tags.map(() => "tags LIKE ?").join(" AND ")})`);
|
|
@@ -13694,9 +15103,9 @@ function listConfigIdentitiesPage(filter = {}, options = {}, db) {
|
|
|
13694
15103
|
}
|
|
13695
15104
|
const where = conditions.length ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
13696
15105
|
const normalized = normalizeBoundedReadOptions(options);
|
|
13697
|
-
const total =
|
|
15106
|
+
const total = d2.query(`SELECT COUNT(*) AS total FROM configs ${where}`).get(...params)?.total ?? 0;
|
|
13698
15107
|
const pageParams = [...params, normalized.limit, normalized.cursor];
|
|
13699
|
-
const rows =
|
|
15108
|
+
const rows = d2.query(`SELECT id, name, slug, kind, category, agent, format, is_template, version, created_at, updated_at, synced_at
|
|
13700
15109
|
FROM configs ${where} ORDER BY id LIMIT ? OFFSET ?`).all(...pageParams);
|
|
13701
15110
|
return boundedReadPage(rows.map((row) => ({
|
|
13702
15111
|
...row,
|
|
@@ -13708,7 +15117,7 @@ function listConfigIdentitiesPage(filter = {}, options = {}, db) {
|
|
|
13708
15117
|
})), total, normalized);
|
|
13709
15118
|
}
|
|
13710
15119
|
function listConfigSummariesPage(filter = {}, options = {}, db) {
|
|
13711
|
-
const
|
|
15120
|
+
const d2 = db || getDatabase();
|
|
13712
15121
|
const conditions = [];
|
|
13713
15122
|
const params = [];
|
|
13714
15123
|
if (filter.category) {
|
|
@@ -13729,8 +15138,8 @@ function listConfigSummariesPage(filter = {}, options = {}, db) {
|
|
|
13729
15138
|
}
|
|
13730
15139
|
if (filter.search) {
|
|
13731
15140
|
conditions.push("(name LIKE ? OR description LIKE ? OR content LIKE ?)");
|
|
13732
|
-
const
|
|
13733
|
-
params.push(
|
|
15141
|
+
const q2 = `%${filter.search}%`;
|
|
15142
|
+
params.push(q2, q2, q2);
|
|
13734
15143
|
}
|
|
13735
15144
|
if (filter.tags && filter.tags.length > 0) {
|
|
13736
15145
|
conditions.push(`(${filter.tags.map(() => "tags LIKE ?").join(" AND ")})`);
|
|
@@ -13739,9 +15148,9 @@ function listConfigSummariesPage(filter = {}, options = {}, db) {
|
|
|
13739
15148
|
}
|
|
13740
15149
|
const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
13741
15150
|
const normalized = normalizeBoundedReadOptions(options);
|
|
13742
|
-
const total =
|
|
15151
|
+
const total = d2.query(`SELECT COUNT(*) AS total FROM configs ${where}`).get(...params)?.total ?? 0;
|
|
13743
15152
|
const pageParams = [...params, normalized.limit, normalized.cursor];
|
|
13744
|
-
const rows =
|
|
15153
|
+
const rows = d2.query(`SELECT id, name, slug, kind, category, agent, target_path, format,
|
|
13745
15154
|
CASE WHEN json_valid(outputs) AND json_type(outputs) = 'array' THEN json_array_length(outputs) ELSE 0 END AS output_count, description, tags,
|
|
13746
15155
|
is_template, version, updated_at
|
|
13747
15156
|
FROM configs ${where} ORDER BY category, name, id LIMIT ? OFFSET ?`).all(...pageParams);
|
|
@@ -13764,14 +15173,14 @@ function listConfigSummariesPage(filter = {}, options = {}, db) {
|
|
|
13764
15173
|
}
|
|
13765
15174
|
function updateConfig(idOrSlug, input, db) {
|
|
13766
15175
|
validateExpectedConfigVersion(input.expected_version);
|
|
13767
|
-
const
|
|
13768
|
-
const existing = getConfig(idOrSlug,
|
|
15176
|
+
const d2 = db || getDatabase();
|
|
15177
|
+
const existing = getConfig(idOrSlug, d2);
|
|
13769
15178
|
const ts = now();
|
|
13770
15179
|
const updates = ["updated_at = ?", "version = version + 1"];
|
|
13771
15180
|
const params = [ts];
|
|
13772
15181
|
if (input.name !== undefined) {
|
|
13773
15182
|
updates.push("name = ?", "slug = ?");
|
|
13774
|
-
params.push(input.name, uniqueSlug(input.name,
|
|
15183
|
+
params.push(input.name, uniqueSlug(input.name, d2, existing.id));
|
|
13775
15184
|
}
|
|
13776
15185
|
if (input.kind !== undefined) {
|
|
13777
15186
|
updates.push("kind = ?");
|
|
@@ -13817,30 +15226,30 @@ function updateConfig(idOrSlug, input, db) {
|
|
|
13817
15226
|
updates.push("synced_at = ?");
|
|
13818
15227
|
params.push(input.synced_at);
|
|
13819
15228
|
}
|
|
13820
|
-
return
|
|
15229
|
+
return d2.transaction(() => {
|
|
13821
15230
|
params.push(existing.id);
|
|
13822
15231
|
const condition = input.expected_version === undefined ? "" : " AND version = ?";
|
|
13823
15232
|
if (input.expected_version !== undefined)
|
|
13824
15233
|
params.push(input.expected_version);
|
|
13825
|
-
const result =
|
|
15234
|
+
const result = d2.run(`UPDATE configs SET ${updates.join(", ")} WHERE id = ?${condition}`, params);
|
|
13826
15235
|
if (result.changes !== 1) {
|
|
13827
15236
|
if (input.expected_version !== undefined)
|
|
13828
15237
|
throw new ConfigVersionConflictError(existing.id, input.expected_version);
|
|
13829
15238
|
throw new ConfigNotFoundError(existing.id);
|
|
13830
15239
|
}
|
|
13831
|
-
const updated = getConfigById(existing.id,
|
|
13832
|
-
createSnapshot(updated.id, updated.content, updated.version,
|
|
15240
|
+
const updated = getConfigById(existing.id, d2);
|
|
15241
|
+
createSnapshot(updated.id, updated.content, updated.version, d2);
|
|
13833
15242
|
return updated;
|
|
13834
15243
|
})();
|
|
13835
15244
|
}
|
|
13836
15245
|
function deleteConfig(idOrSlug, db) {
|
|
13837
|
-
const
|
|
13838
|
-
const existing = getConfig(idOrSlug,
|
|
13839
|
-
|
|
15246
|
+
const d2 = db || getDatabase();
|
|
15247
|
+
const existing = getConfig(idOrSlug, d2);
|
|
15248
|
+
d2.run("DELETE FROM configs WHERE id = ?", [existing.id]);
|
|
13840
15249
|
}
|
|
13841
15250
|
function getConfigStats(db) {
|
|
13842
|
-
const
|
|
13843
|
-
const rows =
|
|
15251
|
+
const d2 = db || getDatabase();
|
|
15252
|
+
const rows = d2.query("SELECT category, COUNT(*) as count FROM configs GROUP BY category").all();
|
|
13844
15253
|
const stats = { total: 0 };
|
|
13845
15254
|
for (const row of rows) {
|
|
13846
15255
|
stats[row.category] = row.count;
|
|
@@ -14040,11 +15449,11 @@ function uniqueProfileSlug(name, db, excludeId) {
|
|
|
14040
15449
|
}
|
|
14041
15450
|
}
|
|
14042
15451
|
function createProfile(input, db) {
|
|
14043
|
-
const
|
|
15452
|
+
const d2 = db || getDatabase();
|
|
14044
15453
|
const id = uuid();
|
|
14045
15454
|
const ts = now();
|
|
14046
|
-
const slug2 = uniqueProfileSlug(input.name,
|
|
14047
|
-
|
|
15455
|
+
const slug2 = uniqueProfileSlug(input.name, d2);
|
|
15456
|
+
d2.run("INSERT INTO profiles (id, name, slug, description, selectors, variables, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", [
|
|
14048
15457
|
id,
|
|
14049
15458
|
input.name,
|
|
14050
15459
|
slug2,
|
|
@@ -14054,31 +15463,31 @@ function createProfile(input, db) {
|
|
|
14054
15463
|
ts,
|
|
14055
15464
|
ts
|
|
14056
15465
|
]);
|
|
14057
|
-
return getProfile(id,
|
|
15466
|
+
return getProfile(id, d2);
|
|
14058
15467
|
}
|
|
14059
15468
|
function getProfile(idOrSlug, db) {
|
|
14060
|
-
const
|
|
14061
|
-
const row =
|
|
15469
|
+
const d2 = db || getDatabase();
|
|
15470
|
+
const row = d2.query("SELECT * FROM profiles WHERE id = ? OR slug = ?").get(idOrSlug, idOrSlug);
|
|
14062
15471
|
if (!row)
|
|
14063
15472
|
throw new ProfileNotFoundError(idOrSlug);
|
|
14064
15473
|
return rowToProfile(row);
|
|
14065
15474
|
}
|
|
14066
15475
|
function listProfilesPage(options = {}, db) {
|
|
14067
|
-
const
|
|
15476
|
+
const d2 = db || getDatabase();
|
|
14068
15477
|
const normalized = normalizeBoundedReadOptions(options);
|
|
14069
|
-
const total =
|
|
14070
|
-
const rows =
|
|
15478
|
+
const total = d2.query("SELECT COUNT(*) AS total FROM profiles").get()?.total ?? 0;
|
|
15479
|
+
const rows = d2.query("SELECT * FROM profiles ORDER BY name LIMIT ? OFFSET ?").all(normalized.limit, normalized.cursor).map(rowToProfile);
|
|
14071
15480
|
return boundedReadPage(rows, total, normalized);
|
|
14072
15481
|
}
|
|
14073
15482
|
function updateProfile(idOrSlug, input, db) {
|
|
14074
|
-
const
|
|
14075
|
-
const existing = getProfile(idOrSlug,
|
|
15483
|
+
const d2 = db || getDatabase();
|
|
15484
|
+
const existing = getProfile(idOrSlug, d2);
|
|
14076
15485
|
const ts = now();
|
|
14077
15486
|
const updates = ["updated_at = ?"];
|
|
14078
15487
|
const params = [ts];
|
|
14079
15488
|
if (input.name !== undefined) {
|
|
14080
15489
|
updates.push("name = ?", "slug = ?");
|
|
14081
|
-
params.push(input.name, uniqueProfileSlug(input.name,
|
|
15490
|
+
params.push(input.name, uniqueProfileSlug(input.name, d2, existing.id));
|
|
14082
15491
|
}
|
|
14083
15492
|
if (input.description !== undefined) {
|
|
14084
15493
|
updates.push("description = ?");
|
|
@@ -14093,34 +15502,34 @@ function updateProfile(idOrSlug, input, db) {
|
|
|
14093
15502
|
params.push(JSON.stringify(input.variables));
|
|
14094
15503
|
}
|
|
14095
15504
|
params.push(existing.id);
|
|
14096
|
-
|
|
14097
|
-
return getProfile(existing.id,
|
|
15505
|
+
d2.run(`UPDATE profiles SET ${updates.join(", ")} WHERE id = ?`, params);
|
|
15506
|
+
return getProfile(existing.id, d2);
|
|
14098
15507
|
}
|
|
14099
15508
|
function deleteProfile(idOrSlug, db) {
|
|
14100
|
-
const
|
|
14101
|
-
const existing = getProfile(idOrSlug,
|
|
14102
|
-
|
|
15509
|
+
const d2 = db || getDatabase();
|
|
15510
|
+
const existing = getProfile(idOrSlug, d2);
|
|
15511
|
+
d2.run("DELETE FROM profiles WHERE id = ?", [existing.id]);
|
|
14103
15512
|
}
|
|
14104
15513
|
function addConfigToProfile(profileIdOrSlug, configId, db, binding) {
|
|
14105
|
-
const
|
|
14106
|
-
const profile = getProfile(profileIdOrSlug,
|
|
14107
|
-
const maxRow =
|
|
15514
|
+
const d2 = db || getDatabase();
|
|
15515
|
+
const profile = getProfile(profileIdOrSlug, d2);
|
|
15516
|
+
const maxRow = d2.query("SELECT MAX(sort_order) as max_order FROM profile_configs WHERE profile_id = ?").get(profile.id);
|
|
14108
15517
|
const order = (maxRow?.max_order ?? -1) + 1;
|
|
14109
|
-
|
|
15518
|
+
d2.run("INSERT OR IGNORE INTO profile_configs (profile_id, config_id, sort_order, binding) VALUES (?, ?, ?, ?)", [profile.id, configId, order, JSON.stringify(normalizeProfileConfigBinding(binding))]);
|
|
14110
15519
|
}
|
|
14111
15520
|
function setProfileConfigBinding(profileIdOrSlug, configId, binding, db) {
|
|
14112
|
-
const
|
|
14113
|
-
const profile = getProfile(profileIdOrSlug,
|
|
15521
|
+
const d2 = db || getDatabase();
|
|
15522
|
+
const profile = getProfile(profileIdOrSlug, d2);
|
|
14114
15523
|
const normalized = normalizeProfileConfigBinding(binding);
|
|
14115
|
-
const result =
|
|
15524
|
+
const result = d2.run("UPDATE profile_configs SET binding = ? WHERE profile_id = ? AND config_id = ?", [JSON.stringify(normalized), profile.id, configId]);
|
|
14116
15525
|
if (result.changes !== 1)
|
|
14117
15526
|
throw new Error(`Config ${configId} is not a member of profile ${profile.slug}.`);
|
|
14118
|
-
return getProfileConfigBindings(profile.id,
|
|
15527
|
+
return getProfileConfigBindings(profile.id, d2).find((row) => row.config_id === configId);
|
|
14119
15528
|
}
|
|
14120
15529
|
function getProfileConfigBindings(profileIdOrSlug, db) {
|
|
14121
|
-
const
|
|
14122
|
-
const profile = getProfile(profileIdOrSlug,
|
|
14123
|
-
return
|
|
15530
|
+
const d2 = db || getDatabase();
|
|
15531
|
+
const profile = getProfile(profileIdOrSlug, d2);
|
|
15532
|
+
return d2.query("SELECT profile_id, config_id, sort_order, binding FROM profile_configs WHERE profile_id = ? ORDER BY sort_order, config_id").all(profile.id).map((row) => ({
|
|
14124
15533
|
profile_id: row.profile_id,
|
|
14125
15534
|
config_id: row.config_id,
|
|
14126
15535
|
sort_order: row.sort_order,
|
|
@@ -14128,35 +15537,35 @@ function getProfileConfigBindings(profileIdOrSlug, db) {
|
|
|
14128
15537
|
}));
|
|
14129
15538
|
}
|
|
14130
15539
|
function removeConfigFromProfile(profileIdOrSlug, configId, db) {
|
|
14131
|
-
const
|
|
14132
|
-
const profile = getProfile(profileIdOrSlug,
|
|
14133
|
-
|
|
15540
|
+
const d2 = db || getDatabase();
|
|
15541
|
+
const profile = getProfile(profileIdOrSlug, d2);
|
|
15542
|
+
d2.run("DELETE FROM profile_configs WHERE profile_id = ? AND config_id = ?", [profile.id, configId]);
|
|
14134
15543
|
}
|
|
14135
15544
|
function addAssetToProfile(profileIdOrSlug, sourceConfigId, binding, db) {
|
|
14136
|
-
const
|
|
14137
|
-
const profile = getProfile(profileIdOrSlug,
|
|
14138
|
-
getConfigById(sourceConfigId,
|
|
15545
|
+
const d2 = db || getDatabase();
|
|
15546
|
+
const profile = getProfile(profileIdOrSlug, d2);
|
|
15547
|
+
getConfigById(sourceConfigId, d2);
|
|
14139
15548
|
const normalized = normalizeProfileAssetBinding(binding);
|
|
14140
|
-
const maxRow =
|
|
15549
|
+
const maxRow = d2.query("SELECT MAX(sort_order) AS max_order FROM profile_assets WHERE profile_id = ?").get(profile.id);
|
|
14141
15550
|
const order = (maxRow?.max_order ?? -1) + 1;
|
|
14142
|
-
|
|
14143
|
-
return getProfileAssetBindings(profile.id,
|
|
15551
|
+
d2.run("INSERT INTO profile_assets (profile_id, source_config_id, asset_key, sort_order, binding) VALUES (?, ?, ?, ?, ?)", [profile.id, sourceConfigId, normalized.assetKey, order, JSON.stringify(normalized)]);
|
|
15552
|
+
return getProfileAssetBindings(profile.id, d2).find((row) => row.binding.assetKey === normalized.assetKey);
|
|
14144
15553
|
}
|
|
14145
15554
|
function setProfileAssetBinding(profileIdOrSlug, assetKey, binding, db) {
|
|
14146
|
-
const
|
|
14147
|
-
const profile = getProfile(profileIdOrSlug,
|
|
15555
|
+
const d2 = db || getDatabase();
|
|
15556
|
+
const profile = getProfile(profileIdOrSlug, d2);
|
|
14148
15557
|
const normalized = normalizeProfileAssetBinding(binding);
|
|
14149
15558
|
if (normalized.assetKey !== assetKey)
|
|
14150
15559
|
throw new Error(`Asset binding key ${normalized.assetKey} does not match route key ${assetKey}.`);
|
|
14151
|
-
const result =
|
|
15560
|
+
const result = d2.run("UPDATE profile_assets SET binding = ? WHERE profile_id = ? AND asset_key = ?", [JSON.stringify(normalized), profile.id, assetKey]);
|
|
14152
15561
|
if (result.changes !== 1)
|
|
14153
15562
|
throw new Error(`Asset ${assetKey} is not a member of profile ${profile.slug}.`);
|
|
14154
|
-
return getProfileAssetBindings(profile.id,
|
|
15563
|
+
return getProfileAssetBindings(profile.id, d2).find((row) => row.binding.assetKey === assetKey);
|
|
14155
15564
|
}
|
|
14156
15565
|
function getProfileAssetBindings(profileIdOrSlug, db) {
|
|
14157
|
-
const
|
|
14158
|
-
const profile = getProfile(profileIdOrSlug,
|
|
14159
|
-
return
|
|
15566
|
+
const d2 = db || getDatabase();
|
|
15567
|
+
const profile = getProfile(profileIdOrSlug, d2);
|
|
15568
|
+
return d2.query("SELECT profile_id, source_config_id, sort_order, binding FROM profile_assets WHERE profile_id = ? ORDER BY sort_order, asset_key").all(profile.id).map((row) => ({
|
|
14160
15569
|
profile_id: row.profile_id,
|
|
14161
15570
|
source_config_id: row.source_config_id,
|
|
14162
15571
|
sort_order: row.sort_order,
|
|
@@ -14164,17 +15573,17 @@ function getProfileAssetBindings(profileIdOrSlug, db) {
|
|
|
14164
15573
|
}));
|
|
14165
15574
|
}
|
|
14166
15575
|
function removeAssetFromProfile(profileIdOrSlug, assetKey, db) {
|
|
14167
|
-
const
|
|
14168
|
-
const profile = getProfile(profileIdOrSlug,
|
|
14169
|
-
|
|
15576
|
+
const d2 = db || getDatabase();
|
|
15577
|
+
const profile = getProfile(profileIdOrSlug, d2);
|
|
15578
|
+
d2.run("DELETE FROM profile_assets WHERE profile_id = ? AND asset_key = ?", [profile.id, assetKey]);
|
|
14170
15579
|
}
|
|
14171
15580
|
function getProfileConfigsPage(profileIdOrSlug, options = {}, db) {
|
|
14172
|
-
const
|
|
14173
|
-
const profile = getProfile(profileIdOrSlug,
|
|
15581
|
+
const d2 = db || getDatabase();
|
|
15582
|
+
const profile = getProfile(profileIdOrSlug, d2);
|
|
14174
15583
|
const normalized = normalizeBoundedReadOptions(options);
|
|
14175
|
-
const total =
|
|
14176
|
-
const rows =
|
|
14177
|
-
return boundedReadPage(rows.map((row) => getConfigById(row.config_id,
|
|
15584
|
+
const total = d2.query("SELECT COUNT(*) AS total FROM profile_configs WHERE profile_id = ?").get(profile.id)?.total ?? 0;
|
|
15585
|
+
const rows = d2.query("SELECT config_id FROM profile_configs WHERE profile_id = ? ORDER BY sort_order LIMIT ? OFFSET ?").all(profile.id, normalized.limit, normalized.cursor);
|
|
15586
|
+
return boundedReadPage(rows.map((row) => getConfigById(row.config_id, d2)), total, normalized);
|
|
14178
15587
|
}
|
|
14179
15588
|
function profileHasSelectors(profile) {
|
|
14180
15589
|
const selectors = profile.selectors ?? {};
|
|
@@ -14191,14 +15600,14 @@ function profileMatchesMachine(profile, machine) {
|
|
|
14191
15600
|
return osMatches && archMatches && hostnameMatches;
|
|
14192
15601
|
}
|
|
14193
15602
|
function resolveProfileForMachineRead(machine = detectMachineContext(), options = {}, db) {
|
|
14194
|
-
const
|
|
15603
|
+
const d2 = db || getDatabase();
|
|
14195
15604
|
const { limit } = normalizeBoundedReadOptions(options);
|
|
14196
15605
|
let cursor = 0;
|
|
14197
15606
|
let scanned = 0;
|
|
14198
15607
|
let total = 0;
|
|
14199
15608
|
let selected = null;
|
|
14200
15609
|
while (true) {
|
|
14201
|
-
const page = listProfilesPage({ limit, cursor },
|
|
15610
|
+
const page = listProfilesPage({ limit, cursor }, d2);
|
|
14202
15611
|
total = page.total;
|
|
14203
15612
|
scanned += page.items.length;
|
|
14204
15613
|
for (const profile of page.items) {
|
|
@@ -14246,31 +15655,31 @@ function currentArch2() {
|
|
|
14246
15655
|
return arch();
|
|
14247
15656
|
}
|
|
14248
15657
|
function registerMachine(hostnameStr, os, archStr, db) {
|
|
14249
|
-
const
|
|
15658
|
+
const d2 = db || getDatabase();
|
|
14250
15659
|
const h = hostnameStr ?? currentHostname2();
|
|
14251
15660
|
const o = os ?? currentOs();
|
|
14252
15661
|
const a = archStr ?? currentArch2();
|
|
14253
|
-
const existing =
|
|
15662
|
+
const existing = d2.query("SELECT * FROM machines WHERE hostname = ?").get(h);
|
|
14254
15663
|
if (existing) {
|
|
14255
15664
|
if (existing.os !== o || existing.arch !== a) {
|
|
14256
|
-
|
|
14257
|
-
return
|
|
15665
|
+
d2.run("UPDATE machines SET os = ?, arch = ? WHERE hostname = ?", [o, a, h]);
|
|
15666
|
+
return d2.query("SELECT * FROM machines WHERE hostname = ?").get(h);
|
|
14258
15667
|
}
|
|
14259
15668
|
return existing;
|
|
14260
15669
|
}
|
|
14261
15670
|
const id = uuid();
|
|
14262
15671
|
const ts = now();
|
|
14263
|
-
|
|
14264
|
-
return
|
|
15672
|
+
d2.run("INSERT INTO machines (id, hostname, os, arch, last_applied_at, created_at) VALUES (?, ?, ?, ?, NULL, ?)", [id, h, o, a, ts]);
|
|
15673
|
+
return d2.query("SELECT * FROM machines WHERE id = ?").get(id);
|
|
14265
15674
|
}
|
|
14266
15675
|
function updateMachineApplied(hostnameStr, db) {
|
|
14267
|
-
const
|
|
15676
|
+
const d2 = db || getDatabase();
|
|
14268
15677
|
const h = hostnameStr ?? currentHostname2();
|
|
14269
|
-
|
|
15678
|
+
d2.run("UPDATE machines SET last_applied_at = ? WHERE hostname = ?", [now(), h]);
|
|
14270
15679
|
}
|
|
14271
15680
|
function listMachines(db) {
|
|
14272
|
-
const
|
|
14273
|
-
return
|
|
15681
|
+
const d2 = db || getDatabase();
|
|
15682
|
+
return d2.query("SELECT * FROM machines ORDER BY last_applied_at DESC NULLS LAST").all();
|
|
14274
15683
|
}
|
|
14275
15684
|
var init_machines = __esm(() => {
|
|
14276
15685
|
init_database();
|
|
@@ -16206,7 +17615,7 @@ function resolveStationProfilePackages(env = process.env) {
|
|
|
16206
17615
|
} catch {
|
|
16207
17616
|
return null;
|
|
16208
17617
|
}
|
|
16209
|
-
const scopes = scopeDirs.map((scope) => ({ scope, names: scopedPackageNames(modulesDir, scope) ?? [] })).filter((entry) => entry.names.length > 0).sort((a,
|
|
17618
|
+
const scopes = scopeDirs.map((scope) => ({ scope, names: scopedPackageNames(modulesDir, scope) ?? [] })).filter((entry) => entry.names.length > 0).sort((a, b2) => a.scope === STATION_PROFILE_PRIMARY_SCOPE ? -1 : b2.scope === STATION_PROFILE_PRIMARY_SCOPE ? 1 : a.scope.localeCompare(b2.scope));
|
|
16210
17619
|
return { scopes };
|
|
16211
17620
|
}
|
|
16212
17621
|
function truncateList(names, max) {
|
|
@@ -16509,6 +17918,22 @@ function applySessionRenderUnlocked(plan, options, coordination) {
|
|
|
16509
17918
|
const manifestPath = resolvePlannedFilePath(plan, plan.manifestFile, targetHome);
|
|
16510
17919
|
assertManifestPrecondition(manifestPath, targetHome, options.expectedManifestSha256);
|
|
16511
17920
|
const previousManifest = readPreviousManifest(manifestPath);
|
|
17921
|
+
if (plan.manifest.claudeProjectImport || previousManifest?.claudeProjectImport) {
|
|
17922
|
+
if (options.force)
|
|
17923
|
+
throw new SessionApplyError("CLAUDE_PROJECT_IMPORT_FORCE: shared project ownership cannot be forced.");
|
|
17924
|
+
if (previousManifest && (previousManifest.tool !== plan.tool || previousManifest.profile !== plan.profile || previousManifest.targetKind !== "project-root" || previousManifest.targetHome !== targetHome || previousManifest.targetOwner?.writer?.id !== SESSION_RENDERER_OWNER_ID)) {
|
|
17925
|
+
throw new SessionApplyError("CLAUDE_PROJECT_IMPORT_OWNER: existing manifest belongs to another target or profile.");
|
|
17926
|
+
}
|
|
17927
|
+
if (previousManifest && !options.expectedManifestSha256) {
|
|
17928
|
+
throw new SessionApplyError("CLAUDE_PROJECT_IMPORT_CAS: changing a managed shared project requires its exact manifest preimage.");
|
|
17929
|
+
}
|
|
17930
|
+
if (previousManifest?.claudeProjectImport && !plan.manifest.claudeProjectImport) {
|
|
17931
|
+
throw new SessionApplyError("CLAUDE_PROJECT_IMPORT_RETIREMENT: removing a shared consumer requires an explicit reviewed migration; automatic removal is unsupported.");
|
|
17932
|
+
}
|
|
17933
|
+
if (plan.manifest.claudeProjectImport && !previousManifest?.claudeProjectImport && existsSync14(join18(targetHome, "CLAUDE.md"))) {
|
|
17934
|
+
throw new SessionApplyError("CLAUDE_PROJECT_IMPORT_CONFLICT: existing unmanaged CLAUDE.md cannot be adopted as an import companion.");
|
|
17935
|
+
}
|
|
17936
|
+
}
|
|
16512
17937
|
const previousHashes = previousManifest ? new Map(previousManifest.files.map((file) => [file.relativePath, file.sha256])) : new Map;
|
|
16513
17938
|
const adoptions = validateFileAdoptions(plan, targetHome, previousHashes, options);
|
|
16514
17939
|
const adoptedHashes = new Map(adoptions.map((entry) => [entry.relativePath, entry.preimageSha256]));
|
|
@@ -17596,7 +19021,7 @@ function writeSessionSnapshot(plan, targetHome, manifestPath, results, previousM
|
|
|
17596
19021
|
content
|
|
17597
19022
|
};
|
|
17598
19023
|
});
|
|
17599
|
-
if (!previousManifest && existingFiles.length === 0 && plan.tool !== "codewith") {
|
|
19024
|
+
if (!previousManifest && existingFiles.length === 0 && plan.tool !== "codewith" && !plan.manifest.claudeProjectImport) {
|
|
17600
19025
|
return {
|
|
17601
19026
|
schema: "hasna.configs.session-render-rollback/v1",
|
|
17602
19027
|
status: "unsupported",
|
|
@@ -17750,7 +19175,8 @@ var selectorSchema = exports_external.object({
|
|
|
17750
19175
|
stationProfile: exports_external.boolean(),
|
|
17751
19176
|
checkGlobalCoverage: exports_external.boolean(),
|
|
17752
19177
|
assetSurface: nonempty.optional(),
|
|
17753
|
-
assetScope: exports_external.enum(["global", "project", "session"]).optional()
|
|
19178
|
+
assetScope: exports_external.enum(["global", "project", "session"]).optional(),
|
|
19179
|
+
claudeProjectImport: exports_external.object({ providerVersion: exports_external.literal("2.1.278") }).strict().optional()
|
|
17754
19180
|
}).strict();
|
|
17755
19181
|
function authority(value) {
|
|
17756
19182
|
const url = new URL(value);
|
|
@@ -17826,6 +19252,10 @@ function readManagedManifest(targetHome) {
|
|
|
17826
19252
|
throw new Error("SESSION_REFRESH_MANIFEST_INVALID: project-scoped render is missing its recorded project root.");
|
|
17827
19253
|
}
|
|
17828
19254
|
manifest.refreshSelector = normalizeSessionHostedProfileSelector(manifest.refreshSelector);
|
|
19255
|
+
const companion = manifest.claudeProjectImport;
|
|
19256
|
+
if (Boolean(companion) !== Boolean(manifest.refreshSelector.claudeProjectImport) || companion && (manifest.tool !== "sumi" || manifest.targetKind !== "project-root" || companion.providerVersion !== manifest.refreshSelector.claudeProjectImport?.providerVersion || companion.capability !== "claude-project-relative-import/v1" || companion.canonicalPath !== "AGENTS.md" || companion.importPath !== "CLAUDE.md" || manifest.files.find((file) => file.relativePath === "AGENTS.md")?.sha256 !== companion.canonicalSha256 || !manifest.files.some((file) => file.relativePath === "CLAUDE.md"))) {
|
|
19257
|
+
throw new Error("SESSION_REFRESH_COMPANION_INVALID: shared project capability, selector and canonical file must agree.");
|
|
19258
|
+
}
|
|
17829
19259
|
return { manifest, sha256: createHash10("sha256").update(raw).digest("hex") };
|
|
17830
19260
|
}
|
|
17831
19261
|
async function refreshSessionRender(input) {
|
|
@@ -17870,6 +19300,7 @@ async function refreshSessionRender(input) {
|
|
|
17870
19300
|
...previous.manifest.targetKind === "project-root" ? { projectRoot: targetHome } : previous.manifest.targetOwner.projectRoot ? { projectRoot: previous.manifest.targetOwner.projectRoot } : {},
|
|
17871
19301
|
sessionId: previous.manifest.sessionId ?? undefined,
|
|
17872
19302
|
refreshSelector: selector,
|
|
19303
|
+
claudeProjectImport: selector.claudeProjectImport,
|
|
17873
19304
|
codewithNativeImports: selector.codewithNativeImports,
|
|
17874
19305
|
allowEmptySources: selector.allowEmptySources,
|
|
17875
19306
|
configs,
|
|
@@ -18362,8 +19793,8 @@ function claudeRuleOutputs(fileName) {
|
|
|
18362
19793
|
function normalizeOutputs(outputs) {
|
|
18363
19794
|
return outputs ?? [];
|
|
18364
19795
|
}
|
|
18365
|
-
function outputsEqual(a,
|
|
18366
|
-
return JSON.stringify(normalizeOutputs(a)) === JSON.stringify(normalizeOutputs(
|
|
19796
|
+
function outputsEqual(a, b2) {
|
|
19797
|
+
return JSON.stringify(normalizeOutputs(a)) === JSON.stringify(normalizeOutputs(b2));
|
|
18367
19798
|
}
|
|
18368
19799
|
var UNGUARDED_LOCAL_ENV_HELPER = '. "$HOME/.local/bin/env"';
|
|
18369
19800
|
var GUARDED_LOCAL_ENV_HELPER = '[ -r "$HOME/.local/bin/env" ] && . "$HOME/.local/bin/env"';
|
|
@@ -19625,7 +21056,7 @@ function scanPackageManagerSecrets(options = {}) {
|
|
|
19625
21056
|
findings.push(...scanFile(file, text, classifyHomeFile(name), false, home));
|
|
19626
21057
|
}
|
|
19627
21058
|
}
|
|
19628
|
-
findings.sort((a,
|
|
21059
|
+
findings.sort((a, b2) => a.path.localeCompare(b2.path) || a.line - b2.line || a.rule.localeCompare(b2.rule));
|
|
19629
21060
|
return {
|
|
19630
21061
|
clean: findings.length === 0,
|
|
19631
21062
|
scannedFiles,
|
|
@@ -19765,7 +21196,7 @@ function scanBunConfigFile(text, path, tracked) {
|
|
|
19765
21196
|
const startsReleaseAgeExcludes = /minimumReleaseAgeExcludes/i.test(stripped);
|
|
19766
21197
|
const scanExcludes = startsReleaseAgeExcludes || inReleaseAgeExcludes;
|
|
19767
21198
|
if (scanExcludes) {
|
|
19768
|
-
const quoted = [...stripped.matchAll(/["']([^"']+)["']/g)].map((
|
|
21199
|
+
const quoted = [...stripped.matchAll(/["']([^"']+)["']/g)].map((m2) => m2[1]);
|
|
19769
21200
|
for (const item of quoted) {
|
|
19770
21201
|
if (!isExactHasnaPackageName(item)) {
|
|
19771
21202
|
findings.push({
|