contentrain

中文文档
0.18.26发布于 2026/11/03MITES Module构建来源已验证

CLI for Contentrain — the content governance ecosystem for teams and AI agents

原始使用文档
文档目录20 节
  1. Install
  2. Global Flags
  3. Commands
  4. Flag Matrix
  5. Typical Flow
  6. serve Modes
  7. Local review UI (default)
  8. MCP stdio (IDE agents)
  9. MCP HTTP (Studio, CI, remote drivers)
  10. generate and #contentrain
  11. IDE Setup and AI Skills
  12. Review Workflow
  13. Studio Integration
  14. contentrain import
  15. contentrain delta
  16. Public static builds
  17. Documentation
  18. Development
  19. Part of the Contentrain ecosystem
  20. License

contentrain

npm version GitHub source Docs

CLI for Contentrain.

Start here:

contentrain is the local operations surface for a Contentrain project:

  • initialize .contentrain/ in an existing repo
  • inspect project health and validation state
  • generate the typed #contentrain SDK client
  • review pending cr/* branches
  • run the local review UI
  • expose the MCP server over stdio (IDE agents) or HTTP (Studio, CI, remote drivers)

This package is the human-facing companion to:

Install

Use npx:

npx contentrain init

Or install globally:

pnpm add -g contentrain
contentrain status

Requirements:

  • Node.js 22+
  • Git available in PATH

Global Flags

FlagEnv varDescription
--debugCONTENTRAIN_DEBUG=1Verbose debug logging to stderr (works on every subcommand)

Example: contentrain --debug status or CONTENTRAIN_DEBUG=1 contentrain validate.

Commands

CommandPurpose
contentrain initInitialize .contentrain/, git workflow, templates, and IDE rules
contentrain import <source>Import a WordPress site (WXR export file or REST URL) into a .contentrain store
contentrain statusShow project overview, models, branch pressure, and validation summary
contentrain doctorCheck setup health, SDK freshness, orphan content, and branch limits
contentrain validateValidate content against schemas, optionally create review-branch fixes
contentrain generateGenerate .contentrain/client/ and #contentrain package imports
contentrain diffReview and merge or reject pending cr/* branches interactively
contentrain merge <branch>Merge one pending cr/* branch non-interactively (CI/agents); deletes its remote copy
contentrain reconcileContent-aware three-way merge of a diverged contentrain ↔ base pair (dry-run plan, interactive decisions)
contentrain pruneDelete merged cr/* branches locally and on the remote (backlog drain)
contentrain describe <model>Inspect a model's schema, stats, and import snippet
contentrain delta <delta.json> --dry-runPlan a WordPress source delta against the store: placement, field changes, conflicts, tombstones, redirects (plan only)
contentrain describe-formatPrint the Contentrain content-format specification
contentrain scaffold --templateApply a template (blog, landing, docs, ecommerce, saas, i18n, mobile)
contentrain setup <agent|--all>Configure MCP server + AI rules for IDE (Claude Code, Cursor, Windsurf, VSCode, Copilot, Codex)
contentrain skillsInstall, update, or list Contentrain AI skills and IDE rules
contentrain serveStart the local review UI (REST + WS), MCP stdio server (--stdio), or MCP HTTP server (--mcpHttp)
contentrain studio connectConnect a repository to a Studio project
contentrain studio loginAuthenticate with Contentrain Studio
contentrain studio logoutLog out from Studio
contentrain studio whoamiShow current authentication status
contentrain studio statusShow project overview from Studio
contentrain studio activityShow recent activity feed
contentrain studio usageShow workspace usage metrics
contentrain studio branchesManage remote content branches
contentrain studio cdn-initSet up CDN for content delivery
contentrain studio cdn-buildTrigger a CDN rebuild
contentrain studio webhooksManage webhooks
contentrain studio submissionsManage form submissions

Flag Matrix

Every read command supports --json for CI use; write commands surface --watch or --yes where they apply:

CommandNotable flags
init--yes, --locales <csv> (default en), --domains <csv> (default marketing,blog,system)
import--out <dir>, --auth <user>, --force, --include-emails, --json
status--json
doctor--json, --usage — non-zero exit on failure; includes a remote cr/* branch check
validate--json, --fix, --interactive, --watch, --model <id>
generate--json, --watch, --published, --at <ISO timestamp>, --require-status, --mediaBaseUrl <url>
diff--json
merge--yes (skip confirm)
reconcile--yes (execute a clean plan without prompting), --json (dry-run plan)
prune--dry-run, --yes, --json (mutates only with --yes)
delta--dry-run (required; there is no apply mode), --incoming <dir>, --store <dir>, --taxonomy <csv>, --json
describe--sample, --locale, --json
describe-format--json
scaffold--template <id>, --locales <csv>, --no-sample, --json
serve--port (default 3333), --host (default localhost), --no-open, --demo, --stdio, --mcpHttp, --authToken

Typical Flow

Initialize a project:

contentrain init

Check project state (with optional JSON for CI):

contentrain status
contentrain status --json

contentrain doctor
contentrain doctor --json
contentrain doctor --usage  # Analyze content key usage

Generate the typed SDK client:

contentrain generate
contentrain generate --watch    # Watch for changes
contentrain generate --json     # CI-friendly JSON output

Validate content and create review-branch fixes:

contentrain validate
contentrain validate --fix
contentrain validate --watch    # Live validation in dev mode
contentrain validate --json     # CI output

Review pending changes:

contentrain diff
contentrain diff --json  # CI integration

Open the local UI:

contentrain serve
contentrain serve --demo  # Start with a temporary demo project

Enable detailed logging:

contentrain --debug status
CONTENTRAIN_DEBUG=1 contentrain validate  # Via environment variable

serve Modes

contentrain serve has three roles.

Local review UI (default)

contentrain serve
contentrain serve --port 3333 --host localhost
contentrain serve --demo  # Temporary project (no setup needed)

Serves REST endpoints for status / content / validation / branches / normalize / doctor / describe-format / preview-merge, a WebSocket stream for live updates, and the embedded Vue serve-ui app bundled with the CLI.

WebSocket event types: connected, config:changed, context:changed, meta:changed, model:changed, content:changed, branch:created, branch:merged, branch:rejected, branch:merge-conflict, sync:warning, validation:updated, normalize:plan-updated, file-watch:error.

MCP stdio (IDE agents)

contentrain serve --stdio

Use stdio mode when connecting Claude Code, Cursor, Windsurf, or another MCP client to the local project.

MCP HTTP (Studio, CI, remote drivers)

contentrain serve --mcpHttp --authToken $(openssl rand -hex 32)
contentrain serve --mcpHttp --port 3333 --host 0.0.0.0 --authToken $TOKEN

Spins up a Streamable HTTP MCP server at POST /mcp. Bearer auth is required on non-loopback binds: like the review UI, the CLI refuses to start on any host other than localhost / 127.0.0.1 / ::1 without --authToken (or CONTENTRAIN_AUTH_TOKEN). Use HTTP mode when:

  • Studio's agent drives MCP remotely
  • a CI runner needs deterministic content operations
  • an agent on another machine orchestrates content changes

HTTP sessions use the same LocalProvider backing as stdio — the transport differs, the behaviour does not. Remote git-host providers (GitHubProvider, GitLabProvider) are constructed by embedders who instantiate the MCP server programmatically; see the MCP package docs for that flow.

To let external agents operate a connected Studio project without running a server yourself, use the hosted endpoint, Studio MCP Cloud.

generate and #contentrain

contentrain generate writes a typed client to .contentrain/client/ and injects #contentrain imports into your package.json.

After generation:

import { query, singleton, dictionary, document } from '#contentrain'

Run with watch mode during local model/content work:

contentrain generate --watch

IDE Setup and AI Skills

Configure your IDE to use Contentrain's MCP server and AI agent rules:

contentrain setup claude-code
contentrain setup cursor
contentrain setup vscode
contentrain setup --all  # Configure all detected IDEs

Install or update AI agent skills and IDE rules:

contentrain skills
contentrain skills --update  # Force update
contentrain skills --list    # List installed skills

This installs:

  • Contentrain Agent Skills (task guidance for Claude, Cursor, etc.)
  • IDE rules files: .claude/rules/, .cursor/rules/, .windsurf/rules/, .github/copilot-instructions.md, and AGENTS.md for Codex

Review Workflow

Most write operations create feature branches from the dedicated contentrain branch. In review mode, these branches are pushed to remote for team review. In auto-merge mode, they are merged into the contentrain branch and baseBranch is advanced via update-ref.

When baseBranch has diverged (commits contentrain lacks — the state a dual-domain migration PR leaves behind), a write is a partial success: it lands on contentrain and reports base_advance: "blocked_diverged" instead of failing. contentrain status shows the relation in both directions; contentrain reconcile merges the branches content-aware (a two-parent merge commit) so the fast-forward advance works again.

Merging a review branch (via contentrain merge, contentrain diff, the Serve UI, or the MCP tools) also deletes its remote copy, so merged branches never pile up as phantom pending reviews. The same applies to rejected/deleted drafts. This is best-effort — an offline or permission failure only produces a warning — and can be disabled with remoteBranchCleanup: false in config.json. In local mode ("git": { "push": false } in config.json, or CONTENTRAIN_NO_PUSH=1) nothing is pushed or deleted on the remote, and merge/prune print that they skipped it. Note that deleting a pushed branch closes any open PR/MR on it.

Use:

contentrain status
contentrain diff
contentrain prune --dry-run   # preview merged local/remote leftovers, then run with --yes

to understand:

  • how many active cr/* review branches exist on the contentrain branch (and on the remote — contentrain doctor)
  • whether branch health is blocking new writes (warning at 50, blocked at 80)
  • what changed before merging or deleting a branch

Studio Integration

The studio command group connects the CLI to Contentrain Studio, the team operating surface for governed content.

Authenticate and connect:

contentrain studio login
contentrain studio whoami
contentrain studio connect

The connect command links your local repository to a Studio project. It detects the git remote, verifies GitHub App installation, scans for .contentrain/ configuration, and creates the project — all in one interactive flow.

contentrain studio connect --workspace ws-123

Set up CDN for content delivery:

contentrain studio cdn-init
contentrain studio cdn-build --wait

Monitor project activity and usage:

contentrain studio status
contentrain studio activity --limit 10
contentrain studio usage

Manage branches, webhooks, and form submissions:

contentrain studio branches
contentrain studio webhooks
contentrain studio submissions --form contact-form

Credentials are stored securely in ~/.contentrain/credentials.json with 0o600 permissions. Use CONTENTRAIN_STUDIO_TOKEN environment variable for CI/CD.

contentrain import

Import a WordPress site into a .contentrain content store:

contentrain import export.xml            # WXR export file (highest offline fidelity)
contentrain import https://site.example  # public REST
contentrain import https://site.example --auth editor  # authenticated REST: prompts for the Application Password
CONTENTRAIN_WP_APP_PASSWORD=… contentrain import https://site.example --auth editor
CONTENTRAIN_WP_AUTH=editor:… contentrain import https://site.example
contentrain import export.xml --include-emails  # also write author/commenter e-mails

Writes the canonical store plus import-report.json, entry-source-map.json (WP id → entry address), and — when the source has comments — comments-export.json (contentrain-comments@1, ready for a comments-service intake). An existing .contentrain is only overwritten with --force. Powered by @contentrain/wp-import.

Personal data. The store holds author names and logins, and commenters' names, website URLs and comment text. A WXR export also carries author and commenter e-mail addresses; they are left out of the store and of comments-export.json unless you pass --include-emails. Commenter IPs, user agents and avatar URLs (including Akismet's comment meta) are never written. The e-mails stay out by default because the store usually ends up in git (sometimes a public repo). The REST path never sees them.

Credentials. The Application Password is read from CONTENTRAIN_WP_APP_PASSWORD (with --auth <user>), from CONTENTRAIN_WP_AUTH=user:password, or from a hidden prompt. --auth user:password still works but is deprecated and warns: argv lands in shell history and process listings.

contentrain delta

Plan what a later WordPress change means for a store that was already delivered:

contentrain delta bridge-delta.json --incoming ./next-export --dry-run         # report
contentrain delta bridge-delta.json --incoming ./next-export --dry-run --json  # the planned SourceDeltaPlan

The command reads the store (--store, default: the current directory) and its entry-source-map.json, from the store root or from bridge/. It reads the new export the same way. For each record it reports where it lives in the store, which fields differ, and which addresses moved (each becomes a 301). Trashed and purged deletions are kept apart. A record that was also edited in the repository is a conflict, and it is not overwritten. There is no apply mode: without --dry-run the command refuses, because applying a plan goes through review. Taxonomies come from the bridge's inventory.json when it is beside the export; name others with --taxonomy.

Public static builds

contentrain generate --published excludes drafts and content outside its publish_at/expire_at window. --at 2026-10-01T12:00:00Z fixes the public build clock for reproducible tests and implies --published. --require-status also excludes entries with no status in meta, for projects where every entry has one (a WordPress import); it implies --published. Without these flags, editorial generation keeps its existing behavior. Watch mode observes metadata edits; a scheduled static publication still needs a build/deploy trigger.

Documentation

Full documentation at ai.contentrain.io/packages/cli.

Development

From the monorepo root:

pnpm --filter contentrain test -- --run
pnpm --filter contentrain exec tsc --noEmit
pnpm --filter contentrain build

Part of the Contentrain ecosystem

Contentrain is a content governance ecosystem for teams and AI agents; agents work on the content through the MCP server. This CLI is one of the open-source tools (docs). Studio adds team review and roles on the same repository, Migrate moves WordPress sites to Astro, and Bridge is a free WordPress plugin that exports a site as a Contentrain store.

License

MIT

版本与发布记录

contentrain 共发布 147 个版本,首次发布于 2026/03/17;过去 12 个月发布了 147 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.18.26latest2026/11/03今天
0.18.252026/11/02今天
0.18.242026/10/312 天前
0.18.232026/10/313 天前
0.18.222026/10/313 天前
0.18.212026/10/303 天前

关于 contentrain 的常见问题

contentrain 是什么?

CLI for contenttrain——团队和AI代理的内容治理生态系统

如何安装 contentrain?

在项目目录运行 npm install contentrain,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 contentrain,可以用 npx contentrain 直接运行。

contentrain 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/contentrain 是否存在。

contentrain 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

contentrain 可以商用吗?

contentrain 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

contentrain 还在维护吗?

最新版本 0.18.26 发布于 2026/11/03(今天);至今共发布 147 个版本,其中过去 12 个月发布了 147 个;首次发布于 2026/03/17。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。