@sitecoreai-demo/sitecoreai-deploy-and-sync
v0.0.3
Published
SitecoreAI Deploy & Sync CLI for serialization and deployment workflows
Readme
SitecoreAI Deploy & Sync CLI
TypeScript CLI modeled after the Sitecore DotNet SDK and aligned with the serialization commands in Sitecore.DevEx.
This implementation runs natively (no dependency on the official sitecore CLI).
It also includes a first-class SitecoreAI Deploy API client.
CLI command: scai (alias: sitecoreai-deploy-sync)
Examples below use the installed CLI command scai (alias: sitecoreai-deploy-sync).
For local development without installation, replace scai with npm run dev --.
Quick start
Install dependencies (npm/pnpm/yarn/bun are all supported):
npm install
pnpm install
yarn install
bun installConfigure an environment (writes to sitecoreai.cli.json and creates it if missing):
scai init
scai init --environment-name local --project "My Project" --environment "Dev"Interactive wizard setup:
scai init --wizardRunning init without flags defaults to the wizard. Provide flags to skip prompts.
Use --skip-deploy-lookup to avoid Deploy API lookups and just enter the CM host.
Auto-setup on startup:
- When you run a command and no config or auth token is found, the CLI launches the init/login wizard.
- In non-interactive/CI mode, it skips auto-setup and prints a hint instead.
- Disable auto-setup with
SITECOREAI_AUTO_WIZARD=0.
Check configured environments:
scai statusValidate configuration:
scai config validateRun a serialization command:
scai serialization pull --environment-name localList environments from the Deploy API:
scai deploy environments list --project "My Project" --type cmUpload deployment source from a directory:
scai deploy deployments source --id <deploymentId> --directory ./my-appAgent/CI usage
For non-interactive usage, authentication flows, and CM vs Editing Host guidance, see
AGENT_CI.md.
Future enhancements: see ROADMAP.md.
Agent metadata and skills:
- Machine-readable config:
agent.json - Skills index:
skills/README.md
Configuration
Configuration is read from sitecoreai.cli.json at your project root (use --config to
point at a different directory). init creates or updates an environment in the
envProfiles section, creates the config if it does not exist, and can set the default
environment with --set-default.
Key behaviors:
--environment-nameselects the environment key insideenvProfiles.- Global output flags:
--json,--quiet, and--log-file <path>. --reflets an environment inherit auth/settings from another environment.- Deploy API access uses a SitecoreAI access token cached in the OS keychain (
deployToken). This token includes SitecoreAI CM/admin scopes in addition to Deploy scopes. initcan accept--deploy-tokendirectly or obtain a token via interactive login or client credentials.loginonly refreshes the SitecoreAI access token for an existing environment.- CM access/refresh tokens are cached in the OS keychain when
settings.cacheAuthenticationTokenistrue(default:true). - For client credentials, provide secrets via environment variables
(
SITECOREAI_CLIENT_SECRETorSITECOREAI_ENV_<NAME>_CLIENT_SECRET). - Environment settings can be overridden with environment variables for CI or secrets.
Global overrides (
SITECOREAI_CLIENT_SECRET, etc.) apply only to the active environment, while per-environment overrides (SITECOREAI_ENV_DEMO_DEPLOY_TOKEN) always apply. - CLI history is written to
~/.sitecoreai/cli-history.log(override withSITECOREAI_HISTORY_PATH). - Use
historyto view recent CLI activity from that log. - Use
history --show-pathto print the log file path. - Module files (
*.module.json) are validated against the serialization module schema.
Telemetry:
- Modeled after the Vercel Skills CLI: anonymous usage events and opt-out via env vars. github.com/vercel-labs/skills
- On first use, the CLI prompts for consent and stores it in
settings.telemetryEnabledinsitecoreai.cli.json. - If
settings.telemetryEnabledis unset, telemetry is disabled until consent is recorded. - Override with env vars:
SITECOREAI_TELEMETRY=false,DISABLE_TELEMETRY=1, orDO_NOT_TRACK=1. - Uses a
ci=1flag when running in CI. - Sends command names, durations, and a random nonce (no full args); sensitive flags are redacted.
- The telemetry service derives an approximate region from CDN headers (e.g.,
US-CA) and does not store raw IPs. - The CLI uses a built-in production telemetry endpoint. For development, override with
SITECOREAI_TELEMETRY_URL. - Telemetry schema:
https://schemas.sitecoreai.dev/v1/telemetry.schema.json. - Telemetry payloads are validated against the telemetry schema before sending.
Telemetry status:
scai telemetry statusPrivacy
Telemetry is strictly anonymous and minimal. We do not send file contents, full arguments,
tokens, or user identifiers. The payload includes only the command name, duration, CLI
version, schema version, a CI flag when applicable, and an approximate region derived
from CDN headers (client-supplied region values are ignored). The telemetry service uses
client IPs only for rate limiting and does not store raw IPs (logs keep only anonymized IP
prefixes). You can opt out at any time via settings.telemetryEnabled or the environment
variables above.
Data handling and retention
- Local history is stored in
~/.sitecoreai/cli-history.log(override withSITECOREAI_HISTORY_PATH) and grows until you delete or rotate it. - Telemetry payloads are minimal and do not include full arguments or credentials. Retention and aggregation are determined by the telemetry service.
Troubleshooting
- Config not found: run
scai initor pass--config <path>. - Auth required: run
scai loginorscai initto refresh tokens. - Network/timeouts: verify the CM host/authority, and increase
settings.apiClientTimeoutInMinutesif needed. - Deploy token missing: provide
--deploy-tokenor configureSITECOREAI_DEPLOY_TOKEN.
Release management
This repo uses Changesets for versioning and release automation.
Local workflow:
npm run changeset- Select the version bump type (patch/minor/major).
- Commit the generated
.changeset/*.mdfile.
CI workflow:
- Push to
mainand the Changesets GitHub Action will open a release PR. - Merge the release PR to publish to npm (requires
NPM_TOKENsecret).
Manual release:
npm run version
npm run releaseSerialization API usage
Serialization commands use the Sitecore Management API (GraphQL) at
/sitecore/api/management on the configured CM host.
- Authentication: OAuth2 via the configured
authority. The CLI supports client credentials and interactive browser login, and caches access tokens insitecoreai.cli.json. - Items: GraphQL queries to read items, metadata, and history for pull/push/diff workflows.
- Roles/Users: GraphQL queries for role/user sync (pull/push).
- Watch: GraphQL history polling to detect remote changes and pull deltas.
- Filesystem: YAML files in the module serialization paths using deterministic YAML output.
Commands
Serialization commands (alias: ser):
serialization infoserialization explainserialization pullserialization pushserialization diffserialization validateserialization watchserialization package create(alias:pkg)serialization package install(alias:pkg)
Environment commands:
initloginlogoutstatushistory
Deploy API commands:
deploy organizations getdeploy organizations healthdeploy organizations licensedeploy organizations launch-demodeploy projects listdeploy projects limitationdeploy projects validate-namedeploy projects getdeploy projects createdeploy projects updatedeploy projects link-repositorydeploy projects unlink-repositorydeploy projects deletedeploy environments listdeploy environments limitationdeploy environments getdeploy environments createdeploy environments variables listdeploy environments variables createdeploy environments variables deletedeploy environments deployments listdeploy environments deployments createdeploy environments get-edge-tokendeploy environments get-editing-secretdeploy environments regenerate-contextdeploy environments promotedeploy environments restartdeploy environments link-repositorydeploy environments unlink-repositorydeploy environments deletedeploy logs listdeploy logs viewdeploy logs datadeploy editing-host listdeploy editing-host createdeploy editing-host updatedeploy editing-host deletedeploy editing-host deploydeploy source-control listdeploy source-control statedeploy source-control access-tokendeploy source-control validatedeploy source-control repository getdeploy source-control repository branchesdeploy source-control repository validatedeploy source-control repository create-from-templatedeploy source-control providersdeploy source-control templatesdeploy source-control getdeploy source-control deletedeploy deployments listdeploy deployments getdeploy deployments statusdeploy deployments deploydeploy deployments canceldeploy deployments sourcedeploy deployments watchdeploy deployments logs
Aliases:
deploy org→deploy organizationsdeploy proj→deploy projectsdeploy env→deploy environmentsdeploy sc→deploy source-controldeploy dep→deploy deploymentsdeploy log→deploy logsdeploy eh→deploy editing-host
Deploy selection rules:
- Projects: use
--idor--name. Project link/unlink requires--id. - Environments: use
--idor--name, optionally scoped with--project. - Environment create requires
--project. - Environment create supports
--cm-onlyto create a CM-only environment. - Project create requires
--name. - Tenant types:
0= nonprod,1= prod. - Project source control ID mapping: create uses
integrationId, update usessourceControlIntegrationId. - Source control integrations and deployments: use
--id. - Project link-repository requires
repositoryIdandintegrationId(others optional). - Environment link-repository requires
repositoryName,repositoryId,integrationId,repositoryRelativePath, andrepositoryBranch. - Source control repository create-from-template requires
--provider(adoorgithub) and template fields (templateRepository,templateOwner,repositoryName,owner,integrationId). - Deploy deployments source accepts
--file(archive) or--directory(auto-zip).
Aliases:
serialization->serserialization package->pkg
Development
Run in dev mode:
npm run dev -- serialization info --helpLint and format:
npm run lint
npm run formatBuild:
npm run buildRun tests:
npm run testIntegration tests (requires env vars):
npm run test:integrationWatch tests:
npm run test:watchRun built CLI:
node dist/cli.js serialization info --help