Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changelog

## [5.15.0](https://github.com/devicecloud-dev/dcd-cli/compare/v5.14.1...v5.15.0) (2026-11-19)


### Features

* **artifacts:** download one flow's artifacts with --result-id or --flow ([#338](https://github.com/devicecloud-dev/dcd-cli/issues/338)) ([3659af3](https://github.com/devicecloud-dev/dcd-cli/commit/3659af364f989a97ec092a31a6bf8b2ee24460de))
* **device:** keep agents to their own device sessions ([#340](https://github.com/devicecloud-dev/dcd-cli/issues/340)) ([74e951f](https://github.com/devicecloud-dev/dcd-cli/commit/74e951f5b1e51231a6b84ae3c4e2e2c51cb48ace))
* **device:** save full-size PNG screenshots ([#343](https://github.com/devicecloud-dev/dcd-cli/issues/343)) ([1325da8](https://github.com/devicecloud-dev/dcd-cli/commit/1325da84e96b2e84d8922e6930c5cc00bab88aa8))


### Bug Fixes

* **artifacts:** fail on an incomplete ZIP instead of reporting success ([#337](https://github.com/devicecloud-dev/dcd-cli/issues/337)) ([e4b18b2](https://github.com/devicecloud-dev/dcd-cli/commit/e4b18b2c9cdbbc352cd96eb76074a4524a7298e2))
* **device:** make dcd device safer to script and to drive from an agent ([#341](https://github.com/devicecloud-dev/dcd-cli/issues/341)) ([860ffb8](https://github.com/devicecloud-dev/dcd-cli/commit/860ffb8c14a9cd1bb8031a33dc6490707befb34b))

## [5.14.1](https://github.com/devicecloud-dev/dcd-cli/compare/v5.14.0...v5.14.1) (2026-11-17)


Expand Down
4 changes: 2 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Top-level `defineCommand` in `src/index.ts` wires fourteen subcommands (`cloud`,

**Flag composition.** Flag definitions are split by domain in `src/config/flags/*.flags.ts` (api, binary, device, environment, execution, github, output) and re-exported as a single `flags` object from `src/constants.ts`. Commands that need the full cloud surface spread `...flags` into their citty `args`; subset commands import individual flag groups.

**`dcd device` (Agent Devices).** Cloud device sessions that a person or an AI agent leases, drives and releases, over the API's `/device/sessions` routes (`src/gateways/device-gateway.ts`). Its rules differ from the other commands, and scripts and agents depend on them: `--json` prints one envelope, `{ ok, session, data, error }`, even on failure (`runDeviceCommand` in `src/utils/device-output.ts` prints it, so the top-level `{ status, error }` never appears); exit codes are 0 ok, 1 usage, 2 failed, 3 limit, 4 session ended or not found (`DEVICE_EXIT`); the session id may be left out when exactly one session is open (`resolveSessionId`); progress goes to stderr and there is no spinner unless stdin and stdout are TTYs. `DeviceApiError` keeps the API's machine code (`LIVE_NOT_FOUND`, …) and the `session` block an error carries, which `ApiError` drops.
**`dcd device` (Agent Devices).** Cloud device sessions that a person or an AI agent leases, drives and releases, over the API's `/device/sessions` routes (`src/gateways/device-gateway.ts`). Its rules differ from the other commands, and scripts and agents depend on them: `--json` prints one envelope, `{ ok, session, data, error }`, even on failure (`runDeviceCommand` in `src/utils/device-output.ts` prints it, so the top-level `{ status, error }` never appears); exit codes are 0 ok, 1 usage, 2 failed, 3 limit, 4 session ended or not found (`DEVICE_EXIT`); the session id may be left out when exactly one session of yours is open (`resolveSessionId`; `artifacts` takes your most recent one, ended or not), and one given must look like a session id (`checkSessionId`); progress goes to stderr and there is no spinner unless stdin and stdout are TTYs. Every subcommand refuses a flag it does not define (`strictFlags` in `src/utils/device-flags.ts`), since citty ignores unknown ones, and an unknown subcommand under `--json` still gets the envelope (`deviceCommand.setup`). Waits ask again through failed polls (`pollOnce`), and a wait for a flow ends with its session. `DeviceApiError` keeps the API's machine code (`LIVE_NOT_FOUND`, …) and the `session` block an error carries, which `ApiError` drops.

**Output rendering.** All human-facing output goes through `src/utils/ui.ts` (the canonical layer: `section`/`branch`/`fields`/`status`/`success`/`info`/`warn`) on top of `src/utils/styling.ts` (`colors`, `symbols`, `statusPalette`). The visual language is a Claude Code-style tree (`⏺` section headings, `⎿` branch groups). Commands must not hand-roll layouts from `colors`/`symbols` or call `console.log`; the `--json` result goes through `logger.json`. Every command takes `--json` (`jsonFlag`), and `src/index.ts` turns thrown errors into `{ status: 'FAILED', error }` whenever `--json` is in argv. Full rules and a cookbook live in `STYLE_GUIDE.md`.

Expand All @@ -53,7 +53,7 @@ Top-level `defineCommand` in `src/index.ts` wires fourteen subcommands (`cloud`,

**MCP server.** `src/mcp/` is a third front-end onto the same service layer (a sibling to `src/commands/`), shipped as the `dcd-mcp` bin over stdio transport (`@modelcontextprotocol/sdk`, `zod` schemas). `index.ts` boots the server; `server.ts` registers tools; `context.ts` resolves auth + API URL **lazily**, and again when a `dcd login` session nears expiry (so `tools/list` works unauthenticated, auth errors surface as tool errors rather than a boot crash, and a long-lived server outlasts the one-hour access token) via the same `resolveAuth`/`resolveApiUrl` as the CLI — `DEVICE_CLOUD_API_KEY` env or stored `dcd login` session, with `DCD_API_URL` to override. **Critical invariant: stdout is the JSON-RPC channel** — tools must never call the `src/commands/*` layer or `utils/cli` `logger` (both write to stdout / can `process.exit`); they call services/gateways directly with `logStderr` and return data via `helpers.ts` `jsonResult`/`errorResult`. The `runTool` wrapper records `mcp tool …` telemetry and converts thrown errors to `isError` results. Tools: `dcd_list_devices`, `dcd_list_runs`, `dcd_get_status`, `dcd_download_artifacts`, `dcd_get_team_settings` (read-only), and `dcd_run_cloud_test` (billable — gated out by `--read-only` / `DCD_MCP_READONLY=1`, annotated destructive, async-by-default). `dcd_run_cloud_test` reuses `computeCommonRoot`/`buildTestMetadataMap` from `src/services/flow-paths.ts` (extracted from `cloud.ts` so both build identical server-side paths). Registry manifest: `server.json` at repo root.

**`dcd mcp` (the bridge).** A second stdio entry point, `src/mcp/bridge.ts`, run by the `dcd mcp` command. It is a low-level `Server` that routes between two MCP clients: the `dcd_*` tools from the same in-process `createServer()` (over an in-memory transport), and the device tools proxied from the hosted `<api>/mcp`, so those are defined and contract-tested once, in the dcd API. It adds the inputs only a local process can serve: `install_app` takes `app_path` (uploaded with `uploadLocalApp`) and `run` takes `path` (a file is sent as `yaml`, a directory is uploaded as a flow bundle). Credentials are the CLI's (`getContext`): the hosted `/mcp` accepts an API key or a `dcd login` session with `x-dcd-org`. One connection is shared, and its `fetch` re-reads the auth headers from `getContext()` on every request, so a renewed session is picked up without remaking the connection (which would close it under a `run` still going). If the hosted endpoint can't be reached, it serves the `dcd_*` tools only and says why on stderr. Read-only mode keeps only device tools annotated `readOnlyHint`. `dcd-mcp` itself is unchanged.
**`dcd mcp` (the bridge).** A second stdio entry point, `src/mcp/bridge.ts`, run by the `dcd mcp` command. It is a low-level `Server` that routes between two MCP clients: the `dcd_*` tools from the same in-process `createServer()` (over an in-memory transport), and the device tools proxied from the hosted `<api>/mcp`, so those are defined and contract-tested once, in the dcd API. It adds the inputs only a local process can serve: `start_device` and `install_app` take `app_path` (uploaded with `uploadLocalApp`, before the session starts for `start_device`) and `run` takes `path` (a file that uses no other files is sent as `yaml`; one that does, or a directory, is uploaded as a flow bundle of only what the entry reaches). `take_screenshot` with `full_size: true` takes `path` too: the hosted tool answers with a link to the PNG, which the bridge downloads there (`saveFullScreenshot`). Those paths, `app_path`, and what `dcd_download_artifacts` writes, must be inside the working directory, and a write never replaces a file the server did not write (`src/mcp/local-files.ts`). When the device tools can't be listed it lists `load_device_tools` instead, whose description says why, and sends `tools/list_changed` once they load. Credentials are the CLI's (`getContext`): the hosted `/mcp` accepts an API key or a `dcd login` session with `x-dcd-org`. One connection is shared, and its `fetch` re-reads the auth headers from `getContext()` on every request, so a renewed session is picked up without remaking the connection (which would close it under a `run` still going). If the hosted endpoint can't be reached, it serves the `dcd_*` tools only and says why on stderr. Read-only mode keeps only device tools annotated `readOnlyHint`. `dcd-mcp` itself is unchanged.

**`dcd mcp install [client]`** (`src/utils/mcp-install.ts`) adds the server to Claude Code (`claude mcp add --scope user`), VS Code (`code --add-mcp`), or Claude Desktop / Cursor (merges an entry into their JSON config, and refuses a file that isn't plain JSON rather than rewrite it). Entries always start dcd by **full path**, since desktop apps opened from the Dock don't read the shell rc that puts `~/.dcd/bin` on PATH: the standalone binary is `process.execPath`; an npm install is node (`stableNodePath`, the PATH entry rather than Homebrew's versioned Cellar path) plus `argv[1]` as started, not resolved. It refuses to run from source or from the npx cache. Note citty runs a parent's `run` **after** its subcommand, so `mcpCommand.run` returns early when a positional is present — without that, `dcd mcp install` would go on to start a server.

Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ $ codex mcp add devicecloud -- dcd mcp

If you use the npm package instead of the standalone binary, the command is `npx` with `"args": ["-y", "@devicecloud.dev/dcd", "mcp"]`. That needs Node 22 or newer on the app's PATH, and it checks npm each time it starts.

It signs in the same way as the CLI: with your `dcd login` session, which it renews as it runs, or with `DEVICE_CLOUD_API_KEY`. Point it at a non-prod environment with `DCD_API_URL`.
It signs in the same way as the CLI: with your `dcd login` session, which it renews as it runs, or with `DEVICE_CLOUD_API_KEY`. Point it at a non-prod environment with `DCD_API_URL` (https, or plain http to `localhost` only).

The tools that take a local path read and write only inside the folder the server was started in, so start it from your project: a flow given to `run` (with the files it uses), and the files `dcd_download_artifacts` writes, which never replace a file the server did not write.

### Tools

Expand All @@ -116,7 +118,7 @@ It signs in the same way as the CLI: with your `dcd login` session, which it ren
| `dcd_list_devices` | Discover available devices, OS versions, and Maestro versions |
| `dcd_list_runs` | List recent test runs (filter by name/date, paginated) |
| `dcd_get_status` | Get the status + per-test results of a run |
| `dcd_download_artifacts` | Download a run's artifacts/report to disk |
| `dcd_download_artifacts` | Download a run's artifacts/report to disk, inside the working directory |
| `dcd_get_team_settings` | Read your team's settings: concurrency, test runtime, integrations and more |
| `dcd_run_cloud_test` | Submit a flow to run on the cloud (**billable**) |

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"test:unit": "node scripts/test-runner.mjs --unit",
"typecheck": "tsc --noEmit -p tsconfig.test.json"
},
"version": "5.14.1",
"version": "5.15.0",
"bugs": {
"url": "https://discord.gg/gm3mJwcNw8"
},
Expand Down
4 changes: 2 additions & 2 deletions server.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
"name": "dev.devicecloud/dcd",
"description": "Run Maestro mobile app tests on devicecloud.dev: submit flows, check status, download artifacts.",
"version": "5.14.1",
"version": "5.15.0",
"repository": {
"url": "https://github.com/devicecloud-dev/dcd-cli",
"source": "github"
Expand All @@ -11,7 +11,7 @@
{
"registryType": "npm",
"identifier": "@devicecloud.dev/dcd",
"version": "5.14.1",
"version": "5.15.0",
"runtimeHint": "npx",
"runtimeArguments": [
{
Expand Down
59 changes: 56 additions & 3 deletions src/commands/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { apiFlags } from '../config/flags/api.flags.js';
import { jsonFlag } from '../config/flags/output.flags.js';
import {
type DownloadResult,
downloadsSucceeded,
ReportDownloadService,
reportFormatDeprecation,
} from '../services/report-download.service.js';
Expand Down Expand Up @@ -42,6 +43,16 @@ export const artifactsCommand = defineCommand({
description:
'Custom file path for downloaded artifacts (default: ./artifacts.zip). Requires --download-artifacts.',
},
'result-id': {
type: 'string',
description:
"Download only this result's artifacts: its flow's attempts on that one device. Requires --download-artifacts.",
},
flow: {
type: 'string',
description:
'Download only the artifacts of the flow with this file path or name (e.g. flows/login.yaml or login). Fails, listing the result ids, when it matches more than one result, e.g. one per device. Requires --download-artifacts.',
},
report: {
type: 'string',
description:
Expand Down Expand Up @@ -75,6 +86,8 @@ export const artifactsCommand = defineCommand({
'download-artifacts',
);
const artifactsPath = args['artifacts-path'] as string | undefined;
const resultIdArg = args['result-id'] as string | undefined;
const flow = args.flow as string | undefined;
const report = validateEnum(
args.report as string | undefined,
REPORT_OPTIONS,
Expand Down Expand Up @@ -108,6 +121,8 @@ export const artifactsCommand = defineCommand({
);
}

const resultId = parseResultFilter(resultIdArg, flow, Boolean(downloadArtifacts));

const service = new ReportDownloadService();
const downloads: DownloadResult[] = [];

Expand All @@ -118,7 +133,9 @@ export const artifactsCommand = defineCommand({
artifactsPath: artifactsPath ?? './artifacts.zip',
debug,
downloadType: downloadArtifacts,
flow,
logger: log,
resultId,
uploadId,
warnLogger: (m: string) => logger.warn(m),
}));
Expand All @@ -140,13 +157,49 @@ export const artifactsCommand = defineCommand({
if (result) downloads.push(result);
}

// Downloading is this command's only job, so a failed or incomplete
// download exits 1, with or without --json. Its warning is already
// printed, and fail() prints nothing more (no second JSON object).
const ok = downloadsSucceeded(downloads);
if (json) {
const ok = downloads.some((d) => d.ok);
logger.json({ status: ok ? 'SUCCESS' : 'FAILED', uploadId, downloads });
// Same exit code a thrown error would give, without a second JSON object.
if (!ok) logger.fail('Every download failed', 1);
}

if (!ok) logger.fail('Download failed', 1);
},
});

/**
* Check --result-id and --flow: at most one, only with --download-artifacts,
* and a result id that is a positive whole number. Returns the parsed id.
*/
export function parseResultFilter(
resultIdArg: string | undefined,
flow: string | undefined,
downloadingArtifacts: boolean,
): number | undefined {
if (resultIdArg !== undefined && flow !== undefined) {
throw new CliError(
'--result-id cannot also be provided when using --flow (flags are mutually exclusive).',
);
}

const flag = resultIdArg === undefined ? (flow === undefined ? undefined : '--flow') : '--result-id';
if (flag && !downloadingArtifacts) {
throw new CliError(`${flag} requires --download-artifacts.`);
}

if (flow !== undefined && flow.trim() === '') {
throw new CliError('--flow needs a flow file path or name.');
}

if (resultIdArg === undefined) return undefined;
const resultId = Number(resultIdArg);
if (!/^\d+$/.test(resultIdArg.trim()) || !Number.isSafeInteger(resultId) || resultId <= 0) {
throw new CliError(`--result-id must be a positive whole number, got '${resultIdArg}'.`);
}

return resultId;
}

export default artifactsCommand;
Loading
Loading