@contentrain/mcp 2.3.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/{annotations-D3tlsF38.mjs → annotations-C-tQVmot.mjs} +15 -1
- package/dist/annotations-C-tQVmot.mjs.map +1 -0
- package/dist/{apply-manager-SLCRLHN_.mjs → apply-manager-BybvnUVC.mjs} +28 -18
- package/dist/apply-manager-BybvnUVC.mjs.map +1 -0
- package/dist/{astro-parser-LNjEspnf.mjs → astro-parser-Cb9uuBpW.mjs} +3 -3
- package/dist/{astro-parser-LNjEspnf.mjs.map → astro-parser-Cb9uuBpW.mjs.map} +1 -1
- package/dist/{availability-sWWRz2W0.mjs → availability-Dgcmvv99.mjs} +1 -1
- package/dist/{availability-sWWRz2W0.mjs.map → availability-Dgcmvv99.mjs.map} +1 -1
- package/dist/{branch-lifecycle-BAfgSQBv.mjs → branch-lifecycle-B6PXZ2N7.mjs} +11 -61
- package/dist/branch-lifecycle-B6PXZ2N7.mjs.map +1 -0
- package/dist/{branch-lifecycle-D4W0WIs4.d.mts → branch-lifecycle-DhzHfzs3.d.mts} +1 -1
- package/dist/{branch-lifecycle-D4W0WIs4.d.mts.map → branch-lifecycle-DhzHfzs3.d.mts.map} +1 -1
- package/dist/{compiler-CNzm2Y2I.mjs → compiler-B6hNQeCC.mjs} +2 -2
- package/dist/{compiler-CNzm2Y2I.mjs.map → compiler-B6hNQeCC.mjs.map} +1 -1
- package/dist/{compiler-sfc.cjs-y0B0L3MH.mjs → compiler-sfc.cjs-8yY7b5bx.mjs} +2 -2
- package/dist/{compiler-sfc.cjs-y0B0L3MH.mjs.map → compiler-sfc.cjs-8yY7b5bx.mjs.map} +1 -1
- package/dist/{config-oxxgznz7.mjs → config-VlRKRwAS.mjs} +1 -1
- package/dist/{config-oxxgznz7.mjs.map → config-VlRKRwAS.mjs.map} +1 -1
- package/dist/{content-manager-DWo3G64y.d.mts → content-manager-Dn4tqDw1.d.mts} +10 -7
- package/dist/content-manager-Dn4tqDw1.d.mts.map +1 -0
- package/dist/{context-DjglDPvj.mjs → context-C3x6I3cE.mjs} +4 -4
- package/dist/{context-DjglDPvj.mjs.map → context-C3x6I3cE.mjs.map} +1 -1
- package/dist/core/apply-manager.d.mts +8 -0
- package/dist/core/apply-manager.d.mts.map +1 -1
- package/dist/core/apply-manager.mjs +10 -9
- package/dist/core/config.d.mts +1 -1
- package/dist/core/config.mjs +1 -1
- package/dist/core/content-manager.d.mts +2 -2
- package/dist/core/content-manager.mjs +2 -2
- package/dist/core/context.d.mts +1 -1
- package/dist/core/context.mjs +5 -5
- package/dist/core/contracts/index.d.mts +2 -2
- package/dist/core/doctor.mjs +7 -6
- package/dist/core/graph-builder.mjs +2 -2
- package/dist/core/meta-manager.d.mts +8 -9
- package/dist/core/meta-manager.d.mts.map +1 -1
- package/dist/core/meta-manager.mjs +2 -2
- package/dist/core/model-manager.d.mts +39 -3
- package/dist/core/model-manager.d.mts.map +1 -1
- package/dist/core/model-manager.mjs +3 -3
- package/dist/core/ops/index.d.mts +40 -3
- package/dist/core/ops/index.d.mts.map +1 -1
- package/dist/core/ops/index.mjs +4 -4
- package/dist/core/overlay-reader.d.mts +1 -1
- package/dist/core/overlay-reader.mjs +1 -1
- package/dist/core/scan-config.mjs +1 -1
- package/dist/core/scanner.mjs +3 -3
- package/dist/core/validator/index.d.mts +1 -1
- package/dist/core/validator/index.d.mts.map +1 -1
- package/dist/core/validator/index.mjs +4 -4
- package/dist/{detect-CdDU4Ew_.mjs → detect-B0oXbQaP.mjs} +1 -1
- package/dist/{detect-CdDU4Ew_.mjs.map → detect-B0oXbQaP.mjs.map} +1 -1
- package/dist/{doctor-BwJ_nmqS.mjs → doctor-DNPuGgcg.mjs} +28 -15
- package/dist/doctor-DNPuGgcg.mjs.map +1 -0
- package/dist/{errors-e0YdjooK.mjs → errors-CvBS12e7.mjs} +1 -1
- package/dist/{errors-e0YdjooK.mjs.map → errors-CvBS12e7.mjs.map} +1 -1
- package/dist/fs-DLbVB-Ek.mjs.map +1 -1
- package/dist/git/branch-lifecycle.d.mts +1 -1
- package/dist/git/branch-lifecycle.mjs +3 -2
- package/dist/git/identity.d.mts +42 -0
- package/dist/git/identity.d.mts.map +1 -0
- package/dist/git/identity.mjs +2 -0
- package/dist/git/transaction.d.mts +1 -1
- package/dist/git/transaction.d.mts.map +1 -1
- package/dist/git/transaction.mjs +9 -8
- package/dist/{graph-builder-DK4Mh8Tn.mjs → graph-builder-BEocwW13.mjs} +2 -2
- package/dist/{graph-builder-DK4Mh8Tn.mjs.map → graph-builder-BEocwW13.mjs.map} +1 -1
- package/dist/{id-DV_T9Ic8.mjs → id-BjhaIxTL.mjs} +1 -1
- package/dist/{id-DV_T9Ic8.mjs.map → id-BjhaIxTL.mjs.map} +1 -1
- package/dist/identity-D8QoGxhT.mjs +125 -0
- package/dist/identity-D8QoGxhT.mjs.map +1 -0
- package/dist/{index-w8QHThNS.d.mts → index-BWbTJlXm.d.mts} +2 -2
- package/dist/index.mjs +21 -20
- package/dist/index.mjs.map +1 -1
- package/dist/{local-8dJ5NIWL.mjs → local-Db5X9mjZ.mjs} +25 -13
- package/dist/local-Db5X9mjZ.mjs.map +1 -0
- package/dist/{meta-manager-CJUiTgP2.mjs → meta-manager-B_Se183X.mjs} +29 -5
- package/dist/meta-manager-B_Se183X.mjs.map +1 -0
- package/dist/{model-manager-DP2CZiMT.mjs → model-manager-DgyKMjLN.mjs} +169 -25
- package/dist/model-manager-DgyKMjLN.mjs.map +1 -0
- package/dist/{node-BxujauDw.mjs → node-DUGiIkv1.mjs} +1 -1
- package/dist/{node-BxujauDw.mjs.map → node-DUGiIkv1.mjs.map} +1 -1
- package/dist/{ops-CGKIKwDc.mjs → ops-BzbThweu.mjs} +165 -26
- package/dist/ops-BzbThweu.mjs.map +1 -0
- package/dist/{overlay-reader-DNaVsgiS.mjs → overlay-reader-CkU_pGXZ.mjs} +1 -1
- package/dist/{overlay-reader-DNaVsgiS.mjs.map → overlay-reader-CkU_pGXZ.mjs.map} +1 -1
- package/dist/{paths-enT2coeX.mjs → paths-CdPPWpbG.mjs} +1 -1
- package/dist/{paths-enT2coeX.mjs.map → paths-CdPPWpbG.mjs.map} +1 -1
- package/dist/providers/github/index.d.mts +1 -1
- package/dist/providers/github/index.mjs +2 -2
- package/dist/providers/gitlab/index.d.mts +1 -1
- package/dist/providers/gitlab/index.mjs +2 -2
- package/dist/providers/local/index.d.mts +7 -1
- package/dist/providers/local/index.d.mts.map +1 -1
- package/dist/providers/local/index.mjs +11 -10
- package/dist/{scan-config-BlNLRCMx.mjs → scan-config-Dx49nCqk.mjs} +1 -1
- package/dist/{scan-config-BlNLRCMx.mjs.map → scan-config-Dx49nCqk.mjs.map} +1 -1
- package/dist/{scanner-CGWhmpDz.mjs → scanner-BSvXjfkp.mjs} +6 -6
- package/dist/{scanner-CGWhmpDz.mjs.map → scanner-BSvXjfkp.mjs.map} +1 -1
- package/dist/serialization-tmgfFBOh.mjs +2 -0
- package/dist/server/http/index.d.mts +1 -1
- package/dist/server/http/index.mjs +21 -20
- package/dist/server/http/index.mjs.map +1 -1
- package/dist/{server-CUZnuHQx.mjs → server-B2ib9TkR.mjs} +313 -115
- package/dist/server-B2ib9TkR.mjs.map +1 -0
- package/dist/{server-DLauBiu2.d.mts → server-CLPNnhYL.d.mts} +2 -2
- package/dist/{server-DLauBiu2.d.mts.map → server-CLPNnhYL.d.mts.map} +1 -1
- package/dist/server.d.mts +1 -1
- package/dist/server.mjs +21 -20
- package/dist/{source-map-generator-Bvbu-kM5.mjs → source-map-generator-DhjiQdV3.mjs} +1 -1
- package/dist/{source-map-generator-Bvbu-kM5.mjs.map → source-map-generator-DhjiQdV3.mjs.map} +1 -1
- package/dist/{svelte-parser-DaFK9iY0.mjs → svelte-parser-CwySu9yn.mjs} +3 -3
- package/dist/{svelte-parser-DaFK9iY0.mjs.map → svelte-parser-CwySu9yn.mjs.map} +1 -1
- package/dist/templates/index.mjs +1 -1
- package/dist/{templates-D6EllixQ.mjs → templates-CAkTIRkE.mjs} +430 -109
- package/dist/templates-CAkTIRkE.mjs.map +1 -0
- package/dist/testing/memory-provider.d.mts +52 -0
- package/dist/testing/memory-provider.d.mts.map +1 -0
- package/dist/testing/memory-provider.mjs +205 -0
- package/dist/testing/memory-provider.mjs.map +1 -0
- package/dist/tools/annotations.d.mts.map +1 -1
- package/dist/tools/annotations.mjs +1 -1
- package/dist/tools/availability.mjs +1 -1
- package/dist/{transaction-1SPznNt3.mjs → transaction-BW9ektWu.mjs} +13 -12
- package/dist/transaction-BW9ektWu.mjs.map +1 -0
- package/dist/{tsx-parser-md1N0Niu.mjs → tsx-parser-BvsK6lyG.mjs} +1 -1
- package/dist/{tsx-parser-md1N0Niu.mjs.map → tsx-parser-BvsK6lyG.mjs.map} +1 -1
- package/dist/tsx-parser-Byc7HlJ8.mjs +2 -0
- package/dist/util/detect.mjs +1 -1
- package/dist/util/fs.d.mts +1 -1
- package/dist/util/fs.d.mts.map +1 -1
- package/dist/util/id.mjs +1 -1
- package/dist/{validator-ChiYk6ap.mjs → validator-0sJ9vh1j.mjs} +65 -8
- package/dist/validator-0sJ9vh1j.mjs.map +1 -0
- package/dist/{vue-parser-CHxDohd8.mjs → vue-parser-auedZiJG.mjs} +3 -3
- package/dist/{vue-parser-CHxDohd8.mjs.map → vue-parser-auedZiJG.mjs.map} +1 -1
- package/package.json +13 -5
- package/testing/conformance/01-new-collection-entry/expected/.contentrain/meta/blog/en.json +1 -0
- package/testing/conformance/01-new-collection-entry/expected/.contentrain/models/blog.json +6 -5
- package/testing/conformance/01-new-collection-entry/setup/.contentrain/models/blog.json +6 -5
- package/testing/conformance/02-new-singleton/expected/.contentrain/meta/hero/en.json +1 -0
- package/testing/conformance/02-new-singleton/expected/.contentrain/models/hero.json +6 -5
- package/testing/conformance/02-new-singleton/setup/.contentrain/models/hero.json +6 -5
- package/testing/conformance/03-new-dictionary/expected/.contentrain/meta/ui-strings/en.json +1 -0
- package/testing/conformance/03-new-dictionary/expected/.contentrain/models/ui-strings.json +4 -3
- package/testing/conformance/03-new-dictionary/setup/.contentrain/models/ui-strings.json +4 -3
- package/dist/annotations-D3tlsF38.mjs.map +0 -1
- package/dist/apply-manager-SLCRLHN_.mjs.map +0 -1
- package/dist/branch-lifecycle-BAfgSQBv.mjs.map +0 -1
- package/dist/content-manager-DWo3G64y.d.mts.map +0 -1
- package/dist/doctor-BwJ_nmqS.mjs.map +0 -1
- package/dist/local-8dJ5NIWL.mjs.map +0 -1
- package/dist/meta-manager-CJUiTgP2.mjs.map +0 -1
- package/dist/model-manager-DP2CZiMT.mjs.map +0 -1
- package/dist/ops-CGKIKwDc.mjs.map +0 -1
- package/dist/serialization-B1CEzR4H.mjs +0 -2
- package/dist/server-CUZnuHQx.mjs.map +0 -1
- package/dist/templates-D6EllixQ.mjs.map +0 -1
- package/dist/transaction-1SPznNt3.mjs.map +0 -1
- package/dist/tsx-parser-C3XsIrwU.mjs +0 -2
- package/dist/validator-ChiYk6ap.mjs.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { n as canonicalStringify$1, t as
|
|
1
|
+
import { n as serializeMarkdownFrontmatter$1, r as canonicalStringify$1, t as parseMarkdownFrontmatter$1 } from "./serialization-tmgfFBOh.mjs";
|
|
2
2
|
import { i as metaFilePath, n as contentFilePath, r as documentFilePath } from "./paths-CmVw5Cw2.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { r as mergeEntryMeta } from "./meta-manager-B_Se183X.mjs";
|
|
4
4
|
import { dirname, join } from "node:path";
|
|
5
|
-
import { generateEntryId, validateEntryId, validateLocale, validateSlug } from "@contentrain/types";
|
|
5
|
+
import { LOCALE_PATTERN, MODEL_FIELD_ORDER, SLUG_PATTERN, canonicalStringify, generateEntryId, validateEntryId, validateLocale, validateSlug } from "@contentrain/types";
|
|
6
6
|
import { mkdir, rm, writeFile } from "node:fs/promises";
|
|
7
7
|
//#region src/core/ops/apply-to-worktree.ts
|
|
8
8
|
/**
|
|
@@ -302,6 +302,8 @@ function rewriteMarkdownMedia(body, base) {
|
|
|
302
302
|
}
|
|
303
303
|
//#endregion
|
|
304
304
|
//#region src/core/ops/content-save.ts
|
|
305
|
+
/** Keys named individually in a replacement advisory before it collapses to a count. */
|
|
306
|
+
const MAX_REPORTED_KEYS = 5;
|
|
305
307
|
/**
|
|
306
308
|
* Build the FileChange[] required to save a batch of content entries. The
|
|
307
309
|
* plan is deterministic, pure, and does not touch disk — it reads existing
|
|
@@ -389,9 +391,14 @@ async function planContentSave(reader, input) {
|
|
|
389
391
|
const mPath = metaFilePath(model, locale, defaultLocale);
|
|
390
392
|
const existing = contentByPath.get(cPath) ?? await readJsonOrEmpty(cPath);
|
|
391
393
|
const newData = entry.data;
|
|
392
|
-
const collisions = Object.keys(newData).filter((k) => k in existing && existing[k] !== newData[k]);
|
|
393
|
-
if (collisions.length > 0) throw new Error(`Dictionary "${model.id}" (${locale}): ${collisions.length} key collision(s) — [${collisions.join(", ")}] already exist with different values. Read existing keys with contentrain_content_list first, or include all keys in a single save call.`);
|
|
394
394
|
const entryAdvisories = [];
|
|
395
|
+
const replaced = Object.keys(newData).filter((k) => k in existing && existing[k] !== newData[k]);
|
|
396
|
+
if (replaced.length > 0) {
|
|
397
|
+
const shown = replaced.slice(0, MAX_REPORTED_KEYS);
|
|
398
|
+
const detail = shown.map((k) => `"${k}": "${existing[k]}" → "${newData[k]}"`).join(", ");
|
|
399
|
+
const more = replaced.length > shown.length ? `, and ${replaced.length - shown.length} more` : "";
|
|
400
|
+
entryAdvisories.push(`Dictionary "${model.id}" (${locale}): replaced ${replaced.length} existing value(s) — ${detail}${more}.`);
|
|
401
|
+
}
|
|
395
402
|
const reverseMap = /* @__PURE__ */ new Map();
|
|
396
403
|
for (const [k, v] of Object.entries(existing)) reverseMap.set(v, k);
|
|
397
404
|
for (const [newKey, newValue] of Object.entries(newData)) {
|
|
@@ -420,28 +427,42 @@ async function planContentSave(reader, input) {
|
|
|
420
427
|
break;
|
|
421
428
|
}
|
|
422
429
|
case "document": {
|
|
430
|
+
const entryAdvisories = [];
|
|
423
431
|
const slug = entry.slug ?? entry.data["slug"];
|
|
424
432
|
if (!slug) throw new Error("Document entries require a slug");
|
|
425
433
|
const slugErr = validateSlug(slug);
|
|
426
434
|
if (slugErr) throw new Error(slugErr);
|
|
427
|
-
const
|
|
428
|
-
const
|
|
429
|
-
|
|
430
|
-
|
|
435
|
+
const incomingFm = { ...entry.data };
|
|
436
|
+
const bodySent = "body" in incomingFm;
|
|
437
|
+
const incomingBody = incomingFm["body"] ?? "";
|
|
438
|
+
delete incomingFm["body"];
|
|
439
|
+
if (!incomingFm["slug"]) incomingFm["slug"] = slug;
|
|
431
440
|
const dPath = documentFilePath(model, locale, slug);
|
|
432
441
|
const mPath = metaFilePath(model, locale, defaultLocale, slug);
|
|
433
|
-
let existingRaw = null;
|
|
434
|
-
try {
|
|
442
|
+
let existingRaw = markdownChanges.get(dPath) ?? null;
|
|
443
|
+
if (existingRaw === null) try {
|
|
435
444
|
existingRaw = await reader.readFile(dPath);
|
|
436
445
|
} catch {}
|
|
437
446
|
const action = existingRaw ? "updated" : "created";
|
|
447
|
+
const existing = existingRaw ? parseMarkdownFrontmatter$1(existingRaw) : null;
|
|
448
|
+
const fmData = {
|
|
449
|
+
...existing?.frontmatter,
|
|
450
|
+
...incomingFm
|
|
451
|
+
};
|
|
452
|
+
const bodyContent = bodySent ? incomingBody : existing?.body ?? "";
|
|
453
|
+
if (bodySent && !incomingBody.trim() && existing?.body.trim()) {
|
|
454
|
+
const notice = `Document "${slug}" (${locale}): body cleared — an explicit empty "body" replaced ${existing.body.length} characters. Omit "body" to leave it untouched.`;
|
|
455
|
+
entryAdvisories.push(notice);
|
|
456
|
+
advisories.push(notice);
|
|
457
|
+
}
|
|
438
458
|
const normalizedBody = mediaBaseUrl ? rewriteMarkdownMedia(bodyContent, mediaBaseUrl) : bodyContent;
|
|
439
459
|
markdownChanges.set(dPath, serializeMarkdownFrontmatter$1(normalizeMedia(fmData), normalizedBody));
|
|
440
460
|
metaByPath.set(mPath, mergeEntryMeta(await priorMeta(mPath), entry.data));
|
|
441
461
|
result.push({
|
|
442
462
|
action,
|
|
443
463
|
slug,
|
|
444
|
-
locale
|
|
464
|
+
locale,
|
|
465
|
+
...entryAdvisories.length > 0 ? { advisories: entryAdvisories } : {}
|
|
445
466
|
});
|
|
446
467
|
break;
|
|
447
468
|
}
|
|
@@ -528,18 +549,6 @@ async function enumerateTwoLevels(reader, dir) {
|
|
|
528
549
|
}
|
|
529
550
|
//#endregion
|
|
530
551
|
//#region src/core/ops/model-save.ts
|
|
531
|
-
/** Field order for canonical model JSON — preserves reader ergonomics. */
|
|
532
|
-
const MODEL_FIELD_ORDER = [
|
|
533
|
-
"id",
|
|
534
|
-
"name",
|
|
535
|
-
"kind",
|
|
536
|
-
"domain",
|
|
537
|
-
"i18n",
|
|
538
|
-
"description",
|
|
539
|
-
"content_path",
|
|
540
|
-
"locale_strategy",
|
|
541
|
-
"fields"
|
|
542
|
-
];
|
|
543
552
|
/**
|
|
544
553
|
* Build the FileChange[] required to create or update a model definition.
|
|
545
554
|
*
|
|
@@ -570,6 +579,136 @@ async function planModelSave(reader, input) {
|
|
|
570
579
|
};
|
|
571
580
|
}
|
|
572
581
|
//#endregion
|
|
573
|
-
|
|
582
|
+
//#region src/core/ops/vocabulary-save.ts
|
|
583
|
+
const VOCABULARY_PATH = ".contentrain/vocabulary.json";
|
|
584
|
+
/** Terms named individually in an advisory before it collapses to a count. */
|
|
585
|
+
const MAX_REPORTED_TERMS = 5;
|
|
586
|
+
async function readVocabulary(reader) {
|
|
587
|
+
try {
|
|
588
|
+
const parsed = JSON.parse(await reader.readFile(VOCABULARY_PATH));
|
|
589
|
+
return {
|
|
590
|
+
version: parsed.version ?? 1,
|
|
591
|
+
terms: parsed.terms ?? {}
|
|
592
|
+
};
|
|
593
|
+
} catch {
|
|
594
|
+
return {
|
|
595
|
+
version: 1,
|
|
596
|
+
terms: {}
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Validate the shape callers get wrong.
|
|
602
|
+
*
|
|
603
|
+
* The nesting is `term -> locale -> translation`, and it reads identically the
|
|
604
|
+
* other way round, so a caller that groups by locale at the top level produces
|
|
605
|
+
* a structurally valid file that matches nothing. That is not a typo anyone
|
|
606
|
+
* notices — the vocabulary simply stops having any effect. Checking that outer
|
|
607
|
+
* keys are term slugs and inner keys are locale codes catches the inversion at
|
|
608
|
+
* the point of writing.
|
|
609
|
+
*/
|
|
610
|
+
function validateTerms(terms) {
|
|
611
|
+
const errors = [];
|
|
612
|
+
for (const [term, translations] of Object.entries(terms)) {
|
|
613
|
+
if (!SLUG_PATTERN.test(term)) errors.push(`Term "${term}": must be kebab-case. The outer key is the term, not a locale.`);
|
|
614
|
+
if (typeof translations !== "object" || translations === null || Array.isArray(translations)) {
|
|
615
|
+
errors.push(`Term "${term}": expected an object of locale → translation.`);
|
|
616
|
+
continue;
|
|
617
|
+
}
|
|
618
|
+
if (Object.keys(translations).length === 0) errors.push(`Term "${term}": has no translations.`);
|
|
619
|
+
for (const [locale, value] of Object.entries(translations)) {
|
|
620
|
+
if (!LOCALE_PATTERN.test(locale)) errors.push(`Term "${term}": "${locale}" is not a locale code. Terms nest as { "${term}": { "en": "…" } } — one term, its translations inside.`);
|
|
621
|
+
if (typeof value !== "string") errors.push(`Term "${term}" (${locale}): translation must be a string, got ${typeof value}.`);
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
return errors;
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* Build the FileChange[] to add or update vocabulary terms.
|
|
628
|
+
*
|
|
629
|
+
* Vocabulary had no write tool at all: the rules forbid editing `.contentrain/`
|
|
630
|
+
* by hand, and there was no supported way to obey that. This closes it through
|
|
631
|
+
* the same plan/apply path every other write uses, so it lands on a `cr/*`
|
|
632
|
+
* branch and follows the project's workflow like anything else.
|
|
633
|
+
*/
|
|
634
|
+
async function planVocabularySave(reader, input) {
|
|
635
|
+
const errors = validateTerms(input.terms);
|
|
636
|
+
if (errors.length > 0) throw new Error(`Vocabulary validation failed:\n- ${errors.join("\n- ")}`);
|
|
637
|
+
const existing = await readVocabulary(reader);
|
|
638
|
+
const added = [];
|
|
639
|
+
const updated = [];
|
|
640
|
+
const advisories = [];
|
|
641
|
+
const merged = { ...existing.terms };
|
|
642
|
+
for (const [term, translations] of Object.entries(input.terms)) {
|
|
643
|
+
const prior = existing.terms[term];
|
|
644
|
+
if (!prior) {
|
|
645
|
+
added.push(term);
|
|
646
|
+
merged[term] = { ...translations };
|
|
647
|
+
continue;
|
|
648
|
+
}
|
|
649
|
+
updated.push(term);
|
|
650
|
+
merged[term] = {
|
|
651
|
+
...prior,
|
|
652
|
+
...translations
|
|
653
|
+
};
|
|
654
|
+
const changed = Object.entries(translations).filter(([l, v]) => l in prior && prior[l] !== v);
|
|
655
|
+
if (changed.length > 0) {
|
|
656
|
+
const shown = changed.slice(0, MAX_REPORTED_TERMS);
|
|
657
|
+
const detail = shown.map(([l, v]) => `${l}: "${prior[l]}" → "${v}"`).join(", ");
|
|
658
|
+
const more = changed.length > shown.length ? `, and ${changed.length - shown.length} more` : "";
|
|
659
|
+
advisories.push(`Term "${term}": replaced ${changed.length} translation(s) — ${detail}${more}.`);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
const byValue = /* @__PURE__ */ new Map();
|
|
663
|
+
for (const [term, translations] of Object.entries(merged)) for (const value of Object.values(translations)) {
|
|
664
|
+
const owner = byValue.get(value);
|
|
665
|
+
if (owner && owner !== term) advisories.push(`Terms "${owner}" and "${term}" share the translation "${value}".`);
|
|
666
|
+
else byValue.set(value, term);
|
|
667
|
+
}
|
|
668
|
+
return {
|
|
669
|
+
changes: [{
|
|
670
|
+
path: VOCABULARY_PATH,
|
|
671
|
+
content: canonicalStringify({
|
|
672
|
+
version: existing.version,
|
|
673
|
+
terms: merged
|
|
674
|
+
})
|
|
675
|
+
}],
|
|
676
|
+
result: {
|
|
677
|
+
added,
|
|
678
|
+
updated,
|
|
679
|
+
total: Object.keys(merged).length
|
|
680
|
+
},
|
|
681
|
+
advisories
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
/** Build the FileChange[] to remove vocabulary terms. */
|
|
685
|
+
async function planVocabularyDelete(reader, input) {
|
|
686
|
+
const existing = await readVocabulary(reader);
|
|
687
|
+
const deleted = [];
|
|
688
|
+
const missing = [];
|
|
689
|
+
const remaining = { ...existing.terms };
|
|
690
|
+
for (const term of input.terms) if (term in remaining) {
|
|
691
|
+
delete remaining[term];
|
|
692
|
+
deleted.push(term);
|
|
693
|
+
} else missing.push(term);
|
|
694
|
+
const advisories = missing.length > 0 ? [`Not in the vocabulary, so nothing to delete: ${missing.join(", ")}.`] : [];
|
|
695
|
+
return {
|
|
696
|
+
changes: deleted.length > 0 ? [{
|
|
697
|
+
path: VOCABULARY_PATH,
|
|
698
|
+
content: canonicalStringify({
|
|
699
|
+
version: existing.version,
|
|
700
|
+
terms: remaining
|
|
701
|
+
})
|
|
702
|
+
}] : [],
|
|
703
|
+
result: {
|
|
704
|
+
deleted,
|
|
705
|
+
missing,
|
|
706
|
+
total: Object.keys(remaining).length
|
|
707
|
+
},
|
|
708
|
+
advisories
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
//#endregion
|
|
712
|
+
export { planContentSave as a, planModelDelete as i, planVocabularySave as n, planContentDelete as o, planModelSave as r, applyChangesToWorktree as s, planVocabularyDelete as t };
|
|
574
713
|
|
|
575
|
-
//# sourceMappingURL=ops-
|
|
714
|
+
//# sourceMappingURL=ops-BzbThweu.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ops-BzbThweu.mjs","names":["canonicalStringify","parseMarkdownFrontmatter","serializeMarkdownFrontmatter","canonicalStringify","canonicalStringify"],"sources":["../src/core/ops/apply-to-worktree.ts","../src/core/ops/content-delete.ts","../src/core/media/media-rewrite.ts","../src/core/ops/content-save.ts","../src/core/ops/model-delete.ts","../src/core/ops/model-save.ts","../src/core/ops/vocabulary-save.ts"],"sourcesContent":["import { mkdir, rm, writeFile } from 'node:fs/promises'\nimport { dirname, join } from 'node:path'\nimport type { FileChange } from '../contracts/index.js'\n\n/**\n * Phase 2 shim — applies a `FileChange[]` to a local worktree directory.\n *\n * Phase 3 replaces this with `LocalProvider.applyPlan` (same logic, owned by\n * the provider) while a `GitHubProvider.applyPlan` produces the equivalent\n * commit through the Git Data API. Until then, tool handlers call this shim\n * inside the existing `createTransaction` flow so Phase 2 gets plan/apply\n * semantics without rewriting the transaction machinery.\n *\n * - `content: string` → `writeFile` (creates parent dirs).\n * - `content: null` → `rm`; missing files are tolerated.\n * - Changes are applied in their given order; callers should sort for\n * determinism.\n */\nexport async function applyChangesToWorktree(worktree: string, changes: readonly FileChange[]): Promise<void> {\n for (const change of changes) {\n const absolute = join(worktree, change.path)\n if (change.content === null) {\n await rm(absolute, { force: true }).catch(() => { /* tolerate missing */ })\n continue\n }\n await mkdir(dirname(absolute), { recursive: true })\n await writeFile(absolute, change.content, 'utf-8')\n }\n}\n","import type { EntryMeta, ModelDefinition } from '@contentrain/types'\nimport { validateSlug } from '@contentrain/types'\nimport type { FileChange, RepoReader } from '../contracts/index.js'\nimport { canonicalStringify } from '../serialization/index.js'\nimport { contentFilePath, documentFilePath, metaFilePath } from './paths.js'\nimport type { OpPlan } from './types.js'\n\nexport interface ContentDeleteInput {\n model: ModelDefinition\n id?: string\n slug?: string\n locale?: string\n keys?: string[]\n /**\n * `config.locales.default` — where a non-i18n model's single meta record\n * lives. Required to resolve meta paths; see `metaFilePath`.\n */\n defaultLocale: string\n}\n\nexport type ContentDeletePlan = OpPlan<string[]>\n\nfunction contentDir(model: Pick<ModelDefinition, 'domain' | 'id' | 'content_path'>): string {\n return model.content_path ?? `.contentrain/content/${model.domain}/${model.id}`\n}\n\nasync function tryReadJson<T>(reader: RepoReader, path: string): Promise<T | null> {\n try {\n return JSON.parse(await reader.readFile(path)) as T\n } catch {\n return null\n }\n}\n\nasync function discoverCollectionLocales(\n reader: RepoReader,\n model: ModelDefinition,\n): Promise<string[]> {\n const dir = contentDir(model)\n const files = await reader.listDirectory(dir)\n const strategy = model.locale_strategy ?? 'file'\n if (strategy === 'directory') {\n return files\n }\n return files\n .filter(f => f.endsWith('.json'))\n .map(f => f.replace('.json', '').replace(`${model.id}.`, ''))\n}\n\n/**\n * Build the FileChange[] required to delete content. Pure — touches no disk.\n *\n * Semantics preserved from legacy `deleteContent`:\n * - Collection: remove the entry ID from each locale's content file and its\n * meta file. Meta file is deleted outright if the removal empties it.\n * - Singleton: delete the locale's content + meta file (locale-scoped when\n * i18n, non-i18n removes whatever meta lives under `.contentrain/meta/{id}/`).\n * - Dictionary: two modes — key-scoped removal updates the file in place,\n * or locale-scoped removes the content + meta pair.\n * - Document: strategy-aware delete (file/suffix/directory/none), plus\n * meta removal under `.contentrain/meta/{id}/{slug}/`.\n */\nexport async function planContentDelete(\n reader: RepoReader,\n input: ContentDeleteInput,\n): Promise<ContentDeletePlan> {\n const { model } = input\n\n // A non-i18n model stores content locale-agnostically in data.json and keeps\n // exactly one meta record, pinned to the default locale. A locale-scoped\n // delete is therefore meaningless — and actively destructive: the locale\n // silently maps onto data.json and the default-locale meta, so passing a\n // non-default locale deletes the shared content and the wrong meta while the\n // named locale's stray meta is never touched. Reject it; stray per-locale\n // meta is cleaned up by `contentrain_validate fix:true`.\n if (!model.i18n && input.locale) {\n throw new Error(\n `Model \"${model.id}\" has i18n disabled — its content is locale-agnostic (stored in data.json), `\n + 'so a locale-scoped delete is invalid. Omit \"locale\" to delete the entry, '\n + 'or run contentrain_validate fix:true to remove stray per-locale meta files.',\n )\n }\n\n const changes: FileChange[] = []\n const removed: string[] = []\n\n switch (model.kind) {\n case 'collection': {\n if (!input.id) throw new Error('Collection delete requires an entry ID')\n\n const locales = input.locale\n ? [input.locale]\n : await discoverCollectionLocales(reader, model)\n\n for (const loc of locales) {\n const cPath = contentFilePath(model, loc)\n const data = await tryReadJson<Record<string, unknown>>(reader, cPath)\n if (!data || !(input.id in data)) continue\n delete data[input.id]\n const sorted: Record<string, unknown> = {}\n for (const k of Object.keys(data).toSorted()) sorted[k] = data[k]\n changes.push({ path: cPath, content: canonicalStringify(sorted) })\n removed.push(`content/${model.domain}/${model.id}/${loc}.json#${input.id}`)\n }\n\n for (const loc of locales) {\n // For a non-i18n model `loc` is the pseudo-locale \"data\" (discovered from\n // data.json); metaFilePath maps it onto the default locale regardless.\n const mPath = metaFilePath(model, loc, input.defaultLocale)\n const meta = await tryReadJson<Record<string, EntryMeta>>(reader, mPath)\n if (!meta || !(input.id in meta)) continue\n delete meta[input.id]\n if (Object.keys(meta).length > 0) {\n changes.push({ path: mPath, content: canonicalStringify(meta) })\n } else {\n changes.push({ path: mPath, content: null })\n }\n }\n break\n }\n\n case 'singleton': {\n if (model.i18n && !input.locale) {\n throw new Error('Singleton delete requires a locale when i18n is enabled')\n }\n const locale = input.locale ?? 'data'\n const cPath = contentFilePath(model, locale)\n changes.push({ path: cPath, content: null })\n removed.push(model.i18n\n ? `content/${model.domain}/${model.id}/${locale}.json`\n : `content/${model.domain}/${model.id}/data.json`)\n\n if (model.i18n) {\n changes.push({ path: metaFilePath(model, locale, input.defaultLocale), content: null })\n } else {\n // Removing data.json leaves a non-i18n model with no content at all, so\n // every meta file under it goes — including strays left by older writes.\n await pushAllMetaForModel(reader, model.id, changes)\n }\n break\n }\n\n case 'dictionary': {\n if (model.i18n && !input.locale) {\n throw new Error('Dictionary delete requires a locale when i18n is enabled')\n }\n const locale = input.locale ?? 'data'\n const cPath = contentFilePath(model, locale)\n\n if (input.keys?.length) {\n const existing = (await tryReadJson<Record<string, string>>(reader, cPath)) ?? {}\n const notFound: string[] = []\n for (const key of input.keys) {\n if (key in existing) delete existing[key]\n else notFound.push(key)\n }\n if (notFound.length > 0) {\n throw new Error(`Dictionary \"${model.id}\" (${locale}): keys not found — [${notFound.join(', ')}]`)\n }\n changes.push({ path: cPath, content: canonicalStringify(existing) })\n removed.push(...input.keys.map(k => `${model.id}/${locale}:${k}`))\n } else {\n changes.push({ path: cPath, content: null })\n removed.push(model.i18n\n ? `content/${model.domain}/${model.id}/${locale}.json`\n : `content/${model.domain}/${model.id}/data.json`)\n if (model.i18n) {\n changes.push({ path: metaFilePath(model, locale, input.defaultLocale), content: null })\n } else {\n await pushAllMetaForModel(reader, model.id, changes)\n }\n }\n break\n }\n\n case 'document': {\n if (!input.slug) throw new Error('Document delete requires a slug')\n const slugErr = validateSlug(input.slug)\n if (slugErr) throw new Error(slugErr)\n\n const dir = contentDir(model)\n const strategy = model.locale_strategy ?? 'file'\n\n if (!model.i18n) {\n changes.push({ path: `${dir}/${input.slug}.md`, content: null })\n } else if (strategy === 'file') {\n const slugDir = `${dir}/${input.slug}`\n const files = await reader.listDirectory(slugDir)\n for (const f of files) changes.push({ path: `${slugDir}/${f}`, content: null })\n } else if (input.locale) {\n changes.push({ path: documentFilePath(model, input.locale, input.slug), content: null })\n } else if (strategy === 'suffix') {\n const files = await reader.listDirectory(dir)\n for (const f of files) {\n if (f.startsWith(`${input.slug}.`) && f.endsWith('.md')) {\n changes.push({ path: `${dir}/${f}`, content: null })\n }\n }\n } else if (strategy === 'directory') {\n const subdirs = await reader.listDirectory(dir)\n for (const d of subdirs) {\n const filePath = `${dir}/${d}/${input.slug}.md`\n if (await reader.fileExists(filePath)) {\n changes.push({ path: filePath, content: null })\n }\n }\n } else if (strategy === 'none') {\n const files = await reader.listDirectory(dir)\n if (files.includes(`${input.slug}.md`)) {\n changes.push({ path: `${dir}/${input.slug}.md`, content: null })\n }\n }\n\n removed.push(`${model.content_path ?? `content/${model.domain}/${model.id}`}/${input.slug}`)\n\n const metaSlugDir = `.contentrain/meta/${model.id}/${input.slug}`\n if (input.locale) {\n changes.push({ path: `${metaSlugDir}/${input.locale}.json`, content: null })\n } else {\n const metaFiles = await reader.listDirectory(metaSlugDir)\n for (const f of metaFiles) changes.push({ path: `${metaSlugDir}/${f}`, content: null })\n }\n break\n }\n }\n\n changes.sort((a, b) => a.path.localeCompare(b.path))\n return { changes, result: removed, advisories: [] }\n}\n\nasync function pushAllMetaForModel(reader: RepoReader, modelId: string, changes: FileChange[]): Promise<void> {\n const metaDir = `.contentrain/meta/${modelId}`\n const files = await reader.listDirectory(metaDir)\n for (const f of files) changes.push({ path: `${metaDir}/${f}`, content: null })\n}\n","import type { FieldDef, FieldType } from '@contentrain/types'\n\n/**\n * Media path → delivery URL rewriting for MCP content writes.\n *\n * Ported from Studio's `server/utils/media-rewrite.ts`, with one deliberate\n * difference: Studio derives the delivery base from a `projectId` plus its\n * runtime config, whereas MCP receives the fully-qualified per-project base\n * directly via `RepoProvider.mediaBaseUrl`\n * (`{siteUrl}/api/cdn/v1/{projectId}` — the project segment is already\n * included). So here `toDeliveryUrl` is a single `{base}/{path}` join.\n *\n * Why this exists: Studio stores uploaded media in CDN/R2 and references it\n * from content by a relative storage path (`media/...`). That path renders\n * nowhere on its own — it must become an absolute, public delivery URL before\n * it reaches a browser. When an external agent writes through MCP Cloud, the\n * write bypasses Studio's content-engine and goes straight through\n * `planContentSave`, so this is where the normalization has to happen: the\n * git-committed value is then already a ready-to-use URL for any consumer\n * (`@contentrain/query`, raw markdown, a plain landing page) with no SDK.\n *\n * Only image/video/file fields (resolved via the model schema, including those\n * nested in object/array fields) and `media/...` src/href targets in\n * markdown/HTML are rewritten. External URLs (`http(s)://`, `//`, `data:`) and\n * already-absolute delivery URLs pass through untouched, so every entry point\n * is idempotent and safe to call repeatedly. In local mode (no base) media\n * stays a relative path — the OSS file model.\n */\n\nconst MEDIA_FIELD_TYPES = new Set<FieldType>(['image', 'video', 'file'])\n\n/**\n * Whether a stored field value is a relative media-storage path (`media/...`)\n * rather than an already-absolute URL or external link. Only these are\n * rewritten to delivery URLs — `http(s)://`, `//`, and `data:` are left as-is.\n */\nexport function isStoredMediaPath(value: unknown): value is string {\n return typeof value === 'string' && value.startsWith('media/')\n}\n\n/** Join a relative media path onto the per-project delivery base. */\nexport function toDeliveryUrl(base: string, path: string): string {\n return `${base.replace(/\\/+$/, '')}/${path}`\n}\n\n/**\n * Rewrite a stored media path to its absolute delivery URL. Non-media values\n * (external URLs, empty, non-strings) pass through untouched, so this is safe\n * to call on any field value.\n */\nexport function rewriteMediaUrl(base: string, value: unknown): unknown {\n return isStoredMediaPath(value) ? toDeliveryUrl(base, value) : value\n}\n\n/**\n * Rewrite media paths within a single field value, guided by its FieldDef so\n * only media fields — including those nested inside object/array fields — are\n * touched. Non-media values pass through.\n */\nexport function rewriteFieldMedia(value: unknown, field: FieldDef, base: string): unknown {\n if (value == null) return value\n\n if (MEDIA_FIELD_TYPES.has(field.type))\n return rewriteMediaUrl(base, value)\n\n if (field.type === 'object' && field.fields && typeof value === 'object' && !Array.isArray(value))\n return rewriteEntryMedia(value as Record<string, unknown>, field.fields, base)\n\n if (field.type === 'array' && Array.isArray(value)) {\n const itemDef: FieldDef | null = typeof field.items === 'string'\n ? { type: field.items as FieldType }\n : field.items ?? null\n if (!itemDef) return value\n return value.map(v => rewriteFieldMedia(v, itemDef, base))\n }\n\n return value\n}\n\n/**\n * Rewrite media paths across one entry/frontmatter object using a field map.\n * Returns a shallow copy (the input is never mutated); a no-op when the object\n * has no media fields.\n */\nexport function rewriteEntryMedia(\n entry: Record<string, unknown>,\n fields: Record<string, FieldDef>,\n base: string,\n): Record<string, unknown> {\n const out = { ...entry }\n for (const [fieldId, field] of Object.entries(fields)) {\n if (fieldId in out)\n out[fieldId] = rewriteFieldMedia(out[fieldId], field, base)\n }\n return out\n}\n\n/** Rewrite `media/...` markdown image/link targets and inline src/href attrs. */\nexport function rewriteMarkdownMedia(body: string, base: string): string {\n return body\n // markdown image/link target: ](media/...) — stops at whitespace, ) or \"\n .replace(/(\\]\\()(media\\/[^)\\s\"]+)/g, (_m, open, p) => `${open}${toDeliveryUrl(base, p)}`)\n // inline HTML src=/href=\"media/...\"\n .replace(/(\\s(?:src|href)=)([\"'])(media\\/[^\"']+)\\2/gi,\n (_m, attr, quote, p) => `${attr}${quote}${toDeliveryUrl(base, p)}${quote}`)\n}\n","import type { ContentrainConfig, EntryMeta, ModelDefinition, Vocabulary } from '@contentrain/types'\nimport { generateEntryId, validateEntryId, validateLocale, validateSlug } from '@contentrain/types'\nimport type { FileChange, RepoReader } from '../contracts/index.js'\nimport type { ContentEntry } from '../content-manager.js'\nimport { canonicalStringify, parseMarkdownFrontmatter, serializeMarkdownFrontmatter } from '../serialization/index.js'\nimport { rewriteEntryMedia, rewriteMarkdownMedia } from '../media/media-rewrite.js'\nimport type { ContentSaveEntryResult, ContentSavePlan } from './types.js'\nimport { contentFilePath, documentFilePath, metaFilePath } from './paths.js'\nimport { mergeEntryMeta } from '../meta-manager.js'\n\n/** Keys named individually in a replacement advisory before it collapses to a count. */\nconst MAX_REPORTED_KEYS = 5\n\ninterface PlanInput {\n model: ModelDefinition\n entries: ContentEntry[]\n config: ContentrainConfig\n vocabulary?: Vocabulary | null\n /**\n * Per-project public media delivery base (`RepoProvider.mediaBaseUrl`). When\n * set (hosted/cloud mode), relative `media/...` references in media fields\n * and markdown bodies are normalized to absolute delivery URLs before the\n * value is committed. Undefined in local mode — paths are kept verbatim.\n */\n mediaBaseUrl?: string\n}\n\n/**\n * Build the FileChange[] required to save a batch of content entries. The\n * plan is deterministic, pure, and does not touch disk — it reads existing\n * state through `reader` and returns changes for a single atomic commit.\n *\n * Grouping: multiple entries targeting the same (model, locale) share a\n * single content file and a single meta file. Reads are cached in-memory\n * so repeated reads of the same path during a plan are one IO.\n */\nexport async function planContentSave(reader: RepoReader, input: PlanInput): Promise<ContentSavePlan> {\n const { model, entries, config, vocabulary, mediaBaseUrl } = input\n const result: ContentSaveEntryResult[] = []\n const advisories: string[] = []\n\n // Hosted/cloud mode: normalize relative `media/...` references to absolute\n // delivery URLs so the committed value renders anywhere with no SDK. A no-op\n // in local mode (no base) or for field-less models (e.g. dictionaries).\n const normalizeMedia = (data: Record<string, unknown>): Record<string, unknown> =>\n mediaBaseUrl && model.fields ? rewriteEntryMedia(data, model.fields, mediaBaseUrl) : data\n\n // In-memory accumulators keyed by content-root-relative path.\n const contentByPath = new Map<string, unknown>()\n const metaByPath = new Map<string, unknown>()\n const markdownChanges = new Map<string, string>()\n\n async function readJsonOrEmpty<T>(path: string): Promise<T> {\n try {\n return JSON.parse(await reader.readFile(path)) as T\n } catch {\n return {} as T\n }\n }\n\n /** Absent file and absent entry both mean \"no prior meta\" — hence undefined, not `{}`. */\n async function readJsonOrUndefined<T>(path: string): Promise<T | undefined> {\n try {\n return JSON.parse(await reader.readFile(path)) as T\n } catch {\n return undefined\n }\n }\n\n /** Prior meta for a whole-file (non-collection) meta path, honouring the accumulator. */\n async function priorMeta(mPath: string): Promise<EntryMeta | undefined> {\n return (metaByPath.get(mPath) as EntryMeta | undefined)\n ?? await readJsonOrUndefined<EntryMeta>(mPath)\n }\n\n const defaultLocale = config.locales.default\n\n for (const entry of entries) {\n const locale = entry.locale ?? defaultLocale\n\n const localeErr = validateLocale(locale, config)\n if (localeErr) throw new Error(localeErr)\n if (entry.id) {\n const err = validateEntryId(entry.id)\n if (err) throw new Error(err)\n }\n if (entry.slug) {\n const err = validateSlug(entry.slug)\n if (err) throw new Error(err)\n }\n\n switch (model.kind) {\n case 'singleton': {\n const cPath = contentFilePath(model, locale)\n const mPath = metaFilePath(model, locale, defaultLocale)\n contentByPath.set(cPath, normalizeMedia(entry.data))\n metaByPath.set(mPath, mergeEntryMeta(await priorMeta(mPath), entry.data))\n result.push({ action: 'updated', locale })\n break\n }\n\n case 'collection': {\n const isNew = !entry.id\n const id = entry.id ?? generateEntryId()\n const cPath = contentFilePath(model, locale)\n const mPath = metaFilePath(model, locale, defaultLocale)\n\n const existing = (contentByPath.get(cPath) as Record<string, unknown> | undefined)\n ?? await readJsonOrEmpty<Record<string, unknown>>(cPath)\n\n const action: 'created' | 'updated' = isNew || !(id in existing) ? 'created' : 'updated'\n existing[id] = normalizeMedia(entry.data)\n\n const sorted: Record<string, unknown> = {}\n for (const key of Object.keys(existing).toSorted()) {\n sorted[key] = existing[key]\n }\n contentByPath.set(cPath, sorted)\n\n const existingMeta = (metaByPath.get(mPath) as Record<string, EntryMeta> | undefined)\n ?? await readJsonOrEmpty<Record<string, EntryMeta>>(mPath)\n existingMeta[id] = mergeEntryMeta(existingMeta[id], entry.data)\n metaByPath.set(mPath, existingMeta)\n\n result.push({ action, id, locale })\n break\n }\n\n case 'dictionary': {\n const cPath = contentFilePath(model, locale)\n const mPath = metaFilePath(model, locale, defaultLocale)\n\n const existing = (contentByPath.get(cPath) as Record<string, string> | undefined)\n ?? await readJsonOrEmpty<Record<string, string>>(cPath)\n\n const newData = entry.data as Record<string, string>\n const entryAdvisories: string[] = []\n\n // Overwriting a key used to be refused outright, which made the most\n // ordinary dictionary operation — correcting a translation — impossible:\n // the workaround was delete, merge, save, merge. Four operations and two\n // branches to fix one string. The refusal also advised \"include all keys\n // in a single save call\", which cannot work, because the check compares\n // values per key rather than counting them.\n //\n // Choosing a translation is a content decision, and MCP does not make\n // those. It reports them — the same way the duplicate-value case two\n // blocks below already does — and the branch diff shows the rest.\n const replaced = Object.keys(newData).filter(\n k => k in existing && existing[k] !== newData[k],\n )\n if (replaced.length > 0) {\n const shown = replaced.slice(0, MAX_REPORTED_KEYS)\n const detail = shown.map(k => `\"${k}\": \"${existing[k]}\" → \"${newData[k]}\"`).join(', ')\n const more = replaced.length > shown.length ? `, and ${replaced.length - shown.length} more` : ''\n entryAdvisories.push(\n `Dictionary \"${model.id}\" (${locale}): replaced ${replaced.length} existing value(s) — ${detail}${more}.`,\n )\n }\n\n const reverseMap = new Map<string, string>()\n for (const [k, v] of Object.entries(existing)) reverseMap.set(v, k)\n for (const [newKey, newValue] of Object.entries(newData)) {\n if (newKey in existing) continue\n const existingKey = reverseMap.get(newValue)\n if (existingKey && existingKey !== newKey) {\n entryAdvisories.push(\n `Value \"${newValue}\" already exists as key \"${existingKey}\". Consider reusing instead of creating \"${newKey}\".`,\n )\n }\n }\n\n if (vocabulary && Object.keys(vocabulary.terms).length > 0) {\n outer:\n for (const [newKey, newValue] of Object.entries(newData)) {\n if (newKey in existing) continue\n for (const translations of Object.values(vocabulary.terms)) {\n if (Object.values(translations).includes(newValue)) {\n entryAdvisories.push(\n `Value \"${newValue}\" matches a vocabulary term. Use the canonical form for consistency.`,\n )\n continue outer\n }\n }\n }\n }\n\n advisories.push(...entryAdvisories)\n\n contentByPath.set(cPath, { ...existing, ...newData })\n metaByPath.set(mPath, mergeEntryMeta(await priorMeta(mPath), entry.data))\n\n result.push({\n action: 'updated',\n locale,\n ...(entryAdvisories.length > 0 ? { advisories: entryAdvisories } : {}),\n })\n break\n }\n\n case 'document': {\n const entryAdvisories: string[] = []\n const slug = entry.slug ?? (entry.data['slug'] as string | undefined)\n if (!slug) throw new Error('Document entries require a slug')\n const slugErr = validateSlug(slug)\n if (slugErr) throw new Error(slugErr)\n\n const incomingFm = { ...entry.data }\n const bodySent = 'body' in incomingFm\n const incomingBody = (incomingFm['body'] as string | undefined) ?? ''\n delete incomingFm['body']\n if (!incomingFm['slug']) incomingFm['slug'] = slug\n\n const dPath = documentFilePath(model, locale, slug)\n const mPath = metaFilePath(model, locale, defaultLocale, slug)\n\n // Accumulator before disk, as the collection branch does: two entries\n // touching one document in a single call must compose, not race.\n let existingRaw: string | null = markdownChanges.get(dPath) ?? null\n if (existingRaw === null) {\n try { existingRaw = await reader.readFile(dPath) }\n catch { /* not yet */ }\n }\n // Same rule the collection branch uses: anything already present —\n // on disk or produced earlier in this plan — makes this an update.\n const action: 'created' | 'updated' = existingRaw ? 'updated' : 'created'\n\n // Merge with what is on disk, the way collections and singletons above\n // already do. Documents were the only kind that replaced instead of\n // merging, so a save that touched one frontmatter field wrote a file\n // containing only that field — and an entirely empty body. Nothing\n // reported it: the response said `valid: true`, because validation runs\n // over the plan's own output, which was internally consistent and\n // wrong. Under auto-merge that reaches the default branch directly.\n const existing = existingRaw ? parseMarkdownFrontmatter(existingRaw) : null\n const fmData = { ...existing?.frontmatter, ...incomingFm }\n\n // Absent `body` means \"I am not editing the body\" — keep what is there.\n // A `body` that is present, even empty, is an instruction, and is\n // honoured; clearing real content that way is announced rather than\n // silent, because it is indistinguishable from a templating mistake.\n const bodyContent = bodySent ? incomingBody : (existing?.body ?? '')\n if (bodySent && !incomingBody.trim() && existing?.body.trim()) {\n const notice = `Document \"${slug}\" (${locale}): body cleared — an explicit empty \"body\" replaced ${existing.body.length} characters. Omit \"body\" to leave it untouched.`\n entryAdvisories.push(notice)\n advisories.push(notice)\n }\n\n // Frontmatter media fields go through the schema-guided rewrite; the\n // markdown body has its `media/...` image/link targets rewritten too.\n const normalizedBody = mediaBaseUrl ? rewriteMarkdownMedia(bodyContent, mediaBaseUrl) : bodyContent\n markdownChanges.set(dPath, serializeMarkdownFrontmatter(normalizeMedia(fmData), normalizedBody))\n metaByPath.set(mPath, mergeEntryMeta(await priorMeta(mPath), entry.data))\n\n result.push({\n action,\n slug,\n locale,\n ...(entryAdvisories.length > 0 ? { advisories: entryAdvisories } : {}),\n })\n break\n }\n }\n }\n\n const changes: FileChange[] = []\n for (const [path, data] of contentByPath) {\n changes.push({ path, content: canonicalStringify(data) })\n }\n for (const [path, meta] of metaByPath) {\n changes.push({ path, content: canonicalStringify(meta) })\n }\n for (const [path, content] of markdownChanges) {\n changes.push({ path, content })\n }\n changes.sort((a, b) => a.path.localeCompare(b.path))\n\n return { changes, result, advisories }\n}\n","import type { ModelDefinition } from '@contentrain/types'\nimport type { FileChange, RepoReader } from '../contracts/index.js'\nimport type { OpPlan } from './types.js'\n\nexport interface ModelDeleteInput {\n model: ModelDefinition\n}\n\nexport type ModelDeletePlan = OpPlan<string[]>\n\n/**\n * Build the FileChange[] required to delete a model and its associated\n * content/meta files.\n *\n * The schema is at most two directory levels deep (e.g. document meta at\n * `.contentrain/meta/{id}/{slug}/{locale}.json`). The helper below walks\n * that much, which is enough for every model kind + locale strategy and\n * keeps us free of a general-purpose recursive lister for now.\n *\n * `result` is the legacy three-entry summary:\n * - `models/{id}.json`\n * - `content/{domain}/{id}/` (only if any content files existed)\n * - `meta/{id}/` (only if any meta files existed)\n */\nexport async function planModelDelete(reader: RepoReader, input: ModelDeleteInput): Promise<ModelDeletePlan> {\n const { model } = input\n const changes: FileChange[] = []\n const removed: string[] = []\n\n changes.push({ path: `.contentrain/models/${model.id}.json`, content: null })\n removed.push(`models/${model.id}.json`)\n\n const contentDir = model.content_path ?? `.contentrain/content/${model.domain}/${model.id}`\n const contentFiles = await enumerateTwoLevels(reader, contentDir)\n for (const path of contentFiles) {\n changes.push({ path, content: null })\n }\n if (contentFiles.length > 0) {\n removed.push(model.content_path ?? `content/${model.domain}/${model.id}/`)\n }\n\n const metaDir = `.contentrain/meta/${model.id}`\n const metaFiles = await enumerateTwoLevels(reader, metaDir)\n for (const path of metaFiles) {\n changes.push({ path, content: null })\n }\n if (metaFiles.length > 0) {\n removed.push(`meta/${model.id}/`)\n }\n\n changes.sort((a, b) => a.path.localeCompare(b.path))\n return { changes, result: removed, advisories: [] }\n}\n\n/** List files up to two directory levels deep. Filters to `.json` and `.md`. */\nasync function enumerateTwoLevels(reader: RepoReader, dir: string): Promise<string[]> {\n const results: string[] = []\n const entries = await reader.listDirectory(dir)\n for (const entry of entries) {\n const path = `${dir}/${entry}`\n if (entry.endsWith('.json') || entry.endsWith('.md')) {\n results.push(path)\n continue\n }\n const subEntries = await reader.listDirectory(path)\n for (const sub of subEntries) {\n if (sub.endsWith('.json') || sub.endsWith('.md')) {\n results.push(`${path}/${sub}`)\n }\n }\n }\n return results\n}\n","import type { ModelDefinition } from '@contentrain/types'\nimport { MODEL_FIELD_ORDER } from '@contentrain/types'\nimport type { FileChange, RepoReader } from '../contracts/index.js'\nimport { canonicalStringify } from '../serialization/index.js'\nimport type { OpPlan } from './types.js'\n\nexport interface ModelSaveInput {\n model: ModelDefinition\n}\n\nexport interface ModelSaveResult {\n action: 'created' | 'updated'\n id: string\n}\n\nexport type ModelSavePlan = OpPlan<ModelSaveResult>\n\n/**\n * Build the FileChange[] required to create or update a model definition.\n *\n * The only disk change is the model JSON file itself. Content and meta\n * directories are created on-demand when their first write lands — git does\n * not track empty directories, and MCP's write helpers `mkdir -p` before\n * every file write, so there is no operational reason to emit an empty-dir\n * ensure step here.\n */\nexport async function planModelSave(reader: RepoReader, input: ModelSaveInput): Promise<ModelSavePlan> {\n const { model } = input\n const modelPath = `.contentrain/models/${model.id}.json`\n\n let action: 'created' | 'updated' = 'created'\n try {\n await reader.readFile(modelPath)\n action = 'updated'\n } catch { /* not yet exists */ }\n\n const changes: FileChange[] = [\n { path: modelPath, content: canonicalStringify(model, MODEL_FIELD_ORDER) },\n ]\n\n return {\n changes,\n result: { action, id: model.id },\n advisories: [],\n }\n}\n","import type { Vocabulary } from '@contentrain/types'\nimport { canonicalStringify, LOCALE_PATTERN, SLUG_PATTERN } from '@contentrain/types'\nimport type { FileChange, RepoReader } from '../contracts/index.js'\nimport type { OpPlan } from './types.js'\n\nconst VOCABULARY_PATH = '.contentrain/vocabulary.json'\n\n/** Terms named individually in an advisory before it collapses to a count. */\nconst MAX_REPORTED_TERMS = 5\n\nexport interface VocabularySaveInput {\n /**\n * Terms to add or update, keyed by term slug, each holding its translations\n * keyed by locale. Merged with what is already there — a term absent from\n * this map is untouched.\n */\n terms: Record<string, Record<string, string>>\n}\n\nexport interface VocabularyDeleteInput {\n /** Term slugs to remove. A slug that is not present is reported, not an error. */\n terms: string[]\n}\n\nexport interface VocabularySaveResult {\n added: string[]\n updated: string[]\n total: number\n}\n\nexport interface VocabularyDeleteResult {\n deleted: string[]\n missing: string[]\n total: number\n}\n\nexport type VocabularySavePlan = OpPlan<VocabularySaveResult>\nexport type VocabularyDeletePlan = OpPlan<VocabularyDeleteResult>\n\nasync function readVocabulary(reader: RepoReader): Promise<Vocabulary> {\n try {\n const parsed = JSON.parse(await reader.readFile(VOCABULARY_PATH)) as Partial<Vocabulary>\n return { version: parsed.version ?? 1, terms: parsed.terms ?? {} }\n } catch {\n return { version: 1, terms: {} }\n }\n}\n\n/**\n * Validate the shape callers get wrong.\n *\n * The nesting is `term -> locale -> translation`, and it reads identically the\n * other way round, so a caller that groups by locale at the top level produces\n * a structurally valid file that matches nothing. That is not a typo anyone\n * notices — the vocabulary simply stops having any effect. Checking that outer\n * keys are term slugs and inner keys are locale codes catches the inversion at\n * the point of writing.\n */\nfunction validateTerms(terms: Record<string, Record<string, string>>): string[] {\n const errors: string[] = []\n\n for (const [term, translations] of Object.entries(terms)) {\n if (!SLUG_PATTERN.test(term)) {\n errors.push(`Term \"${term}\": must be kebab-case. The outer key is the term, not a locale.`)\n }\n if (typeof translations !== 'object' || translations === null || Array.isArray(translations)) {\n errors.push(`Term \"${term}\": expected an object of locale → translation.`)\n continue\n }\n if (Object.keys(translations).length === 0) {\n errors.push(`Term \"${term}\": has no translations.`)\n }\n for (const [locale, value] of Object.entries(translations)) {\n if (!LOCALE_PATTERN.test(locale)) {\n errors.push(\n `Term \"${term}\": \"${locale}\" is not a locale code. Terms nest as { \"${term}\": { \"en\": \"…\" } } — one term, its translations inside.`,\n )\n }\n if (typeof value !== 'string') {\n errors.push(`Term \"${term}\" (${locale}): translation must be a string, got ${typeof value}.`)\n }\n }\n }\n\n return errors\n}\n\n/**\n * Build the FileChange[] to add or update vocabulary terms.\n *\n * Vocabulary had no write tool at all: the rules forbid editing `.contentrain/`\n * by hand, and there was no supported way to obey that. This closes it through\n * the same plan/apply path every other write uses, so it lands on a `cr/*`\n * branch and follows the project's workflow like anything else.\n */\nexport async function planVocabularySave(\n reader: RepoReader,\n input: VocabularySaveInput,\n): Promise<VocabularySavePlan> {\n const errors = validateTerms(input.terms)\n if (errors.length > 0) {\n throw new Error(`Vocabulary validation failed:\\n- ${errors.join('\\n- ')}`)\n }\n\n const existing = await readVocabulary(reader)\n const added: string[] = []\n const updated: string[] = []\n const advisories: string[] = []\n\n const merged: Record<string, Record<string, string>> = { ...existing.terms }\n for (const [term, translations] of Object.entries(input.terms)) {\n const prior = existing.terms[term]\n if (!prior) {\n added.push(term)\n merged[term] = { ...translations }\n continue\n }\n updated.push(term)\n // Merge per locale: adding a Turkish translation must not drop the English.\n merged[term] = { ...prior, ...translations }\n\n const changed = Object.entries(translations).filter(([l, v]) => l in prior && prior[l] !== v)\n if (changed.length > 0) {\n const shown = changed.slice(0, MAX_REPORTED_TERMS)\n const detail = shown.map(([l, v]) => `${l}: \"${prior[l]}\" → \"${v}\"`).join(', ')\n const more = changed.length > shown.length ? `, and ${changed.length - shown.length} more` : ''\n advisories.push(`Term \"${term}\": replaced ${changed.length} translation(s) — ${detail}${more}.`)\n }\n }\n\n // A canonical term whose value duplicates another term's is the whole thing\n // this file exists to prevent, so it is worth saying out loud.\n const byValue = new Map<string, string>()\n for (const [term, translations] of Object.entries(merged)) {\n for (const value of Object.values(translations)) {\n const owner = byValue.get(value)\n if (owner && owner !== term) {\n advisories.push(`Terms \"${owner}\" and \"${term}\" share the translation \"${value}\".`)\n } else {\n byValue.set(value, term)\n }\n }\n }\n\n const next: Vocabulary = { version: existing.version, terms: merged }\n const changes: FileChange[] = [\n { path: VOCABULARY_PATH, content: canonicalStringify(next) },\n ]\n\n return {\n changes,\n result: { added, updated, total: Object.keys(merged).length },\n advisories,\n }\n}\n\n/** Build the FileChange[] to remove vocabulary terms. */\nexport async function planVocabularyDelete(\n reader: RepoReader,\n input: VocabularyDeleteInput,\n): Promise<VocabularyDeletePlan> {\n const existing = await readVocabulary(reader)\n\n const deleted: string[] = []\n const missing: string[] = []\n const remaining = { ...existing.terms }\n\n for (const term of input.terms) {\n if (term in remaining) {\n delete remaining[term]\n deleted.push(term)\n } else {\n missing.push(term)\n }\n }\n\n const advisories = missing.length > 0\n ? [`Not in the vocabulary, so nothing to delete: ${missing.join(', ')}.`]\n : []\n\n // Nothing changed — emit no FileChange, so the caller can skip the commit\n // rather than create an empty branch.\n const changes: FileChange[] = deleted.length > 0\n ? [{ path: VOCABULARY_PATH, content: canonicalStringify({ version: existing.version, terms: remaining } satisfies Vocabulary) }]\n : []\n\n return {\n changes,\n result: { deleted, missing, total: Object.keys(remaining).length },\n advisories,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAkBA,eAAsB,uBAAuB,UAAkB,SAA+C;AAC5G,MAAK,MAAM,UAAU,SAAS;EAC5B,MAAM,WAAW,KAAK,UAAU,OAAO,KAAK;AAC5C,MAAI,OAAO,YAAY,MAAM;AAC3B,SAAM,GAAG,UAAU,EAAE,OAAO,MAAM,CAAC,CAAC,YAAY,GAA2B;AAC3E;;AAEF,QAAM,MAAM,QAAQ,SAAS,EAAE,EAAE,WAAW,MAAM,CAAC;AACnD,QAAM,UAAU,UAAU,OAAO,SAAS,QAAQ;;;;;ACJtD,SAAS,WAAW,OAAwE;AAC1F,QAAO,MAAM,gBAAgB,wBAAwB,MAAM,OAAO,GAAG,MAAM;;AAG7E,eAAe,YAAe,QAAoB,MAAiC;AACjF,KAAI;AACF,SAAO,KAAK,MAAM,MAAM,OAAO,SAAS,KAAK,CAAC;SACxC;AACN,SAAO;;;AAIX,eAAe,0BACb,QACA,OACmB;CACnB,MAAM,MAAM,WAAW,MAAM;CAC7B,MAAM,QAAQ,MAAM,OAAO,cAAc,IAAI;AAE7C,MADiB,MAAM,mBAAmB,YACzB,YACf,QAAO;AAET,QAAO,MACJ,QAAO,MAAK,EAAE,SAAS,QAAQ,CAAC,CAChC,KAAI,MAAK,EAAE,QAAQ,SAAS,GAAG,CAAC,QAAQ,GAAG,MAAM,GAAG,IAAI,GAAG,CAAC;;;;;;;;;;;;;;;AAgBjE,eAAsB,kBACpB,QACA,OAC4B;CAC5B,MAAM,EAAE,UAAU;AASlB,KAAI,CAAC,MAAM,QAAQ,MAAM,OACvB,OAAM,IAAI,MACR,UAAU,MAAM,GAAG,kOAGpB;CAGH,MAAM,UAAwB,EAAE;CAChC,MAAM,UAAoB,EAAE;AAE5B,SAAQ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
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overlay-reader-
|
|
1
|
+
{"version":3,"file":"overlay-reader-CkU_pGXZ.mjs","names":[],"sources":["../src/core/overlay-reader.ts"],"sourcesContent":["import type { FileChange, RepoReader } from './contracts/index.js'\n\n/**\n * A RepoReader that overlays a set of pending FileChanges on top of an\n * underlying reader. Used in the remote-provider write path so helpers\n * like {@link import('./context.js').buildContextChange} and\n * {@link import('./validator/project.js').validateProject} see the\n * post-change state — the state the pending commit is about to produce\n * — rather than the pre-change base branch.\n *\n * Semantics:\n *\n * - `readFile(path)` — returns pending `content` when the overlay maps\n * the path; falls back to the base reader otherwise. A pending delete\n * (`content: null`) surfaces as \"missing\" (throws, matching\n * `RepoReader.readFile`'s missing-file contract).\n *\n * - `listDirectory(path)` — merges the base directory listing with\n * pending additions that live directly in the same folder, removes\n * entries whose pending change is a delete, and de-duplicates the\n * result. Pending paths in nested subdirectories surface only at\n * their own listings.\n *\n * - `fileExists(path)` — pending adds → `true`, pending deletes →\n * `false`, otherwise delegates.\n *\n * The overlay keys are canonicalised to match the FileChange contract:\n * forward slashes, no leading `/`, no `..` segments (FileChanges are\n * required to respect these invariants).\n */\nexport class OverlayReader implements RepoReader {\n private readonly overlay: Map<string, FileChange>\n\n constructor(\n private readonly base: RepoReader,\n pendingChanges: FileChange[],\n ) {\n this.overlay = new Map()\n for (const change of pendingChanges) {\n this.overlay.set(normalise(change.path), change)\n }\n }\n\n async readFile(path: string, ref?: string): Promise<string> {\n const key = normalise(path)\n const pending = this.overlay.get(key)\n if (pending) {\n if (pending.content === null) {\n throw new Error(`OverlayReader: \"${path}\" is marked for deletion`)\n }\n return pending.content\n }\n return this.base.readFile(path, ref)\n }\n\n async listDirectory(path: string, ref?: string): Promise<string[]> {\n const baseEntries = await this.base.listDirectory(path, ref)\n const dirKey = normalise(path)\n const prefix = dirKey === '' ? '' : `${dirKey}/`\n\n const direct = [...this.overlay.entries()]\n .filter(([key]) => key.startsWith(prefix))\n .map(([key, change]) => ({\n name: key.slice(prefix.length).split('/')[0] ?? '',\n isNested: key.slice(prefix.length).includes('/'),\n deleted: change.content === null,\n }))\n .filter(entry => entry.name.length > 0)\n\n // For nested pending paths (e.g. overlay at `dir/sub/a.json` when\n // listing `dir`), the immediate child directory `sub` must surface\n // even though no pending change targets it directly.\n const deleted = new Set(\n direct.filter(e => e.deleted && !e.isNested).map(e => e.name),\n )\n const added = direct\n .filter(e => !e.deleted)\n .map(e => e.name)\n\n const result = baseEntries.filter(n => !deleted.has(n))\n for (const name of added) {\n if (!result.includes(name)) result.push(name)\n }\n return result\n }\n\n async fileExists(path: string, ref?: string): Promise<boolean> {\n const key = normalise(path)\n const pending = this.overlay.get(key)\n if (pending) return pending.content !== null\n return this.base.fileExists(path, ref)\n }\n}\n\nfunction normalise(path: string): string {\n return path.replace(/^\\/+/, '')\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,IAAa,gBAAb,MAAiD;CAC/C;CAEA,YACE,MACA,gBACA;AAFiB,OAAA,OAAA;AAGjB,OAAK,0BAAU,IAAI,KAAK;AACxB,OAAK,MAAM,UAAU,eACnB,MAAK,QAAQ,IAAI,UAAU,OAAO,KAAK,EAAE,OAAO;;CAIpD,MAAM,SAAS,MAAc,KAA+B;EAC1D,MAAM,MAAM,UAAU,KAAK;EAC3B,MAAM,UAAU,KAAK,QAAQ,IAAI,IAAI;AACrC,MAAI,SAAS;AACX,OAAI,QAAQ,YAAY,KACtB,OAAM,IAAI,MAAM,mBAAmB,KAAK,0BAA0B;AAEpE,UAAO,QAAQ;;AAEjB,SAAO,KAAK,KAAK,SAAS,MAAM,IAAI;;CAGtC,MAAM,cAAc,MAAc,KAAiC;EACjE,MAAM,cAAc,MAAM,KAAK,KAAK,cAAc,MAAM,IAAI;EAC5D,MAAM,SAAS,UAAU,KAAK;EAC9B,MAAM,SAAS,WAAW,KAAK,KAAK,GAAG,OAAO;EAE9C,MAAM,SAAS,CAAC,GAAG,KAAK,QAAQ,SAAS,CAAC,CACvC,QAAQ,CAAC,SAAS,IAAI,WAAW,OAAO,CAAC,CACzC,KAAK,CAAC,KAAK,aAAa;GACvB,MAAM,IAAI,MAAM,OAAO,OAAO,CAAC,MAAM,IAAI,CAAC,MAAM;GAChD,UAAU,IAAI,MAAM,OAAO,OAAO,CAAC,SAAS,IAAI;GAChD,SAAS,OAAO,YAAY;GAC7B,EAAE,CACF,QAAO,UAAS,MAAM,KAAK,SAAS,EAAE;EAKzC,MAAM,UAAU,IAAI,IAClB,OAAO,QAAO,MAAK,EAAE,WAAW,CAAC,EAAE,SAAS,CAAC,KAAI,MAAK,EAAE,KAAK,CAC9D;EACD,MAAM,QAAQ,OACX,QAAO,MAAK,CAAC,EAAE,QAAQ,CACvB,KAAI,MAAK,EAAE,KAAK;EAEnB,MAAM,SAAS,YAAY,QAAO,MAAK,CAAC,QAAQ,IAAI,EAAE,CAAC;AACvD,OAAK,MAAM,QAAQ,MACjB,KAAI,CAAC,OAAO,SAAS,KAAK,CAAE,QAAO,KAAK,KAAK;AAE/C,SAAO;;CAGT,MAAM,WAAW,MAAc,KAAgC;EAC7D,MAAM,MAAM,UAAU,KAAK;EAC3B,MAAM,UAAU,KAAK,QAAQ,IAAI,IAAI;AACrC,MAAI,QAAS,QAAO,QAAQ,YAAY;AACxC,SAAO,KAAK,KAAK,WAAW,MAAM,IAAI;;;AAI1C,SAAS,UAAU,MAAsB;AACvC,QAAO,KAAK,QAAQ,QAAQ,GAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paths-
|
|
1
|
+
{"version":3,"file":"paths-CdPPWpbG.mjs","names":[],"sources":["../src/providers/shared/paths.ts"],"sourcesContent":["/**\n * Normalise an optional contentRoot — strip leading/trailing slashes,\n * treat `''`, `/` and `undefined` as \"no prefix\". Used by API-backed\n * providers (GitHub, GitLab, future Bitbucket) to anchor content-relative\n * paths against a repo subdirectory when Contentrain lives under a\n * monorepo path like `apps/web/.contentrain/`.\n */\nexport function normaliseContentRoot(raw?: string): string {\n if (!raw || raw === '/' || raw === '') return ''\n return raw.replace(/^\\/+|\\/+$/g, '')\n}\n\n/**\n * Resolve a content-root-relative path to a repo-relative path. The result\n * always uses forward slashes and has no leading slash — the form every\n * REST git API consumes for `file_path` / `path` query parameters and the\n * Git Data API tree entries.\n */\nexport function resolveRepoPath(contentRoot: string | undefined, relativePath: string): string {\n const prefix = normaliseContentRoot(contentRoot)\n const cleanPath = relativePath.replace(/^\\/+/, '')\n return prefix ? `${prefix}/${cleanPath}` : cleanPath\n}\n"],"mappings":";;;;;;;;AAOA,SAAgB,qBAAqB,KAAsB;AACzD,KAAI,CAAC,OAAO,QAAQ,OAAO,QAAQ,GAAI,QAAO;AAC9C,QAAO,IAAI,QAAQ,cAAc,GAAG;;;;;;;;AAStC,SAAgB,gBAAgB,aAAiC,cAA8B;CAC7F,MAAM,SAAS,qBAAqB,YAAY;CAChD,MAAM,YAAY,aAAa,QAAQ,QAAQ,GAAG;AAClD,QAAO,SAAS,GAAG,OAAO,GAAG,cAAc"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as RepoReader, g as RepoProvider, h as ProviderCapabilities, i as CommitAuthor, m as MergeResult, n as Branch, o as FileDiff, r as Commit, t as ApplyPlanInput } from "../../index-
|
|
1
|
+
import { _ as RepoReader, g as RepoProvider, h as ProviderCapabilities, i as CommitAuthor, m as MergeResult, n as Branch, o as FileDiff, r as Commit, t as ApplyPlanInput } from "../../index-BWbTJlXm.mjs";
|
|
2
2
|
import { Octokit } from "@octokit/rest";
|
|
3
3
|
|
|
4
4
|
//#region src/providers/github/app-auth.d.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as isNotFoundError } from "../../errors-
|
|
2
|
-
import { t as resolveRepoPath } from "../../paths-
|
|
1
|
+
import { t as isNotFoundError } from "../../errors-CvBS12e7.mjs";
|
|
2
|
+
import { t as resolveRepoPath } from "../../paths-CdPPWpbG.mjs";
|
|
3
3
|
import { CONTENTRAIN_BRANCH } from "@contentrain/types";
|
|
4
4
|
import { createPrivateKey, createSign } from "node:crypto";
|
|
5
5
|
//#region src/providers/github/app-auth.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as RepoReader, g as RepoProvider, h as ProviderCapabilities, i as CommitAuthor, m as MergeResult, n as Branch, o as FileDiff, r as Commit, t as ApplyPlanInput } from "../../index-
|
|
1
|
+
import { _ as RepoReader, g as RepoProvider, h as ProviderCapabilities, i as CommitAuthor, m as MergeResult, n as Branch, o as FileDiff, r as Commit, t as ApplyPlanInput } from "../../index-BWbTJlXm.mjs";
|
|
2
2
|
import { Gitlab } from "@gitbeaker/rest";
|
|
3
3
|
|
|
4
4
|
//#region src/providers/gitlab/capabilities.d.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as isNotFoundError } from "../../errors-
|
|
2
|
-
import { t as resolveRepoPath } from "../../paths-
|
|
1
|
+
import { t as isNotFoundError } from "../../errors-CvBS12e7.mjs";
|
|
2
|
+
import { t as resolveRepoPath } from "../../paths-CdPPWpbG.mjs";
|
|
3
3
|
import { CONTENTRAIN_BRANCH } from "@contentrain/types";
|
|
4
4
|
//#region src/providers/gitlab/capabilities.ts
|
|
5
5
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as RepoReader, a as FileChange, g as RepoProvider, h as ProviderCapabilities$1, i as CommitAuthor, m as MergeResult, n as Branch, o as FileDiff, r as Commit } from "../../index-
|
|
1
|
+
import { _ as RepoReader, a as FileChange, g as RepoProvider, h as ProviderCapabilities$1, i as CommitAuthor, m as MergeResult, n as Branch, o as FileDiff, r as Commit, y as WriteReadiness } from "../../index-BWbTJlXm.mjs";
|
|
2
2
|
import { SyncResult, WorkflowMode } from "@contentrain/types";
|
|
3
3
|
|
|
4
4
|
//#region src/providers/local/types.d.ts
|
|
@@ -72,6 +72,12 @@ declare class LocalProvider implements RepoProvider {
|
|
|
72
72
|
readFile(path: string, ref?: string): Promise<string>;
|
|
73
73
|
listDirectory(path: string, ref?: string): Promise<string[]>;
|
|
74
74
|
fileExists(path: string, ref?: string): Promise<boolean>;
|
|
75
|
+
/**
|
|
76
|
+
* Branch pressure gate. Unmerged `cr/*` branches accumulate in a local repo
|
|
77
|
+
* and eventually have to stop new writes; hosted providers have no such
|
|
78
|
+
* limit, so they omit this method entirely.
|
|
79
|
+
*/
|
|
80
|
+
checkWriteReadiness(): Promise<WriteReadiness>;
|
|
75
81
|
applyPlan(input: LocalApplyPlanInput): Promise<LocalApplyResult>;
|
|
76
82
|
listBranches(prefix?: string): Promise<Branch[]>;
|
|
77
83
|
createBranch(name: string, fromRef?: string): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/providers/local/types.ts","../../../src/providers/local/provider.ts","../../../src/providers/local/reader.ts"],"mappings":";;;;;UAIiB,kBAAA;EACf,IAAA;EACA,KAAA;EACA,MAAA;EACA,OAAA;AAAA;;;;;;AAYF;;;;UAAiB,mBAAA;EAYL;EAVV,MAAA;EAY+B;EAV/B,OAAA,EAAS,UAAA;EAFT;EAIA,OAAA;EAFS;EAIT,MAAA,GAAS,YAAA;EAAT;EAEA,IAAA;EAAA;EAEA,OAAA,GAAU,kBAAA;EAAA;EAEV,gBAAA,GAAmB,YAAA;AAAA;AAAA,UAGJ,gBAAA,SAAyB,MAAA;EAHT;AAGjC;;;;;EAOE,cAAA;EAEA;EAAA,IAAA,GAAO,UAAA;EAEP;EAAA,OAAA;AAAA;;;;;AA5CF;;;;;;;;;;AAgBA;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/providers/local/types.ts","../../../src/providers/local/provider.ts","../../../src/providers/local/reader.ts"],"mappings":";;;;;UAIiB,kBAAA;EACf,IAAA;EACA,KAAA;EACA,MAAA;EACA,OAAA;AAAA;;;;;;AAYF;;;;UAAiB,mBAAA;EAYL;EAVV,MAAA;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AAA;EAQ5C,UAAA,CAAW,IAAA,UAAc,IAAA,YAAgB,OAAA;AAAA"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import "../../contracts-DfL0BfrD.mjs";
|
|
2
|
-
import "../../ops-
|
|
3
|
-
import "../../serialization-
|
|
2
|
+
import "../../ops-BzbThweu.mjs";
|
|
3
|
+
import "../../serialization-tmgfFBOh.mjs";
|
|
4
4
|
import "../../fs-DLbVB-Ek.mjs";
|
|
5
|
-
import "../../meta-manager-
|
|
6
|
-
import "../../
|
|
7
|
-
import
|
|
8
|
-
import "../../
|
|
9
|
-
import "../../
|
|
10
|
-
import "../../
|
|
11
|
-
import "../../
|
|
12
|
-
import
|
|
5
|
+
import "../../meta-manager-B_Se183X.mjs";
|
|
6
|
+
import "../../identity-D8QoGxhT.mjs";
|
|
7
|
+
import "../../config-VlRKRwAS.mjs";
|
|
8
|
+
import "../../branch-lifecycle-B6PXZ2N7.mjs";
|
|
9
|
+
import { E as LocalReader } from "../../model-manager-DgyKMjLN.mjs";
|
|
10
|
+
import "../../context-C3x6I3cE.mjs";
|
|
11
|
+
import "../../id-BjhaIxTL.mjs";
|
|
12
|
+
import "../../transaction-BW9ektWu.mjs";
|
|
13
|
+
import { t as LocalProvider } from "../../local-Db5X9mjZ.mjs";
|
|
13
14
|
export { LocalProvider, LocalReader };
|
|
@@ -156,4 +156,4 @@ async function discoverFiles(projectRoot, options) {
|
|
|
156
156
|
//#endregion
|
|
157
157
|
export { classifyFile as a, autoDetectSourceDirs as i, SCAN_EXTENSIONS as n, discoverFiles as o, SCAN_IGNORE_DIRS as r, MAX_SCAN_FILES as t };
|
|
158
158
|
|
|
159
|
-
//# sourceMappingURL=scan-config-
|
|
159
|
+
//# sourceMappingURL=scan-config-Dx49nCqk.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scan-config-
|
|
1
|
+
{"version":3,"file":"scan-config-Dx49nCqk.mjs","names":[],"sources":["../src/core/scan-config.ts"],"sourcesContent":["import { readdir } from 'node:fs/promises'\nimport { join, extname, basename } from 'node:path'\nimport { pathExists } from '../util/fs.js'\n\n// ─── Shared Scan Constants ───\n\n/** File extensions to scan across all JS/TS ecosystem projects */\nexport const SCAN_EXTENSIONS = new Set([\n '.tsx', '.jsx', '.vue', '.ts', '.js', '.mjs', '.astro', '.svelte',\n])\n\n/** Directory names to always exclude from scanning */\nexport const SCAN_IGNORE_DIRS = new Set([\n // Package managers / deps\n 'node_modules', '.pnpm',\n // Build outputs\n 'dist', 'build', 'out', '.output',\n // Framework caches\n '.nuxt', '.next', '.svelte-kit', '.expo', '.turbo', '.parcel-cache', '.vercel', '.netlify',\n // Test / coverage\n 'coverage', '__tests__', '__mocks__',\n // VCS / IDE\n '.git', '.vscode', '.idea',\n // Contentrain\n '.contentrain',\n])\n\n/** Max files per scan operation */\nexport const MAX_SCAN_FILES = 500\n\n/** File patterns to skip regardless of extension */\nconst SKIP_FILE_RE = /\\.(test|spec)\\.[^.]+$|\\.d\\.ts$|\\.min\\.[^.]+$/\n\n// ─── File Classification ───\n// Covers: React, Next.js, Nuxt, Vue, Astro, SvelteKit, Remix,\n// React Native/Expo, NestJS, Express, Fastify, Koa, Hapi\n\n/** Directories that represent entry points / pages / screens */\nconst PAGE_DIR_NAMES = new Set([\n // Frontend routing\n 'pages', 'routes', 'screens', 'views',\n // Backend entry points\n 'controllers', 'handlers', 'resolvers',\n])\n\n/** Directories that represent reusable components / modules */\nconst COMPONENT_DIR_NAMES = new Set([\n // UI components\n 'components', 'ui', 'widgets', 'elements',\n // Feature modules\n 'features', 'modules',\n // Backend services\n 'services', 'providers',\n // Shared / common\n 'shared', 'common',\n])\n\n/** Directories that represent layouts / templates */\nconst LAYOUT_DIR_NAMES = new Set([\n 'layouts', 'templates',\n])\n\n/** Next.js App Router special files that are page-like */\nconst NEXTJS_PAGE_FILES = new Set([\n 'page.tsx', 'page.jsx', 'page.ts', 'page.js',\n 'layout.tsx', 'layout.jsx', 'layout.ts', 'layout.js',\n 'error.tsx', 'error.jsx',\n 'loading.tsx', 'loading.jsx',\n 'not-found.tsx', 'not-found.jsx',\n])\n\n/** Classify a file into page/component/layout/other based on path heuristics */\nexport function classifyFile(relPath: string): 'page' | 'component' | 'layout' | 'other' {\n const parts = relPath.split('/')\n const fileName = parts[parts.length - 1] ?? ''\n\n // Next.js App Router: files in app/ with special names are pages\n if (parts.includes('app') && NEXTJS_PAGE_FILES.has(fileName)) {\n return fileName.startsWith('layout') ? 'layout' : 'page'\n }\n\n // Check directory names in path (check layout first — more specific)\n for (const part of parts) {\n const lower = part.toLowerCase()\n if (LAYOUT_DIR_NAMES.has(lower)) return 'layout'\n if (PAGE_DIR_NAMES.has(lower)) return 'page'\n if (COMPONENT_DIR_NAMES.has(lower)) return 'component'\n }\n\n return 'other'\n}\n\n// ─── Source Directory Detection ───\n\n/** Common source directories across all JS/TS project types */\nconst AUTO_DETECT_DIRS = [\n // Standard source\n 'src', 'app', 'lib',\n // Frontend specific\n 'pages', 'components', 'layouts', 'views',\n // Mobile\n 'screens',\n // Backend\n 'modules', 'routes', 'controllers', 'services',\n // Shared\n 'features', 'shared', 'common',\n // Hooks / composables\n 'hooks', 'composables',\n // Stores\n 'stores',\n]\n\n/** Auto-detect which source directories exist in the project */\nexport async function autoDetectSourceDirs(projectRoot: string): Promise<string[]> {\n const found: string[] = []\n for (const dir of AUTO_DETECT_DIRS) {\n if (await pathExists(join(projectRoot, dir))) {\n found.push(dir)\n }\n }\n return found.length > 0 ? found : ['.']\n}\n\n// ─── File Discovery ───\n\nexport interface DiscoverFilesOptions {\n paths?: string[]\n include?: string[]\n exclude?: string[]\n}\n\n/**\n * Discover source files matching scan criteria.\n * Returns relative paths (relative to projectRoot).\n */\nexport async function discoverFiles(\n projectRoot: string,\n options?: DiscoverFilesOptions,\n): Promise<string[]> {\n const extensions = options?.include\n ? new Set(options.include.map(e => e.startsWith('.') ? e : `.${e}`))\n : SCAN_EXTENSIONS\n const extraExcludes = new Set(options?.exclude ?? [])\n const scanDirs = options?.paths ?? await autoDetectSourceDirs(projectRoot)\n\n const files: string[] = []\n\n for (const dir of scanDirs) {\n const absDir = join(projectRoot, dir)\n if (!(await pathExists(absDir))) continue\n\n let entries: string[]\n try {\n entries = await readdir(absDir, { recursive: true }) as unknown as string[]\n } catch {\n continue\n }\n\n for (const entry of entries) {\n if (files.length >= MAX_SCAN_FILES) break\n\n const fileName = basename(entry)\n\n // Check if any path segment is excluded\n const pathSegments = entry.split('/')\n if (pathSegments.some(seg => SCAN_IGNORE_DIRS.has(seg) || extraExcludes.has(seg))) continue\n\n // Check extension\n if (!extensions.has(extname(fileName))) continue\n\n // Skip test/spec/declaration/minified files\n if (SKIP_FILE_RE.test(fileName)) continue\n\n files.push(join(dir, entry))\n }\n\n if (files.length >= MAX_SCAN_FILES) break\n }\n\n return files.toSorted((a, b) => a.localeCompare(b)).slice(0, MAX_SCAN_FILES)\n}\n"],"mappings":";;;;;AAOA,MAAa,kBAAkB,IAAI,IAAI;CACrC;CAAQ;CAAQ;CAAQ;CAAO;CAAO;CAAQ;CAAU;CACzD,CAAC;;AAGF,MAAa,mBAAmB,IAAI,IAAI;CAEtC;CAAgB;CAEhB;CAAQ;CAAS;CAAO;CAExB;CAAS;CAAS;CAAe;CAAS;CAAU;CAAiB;CAAW;CAEhF;CAAY;CAAa;CAEzB;CAAQ;CAAW;CAEnB;CACD,CAAC;;AAGF,MAAa,iBAAiB;;AAG9B,MAAM,eAAe;;AAOrB,MAAM,iBAAiB,IAAI,IAAI;CAE7B;CAAS;CAAU;CAAW;CAE9B;CAAe;CAAY;CAC5B,CAAC;;AAGF,MAAM,sBAAsB,IAAI,IAAI;CAElC;CAAc;CAAM;CAAW;CAE/B;CAAY;CAEZ;CAAY;CAEZ;CAAU;CACX,CAAC;;AAGF,MAAM,mBAAmB,IAAI,IAAI,CAC/B,WAAW,YACZ,CAAC;;AAGF,MAAM,oBAAoB,IAAI,IAAI;CAChC;CAAY;CAAY;CAAW;CACnC;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AEjC,IAAI;AACJ,MAAI;AACF,aAAU,MAAM,QAAQ,QAAQ,EAAE,WAAW,MAAM,CAAC;UAC9C;AACN;;AAGF,OAAK,MAAM,SAAS,SAAS;AAC3B,OAAI,MAAM,UAAA,IAA0B;GAEpC,MAAM,WAAW,SAAS,MAAM;AAIhC,OADqB,MAAM,MAAM,IAAI,CACpB,MAAK,QAAO,iBAAiB,IAAI,IAAI,IAAI,cAAc,IAAI,IAAI,CAAC,CAAE;AAGnF,OAAI,CAAC,WAAW,IAAI,QAAQ,SAAS,CAAC,CAAE;AAGxC,OAAI,aAAa,KAAK,SAAS,CAAE;AAEjC,SAAM,KAAK,KAAK,KAAK,MAAM,CAAC;;AAG9B,MAAI,MAAM,UAAA,IAA0B;;AAGtC,QAAO,MAAM,UAAU,GAAG,MAAM,EAAE,cAAc,EAAE,CAAC,CAAC,MAAM,GAAA,IAAkB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { o as readText } from "./fs-DLbVB-Ek.mjs";
|
|
2
|
-
import { i as autoDetectSourceDirs, o as discoverFiles } from "./scan-config-
|
|
3
|
-
import { t as parseTsx } from "./tsx-parser-
|
|
2
|
+
import { i as autoDetectSourceDirs, o as discoverFiles } from "./scan-config-Dx49nCqk.mjs";
|
|
3
|
+
import { t as parseTsx } from "./tsx-parser-BvsK6lyG.mjs";
|
|
4
4
|
import { extname, join } from "node:path";
|
|
5
5
|
//#region src/core/ast-scanner/pre-filter.ts
|
|
6
6
|
const PURE_NUMBER_RE = /^-?\d+(\.\d+)?$/;
|
|
@@ -273,7 +273,7 @@ const ASTRO_EXTENSIONS = new Set([".astro"]);
|
|
|
273
273
|
*/
|
|
274
274
|
async function loadVueParser() {
|
|
275
275
|
try {
|
|
276
|
-
return (await import("./vue-parser-
|
|
276
|
+
return (await import("./vue-parser-auedZiJG.mjs")).parseVue;
|
|
277
277
|
} catch {
|
|
278
278
|
return;
|
|
279
279
|
}
|
|
@@ -284,7 +284,7 @@ async function loadVueParser() {
|
|
|
284
284
|
*/
|
|
285
285
|
async function loadSvelteParser() {
|
|
286
286
|
try {
|
|
287
|
-
return (await import("./svelte-parser-
|
|
287
|
+
return (await import("./svelte-parser-CwySu9yn.mjs")).parseSvelte;
|
|
288
288
|
} catch {
|
|
289
289
|
return;
|
|
290
290
|
}
|
|
@@ -295,7 +295,7 @@ async function loadSvelteParser() {
|
|
|
295
295
|
*/
|
|
296
296
|
async function loadAstroParser() {
|
|
297
297
|
try {
|
|
298
|
-
return (await import("./astro-parser-
|
|
298
|
+
return (await import("./astro-parser-Cb9uuBpW.mjs")).parseAstro;
|
|
299
299
|
} catch {
|
|
300
300
|
return;
|
|
301
301
|
}
|
|
@@ -601,4 +601,4 @@ async function scanSummary(projectRoot, options) {
|
|
|
601
601
|
//#endregion
|
|
602
602
|
export { scanSummary as n, scanCandidates as t };
|
|
603
603
|
|
|
604
|
-
//# sourceMappingURL=scanner-
|
|
604
|
+
//# sourceMappingURL=scanner-BSvXjfkp.mjs.map
|