Skip to content

The scwrap CLI

scwrap deployments shows what an instance runs, scwrap check builds a Release on the instance without deploying it, scwrap deploy has the instance build and deploy Releases through a journal, scwrap retry finishes a pending deploy, scwrap remove uninstalls a Release, scwrap rollback and scwrap platform rollback reinstall what a deploy replaced, and scwrap secrets set rotates a secret.

scwrap is the command-line tool for an instance's Releases. It is the bin of @scwrap/deploy. A Scraper repository and the Scwrap repository both run it as pnpm scwrap, whose script sets the default catalog (Installation).

text
scwrap deployments
scwrap check <file.ts>
scwrap deploy <file.ts>
scwrap deploy [--changed] [--force] [--catalog <module>] [--export <name>] [--journal <dir>] [scraper-id…]
scwrap retry --journal <dir>
scwrap remove [--force] [--deployment-id <id>] <scraper-id>
scwrap rollback [--force] [--deployment-id <id>] <scraper-id> [revision]
scwrap platform rollback [--force] [--deployment-id <id>] [platform-digest]
scwrap secrets set <name>

WARNING

deploy, retry, remove, rollback, platform rollback and secrets set change a live instance. Check which instance SCWRAP_INSTANCE_URL names before you run them.

Connecting to an instance ​

Every command needs the instance's URL and its deployer token.

FlagEnvironment variableMeaning
--instanceSCWRAP_INSTANCE_URLThe instance's HTTPS origin.
--tokenSCWRAP_INSTANCE_DEPLOYER_TOKENThe deployer token, sent as a bearer token. The run token is refused. A named deployer token limited to some Scrapers deploys, removes and rolls back only those, and cannot upgrade or roll back the platform or set secrets.

Flags override the environment. Prefer the environment for the token, so it does not end up in your shell history or in the process list.

The CLI is strict about where it sends the token:

  • The URL must be HTTPS, without credentials, query string or fragment.
  • It does not follow redirects.
  • It reads no dotenv file, no repository configuration and no credential file.

Before you deploy ​

deploy imports the catalog to learn each Release's module, so build the packages the catalog imports first:

sh
pnpm --filter '{./releases}^...' build

In the Scwrap repository, the catalog's package is @scwrap/infra: pnpm turbo run build --filter='@scwrap/infra^...'. The CLI needs no TypeScript, esbuild toolchain or matching effect for the build itself: the instance builds every Release from its source against its own SDKs (Builds).

What the CLI sends ​

check and deploy send each Release as source to the instance's POST /builds. The CLI starts at the Release's module, a .ts file, and follows its imports:

  • effect, the seven SDKs, the curated packages such as cheerio, and their subpaths stay as they are. The instance provides them.
  • A relative import of a .ts file, and an import of a workspace package whose types resolve to .ts source outside node_modules, such as @j4k4/tff in a Scraper repository, add that file. The CLI rewrites a package import to a relative one, such as ../../packages/tff/src/index.ts.
  • A local import that resolves to anything but a .ts file stops the CLI before it sends anything. Any other package is left as it is and fails the build on the instance with the allowed imports.

The files are sent by their paths relative to the directory that holds all of them, with the Release's module as entry. A build takes at most 100 files and 1 MiB.

scwrap deployments ​

Prints what the instance runs.

sh
pnpm scwrap deployments
json
{
  "activeRuns": [{ "count": 2, "scraper": "quotes" }],
  "generation": "…",
  "pendingDeploymentId": null,
  "platformDigest": "…",
  "releases": [
    { "digest": "…", "id": "earthquakes", "isolation": "dynamic-worker", "revision": "v1" },
    { "digest": "…", "id": "quotes", "isolation": "dynamic-worker", "revision": "v1" }
  ]
}
FieldMeaning
activeRunsHow many Runs each Scraper has running (Active Runs), or null when the instance cannot count them.
generationThe identity of everything installed: the platform plus every Release. It changes with every deploy.
pendingDeploymentIdA deployment that has not finished, or null.
releasesThe installed Release identities.

scwrap check ​

Builds a Release file on the instance without deploying it: the instance checks its imports, typechecks it with the Effect diagnostics, bundles it and reads its id and revision.

sh
pnpm scwrap check releases/src/quotes.ts

It prints releases/src/quotes.ts typechecks and builds as quotes v1, or fails with … failed to build: and the diagnostics. A one-file Scraper is checked the same way.

scwrap deploy ​

scwrap deploy <file.ts> deploys the Release a .ts file exports by default, such as a one-file Scraper, without reading a catalog. --force and --journal work the same.

Without a file, it collects the source of the selected Releases, saves the build requests to a journal and has the instance build and deploy them one at a time.

sh
pnpm scwrap deploy quotes
ArgumentMeaning
scraper-id…The Releases to deploy, by Scraper ID.
--changedWithout Scraper IDs, select the whole catalog. The instance builds each and skips every Release it already runs with the same id and digest, with or without the flag. It never removes an installed Release, so Releases from other catalogs stay.
--catalogA module that exports an array of Releases. It is imported and executed, so use only modules you trust. Defaults to the SCWRAP_CATALOG environment variable, which pnpm scwrap sets unless it is already set: to releases/src/catalog.ts in a Scraper repository, to apps/infra/src/instance-scrapers.ts in the Scwrap repository.
--exportThe name of the exported array. Defaults to the module's default export.
--journalA new directory for this deploy's journal. It must not exist yet, and its parent must. Without the flag the CLI creates one.
--forceStop the instance's active Runs before each deploy instead of letting them finish (Active Runs). The journal keeps it, so retry forces too.

The CLI first prints the journal's path, on standard error:

text
Journal: /home/you/.local/state/scwrap/journals/2026-11-22T16-21-07-512Z-3f9a1c2e

Then it prints one line per Release, on standard output, the instance's build status without its diagnostics:

json
{"buildId":"…","status":"passed","scraper":{"id":"quotes","revision":"v1"},"deployment":{"deploymentId":"build-…","generation":"…","status":"active"}}

A Release the instance already ran as built answers deployment without a deploymentId. scwrap deployments shows each Release's digest, which every result record it produces carries.

A Release that imports a deprecated name from scwrap-sdk.mjs still deploys; the instance names it in the build's diagnostics, which the CLI prints on standard error:

text
Warning: quotes imports OldName (deprecated in @scwrap/deploy 0.2.0) from scwrap-sdk.mjs. A later platform removes them; rebuild against the replacement before upgrading.

A Release whose bundle uses a capability its Scraper holds no grant for, such as apifyProxy without proxy:apify, also deploys with a warning on standard error (Grants).

What deploy does ​

  1. Collects every source first. Every selected Release's files are read before the first request. A local import the CLI cannot send stops the deploy before anything changed.
  2. Writes the journal. plan.json holds the instance URL and the build requests.
  3. Builds and deploys one Release at a time. Each request goes to POST /builds with deploy: true. While the build answers running or its deployment pending, the CLI reads GET /builds/<buildId> every 2 seconds, for up to 10 minutes; the instance hands a passed build to its deployment controller on the first read that sees it pass. A 409 is read again every 5 seconds, for up to 2 minutes.
  4. Stops at the first failure. A build that fails stops the batch with its diagnostics.

A batch is sequential, not atomic. If the third of five Releases fails, the first two are installed. The same files always make the same build on the same instance toolchain, so a repeated request deploys nothing twice.

Statuses ​

OutcomeMeaningDo
activeThe instance runs this Release.Nothing. The batch continues.
pendingThe deployment did not confirm within the CLI's wait. The batch stops and the command exits unsuccessfully, naming the retry command to run.Run retry with the same journal.
failedThe build failed: an import the instance refuses, a type error, a bundling error or no Release. Nothing changed.Fix the source and deploy again.
Any other failureThe command exits unsuccessfully with the HTTP status and the instance's error text, such as Build returned HTTP 403: … for a named token limited to other Scrapers.Run retry.

Active Runs ​

deploy, remove, rollback and platform rollback first say on standard error how many Runs are active:

text
3 Runs are active (earthquakes: 2, quotes: 1). They finish on the version they started on, for up to 15 minutes after the deploy. Pass --force to stop them now instead.

Without --force the deploy goes ahead at once and those Runs finish with all their items on the code they started on (Runs during a deploy). With --force the instance stops them first: each keeps the items it produced, ends failed and says which deploy stopped it. Every Scraper's Runs are counted and stopped, because every deploy replaces the Run owners of all of them, so --force needs an unlimited deployer token.

When the instance cannot count its Runs, the CLI warns the instance could not count its active Runs and deploys anyway.

scwrap retry ​

Sends a journal's saved commands again and continues the batch.

sh
pnpm scwrap retry --journal "$HOME/.local/state/scwrap/journals/2026-11-22T16-21-07-512Z-3f9a1c2e"

--journal is required here: it is the path deploy printed. retry needs only the journal and the connection. It does not read the catalog or the source: it sends the saved build requests again. The instance recognises a repeated request as the same build, and that build's deployment by its ID build-<buildId>, so it answers with the saved outcome instead of deploying twice.

Run it until every Release is active.

scwrap remove ​

Removes one installed Release from the instance. The controller deploys a new release Worker version without it, so its Definition leaves the catalog, the MCP tools and the run routes. Its stored results stay in the results bucket until they expire.

sh
pnpm scwrap remove quotes

The instance answers 404 for a Release it does not run. remove uses no journal: when the activation is not confirmed, it exits unsuccessfully with the same command plus --deployment-id, which resubmits the removal under its original ID. Remove the Release from the catalog too, or the next deploy --changed installs it again.

scwrap rollback ​

Reinstalls a Release identity that a later deploy replaced: its revision and digest come back, and so does its exact code, which the instance keeps by digest. It builds nothing and reads no catalog.

sh
pnpm scwrap rollback quotes
pnpm scwrap rollback quotes v3
ArgumentMeaning
scraper-idThe Release to roll back.
revisionOptional. The most recent replaced identity with this revision. Without it, the most recent replaced identity that differs from the installed one.
--deployment-idResubmit a pending rollback under its original ID.
json
{"id":"quotes","deploymentId":"…","generation":"…","status":"active"}

The instance records the identity every deploy, removal and rollback replaces, the last 20 per Scraper, so a rollback can be rolled forward again by naming the newer revision, and a removed Release can be reinstalled. Identities replaced before the instance kept this record cannot be rolled back to.

AnswerMeaning
404No replaced identity this instance can run matches. The error lists the recorded revisions and any Node releases it skipped.
409Another generation or a pending deploy, as for deploy; or the identity imports a name the current platform no longer exports. Nothing changed.

After scwrap deployments and GET /scrapers show the old identity, fix or revert the Release in its catalog too. The next deploy --changed, which CI runs on every push, otherwise installs the catalog's identity again.

scwrap platform rollback ​

Reinstalls the platform an upgrade replaced and keeps every installed Release. Without an argument it takes the most recent replaced platform; with a platform-digest from an earlier scwrap deployments, that retained platform.

sh
pnpm scwrap platform rollback

It needs an unlimited deployer token. The instance refuses, with 409 and nothing changed, a platform whose scwrap-sdk.mjs lacks a name an installed Release imports, and a platform from before a Durable Object class the release Worker has since added. It restores the platform's code but keeps the current run tokens and grants. Rolling back the platform covers what to do afterwards.

scwrap secrets set ​

Replaces one of the release Worker's secrets, BROWSER_USE_API_KEY, RELEASE_ENV or SCRAPER_SETTINGS, with the value on standard input. The instance answers 404 for any other name. One trailing newline is dropped.

sh
pnpm scwrap secrets set SCRAPER_SETTINGS < scraper-settings.json

It prints the name, the generation and the new Worker version. The controller refuses while a deployment is pending (409). Rotating secrets describes what a rotation does to Runs.

The journal ​

The journal is what makes a deploy safe to repeat.

text
2026-11-22T16-21-07-512Z-3f9a1c2e/
  plan.json     the instance URL and the build requests: each Release's source files and entry

Without --journal, deploy creates the directory under $XDG_STATE_HOME/scwrap/journals, or under $HOME/.local/state/scwrap/journals when XDG_STATE_HOME is not set, and names it after the time it started.

Rules:

  • Keep it outside the repository. It contains your source. It never contains the token.
  • One journal per deploy. deploy refuses a directory that exists.
  • Prefer retry for a deploy whose outcome is unknown. It sends exactly what the first attempt sent, even after the source changed.
  • Never edit or delete its files. Changed source is a new build and a new deployment. A damaged journal fails closed: inspect it before doing anything else.
  • Keep it until every outcome is known.

plan.json is created with mode 0600 and the directory with 0700.

In CI ​

The Scwrap repository's production deploy job runs the same commands after the tests pass, and a Scraper repository's CI can do the same:

sh
pnpm scwrap deploy --changed --journal "$journal"

It passes --journal because it uploads that directory afterwards. When deploy does not finish, it runs retry up to five times with the same journal, waiting 15 seconds before the first and 15 seconds longer before each next one, keeps the journal as a workflow artifact, and then checks with scwrap deployments that nothing is pending.

Source ​