@contentrain/mcp 1.5.0 → 1.5.2

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.
Files changed (29) hide show
  1. package/README.md +1 -1
  2. package/dist/{apply-manager-CDss8ZIr.mjs → apply-manager-BJ3nKEls.mjs} +2 -2
  3. package/dist/{apply-manager-CDss8ZIr.mjs.map → apply-manager-BJ3nKEls.mjs.map} +1 -1
  4. package/dist/core/apply-manager.mjs +2 -2
  5. package/dist/core/overlay-reader.mjs +1 -1
  6. package/dist/core/validator/index.mjs +1 -1
  7. package/dist/git/transaction.mjs +1 -1
  8. package/dist/index.mjs +5 -5
  9. package/dist/{local-BEl5L7p5.mjs → local-BJEAd4Ub.mjs} +3 -3
  10. package/dist/local-BJEAd4Ub.mjs.map +1 -0
  11. package/dist/{overlay-reader-DOdyDRIv.mjs → overlay-reader-CUs9jgqk.mjs} +1 -1
  12. package/dist/{overlay-reader-DOdyDRIv.mjs.map → overlay-reader-CUs9jgqk.mjs.map} +1 -1
  13. package/dist/providers/github/index.mjs +1 -1
  14. package/dist/providers/github/index.mjs.map +1 -1
  15. package/dist/providers/gitlab/index.mjs +1 -1
  16. package/dist/providers/gitlab/index.mjs.map +1 -1
  17. package/dist/providers/local/index.mjs +2 -2
  18. package/dist/server/http/index.mjs +5 -5
  19. package/dist/{server-BiiVUjgs.mjs → server-RwV1Ig5l.mjs} +20 -15
  20. package/dist/server-RwV1Ig5l.mjs.map +1 -0
  21. package/dist/server.mjs +5 -5
  22. package/dist/{transaction-0D_edyh0.mjs → transaction-LiTjan9Q.mjs} +3 -3
  23. package/dist/transaction-LiTjan9Q.mjs.map +1 -0
  24. package/dist/{validator-BX2ou7V-.mjs → validator-Bo06QPVB.mjs} +1 -1
  25. package/dist/{validator-BX2ou7V-.mjs.map → validator-Bo06QPVB.mjs.map} +1 -1
  26. package/package.json +1 -1
  27. package/dist/local-BEl5L7p5.mjs.map +0 -1
  28. package/dist/server-BiiVUjgs.mjs.map +0 -1
  29. package/dist/transaction-0D_edyh0.mjs.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"server-BiiVUjgs.mjs","names":["packageJson.version"],"sources":["../src/tools/context.ts","../src/git/errors.ts","../src/tools/guards.ts","../src/tools/setup.ts","../src/tools/commit-plan.ts","../src/tools/model.ts","../src/tools/content.ts","../src/tools/workflow.ts","../src/tools/normalize.ts","../src/tools/bulk.ts","../src/tools/doctor.ts","../package.json","../src/server.ts"],"sourcesContent":["import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport { z } from 'zod'\nimport type { ToolProvider } from '../server.js'\nimport { readConfig, readVocabulary } from '../core/config.js'\nimport { readContext } from '../core/context.js'\nimport { countEntries, listModels, readModel } from '../core/model-manager.js'\nimport { resolveLocaleStrategy } from '../core/content-manager.js'\nimport { contentDirPath, contentFilePath } from '../core/ops/paths.js'\nimport { detectStack } from '../util/detect.js'\nimport { join } from 'node:path'\nimport { pathExists } from '../util/fs.js'\nimport { checkBranchHealth, cleanupMergedBranches } from '../git/branch-lifecycle.js'\nimport { TOOL_ANNOTATIONS } from './annotations.js'\n\nexport function registerContextTools(\n server: McpServer,\n provider: ToolProvider,\n projectRoot: string | undefined,\n): void {\n // ─── contentrain_status ───\n server.tool(\n 'contentrain_status',\n 'Get full project status (read-only). Returns config, models, context. Do NOT manually edit .contentrain/ based on this output.',\n {},\n TOOL_ANNOTATIONS['contentrain_status']!,\n async () => {\n // Read-only status works over any provider. Stack detection and\n // branch health are projectRoot-only — they degrade gracefully\n // when the session is driven by a remote provider.\n const initialized = await provider.fileExists('.contentrain/config.json')\n\n if (!initialized) {\n const detectedStack = projectRoot ? await detectStack(projectRoot) : null\n return {\n content: [{\n type: 'text' as const,\n text: JSON.stringify({\n initialized: false,\n ...(detectedStack ? { detected_stack: detectedStack } : {}),\n suggestion: 'Run contentrain_init to set up .contentrain/ structure',\n next_steps: ['Run contentrain_init'],\n }, null, 2),\n }],\n }\n }\n\n const config = await readConfig(provider)\n const models = await listModels(provider)\n // Local flow uses the filesystem helper for byte-parity; remote\n // flows read the committed `.contentrain/context.json` through\n // the provider. Either way, the context block surfaces the last\n // operation + stats that were written alongside the last commit.\n const context = projectRoot ? await readContext(projectRoot) : await readContext(provider)\n const vocabulary = await readVocabulary(provider)\n\n // Stats source depends on the provider:\n // - Local (projectRoot): context.json's stats can lag (init writes 0/0,\n // and the working-tree copy may be unsynced after a write), which made\n // status report models:0/entries:0 alongside a non-empty models array.\n // Derive both live from the just-enumerated models. #19\n // - Remote: the committed context.json is rebuilt per-commit and is the\n // source of truth; the reader can't always walk content cheaply, so\n // trust context.stats.\n let stats: Record<string, unknown> | null = context?.stats ?? null\n if (projectRoot) {\n const fullModels = await Promise.all(models.map(m => readModel(provider, m.id)))\n const entryCounts = await Promise.all(\n fullModels.filter((m): m is NonNullable<typeof m> => m !== null).map(m => countEntries(provider, m)),\n )\n stats = {\n models: models.length,\n entries: entryCounts.reduce((acc, c) => acc + c.total, 0),\n locales: config?.locales.supported ?? context?.stats?.locales ?? ['en'],\n ...(context?.stats?.lastSync ? { lastSync: context.stats.lastSync } : {}),\n }\n }\n\n const errors: string[] = []\n if (!config) errors.push('.contentrain/config.json missing')\n\n const result: Record<string, unknown> = {\n initialized: true,\n config: config ? {\n stack: config.stack,\n workflow: config.workflow,\n locales: config.locales,\n domains: config.domains,\n repository: config.repository,\n } : null,\n models,\n context: (context || stats) ? {\n lastOperation: context?.lastOperation ?? null,\n stats,\n } : null,\n vocabulary: vocabulary && Object.keys(vocabulary.terms).length > 0\n ? { size: Object.keys(vocabulary.terms).length, terms: vocabulary.terms }\n : { size: 0 },\n }\n\n // Branch lifecycle: lazy cleanup + health check. Local-only, uses\n // simple-git against the working tree. Skipped on remote providers\n // where branch state is managed by Studio / the platform.\n if (projectRoot) {\n const hasGitRepo = await pathExists(join(projectRoot, '.git'))\n if (hasGitRepo) {\n try {\n const cleanup = await cleanupMergedBranches(projectRoot)\n const health = await checkBranchHealth(projectRoot)\n result['branches'] = {\n total: health.total,\n merged: health.merged,\n unmerged: health.unmerged,\n cleaned_up: cleanup.deleted,\n }\n if (health.message) {\n result['branch_warning'] = health.message\n }\n if (health.blocked) {\n errors.push(health.message!)\n }\n } catch {\n // Branch health check is best-effort — don't fail status\n }\n }\n }\n\n if (errors.length > 0) {\n result['validation'] = { errors: errors.length, warnings: 0, summary: errors }\n }\n\n const nextSteps: string[] = []\n if (models.length === 0) nextSteps.push('Create models with contentrain_model_save')\n if (errors.length > 0) nextSteps.push(`Fix ${errors.length} validation error(s)`)\n if (nextSteps.length === 0) nextSteps.push('Use contentrain_describe to inspect a model')\n result['next_steps'] = nextSteps\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(result, null, 2) }],\n }\n },\n )\n\n // ─── contentrain_describe ───\n server.tool(\n 'contentrain_describe',\n 'Get full schema of a single model (read-only). Do NOT manually create content files — use contentrain_content_save instead.',\n {\n model: z.string().describe('Model ID (e.g. \"blog-post\", \"hero\")'),\n include_sample: z.boolean().optional().default(false).describe('Include one sample entry'),\n locale: z.string().optional().describe('Locale for sample content (default: config default locale)'),\n },\n TOOL_ANNOTATIONS['contentrain_describe']!,\n async ({ model: modelId, include_sample, locale }) => {\n const modelDef = await readModel(provider, modelId)\n if (!modelDef) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({ error: `Model \"${modelId}\" not found` }) }],\n isError: true,\n }\n }\n\n const config = await readConfig(provider)\n const effectiveLocale = locale ?? config?.locales.default ?? 'en'\n const stats = await countEntries(provider, modelDef)\n\n const result: Record<string, unknown> = {\n id: modelDef.id,\n name: modelDef.name,\n kind: modelDef.kind,\n domain: modelDef.domain,\n i18n: modelDef.i18n,\n description: modelDef.description,\n fields: modelDef.fields,\n stats: { total_entries: stats.total, locales: stats.locales },\n }\n\n if (include_sample) {\n const sample = await getSample(provider, modelDef, effectiveLocale)\n if (sample) result['sample'] = sample\n }\n\n // Stack-aware import snippet\n const stack = config?.stack ?? 'other'\n result['import_snippet'] = generateImportSnippet(modelDef, stack, effectiveLocale)\n\n // Vocabulary hint for dictionary models\n if (modelDef.kind === 'dictionary') {\n const vocabulary = await readVocabulary(provider)\n if (vocabulary && Object.keys(vocabulary.terms).length > 0) {\n result['vocabulary_hint'] = {\n note: 'Check these approved terms before creating new dictionary keys',\n terms: vocabulary.terms,\n }\n }\n }\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(result, null, 2) }],\n }\n },\n )\n\n // ─── contentrain_describe_format ───\n server.tool(\n 'contentrain_describe_format',\n 'Describes the Contentrain content file format for any language/platform. Returns a comprehensive specification of the file structure, JSON formats, markdown conventions, meta files, and locale strategies.',\n {},\n TOOL_ANNOTATIONS['contentrain_describe_format']!,\n async () => {\n const formatSpec = {\n overview: 'Contentrain stores content as plain JSON and Markdown files in a .contentrain/ directory at the project root. All files are committed to git.',\n directory_structure: {\n description: 'Standard layout of .contentrain/ directory',\n layout: {\n '.contentrain/config.json': 'Project configuration (stack, workflow, locales, domains)',\n '.contentrain/context.json': 'Last operation metadata (written by MCP after every write)',\n '.contentrain/vocabulary.json': 'Shared vocabulary/terms (optional)',\n '.contentrain/models/{model-id}.json': 'Model schema definitions',\n '.contentrain/content/{domain}/{model-id}/': 'Content files per model',\n '.contentrain/meta/{model-id}/': 'Metadata files per model (status, source, timestamps)',\n },\n },\n model_kinds: {\n collection: {\n description: 'Multiple entries stored as an object-map keyed by entry ID',\n storage_format: 'JSON object-map: { \"entry-id-1\": { ...fields }, \"entry-id-2\": { ...fields } }',\n note: 'Keys are sorted alphabetically for canonical output. Entry IDs are alphanumeric (1-40 chars, hyphens/underscores allowed).',\n example: '{ \"abc123\": { \"title\": \"Hello\", \"slug\": \"hello\" }, \"def456\": { \"title\": \"World\", \"slug\": \"world\" } }',\n },\n singleton: {\n description: 'Single entry (e.g. site settings, hero section)',\n storage_format: 'JSON object with field key-value pairs: { \"title\": \"My Site\", \"description\": \"...\" }',\n },\n document: {\n description: 'Markdown files with YAML-like frontmatter',\n storage_format: 'Markdown file: ---\\\\nslug: my-post\\\\ntitle: My Post\\\\n---\\\\n\\\\nMarkdown body content here.',\n frontmatter_rules: [\n 'Delimited by --- on its own line',\n 'Key-value pairs: key: value',\n 'Arrays: key:\\\\n - item1\\\\n - item2',\n 'Inline arrays: key: [item1, item2]',\n 'Values auto-parsed: true/false -> boolean, integers -> number, quoted -> string',\n '\"body\" key is reserved for the markdown content below the frontmatter',\n ],\n },\n dictionary: {\n description: 'Flat key-value string map (e.g. i18n translation files)',\n storage_format: 'JSON object: { \"greeting\": \"Hello\", \"farewell\": \"Goodbye\" }',\n note: 'All values must be strings.',\n },\n },\n meta_files: {\n description: 'Metadata is stored separately from content in .contentrain/meta/{model-id}/',\n collection_meta: 'Object-map: { \"entry-id\": { \"status\": \"draft\", \"source\": \"agent\", \"updated_by\": \"contentrain-mcp\" } }',\n singleton_meta: 'Single object: { \"status\": \"published\", \"source\": \"human\", \"updated_by\": \"user@example.com\" }',\n fields: {\n status: 'Content lifecycle status: \"draft\" | \"in_review\" | \"published\" | \"rejected\" | \"archived\"',\n source: 'Who created the entry: \"agent\" | \"human\" | \"import\"',\n updated_by: 'Author identifier string',\n approved_by: 'Optional: approver identifier',\n version: 'Optional: version string',\n publish_at: 'Optional: ISO 8601 date for scheduled publishing',\n expire_at: 'Optional: ISO 8601 date for scheduled expiry (must be after publish_at)',\n },\n },\n locale_strategies: {\n description: 'How localized content files are organized. Set per-model via locale_strategy field.',\n strategies: {\n file: {\n description: 'Default. Each locale is a separate file in the model directory.',\n json_pattern: '{content-dir}/{locale}.json (e.g. en.json, tr.json)',\n md_pattern: '{content-dir}/{slug}/{locale}.md',\n },\n suffix: {\n description: 'Locale appended to filename.',\n json_pattern: '{content-dir}/{model-id}.{locale}.json',\n md_pattern: '{content-dir}/{slug}.{locale}.md',\n },\n directory: {\n description: 'Locale as subdirectory.',\n json_pattern: '{content-dir}/{locale}/{model-id}.json',\n md_pattern: '{content-dir}/{locale}/{slug}.md',\n },\n none: {\n description: 'No locale in path (single-language or externally managed).',\n json_pattern: '{content-dir}/{model-id}.json',\n md_pattern: '{content-dir}/{slug}.md',\n },\n },\n },\n i18n_disabled: {\n description: 'When a model has i18n:false, locale is ignored in file paths.',\n json_pattern: '{content-dir}/data.json (always \"data.json\", no locale suffix)',\n md_pattern: '{content-dir}/{slug}.md (no locale in path)',\n },\n canonical_serialization: {\n description: 'All JSON files use deterministic serialization for clean git diffs.',\n rules: [\n 'Object keys sorted alphabetically',\n '2-space indentation',\n 'Trailing newline at end of file',\n 'No trailing commas',\n 'UTF-8 encoding',\n ],\n },\n content_path_override: {\n description: 'Models can specify a custom content_path to store content outside .contentrain/content/.',\n example: 'A model with content_path: \"content/blog\" stores files at {project-root}/content/blog/ instead of .contentrain/content/{domain}/{model-id}/',\n note: 'This is useful for frameworks that expect content in specific directories (e.g. Nuxt Content, Astro).',\n },\n reading_content: {\n steps: [\n '1. Read .contentrain/config.json to get locales and workflow settings',\n '2. Read .contentrain/models/{model-id}.json to get the schema and model kind',\n '3. Determine content directory: model.content_path or .contentrain/content/{domain}/{model-id}/',\n '4. Determine file path using locale_strategy and i18n flag',\n '5. Parse JSON (collection/singleton/dictionary) or Markdown frontmatter (document)',\n '6. Optionally read .contentrain/meta/{model-id}/{locale}.json for status/metadata',\n ],\n },\n vocabulary: {\n description: 'Canonical terms for content consistency across models and locales.',\n file: '.contentrain/vocabulary.json',\n format: {\n version: 'number',\n terms: 'Record<category, Record<slug, translation_value>>',\n },\n usage: [\n 'Check vocabulary before creating dictionary entries — reuse canonical terms',\n 'If a new term is needed, consider adding it to vocabulary first',\n 'Vocabulary applies across ALL dictionary models and ALL locales',\n ],\n },\n }\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(formatSpec, null, 2) }],\n }\n },\n )\n}\n\nasync function getSample(\n reader: import('../core/contracts/index.js').RepoReader,\n model: import('@contentrain/types').ModelDefinition,\n locale: string,\n): Promise<unknown> {\n const cDir = contentDirPath(model)\n\n if (model.kind === 'collection') {\n const data = await tryReadJson<Record<string, Record<string, unknown>>>(\n reader,\n contentFilePath(model, locale),\n )\n if (!data) return null\n const firstKey = Object.keys(data)[0]\n return firstKey ? { id: firstKey, ...data[firstKey] } : null\n }\n\n if (model.kind === 'singleton' || model.kind === 'dictionary') {\n return tryReadJson(reader, contentFilePath(model, locale))\n }\n\n if (model.kind === 'document') {\n const strategy = resolveLocaleStrategy(model)\n\n if (!model.i18n) {\n const entry = (await reader.listDirectory(cDir)).find(item => item.endsWith('.md'))\n const slug = entry?.replace(/\\.md$/u, '')\n return slug ? { slug, locale } : null\n }\n\n if (strategy === 'file') {\n const slug = (await reader.listDirectory(cDir))[0]\n return slug ? { slug, locale } : null\n }\n\n if (strategy === 'suffix') {\n const suffix = `.${locale}.md`\n const entry = (await reader.listDirectory(cDir)).find(file => file.endsWith(suffix))\n const slug = entry?.slice(0, -suffix.length)\n return slug ? { slug, locale } : null\n }\n\n if (strategy === 'directory') {\n const entry = (await reader.listDirectory(`${cDir}/${locale}`)).find(item => item.endsWith('.md'))\n const slug = entry?.replace(/\\.md$/u, '')\n return slug ? { slug, locale } : null\n }\n\n const entry = (await reader.listDirectory(cDir)).find(item => item.endsWith('.md'))\n const slug = entry?.replace(/\\.md$/u, '')\n return slug ? { slug, locale } : null\n }\n\n return null\n}\n\nasync function tryReadJson<T>(\n reader: import('../core/contracts/index.js').RepoReader,\n path: string,\n): Promise<T | null> {\n try {\n return JSON.parse(await reader.readFile(path)) as T\n } catch {\n return null\n }\n}\n\nfunction buildContentPath(\n model: import('@contentrain/types').ModelDefinition,\n locale: string,\n): string {\n const strategy = model.locale_strategy ?? 'file'\n const baseDir = model.content_path ?? `.contentrain/content/${model.domain}/${model.id}`\n\n if (model.kind === 'document') {\n // When i18n is disabled, documents are flat {slug}.md\n if (!model.i18n) return `${baseDir}/{slug}.md`\n\n // Documents use directories — show the base path pattern\n switch (strategy) {\n case 'suffix': return `${baseDir}/{slug}.${locale}.md`\n case 'directory': return `${baseDir}/${locale}/{slug}.md`\n case 'none': return `${baseDir}/{slug}.md`\n case 'file':\n default: return `${baseDir}/{slug}/${locale}.md`\n }\n }\n\n // JSON-based models (collection, singleton, dictionary)\n // When i18n is disabled, always data.json\n if (!model.i18n) return `${baseDir}/data.json`\n\n switch (strategy) {\n case 'suffix': return `${baseDir}/${model.id}.${locale}.json`\n case 'directory': return `${baseDir}/${locale}/${model.id}.json`\n case 'none': return `${baseDir}/${model.id}.json`\n case 'file':\n default: return `${baseDir}/${locale}.json`\n }\n}\n\nfunction generateImportSnippet(\n model: import('@contentrain/types').ModelDefinition,\n stack: string,\n locale: string,\n): Record<string, string> {\n const path = buildContentPath(model, locale)\n\n const snippets: Record<string, string> = {\n generic: `import data from '${path}'`,\n }\n\n switch (stack) {\n case 'nuxt':\n snippets['nuxt'] = model.kind === 'document'\n ? `const { data } = await useAsyncData(() => queryContent('${model.domain}/${model.id}').locale('${locale}').find())`\n : `const { data } = await useFetch('/api/content/${model.id}?locale=${locale}')`\n break\n case 'next':\n snippets['next'] = `import data from '@/${path}'`\n break\n case 'astro':\n snippets['astro'] = `import data from '~/${path}'`\n break\n }\n\n return snippets\n}\n","/**\n * Error normalization for git-backed MCP operations.\n *\n * `simple-git` surfaces a failed `git commit`/`push`/`merge` as a `GitError`\n * whose `message` is the raw subprocess stderr — which, for hook tooling\n * (commitlint, husky, lefthook), is colorized multi-line text. Returning that\n * verbatim inside a JSON error produces an unreadable ANSI-escaped blob.\n *\n * This helper strips ANSI, preserves any structured fields the thrown error\n * already carries (`code`/`agent_hint`/`developer_action`), and detects git\n * hook rejections so the agent gets an actionable, structured envelope.\n */\n\n// Build the ANSI matcher without a literal control char so oxlint's\n// no-control-regex rule stays happy.\nconst ANSI_RE = new RegExp(`${String.fromCharCode(27)}\\\\[[0-9;]*m`, 'g')\n\nexport function stripAnsi(input: string): string {\n return input.replace(ANSI_RE, '')\n}\n\nexport interface NormalizedError {\n error: string\n stage?: string\n hook?: string\n code?: string\n agent_hint?: string\n developer_action?: string\n}\n\n/**\n * Normalize any thrown error into a structured, ANSI-free envelope for MCP\n * tool responses. `stage` labels where it happened (e.g. 'content_save').\n */\nexport function normalizeOperationError(err: unknown, stage?: string): NormalizedError {\n const e = err as { message?: string, code?: string, agent_hint?: string, developer_action?: string } | undefined\n const rawMessage = e?.message ?? String(err)\n const message = stripAnsi(rawMessage).trim()\n\n const out: NormalizedError = { error: message }\n if (stage) out.stage = stage\n if (e?.code) out.code = e.code\n if (e?.agent_hint) out.agent_hint = e.agent_hint\n if (e?.developer_action) out.developer_action = e.developer_action\n\n // Detect a git hook rejection (only when the error isn't already a\n // structured Contentrain error with its own code).\n if (!out.code) {\n const hookName = /\\b(commit-msg|pre-commit|prepare-commit-msg|pre-push)\\b/i.exec(message)?.[1]\n const hookTool = /\\b(commitlint|husky|lefthook)\\b/i.exec(message)?.[1]\n if (hookName || hookTool) {\n out.stage = out.stage ?? 'git-commit'\n out.hook = hookName ?? hookTool\n out.agent_hint = out.agent_hint\n ?? 'A git hook rejected the Contentrain commit. Contentrain commits with --no-verify, but a wrapping CLI or server-side hook may still run. Ask the developer to allow machine-generated \"[contentrain]\" commits or to exclude cr/* branches from the hook.'\n }\n }\n\n return out\n}\n","/**\n * Emit a uniform \"capability not available\" response for tools that\n * require local filesystem access but are being driven by a remote\n * provider (HTTP + GitHubProvider at the moment). The agent can use\n * `capability_required` to decide whether to retry against a different\n * transport or surface the limitation to the user.\n */\nexport function capabilityError(tool: string, capability: string) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n error: `${tool} requires local filesystem access.`,\n capability_required: capability,\n hint: 'This tool is unavailable when MCP is driven by a remote provider (e.g. GitHubProvider). Use a LocalProvider or the stdio transport.',\n }) }],\n isError: true as const,\n }\n}\n","import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { ContentrainConfig, Vocabulary } from '@contentrain/types'\nimport { z } from 'zod'\nimport { join } from 'node:path'\nimport { readFile, writeFile, appendFile } from 'node:fs/promises'\nimport { simpleGit } from 'simple-git'\nimport type { ToolProvider } from '../server.js'\nimport { detectStack } from '../util/detect.js'\nimport { contentrainDir, ensureDir, pathExists, writeJson } from '../util/fs.js'\nimport { readConfig, readVocabulary } from '../core/config.js'\nimport { writeModel } from '../core/model-manager.js'\nimport { writeContent, type ContentEntry } from '../core/content-manager.js'\nimport { getTemplate, listTemplates } from '../templates/index.js'\nimport { createTransaction, buildBranchName, ensureContentBranch } from '../git/transaction.js'\nimport { checkBranchHealth } from '../git/branch-lifecycle.js'\nimport { normalizeOperationError } from '../git/errors.js'\nimport { TOOL_ANNOTATIONS } from './annotations.js'\nimport { capabilityError } from './guards.js'\n\nexport function registerSetupTools(\n server: McpServer,\n _provider: ToolProvider,\n projectRoot: string | undefined,\n): void {\n // ─── contentrain_init ───\n server.tool(\n 'contentrain_init',\n 'Initialize .contentrain/ structure. Changes are auto-committed to git — do NOT manually create .contentrain/ files.',\n {\n stack: z.string().optional().describe('Framework stack (nuxt, next, astro, svelte, react-vite, other). Auto-detected if omitted.'),\n locales: z.array(z.string()).optional().describe('Supported locales. Default: [\"en\"]'),\n domains: z.array(z.string()).optional().describe('Content domains. Default: auto-suggested'),\n },\n TOOL_ANNOTATIONS['contentrain_init']!,\n async ({ stack, locales, domains }) => {\n if (!projectRoot) return capabilityError('contentrain_init', 'localWorktree')\n const crDir = contentrainDir(projectRoot)\n\n // Already initialized?\n if (await pathExists(join(crDir, 'config.json'))) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n error: 'Already initialized',\n suggestion: 'Use contentrain_status to see current state',\n }) }],\n isError: true,\n }\n }\n\n // Detect stack\n const detectedStack = stack ?? await detectStack(projectRoot)\n const supportedLocales = locales ?? ['en']\n const suggestedDomains = domains ?? suggestDomains(projectRoot)\n\n // Ensure .git exists and has at least one commit.\n //\n // `createTransaction` forks a worktree off the project's current\n // branch via `ensureContentBranch`, which calls `git branch\n // contentrain <base>`. An empty repo (zero commits) has no base\n // ref to fork from and the whole transaction fails. Parity with\n // `contentrain init` CLI command: if we just ran `git init` — or\n // the existing repo happens to be commit-free — seed an\n // `--allow-empty` initial commit so the branch operation has a\n // ref to anchor on.\n const hasGit = await pathExists(join(projectRoot, '.git'))\n const git = simpleGit(projectRoot)\n if (!hasGit) {\n await git.init()\n }\n const hasAnyCommit = await git.raw(['rev-list', '-n', '1', '--all']).then(out => out.trim().length > 0).catch(() => false)\n if (!hasAnyCommit) {\n await git.commit('initial commit', { '--allow-empty': null, '--no-verify': null })\n }\n\n // Branch health gate\n const initHealth = await checkBranchHealth(projectRoot)\n if (initHealth.blocked) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n error: initHealth.message,\n action: 'blocked',\n hint: 'Merge or delete old contentrain/* branches before creating new ones.',\n }, null, 2) }],\n isError: true,\n }\n }\n\n // Create git transaction\n const branch = buildBranchName('new', 'init')\n const tx = await createTransaction(projectRoot, branch)\n\n try {\n await tx.write(async (wt) => {\n const wtCrDir = join(wt, '.contentrain')\n\n // Create directories with .gitkeep so git tracks them\n await Promise.all(['models', 'content', 'meta'].map(async (dir) => {\n await ensureDir(join(wtCrDir, dir))\n await writeFile(join(wtCrDir, dir, '.gitkeep'), '', 'utf-8')\n }))\n\n // Write config\n const config: ContentrainConfig = {\n version: 1,\n stack: detectedStack as ContentrainConfig['stack'],\n workflow: 'auto-merge',\n locales: {\n default: supportedLocales[0] ?? 'en',\n supported: supportedLocales,\n },\n domains: suggestedDomains,\n }\n await writeJson(join(wtCrDir, 'config.json'), config)\n\n // Write empty vocabulary\n const vocabulary: Vocabulary = { version: 1, terms: {} }\n await writeJson(join(wtCrDir, 'vocabulary.json'), vocabulary)\n\n // Write initial context\n await writeJson(join(wtCrDir, 'context.json'), {\n version: '1',\n lastOperation: {\n tool: 'contentrain_init',\n model: '',\n locale: supportedLocales[0] ?? 'en',\n timestamp: new Date().toISOString(),\n source: process.env['CONTENTRAIN_SOURCE'] === 'mcp-studio' ? 'mcp-studio' : 'mcp-local',\n },\n stats: { models: 0, entries: 0, locales: supportedLocales, lastSync: new Date().toISOString() },\n })\n\n // Update .gitignore\n await updateGitignore(wt)\n })\n\n await tx.commit('[contentrain] init: project setup', {\n tool: 'contentrain_init',\n model: '',\n locale: supportedLocales[0] ?? 'en',\n })\n const gitResult = await tx.complete()\n\n // Ensure the contentrain branch exists after init\n await ensureContentBranch(projectRoot)\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n status: 'committed',\n message: 'Project initialized and committed to git. Do NOT manually edit .contentrain/ files.',\n config_created: '.contentrain/config.json',\n detected_stack: detectedStack,\n detected_locales: supportedLocales,\n suggested_domains: suggestedDomains,\n files_created: [\n '.contentrain/config.json',\n '.contentrain/vocabulary.json',\n '.contentrain/context.json',\n ],\n directories_created: [\n '.contentrain/models/',\n '.contentrain/content/',\n '.contentrain/meta/',\n ],\n gitignore_updated: true,\n git: { branch, action: gitResult.action, commit: gitResult.commit, ...(gitResult.sync ? { sync: gitResult.sync } : {}) },\n next_steps: [\n 'Create models with contentrain_model_save or contentrain_scaffold',\n 'Use contentrain_scan to find hardcoded strings',\n ],\n }, null, 2) }],\n }\n } catch (error) {\n await tx.cleanup()\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n ...normalizeOperationError(error, 'init'),\n }) }],\n isError: true,\n }\n } finally {\n await tx.cleanup()\n }\n },\n )\n\n // ─── contentrain_scaffold ───\n server.tool(\n 'contentrain_scaffold',\n `Template-based project setup. Available templates: ${listTemplates().join(', ')}. Changes are auto-committed to git.`,\n {\n template: z.string().describe('Template ID: blog, landing, docs, ecommerce, saas, i18n, mobile'),\n locales: z.array(z.string()).optional().describe('Override locales'),\n with_sample_content: z.boolean().optional().default(true).describe('Include sample content (default: true)'),\n },\n TOOL_ANNOTATIONS['contentrain_scaffold']!,\n async ({ template: templateId, locales, with_sample_content }) => {\n if (!projectRoot) return capabilityError('contentrain_scaffold', 'localWorktree')\n const config = await readConfig(projectRoot)\n if (!config) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n error: 'Project not initialized. Run contentrain_init first.',\n }) }],\n isError: true,\n }\n }\n\n const tmpl = getTemplate(templateId)\n if (!tmpl) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n error: `Unknown template: \"${templateId}\". Available: ${listTemplates().join(', ')}`,\n }) }],\n isError: true,\n }\n }\n\n // Branch health gate\n const scaffoldHealth = await checkBranchHealth(projectRoot)\n if (scaffoldHealth.blocked) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n error: scaffoldHealth.message,\n action: 'blocked',\n hint: 'Merge or delete old contentrain/* branches before creating new ones.',\n }, null, 2) }],\n isError: true,\n }\n }\n\n const effectiveLocales = locales ?? config.locales.supported\n const defaultLocale = effectiveLocales[0] ?? 'en'\n\n const branch = buildBranchName('new', `scaffold-${templateId}`, defaultLocale)\n const tx = await createTransaction(projectRoot, branch)\n\n try {\n const modelsCreated: Array<{ id: string; kind: string; fields: number }> = []\n let contentCreated = 0\n let vocabAdded = 0\n\n await tx.write(async (wt) => {\n // Write models\n await Promise.all(tmpl.models.map(async (model) => {\n await writeModel(wt, model)\n modelsCreated.push({\n id: model.id,\n kind: model.kind,\n fields: model.fields ? Object.keys(model.fields).length : 0,\n })\n }))\n\n // Write sample content via content pipeline (handles content_path, locale_strategy, meta)\n if (with_sample_content && tmpl.sample_content) {\n contentCreated = await writeSampleContent(wt, tmpl, effectiveLocales, config)\n }\n\n // Merge vocabulary\n if (tmpl.vocabulary) {\n vocabAdded = await mergeVocabulary(wt, tmpl.vocabulary, effectiveLocales)\n }\n\n })\n\n await tx.commit(`[contentrain] scaffold: ${templateId} (${defaultLocale})`, {\n tool: 'contentrain_scaffold',\n model: tmpl.models.map(m => m.id).join(', '),\n locale: defaultLocale,\n })\n const gitResult = await tx.complete()\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n status: 'committed',\n message: 'Scaffold applied and committed to git. Do NOT manually edit .contentrain/ files.',\n models_created: modelsCreated,\n content_created: contentCreated,\n vocabulary_terms_added: vocabAdded,\n git: { branch, action: gitResult.action, commit: gitResult.commit, ...(gitResult.sync ? { sync: gitResult.sync } : {}) },\n context_updated: true,\n next_steps: [\n 'Customize models with contentrain_model_save',\n 'Add content with contentrain_content_save',\n 'Run contentrain_submit when ready',\n ],\n }, null, 2) }],\n }\n } catch (error) {\n await tx.cleanup()\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n ...normalizeOperationError(error, 'scaffold'),\n }) }],\n isError: true,\n }\n } finally {\n await tx.cleanup()\n }\n },\n )\n}\n\nfunction suggestDomains(_projectRoot: string): string[] {\n return ['marketing', 'blog', 'system']\n}\n\nasync function updateGitignore(projectRoot: string): Promise<void> {\n const gitignorePath = join(projectRoot, '.gitignore')\n const cacheEntry = '.contentrain/.cache/'\n\n if (await pathExists(gitignorePath)) {\n const content = await readFile(gitignorePath, 'utf-8')\n if (!content.includes(cacheEntry)) {\n await appendFile(gitignorePath, `\\n# Contentrain cache\\n${cacheEntry}\\n`)\n }\n } else {\n await writeFile(gitignorePath, `# Contentrain cache\\n${cacheEntry}\\n`, 'utf-8')\n }\n}\n\nasync function writeSampleContent(\n worktreePath: string,\n tmpl: import('@contentrain/types').ScaffoldTemplate,\n locales: string[],\n config: import('@contentrain/types').ContentrainConfig,\n): Promise<number> {\n if (!tmpl.sample_content) return 0\n\n let count = 0\n\n for (const model of tmpl.models) {\n const sampleData = tmpl.sample_content[model.id]\n if (!sampleData) continue\n\n for (const [localeOrKey, data] of Object.entries(sampleData)) {\n const entryMap = data as Record<string, Record<string, unknown>>\n let targetLocale: string\n if (localeOrKey === 'data') {\n targetLocale = locales[0] ?? 'en'\n } else if (locales.includes(localeOrKey)) {\n targetLocale = localeOrKey\n } else {\n continue\n }\n\n // Convert template payload to ContentEntry[] based on model kind\n let entries: ContentEntry[]\n\n if (model.kind === 'singleton' || model.kind === 'dictionary') {\n // Singleton/dictionary: the entire locale object IS the data for one entry\n entries = [{ locale: targetLocale, data: entryMap as Record<string, unknown> }]\n } else if (model.kind === 'document') {\n // Document: keys are slugs, values are frontmatter objects\n entries = Object.entries(entryMap).map(([slug, fields]) => ({\n slug,\n locale: targetLocale,\n data: fields,\n }))\n } else {\n // Collection: keys are entry IDs, values are field objects\n entries = Object.entries(entryMap).map(([id, fields]) => ({\n id,\n locale: targetLocale,\n data: fields,\n }))\n }\n\n await writeContent(worktreePath, model, entries, config)\n count += entries.length\n }\n }\n\n return count\n}\n\nasync function mergeVocabulary(\n projectRoot: string,\n newTerms: Record<string, Record<string, string>>,\n _locales: string[],\n): Promise<number> {\n const vocabPath = join(contentrainDir(projectRoot), 'vocabulary.json')\n const existing = await readVocabulary(projectRoot)\n const vocab: Vocabulary = existing ?? { version: 1, terms: {} }\n\n let added = 0\n for (const [key, translations] of Object.entries(newTerms)) {\n if (!(key in vocab.terms)) {\n added++\n }\n vocab.terms[key] = { ...vocab.terms[key], ...translations }\n }\n\n await writeJson(vocabPath, vocab)\n return added\n}\n","import { CONTENTRAIN_BRANCH } from '@contentrain/types'\nimport type { FileChange } from '../core/contracts/index.js'\nimport { buildContextChange } from '../core/context.js'\nimport { OverlayReader } from '../core/overlay-reader.js'\nimport { LocalProvider } from '../providers/local/index.js'\nimport type { ToolProvider } from '../server.js'\n\n/**\n * Context payload written into `.contentrain/context.json` as part of the\n * same commit. Kept as a loose object so tool-specific payloads can add\n * optional fields (`locale`, `entries`) without churning the helper's\n * signature.\n */\nexport interface CommitContextPayload {\n tool: string\n model: string\n locale?: string\n entries?: string[]\n}\n\nexport interface CommitThroughProviderInput {\n branch: string\n changes: FileChange[]\n message: string\n contextPayload: CommitContextPayload\n}\n\nexport interface CommitThroughProviderResult {\n commitSha: string\n workflowAction: 'auto-merged' | 'pending-review'\n sync?: unknown\n}\n\n/**\n * Commit a plan's changes through whichever provider is wired into the\n * tool handler. Encapsulates the LocalProvider vs remote RepoProvider\n * dispatch that every write-side tool (content_save, content_delete,\n * model_save, model_delete) used to inline:\n *\n * - **LocalProvider** — goes through the worktree-backed transaction.\n * `context` payload is threaded as an extra write-through and the\n * transaction layer decides `auto-merged` vs `pending-review` based on\n * the project's configured workflow. Selective-sync result is surfaced\n * to the caller via `sync`.\n *\n * - **Any other RepoProvider** — the context.json write becomes an extra\n * `FileChange` bundled into the plan so the whole commit lands\n * atomically through the generic `RepoWriter.applyPlan`. Remote flows\n * always report `pending-review`; Studio (or whatever orchestrator is\n * driving the server) owns the merge.\n *\n * The return shape is deliberately uniform so callers don't have to\n * branch on provider type again.\n */\nexport async function commitThroughProvider(\n provider: ToolProvider,\n input: CommitThroughProviderInput,\n): Promise<CommitThroughProviderResult> {\n const { branch, changes, message, contextPayload } = input\n\n if (provider instanceof LocalProvider) {\n const result = await provider.applyPlan({\n branch,\n changes,\n message,\n context: contextPayload,\n })\n return {\n commitSha: result.sha,\n workflowAction: result.workflowAction,\n sync: result.sync,\n }\n }\n\n // Build context.json against an overlay of the pending FileChanges so\n // `stats.entries` / `stats.models` reflect the state *after* this\n // commit lands, not the pre-change base branch. Without the overlay\n // the committed context.json would be stale — a new entry added in\n // this commit would not appear in the entry count until the next\n // write.\n const overlay = new OverlayReader(provider, changes)\n const contextChange = await buildContextChange(overlay, contextPayload)\n const allChanges = [...changes, contextChange]\n .toSorted((a, b) => a.path.localeCompare(b.path))\n // Feature branches ALWAYS fork from the `contentrain` branch — that's\n // the single source of truth the local transaction flow enforces, and\n // the remote flow must match it so Studio's cr/* → contentrain →\n // defaultBranch model stays consistent. `config.repository.default_branch`\n // names the repo's primary branch (main / master / trunk) — that is\n // NOT the content tracking branch, only the downstream target.\n const commit = await provider.applyPlan({\n branch,\n changes: allChanges,\n message,\n author: { name: 'Contentrain', email: 'mcp@contentrain.io' },\n base: CONTENTRAIN_BRANCH,\n })\n return {\n commitSha: commit.sha,\n workflowAction: 'pending-review',\n }\n}\n","import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { ModelDefinition } from '@contentrain/types'\nimport { z } from 'zod'\nimport type { ToolProvider } from '../server.js'\nimport { readConfig } from '../core/config.js'\n\nimport { resolveContentDir, resolveJsonFilePath, resolveMdFilePath } from '../core/content-manager.js'\nimport { checkReferences, readModel, validateModelDefinition, fieldDefZodSchema } from '../core/model-manager.js'\nimport { planModelDelete, planModelSave } from '../core/ops/index.js'\nimport { LocalProvider } from '../providers/local/index.js'\nimport { buildBranchName } from '../git/transaction.js'\nimport { checkBranchHealth } from '../git/branch-lifecycle.js'\nimport { normalizeOperationError } from '../git/errors.js'\nimport { TOOL_ANNOTATIONS } from './annotations.js'\nimport { commitThroughProvider } from './commit-plan.js'\n\n// Shared field definition schema — single source of truth with normalize extract\nconst fieldDefSchema = fieldDefZodSchema\n\nexport function registerModelTools(\n server: McpServer,\n provider: ToolProvider,\n projectRoot: string | undefined,\n): void {\n // ─── contentrain_model_save ───\n server.tool(\n 'contentrain_model_save',\n 'Create or update a model definition. Changes are auto-committed to git — do NOT manually edit .contentrain/ files after calling this tool.',\n {\n id: z.string().describe('Model ID (kebab-case, e.g. \"blog-post\")'),\n name: z.string().describe('Human-readable name'),\n kind: z.enum(['singleton', 'collection', 'document', 'dictionary']).describe('Model kind'),\n domain: z.string().describe('Content domain (e.g. \"blog\", \"marketing\", \"system\")'),\n i18n: z.boolean().describe('Whether this model supports localization'),\n description: z.string().optional().describe('Model description'),\n fields: fieldDefSchema.optional().describe('Field definitions (not needed for dictionary)'),\n content_path: z.string().optional().describe('Framework-relative path for content files (e.g. \"content/blog\", \"locales\"). When set, content is written here instead of .contentrain/content/'),\n locale_strategy: z.enum(['file', 'suffix', 'directory', 'none']).optional().describe('How locale is encoded in file names. Default: \"file\"'),\n },\n TOOL_ANNOTATIONS['contentrain_model_save']!,\n async (input) => {\n const config = await readConfig(provider)\n if (!config) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({ error: 'Project not initialized. Run contentrain_init first.' }) }],\n isError: true,\n }\n }\n\n const errors = validateModel(input)\n if (errors.length > 0) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({ error: 'Validation failed', details: errors }) }],\n isError: true,\n }\n }\n\n if (input.locale_strategy === 'none' && input.i18n !== false) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n error: 'locale_strategy \"none\" requires i18n:false. The \"none\" strategy stores a single file without locale encoding, which is incompatible with multi-locale content. Use \"file\", \"suffix\", or \"directory\" for i18n models.',\n }) }],\n isError: true,\n }\n }\n\n if (provider instanceof LocalProvider) {\n const health = await checkBranchHealth(provider.projectRoot)\n if (health.blocked) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n error: health.message,\n action: 'blocked',\n hint: 'Merge or delete old contentrain/* branches before creating new ones.',\n }, null, 2) }],\n isError: true,\n }\n }\n }\n\n const model: ModelDefinition = {\n id: input.id,\n name: input.name,\n kind: input.kind,\n domain: input.domain,\n i18n: input.i18n,\n description: input.description,\n fields: input.fields as ModelDefinition['fields'],\n content_path: input.content_path,\n locale_strategy: input.locale_strategy,\n }\n\n const savePlan = await planModelSave(provider, { model })\n const action = savePlan.result.action\n const branch = buildBranchName('model', input.id)\n const message = `[contentrain] ${action}: ${input.id}`\n const contextPayload = { tool: 'contentrain_model_save', model: input.id }\n\n let commitSha: string\n let workflowAction: 'auto-merged' | 'pending-review'\n let sync: unknown\n\n try {\n const result = await commitThroughProvider(provider, {\n branch,\n changes: savePlan.changes,\n message,\n contextPayload,\n })\n commitSha = result.commitSha\n workflowAction = result.workflowAction\n sync = result.sync\n } catch (error) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n ...normalizeOperationError(error, 'model_save'),\n }) }],\n isError: true,\n }\n }\n\n // DX helpers (import snippet, example path) are only computed when we\n // can resolve local paths — they do not apply to remote-only flows.\n const defaultLocale = config.locales.default\n const contentPath = model.content_path ?? `.contentrain/content/${input.domain}/${input.id}`\n let displayPath: string | undefined\n let importSnippet: Record<string, string> | undefined\n if (projectRoot) {\n const contentDir = resolveContentDir(projectRoot, model)\n const exampleFilePath = model.kind === 'document'\n ? resolveMdFilePath(contentDir, model, defaultLocale, '{slug}')\n : resolveJsonFilePath(contentDir, model, defaultLocale)\n displayPath = exampleFilePath.replace(projectRoot + '/', '').replace(projectRoot, '')\n importSnippet = {\n generic: `import data from '${displayPath}'`,\n }\n if (config.stack === 'nuxt') {\n importSnippet['nuxt'] = model.kind === 'document'\n ? `const { data } = await useAsyncData(() => queryContent('${model.domain}/${model.id}').locale('${defaultLocale}').find())`\n : `const { data } = await useFetch('/api/content/${model.id}?locale=${defaultLocale}')`\n }\n }\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n status: 'committed',\n message: 'Model saved and committed to git. Do NOT manually edit .contentrain/ files.',\n action,\n model: input.id,\n validation: { valid: true, errors: [] },\n git: { branch, action: workflowAction, commit: commitSha, ...(sync ? { sync } : {}) },\n context_updated: true,\n content_path: contentPath + '/',\n ...(displayPath ? { example_file: displayPath } : {}),\n ...(importSnippet ? { import_snippet: importSnippet } : {}),\n next_steps: ['Add content with contentrain_content_save'],\n }, null, 2) }],\n }\n },\n )\n\n // ─── contentrain_model_delete ───\n server.tool(\n 'contentrain_model_delete',\n 'Delete a model and its content/meta. Changes are auto-committed to git — do NOT manually edit .contentrain/ files.',\n {\n model: z.string().describe('Model ID to delete'),\n confirm: z.literal(true).describe('Must be true to confirm deletion'),\n },\n TOOL_ANNOTATIONS['contentrain_model_delete']!,\n async ({ model: modelId }) => {\n const config = await readConfig(provider)\n if (!config) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({ error: 'Project not initialized.' }) }],\n isError: true,\n }\n }\n\n const existing = await readModel(provider, modelId)\n if (!existing) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({ error: `Model \"${modelId}\" not found` }) }],\n isError: true,\n }\n }\n\n if (provider instanceof LocalProvider) {\n const deleteHealth = await checkBranchHealth(provider.projectRoot)\n if (deleteHealth.blocked) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n error: deleteHealth.message,\n action: 'blocked',\n hint: 'Merge or delete old contentrain/* branches before creating new ones.',\n }, null, 2) }],\n isError: true,\n }\n }\n }\n\n // Reference integrity — both local and remote now go through the\n // reader-based checkReferences so deletes on GitHubProvider get the\n // same REFERENCED_MODEL guard as local flows.\n const refs = await checkReferences(provider, modelId)\n if (refs.length > 0) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n deleted: false,\n error: 'REFERENCED_MODEL',\n referenced_by: refs,\n next_steps: ['Remove relation fields from referencing models first'],\n }, null, 2) }],\n }\n }\n\n const deletePlan = await planModelDelete(provider, { model: existing })\n const branch = buildBranchName('model', modelId)\n const message = `[contentrain] delete: ${modelId}`\n const contextPayload = { tool: 'contentrain_model_delete', model: modelId }\n\n let commitSha: string\n let workflowAction: 'auto-merged' | 'pending-review'\n let sync: unknown\n\n try {\n const result = await commitThroughProvider(provider, {\n branch,\n changes: deletePlan.changes,\n message,\n contextPayload,\n })\n commitSha = result.commitSha\n workflowAction = result.workflowAction\n sync = result.sync\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n status: 'committed',\n message: 'Model deleted and committed to git. Do NOT manually edit .contentrain/ files.',\n deleted: true,\n git: { branch, action: workflowAction, commit: commitSha, ...(sync ? { sync } : {}) },\n files_removed: deletePlan.result,\n context_updated: true,\n }, null, 2) }],\n }\n } catch (error) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n ...normalizeOperationError(error, 'model_delete'),\n }) }],\n isError: true,\n }\n }\n },\n )\n}\n\n// validateModel is now validateModelDefinition from model-manager.ts (shared)\nconst validateModel = validateModelDefinition\n","import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport { z } from 'zod'\nimport type { ToolProvider } from '../server.js'\nimport { readConfig, readVocabulary } from '../core/config.js'\nimport { readModel } from '../core/model-manager.js'\nimport { listContent } from '../core/content-manager.js'\nimport { planContentDelete, planContentSave } from '../core/ops/index.js'\nimport { LocalProvider } from '../providers/local/index.js'\nimport { buildBranchName } from '../git/transaction.js'\nimport { checkBranchHealth } from '../git/branch-lifecycle.js'\nimport { normalizeOperationError } from '../git/errors.js'\nimport { validateProject } from '../core/validator/index.js'\nimport { OverlayReader } from '../core/overlay-reader.js'\nimport { TOOL_ANNOTATIONS } from './annotations.js'\nimport { commitThroughProvider } from './commit-plan.js'\n\nexport function registerContentTools(\n server: McpServer,\n provider: ToolProvider,\n projectRoot: string | undefined,\n): void {\n // ─── contentrain_content_save ───\n server.tool(\n 'contentrain_content_save',\n 'Save content entries. Entry format varies by model kind: DICTIONARY — provide \"locale\" and \"data\" (flat key-value, all string values); \"id\" and \"slug\" are ignored; data keys are the identities. COLLECTION — provide \"locale\" and \"data\"; \"id\" is optional (auto-generated if omitted); \"slug\" is ignored. DOCUMENT — provide \"slug\" (required), \"locale\", and \"data\"; use the \"body\" key inside data for markdown content. SINGLETON — provide only \"locale\" and \"data\". Changes are auto-committed to git — do NOT manually edit .contentrain/ files after calling this tool.',\n {\n model: z.string().describe('Model ID'),\n entries: z.array(z.object({\n id: z.string().optional().describe('Entry ID (collection only, auto-generated if omitted)'),\n slug: z.string().optional().describe('Slug (document only)'),\n locale: z.string().optional().describe('Locale code (defaults to config default)'),\n data: z.record(z.string(), z.unknown()).describe('Content data. For documents, include \"body\" key for markdown content.'),\n publish_at: z.string().optional().describe('ISO 8601 date for scheduled publishing (stored in meta)'),\n expire_at: z.string().optional().describe('ISO 8601 date for scheduled expiry (stored in meta, must be after publish_at)'),\n })).describe('Content entries to save'),\n },\n TOOL_ANNOTATIONS['contentrain_content_save']!,\n async (input) => {\n const config = await readConfig(provider)\n if (!config) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({ error: 'Project not initialized. Run contentrain_init first.' }) }],\n isError: true,\n }\n }\n\n const model = await readModel(provider, input.model)\n if (!model) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({ error: `Model \"${input.model}\" not found` }) }],\n isError: true,\n }\n }\n\n // Validate locales and scheduling fields before starting transaction\n for (const entry of input.entries) {\n if (entry.locale && !config.locales.supported.includes(entry.locale)) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n error: `Locale \"${entry.locale}\" is not supported. Supported: [${config.locales.supported.join(', ')}]`,\n }) }],\n isError: true,\n }\n }\n\n // Validate publish_at / expire_at\n if (entry.publish_at !== undefined) {\n const d = new Date(entry.publish_at)\n if (Number.isNaN(d.getTime())) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n error: `Invalid publish_at date: \"${entry.publish_at}\". Must be a valid ISO 8601 date string.`,\n }) }],\n isError: true,\n }\n }\n }\n if (entry.expire_at !== undefined) {\n const d = new Date(entry.expire_at)\n if (Number.isNaN(d.getTime())) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n error: `Invalid expire_at date: \"${entry.expire_at}\". Must be a valid ISO 8601 date string.`,\n }) }],\n isError: true,\n }\n }\n }\n if (entry.publish_at !== undefined && entry.expire_at !== undefined) {\n if (new Date(entry.expire_at) <= new Date(entry.publish_at)) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n error: `expire_at (\"${entry.expire_at}\") must be after publish_at (\"${entry.publish_at}\").`,\n }) }],\n isError: true,\n }\n }\n }\n\n // Merge scheduling fields into data so meta-manager picks them up\n if (entry.publish_at !== undefined) entry.data['publish_at'] = entry.publish_at\n if (entry.expire_at !== undefined) entry.data['expire_at'] = entry.expire_at\n }\n\n // Branch health gate — LocalProvider only (git branch count check).\n if (provider instanceof LocalProvider) {\n const health = await checkBranchHealth(provider.projectRoot)\n if (health.blocked) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n error: health.message,\n action: 'blocked',\n hint: 'Merge or delete old contentrain/* branches before creating new ones.',\n }, null, 2) }],\n isError: true,\n }\n }\n }\n\n const vocabulary = await readVocabulary(provider)\n\n let plan: Awaited<ReturnType<typeof planContentSave>>\n try {\n plan = await planContentSave(provider, {\n model,\n entries: input.entries,\n config,\n vocabulary,\n })\n } catch (error) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n ...normalizeOperationError(error, 'content_save'),\n }) }],\n isError: true,\n }\n }\n\n const entryIds = plan.result\n .map(r => r.id ?? r.slug ?? r.locale)\n .filter((v): v is string => Boolean(v))\n\n const branch = buildBranchName('content', input.model)\n const message = `[contentrain] content: ${input.model}`\n const contextPayload = {\n tool: 'contentrain_content_save',\n model: input.model,\n locale: input.entries[0]?.locale,\n entries: entryIds,\n }\n\n let commitSha: string\n let workflowAction: 'auto-merged' | 'pending-review'\n let sync: unknown\n\n try {\n const result = await commitThroughProvider(provider, {\n branch,\n changes: plan.changes,\n message,\n contextPayload,\n })\n commitSha = result.commitSha\n workflowAction = result.workflowAction\n sync = result.sync\n } catch (error) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n ...normalizeOperationError(error, 'content_save'),\n }) }],\n isError: true,\n }\n }\n\n // Post-save validation — runs against an OverlayReader that layers the\n // just-saved changes on top of the provider's base view. This validates\n // the committed state for BOTH providers and BOTH workflow modes. The\n // old local path validated `projectRoot` (the developer working tree),\n // which in review mode (or before selectiveSync) had not yet received the\n // feature-branch files — producing false \"locale file missing\" errors for\n // content that was just created. #7\n const validationResult = await validateProject(\n new OverlayReader(provider, plan.changes),\n { model: input.model },\n )\n\n const allAdvisories = plan.result.flatMap(r => r.advisories ?? [])\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n status: 'committed',\n message: 'Content saved and committed to git. Do NOT manually edit .contentrain/ files.',\n results: plan.result,\n git: { branch, action: workflowAction, commit: commitSha, ...(sync ? { sync } : {}) },\n ...(allAdvisories.length > 0 ? {\n advisories: allAdvisories,\n advisory_note: 'Save succeeded. Review these warnings and consider consolidating duplicate values.',\n } : {}),\n validation: {\n valid: validationResult.valid,\n errors: validationResult.issues.filter(i => i.severity === 'error').map(i => i.message),\n },\n context_updated: true,\n next_steps: [\n ...(allAdvisories.length > 0 ? ['ADVISORY: Duplicate values detected — review advisories above'] : []),\n ...(!validationResult.valid ? ['WARNING: Content has validation errors — run contentrain_validate for details'] : []),\n ...(model.kind === 'collection'\n ? ['Use contentrain_content_list to verify', 'Add more entries or publish']\n : ['Use contentrain_content_list to verify']),\n ],\n }, null, 2) }],\n }\n },\n )\n\n // ─── contentrain_content_delete ───\n server.tool(\n 'contentrain_content_delete',\n 'Delete content entries. For dictionaries, use \"keys\" to remove specific keys (omit to delete entire locale file). Changes are auto-committed to git — do NOT manually edit .contentrain/ files after calling this tool.',\n {\n model: z.string().describe('Model ID'),\n id: z.string().optional().describe('Entry ID (collection)'),\n slug: z.string().optional().describe('Slug (document)'),\n locale: z.string().optional().describe('Locale code'),\n keys: z.array(z.string()).optional().describe('Dictionary only: specific keys to remove. Omit to delete entire locale file.'),\n confirm: z.literal(true).describe('Must be true to confirm deletion'),\n },\n TOOL_ANNOTATIONS['contentrain_content_delete']!,\n async (input) => {\n const config = await readConfig(provider)\n if (!config) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({ error: 'Project not initialized.' }) }],\n isError: true,\n }\n }\n\n const model = await readModel(provider, input.model)\n if (!model) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({ error: `Model \"${input.model}\" not found` }) }],\n isError: true,\n }\n }\n\n if (provider instanceof LocalProvider) {\n const deleteHealth = await checkBranchHealth(provider.projectRoot)\n if (deleteHealth.blocked) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n error: deleteHealth.message,\n action: 'blocked',\n hint: 'Merge or delete old contentrain/* branches before creating new ones.',\n }, null, 2) }],\n isError: true,\n }\n }\n }\n\n let deletePlan: Awaited<ReturnType<typeof planContentDelete>>\n try {\n deletePlan = await planContentDelete(provider, {\n model,\n id: input.id,\n slug: input.slug,\n locale: input.locale,\n keys: input.keys,\n })\n } catch (error) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n ...normalizeOperationError(error, 'content_delete'),\n }) }],\n isError: true,\n }\n }\n\n const branch = buildBranchName('content', input.model)\n const message = `[contentrain] delete content: ${input.model}`\n const contextPayload = {\n tool: 'contentrain_content_delete',\n model: input.model,\n locale: input.locale,\n }\n\n let commitSha: string\n let workflowAction: 'auto-merged' | 'pending-review'\n let sync: unknown\n\n try {\n const result = await commitThroughProvider(provider, {\n branch,\n changes: deletePlan.changes,\n message,\n contextPayload,\n })\n commitSha = result.commitSha\n workflowAction = result.workflowAction\n sync = result.sync\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n status: 'committed',\n message: 'Content deleted and committed to git. Do NOT manually edit .contentrain/ files.',\n deleted: true,\n files_removed: deletePlan.result,\n git: { branch, action: workflowAction, commit: commitSha, ...(sync ? { sync } : {}) },\n context_updated: true,\n }, null, 2) }],\n }\n } catch (error) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n ...normalizeOperationError(error, 'content_delete'),\n }) }],\n isError: true,\n }\n }\n },\n )\n\n // ─── contentrain_content_list ───\n server.tool(\n 'contentrain_content_list',\n 'List content entries (read-only). Returns data from .contentrain/ — do NOT manually create or modify content files.',\n {\n model: z.string().describe('Model ID'),\n locale: z.string().optional().describe('Locale code (defaults to config default)'),\n filter: z.record(z.string(), z.unknown()).optional().describe('Filter criteria (collection only)'),\n resolve: z.boolean().optional().describe('Resolve relation fields to actual data'),\n limit: z.number().optional().describe('Max entries to return'),\n offset: z.number().optional().describe('Skip N entries'),\n },\n TOOL_ANNOTATIONS['contentrain_content_list']!,\n async (input) => {\n const config = await readConfig(provider)\n if (!config) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({ error: 'Project not initialized.' }) }],\n isError: true,\n }\n }\n\n const model = await readModel(provider, input.model)\n if (!model) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({ error: `Model \"${input.model}\" not found` }) }],\n isError: true,\n }\n }\n\n try {\n // LocalProvider path keeps the legacy filesystem implementation\n // (with full `resolve:true` relation hydration). Remote providers\n // get the reader-based path — `resolve:true` is rejected there\n // because cross-model relation walks need local disk today.\n const listOpts = {\n locale: input.locale,\n filter: input.filter as Record<string, unknown>,\n resolve: input.resolve,\n limit: input.limit,\n offset: input.offset,\n }\n const result = projectRoot\n ? await listContent(projectRoot, model, listOpts, config)\n : await listContent(provider, model, listOpts, config)\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(result, null, 2) }],\n }\n } catch (error) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n ...normalizeOperationError(error, 'content_list'),\n }) }],\n isError: true,\n }\n }\n },\n )\n}\n","import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport { CONTENTRAIN_BRANCH } from '@contentrain/types'\nimport { z } from 'zod'\nimport { simpleGit, type SimpleGit } from 'simple-git'\nimport type { ToolProvider } from '../server.js'\nimport { validateProject } from '../core/validator/index.js'\nimport { readConfig } from '../core/config.js'\nimport { createTransaction, buildBranchName, mergeBranch } from '../git/transaction.js'\nimport { checkBranchHealth, cleanupMergedBranches } from '../git/branch-lifecycle.js'\nimport { isMerged } from '../providers/local/branch-ops.js'\nimport { normalizeOperationError } from '../git/errors.js'\nimport { TOOL_ANNOTATIONS } from './annotations.js'\nimport { capabilityError } from './guards.js'\n\n/**\n * Resolve a merge target from either an exact branch name or a\n * model/locale/latest selector. Returns the concrete branch, or an error with\n * candidate branches when the selector is ambiguous or matches nothing.\n */\nasync function resolveMergeBranch(\n git: SimpleGit,\n input: { branch?: string, model?: string, locale?: string, latest?: boolean },\n): Promise<{ branch: string } | { error: string, candidates: string[] }> {\n const summary = await git.branchLocal()\n const crBranches = summary.all.filter(b => b.startsWith('cr/') && b !== CONTENTRAIN_BRANCH)\n\n if (input.branch) {\n if (summary.all.includes(input.branch)) return { branch: input.branch }\n return { error: `Branch \"${input.branch}\" not found locally.`, candidates: crBranches }\n }\n\n if (!input.model) {\n return { error: 'Provide either \"branch\" (exact name) or \"model\" (to resolve the branch).', candidates: crBranches }\n }\n\n const prefix = input.locale\n ? `cr/content/${input.model}/${input.locale}/`\n : `cr/content/${input.model}/`\n let matches = crBranches.filter(b => b.startsWith(prefix))\n if (matches.length === 0) {\n // Fall back to any scope whose path contains the model segment (fix/bulk/...)\n matches = crBranches.filter(b => b.split('/').includes(input.model!))\n }\n if (matches.length === 0) {\n return { error: `No pending cr/* branch found for model \"${input.model}\".`, candidates: crBranches }\n }\n if (matches.length === 1) return { branch: matches[0]! }\n if (!input.latest) {\n return { error: `Multiple branches match model \"${input.model}\". Pass latest:true or an exact branch.`, candidates: matches }\n }\n const withTimes = await Promise.all(matches.map(async (b) => {\n const t = await git.raw(['log', '-1', '--format=%ct', b]).then(s => Number(s.trim())).catch(() => 0)\n return { b, t }\n }))\n const newest = withTimes.toSorted((left, right) => right.t - left.t)[0]!\n return { branch: newest.b }\n}\n\nexport function registerWorkflowTools(\n server: McpServer,\n provider: ToolProvider,\n projectRoot: string | undefined,\n): void {\n // ─── contentrain_validate ───\n server.tool(\n 'contentrain_validate',\n 'Validate project content against model schemas. Detects required field violations, type mismatches, broken relations, secret leaks, i18n parity issues, and more. If fix:true, auto-fixes structural issues (canonical sort, orphan meta, missing locale files) — do NOT manually edit .contentrain/ files.',\n {\n model: z.string().optional().describe('Model ID to validate (omit for all models)'),\n fix: z.boolean().optional().describe('Auto-fix structural issues (canonical sort, orphan meta, missing locale files). Default: false'),\n },\n TOOL_ANNOTATIONS['contentrain_validate']!,\n async (input) => {\n // Read-only validate runs over any provider (LocalProvider or remote\n // GitHubProvider). Fix mode still needs a local worktree — it opens a\n // git transaction — so it short-circuits with a capability error when\n // no projectRoot is available.\n if (input.fix && !projectRoot) {\n return capabilityError('contentrain_validate', 'localWorktree')\n }\n\n const config = await readConfig(provider)\n if (!config) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({ error: 'Project not initialized. Run contentrain_init first.' }) }],\n isError: true,\n }\n }\n\n try {\n let result: Awaited<ReturnType<typeof validateProject>> | undefined\n\n if (input.fix && projectRoot) {\n // Branch health gate for fix mode (creates a branch)\n const fixHealth = await checkBranchHealth(projectRoot)\n if (fixHealth.blocked) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n error: fixHealth.message,\n action: 'blocked',\n hint: 'Merge or delete old contentrain/* branches before auto-fixing.',\n }, null, 2) }],\n isError: true,\n }\n }\n\n // Use git transaction for fixes. Force auto-merge: structural fixes\n // (canonical sort, orphan meta, missing locale files) are cosmetic\n // infra repairs and should land directly on contentrain rather than\n // spawn a pending cr/fix/validate review branch.\n const branch = buildBranchName('fix', 'validate')\n const tx = await createTransaction(projectRoot, branch, { workflowOverride: 'auto-merge' })\n\n try {\n await tx.write(async (wt) => {\n result = await validateProject(wt, { model: input.model, fix: true })\n })\n\n if (result!.fixed > 0) {\n await tx.commit(`[contentrain] validate: auto-fix ${result!.fixed} issue(s)`, {\n tool: 'contentrain_validate',\n model: input.model ?? '*',\n })\n const gitResult = await tx.complete()\n\n const nextSteps: string[] = []\n if (result!.summary.errors > 0) nextSteps.push('Fix remaining errors manually')\n if (result!.summary.warnings > 0) nextSteps.push('Review warnings')\n nextSteps.push('Run contentrain_validate again to verify')\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n status: 'committed',\n message: `Validation complete. ${result!.fixed} issue(s) auto-fixed and committed to git. Do NOT manually edit .contentrain/ files.`,\n ...result!,\n git: { branch, action: gitResult.action, commit: gitResult.commit, ...(gitResult.sync ? { sync: gitResult.sync } : {}) },\n context_updated: true,\n next_steps: nextSteps,\n }, null, 2) }],\n }\n } else {\n // Nothing to fix, cleanup the branch\n await tx.cleanup()\n }\n } catch (error) {\n await tx.cleanup()\n throw error\n } finally {\n await tx.cleanup()\n }\n }\n\n // No fix or nothing was fixed — run read-only validation. Prefer the\n // local disk walk when we have a projectRoot (identical behavior to\n // pre-5.5 callers); otherwise drive the reader-based path so remote\n // providers stay supported.\n if (!result) {\n result = projectRoot\n ? await validateProject(projectRoot, { model: input.model, fix: false })\n : await validateProject(provider, { model: input.model, fix: false })\n }\n\n const nextSteps: string[] = []\n if (result.summary.errors > 0) nextSteps.push('Fix errors in content using contentrain_content_save')\n if (result.summary.warnings > 0) nextSteps.push('Review warnings')\n if (result.valid) nextSteps.push('Run contentrain_submit to push changes')\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n status: 'validated',\n message: result.valid\n ? 'All validation checks passed.'\n : `Validation found ${result.summary.errors} error(s) and ${result.summary.warnings} warning(s).`,\n ...result,\n next_steps: nextSteps,\n }, null, 2) }],\n }\n } catch (error) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n error: `Validation failed: ${error instanceof Error ? error.message : String(error)}`,\n }) }],\n isError: true,\n }\n }\n },\n )\n\n // ─── contentrain_submit ───\n server.tool(\n 'contentrain_submit',\n 'Push contentrain/* branches to remote. MCP is push-only — PR creation is handled by the platform. Do NOT manually push or create PRs.',\n {\n branches: z.array(z.string()).optional().describe('Specific branch names to push (omit for all contentrain/* branches)'),\n message: z.string().optional().describe('Optional message for the push operation'),\n },\n TOOL_ANNOTATIONS['contentrain_submit']!,\n async (input) => {\n // Submit pushes a branch to origin via simple-git — needs both a\n // local worktree (to enumerate cr/* branches) and pushRemote\n // (semantic capability name, even though the underlying code is\n // simple-git rather than a provider call).\n if (!provider.capabilities.localWorktree || !provider.capabilities.pushRemote || !projectRoot) {\n return capabilityError('contentrain_submit', 'localWorktree')\n }\n const config = await readConfig(projectRoot)\n if (!config) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({ error: 'Project not initialized. Run contentrain_init first.' }) }],\n isError: true,\n }\n }\n\n const git = simpleGit(projectRoot)\n const remoteName = process.env['CONTENTRAIN_REMOTE'] ?? 'origin'\n\n // Check remote exists\n let hasRemote = false\n try {\n const remotes = await git.getRemotes()\n hasRemote = remotes.some(r => r.name === remoteName)\n } catch {\n hasRemote = false\n }\n\n if (!hasRemote) {\n const summary = await git.branchLocal().catch(() => ({ all: [] as string[] }))\n const pending = summary.all.filter(b => b.startsWith('cr/') && b !== CONTENTRAIN_BRANCH)\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n error: `No remote \"${remoteName}\" configured — contentrain_submit (push) is unavailable.`,\n stage: 'submit',\n agent_hint: 'This project has no git remote. In a local/solo workflow, land pending review branches with contentrain_merge instead of submit, or set workflow:\"auto-merge\" in config.json so saves merge locally without a remote.',\n pending_branches: pending,\n next_steps: [\n pending.length > 0\n ? `Merge a pending branch locally: contentrain_merge { branch: \"${pending[0]}\", confirm: true }`\n : 'Make changes with contentrain_content_save — auto-merge lands them locally without a remote',\n `Or add a remote to enable submit: git remote add ${remoteName} <url>`,\n ],\n }, null, 2) }],\n isError: true,\n }\n }\n\n try {\n // Determine the base branch for merge-status checks\n const baseBranch = config.repository?.default_branch\n ?? process.env['CONTENTRAIN_BRANCH']\n ?? ((await git.raw(['branch', '--show-current'])).trim() || 'main')\n\n // Get contentrain branches\n const branchSummary = await git.branchLocal()\n\n // Get branches NOT yet merged into base (only these need pushing)\n let unmergedRaw = ''\n try {\n unmergedRaw = await git.raw(['branch', '--no-merged', baseBranch])\n } catch {\n // If base branch doesn't exist yet, treat all as unmerged\n unmergedRaw = branchSummary.all.join('\\n')\n }\n const unmergedSet = new Set(\n unmergedRaw.split('\\n').map(b => b.replace(/^\\*?\\s+/, '').trim()).filter(Boolean),\n )\n\n let branchesToPush: string[]\n\n if (input.branches && input.branches.length > 0) {\n branchesToPush = input.branches.filter(b => branchSummary.all.includes(b))\n const missing = input.branches.filter(b => !branchSummary.all.includes(b))\n if (missing.length > 0) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n error: `Branches not found: ${missing.join(', ')}`,\n }) }],\n isError: true,\n }\n }\n // Filter out already-merged branches from explicit list\n branchesToPush = branchesToPush.filter(b => unmergedSet.has(b))\n } else {\n branchesToPush = branchSummary.all.filter(b => b.startsWith('cr/') && unmergedSet.has(b))\n }\n\n if (branchesToPush.length === 0) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n error: 'No unmerged cr/* branches found to push.',\n next_steps: ['Make changes first with contentrain_content_save or contentrain_model_save'],\n }) }],\n isError: true,\n }\n }\n\n // Push each branch\n const pushed: string[] = []\n const errors: Array<{ branch: string; error: string }> = []\n\n for (const branch of branchesToPush) {\n try {\n await git.push(remoteName, branch)\n pushed.push(branch)\n } catch (error) {\n errors.push({\n branch,\n error: error instanceof Error ? error.message : String(error),\n })\n }\n }\n\n // Best-effort: push the contentrain branch itself\n try {\n await git.push(remoteName, CONTENTRAIN_BRANCH)\n } catch {\n // contentrain branch push is best-effort\n }\n\n // Lazy cleanup: delete merged branches after push\n const cleanup = await cleanupMergedBranches(projectRoot)\n\n const nextSteps: string[] = []\n if (pushed.length > 0) nextSteps.push('Create PRs on your git platform for review')\n if (pushed.length > 0) nextSteps.push('For merge: use contentrain_merge or direct user to http://localhost:3333/branches')\n if (errors.length > 0) nextSteps.push('Fix push errors and retry')\n if (cleanup.remaining >= 50) nextSteps.push(`Warning: ${cleanup.remaining} active contentrain branches. Consider reviewing old branches.`)\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n status: 'committed',\n message: `Pushed ${pushed.length} branch(es) to ${remoteName}.`,\n pushed,\n errors: errors.length > 0 ? errors : undefined,\n remote: remoteName,\n cleanup: cleanup.deleted > 0 ? { deleted: cleanup.deleted, remaining: cleanup.remaining } : undefined,\n next_steps: nextSteps,\n }, null, 2) }],\n }\n } catch (error) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n error: `Submit failed: ${error instanceof Error ? error.message : String(error)}`,\n }) }],\n isError: true,\n }\n }\n },\n )\n\n // ─── contentrain_merge ───\n server.tool(\n 'contentrain_merge',\n 'Merge a review-mode branch into contentrain. Local git operation — no external platform needed. Merges the feature branch into the contentrain branch, advances the base branch via update-ref, selectively syncs .contentrain/ files to the working tree, and prunes the merged branch. Target by exact \"branch\" name, or resolve by \"model\" (+ optional \"locale\"/\"latest\").',\n {\n branch: z.string().optional().describe('Exact branch name to merge (e.g. cr/content/blog-post/...). Omit to resolve by model.'),\n model: z.string().optional().describe('Resolve the branch by model id (e.g. \"blog-post\").'),\n locale: z.string().optional().describe('Narrow model resolution to a locale.'),\n latest: z.boolean().optional().describe('When multiple branches match the model, merge the most recently committed one.'),\n confirm: z.literal(true).describe('Must be true to confirm the merge'),\n },\n TOOL_ANNOTATIONS['contentrain_merge']!,\n async (input) => {\n // Merge runs a local git transaction (worktree + update-ref +\n // selective sync). Remote providers do not expose this today; use\n // provider.mergeBranch directly from a Studio-style driver instead.\n if (!provider.capabilities.localWorktree || !projectRoot) {\n return capabilityError('contentrain_merge', 'localWorktree')\n }\n const config = await readConfig(projectRoot)\n if (!config) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({ error: 'Project not initialized. Run contentrain_init first.' }) }],\n isError: true,\n }\n }\n\n try {\n // Resolve the target branch from exact name or model/locale/latest selector\n const git = simpleGit(projectRoot)\n const resolved = await resolveMergeBranch(git, input)\n if ('error' in resolved) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n error: resolved.error,\n candidates: resolved.candidates,\n next_steps: [\n 'Pass an exact { branch } or { model, latest: true }',\n 'List pending branches with contentrain_branch_list',\n ],\n }, null, 2) }],\n isError: true,\n }\n }\n const targetBranch = resolved.branch\n\n const result = await mergeBranch(projectRoot, targetBranch)\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n status: 'merged',\n branch: targetBranch,\n action: result.action,\n commit: result.commit,\n sync: result.sync,\n next_steps: [\n 'Run `contentrain generate` (or `npx contentrain-query generate`) to update the SDK client',\n 'Run contentrain_validate to verify content integrity',\n result.sync.skipped.length > 0\n ? `${result.sync.skipped.length} file(s) skipped due to local changes — resolve manually`\n : '',\n ].filter(Boolean),\n }, null, 2) }],\n }\n } catch (error) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(normalizeOperationError(error, 'merge'), null, 2) }],\n isError: true,\n }\n }\n },\n )\n\n // ─── contentrain_branch_list ───\n server.tool(\n 'contentrain_branch_list',\n 'List pending contentrain (cr/*) branches with their merge status against the contentrain branch. Use this to discover branch names for contentrain_merge / contentrain_branch_delete, and to monitor branch-health limits (warning at 50, blocked at 80 unmerged).',\n {\n unmerged_only: z.boolean().optional().describe('Only list branches not yet merged into contentrain. Default: false'),\n },\n TOOL_ANNOTATIONS['contentrain_branch_list']!,\n async (input) => {\n if (!provider.capabilities.localWorktree || !projectRoot) {\n return capabilityError('contentrain_branch_list', 'localWorktree')\n }\n try {\n const git = simpleGit(projectRoot)\n const summary = await git.branchLocal()\n const crBranches = summary.all.filter(b => b.startsWith('cr/') && b !== CONTENTRAIN_BRANCH)\n\n const branches = await Promise.all(crBranches.map(async (name) => {\n const [merged, ts] = await Promise.all([\n isMerged(projectRoot, name, CONTENTRAIN_BRANCH),\n git.raw(['log', '-1', '--format=%cI', name]).then(s => s.trim()).catch(() => ''),\n ])\n return { name, sha: summary.branches[name]?.commit ?? '', merged, lastCommit: ts }\n }))\n const ordered = branches.toSorted((left, right) => right.lastCommit.localeCompare(left.lastCommit))\n const filtered = input.unmerged_only ? ordered.filter(b => !b.merged) : ordered\n const health = await checkBranchHealth(projectRoot)\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n total: ordered.length,\n unmerged: ordered.filter(b => !b.merged).length,\n branches: filtered,\n health: { warning: health.warning, blocked: health.blocked, message: health.message },\n next_steps: [\n 'Merge a branch: contentrain_merge { branch: \"...\", confirm: true }',\n 'Delete a stale branch: contentrain_branch_delete { branch: \"...\", confirm: true }',\n ],\n }, null, 2) }],\n }\n } catch (error) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(normalizeOperationError(error, 'branch_list'), null, 2) }],\n isError: true,\n }\n }\n },\n )\n\n // ─── contentrain_branch_delete ───\n server.tool(\n 'contentrain_branch_delete',\n 'Delete a pending contentrain (cr/*) branch that will not be merged — e.g. a branch left behind by a failed operation, or a superseded draft. Only cr/* branches can be deleted; the contentrain branch is protected. This is destructive: the branch and its unmerged commits are removed.',\n {\n branch: z.string().describe('The cr/* branch to delete'),\n confirm: z.literal(true).describe('Must be true to confirm deletion'),\n },\n TOOL_ANNOTATIONS['contentrain_branch_delete']!,\n async (input) => {\n if (!provider.capabilities.localWorktree || !projectRoot) {\n return capabilityError('contentrain_branch_delete', 'localWorktree')\n }\n if (!input.branch.startsWith('cr/') || input.branch === CONTENTRAIN_BRANCH) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n error: `Refusing to delete \"${input.branch}\". Only cr/* feature branches can be deleted (the contentrain branch is protected).`,\n }) }],\n isError: true,\n }\n }\n try {\n const git = simpleGit(projectRoot)\n const summary = await git.branchLocal()\n if (!summary.all.includes(input.branch)) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n error: `Branch \"${input.branch}\" not found locally.`,\n next_steps: ['List branches with contentrain_branch_list'],\n }) }],\n isError: true,\n }\n }\n const merged = await isMerged(projectRoot, input.branch, CONTENTRAIN_BRANCH)\n // Force-delete (-D): the branch may carry unmerged commits the caller\n // has explicitly decided to discard.\n await git.raw(['branch', '-D', input.branch])\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n status: 'deleted',\n branch: input.branch,\n was_merged: merged,\n warning: merged ? undefined : 'Branch was not merged — its commits were discarded.',\n }, null, 2) }],\n }\n } catch (error) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(normalizeOperationError(error, 'branch_delete'), null, 2) }],\n isError: true,\n }\n }\n },\n )\n}\n","import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { FieldDef } from '@contentrain/types'\nimport { z } from 'zod'\nimport type { ToolProvider } from '../server.js'\nimport { readConfig } from '../core/config.js'\nimport { buildGraph } from '../core/graph-builder.js'\nimport { scanCandidates, scanSummary } from '../core/scanner.js'\nimport { applyExtract, applyReuse } from '../core/apply-manager.js'\nimport { fieldDefZodSchema } from '../core/model-manager.js'\nimport { TOOL_ANNOTATIONS } from './annotations.js'\nimport { capabilityError } from './guards.js'\n\nexport function registerNormalizeTools(\n server: McpServer,\n provider: ToolProvider,\n projectRoot: string | undefined,\n): void {\n // ─── contentrain_scan ───\n server.tool(\n 'contentrain_scan',\n 'Scan project source code for content strings. Three modes: \"graph\" builds import/component graph for project intelligence, \"candidates\" extracts string literals with pre-filtering and pagination, \"summary\" provides quick overview stats. Read-only — no changes to disk or git. MCP finds strings deterministically; the agent decides what is content. Recommended workflow: start with \"summary\" or \"graph\" for orientation, then paginate through \"candidates\" to evaluate strings.',\n {\n mode: z.enum(['graph', 'candidates', 'summary']).optional().describe('Scan mode. Default: candidates'),\n paths: z.array(z.string()).optional().describe('Directories to scan (relative to project root). Default: auto-detect'),\n include: z.array(z.string()).optional().describe('File extensions to include. Default: .tsx, .jsx, .vue, .ts, .js, .mjs, .astro, .svelte'),\n exclude: z.array(z.string()).optional().describe('Additional directory names to exclude'),\n limit: z.number().optional().describe('Candidates mode: batch size. Default: 50'),\n offset: z.number().optional().describe('Candidates mode: pagination offset. Default: 0'),\n min_length: z.number().optional().describe('Candidates mode: minimum string length. Default: 2'),\n max_length: z.number().optional().describe('Candidates mode: maximum string length. Default: 500'),\n },\n TOOL_ANNOTATIONS['contentrain_scan']!,\n async (input) => {\n // AST scans require local disk access — GitHubProvider et al. expose\n // `astScan: false`, so this rejects with a uniform capability error.\n if (!provider.capabilities.astScan || !projectRoot) {\n return capabilityError('contentrain_scan', 'astScan')\n }\n const config = await readConfig(projectRoot)\n if (!config) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({ error: 'Project not initialized. Run contentrain_init first.' }) }],\n isError: true,\n }\n }\n\n const mode = input.mode ?? 'candidates'\n\n try {\n switch (mode) {\n case 'graph': {\n const graph = await buildGraph(projectRoot, {\n paths: input.paths,\n include: input.include,\n exclude: input.exclude,\n })\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n mode: 'graph',\n ...graph,\n next_steps: [\n 'Use mode:candidates to scan specific files/directories for strings',\n 'Focus on pages and components with high string counts first',\n ],\n }, null, 2) }],\n }\n }\n\n case 'candidates': {\n const result = await scanCandidates(projectRoot, {\n paths: input.paths,\n include: input.include,\n exclude: input.exclude,\n limit: input.limit,\n offset: input.offset,\n min_length: input.min_length,\n max_length: input.max_length,\n })\n\n const nextSteps: string[] = []\n if (result.stats.has_more) {\n nextSteps.push(`Use offset:${(input.offset ?? 0) + (input.limit ?? 50)} for next batch`)\n }\n nextSteps.push('Evaluate each candidate: is it user-facing content? Which domain/model?')\n if (result.duplicates.length > 0) {\n nextSteps.push('Consider deduplicating repeated strings into shared models')\n }\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n mode: 'candidates',\n ...result,\n next_steps: nextSteps,\n }, null, 2) }],\n }\n }\n\n case 'summary': {\n const result = await scanSummary(projectRoot, {\n paths: input.paths,\n include: input.include,\n exclude: input.exclude,\n min_length: input.min_length,\n max_length: input.max_length,\n })\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n mode: 'summary',\n ...result,\n next_steps: [\n 'Use mode:graph for project structure analysis',\n 'Use mode:candidates to scan directories with most candidates',\n ],\n }, null, 2) }],\n }\n }\n\n default:\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({ error: `Unknown mode: ${mode}` }) }],\n isError: true,\n }\n }\n } catch (error) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n error: `Scan failed: ${error instanceof Error ? error.message : String(error)}`,\n }) }],\n isError: true,\n }\n }\n },\n )\n\n // ─── contentrain_apply ───\n server.tool(\n 'contentrain_apply',\n 'Apply normalize operations. Two modes: \"extract\" writes agent-approved strings to Contentrain content files (source untouched), \"reuse\" patches source files with agent-provided replacement expressions. DRY RUN (default, dry_run:true): validates inputs, resolves conflicts, and returns a full preview — NO changes to disk or git. EXECUTE (dry_run:false): writes files to disk, commits to a branch, and requires branch health check to pass. Recommended workflow: always run dry_run first, review the preview, then call again with dry_run:false to execute. Normalize operations always use review workflow (never auto-merge).',\n {\n mode: z.enum(['extract', 'reuse']).describe('Apply mode: extract (content creation) or reuse (source patching)'),\n dry_run: z.boolean().optional().default(true).describe('Defaults to preview mode (dry_run:true). Set dry_run:false to execute after reviewing the preview.'),\n\n // Extract mode fields\n extractions: z.array(z.object({\n model: z.string().describe('Model ID (e.g. \"ui-texts\", \"hero-section\")'),\n kind: z.enum(['singleton', 'collection', 'dictionary', 'document']).describe('Model kind'),\n domain: z.string().describe('Content domain (e.g. \"marketing\", \"app\")'),\n i18n: z.boolean().optional().describe('Enable i18n. Default: true'),\n fields: fieldDefZodSchema.optional().describe('Field definitions — shared schema with model_save for full parity'),\n entries: z.array(z.object({\n locale: z.string().optional().describe('Locale. Default: project default'),\n slug: z.string().optional().describe('Document slug'),\n data: z.record(z.any()).describe('Content data'),\n source: z.object({\n file: z.string().describe('Source file path'),\n line: z.number().describe('Source line number'),\n value: z.string().describe('Original string value'),\n }).optional().describe('Source tracking for traceability'),\n sources: z.array(z.object({\n file: z.string().describe('Source file path'),\n line: z.number().describe('Source line number'),\n key: z.string().describe('Dictionary key this source maps to'),\n value: z.string().describe('Original string value'),\n })).optional().describe('Per-key source tracking for dictionary models'),\n })).describe('Content entries to create'),\n })).optional().describe('Extract mode: content extractions'),\n\n // Reuse mode fields\n scope: z.object({\n model: z.string().optional().describe('Target model ID'),\n domain: z.string().optional().describe('Target domain'),\n }).optional().describe('Reuse mode: scope (model or domain required)'),\n patches: z.array(z.object({\n file: z.string().describe('Relative file path to patch'),\n line: z.number().describe('Line number hint (±10 line search)'),\n old_value: z.string().describe('Original string to replace'),\n new_expression: z.string().describe('Replacement expression (agent-determined)'),\n import_statement: z.string().optional().describe('Import to add if needed'),\n })).optional().describe('Reuse mode: patches to apply (max 100)'),\n },\n TOOL_ANNOTATIONS['contentrain_apply']!,\n async (input) => {\n // Normalize extract needs to read source files; reuse needs to write\n // them back. Remote providers expose both capabilities as `false` and\n // get rejected before any work starts.\n const capability = input.mode === 'reuse' ? 'sourceWrite' : 'sourceRead'\n if (!provider.capabilities[capability] || !projectRoot) {\n return capabilityError('contentrain_apply', capability)\n }\n const config = await readConfig(projectRoot)\n if (!config) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({ error: 'Project not initialized. Run contentrain_init first.' }) }],\n isError: true,\n }\n }\n\n try {\n switch (input.mode) {\n case 'extract': {\n if (!input.extractions || input.extractions.length === 0) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({ error: 'Extract mode requires extractions array' }) }],\n isError: true,\n }\n }\n\n const result = await applyExtract(projectRoot, {\n extractions: input.extractions.map(e => ({\n ...e,\n fields: e.fields as Record<string, FieldDef> | undefined,\n })),\n dry_run: input.dry_run,\n })\n\n // Check for branch-blocked response\n if (result.error !== undefined) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n mode: 'extract',\n ...result,\n }, null, 2) }],\n isError: true,\n }\n }\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n mode: 'extract',\n ...result,\n }, null, 2) }],\n }\n }\n\n case 'reuse': {\n if (!input.scope) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({ error: 'Reuse mode requires scope (model or domain)' }) }],\n isError: true,\n }\n }\n if (!input.patches || input.patches.length === 0) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({ error: 'Reuse mode requires patches array' }) }],\n isError: true,\n }\n }\n\n const result = await applyReuse(projectRoot, {\n scope: input.scope,\n patches: input.patches,\n dry_run: input.dry_run,\n })\n\n // Check for branch-blocked response\n if (result.error !== undefined) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n mode: 'reuse',\n ...result,\n }, null, 2) }],\n isError: true,\n }\n }\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n mode: 'reuse',\n ...result,\n }, null, 2) }],\n }\n }\n\n default:\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({ error: `Unknown mode: ${input.mode}` }) }],\n isError: true,\n }\n }\n } catch (error) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n error: `Apply failed: ${error instanceof Error ? error.message : String(error)}`,\n }) }],\n isError: true,\n }\n }\n },\n )\n}\n","import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { EntryMeta } from '@contentrain/types'\nimport { z } from 'zod'\nimport type { ToolProvider } from '../server.js'\nimport { readConfig } from '../core/config.js'\nimport { readModel } from '../core/model-manager.js'\nimport { resolveContentDir, resolveJsonFilePath, deleteContent } from '../core/content-manager.js'\nimport { readMeta, writeMeta } from '../core/meta-manager.js'\nimport { createTransaction, buildBranchName } from '../git/transaction.js'\nimport { checkBranchHealth } from '../git/branch-lifecycle.js'\nimport { normalizeOperationError } from '../git/errors.js'\nimport { readJson, writeJson } from '../util/fs.js'\nimport { TOOL_ANNOTATIONS } from './annotations.js'\nimport { capabilityError } from './guards.js'\n\nexport function registerBulkTools(\n server: McpServer,\n _provider: ToolProvider,\n projectRoot: string | undefined,\n): void {\n server.tool(\n 'contentrain_bulk',\n 'Batch operations on content entries. All operations are auto-committed to git.',\n {\n operation: z.enum(['copy_locale', 'update_status', 'delete_entries']),\n model: z.string().describe('Model ID'),\n source_locale: z.string().optional().describe('Source locale for copy_locale operation'),\n target_locale: z.string().optional().describe('Target locale for copy_locale operation'),\n entry_ids: z.array(z.string()).optional().describe('Entry IDs for update_status or delete_entries'),\n status: z.enum(['draft', 'in_review', 'published', 'rejected', 'archived']).optional().describe('New status for update_status'),\n confirm: z.boolean().optional().describe('Must be true for delete_entries'),\n },\n TOOL_ANNOTATIONS['contentrain_bulk']!,\n async (input) => {\n if (!projectRoot) return capabilityError('contentrain_bulk', 'localWorktree')\n const config = await readConfig(projectRoot)\n if (!config) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({ error: 'Project not initialized. Run contentrain_init first.' }) }],\n isError: true,\n }\n }\n\n const model = await readModel(projectRoot, input.model)\n if (!model) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({ error: `Model \"${input.model}\" not found` }) }],\n isError: true,\n }\n }\n\n // Branch health gate\n const health = await checkBranchHealth(projectRoot)\n if (health.blocked) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n error: health.message,\n action: 'blocked',\n hint: 'Merge or delete old contentrain/* branches before creating new ones.',\n }, null, 2) }],\n isError: true,\n }\n }\n\n switch (input.operation) {\n case 'copy_locale': {\n if (!input.source_locale || !input.target_locale) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({ error: 'copy_locale requires source_locale and target_locale' }) }],\n isError: true,\n }\n }\n if (!config.locales.supported.includes(input.source_locale)) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n error: `Source locale \"${input.source_locale}\" is not supported. Supported: [${config.locales.supported.join(', ')}]`,\n }) }],\n isError: true,\n }\n }\n if (!config.locales.supported.includes(input.target_locale)) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n error: `Target locale \"${input.target_locale}\" is not supported. Supported: [${config.locales.supported.join(', ')}]`,\n }) }],\n isError: true,\n }\n }\n\n // Guard: copy_locale requires i18n model — non-i18n models use data.json for all locales\n if (!model.i18n) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n error: `Model \"${input.model}\" has i18n disabled. copy_locale only works with i18n-enabled models. Enable i18n first with contentrain_model_save.`,\n }) }],\n isError: true,\n }\n }\n\n if (model.kind !== 'collection' && model.kind !== 'singleton' && model.kind !== 'dictionary') {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({ error: 'copy_locale is only supported for collection, singleton, and dictionary models' }) }],\n isError: true,\n }\n }\n\n const branch = buildBranchName('bulk', input.model, input.target_locale)\n const tx = await createTransaction(projectRoot, branch)\n\n try {\n let copiedCount = 0\n\n await tx.write(async (wt) => {\n const cDir = resolveContentDir(wt, model)\n const sourceFile = resolveJsonFilePath(cDir, model, input.source_locale!)\n const targetFile = resolveJsonFilePath(cDir, model, input.target_locale!)\n\n const sourceData = await readJson<Record<string, unknown>>(sourceFile)\n if (!sourceData) {\n throw new Error(`No content found for locale \"${input.source_locale}\" in model \"${input.model}\"`)\n }\n\n await writeJson(targetFile, sourceData)\n\n if (model.kind === 'collection') {\n const entries = sourceData as Record<string, Record<string, unknown>>\n const entryIds = Object.keys(entries)\n const metaOps = entryIds.map(entryId =>\n writeMeta(wt, model, { locale: input.target_locale!, entryId }, {\n status: 'draft',\n source: 'agent',\n updated_by: 'contentrain-mcp',\n }),\n )\n await Promise.all(metaOps)\n copiedCount = entryIds.length\n } else {\n await writeMeta(wt, model, { locale: input.target_locale! }, {\n status: 'draft',\n source: 'agent',\n updated_by: 'contentrain-mcp',\n })\n copiedCount = 1\n }\n\n })\n\n await tx.commit(`[contentrain] bulk: copy ${input.source_locale} → ${input.target_locale} for ${input.model}`, {\n tool: 'contentrain_bulk',\n model: input.model,\n locale: input.target_locale!,\n })\n const gitResult = await tx.complete()\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n status: 'committed',\n operation: 'copy_locale',\n message: `Copied ${copiedCount} entries from ${input.source_locale} to ${input.target_locale}.`,\n copied: copiedCount,\n git: { branch, action: gitResult.action, commit: gitResult.commit, ...(gitResult.sync ? { sync: gitResult.sync } : {}) },\n context_updated: true,\n }, null, 2) }],\n }\n } catch (error) {\n await tx.cleanup()\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n ...normalizeOperationError(error, 'bulk_copy_locale'),\n }) }],\n isError: true,\n }\n } finally {\n await tx.cleanup()\n }\n }\n\n case 'update_status': {\n if (!input.entry_ids || input.entry_ids.length === 0) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({ error: 'update_status requires entry_ids' }) }],\n isError: true,\n }\n }\n if (!input.status) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({ error: 'update_status requires status' }) }],\n isError: true,\n }\n }\n\n if (model.kind !== 'collection') {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({ error: 'update_status with entry_ids is only supported for collection models' }) }],\n isError: true,\n }\n }\n\n const branch = buildBranchName('bulk', input.model)\n const tx = await createTransaction(projectRoot, branch)\n\n try {\n let updatedCount = 0\n const notFound: string[] = []\n\n await tx.write(async (wt) => {\n for (const locale of config.locales.supported) {\n const metaData = await readMeta(wt, model, { locale }) as Record<string, EntryMeta> | null\n\n const updateOps: Array<Promise<void>> = []\n for (const entryId of input.entry_ids!) {\n const existing = metaData?.[entryId]\n if (existing) {\n updateOps.push(writeMeta(wt, model, { locale, entryId }, {\n ...existing,\n status: input.status!,\n updated_by: 'contentrain-mcp',\n }))\n updatedCount++\n } else if (locale === config.locales.default) {\n notFound.push(entryId)\n }\n }\n await Promise.all(updateOps)\n }\n\n })\n\n await tx.commit(`[contentrain] bulk: update status → ${input.status} for ${input.model}`, {\n tool: 'contentrain_bulk',\n model: input.model,\n entries: input.entry_ids!,\n })\n const gitResult = await tx.complete()\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n status: 'committed',\n operation: 'update_status',\n message: `Updated ${updatedCount} meta entries to status \"${input.status}\".`,\n updated: updatedCount,\n not_found: notFound.length > 0 ? notFound : undefined,\n git: { branch, action: gitResult.action, commit: gitResult.commit, ...(gitResult.sync ? { sync: gitResult.sync } : {}) },\n context_updated: true,\n }, null, 2) }],\n }\n } catch (error) {\n await tx.cleanup()\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n ...normalizeOperationError(error, 'bulk_update_status'),\n }) }],\n isError: true,\n }\n } finally {\n await tx.cleanup()\n }\n }\n\n case 'delete_entries': {\n if (!input.entry_ids || input.entry_ids.length === 0) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({ error: 'delete_entries requires entry_ids' }) }],\n isError: true,\n }\n }\n if (input.confirm !== true) {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({ error: 'delete_entries requires confirm:true' }) }],\n isError: true,\n }\n }\n\n if (model.kind !== 'collection') {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({ error: 'delete_entries with entry_ids is only supported for collection models' }) }],\n isError: true,\n }\n }\n\n const branch = buildBranchName('bulk', input.model)\n const tx = await createTransaction(projectRoot, branch)\n\n try {\n const allRemoved: string[] = []\n\n await tx.write(async (wt) => {\n for (const entryId of input.entry_ids!) {\n const removed = await deleteContent(wt, model, { id: entryId })\n allRemoved.push(...removed)\n }\n\n })\n\n await tx.commit(`[contentrain] bulk: delete ${input.entry_ids.length} entries from ${input.model}`, {\n tool: 'contentrain_bulk',\n model: input.model,\n entries: input.entry_ids!,\n })\n const gitResult = await tx.complete()\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n status: 'committed',\n operation: 'delete_entries',\n message: `Deleted ${input.entry_ids.length} entries.`,\n deleted: input.entry_ids.length,\n files_removed: allRemoved,\n git: { branch, action: gitResult.action, commit: gitResult.commit, ...(gitResult.sync ? { sync: gitResult.sync } : {}) },\n context_updated: true,\n }, null, 2) }],\n }\n } catch (error) {\n await tx.cleanup()\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({\n ...normalizeOperationError(error, 'bulk_delete_entries'),\n }) }],\n isError: true,\n }\n } finally {\n await tx.cleanup()\n }\n }\n\n default: {\n return {\n content: [{ type: 'text' as const, text: JSON.stringify({ error: `Unknown operation: ${input.operation}` }) }],\n isError: true,\n }\n }\n }\n },\n )\n}\n","import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport { z } from 'zod'\nimport type { ToolProvider } from '../server.js'\nimport { runDoctor } from '../core/doctor.js'\nimport { TOOL_ANNOTATIONS } from './annotations.js'\nimport { capabilityError } from './guards.js'\n\nexport function registerDoctorTools(\n server: McpServer,\n _provider: ToolProvider,\n projectRoot: string | undefined,\n): void {\n server.tool(\n 'contentrain_doctor',\n 'Project health report (read-only). Returns structured checks: git, node, .contentrain/ structure, model parse, orphan content, branch pressure, SDK freshness. Pass `usage: true` for a deeper analysis of content-key references in source files (unused keys, duplicate dictionary values, locale coverage). Local-filesystem only — unavailable over remote providers.',\n {\n usage: z.boolean().optional().default(false).describe('Run the heavier usage-analysis branch (unused keys, duplicate values, missing locales). Default: false.'),\n },\n TOOL_ANNOTATIONS['contentrain_doctor']!,\n async ({ usage }) => {\n if (!projectRoot) return capabilityError('contentrain_doctor', 'localWorktree')\n\n const report = await runDoctor(projectRoot, { usage })\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(report, null, 2) }],\n }\n },\n )\n}\n","","import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { RepoProvider } from './core/contracts/index.js'\nimport { LocalProvider } from './providers/local/index.js'\n\n/**\n * The provider shape tool handlers consume. Now that every provider\n * (Local, GitHub, GitLab) implements the full `RepoProvider`, tools can\n * depend on the shared surface directly — no private alias required.\n * Kept as a re-export so callers that already import `ToolProvider` do\n * not need to migrate.\n */\nexport type ToolProvider = RepoProvider\nimport { registerContextTools } from './tools/context.js'\nimport { registerSetupTools } from './tools/setup.js'\nimport { registerModelTools } from './tools/model.js'\nimport { registerContentTools } from './tools/content.js'\nimport { registerWorkflowTools } from './tools/workflow.js'\nimport { registerNormalizeTools } from './tools/normalize.js'\nimport { registerBulkTools } from './tools/bulk.js'\nimport { registerDoctorTools } from './tools/doctor.js'\nimport packageJson from '../package.json' with { type: 'json' }\n\nexport interface CreateServerOptions {\n /**\n * Content provider — drives reads (and, in later phases, writes) through\n * a reader surface. Required when `projectRoot` is omitted. Accepts the\n * narrow `ToolProvider` shape so either `LocalProvider` or\n * `GitHubProvider` satisfies the contract.\n */\n provider?: ToolProvider\n /**\n * Local project root. When the provider is a `LocalProvider`, its own\n * `projectRoot` is used as the fallback. Tools that require local disk\n * (normalize, setup, git submit/merge) short-circuit with a capability\n * error when no projectRoot is available.\n */\n projectRoot?: string\n}\n\n/**\n * Create an MCP server instance with every Contentrain tool registered.\n *\n * Two signatures:\n *\n * - `createServer('/path/to/project')` — legacy stdio flow. A `LocalProvider`\n * is constructed under the hood; every tool keeps behaving exactly as it\n * did before phase 5.3.\n * - `createServer({ provider, projectRoot? })` — phase 5.3 flow. Any\n * `RepoProvider` (including `GitHubProvider`) drives reads and writes. If\n * the provider is a `LocalProvider` and `projectRoot` is omitted, the\n * provider's own `projectRoot` is used. Otherwise `projectRoot` stays\n * undefined and tools that need local disk report a capability error.\n *\n * Public MCP tool surface (names, parameters, response JSON shape) is\n * unchanged across both signatures.\n */\nexport function createServer(projectRoot: string): McpServer\nexport function createServer(opts: CreateServerOptions): McpServer\nexport function createServer(input: string | CreateServerOptions): McpServer {\n const { provider, projectRoot } = resolveServerContext(input)\n\n const server = new McpServer({\n name: 'contentrain-mcp',\n version: packageJson.version,\n })\n\n registerContextTools(server, provider, projectRoot)\n registerSetupTools(server, provider, projectRoot)\n registerModelTools(server, provider, projectRoot)\n registerContentTools(server, provider, projectRoot)\n registerWorkflowTools(server, provider, projectRoot)\n registerNormalizeTools(server, provider, projectRoot)\n registerBulkTools(server, provider, projectRoot)\n registerDoctorTools(server, provider, projectRoot)\n\n return server\n}\n\nfunction resolveServerContext(input: string | CreateServerOptions): {\n provider: ToolProvider\n projectRoot: string | undefined\n} {\n if (typeof input === 'string') {\n return { provider: new LocalProvider(input), projectRoot: input }\n }\n if (input.provider) {\n let projectRoot = input.projectRoot\n if (!projectRoot && input.provider instanceof LocalProvider) {\n projectRoot = input.provider.projectRoot\n }\n return { provider: input.provider, projectRoot }\n }\n if (input.projectRoot) {\n return { provider: new LocalProvider(input.projectRoot), projectRoot: input.projectRoot }\n }\n throw new Error('createServer: either `provider` or `projectRoot` must be provided')\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,SAAgB,qBACd,QACA,UACA,aACM;AAEN,QAAO,KACL,sBACA,kIACA,EAAE,EACF,iBAAiB,uBACjB,YAAY;AAMV,MAAI,CAFgB,MAAM,SAAS,WAAW,2BAA2B,EAEvD;GAChB,MAAM,gBAAgB,cAAc,MAAM,YAAY,YAAY,GAAG;AACrE,UAAO,EACL,SAAS,CAAC;IACR,MAAM;IACN,MAAM,KAAK,UAAU;KACnB,aAAa;KACb,GAAI,gBAAgB,EAAE,gBAAgB,eAAe,GAAG,EAAE;KAC1D,YAAY;KACZ,YAAY,CAAC,uBAAuB;KACrC,EAAE,MAAM,EAAE;IACZ,CAAC,EACH;;EAGH,MAAM,SAAS,MAAM,WAAW,SAAS;EACzC,MAAM,SAAS,MAAM,WAAW,SAAS;EAKzC,MAAM,UAAU,cAAc,MAAM,YAAY,YAAY,GAAG,MAAM,YAAY,SAAS;EAC1F,MAAM,aAAa,MAAM,eAAe,SA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,MAAM;EACGA;EACV,CAAC;AAEF,sBAAqB,QAAQ,UAAU,YAAY;AACnD,oBAAmB,QAAQ,UAAU,YAAY;AACjD,oBAAmB,QAAQ,UAAU,YAAY;AACjD,sBAAqB,QAAQ,UAAU,YAAY;AACnD,uBAAsB,QAAQ,UAAU,YAAY;AACpD,wBAAuB,QAAQ,UAAU,YAAY;AACrD,mBAAkB,QAAQ,UAAU,YAAY;AAChD,qBAAoB,QAAQ,UAAU,YAAY;AAElD,QAAO;;AAGT,SAAS,qBAAqB,OAG5B;AACA,KAAI,OAAO,UAAU,SACnB,QAAO;EAAE,UAAU,IAAI,cAAc,MAAM;EAAE,aAAa;EAAO;AAEnE,KAAI,MAAM,UAAU;EAClB,IAAI,cAAc,MAAM;AACxB,MAAI,CAAC,eAAe,MAAM,oBAAoB,cAC5C,eAAc,MAAM,SAAS;AAE/B,SAAO;GAAE,UAAU,MAAM;GAAU;GAAa;;AAElD,KAAI,MAAM,YACR,QAAO;EAAE,UAAU,IAAI,cAAc,MAAM,YAAY;EAAE,aAAa,MAAM;EAAa;AAE3F,OAAM,IAAI,MAAM,oEAAoE"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"transaction-0D_edyh0.mjs","names":["removeFile"],"sources":["../src/providers/local/migration.ts","../src/git/transaction.ts"],"sourcesContent":["import type { SimpleGit } from 'simple-git'\n\n/**\n * Migration: the first MCP release used `contentrain/*` feature branches.\n * Once we introduced the singleton `contentrain` branch (tracking the\n * committed content state), those old feature branches became a ref-\n * namespace conflict — git cannot hold both `contentrain` (a leaf ref)\n * and `contentrain/foo` (implying a directory) simultaneously.\n *\n * `migrateLegacyBranches` removes the old-prefix branches so the\n * singleton `contentrain` ref can be created. It is idempotent and\n * safe to call before every `ensureContentBranch` run.\n *\n * Strategy:\n * 1. Delete merged `contentrain/*` branches first (`-d`). Their commits\n * are already on the base branch via the old auto-merge flow.\n * 2. Force-delete whatever remains (`-D`). Any unmerged leftover is\n * from an abandoned or partially-committed legacy branch — content\n * on `main` always wins, and the singleton `contentrain` branch is\n * about to be created from `main`/`baseBranch` anyway.\n *\n * Returns the number of branches that were deleted. Callers may log it;\n * the git transaction layer does not need the count for correctness.\n */\nexport async function migrateLegacyBranches(\n git: SimpleGit,\n baseBranch: string,\n): Promise<number> {\n const branches = await git.branchLocal()\n const oldPrefixBranches = branches.all.filter(b => b.startsWith('contentrain/'))\n if (oldPrefixBranches.length === 0) return 0\n\n let deleted = 0\n\n // 1) Delete merged legacy branches first — the safe path.\n let mergedLegacy: string[] = []\n try {\n const mergedOutput = await git.raw(['branch', '--merged', baseBranch])\n mergedLegacy = mergedOutput.split('\\n')\n .map(b => b.trim().replace(/^\\*\\s*/, ''))\n .filter(b => b.startsWith('contentrain/'))\n } catch {\n // `branch --merged` fails before baseBranch exists — fall through.\n }\n\n for (const b of mergedLegacy) {\n try {\n await git.raw(['branch', '-d', b])\n deleted++\n } catch {\n // Branch may be protected or already gone — safe to skip.\n }\n }\n\n // 2) Force-delete any unmerged legacy branches still present.\n const remaining = (await git.branchLocal()).all.filter(b => b.startsWith('contentrain/'))\n for (const b of remaining) {\n try {\n await git.raw(['branch', '-D', b])\n deleted++\n } catch {\n // Skip — best-effort cleanup.\n }\n }\n\n return deleted\n}\n","import { simpleGit, type SimpleGit } from 'simple-git'\nimport { join } from 'node:path'\nimport { rm as removeFile } from 'node:fs/promises'\nimport { tmpdir } from 'node:os'\nimport { randomUUID } from 'node:crypto'\nimport { readConfig } from '../core/config.js'\nimport { writeContext } from '../core/context.js'\nimport { branchTimestamp } from '../util/id.js'\nimport { migrateLegacyBranches } from '../providers/local/migration.js'\nimport type { SyncResult, WorkflowMode } from '@contentrain/types'\nimport { CONTENTRAIN_BRANCH } from '@contentrain/types'\n\nexport interface ContextUpdate {\n tool: string\n model: string\n locale?: string\n entries?: string[]\n}\n\nexport interface GitTransaction {\n worktree: string\n branch: string\n write(callback: (worktreePath: string) => Promise<void>): Promise<void>\n commit(message: string, contextUpdate?: ContextUpdate): Promise<string>\n complete(): Promise<{ action: 'auto-merged' | 'pending-review'; commit: string; sync?: SyncResult; warning?: string }>\n cleanup(): Promise<void>\n}\n\nexport async function ensureContentBranch(projectRoot: string): Promise<void> {\n const git = simpleGit(projectRoot)\n const config = await readConfig(projectRoot)\n\n // Check if contentrain branch exists locally\n const branches = await git.branchLocal()\n if (branches.all.includes(CONTENTRAIN_BRANCH)) return\n\n // Detect base branch\n const baseBranch = config?.repository?.default_branch\n || (await git.raw(['branch', '--show-current'])).trim()\n || 'main'\n\n // Clean up legacy `contentrain/*` feature branches so the singleton\n // `contentrain` ref can be created. Idempotent — safe to call even\n // when no legacy branches exist.\n await migrateLegacyBranches(git, baseBranch)\n\n // Create contentrain branch from base\n await git.branch([CONTENTRAIN_BRANCH, baseBranch])\n\n // Push to remote if exists\n const remoteName = process.env['CONTENTRAIN_REMOTE'] ?? 'origin'\n try {\n const remotes = await git.getRemotes()\n if (remotes.some(r => r.name === remoteName)) {\n await git.push(['-u', remoteName, CONTENTRAIN_BRANCH])\n }\n } catch {\n // Remote push is best-effort\n }\n}\n\nasync function selectiveSync(\n projectRoot: string,\n _worktreePath: string,\n contentrainTip: string,\n _previousBaseRef?: string,\n dirtyFilesBeforeUpdate?: Set<string>,\n): Promise<SyncResult> {\n const git = simpleGit(projectRoot)\n const synced: string[] = []\n const skipped: string[] = []\n\n // Use git plumbing to find ALL files that differ between old and new commits.\n // diff-tree is fast and ignores working tree / index state entirely.\n // Not limited to .contentrain/ — some ops also modify .gitignore, etc.\n const compareRef = _previousBaseRef ?? contentrainTip\n let changedFiles: string[] = []\n try {\n const diffOutput = await git.raw([\n 'diff-tree', '--name-only', '-r', '--no-commit-id',\n compareRef, contentrainTip,\n ])\n changedFiles = diffOutput.split('\\n').filter(f => f.trim().length > 0)\n } catch {\n // Fallback: list .contentrain/ files from the contentrainTip commit\n try {\n const lsOutput = await git.raw(['ls-tree', '-r', '--name-only', contentrainTip, '.contentrain/'])\n changedFiles = lsOutput.split('\\n').filter(f => f.trim().length > 0)\n } catch {\n return { synced, skipped }\n }\n }\n\n if (changedFiles.length === 0) return { synced, skipped }\n\n // Use pre-captured dirty files (before update-ref) to avoid false positives.\n // After update-ref, files appear as \"modified\" in status even though the developer\n // didn't touch them. We use the pre-update state to know what was truly dirty.\n const dirtyFiles = dirtyFilesBeforeUpdate ?? new Set<string>()\n\n // Determine which changed files still exist in contentrainTip (HEAD after update-ref)\n // Check each changed file individually — `ls-tree` on specific paths is efficient\n const filesInTip = new Set<string>()\n for (const file of changedFiles) {\n try {\n await git.raw(['cat-file', '-e', `${contentrainTip}:${file}`])\n filesInTip.add(file)\n } catch {\n // File does not exist in tip (was deleted)\n }\n }\n\n for (const file of changedFiles) {\n if (dirtyFiles.has(file)) {\n skipped.push(file)\n } else if (filesInTip.has(file)) {\n // File exists in new HEAD — checkout from HEAD\n try {\n await git.checkout(['HEAD', '--', file])\n synced.push(file)\n } catch {\n skipped.push(file)\n }\n } else {\n // File was deleted in new HEAD — remove from working tree\n try {\n const filePath = join(projectRoot, file)\n await removeFile(filePath, { force: true })\n synced.push(file)\n } catch {\n skipped.push(file)\n }\n }\n }\n\n const warning = skipped.length > 0\n ? `${skipped.length} file(s) skipped due to local changes: ${skipped.join(', ')}. Commit your changes, then run: git checkout HEAD -- ${skipped.join(' ')}`\n : undefined\n\n return { synced, skipped, warning }\n}\n\nexport async function createTransaction(\n projectRoot: string,\n branchName: string,\n options?: { workflowOverride?: WorkflowMode },\n): Promise<GitTransaction> {\n const git = simpleGit(projectRoot)\n const config = await readConfig(projectRoot)\n const workflow = options?.workflowOverride ?? config?.workflow ?? 'auto-merge'\n\n const remoteName = process.env['CONTENTRAIN_REMOTE'] ?? 'origin'\n\n // Detect base branch + current branch + remote in ONE batch\n // (reduces subprocess spawns from 4 to 2)\n let baseBranch = process.env['CONTENTRAIN_BRANCH'] ?? config?.repository?.default_branch ?? ''\n let currentBranch = ''\n let hasRemote = false\n\n const [branchResult, remotes] = await Promise.all([\n git.raw(['branch', '--show-current']).catch(() => ''),\n git.getRemotes().catch(() => []),\n ])\n currentBranch = branchResult.trim()\n if (!baseBranch) baseBranch = currentBranch || 'main'\n hasRemote = (remotes as { name: string }[]).some(r => r.name === remoteName)\n\n // Check if developer is on contentrain branch\n if (currentBranch === CONTENTRAIN_BRANCH) {\n throw Object.assign(new Error(\n `The '${CONTENTRAIN_BRANCH}' branch is checked out in your working directory. `\n + `Contentrain manages this branch automatically. `\n + `Switch to your working branch and retry.`,\n ), {\n code: 'CONTENT_BRANCH_CHECKED_OUT',\n agent_hint: 'Ask the developer to switch to their working branch (e.g., main or a feature branch), then retry the operation.',\n developer_action: `git checkout ${baseBranch}`,\n })\n }\n\n // Ensure contentrain branch exists (with migration for old contentrain/* branches)\n await ensureContentBranch(projectRoot)\n\n // Fetch latest from remote (parallel fetch for both branches)\n if (hasRemote) {\n await Promise.all([\n git.fetch(remoteName, baseBranch).catch(() => {}),\n git.fetch(remoteName, CONTENTRAIN_BRANCH).catch(() => {}),\n ])\n }\n\n const worktreePath = join(tmpdir(), `cr-${randomUUID()}`)\n const branch = branchName\n\n // Create worktree on contentrain branch\n await git.raw(['worktree', 'add', worktreePath, CONTENTRAIN_BRANCH])\n\n const wtGit = simpleGit(worktreePath)\n\n // Configure author (sequential — git config uses lock file)\n const authorName = process.env['CONTENTRAIN_AUTHOR_NAME'] ?? 'Contentrain'\n const authorEmail = process.env['CONTENTRAIN_AUTHOR_EMAIL'] ?? 'mcp@contentrain.io'\n await wtGit.addConfig('user.name', authorName)\n await wtGit.addConfig('user.email', authorEmail)\n\n // Sync contentrain with base branch (bring main changes into contentrain)\n try {\n await wtGit.merge([baseBranch, '--no-edit'])\n } catch {\n try { await wtGit.merge(['--abort']) } catch { /* not in merge state */ }\n if (hasRemote) {\n try {\n await wtGit.merge([`${remoteName}/${baseBranch}`, '--no-edit'])\n } catch {\n try { await wtGit.merge(['--abort']) } catch { /* ignore */ }\n }\n }\n }\n\n // Sync with remote contentrain if exists\n if (hasRemote) {\n try {\n await wtGit.merge([`${remoteName}/${CONTENTRAIN_BRANCH}`, '--no-edit'])\n } catch {\n try { await wtGit.merge(['--abort']) } catch { /* ignore */ }\n }\n }\n\n // Create feature branch from contentrain\n await wtGit.checkout(['-b', branch])\n\n let commitHash = ''\n let pendingReview = false\n let savedContextUpdate: ContextUpdate | undefined\n\n return {\n worktree: worktreePath,\n branch,\n\n async write(callback) {\n await callback(worktreePath)\n },\n\n async commit(message, contextUpdate?) {\n // context.json is intentionally NOT committed on the feature branch — it\n // is regenerated on the contentrain branch after the merge (see\n // complete()). Committing it per-branch caused cross-branch merge\n // conflicts on a single mutable file. `--no-verify` keeps the repo's\n // commit-msg / pre-commit hooks (commitlint, lefthook, husky) from\n // rejecting these machine-generated infra commits.\n savedContextUpdate = contextUpdate\n await wtGit.add('.')\n const result = await wtGit.commit(message, { '--allow-empty': null, '--no-verify': null })\n commitHash = result.commit || ''\n return commitHash\n },\n\n async complete() {\n if (workflow === 'review') {\n if (hasRemote) {\n await git.push(remoteName, branch)\n }\n // Pending-review branches must survive for a later contentrain_merge.\n pendingReview = true\n return { action: 'pending-review', commit: commitHash }\n }\n\n // auto-merge: merge feature branch into contentrain, then advance base\n\n // Switch to contentrain branch in worktree\n await wtGit.checkout(CONTENTRAIN_BRANCH)\n\n // Merge feature branch into contentrain\n try {\n await wtGit.merge([branch, '--no-edit'])\n } catch {\n try {\n await wtGit.merge(['--abort'])\n } catch { /* not in merge state */ }\n throw Object.assign(new Error(\n `Merge conflict when merging branch \"${branch}\" into \"${CONTENTRAIN_BRANCH}\". `\n + `The branch still exists with your changes intact. `\n + `Resolve the conflict manually, or delete the branch and retry.`,\n ), {\n code: 'CONTENT_BRANCH_MERGE_CONFLICT',\n agent_hint: 'The feature branch could not be merged into the contentrain branch. Ask the developer to resolve the conflict.',\n developer_action: `git checkout ${CONTENTRAIN_BRANCH} && git merge ${branch}`,\n })\n }\n\n // Regenerate context.json on the contentrain branch (post-merge,\n // single-threaded) and fold it into the tip before advancing the base.\n if (savedContextUpdate) {\n await regenerateContextOnContentrain(wtGit, worktreePath, savedContextUpdate)\n }\n\n // Get contentrain tip + old base ref + dirty files in parallel\n const [contentrainTip, previousBaseRef, statusBeforeUpdate] = await Promise.all([\n wtGit.raw(['rev-parse', 'HEAD']).then(s => s.trim()),\n git.raw(['rev-parse', baseBranch]).then(s => s.trim()),\n git.status(),\n ])\n const dirtyFilesBeforeUpdate = new Set(statusBeforeUpdate.files.map(f => f.path))\n\n // Verify fast-forward: baseBranch must be an ancestor of contentrainTip\n // (guaranteed by the merge above, but verify for safety)\n try {\n await git.raw(['merge-base', '--is-ancestor', previousBaseRef, contentrainTip])\n } catch {\n throw Object.assign(new Error(\n `Cannot fast-forward \"${baseBranch}\" to contentrain tip. `\n + `The base branch has diverged. Merge \"${baseBranch}\" into \"${CONTENTRAIN_BRANCH}\" first.`,\n ), {\n code: 'BASE_UPDATE_FAILED',\n agent_hint: `The base branch has commits not in contentrain. Merge ${baseBranch} into ${CONTENTRAIN_BRANCH} first.`,\n developer_action: `git checkout ${CONTENTRAIN_BRANCH} && git merge ${baseBranch} && git checkout ${baseBranch}`,\n })\n }\n\n // Advance base branch to contentrain tip via update-ref\n await git.raw(['update-ref', `refs/heads/${baseBranch}`, contentrainTip])\n\n // Refresh index to match new HEAD.\n // update-ref moves the branch pointer but leaves the index stale.\n // read-tree updates the index to match HEAD without touching the working tree.\n try {\n await git.raw(['read-tree', 'HEAD'])\n } catch {\n // fallback: try reset for older git versions\n try { await git.raw(['reset', 'HEAD']) } catch { /* ignore */ }\n }\n\n // Selective sync: copy .contentrain/ files to developer's working tree\n const sync = await selectiveSync(projectRoot, worktreePath, contentrainTip, previousBaseRef, dirtyFilesBeforeUpdate)\n\n // Push to remote (best-effort with retry)\n if (hasRemote) {\n // Push contentrain branch\n try {\n await git.push(remoteName, CONTENTRAIN_BRANCH)\n } catch {\n // Retry: fetch, merge, push\n try {\n await wtGit.fetch(remoteName, CONTENTRAIN_BRANCH)\n await wtGit.merge([`${remoteName}/${CONTENTRAIN_BRANCH}`, '--no-edit'])\n await git.push(remoteName, CONTENTRAIN_BRANCH)\n } catch {\n // Push failed after retry — continue, local state is fine\n }\n }\n\n // Push base branch\n try {\n await git.push(remoteName, baseBranch)\n } catch {\n // push may fail, local merge succeeded\n }\n }\n\n return {\n action: 'auto-merged' as const,\n commit: commitHash,\n sync,\n ...(sync.warning ? { warning: sync.warning } : {}),\n }\n },\n\n async cleanup() {\n try {\n await git.raw(['worktree', 'remove', worktreePath, '--force'])\n } catch {\n // worktree may already be cleaned up\n }\n // Prune the feature branch unless it is a pending-review branch that must\n // survive for a later contentrain_merge. Auto-merged branches (already in\n // contentrain) and failed/empty branches are both safe to delete, so\n // failed saves and merged saves no longer leak dangling cr/* refs.\n if (!pendingReview) {\n await safeDeleteBranch(git, branch)\n }\n },\n }\n}\n\nexport async function mergeBranch(\n projectRoot: string,\n branchName: string,\n): Promise<{ action: 'merged'; commit: string; sync: SyncResult }> {\n const git = simpleGit(projectRoot)\n const config = await readConfig(projectRoot)\n const remoteName = process.env['CONTENTRAIN_REMOTE'] ?? 'origin'\n\n // Detect base branch\n const baseBranch = process.env['CONTENTRAIN_BRANCH']\n ?? config?.repository?.default_branch\n ?? ((await git.raw(['branch', '--show-current'])).trim() || 'main')\n\n // Ensure contentrain branch exists\n await ensureContentBranch(projectRoot)\n\n // Check remote\n let hasRemote = false\n try {\n const remotes = await git.getRemotes()\n hasRemote = remotes.some(r => r.name === remoteName)\n } catch {\n hasRemote = false\n }\n\n // Create temp worktree on contentrain branch\n const worktreePath = join(tmpdir(), `cr-merge-${randomUUID()}`)\n await git.raw(['worktree', 'add', worktreePath, CONTENTRAIN_BRANCH])\n\n const wtGit = simpleGit(worktreePath)\n\n // Configure author\n const authorName = process.env['CONTENTRAIN_AUTHOR_NAME'] ?? 'Contentrain'\n const authorEmail = process.env['CONTENTRAIN_AUTHOR_EMAIL'] ?? 'mcp@contentrain.io'\n await wtGit.addConfig('user.name', authorName)\n await wtGit.addConfig('user.email', authorEmail)\n\n try {\n // Merge the feature branch into contentrain\n try {\n await wtGit.merge([branchName, '--no-edit'])\n } catch {\n try { await wtGit.merge(['--abort']) } catch { /* not in merge state */ }\n throw Object.assign(new Error(\n `Merge conflict when merging branch \"${branchName}\" into \"${CONTENTRAIN_BRANCH}\". `\n + `The branch still exists with your changes intact. `\n + `Resolve the conflict manually, or delete the branch and retry.`,\n ), {\n code: 'CONTENT_BRANCH_MERGE_CONFLICT',\n agent_hint: 'The feature branch could not be merged into the contentrain branch. Ask the developer to resolve the conflict.',\n developer_action: `git checkout ${CONTENTRAIN_BRANCH} && git merge ${branchName}`,\n })\n }\n\n // Regenerate context.json on contentrain post-merge (deterministic,\n // single-threaded) so review-mode branches — which carry no context.json —\n // still produce up-to-date stats once landed.\n await regenerateContextOnContentrain(wtGit, worktreePath, { tool: 'contentrain_merge', model: '*' })\n\n // Get contentrain tip + old base ref + dirty files in parallel\n const [contentrainTip, previousBaseRef, statusBeforeUpdate] = await Promise.all([\n wtGit.raw(['rev-parse', 'HEAD']).then(s => s.trim()),\n git.raw(['rev-parse', baseBranch]).then(s => s.trim()),\n git.status(),\n ])\n const dirtyFilesBeforeUpdate = new Set(statusBeforeUpdate.files.map(f => f.path))\n\n // Verify fast-forward: baseBranch must be an ancestor of contentrainTip\n try {\n await git.raw(['merge-base', '--is-ancestor', previousBaseRef, contentrainTip])\n } catch {\n throw Object.assign(new Error(\n `Cannot fast-forward \"${baseBranch}\" to contentrain tip. `\n + `The base branch has diverged. Merge \"${baseBranch}\" into \"${CONTENTRAIN_BRANCH}\" first.`,\n ), {\n code: 'BASE_UPDATE_FAILED',\n agent_hint: `The base branch has commits not in contentrain. Merge ${baseBranch} into ${CONTENTRAIN_BRANCH} first.`,\n developer_action: `git checkout ${CONTENTRAIN_BRANCH} && git merge ${baseBranch} && git checkout ${baseBranch}`,\n })\n }\n\n // Advance base branch to contentrain tip via update-ref\n await git.raw(['update-ref', `refs/heads/${baseBranch}`, contentrainTip])\n\n // Refresh index to match new HEAD\n try {\n await git.raw(['read-tree', 'HEAD'])\n } catch {\n try { await git.raw(['reset', 'HEAD']) } catch { /* ignore */ }\n }\n\n // Selective sync: copy .contentrain/ files to developer's working tree\n const sync = await selectiveSync(projectRoot, worktreePath, contentrainTip, previousBaseRef, dirtyFilesBeforeUpdate)\n\n // Push to remote (best-effort)\n if (hasRemote) {\n try {\n await git.push(remoteName, CONTENTRAIN_BRANCH)\n } catch {\n try {\n await wtGit.fetch(remoteName, CONTENTRAIN_BRANCH)\n await wtGit.merge([`${remoteName}/${CONTENTRAIN_BRANCH}`, '--no-edit'])\n await git.push(remoteName, CONTENTRAIN_BRANCH)\n } catch {\n // Push failed after retry — continue, local state is fine\n }\n }\n\n try {\n await git.push(remoteName, baseBranch)\n } catch {\n // push may fail, local merge succeeded\n }\n }\n\n // Prune the now-merged feature branch so merged cr/* refs don't accumulate.\n await safeDeleteBranch(git, branchName)\n\n return {\n action: 'merged' as const,\n commit: contentrainTip,\n sync,\n }\n } finally {\n // Cleanup worktree\n try {\n await git.raw(['worktree', 'remove', worktreePath, '--force'])\n } catch {\n // worktree may already be cleaned up\n }\n }\n}\n\nexport function buildBranchName(scope: string, target: string, locale?: string): string {\n const ts = branchTimestamp()\n const parts = ['cr', scope, target]\n if (locale) parts.push(locale)\n parts.push(ts)\n return parts.join('/')\n}\n\n/**\n * Force-delete a local branch, swallowing all errors. Never deletes the\n * singleton `contentrain` branch. Used to prune feature branches after they\n * are merged (auto-merge / contentrain_merge) or when a transaction fails\n * before completing — so failed/merged `cr/*` refs do not accumulate.\n */\nasync function safeDeleteBranch(git: SimpleGit, branch: string): Promise<void> {\n if (!branch || branch === CONTENTRAIN_BRANCH) return\n try {\n await git.raw(['branch', '-D', branch])\n } catch {\n // Branch may not exist, be checked out, or already be deleted — ignore.\n }\n}\n\n/**\n * Regenerate `.contentrain/context.json` deterministically inside a worktree\n * that is currently on the `contentrain` branch, then commit it (hooks\n * bypassed). Called AFTER a feature branch is merged so context.json is only\n * ever written on `contentrain`, single-threaded — eliminating the per-branch\n * merge conflicts that came from committing it on every feature branch.\n */\nasync function regenerateContextOnContentrain(\n wtGit: SimpleGit,\n worktreePath: string,\n contextUpdate: ContextUpdate,\n): Promise<void> {\n await writeContext(worktreePath, contextUpdate)\n await wtGit.add('.contentrain/context.json')\n try {\n await wtGit.commit('[contentrain] context: update', { '--no-verify': null })\n } catch {\n // Nothing staged (context.json unchanged) — fine.\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,eAAsB,sBACpB,KACA,YACiB;AAGjB,MAFiB,MAAM,IAAI,aAAa,EACL,IAAI,QAAO,MAAK,EAAE,WAAW,eAAe,CAAC,CAC1D,WAAW,EAAG,QAAO;CAE3C,IAAI,UAAU;CAGd,IAAI,eAAyB,EAAE;AAC/B,KAAI;AAEF,kBADqB,MAAM,IAAI,IAAI;GAAC;GAAU;GAAY;GAAW,CAAC,EAC1C,MAAM,KAAK,CACpC,KAAI,MAAK,EAAE,MAAM,CAAC,QAAQ,UAAU,GAAG,CAAC,CACxC,QAAO,MAAK,EAAE,WAAW,eAAe,CAAC;SACtC;AAIR,MAAK,MAAM,KAAK,aACd,KAAI;AACF,QAAM,IAAI,IAAI;GAAC;GAAU;GAAM;GAAE,CAAC;AAClC;SACM;CAMV,MAAM,aAAa,MAAM,IAAI,aAAa,EAAE,IAAI,QAAO,MAAK,EAAE,WAAW,eAAe,CAAC;AACzF,MAAK,MAAM,KAAK,UACd,KAAI;AACF,QAAM,IAAI,IAAI;GAAC;GAAU;GAAM;GAAE,CAAC;AAClC;SACM;AAKV,QAAO;;;;ACrCT,eAAsB,oBAAoB,aAAoC;CAC5E,MAAM,MAAM,UAAU,YAAY;CAClC,MAAM,SAAS,MAAM,WAAW,YAAY;AAI5C,MADiB,MAAM,IAAI,aAAa,EAC3B,IAAI,SAAS,mBAAmB,CAAE;CAG/C,MAAM,aAAa,QAAQ,YAAY,mBACjC,MAA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