Skip to content

Expose CLI commands as a programmatic library API - #512

Merged
tuler merged 10 commits into
prerelease/v2-alphafrom
claude/cartesi-cli-library-api-2m3q2q
Nov 24, 2026
Merged

tuler merged 10 commits into
prerelease/v2-alphafrom
claude/cartesi-cli-library-api-2m3q2q

Conversation

@tuler

@tuler tuler commented Aug 7, 2026 •

Copy link
Copy Markdown
Member

Summary

This PR refactors the Cartesi CLI to expose all commands as a programmatic library API, allowing developers to use CLI functionality directly from TypeScript/JavaScript code without invoking the command-line interface.

import { build, depositErc20, hash, run, send } from "@cartesi/cli";

await build();
const node = await run({ epochLength: 10 });
await send({ input: "hello" });
await depositErc20({ amount: "1.5" });
await node.stop();

Key Changes

  • New API modules (apps/cli/src/api/): Created modular API functions for every command but the deprecated deploy:

    • build.ts - Build application drives, nvrams and machine snapshot
    • run.ts - Start local Cartesi rollups environment, with its PRT nodes
    • send.ts - Send inputs to deployed applications
    • deposit/ - Deposit assets: depositEther, depositErc20, depositErc721, depositErc1155, depositErc1155Batch
    • foreclose.ts, refund.ts, withdraw.ts - Recover funds from an application, sharing recovery.ts
    • logs.ts - Read the logs of the node and its PRT nodes, or of the services given
    • hash.ts - Get machine snapshot hash
    • status.ts - Query environment status
    • shell.ts - Boot machine in interactive mode
    • doctor.ts - Check system requirements
    • create.ts - Create new applications from templates
    • clean.ts - Clean build artifacts
    • address-book.ts - Get deployed contract addresses
    • connection.ts - Shared resolution of client, sender and application address
    • types.ts - Shared types and configuration resolution
  • Command refactoring: Updated the command files to delegate to the new API modules, eliminating code duplication. Commands keep the interactive prompts and the terminal output, and pass resolved values to the API. Helpers that upstream unit tests import moved along with the code that uses them, and the tests import them from their new place: selectLogServices, buildLogsArgs and listServices to api/logs.ts, and the fund recovery helpers to src/foreclose.ts, src/refund.ts and src/withdraw.ts. addRecoveryOptions moved to commands/recovery.ts, keeping Commander out of the modules the API uses.

  • Library exports:

    • Added src/lib.ts as the main library entrypoint, bundled to dist/lib.js alongside the CLI bundle
    • Added main, exports and types to package.json, pointing at the library build and its declarations, while bin keeps pointing at the CLI build (dist/index.js). This restores the fields dropped in d78d897, now that the package does ship a library and does emit declarations
    • Added TypeScript declaration generation via tsconfig.build.json, covering the library entrypoint and what it imports
    • Moved viem, execa, semver and smol-toml back to dependencies. The library build leaves them external and loads them from node_modules, so a consumer shares them: errors thrown from viem are instances of the consumer's viem classes, and viem isn't shipped twice. The CLI bundle and the binaries still bundle everything. Every other package stays a devDependency, inlined by the bundler
  • Enhanced wallet support: Added interactive parameter to getRpcUrl() for programmatic use cases, and DevnetClient for the devnet client type

  • Test coverage: Added unit tests for encodeInput(), resolveConfig(), parseAmount(), the deposit error hierarchy, the doctor requirements and the address normalization of resolveConnection()

  • Documentation: Updated README with library usage examples

Notable Implementation Details

  • API functions follow a consistent pattern with Options and Result types
  • Progress reporting is configurable (silent, default, verbose) for library use
  • Configuration can be provided as parsed Config objects or file paths
  • The run() function returns a RunResult object with methods to deploy/undeploy applications, stop the PRT nodes and stop the environment, and it reports configuration worth saying out loud (a [prt] section with no effect, a reader-mode change on a rebuild) through an onNotice callback instead of printing; the command prints those notices
  • run() owns the PRT orchestration: it resolves [prt] before anything starts and reports its warnings once, funds the pool accounts, deploys with the sentries, starts the PRT nodes for the deployment and exposes them as prtConfig and prtServices. A redeploy resolves [prt] again and reports its warnings again
  • All API functions are silent by default (no terminal output) unless progress option is specified
  • doctor() runs every check concurrently and returns all results. Each check lists the checks it requires, and is reported as skipped when one of them is not satisfied, which the command doesn't print; the docker errors are mapped to what to install by a single helper
  • build() resolves the accounts drive layout of the built machine and returns it with the emergency withdrawal configuration derived from it, which cartesi build and the "Build and redeploy" of cartesi run then print; run() resolves that configuration itself, before starting the environment and again on every redeploy
  • foreclose(), refund() and withdraw() run cartesi-rollups-cli with --yes and --json and return its output. With stream: true it is attached to the terminal with the transaction options as given, which the commands use, and a failure it printed is thrown as a NodeCommandError
  • send and the deposits checksum the application, sender and token addresses they are given, which also rejects a malformed address early
  • Deposit amounts are given in the base unit of the asset as a bigint, or in its display unit as a string ("1.5"); the token defaults to the corresponding devnet test token
  • Deposits that cannot be made throw DepositError subclasses (InsufficientBalanceError, InvalidAmountError, TokenNotFoundError) instead of printing and returning; the commands render them as before
  • Four types are now explicit so that declaration emit stays portable, as the types inferred for them inline dependency internals that cannot be named from outside their own package: execaDockerFallback returns execa's Result, cartesi is a viem Chain, getAnvilClient returns a viem PublicClient, and DevnetClient is spelled out from viem's TestClient, PublicActions and WalletActions
  • Consumers that compile with skipLibCheck: false need @types/node, as the declarations of the environment reference NodeJS.ProcessEnv

Behavior Changes

  • run: "Build and redeploy" now builds with the configuration files given to run -c, instead of always cartesi.toml
  • doctor: every requirement whose requirements are met is checked and reported, instead of stopping at the first failure
  • deposit erc721: a failed ownership check that is not ERC721NonexistentToken now stops instead of reporting the failure and continuing
  • deposit erc1155-batch: the token-ids/amounts length mismatch is reported after the application address prompt, rather than before it

Testing

Type checking, linting, declaration emit and the 555 unit tests pass, each commit independently. The published package was checked by installing the output of npm pack into an empty project, with TypeScript 7 and @types/node: it type-checks with skipLibCheck: false under both nodenext and bundler module resolution, and a deposit against an unreachable RPC throws an error that is an instance of the project's own HttpRequestError and BaseError. Docker was not available in the development environment, so the docker-dependent paths (build, run, logs, deposits, the PRT nodes, the fund recovery commands) were not exercised end to end and rely on CI.

https://claude.ai/code/session_015SA64hXXCsNWisTYLVpEBn

@changeset-bot

changeset-bot Bot commented Aug 7, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5e073ca

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cartesi/cli Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

github-actions Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Coverage Report

Status Category Percentage Covered / Total
🟢 Lines 85.18% (🎯 0%) 14091 / 16543
🔵 Statements 85.18% 14091 / 16543
🔵 Functions 79.28% 375 / 473
🔵 Branches 0% 0 / 0
📁 File Coverage (20 files)
File Lines Statements Functions Branches Uncovered Lines
apps/cli/src/api/build.ts 🔴 7.27% 🔴 7.27% 🔴 0% 🔴 0% 74-125, 130-136, 151-244
apps/cli/src/api/connection.ts 🟢 88.89% 🟢 88.89% 🟢 100% 🔴 0% 70-72
apps/cli/src/api/deposit/common.ts 🟢 100% 🟢 100% 🟢 100% 🔴 0% -
apps/cli/src/api/deposit/erc1155.ts 🔴 4.21% 🔴 4.21% 🔴 0% 🔴 0% 80-159, 170-263, 272-302
apps/cli/src/api/deposit/erc20.ts 🔴 8% 🔴 8% 🔴 0% 🔴 0% 32-45, 77-154
apps/cli/src/api/deposit/erc721.ts 🔴 6.3% 🔴 6.3% 🔴 0% 🔴 0% 41-50, 79-187
apps/cli/src/api/deposit/ether.ts 🔴 15.56% 🔴 15.56% 🔴 0% 🔴 0% 29-66
apps/cli/src/api/deposit/index.ts 🟢 100% 🟢 100% 🟢 100% 🔴 0% -
apps/cli/src/api/deposit/progress.ts 🟡 66.67% 🟡 66.67% 🔴 0% 🔴 0% 14, 18
apps/cli/src/api/doctor.ts 🔴 34.97% 🔴 34.97% 🔴 30% 🔴 0% 57-74, 79-91, 95-106, 110-1...
apps/cli/src/api/logs.ts 🔴 38.82% 🔴 38.82% 🟡 60% 🔴 0% 12-23, 136-175
apps/cli/src/api/run.ts 🔴 4.98% 🔴 4.98% 🔴 0% 🔴 0% 222-244, 248-261, 268-286, ...
apps/cli/src/api/send.ts 🟡 71.96% 🟡 71.96% 🟡 75% 🔴 0% 46-47, 74-78, 95, 104, 156-176
apps/cli/src/api/types.ts 🟢 100% 🟢 100% 🟢 100% 🔴 0% -
apps/cli/src/base.ts 🔴 42.11% 🔴 42.11% 🟡 70.59% 🔴 0% 62, 101-174, 200-204, 208-2...
apps/cli/src/builder/directory.ts 🟢 100% 🟢 100% 🟢 100% 🔴 0% -
apps/cli/src/builder/docker.ts 🟢 87.12% 🟢 87.12% 🟡 66.67% 🔴 0% 77-79, 81, 114-116, 174-183
apps/cli/src/builder/empty.ts 🟢 100% 🟢 100% 🟢 100% 🔴 0% -
apps/cli/src/builder/index.ts 🟢 100% 🟢 100% 🟢 100% 🔴 0% -
apps/cli/src/builder/none.ts 🟢 100% 🟢 100% 🟢 100% 🔴 0% -

@tuler
tuler force-pushed the claude/cartesi-cli-library-api-2m3q2q branch from 33b100c to 237eb4c Compare October 5, 2026 20:15
@tuler
tuler force-pushed the claude/cartesi-cli-library-api-2m3q2q branch 2 times, most recently from 00a89f2 to 6998883 Compare October 13, 2026 22:27
@tuler
tuler added this pull request to stack #558 October 14, 2026 02:21
@brunomenezes

Copy link
Copy Markdown
Member

@tuler could you rebase?

@tuler
tuler force-pushed the claude/cartesi-cli-library-api-2m3q2q branch from 6998883 to 6e24891 Compare October 19, 2026 13:50
@tuler
tuler force-pushed the claude/cartesi-cli-library-api-2m3q2q branch from 6e24891 to cf77b41 Compare November 3, 2026 15:44
Every command is now also a function, so applications can be built, run
and inspected from a script:

    import { build, hash, run } from "@cartesi/cli";

The command actions were moved to `src/api`, and the Commander commands
became thin wrappers around them. The API functions take plain option
objects with defaults, return values instead of printing, throw instead
of exiting, and are silent unless `progress` is set to "default" or
"verbose", which reproduces the CLI output.

`src/lib.ts` is the new package entrypoint, bundled to `dist/lib.js` and
typed by `dist/types`, generated with `tsc --emitDeclarationOnly`. The
`bin` entrypoint is unchanged.

While rewiring the run command, "build and redeploy" now builds with the
configuration files given to `run`, instead of always `cartesi.toml`.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015SA64hXXCsNWisTYLVpEBn
The doctor API now runs every check in parallel and returns all results,
failed and successful, instead of stopping at the first failure and
reporting progress through callbacks. The command renders the results
after they are gathered.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015SA64hXXCsNWisTYLVpEBn
Adds `depositEther`, `depositErc20`, `depositErc721`, `depositErc1155`
and `depositErc1155Batch` to the library API, moving the deposit logic
out of the commands. The commands keep the prompts, and pass everything
resolved to the API.

Amounts are given in the base unit of the asset as a bigint, or in its
display unit as a string. Deposits that cannot be made now throw
`DepositError` subclasses instead of printing and returning, which the
commands render the same way as before.

The connection setup shared by `send` and the deposits (client, sender
and application address) moved to `resolveConnection`.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015SA64hXXCsNWisTYLVpEBn
@tuler
tuler force-pushed the claude/cartesi-cli-library-api-2m3q2q branch from cf77b41 to 0f8ea17 Compare November 12, 2026 20:04
@brunomenezes

Copy link
Copy Markdown
Member

@tuler, I built and tested this PR on 0f8ea17 locally. Build, typecheck, lint, the 548 unit tests and the integration suite (95 pass, 1 skipped) all pass. I then ran the PR build (node apps/cli/dist/index.js) side by side with cartesi 2.0.0-alpha.42, which was released from this PR's base (b8f9f18), on the same project. Below are the enumerated regressions and description mismatches I found. Every output shown comes from running code: those side-by-side runs, a consumer project using the packed tarball (5, 6), and a script against the devnet (7).

1. doctor error messages got worse

Running the checks concurrently means every check now reports its own failure, and only checkDocker, checkCompose and checkBuildx turn raw execa errors into friendly messages. The RISC-V check used to share checkBuildx's try, so its exit code 125 also mapped to the Buildx message. Now checkRiscv (src/api/doctor.ts:118) has no catch. Failed lines also no longer name the check, so Command failed with ENOENT: … doesn't say which requirement failed.

Docker not installed:

cd apps/cli && bun run build
env PATH=/nonexistent "$(command -v node)" dist/index.js doctor

alpha.42:

✖ Docker not found

This PR:

✖ Docker not found
✖ Command failed with ENOENT: docker compose version --short
spawn docker ENOENT
✖ Command failed with ENOENT: docker buildx version
spawn docker ENOENT
✖ Command failed with ENOENT: docker buildx ls --format '{{.Platforms}}'
spawn docker ENOENT
✖ Could not determine the Cartesi Machine version. Check that Docker is running.

Buildx missing, simulated with a docker wrapper that exits 125 for buildx:

mkdir -p /tmp/nobuildx && cat > /tmp/nobuildx/docker <<'EOF'
#!/bin/sh
[ "$1" = "buildx" ] && { echo "docker: unknown command: docker buildx" >&2; exit 125; }
exec "$(PATH=${PATH#/tmp/nobuildx:} command -v docker)" "$@"
EOF
chmod +x /tmp/nobuildx/docker
PATH=/tmp/nobuildx:$PATH node dist/index.js doctor

alpha.42:

✔ Docker Engine 29.9.2
✔ Docker Compose 5.6.1
✖ Docker Buildx is required but not installed. Please refer to the Docker Desktop documentation for installation instructions: https://docs.docker.com/desktop/

This PR:

✔ Docker Engine 29.9.2
✔ Docker Compose 5.6.1
✖ Docker Buildx is required but not installed. Please refer to the Docker Desktop documentation for installation instructions: https://docs.docker.com/desktop/
✖ Command failed with exit code 125: docker buildx ls --format '{{.Platforms}}'

docker: unknown command: docker buildx
✔ Cartesi Machine 0.22.0

2. "Build and redeploy" in cartesi run no longer prints the accounts drive layout

Before, the shell ran the build command (build.parseAsync([])), which prints describeWithdrawalConfig after building. Now it calls the build() API (src/commands/run.ts:144), which returns the layout without printing it, and drops the result. Only cartesi build prints the layout now. That goes against "Commands keep the interactive prompts and the terminal output".

To reproduce, create a project with cartesi create pr512app --template typescript, and give it this cartesi.toml (also used in 3):

[nvrams.accounts]
size = "4Mi"
accounts_drive = true

[prt.nodes.alice]
address = "0x70997970C51812dc3A010C7d01b50e0d17dc79C8"
sentry = true

Then run cartesi build, cartesi run --prt, and press b. After the build, alpha.42 prints:

accounts drive  accounts (nvram) → /dev/uio0
start           0xa0000000
size            4 MiB (2^22 bytes)
accounts        131072 × 32 bytes

withdrawal config
  guardian                    0x70997970C51812dc3A010C7d01b50e0d17dc79C8  devnet account 1
  …
--withdrawal-config '{"guardian":…}'
devnet defaults in use: set guardian and withdrawal_output_builder under [withdrawal] to deploy elsewhere

With this PR, the output goes from ✔ Build nvram accounts straight to the redeploy.

3. PRT warnings are printed twice on cartesi run --prt

run() calls reportPrtWarnings before starting the environment (src/api/run.ts:516). On startup, deploy() calls it again (src/api/run.ts:602). The base branch reported them once at startup and only repeated them on a redeploy. Every [prt] warning shows twice whenever a machine snapshot exists.

With the project from 2, after cartesi build, run cartesi run --prt (default --claim-staging-period 0).

alpha.42:

WARNING: with --claim-staging-period 0 a staged claim is accepted at once, so the sentries have no effect
✔ pr512app starting at http://127.0.0.1:6751
✔ anvil service ready at http://127.0.0.1:6751/anvil
✔ rpc service ready at http://127.0.0.1:6751/rpc
✔ inspect service ready at http://127.0.0.1:6751/inspect/pr512app
✔ pr512app machine hash is 0x5cbb…60fb

This PR:

WARNING: with --claim-staging-period 0 a staged claim is accepted at once, so the sentries have no effect
✔ pr512app starting at http://127.0.0.1:6751
✔ anvil service ready at http://127.0.0.1:6751/anvil
✔ rpc service ready at http://127.0.0.1:6751/rpc
✔ inspect service ready at http://127.0.0.1:6751/inspect/pr512app
WARNING: with --claim-staging-period 0 a staged claim is accepted at once, so the sentries have no effect
✔ pr512app machine hash is 0x5cbb…60fb

Apart from that, the PRT output matches alpha.42: the reference line, sentry manager none, the per-node lines, and the single warning on "Build and redeploy".

4. Not every command has an API

The description says it "Created modular API functions for all commands" and "Updated all command files to delegate to the new API modules". But withdraw, foreclose and refund have no API module, and src/lib.ts doesn't export them. Adding them would complete the list of commands. deploy can stay out, since it's deprecated and only prints a deprecation message.

5. Published declarations need ora

depositSpinner (src/api/deposit/common.ts:90) is exported, so dist/types/api/deposit/common.d.ts references import("ora").Ora. ora is a devDependency, so a consumer with skipLibCheck: false fails under both bundler and nodenext:

dist/types/api/deposit/common.d.ts(61,…): error TS2307: Cannot find module 'ora' or its corresponding type declarations.

To reproduce:

  1. Run bun run build && npm pack in apps/cli.
  2. In an empty project, install the tarball, typescript and @types/node.
  3. Use a tsconfig.json with "skipLibCheck": false and "module": "nodenext". On TypeScript 7, also add "types": ["node"], since @types/node is no longer loaded by default.
  4. Type-check a file that imports anything from @cartesi/cli.

Type-check command running inside the "empty-project"

npx tsc -p .

This contradicts "with skipLibCheck both on and off". Making depositSpinner internal, or typing it without ora, would fix it.

Note

Runtime isn't affected, and projects with the default skipLibCheck: true (tsc --init, the Vite and Next.js templates) won't see the error. But with this PR the declarations become part of the package's public surface, so they should type-check on their own rather than depend on consumers skipping the check.

6. The four runtime dependencies are bundled into dist/lib.js as well

viem, execa, semver and smol-toml moved to dependencies "as the published declarations reference them". But the lib.ts Bun.build in build.ts has no external, so Bun also copies their code into dist/lib.js, which then imports only node: builtins. Consumers install the four packages, but at runtime the library uses its own bundled copies. Two consequences:

  • Errors the library rethrows from viem aren't instances of the consumer's viem classes. A depositEther against an unreachable RPC throws HttpRequestError, but e instanceof HttpRequestError and e instanceof BaseError are both false with the consumer's viem. With the four packages external, both are true.
  • dist/lib.js is 1004 KiB, against 462 KiB with them external, and an app that also uses viem ships two copies of it.

Adding external: ["viem", "execa", "semver", "smol-toml"] to the library build would fix both and match the description.

7. Minor

  • depositErc721 checks ownership with currentOwner !== from (src/api/deposit/erc721.ts:122). ownerOf returns a checksummed address, so a library caller passing a lowercase from gets InsufficientBalanceError for a token it owns. With a running devnet, mint a test NFT to devnet account 8, then call depositErc721 with that tokenId:

    from: "0x23618e81e3f5cdf7f54c3d65f7fbc0abf5b21e8f" -> InsufficientBalanceError: Insufficient balance
    from: "0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f" -> deposited
    

    The CLI command isn't affected, because it normalizes --from with getAddress. Normalizing from with getAddress in resolveConnection (src/api/connection.ts:83) as well would fix it for every API that resolves the sender (send and all deposits), and would reject a malformed address early.

  • deposit erc721 and deposit erc1155/erc1155-batch now parse only the token address before asking for the application address (src/commands/deposit/erc721.ts:49, erc1155.ts:47 and :116). The contract reads come after the prompt, so a wrong token address fails only after the prompt. erc20 still reads the token first. "Behavior Changes" mentions only the erc1155-batch length check.

Running the checks concurrently made every check that needs docker fail
on its own when docker is missing, and the RISC-V check had no mapping
of the docker errors, so it printed raw execa messages.

Each check now lists the checks it requires, and is reported as skipped
when one of them is not satisfied; the command prints only the checks
that ran. The docker errors are mapped by a single helper, so the RISC-V
check also says Buildx is missing. The checks still run concurrently and
every result is returned. DoctorCheck has a status instead of ok, to
tell a skipped check from a failed one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015SA64hXXCsNWisTYLVpEBn
The "Build and redeploy" of cartesi run used to run the build command,
which prints the accounts drive layout after building. It now calls the
build API, which returns the layout without printing it, so only
cartesi build printed it.

The printing moves to printBuildResult, which both commands call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015SA64hXXCsNWisTYLVpEBn
run() reported the [prt] warnings before starting the environment, and
the deploy at startup reported them again, so every warning was printed
twice when a machine snapshot existed.

The deploy at startup now uses the [prt] setup resolved and reported
before the environment started. A redeploy still resolves [prt] again
and reports its warnings, as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015SA64hXXCsNWisTYLVpEBn
Adds foreclose, refund and withdraw to the library API. The helpers the
commands kept, and their unit tests import, move to src/foreclose.ts,
src/refund.ts and src/withdraw.ts, with the tests pointed there.

As a library, cartesi-rollups-cli runs with --yes and --json, and its
output is returned. With stream it is attached to the terminal with the
transaction options as given, which the commands use. A failure the
attached command printed is thrown as a NodeCommandError, which is the
only error handleNodeCommandError now swallows, so an error from the
steps before the node command is still printed by the commands.

withdraw asks for the account only after the application is known to be
foreclosed, as before. The replay and proof steps follow the caller's
progress, silent by default.

addRecoveryOptions moves to src/commands/recovery.ts, keeping Commander
out of the modules the API uses, and getAnvilClient gets an explicit
return type, as the inferred one cannot be named from outside viem.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015SA64hXXCsNWisTYLVpEBn
depositErc721 compared the token owner read from the chain, which is
checksummed, with the sender as given, so a lowercase sender was told it
had no balance for a token it owned. The CLI wasn't affected, as it
checksums --from.

resolveConnection now checksums the application and the sender it is
given, which also rejects a malformed address before anything is sent,
for send and every deposit. The deposits checksum their token too, and
depositErc721 compares addresses whatever their case.

The erc721 deposit command reads the token again before asking for the
application, as it did before the deposits moved to the API, so a wrong
token address fails before the prompt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015SA64hXXCsNWisTYLVpEBn
depositSpinner was exported from api/deposit/common.ts, whose
declarations are part of the public types, so they referenced
import("ora").Ora. ora is a devDependency, which a consumer of the
library doesn't install, so type-checking with skipLibCheck: false
failed with "Cannot find module 'ora'".

The spinner and the application label, both internal to the deposits,
move to api/deposit/progress.ts, which no public declaration imports.
Checked by type-checking a project that installs the packed package,
with skipLibCheck: false, under nodenext and bundler resolution.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015SA64hXXCsNWisTYLVpEBn
The library build bundled its own copies of execa, semver, smol-toml and
viem, though they are installed as its dependencies. An error the
library threw from viem was then an instance of its private copy, so
instanceof HttpRequestError and BaseError were false with the consumer's
viem, and an app also using viem shipped it twice.

The library build now leaves them, and their subpaths, external.
dist/lib.js drops from 1031 KiB to 489 KiB. The CLI bundle and the
binaries still bundle everything, as they run without node_modules.

Checked with a project that installs the packed package: a deposit
against an unreachable RPC now throws an error that is an instance of
the project's HttpRequestError and BaseError.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015SA64hXXCsNWisTYLVpEBn

tuler commented Nov 16, 2026

Copy link
Copy Markdown
Member Author

@brunomenezes thanks for the thorough review. Each item now has its own commit:

  1. doctor messages (d1fd5a9): each check lists the checks it requires. If one of them failed, the check is reported as skipped and the command doesn't print it. Compose and Buildx require the Engine, and RISC-V requires the Engine and Buildx. One docker() helper now maps ENOENT to "Docker not found" and exit code 125 to the check's install message, so RISC-V gets a friendly message again. DoctorCheck is now { name, status: "ok" | "failed" | "skipped", detail?, message? }. The Cartesi Machine check still runs on its own, because a host cartesi-machine passes it without docker. So with Docker missing you'll still see its line after ✖ Docker not found.
  2. "Build and redeploy" layout (a3e19f7): printBuildResult() is now shared by cartesi build and the run shell, so the accounts drive layout and withdrawal config are printed again.
  3. PRT warnings printed twice (4b4c6d2): the startup deploy no longer resolves [prt] again or repeats its warnings. A redeploy from the shell still does both, as on the base branch.
  4. Recovery APIs (ab9e618): added foreclose(), refund() and withdraw(). By default they run cartesi-rollups-cli with --yes --json and return its parsed output. With stream: true they attach to the terminal with the transaction options, which is what the commands use. A failure the tool printed is thrown as NodeCommandError (with exitCode), and handleNodeCommandError now only swallows that error class. The command definitions are unchanged. The helpers the unit tests import moved to src/foreclose.ts, src/refund.ts and src/withdraw.ts, and the tests were repointed.
  5. ora in declarations (2aba933): depositSpinner and applicationLabel moved to an internal api/deposit/progress.ts that lib.ts doesn't export. The only external packages the public .d.ts graph now reaches are execa, smol-toml and viem.
  6. Bundled dependencies (5e073ca): the library build marks execa, semver, smol-toml and viem (and their subpaths) as external. The CLI bundle and the binaries stay self-contained. dist/lib.js went from about 1031 KiB to 489 KiB.
  7. Minor (ffd3356): resolveConnection checksums application and from with getAddress, so a malformed address is rejected early. erc721 compares owners with isAddressEqual, and the deposits checksum the token address. deposit erc721 reads the token before the application prompt again. A correction on 7b: on the base branch, erc1155 and erc1155-batch never read the contract before the prompt (parseToken returned the address and a fixed name), so I left their order as it was. Only erc721 had changed order.

Verification: typecheck, declaration emit, lint and the 555 unit tests pass at each commit. I used your npm pack method: an empty project with the tarball, TypeScript 7 and @types/node, skipLibCheck: false. It type-checks with 0 errors under both nodenext and bundler. The tarball from before these commits fails with Cannot find module 'ora'. In that project, a depositEther against an unreachable RPC now gives instanceof HttpRequestError and instanceof BaseError both true; before these commits both were false. The PR description is updated to match, including the "every command but the deprecated deploy" wording.

I had no Docker daemon, so I couldn't run the Docker-dependent paths: items 2 and 3 in cartesi run, the recovery commands end to end, and the integration suite. Could you rerun your side-by-side checks for those?


Generated by Claude Code

@brunomenezes

brunomenezes commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

@brunomenezes thanks for the thorough review. Each item now has its own commit:
...
I had no Docker daemon, so I couldn't run the Docker-dependent paths: items 2 and 3 in cartesi run, the recovery commands end to end, and the integration suite. Could you rerun your side-by-side checks for those?

Generated by Claude Code

I re-ran everything on 5e073ca, including the Docker-dependent paths you couldn't run. The side-by-side cartesi run --prt against alpha.42, the recovery commands and the integration suite (95 pass, 1 skipped). I also checked foreclose(), refund() and withdraw() from dist/lib.js against a devnet, and the tarball and doctor cases from my first comment. All seven points are resolved, and I found nothing new.

One small thing: when withdraw() is called for an account that isn't in the drive, the error is account not found: 0x… followed by the full usage text of cartesi-rollups-machine-tool. The CLI prints the same, so it's only cosmetic, but a library caller would probably want just the first line.

And you're right about erc1155. Sorry about that one.

I know it is a stacked PR, but are you going to make this one ready to review so we can merge? I will look the 514 later.

@tuler
tuler marked this pull request as ready for review November 24, 2026 15:09
@github-project-automation github-project-automation Bot moved this to 👍 Waiting Merge in Rollups Tooling Nov 24, 2026
@github-project-automation github-project-automation Bot moved this from Todo to Waiting Merge in Rollups SDK Nov 24, 2026
@tuler
tuler merged commit 9c31e38 into prerelease/v2-alpha Nov 24, 2026
4 checks passed
@tuler
tuler deleted the claude/cartesi-cli-library-api-2m3q2q branch November 24, 2026 17:15
@github-project-automation github-project-automation Bot moved this from Waiting Merge to Done in Rollups SDK Nov 24, 2026
@github-project-automation github-project-automation Bot moved this from 👍 Waiting Merge to 📦 Done in Rollups Tooling Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done
Status: 📦 Done

Development

Successfully merging this pull request may close these issues.

3 participants