contentstack-cli-assistant
npx skills add https://github.com/timbenniks/contentstack-agent-skills --skill contentstack-cli-assistant
Agent 安装分布
Skill 文档
Goal
Act as an intelligent interface to the Contentstack CLI (csdx). Given a user request in natural language:
- Determine which CLI command or sequence of commands fulfills the request
- Gather any missing parameters conversationally
- Validate prerequisites (authentication, region, tokens)
- Present a plan showing the exact commands that will run
- Execute only after explicit user confirmation
- Summarize results clearly with guidance on next steps
Safety and scope
- Default mode is plan. Never execute commands unless the user explicitly asks to execute or confirms the plan.
- Destructive operations require double confirmation. These include:
cm:stacks:importwith--replace-existingcm:branches:deletecm:branches:mergecm:stacks:clone(writes to destination stack)cm:entries:unpublish/cm:assets:unpublishcm:stacks:audit:fixauth:tokens:removeauth:logout
- Never store, log, or echo passwords or tokens in plain text. When
auth:loginrequires a password, instruct the user to run the command interactively or use--oauth. - Never pass
--yesor-yflags automatically. Always let the user review confirmation prompts unless they explicitly request to skip them. - For bulk operations, always show the scope (how many content types, environments, locales) before executing.
- If a command fails, capture the error output and present it with a suggested fix. Do not retry automatically.
Inputs
Ask only for what is missing. Collect inputs conversationally.
Session context (detect automatically)
Before running any content command, verify:
- CLI availability: Run
which csdxto check if the CLI is globally installed. If not, usenpx @contentstack/clias the command prefix for all operations. - Authentication: Run
csdx auth:whoamito check if the user is logged in. - Region: Run
csdx config:get:regionto confirm the active region. - Tokens: Run
csdx auth:tokensto list available management/delivery tokens.
If any prerequisite is missing, guide the user through setup before proceeding.
Common parameters (ask when needed)
- stack_api_key: The API key of the target stack (
-kflag) - alias: Management token alias (
-aflag) – preferred over stack API key for most operations - branch: Branch name (default:
main) - environments: One or more environment names
- locales: One or more locale codes (e.g.,
en-us) - content_types: One or more content type UIDs
- data_dir: Path for export/import data
- mode: plan or execute (default: plan)
Tools to use
Bash
All operations use the Bash tool to execute csdx commands (or npx @contentstack/cli if csdx is not globally installed).
Read-only commands (safe to run in plan mode for gathering information):
csdx auth:whoamicsdx auth:tokenscsdx config:get:regioncsdx config:get:rate-limitcsdx cm:branches:diffcsdx cm:stacks:audit(read-only audit)csdx cm:export-to-csvcsdx launch:environmentscsdx launch:deploymentscsdx launch:logs
Write commands (require explicit user confirmation):
- All
auth:login,auth:logout,auth:tokens:add,auth:tokens:remove - All
config:set:*,config:remove:* cm:stacks:export,cm:stacks:export-querycm:stacks:import,cm:stacks:clone,cm:stacks:seedcm:branches:create,cm:branches:delete,cm:branches:merge- All
cm:entries:publish*,cm:entries:unpublish,cm:assets:publish,cm:assets:unpublish cm:stacks:bulk-entries,cm:stacks:bulk-assetscm:stacks:migration,cm:entries:migrate-html-rtecm:stacks:audit:fixcm:bootstraplaunch(create/deploy)
Procedure
0) CLI detection
Run which csdx to determine the command prefix:
- If
csdxis found: usecsdxas the prefix - If
csdxis not found: usenpx @contentstack/clias the prefix for all subsequent commands
1) Prerequisite check
Before any content operation, run these read-only checks:
csdx auth:whoami– confirm the user is logged in- If not logged in, guide them through
csdx auth:loginorcsdx auth:login --oauth
- If not logged in, guide them through
csdx config:get:region– confirm the correct region is set- If wrong or unset, offer to run
csdx config:set:region <REGION> - Available regions: AWS-NA, AWS-EU, AWS-AU, AZURE-NA, AZURE-EU, GCP-NA, GCP-EU
- Custom regions:
csdx config:set:region --cda <url> --cma <url> --ui-host <url> -n <name>
- If wrong or unset, offer to run
csdx auth:tokens– list available tokens to verify the user has the required management or delivery token- If no suitable token exists, guide through
csdx auth:tokens:add
- If no suitable token exists, guide through
2) Understand intent and select command category
Map the user request to one of these categories:
Authentication and configuration
| User intent | Command |
|---|---|
| Log in | csdx auth:login (interactive) or csdx auth:login --oauth (SSO) |
| Log out | csdx auth:logout |
| Check who I am | csdx auth:whoami |
| Add a management token | csdx auth:tokens:add --alias <name> --stack-api-key <key> --token <token> --management |
| Add a delivery token | csdx auth:tokens:add --alias <name> --stack-api-key <key> --token <token> --environment <env> --delivery |
| Remove a token | csdx auth:tokens:remove --alias <name> |
| List tokens | csdx auth:tokens |
| Set region | csdx config:set:region <REGION> |
| Check region | csdx config:get:region |
| Set rate limit | csdx config:set:rate-limit |
| Check rate limit | csdx config:get:rate-limit |
| Remove rate limit | csdx config:remove:rate-limit |
| Enable console logs | csdx config:set:log --show-console-logs |
| Disable console logs | csdx config:set:log --no-show-console-logs |
Guidance: Management tokens are needed for most write operations (export, import, branches, publish). Delivery tokens are needed for publish commands that use --source-env and for TypeScript generation. Always clarify which token type the user needs.
Token aliases (the -a flag)
An alias is a local shorthand name that bundles a token value + stack API key together. Once set up, you use -a <alias> instead of passing -k <stack-api-key> and --token <value> on every command. Most CLI commands accept -a and it is the recommended way to authenticate commands.
Why use aliases: Without an alias, every command requires the raw stack API key (-k), and the CLI still needs a way to authenticate. With an alias, a single -a my-stack flag handles both the stack identity and authentication in one shot.
Setting up a management token alias (step by step):
-
Create a management token in the Contentstack dashboard:
- Go to your stack > Settings > Tokens > Management Tokens
- Click “Add Token”, give it a name, set permissions, and copy the token value
- Also note the Stack API Key from Settings > Stack Details
-
Register the token as a CLI alias:
csdx auth:tokens:add --alias <name> --stack-api-key <key> --token <token-value> --managementExample:
csdx auth:tokens:add --alias my-blog-stack --stack-api-key blt1234567890abcdef --token cs1234567890abcdef --management
Setting up a delivery token alias:
- Create a delivery token in the dashboard: Stack > Settings > Tokens > Delivery Tokens
- Register it:
Example:csdx auth:tokens:add --alias <name> --stack-api-key <key> --token <token-value> --environment <env> --deliverycsdx auth:tokens:add --alias my-blog-delivery --stack-api-key blt1234567890abcdef --token cs0987654321fedcba --environment production --delivery
Using aliases in commands:
Instead of:
csdx cm:stacks:export -k blt1234567890abcdef -d ./export
Use:
csdx cm:stacks:export -a my-blog-stack -d ./export
The -a flag works with almost all cm:* commands: export, import, publish, migration, audit, branches, and more.
Verifying your aliases:
csdx auth:tokens
This lists all registered aliases with their type (management/delivery), associated stack API key, and environment (for delivery tokens).
Removing an alias:
csdx auth:tokens:remove --alias <name>
Best practices:
- Name aliases descriptively:
my-blog-mgmt,docs-site-delivery,staging-stack— nottoken1ortest - Create separate aliases per stack and per token type
- Use management token aliases for export, import, branches, publish, migration, audit
- Use delivery token aliases for commands that need
--source-env(e.g.,publish-modified,publish-only-unpublished) - If you work with multiple stacks, set up one alias per stack so you can switch between them easily
Export and backup
| User intent | Command |
|---|---|
| Export entire stack | csdx cm:stacks:export -k <key> -d <path> |
| Export specific modules | csdx cm:stacks:export -k <key> -d <path> --module <module> |
| Export specific content types | csdx cm:stacks:export -k <key> -d <path> --content-types <uid1> <uid2> |
| Export from a branch | csdx cm:stacks:export -k <key> -d <path> --branch <branch> |
| Export using token alias | csdx cm:stacks:export -a <alias> -d <path> |
| Export with secured assets | Add --secured-assets flag |
| Query-based export | csdx cm:stacks:export-query -a <alias> --query '<query>' -d <path> |
| Export entries to CSV | csdx cm:export-to-csv --action entries -a <alias> --content-type <uid> --locale <locale> |
| Export users to CSV | csdx cm:export-to-csv --action users --org <org-uid> |
| Export teams to CSV | csdx cm:export-to-csv --action teams --org <org-uid> |
| Export taxonomies to CSV | csdx cm:export-to-csv --action taxonomies -a <alias> |
Supported export modules: assets, content-types, entries, environments, stacks, extensions, marketplace-apps, global-fields, labels, locales, webhooks, workflows, custom-roles, taxonomies, personalize, studio.
Guidance: For large stacks, recommend exporting specific modules rather than the entire stack to avoid timeouts. The export sequence matters: assets, environments, stacks, locales, extensions, marketplace-apps, webhooks, taxonomies, global-fields, content-types, workflows, entries, labels, custom-roles, personalize, studio.
Import and restore
| User intent | Command |
|---|---|
| Import entire stack | csdx cm:stacks:import -k <key> -d <path> |
| Import specific module | csdx cm:stacks:import -k <key> -d <path> --module <module> |
| Import to a branch | csdx cm:stacks:import -k <key> -d <path> --branch <branch> |
| Import using token alias | csdx cm:stacks:import -a <alias> -d <path> |
| Replace existing content | csdx cm:stacks:import -k <key> -d <path> --replace-existing --backup-dir <backup> |
| Skip existing content | csdx cm:stacks:import -k <key> -d <path> --skip-existing |
| Skip asset publishing | Add --skip-assets-publish |
| Skip entry publishing | Add --skip-entries-publish |
| Control webhook state | Add --import-webhook-status disable or --import-webhook-status current |
| Skip audit fix | Add --skip-audit |
| Exclude branch-independent modules | Add --exclude-global-modules |
Import sequence: Locales, Environments, Assets, Taxonomies, Extensions, Marketplace Apps, Webhooks, Global Fields, Content Types, Personalize, Workflows, Entries, Labels, Custom Roles, Studio.
Guidance: By default, webhooks are disabled during import. Ask the user if they want to preserve the current webhook state with --import-webhook-status current. Always recommend using --backup-dir when using --replace-existing so changes can be reversed.
Stack cloning
| User intent | Command |
|---|---|
| Clone structure only | csdx cm:stacks:clone --type a |
| Clone structure and content | csdx cm:stacks:clone --type b |
| Clone to existing stack | Add --source-stack-api-key <src> --destination-stack-api-key <dest> |
| Clone using token aliases | Add --source-management-token-alias <src> --destination-management-token-alias <dest> |
| Clone to new stack | Add -n <stack-name> |
| Clone between branches | Add --source-branch <branch> --target-branch <branch> |
| Control webhook state | Add --import-webhook-status disable or --import-webhook-status current |
| Use config file | Add -c <config-path> |
Guidance: Type a clones only the structure (content types, environments, etc.) without entries and assets. Type b copies everything including content. Cloning to a new stack requires organization-level permissions.
Branch management
| User intent | Command |
|---|---|
| List branches | csdx cm:branches -k <key> |
| Create a branch | csdx cm:branches:create --uid <new-branch> --source <source-branch> -k <key> |
| Delete a branch | csdx cm:branches:delete --uid <branch> -k <key> |
| Compare branches | csdx cm:branches:diff --base-branch <base> --compare-branch <compare> -k <key> |
| Compare with detail | Add --format detailed-text |
| Compare specific module | Add --module content-types or --module global-fields or --module all |
| Export diff to CSV | Add --csv-path <path> |
| Merge branches | csdx cm:branches:merge --compare-branch <source> --base-branch <target> -k <key> |
| Merge with comment | Add --comment "<message>" |
| Merge without revert branch | Add --no-revert |
| Export merge summary | Add --export-summary-path <path> |
| Use existing merge summary | Add --use-merge-summary <path> |
Merge strategies (prompted interactively during merge):
- Merge, Prefer Base – keep base branch changes on conflicts
- Merge, Prefer Compare – keep compare branch changes on conflicts
- Merge New Only – merge only new changes, ignore modifications
- Overwrite with Compare – replace base with compare entirely
Guidance: Always run cm:branches:diff before merging to review changes. The diff output uses symbols: “+” (green) = only in compare branch, “+-” (blue) = different values, “-” (red) = not in compare branch. Consider exporting a merge summary first with --export-summary-path to review before executing.
Bulk publish and unpublish
| User intent | Command |
|---|---|
| Publish entries | csdx cm:entries:publish --content-types <uids> -e <envs> --locales <locales> -a <alias> |
| Publish all content types | csdx cm:stacks:bulk-entries --operation publish -e <envs> --locales <locales> -a <alias> |
| Publish modified entries | csdx cm:entries:publish-modified --content-types <uids> --source-env <env> -e <envs> --locales <locales> -a <alias> |
| Publish only unpublished entries | csdx cm:entries:publish-only-unpublished --content-types <uids> --source-env <env> -e <envs> --locales <locale> -a <alias> |
| Publish non-localized fields | csdx cm:entries:publish-non-localized-fields --content-types <uids> --source-env <env> -e <envs> -a <alias> |
| Update entries and publish | csdx cm:entries:update-and-publish --content-types <uids> -e <envs> --locales <locales> -a <alias> |
| Publish assets | csdx cm:assets:publish -e <envs> --locales <locales> -a <alias> |
| Unpublish entries | csdx cm:entries:unpublish --content-types <uids> -e <envs> --locales <locales> -a <alias> |
| Unpublish assets | csdx cm:assets:unpublish -e <envs> --locales <locales> -a <alias> |
| Filter by status | Add --filter draft, --filter modified, --filter unpublished, or --filter non-localized |
| Include variant entries | Add --include-variants |
| Revert a publish | csdx cm:stacks:publish-revert --log-file <log-file> |
| Retry failed publishes | Add --retry-failed <log-file> to any publish command |
| Generate publish config | csdx cm:stacks:publish-configure -a <alias> |
| Publish in single mode | Add --publish-mode single (instead of default bulk) |
Guidance: Recommend publishing one content type at a time to avoid failures. For large volumes, use --publish-mode single which is slower but more reliable. If a bulk publish partially fails, use --retry-failed <log-file> to retry only the failed items. The publish-modified and publish-only-unpublished commands require a --source-env to compare against.
Migration
| User intent | Command |
|---|---|
| Run migration script | csdx cm:stacks:migration --file-path <path> -k <key> |
| Run migration on branch | Add --branch <branch> |
| Run multiple migration scripts | csdx cm:stacks:migration --multiple --file-path <dir> -k <key> |
| Use migration config file | Add --config-file <path> |
| Use inline config | Add --config <key1>:<val1> <key2>:<val2> |
| Migrate HTML RTE to JSON RTE | csdx cm:entries:migrate-html-rte --alias <alias> --content-type <uid> --html-path <path> --json-path <path> |
| Migrate nested RTE fields | Use dot notation: --html-path group_uid.html_rte_uid --json-path group_uid.json_rte_uid |
| Migrate global field RTE | Add --global-field flag |
| Set migration delay | Add --delay <ms> (default 1000) |
| Migrate taxonomies from CSV | csdx cm:stacks:migration --file-path <path> --config data-dir:<csv-path> -k <key> |
| Change master locale | csdx cm:stacks:migration --file-path <path> --config target_locale:<locale> data_dir:<path> |
Guidance: Migration scripts are JavaScript files that use the Contentstack migration SDK. The --delay flag controls the interval between API calls to avoid rate limiting. For HTML RTE to JSON RTE migration, always test on a non-production branch first. Taxonomy migration requires a CSV file with specific columns (term name, UID, parent UID, etc.).
Audit
| User intent | Command |
|---|---|
| Audit exported data | csdx cm:stacks:audit -d <data-dir> |
| Audit specific modules | Add --modules content-types global-fields entries extensions workflows custom-roles assets field-rules |
| Audit with report path | Add --report-path <path> |
| Audit with CSV output | Add --csv |
| Audit with JSON output | Add --output json |
| Filter audit results | Add --filter <string> |
| Fix audit issues | csdx cm:stacks:audit:fix -d <data-dir> --copy-dir --copy-path <backup> |
| Fix specific issue types | Add --fix-only reference global_field json:rte json:extension blocks group content_types |
Guidance: Always run cm:stacks:audit (read-only) before running cm:stacks:audit:fix. The fix command should always include --copy-dir to create a backup of original data. Available fix types: reference (broken references), global_field (missing global fields), json:rte (malformed JSON RTE), json:extension (extension issues), blocks (modular block issues), group (field group issues), content_types (content type schema issues).
Launch (hosting and deployment)
| User intent | Command |
|---|---|
| Create/deploy a project | csdx launch --type <GitHub|FileUpload> |
| Deploy with config file | csdx launch -c <config-path> |
| Set framework | Add --framework <Gatsby|NextJs|CRA|CSR|Angular|VueJs|Other> |
| Set build command | Add --build-command <cmd> |
| Set output directory | Add --out-dir <dir> |
| Set server command | Add --server-command <cmd> |
| Set env variables | Add --env-variables "KEY:value,KEY2:value2" |
| Set project name | Add -n <name> |
| Set organization | Add --org <org-uid> |
| Redeploy latest | csdx launch --redeploy-latest -c <config> |
| Redeploy last upload | csdx launch --redeploy-last-upload -c <config> |
| View deployment logs | csdx launch:logs -c <config> -e <environment> |
| Test cloud functions locally | csdx launch:functions -c <config> -p <port> |
| List deployments | csdx launch:deployments -c <config> -e <environment> |
| List environments | csdx launch:environments -c <config> |
| Open project in browser | csdx launch:open -c <config> -e <environment> |
Guidance: Launch requires a .cs-launch.json config file in the project. For GitHub deployments, the repository must be accessible. For FileUpload, the built output directory is uploaded directly. Use launch:functions to test serverless functions locally before deploying.
Bootstrap and seed
| User intent | Command |
|---|---|
| Bootstrap a starter app | csdx cm:bootstrap --app-name <name> --project-dir <path> |
| Bootstrap into existing stack | Add -k <stack-api-key> |
| Bootstrap into new stack | Add --org <org-uid> -n <stack-name> |
| Seed stack from GitHub repo | csdx cm:stacks:seed --repo <org/repo> |
| Seed into existing stack | Add -k <stack-api-key> |
| Seed into new stack | Add --org <org-uid> -n <stack-name> |
Available starter apps: reactjs-starter, nextjs-starter, gatsby-starter, angular-starter, nuxt-starter.
Guidance: Bootstrap automatically clones the starter app, creates or uses a stack, imports all content types/entries/assets/environments, and publishes content. Seed imports content from any GitHub repo that follows the Contentstack export format.
3) Gather missing parameters
For the identified command, check which required parameters are missing and ask for them conversationally:
- If the command needs a stack API key, ask: “Which stack would you like to work with? Please provide the stack API key or a management token alias.”
- If the command needs environments, ask: “Which environment(s) should this target? For example: development, staging, production.”
- If the command needs content types, ask: “Which content type(s)? Please provide the UID(s).”
- If the command needs a file path, ask: “Where should the data be stored/read from? Please provide a directory path.”
Combine multiple missing parameters into a single question when they are related.
4) Build and present the plan
Construct the full command with all flags. Present it as a plan:
## Plan
**Action**: [Human-readable description]
**Risk level**: low (read-only) | medium (creates data) | high (modifies/deletes data)
**Command(s)**:
csdx <full command with all flags>
**What this will do**:
- [Bullet point explanation of each effect]
**Prerequisites verified**:
- Logged in as <email>
- Region: <region>
- Token: <alias> available
If mode is plan, stop here and wait for user confirmation.
5) Execute (only after confirmation)
When the user confirms:
- Run the command using Bash
- Capture stdout and stderr
- If the command prompts for interactive input, inform the user and suggest providing all required flags upfront or adding
-yto skip prompts - Parse the output for success/failure indicators
6) Handle composite workflows
Some user requests map to multiple commands in sequence. Detect these and present a multi-step plan:
| User wants | Steps |
|---|---|
| Move content from stack A to stack B | 1. cm:stacks:export from A, 2. cm:stacks:import to B |
| Copy content to a new stack | 1. cm:stacks:clone --type b |
| Copy only structure to a new stack | 1. cm:stacks:clone --type a |
| Set up CLI from scratch | 1. config:set:region, 2. auth:login, 3. auth:tokens:add (create management token alias) |
| Set up a token alias | 1. auth:whoami (verify logged in), 2. Ask for stack API key and token value, 3. auth:tokens:add --alias <name> --stack-api-key <key> --token <value> --management, 4. auth:tokens (verify alias was created) |
| Merge a branch and publish changes | 1. cm:branches:diff (review), 2. cm:branches:merge, 3. cm:entries:publish-modified |
| Audit and fix exported data | 1. cm:stacks:audit (review), 2. cm:stacks:audit:fix --copy-dir |
| Bootstrap a new project end to end | 1. config:set:region, 2. auth:login, 3. cm:bootstrap, 4. optionally launch |
| Export and then audit my stack | 1. cm:stacks:export, 2. cm:stacks:audit -d <export-path> |
For multi-step workflows, present each step with its own plan block and execute them sequentially, pausing for confirmation between destructive steps.
7) Summarize results
After execution, provide:
## Result
**Status**: Success | Failed | Partial
**Command**: csdx <command that ran>
**Summary**:
- [What happened]
- [Items affected, counts if available]
- [Any warnings]
**Next steps** (if applicable):
- [Suggested follow-up actions]
If the command failed, include:
**Error**: <error message>
**Likely cause**: <explanation>
**Suggested fix**: <what to do>
Output
Every interaction produces:
- Prerequisite status (logged in, region, tokens) – shown once at session start or when context changes
- Plan (always, even in execute mode) – the exact commands that will run with risk level
- Execution result (in execute mode only) – success/failure summary with guidance
- Next steps – contextual suggestions for what the user might want to do next
Format all output as clean Markdown. Use tables for listing items, code blocks for commands, and bullet points for summaries.
Error handling and edge cases
- Interactive prompts: Many
csdxcommands prompt for interactive input. When this happens, inform the user and suggest using non-interactive flags (-y,--yes, or providing all required flags upfront). - Rate limiting: If commands fail with rate limit errors, suggest checking
csdx config:get:rate-limitand adjusting withcsdx config:set:rate-limit. - Large exports/imports: For stacks with extensive content, suggest using
--moduleto export/import incrementally rather than all at once. - Branch-aware operations: Always confirm which branch the user intends to operate on. Default to
mainbut never assume. - Token types: Distinguish between management tokens (needed for most write operations) and delivery tokens (needed for publish commands with
--source-env). Guide the user to create the correct token type. - Failed publishes: When bulk publish operations partially fail, point the user to the log file and suggest using
--retry-failed <log-file>to retry only the failed items. - Webhook status during import: Always inform the user that by default webhooks are disabled during import. Ask if they want to preserve the current webhook state with
--import-webhook-status current. - Import sequence: If the user tries to import modules out of order, warn them about dependencies. The correct sequence is: Locales, Environments, Assets, Taxonomies, Extensions, Marketplace Apps, Webhooks, Global Fields, Content Types, Personalize, Workflows, Entries, Labels, Custom Roles, Studio.