@devicecloud.dev/dcd 5.12.0 → 5.13.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -40
- package/dist/commands/cloud.d.ts +1 -1
- package/dist/commands/cloud.js +5 -2
- package/dist/commands/device.js +183 -1
- package/dist/commands/mcp.js +26 -5
- package/dist/config/flags/execution.flags.d.ts +9 -1
- package/dist/config/flags/execution.flags.js +9 -1
- package/dist/constants.d.ts +1 -1
- package/dist/gateways/cli-auth-gateway.d.ts +5 -1
- package/dist/gateways/cli-auth-gateway.js +32 -8
- package/dist/gateways/device-gateway.d.ts +6 -1
- package/dist/gateways/device-gateway.js +4 -0
- package/dist/mcp/bridge.js +21 -6
- package/dist/mcp/tools/run-cloud-test.js +7 -2
- package/dist/services/results-polling.service.js +4 -2
- package/dist/types/domain/device-session.types.d.ts +36 -0
- package/dist/types/domain/device-session.types.js +13 -0
- package/dist/types/domain/device.types.d.ts +0 -1
- package/dist/types/domain/device.types.js +0 -1
- package/dist/utils/cli.d.ts +4 -1
- package/dist/utils/cli.js +5 -2
- package/dist/utils/mcp-install.d.ts +9 -2
- package/dist/utils/mcp-install.js +12 -2
- package/dist/utils/tool-spawn.d.ts +21 -0
- package/dist/utils/tool-spawn.js +65 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -36,30 +36,32 @@ See full documentation: [Docs](https://docs.devicecloud.dev)
|
|
|
36
36
|
|
|
37
37
|
## MCP server
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
`dcd mcp` is an [MCP](https://modelcontextprotocol.io) server, so AI agents (Claude, Codex, Cursor, VS Code) can run cloud tests and read their results. You don't run it yourself. You add it to your MCP client's config, and the client starts it. It works the same on your machine and headless, such as in CI.
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
### Set it up with `dcd mcp install`
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
| --- | --- | --- | --- |
|
|
45
|
-
| **`dcd mcp`** (recommended) | the CLI | device tools + `dcd_*` cloud-test tools | you want everything, including installing a local build or running local flow files |
|
|
46
|
-
| **Hosted** `https://api.devicecloud.dev/mcp` | nothing | device tools | the agent only drives devices, with apps and flows that are already uploaded or at a URL |
|
|
47
|
-
| **`dcd-mcp`** | the CLI | `dcd_*` cloud-test tools | you only run cloud tests (the older server; `dcd mcp` covers it) |
|
|
43
|
+
Install the CLI (see the top of this page), sign in, then add the server to your AI tool:
|
|
48
44
|
|
|
49
|
-
|
|
45
|
+
```sh-session
|
|
46
|
+
$ dcd login
|
|
47
|
+
$ dcd mcp install cursor # or claude-code, claude-desktop, codex, vscode
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Leave out the client name to pick from a list. Add `--read-only` for a server that only offers tools that change nothing, or `--print` to see what would be added without changing anything. For Claude Code, Codex and VS Code it runs `claude mcp add`, `codex mcp add` and `code --add-mcp`. For Claude Desktop and Cursor it adds an entry to their JSON config file and keeps everything else in it. Restart the app afterwards.
|
|
50
51
|
|
|
51
|
-
|
|
52
|
+
### Headless, with an API key
|
|
52
53
|
|
|
53
|
-
|
|
54
|
+
For an agent that runs without you, such as in CI or a script, sign in with an API key instead of `dcd login`. Create one in the console under Settings → API Keys, and give it to the server as `DEVICE_CLOUD_API_KEY` in its environment. For example, for Claude Code in CI:
|
|
54
55
|
|
|
55
56
|
```sh-session
|
|
56
|
-
$ dcd
|
|
57
|
-
$ dcd mcp install cursor # or claude-code, claude-desktop, vscode
|
|
57
|
+
$ claude mcp add --scope user devicecloud -e DEVICE_CLOUD_API_KEY="$DEVICE_CLOUD_API_KEY" -- dcd mcp
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
In a JSON config, put it in the server's `env`: `"env": { "DEVICE_CLOUD_API_KEY": "<your-api-key>" }`. Store the key as a secret in your CI provider, never in the repository.
|
|
61
|
+
|
|
62
|
+
### Setting it up by hand
|
|
61
63
|
|
|
62
|
-
|
|
64
|
+
Start dcd by its **full path**. Desktop apps such as Claude Desktop and Cursor are usually opened from the Dock or Start menu, so they don't see the PATH your shell sets up, and a bare `dcd` gives "command not found". The installer prints the path at the end; it's `~/.dcd/bin/dcd` by default, written out in full because config files don't expand `~`.
|
|
63
65
|
|
|
64
66
|
Claude Desktop (`claude_desktop_config.json`) and Cursor (`~/.cursor/mcp.json`):
|
|
65
67
|
|
|
@@ -88,29 +90,42 @@ VS Code (`.vscode/mcp.json`, or the user `mcp.json`) uses `servers` and a `type`
|
|
|
88
90
|
}
|
|
89
91
|
```
|
|
90
92
|
|
|
91
|
-
|
|
93
|
+
Codex (`~/.codex/config.toml`, shared by the Codex CLI, IDE extension and desktop app):
|
|
94
|
+
|
|
95
|
+
```toml
|
|
96
|
+
[mcp_servers.devicecloud]
|
|
97
|
+
command = "/Users/you/.dcd/bin/dcd"
|
|
98
|
+
args = ["mcp"]
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Claude Code and the Codex CLI, run from a terminal, do see your PATH:
|
|
92
102
|
|
|
93
103
|
```sh-session
|
|
94
104
|
$ claude mcp add --scope user devicecloud -- dcd mcp
|
|
105
|
+
$ codex mcp add devicecloud -- dcd mcp
|
|
95
106
|
```
|
|
96
107
|
|
|
97
108
|
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.
|
|
98
109
|
|
|
99
|
-
It signs in the same way as the CLI:
|
|
110
|
+
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`.
|
|
100
111
|
|
|
101
|
-
|
|
112
|
+
### Tools
|
|
102
113
|
|
|
103
|
-
|
|
114
|
+
| Tool | What it does |
|
|
115
|
+
| --- | --- |
|
|
116
|
+
| `dcd_list_devices` | Discover available devices, OS versions, and Maestro versions |
|
|
117
|
+
| `dcd_list_runs` | List recent test runs (filter by name/date, paginated) |
|
|
118
|
+
| `dcd_get_status` | Get the status + per-test results of a run |
|
|
119
|
+
| `dcd_download_artifacts` | Download a run's artifacts/report to disk |
|
|
120
|
+
| `dcd_run_cloud_test` | Submit a flow to run on the cloud (**billable**) |
|
|
104
121
|
|
|
105
|
-
|
|
122
|
+
By default `dcd_run_cloud_test` is async: it returns an `uploadId` immediately, which you poll with `dcd_get_status`. Pass `wait: true` (bounded by `waitTimeoutSeconds`) to block until completion, or `dryRun: true` to preview the flows without submitting.
|
|
106
123
|
|
|
107
|
-
|
|
108
|
-
$ claude mcp add --transport http devicecloud https://api.devicecloud.dev/mcp
|
|
109
|
-
```
|
|
124
|
+
**Read-only mode.** `dcd_run_cloud_test` consumes test minutes, so it is annotated as non-read-only/destructive (clients can prompt before calling it). To hide it entirely, which is recommended for autonomous or untrusted agents, add `--read-only` after `mcp` in the args (or pass it to `dcd mcp install`), or set `DCD_MCP_READONLY=1` in `env`.
|
|
110
125
|
|
|
111
126
|
### `dcd-mcp`
|
|
112
127
|
|
|
113
|
-
The older server
|
|
128
|
+
The npm package also ships `dcd-mcp`, an older server with the same `dcd_*` tools. `dcd mcp` covers it, so you only need it for a setup that already uses it:
|
|
114
129
|
|
|
115
130
|
```jsonc
|
|
116
131
|
{
|
|
@@ -124,23 +139,7 @@ The older server, with the `dcd_*` tools only. Add it to your MCP client config:
|
|
|
124
139
|
}
|
|
125
140
|
```
|
|
126
141
|
|
|
127
|
-
`--package` matters: the package's default bin is `dcd`, so `npx @devicecloud.dev/dcd dcd-mcp` would run `dcd dcd-mcp` (an unknown command) instead of the server.
|
|
128
|
-
|
|
129
|
-
Auth is inherited from the CLI: set `DEVICE_CLOUD_API_KEY` as above, or run `dcd login` once and the server picks up the stored session. Point it at a non-prod environment with `DCD_API_URL`.
|
|
130
|
-
|
|
131
|
-
**`dcd_*` tools** (served by both `dcd mcp` and `dcd-mcp`)
|
|
132
|
-
|
|
133
|
-
| Tool | What it does |
|
|
134
|
-
| --- | --- |
|
|
135
|
-
| `dcd_list_devices` | Discover available devices, OS versions, and Maestro versions |
|
|
136
|
-
| `dcd_list_runs` | List recent test runs (filter by name/date, paginated) |
|
|
137
|
-
| `dcd_get_status` | Get the status + per-test results of a run |
|
|
138
|
-
| `dcd_download_artifacts` | Download a run's artifacts/report to disk |
|
|
139
|
-
| `dcd_run_cloud_test` | Submit a flow to run on the cloud (**billable**) |
|
|
140
|
-
|
|
141
|
-
**Read-only mode.** `dcd_run_cloud_test` consumes test minutes, so it is annotated as non-read-only/destructive (clients can prompt before calling it). To hide it entirely — recommended for autonomous or untrusted agents — pass `--read-only` at the end of `args` (`["-y", "--package=@devicecloud.dev/dcd", "dcd-mcp", "--read-only"]`), or set `DCD_MCP_READONLY=1` in `env`.
|
|
142
|
-
|
|
143
|
-
By default `dcd_run_cloud_test` is async: it returns an `uploadId` immediately, which you poll with `dcd_get_status`. Pass `wait: true` (bounded by `waitTimeoutSeconds`) to block until completion, or `dryRun: true` to preview the flows without submitting.
|
|
142
|
+
`--package` matters: the package's default bin is `dcd`, so `npx @devicecloud.dev/dcd dcd-mcp` would run `dcd dcd-mcp` (an unknown command) instead of the server. It signs in like `dcd mcp`, and takes `--read-only` and `DCD_MCP_READONLY=1` the same way.
|
|
144
143
|
|
|
145
144
|
|
|
146
145
|
## Development
|
package/dist/commands/cloud.d.ts
CHANGED
|
@@ -141,7 +141,7 @@ export declare const cloudCommand: import("citty").CommandDef<{
|
|
|
141
141
|
readonly 'runner-type': {
|
|
142
142
|
readonly type: "string";
|
|
143
143
|
readonly default: "default";
|
|
144
|
-
readonly description: "[experimental] The type of runner to use (options: default, m4, m1,
|
|
144
|
+
readonly description: "[experimental] The type of runner to use (options: default, m4, m1, cpu1) - note: anything other than default or cpu1 will incur premium pricing tiers. See https://docs.devicecloud.dev/configuration/runner-type for more information.";
|
|
145
145
|
};
|
|
146
146
|
readonly env: {
|
|
147
147
|
readonly type: "string";
|
package/dist/commands/cloud.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { defineCommand } from 'citty';
|
|
3
3
|
import { existsSync } from 'node:fs';
|
|
4
4
|
import * as path from 'node:path';
|
|
5
|
+
import { RETIRED_RUNNER_TYPES, RUNNER_TYPE_OPTIONS, } from '../config/flags/execution.flags.js';
|
|
5
6
|
import { flags as allFlags } from '../constants.js';
|
|
6
7
|
import { ApiGateway } from '../gateways/api-gateway.js';
|
|
7
8
|
import { uploadBinary, uploadFlowZip, verifyAppZip, writeJSONFile, } from '../methods.js';
|
|
@@ -42,7 +43,6 @@ process.on('warning', (warning) => {
|
|
|
42
43
|
const DOWNLOAD_OPTIONS = ['ALL', 'FAILED'];
|
|
43
44
|
const REPORT_OPTIONS = ['allure', 'html', 'html-detailed', 'junit'];
|
|
44
45
|
const ORIENTATION_OPTIONS = ['0', '90'];
|
|
45
|
-
const RUNNER_TYPE_OPTIONS = ['default', 'm4', 'm1', 'gpu1', 'cpu1'];
|
|
46
46
|
const PRIORITY_OPTIONS = ['low', 'normal', 'high'];
|
|
47
47
|
const RENDER_ENGINE_OPTIONS = ['lavapipe', 'swiftshader'];
|
|
48
48
|
/**
|
|
@@ -168,7 +168,10 @@ export const cloudCommand = defineCommand({
|
|
|
168
168
|
let quiet = Boolean(args.quiet);
|
|
169
169
|
const report = validateEnum(args.report, REPORT_OPTIONS, 'report');
|
|
170
170
|
let retry = parseIntFlag(args.retry, 'retry');
|
|
171
|
-
const runnerType = validateEnum(args['runner-type'], RUNNER_TYPE_OPTIONS, 'runner-type'
|
|
171
|
+
const runnerType = validateEnum(args['runner-type'], RUNNER_TYPE_OPTIONS, 'runner-type',
|
|
172
|
+
// gpu1 still validates so old scripts keep working; the API runs it
|
|
173
|
+
// on cpu1.
|
|
174
|
+
RETIRED_RUNNER_TYPES) ?? 'default';
|
|
172
175
|
const renderEngine = validateEnum(args['render-engine'], RENDER_ENGINE_OPTIONS, 'render-engine');
|
|
173
176
|
const showCrosshairs = Boolean(args['show-crosshairs']);
|
|
174
177
|
const maestroChromeOnboarding = Boolean(args['maestro-chrome-onboarding']);
|
package/dist/commands/device.js
CHANGED
|
@@ -5,7 +5,7 @@ import { resolve as resolvePath } from 'node:path';
|
|
|
5
5
|
import { apiFlags } from '../config/flags/api.flags.js';
|
|
6
6
|
import { jsonFlag } from '../config/flags/output.flags.js';
|
|
7
7
|
import { DeviceApiError, DeviceGateway, START_RECOVERY_WINDOW_MS, startOutcomeUnknown, } from '../gateways/device-gateway.js';
|
|
8
|
-
import { ENDED_STATES, } from '../types/domain/device-session.types.js';
|
|
8
|
+
import { DEVICE_KEYS, ENDED_STATES, SWIPE_DIRECTIONS, } from '../types/domain/device-session.types.js';
|
|
9
9
|
import { platformOfAppFile, uploadLocalApp } from '../utils/app-upload.js';
|
|
10
10
|
import { refreshAuth, resolveAuth } from '../utils/auth.js';
|
|
11
11
|
import { openBrowser } from '../utils/browser.js';
|
|
@@ -580,6 +580,184 @@ const launchSub = defineCommand({
|
|
|
580
580
|
});
|
|
581
581
|
},
|
|
582
582
|
});
|
|
583
|
+
/** Shared by the typed-action subcommands: the Maestro switch. */
|
|
584
|
+
const maestroArg = {
|
|
585
|
+
type: 'boolean',
|
|
586
|
+
default: false,
|
|
587
|
+
description: 'Run the action as a Maestro flow instead of directly on the device',
|
|
588
|
+
};
|
|
589
|
+
/** A percentage of the screen from a flag value, or a usage error. */
|
|
590
|
+
function percentArg(value, flag) {
|
|
591
|
+
const n = typeof value === 'number' ? value : Number(value);
|
|
592
|
+
if (typeof value === 'boolean' || value === '' || !Number.isFinite(n) || n < 0 || n > 100) {
|
|
593
|
+
throw new CliError(`--${flag} must be a number from 0 to 100 (a percentage of the screen).`, 1);
|
|
594
|
+
}
|
|
595
|
+
return n;
|
|
596
|
+
}
|
|
597
|
+
/** "x,y" (percentages) from a flag value, or a usage error. */
|
|
598
|
+
function pointArg(value, flag) {
|
|
599
|
+
const parts = typeof value === 'string' ? value.split(',') : [];
|
|
600
|
+
if (parts.length !== 2) {
|
|
601
|
+
throw new CliError(`--${flag} must be "x,y", percentages of the screen, e.g. --${flag} 50,80.`, 1);
|
|
602
|
+
}
|
|
603
|
+
return { x: percentArg(parts[0].trim(), flag), y: percentArg(parts[1].trim(), flag) };
|
|
604
|
+
}
|
|
605
|
+
/**
|
|
606
|
+
* Send one typed action and print its outcome, the way `launch` does: exit 2
|
|
607
|
+
* with the result when the device could not do it.
|
|
608
|
+
*/
|
|
609
|
+
async function performAction(args, id, body, labels) {
|
|
610
|
+
const ctx = await context(args);
|
|
611
|
+
const sessionId = await resolveSessionId(ctx.apiUrl, ctx.auth, id);
|
|
612
|
+
const { result, session } = await DeviceGateway.action(ctx.apiUrl, ctx.auth, sessionId, {
|
|
613
|
+
...body,
|
|
614
|
+
...(args.maestro ? { mode: 'maestro' } : {}),
|
|
615
|
+
});
|
|
616
|
+
return {
|
|
617
|
+
session,
|
|
618
|
+
data: { result },
|
|
619
|
+
...(!result.success && {
|
|
620
|
+
failure: { code: null, message: result.error || labels.failed },
|
|
621
|
+
}),
|
|
622
|
+
print() {
|
|
623
|
+
logger.log(result.success ? ui.success(labels.done) : `${ui.statusSymbol('FAILED')} ${labels.failed}`);
|
|
624
|
+
if (result.error)
|
|
625
|
+
logger.log(colors.error(result.error));
|
|
626
|
+
},
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
const tapSub = defineCommand({
|
|
630
|
+
meta: { name: 'tap', description: 'Tap an element by text or id, or a point on the screen' },
|
|
631
|
+
args: {
|
|
632
|
+
...commonArgs,
|
|
633
|
+
id: idArg,
|
|
634
|
+
text: { type: 'string', description: 'The element\'s text, label or hint, matched whole, ignoring case' },
|
|
635
|
+
rid: { type: 'string', description: 'The element\'s resource id (rid in `dcd device inspect`)' },
|
|
636
|
+
x: { type: 'string', description: 'With --y: a point, as percentages of the screen (0-100)' },
|
|
637
|
+
y: { type: 'string', description: 'See --x' },
|
|
638
|
+
maestro: maestroArg,
|
|
639
|
+
},
|
|
640
|
+
async run({ args }) {
|
|
641
|
+
const json = Boolean(args.json);
|
|
642
|
+
await runDeviceCommand(json, async () => {
|
|
643
|
+
const targets = [
|
|
644
|
+
args.text !== undefined,
|
|
645
|
+
args.rid !== undefined,
|
|
646
|
+
args.x !== undefined || args.y !== undefined,
|
|
647
|
+
].filter(Boolean).length;
|
|
648
|
+
if (targets !== 1) {
|
|
649
|
+
throw new CliError('tap takes exactly one target: --text, --rid, or --x and --y.', 1);
|
|
650
|
+
}
|
|
651
|
+
const body = args.text !== undefined
|
|
652
|
+
? { type: 'tap', text: String(args.text) }
|
|
653
|
+
: args.rid !== undefined
|
|
654
|
+
? { type: 'tap', id: String(args.rid) }
|
|
655
|
+
: { type: 'tap', x: percentArg(args.x, 'x'), y: percentArg(args.y, 'y') };
|
|
656
|
+
const what = args.text !== undefined
|
|
657
|
+
? `"${String(args.text)}"`
|
|
658
|
+
: args.rid !== undefined
|
|
659
|
+
? `id ${String(args.rid)}`
|
|
660
|
+
: `${String(args.x)}%,${String(args.y)}%`;
|
|
661
|
+
return performAction(args, args.id, body, {
|
|
662
|
+
done: `Tapped ${what}`,
|
|
663
|
+
failed: `Tap ${what} failed`,
|
|
664
|
+
});
|
|
665
|
+
});
|
|
666
|
+
},
|
|
667
|
+
});
|
|
668
|
+
const typeSub = defineCommand({
|
|
669
|
+
meta: { name: 'type', description: 'Type text into the focused field' },
|
|
670
|
+
args: {
|
|
671
|
+
...commonArgs,
|
|
672
|
+
id: idArg,
|
|
673
|
+
// Not `required`: citty would reject a missing value before runDeviceCommand,
|
|
674
|
+
// and --json would then print the top-level error instead of the envelope.
|
|
675
|
+
text: { type: 'string', description: 'What to type' },
|
|
676
|
+
sensitive: {
|
|
677
|
+
type: 'boolean',
|
|
678
|
+
default: false,
|
|
679
|
+
description: 'The text is a secret: stored encrypted, never shown, masked in the output',
|
|
680
|
+
},
|
|
681
|
+
maestro: maestroArg,
|
|
682
|
+
},
|
|
683
|
+
async run({ args }) {
|
|
684
|
+
const json = Boolean(args.json);
|
|
685
|
+
await runDeviceCommand(json, async () => {
|
|
686
|
+
const text = String(args.text ?? '');
|
|
687
|
+
if (!text)
|
|
688
|
+
throw new CliError('--text must not be empty.', 1);
|
|
689
|
+
const shown = args.sensitive ? `${text.length} character(s)` : `"${text}"`;
|
|
690
|
+
return performAction(args, args.id, { type: 'type', text, ...(args.sensitive ? { sensitive: true } : {}) }, { done: `Typed ${shown}`, failed: `Typing ${shown} failed` });
|
|
691
|
+
});
|
|
692
|
+
},
|
|
693
|
+
});
|
|
694
|
+
const isDirection = (value) => typeof value === 'string' && SWIPE_DIRECTIONS.includes(value);
|
|
695
|
+
const swipeSub = defineCommand({
|
|
696
|
+
meta: { name: 'swipe', description: 'Swipe up, down, left or right, or from one point to another' },
|
|
697
|
+
args: {
|
|
698
|
+
...commonArgs,
|
|
699
|
+
id: idArg,
|
|
700
|
+
direction: {
|
|
701
|
+
type: 'positional',
|
|
702
|
+
required: false,
|
|
703
|
+
description: 'up, down, left or right (a swipe across most of the screen)',
|
|
704
|
+
},
|
|
705
|
+
from: { type: 'string', description: 'With --to: where the swipe starts, as "x,y" percentages' },
|
|
706
|
+
to: { type: 'string', description: 'Where it ends, as "x,y" percentages' },
|
|
707
|
+
maestro: maestroArg,
|
|
708
|
+
},
|
|
709
|
+
async run({ args }) {
|
|
710
|
+
const json = Boolean(args.json);
|
|
711
|
+
await runDeviceCommand(json, async () => {
|
|
712
|
+
let id = args.id;
|
|
713
|
+
let direction = args.direction;
|
|
714
|
+
// `dcd device swipe up`: the one positional is the direction, not a session.
|
|
715
|
+
if (id && !direction && isDirection(id))
|
|
716
|
+
[id, direction] = [undefined, id];
|
|
717
|
+
const byPoints = args.from !== undefined || args.to !== undefined;
|
|
718
|
+
if ((direction === undefined) === !byPoints) {
|
|
719
|
+
throw new CliError('swipe takes a direction (up, down, left, right), or --from and --to.', 1);
|
|
720
|
+
}
|
|
721
|
+
let body;
|
|
722
|
+
let what;
|
|
723
|
+
if (direction !== undefined) {
|
|
724
|
+
if (!isDirection(direction)) {
|
|
725
|
+
throw new CliError(`direction must be one of ${SWIPE_DIRECTIONS.join(', ')}.`, 1);
|
|
726
|
+
}
|
|
727
|
+
body = { type: 'swipe', direction };
|
|
728
|
+
what = direction;
|
|
729
|
+
}
|
|
730
|
+
else {
|
|
731
|
+
body = { type: 'swipe', from: pointArg(args.from, 'from'), to: pointArg(args.to, 'to') };
|
|
732
|
+
what = `${String(args.from)} to ${String(args.to)}`;
|
|
733
|
+
}
|
|
734
|
+
return performAction(args, id, body, { done: `Swiped ${what}`, failed: `Swipe ${what} failed` });
|
|
735
|
+
});
|
|
736
|
+
},
|
|
737
|
+
});
|
|
738
|
+
const pressKeySub = defineCommand({
|
|
739
|
+
meta: { name: 'press-key', description: `Press a key: ${DEVICE_KEYS.join(', ')}` },
|
|
740
|
+
args: {
|
|
741
|
+
...commonArgs,
|
|
742
|
+
id: idArg,
|
|
743
|
+
key: { type: 'positional', required: false, description: `One of ${DEVICE_KEYS.join(', ')}` },
|
|
744
|
+
maestro: maestroArg,
|
|
745
|
+
},
|
|
746
|
+
async run({ args }) {
|
|
747
|
+
const json = Boolean(args.json);
|
|
748
|
+
await runDeviceCommand(json, async () => {
|
|
749
|
+
let id = args.id;
|
|
750
|
+
let key = args.key;
|
|
751
|
+
// `dcd device press-key back`: the one positional is the key, not a session.
|
|
752
|
+
if (id && !key && DEVICE_KEYS.includes(id))
|
|
753
|
+
[id, key] = [undefined, id];
|
|
754
|
+
if (!key || !DEVICE_KEYS.includes(key)) {
|
|
755
|
+
throw new CliError(`key must be one of ${DEVICE_KEYS.join(', ')}.`, 1);
|
|
756
|
+
}
|
|
757
|
+
return performAction(args, id, { type: 'press_key', key }, { done: `Pressed ${key}`, failed: `Press ${key} failed` });
|
|
758
|
+
});
|
|
759
|
+
},
|
|
760
|
+
});
|
|
583
761
|
const modelsSub = defineCommand({
|
|
584
762
|
meta: { name: 'models', description: 'The devices a session can ask for' },
|
|
585
763
|
args: {
|
|
@@ -1171,6 +1349,10 @@ export const deviceCommand = defineCommand({
|
|
|
1171
1349
|
stop: stopSub,
|
|
1172
1350
|
install: installSub,
|
|
1173
1351
|
launch: launchSub,
|
|
1352
|
+
tap: tapSub,
|
|
1353
|
+
type: typeSub,
|
|
1354
|
+
swipe: swipeSub,
|
|
1355
|
+
'press-key': pressKeySub,
|
|
1174
1356
|
models: modelsSub,
|
|
1175
1357
|
inspect: inspectSub,
|
|
1176
1358
|
screenshot: screenshotSub,
|
package/dist/commands/mcp.js
CHANGED
|
@@ -11,18 +11,26 @@ import { apiKeyOverride } from '../utils/auth.js';
|
|
|
11
11
|
import { canPrompt } from '../utils/ci.js';
|
|
12
12
|
import { CliError, getInstallMethod, logger } from '../utils/cli.js';
|
|
13
13
|
import { readConfig } from '../utils/config-store.js';
|
|
14
|
-
import { CLIENT_LABELS, claudeCodeAddArgs, clientConfigPath, MCP_CLIENTS, mcpServersSnippet, SERVER_NAME, serverLaunch, shellLine, stableNodePath, vscodeAddArgs, writeClientConfig, } from '../utils/mcp-install.js';
|
|
14
|
+
import { CLIENT_LABELS, claudeCodeAddArgs, clientConfigPath, codexAddArgs, MCP_CLIENTS, mcpServersSnippet, SERVER_NAME, serverLaunch, shellLine, stableNodePath, vscodeAddArgs, writeClientConfig, } from '../utils/mcp-install.js';
|
|
15
15
|
import { colors } from '../utils/styling.js';
|
|
16
|
+
import { toolSpawn } from '../utils/tool-spawn.js';
|
|
16
17
|
import { ui } from '../utils/ui.js';
|
|
17
18
|
const RELOAD_HINT = {
|
|
18
19
|
'claude-code': 'Start a new Claude Code session to load it.',
|
|
19
20
|
'claude-desktop': 'Restart Claude Desktop to load it.',
|
|
21
|
+
codex: 'Start a new Codex session to load it.',
|
|
20
22
|
cursor: 'Restart Cursor, or reload its MCP servers, to load it.',
|
|
21
23
|
vscode: 'VS Code asks you to trust the server the first time it starts.',
|
|
22
24
|
};
|
|
23
25
|
/** Run another tool's CLI without a shell. Undefined when it isn't installed. */
|
|
24
26
|
function runTool(command, args) {
|
|
25
|
-
const
|
|
27
|
+
const spawn = toolSpawn(command, args);
|
|
28
|
+
if (!spawn)
|
|
29
|
+
return undefined;
|
|
30
|
+
const result = spawnSync(spawn.command, spawn.args, {
|
|
31
|
+
encoding: 'utf8',
|
|
32
|
+
windowsVerbatimArguments: spawn.windowsVerbatimArguments,
|
|
33
|
+
});
|
|
26
34
|
if (result.error?.code === 'ENOENT')
|
|
27
35
|
return undefined;
|
|
28
36
|
return { ok: result.status === 0, output: `${result.stdout ?? ''}${result.stderr ?? ''}`.trim() };
|
|
@@ -57,6 +65,17 @@ function install(client, launch) {
|
|
|
57
65
|
throw new CliError(`claude mcp add failed: ${added.output}`);
|
|
58
66
|
return { target: shellLine('claude', add), replaced: removed.ok };
|
|
59
67
|
}
|
|
68
|
+
if (client === 'codex') {
|
|
69
|
+
const add = codexAddArgs(launch);
|
|
70
|
+
const removed = runTool('codex', ['mcp', 'remove', SERVER_NAME]);
|
|
71
|
+
if (!removed) {
|
|
72
|
+
throw new CliError(`The codex command isn't on PATH. Run this where it is:\n ${shellLine('codex', add)}`);
|
|
73
|
+
}
|
|
74
|
+
const added = runTool('codex', add);
|
|
75
|
+
if (!added.ok)
|
|
76
|
+
throw new CliError(`codex mcp add failed: ${added.output}`);
|
|
77
|
+
return { target: shellLine('codex', add), replaced: removed.ok };
|
|
78
|
+
}
|
|
60
79
|
if (client === 'vscode') {
|
|
61
80
|
const add = vscodeAddArgs(launch);
|
|
62
81
|
const added = runTool('code', add);
|
|
@@ -77,6 +96,8 @@ function install(client, launch) {
|
|
|
77
96
|
function preview(client, launch) {
|
|
78
97
|
if (client === 'claude-code')
|
|
79
98
|
return { target: 'command', text: shellLine('claude', claudeCodeAddArgs(launch)) };
|
|
99
|
+
if (client === 'codex')
|
|
100
|
+
return { target: 'command', text: shellLine('codex', codexAddArgs(launch)) };
|
|
80
101
|
if (client === 'vscode')
|
|
81
102
|
return { target: 'command', text: shellLine('code', vscodeAddArgs(launch)) };
|
|
82
103
|
return {
|
|
@@ -87,7 +108,7 @@ function preview(client, launch) {
|
|
|
87
108
|
const installSub = defineCommand({
|
|
88
109
|
meta: {
|
|
89
110
|
name: 'install',
|
|
90
|
-
description: 'Add the DeviceCloud MCP server to Claude Code, Claude Desktop, Cursor or VS Code',
|
|
111
|
+
description: 'Add the DeviceCloud MCP server to Claude Code, Claude Desktop, Codex, Cursor or VS Code',
|
|
91
112
|
},
|
|
92
113
|
args: {
|
|
93
114
|
client: {
|
|
@@ -138,7 +159,7 @@ const installSub = defineCommand({
|
|
|
138
159
|
}
|
|
139
160
|
logger.log(ui.success(`${result.replaced ? 'Updated' : 'Added'} DeviceCloud in ${CLIENT_LABELS[client]}`));
|
|
140
161
|
const rows = [
|
|
141
|
-
[client === 'claude-code' || client === 'vscode' ? 'ran' : 'wrote', result.target],
|
|
162
|
+
[client === 'claude-code' || client === 'codex' || client === 'vscode' ? 'ran' : 'wrote', result.target],
|
|
142
163
|
['starts', colors.highlight(shellLine(launch.command, launch.args))],
|
|
143
164
|
];
|
|
144
165
|
logger.log(ui.branch(ui.fields(rows)));
|
|
@@ -157,7 +178,7 @@ const installSub = defineCommand({
|
|
|
157
178
|
export const mcpCommand = defineCommand({
|
|
158
179
|
meta: {
|
|
159
180
|
name: 'mcp',
|
|
160
|
-
description: 'MCP server for AI agents, started by your MCP client (Claude, Cursor, VS Code)',
|
|
181
|
+
description: 'MCP server for AI agents, started by your MCP client (Claude, Codex, Cursor, VS Code)',
|
|
161
182
|
},
|
|
162
183
|
args: {
|
|
163
184
|
'read-only': {
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/** The runner types offered in help text, error messages and the MCP schema. */
|
|
2
|
+
export declare const RUNNER_TYPE_OPTIONS: readonly ["default", "m4", "m1", "cpu1"];
|
|
3
|
+
/**
|
|
4
|
+
* Runner types that were removed but are still accepted, so scripts that pass
|
|
5
|
+
* them keep working. gpu1 was removed on 9 November 2026 and the API runs it
|
|
6
|
+
* on cpu1. Never offered anywhere a user picks from.
|
|
7
|
+
*/
|
|
8
|
+
export declare const RETIRED_RUNNER_TYPES: readonly ["gpu1"];
|
|
1
9
|
/**
|
|
2
10
|
* Test execution and flow management flags
|
|
3
11
|
*/
|
|
@@ -45,6 +53,6 @@ export declare const executionFlags: {
|
|
|
45
53
|
readonly 'runner-type': {
|
|
46
54
|
readonly type: "string";
|
|
47
55
|
readonly default: "default";
|
|
48
|
-
readonly description: "[experimental] The type of runner to use (options: default, m4, m1,
|
|
56
|
+
readonly description: "[experimental] The type of runner to use (options: default, m4, m1, cpu1) - note: anything other than default or cpu1 will incur premium pricing tiers. See https://docs.devicecloud.dev/configuration/runner-type for more information.";
|
|
49
57
|
};
|
|
50
58
|
};
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/** The runner types offered in help text, error messages and the MCP schema. */
|
|
2
|
+
export const RUNNER_TYPE_OPTIONS = ['default', 'm4', 'm1', 'cpu1'];
|
|
3
|
+
/**
|
|
4
|
+
* Runner types that were removed but are still accepted, so scripts that pass
|
|
5
|
+
* them keep working. gpu1 was removed on 9 November 2026 and the API runs it
|
|
6
|
+
* on cpu1. Never offered anywhere a user picks from.
|
|
7
|
+
*/
|
|
8
|
+
export const RETIRED_RUNNER_TYPES = ['gpu1'];
|
|
1
9
|
/**
|
|
2
10
|
* Test execution and flow management flags
|
|
3
11
|
*/
|
|
@@ -45,6 +53,6 @@ export const executionFlags = {
|
|
|
45
53
|
'runner-type': {
|
|
46
54
|
type: 'string',
|
|
47
55
|
default: 'default',
|
|
48
|
-
description: '[experimental] The type of runner to use (options: default, m4, m1,
|
|
56
|
+
description: '[experimental] The type of runner to use (options: default, m4, m1, cpu1) - note: anything other than default or cpu1 will incur premium pricing tiers. See https://docs.devicecloud.dev/configuration/runner-type for more information.',
|
|
49
57
|
},
|
|
50
58
|
};
|
package/dist/constants.d.ts
CHANGED
|
@@ -127,7 +127,7 @@ export declare const flags: {
|
|
|
127
127
|
readonly 'runner-type': {
|
|
128
128
|
readonly type: "string";
|
|
129
129
|
readonly default: "default";
|
|
130
|
-
readonly description: "[experimental] The type of runner to use (options: default, m4, m1,
|
|
130
|
+
readonly description: "[experimental] The type of runner to use (options: default, m4, m1, cpu1) - note: anything other than default or cpu1 will incur premium pricing tiers. See https://docs.devicecloud.dev/configuration/runner-type for more information.";
|
|
131
131
|
};
|
|
132
132
|
readonly env: {
|
|
133
133
|
readonly type: "string";
|
|
@@ -8,7 +8,11 @@ import type { StoredSession } from '../utils/config-store.js';
|
|
|
8
8
|
*/
|
|
9
9
|
export declare class SessionRefreshError extends Error {
|
|
10
10
|
readonly definitive: boolean;
|
|
11
|
-
|
|
11
|
+
/** Supabase Auth's error code (`session_expired`, …), when it sent one. */
|
|
12
|
+
readonly code?: string | undefined;
|
|
13
|
+
constructor(message: string, definitive: boolean,
|
|
14
|
+
/** Supabase Auth's error code (`session_expired`, …), when it sent one. */
|
|
15
|
+
code?: string | undefined);
|
|
12
16
|
}
|
|
13
17
|
export interface RefreshedSession {
|
|
14
18
|
access_token: string;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Does not talk to the dcd API — the dcd-side session exchange lives in the
|
|
6
6
|
* login command's PKCE rendezvous flow (see src/commands/login.ts).
|
|
7
7
|
*/
|
|
8
|
-
import { createClient, isAuthApiError } from '@supabase/supabase-js';
|
|
8
|
+
import { createClient, isAuthApiError, isAuthSessionMissingError } from '@supabase/supabase-js';
|
|
9
9
|
import { getSupabaseKey } from '../config/supabase-key.js';
|
|
10
10
|
/**
|
|
11
11
|
* Thrown when a session refresh fails. `definitive` distinguishes "Supabase
|
|
@@ -15,12 +15,30 @@ import { getSupabaseKey } from '../config/supabase-key.js';
|
|
|
15
15
|
*/
|
|
16
16
|
export class SessionRefreshError extends Error {
|
|
17
17
|
definitive;
|
|
18
|
-
|
|
18
|
+
code;
|
|
19
|
+
constructor(message, definitive,
|
|
20
|
+
/** Supabase Auth's error code (`session_expired`, …), when it sent one. */
|
|
21
|
+
code) {
|
|
19
22
|
super(message);
|
|
20
23
|
this.definitive = definitive;
|
|
24
|
+
this.code = code;
|
|
21
25
|
this.name = 'SessionRefreshError';
|
|
22
26
|
}
|
|
23
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* What to tell the user for the refusals that have a plain cause. Supabase
|
|
30
|
+
* Auth answers `session_expired` once a session passes the project's maximum
|
|
31
|
+
* length or inactivity timeout, and `session_not_found` /
|
|
32
|
+
* `refresh_token_not_found` once the session has been ended (signed out
|
|
33
|
+
* elsewhere, revoked, or removed after expiring). Any other refusal keeps
|
|
34
|
+
* Supabase's own message.
|
|
35
|
+
*/
|
|
36
|
+
const SIGNED_OUT = 'Your session was signed out. Run `dcd login` to sign in again.';
|
|
37
|
+
const REFRESH_REFUSAL_MESSAGES = new Map([
|
|
38
|
+
['session_expired', 'Your session expired. Run `dcd login` to sign in again.'],
|
|
39
|
+
['session_not_found', SIGNED_OUT],
|
|
40
|
+
['refresh_token_not_found', SIGNED_OUT],
|
|
41
|
+
]);
|
|
24
42
|
function client(supabaseUrl, supabaseKey) {
|
|
25
43
|
return createClient(supabaseUrl, supabaseKey, {
|
|
26
44
|
auth: { persistSession: false, autoRefreshToken: false, detectSessionInUrl: false },
|
|
@@ -44,12 +62,18 @@ export const CliAuthGateway = {
|
|
|
44
62
|
if (error || !data.session || !data.user) {
|
|
45
63
|
// 4xx from GoTrue means the token itself was rejected; anything else
|
|
46
64
|
// (fetch failure, 5xx) could succeed on retry with the same token.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
65
|
+
// supabase-js turns GoTrue's `session_not_found` into an
|
|
66
|
+
// AuthSessionMissingError rather than an AuthApiError (it throws the same
|
|
67
|
+
// for an empty refresh token); only `dcd login` fixes either.
|
|
68
|
+
const apiError = error != null && isAuthApiError(error) ? error : undefined;
|
|
69
|
+
const sessionMissing = error != null && isAuthSessionMissingError(error);
|
|
70
|
+
const definitive = sessionMissing ||
|
|
71
|
+
(apiError !== undefined && apiError.status >= 400 && apiError.status < 500);
|
|
72
|
+
const code = apiError?.code ?? (sessionMissing ? 'session_not_found' : undefined);
|
|
73
|
+
const known = definitive && code ? REFRESH_REFUSAL_MESSAGES.get(code) : undefined;
|
|
74
|
+
throw new SessionRefreshError(known ??
|
|
75
|
+
`Failed to refresh session: ${error?.message ?? 'no session returned'}. ` +
|
|
76
|
+
`Run \`dcd login\` again.`, definitive, code);
|
|
53
77
|
}
|
|
54
78
|
const s = data.session;
|
|
55
79
|
const u = data.user;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AuthContext } from '../types/domain/auth.types.js';
|
|
2
|
-
import type { DeviceArtifactsPage, DeviceBundleUploadUrls,
|
|
2
|
+
import type { DeviceActionRequest, DeviceArtifactsPage, DeviceBundleUploadUrls, DeviceCatalogue, DeviceCommandResult, DeviceFlowBundle, DeviceHumanStatus, DeviceInstalledApp, DeviceLogs, DeviceRunResponse, DeviceScreen, DeviceScreenshot, DeviceSession, StartDeviceSessionRequest } from '../types/domain/device-session.types.js';
|
|
3
3
|
/**
|
|
4
4
|
* An error answer from /device/sessions. Unlike ApiError it keeps the API's
|
|
5
5
|
* machine code (`LIVE_NOT_FOUND`, `LIVE_SPEND_CAP`, …) and the `session`
|
|
@@ -83,6 +83,11 @@ export declare const DeviceGateway: {
|
|
|
83
83
|
human: DeviceHumanStatus;
|
|
84
84
|
session: DeviceSession;
|
|
85
85
|
}>;
|
|
86
|
+
/** One typed action: tap, type, swipe or press_key. Synchronous: answers with the outcome. */
|
|
87
|
+
action(baseUrl: string, auth: AuthContext, id: string, body: DeviceActionRequest): Promise<{
|
|
88
|
+
result: DeviceCommandResult;
|
|
89
|
+
session: DeviceSession;
|
|
90
|
+
}>;
|
|
86
91
|
run(baseUrl: string, auth: AuthContext, id: string, body: {
|
|
87
92
|
env?: Record<string, string>;
|
|
88
93
|
flow?: string;
|
|
@@ -157,6 +157,10 @@ export const DeviceGateway = {
|
|
|
157
157
|
requestHuman(baseUrl, auth, id, reason) {
|
|
158
158
|
return request(baseUrl, auth, 'POST', `${sessionPath(id)}/request-human`, { reason });
|
|
159
159
|
},
|
|
160
|
+
/** One typed action: tap, type, swipe or press_key. Synchronous: answers with the outcome. */
|
|
161
|
+
action(baseUrl, auth, id, body) {
|
|
162
|
+
return request(baseUrl, auth, 'POST', `${sessionPath(id)}/actions`, body);
|
|
163
|
+
},
|
|
160
164
|
run(baseUrl, auth, id, body) {
|
|
161
165
|
return request(baseUrl, auth, 'POST', `${sessionPath(id)}/run`, body);
|
|
162
166
|
},
|
package/dist/mcp/bridge.js
CHANGED
|
@@ -31,14 +31,20 @@ import { uploadFlowBundle } from '../utils/device-bundle.js';
|
|
|
31
31
|
import { getContext, isReadOnly, logStderr } from './context.js';
|
|
32
32
|
import { errorResult, runTool } from './helpers.js';
|
|
33
33
|
import { createServer } from './server.js';
|
|
34
|
-
|
|
34
|
+
/*
|
|
35
|
+
* Sent at initialize, before this server knows which hosted tools the
|
|
36
|
+
* account has: the hosted server only serves its tools to organizations that
|
|
37
|
+
* have them. So these name only the dcd_* tools, and the hosted tools explain
|
|
38
|
+
* themselves in their own descriptions.
|
|
39
|
+
*/
|
|
40
|
+
const INSTRUCTIONS = 'DeviceCloud tools. dcd_* tools run Maestro test suites in the cloud: dcd_list_devices shows what you can test on, dcd_run_cloud_test submits flows (billable), and dcd_get_status follows a run. Any other tools describe their own use. Where a tool takes a path to a local file (an app build, a flow file or a directory), this server uploads it for you.';
|
|
35
41
|
/**
|
|
36
42
|
* How long one forwarded call may take. Longer than dcd_run_cloud_test's
|
|
37
43
|
* longest wait (3600s) plus an upload. The MCP client calling this server
|
|
38
44
|
* still applies its own timeout, and its cancel is passed through.
|
|
39
45
|
*/
|
|
40
46
|
export const CALL_TIMEOUT_MS = 2 * 60 * 60 * 1000;
|
|
41
|
-
const READ_ONLY_INSTRUCTIONS = 'DeviceCloud tools, read-only: nothing here
|
|
47
|
+
const READ_ONLY_INSTRUCTIONS = 'DeviceCloud tools, read-only: nothing here runs a test or changes anything. dcd_* tools read cloud test runs and their results. Any other tools describe their own use.';
|
|
42
48
|
/** The inputs this bridge adds to hosted tools, and what they say. */
|
|
43
49
|
const LOCAL_INPUTS = {
|
|
44
50
|
install_app: {
|
|
@@ -187,7 +193,11 @@ class RemoteDevices {
|
|
|
187
193
|
async open() {
|
|
188
194
|
const { apiUrl } = await getContext();
|
|
189
195
|
const client = new Client({ name: 'dcd-mcp-bridge', version: getCliVersion() });
|
|
190
|
-
|
|
196
|
+
// In read-only mode, ask the hosted server for its read-only tools too, so
|
|
197
|
+
// it refuses the rest as well. The filter here stays for an API without
|
|
198
|
+
// the flag, which ignores it and lists every tool.
|
|
199
|
+
const url = new URL(`${apiUrl}/mcp${isReadOnly() ? '?read_only=true' : ''}`);
|
|
200
|
+
await client.connect(new StreamableHTTPClientTransport(url, {
|
|
191
201
|
fetch: async (url, init) => {
|
|
192
202
|
const { auth } = await getContext();
|
|
193
203
|
const headers = new Headers(init?.headers);
|
|
@@ -257,9 +267,14 @@ export async function createBridgeServer(opts = {}) {
|
|
|
257
267
|
}
|
|
258
268
|
return runTool(`device ${name}`, async () => {
|
|
259
269
|
await remote.list();
|
|
260
|
-
if (!remote.has(name))
|
|
261
|
-
|
|
262
|
-
|
|
270
|
+
if (!remote.has(name)) {
|
|
271
|
+
// In read-only mode the hosted server lists only its read-only tools,
|
|
272
|
+
// so a device tool that changes something is unknown here as well.
|
|
273
|
+
return errorResult(readOnly
|
|
274
|
+
? `Unknown tool: ${name}. In read-only mode this server offers only the tools that change nothing.`
|
|
275
|
+
: `Unknown tool: ${name}`);
|
|
276
|
+
}
|
|
277
|
+
// An API without the read-only flag lists every tool; refuse these here.
|
|
263
278
|
if (readOnly && !remote.isReadOnly(name)) {
|
|
264
279
|
return errorResult(`${name} is not available in read-only mode.`);
|
|
265
280
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as path from 'node:path';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
+
import { RETIRED_RUNNER_TYPES, RUNNER_TYPE_OPTIONS, } from '../../config/flags/execution.flags.js';
|
|
3
4
|
import { ApiGateway } from '../../gateways/api-gateway.js';
|
|
4
5
|
import { plan } from '../../services/execution-plan.service.js';
|
|
5
6
|
import { isSubmitEndpointMissing, submitWithRetry, } from '../../services/flow-submit.service.js';
|
|
@@ -81,10 +82,14 @@ export function registerRunCloudTest(server) {
|
|
|
81
82
|
excludeFlows: z.array(z.string()).optional().describe('Flow paths/patterns to exclude'),
|
|
82
83
|
maestroVersion: z.string().optional().describe('Pin a specific Maestro version'),
|
|
83
84
|
retry: z.number().int().min(0).max(2).optional().describe('Auto-retry failed tests (max 2)'),
|
|
85
|
+
// A retired runner type still validates, so an agent configured with
|
|
86
|
+
// one keeps working (the API runs gpu1 on cpu1), but the schema's
|
|
87
|
+
// `enum` lists only the current ones: zod metadata overrides it.
|
|
84
88
|
runnerType: z
|
|
85
|
-
.enum([
|
|
89
|
+
.enum([...RUNNER_TYPE_OPTIONS, ...RETIRED_RUNNER_TYPES])
|
|
90
|
+
.meta({ enum: [...RUNNER_TYPE_OPTIONS] })
|
|
86
91
|
.optional()
|
|
87
|
-
.describe('Runner type (default "default").
|
|
92
|
+
.describe('Runner type (default "default").'),
|
|
88
93
|
priority: z
|
|
89
94
|
.enum(['low', 'normal', 'high'])
|
|
90
95
|
.optional()
|
|
@@ -446,8 +446,10 @@ export class ResultsPollingService {
|
|
|
446
446
|
catch (error) {
|
|
447
447
|
if (isDefinitiveAuthFailure(error)) {
|
|
448
448
|
const reason = error instanceof Error ? error.message : String(error);
|
|
449
|
-
throw new PollingAuthError(
|
|
450
|
-
|
|
449
|
+
throw new PollingAuthError(
|
|
450
|
+
// The reason already says to run `dcd login`, so don't repeat it.
|
|
451
|
+
`${reason}\n\n` +
|
|
452
|
+
`The test is still running in the cloud. Once you've signed in again, reconnect with:\n dcd status --upload-id ${uploadId}`);
|
|
451
453
|
}
|
|
452
454
|
throw error;
|
|
453
455
|
}
|
|
@@ -99,6 +99,42 @@ export interface DeviceFlowResult {
|
|
|
99
99
|
file: null | string;
|
|
100
100
|
success: boolean;
|
|
101
101
|
}
|
|
102
|
+
export type DeviceSwipeDirection = 'down' | 'left' | 'right' | 'up';
|
|
103
|
+
export interface DevicePoint {
|
|
104
|
+
/** Percentages of the screen's width and height, 0 to 100. */
|
|
105
|
+
x: number;
|
|
106
|
+
y: number;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* One typed action for POST /device/sessions/:id/actions. `mode: 'maestro'`
|
|
110
|
+
* runs it as a Maestro flow instead of on the device directly.
|
|
111
|
+
*/
|
|
112
|
+
export type DeviceActionRequest = {
|
|
113
|
+
id?: string;
|
|
114
|
+
mode?: 'maestro';
|
|
115
|
+
text?: string;
|
|
116
|
+
type: 'tap';
|
|
117
|
+
x?: number;
|
|
118
|
+
y?: number;
|
|
119
|
+
} | {
|
|
120
|
+
key: string;
|
|
121
|
+
mode?: 'maestro';
|
|
122
|
+
type: 'press_key';
|
|
123
|
+
} | {
|
|
124
|
+
mode?: 'maestro';
|
|
125
|
+
sensitive?: boolean;
|
|
126
|
+
text: string;
|
|
127
|
+
type: 'type';
|
|
128
|
+
} | {
|
|
129
|
+
direction?: DeviceSwipeDirection;
|
|
130
|
+
from?: DevicePoint;
|
|
131
|
+
mode?: 'maestro';
|
|
132
|
+
to?: DevicePoint;
|
|
133
|
+
type: 'swipe';
|
|
134
|
+
};
|
|
135
|
+
/** The keys press_key takes, as the API names them. */
|
|
136
|
+
export declare const DEVICE_KEYS: readonly ["back", "home", "enter", "backspace", "tab", "volume_up", "volume_down", "lock", "power"];
|
|
137
|
+
export declare const SWIPE_DIRECTIONS: readonly DeviceSwipeDirection[];
|
|
102
138
|
/** The result of a typed action, a launch or a run. */
|
|
103
139
|
export interface DeviceCommandResult {
|
|
104
140
|
error?: string;
|
|
@@ -3,3 +3,16 @@
|
|
|
3
3
|
// dcd/api/src/apps/live/live.types.ts and device-sessions.controller.ts.
|
|
4
4
|
/** States a session can no longer leave. */
|
|
5
5
|
export const ENDED_STATES = ['released', 'expired', 'failed'];
|
|
6
|
+
/** The keys press_key takes, as the API names them. */
|
|
7
|
+
export const DEVICE_KEYS = [
|
|
8
|
+
'back',
|
|
9
|
+
'home',
|
|
10
|
+
'enter',
|
|
11
|
+
'backspace',
|
|
12
|
+
'tab',
|
|
13
|
+
'volume_up',
|
|
14
|
+
'volume_down',
|
|
15
|
+
'lock',
|
|
16
|
+
'power',
|
|
17
|
+
];
|
|
18
|
+
export const SWIPE_DIRECTIONS = ['up', 'down', 'left', 'right'];
|
|
@@ -18,7 +18,6 @@ export declare enum EiOSDevices {
|
|
|
18
18
|
'iphone-14' = "iphone-14",
|
|
19
19
|
'iphone-16' = "iphone-16",
|
|
20
20
|
'iphone-16-pro' = "iphone-16-pro",
|
|
21
|
-
'iphone-16-pro-max' = "iphone-16-pro-max",
|
|
22
21
|
'iphone-17' = "iphone-17",
|
|
23
22
|
'iphone-18-pro' = "iphone-18-pro",
|
|
24
23
|
'iphone-18-pro-max' = "iphone-18-pro-max",
|
|
@@ -19,7 +19,6 @@ export var EiOSDevices;
|
|
|
19
19
|
EiOSDevices["iphone-14"] = "iphone-14";
|
|
20
20
|
EiOSDevices["iphone-16"] = "iphone-16";
|
|
21
21
|
EiOSDevices["iphone-16-pro"] = "iphone-16-pro";
|
|
22
|
-
EiOSDevices["iphone-16-pro-max"] = "iphone-16-pro-max";
|
|
23
22
|
EiOSDevices["iphone-17"] = "iphone-17";
|
|
24
23
|
EiOSDevices["iphone-18-pro"] = "iphone-18-pro";
|
|
25
24
|
EiOSDevices["iphone-18-pro-max"] = "iphone-18-pro-max";
|
package/dist/utils/cli.d.ts
CHANGED
|
@@ -26,8 +26,11 @@ export declare function wantsJson(rawArgs: string[]): boolean;
|
|
|
26
26
|
/**
|
|
27
27
|
* Validate that a string flag value is one of the allowed options.
|
|
28
28
|
* Returns the value untouched on success; throws CliError otherwise.
|
|
29
|
+
*
|
|
30
|
+
* `unlisted` values are accepted too but left out of the error message: a
|
|
31
|
+
* retired option that old scripts may still pass, which nobody should pick.
|
|
29
32
|
*/
|
|
30
|
-
export declare function validateEnum<T extends string>(value: string | undefined, allowed: readonly T[], flagName: string): T | undefined;
|
|
33
|
+
export declare function validateEnum<T extends string, U extends string = never>(value: string | undefined, allowed: readonly T[], flagName: string, unlisted?: readonly U[]): T | U | undefined;
|
|
31
34
|
/**
|
|
32
35
|
* Coerce a flag value (possibly a single string, array, or undefined) into a
|
|
33
36
|
* flat string array. Comma-separated values inside each entry are split out.
|
package/dist/utils/cli.js
CHANGED
|
@@ -103,11 +103,14 @@ export function wantsJson(rawArgs) {
|
|
|
103
103
|
/**
|
|
104
104
|
* Validate that a string flag value is one of the allowed options.
|
|
105
105
|
* Returns the value untouched on success; throws CliError otherwise.
|
|
106
|
+
*
|
|
107
|
+
* `unlisted` values are accepted too but left out of the error message: a
|
|
108
|
+
* retired option that old scripts may still pass, which nobody should pick.
|
|
106
109
|
*/
|
|
107
|
-
export function validateEnum(value, allowed, flagName) {
|
|
110
|
+
export function validateEnum(value, allowed, flagName, unlisted = []) {
|
|
108
111
|
if (value === undefined || value === null || value === '')
|
|
109
112
|
return undefined;
|
|
110
|
-
if (!allowed.includes(value)) {
|
|
113
|
+
if (!allowed.includes(value) && !unlisted.includes(value)) {
|
|
111
114
|
throw new CliError(`Invalid value for --${flagName}: "${value}". Expected one of: ${allowed.join(', ')}`);
|
|
112
115
|
}
|
|
113
116
|
return value;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type InstallMethod } from './cli.js';
|
|
2
2
|
/** The server's name in every client's config. */
|
|
3
3
|
export declare const SERVER_NAME = "devicecloud";
|
|
4
|
-
export declare const MCP_CLIENTS: readonly ["claude-code", "claude-desktop", "cursor", "vscode"];
|
|
4
|
+
export declare const MCP_CLIENTS: readonly ["claude-code", "claude-desktop", "codex", "cursor", "vscode"];
|
|
5
5
|
export type McpClient = (typeof MCP_CLIENTS)[number];
|
|
6
6
|
export declare const CLIENT_LABELS: Record<McpClient, string>;
|
|
7
7
|
export interface ServerLaunch {
|
|
@@ -27,7 +27,8 @@ export declare function serverLaunch(opts: {
|
|
|
27
27
|
export declare function stableNodePath(execPath: string, pathEnv?: string | undefined, platform?: NodeJS.Platform): string;
|
|
28
28
|
/**
|
|
29
29
|
* The JSON config file a client reads, or undefined when it is configured
|
|
30
|
-
* through its own CLI (Claude Code, VS Code) or has no known location
|
|
30
|
+
* through its own CLI (Claude Code, Codex, VS Code) or has no known location
|
|
31
|
+
* here.
|
|
31
32
|
*/
|
|
32
33
|
export declare function clientConfigPath(client: McpClient, platform?: NodeJS.Platform, home?: string, env?: NodeJS.ProcessEnv): string | undefined;
|
|
33
34
|
/** The `mcpServers` block Claude Desktop and Cursor read, with ours in it. */
|
|
@@ -44,6 +45,12 @@ export declare function writeClientConfig(file: string, launch: ServerLaunch): {
|
|
|
44
45
|
};
|
|
45
46
|
/** `claude mcp add` arguments, at user scope so it works in every project. */
|
|
46
47
|
export declare function claudeCodeAddArgs(launch: ServerLaunch): string[];
|
|
48
|
+
/**
|
|
49
|
+
* `codex mcp add` arguments. Codex keeps MCP servers in ~/.codex/config.toml,
|
|
50
|
+
* which its CLI, IDE extension and desktop app share, so its own CLI writes
|
|
51
|
+
* the entry rather than this one parsing TOML.
|
|
52
|
+
*/
|
|
53
|
+
export declare function codexAddArgs(launch: ServerLaunch): string[];
|
|
47
54
|
/** `code --add-mcp` arguments, which add the server to the VS Code user profile. */
|
|
48
55
|
export declare function vscodeAddArgs(launch: ServerLaunch): string[];
|
|
49
56
|
/** A command line to show a person, quoting the parts that need it. */
|
|
@@ -12,10 +12,11 @@ import * as path from 'node:path';
|
|
|
12
12
|
import { CliError } from './cli.js';
|
|
13
13
|
/** The server's name in every client's config. */
|
|
14
14
|
export const SERVER_NAME = 'devicecloud';
|
|
15
|
-
export const MCP_CLIENTS = ['claude-code', 'claude-desktop', 'cursor', 'vscode'];
|
|
15
|
+
export const MCP_CLIENTS = ['claude-code', 'claude-desktop', 'codex', 'cursor', 'vscode'];
|
|
16
16
|
export const CLIENT_LABELS = {
|
|
17
17
|
'claude-code': 'Claude Code',
|
|
18
18
|
'claude-desktop': 'Claude Desktop',
|
|
19
|
+
codex: 'Codex',
|
|
19
20
|
cursor: 'Cursor',
|
|
20
21
|
vscode: 'VS Code',
|
|
21
22
|
};
|
|
@@ -66,7 +67,8 @@ export function stableNodePath(execPath, pathEnv = process.env.PATH, platform =
|
|
|
66
67
|
}
|
|
67
68
|
/**
|
|
68
69
|
* The JSON config file a client reads, or undefined when it is configured
|
|
69
|
-
* through its own CLI (Claude Code, VS Code) or has no known location
|
|
70
|
+
* through its own CLI (Claude Code, Codex, VS Code) or has no known location
|
|
71
|
+
* here.
|
|
70
72
|
*/
|
|
71
73
|
export function clientConfigPath(client, platform = process.platform, home = os.homedir(), env = process.env) {
|
|
72
74
|
if (client === 'cursor')
|
|
@@ -122,6 +124,14 @@ export function writeClientConfig(file, launch) {
|
|
|
122
124
|
export function claudeCodeAddArgs(launch) {
|
|
123
125
|
return ['mcp', 'add', '--scope', 'user', SERVER_NAME, '--', launch.command, ...launch.args];
|
|
124
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* `codex mcp add` arguments. Codex keeps MCP servers in ~/.codex/config.toml,
|
|
129
|
+
* which its CLI, IDE extension and desktop app share, so its own CLI writes
|
|
130
|
+
* the entry rather than this one parsing TOML.
|
|
131
|
+
*/
|
|
132
|
+
export function codexAddArgs(launch) {
|
|
133
|
+
return ['mcp', 'add', SERVER_NAME, '--', launch.command, ...launch.args];
|
|
134
|
+
}
|
|
125
135
|
/** `code --add-mcp` arguments, which add the server to the VS Code user profile. */
|
|
126
136
|
export function vscodeAddArgs(launch) {
|
|
127
137
|
return ['--add-mcp', JSON.stringify({ name: SERVER_NAME, ...launch })];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface ToolSpawn {
|
|
2
|
+
command: string;
|
|
3
|
+
args: string[];
|
|
4
|
+
/** Pass the arguments to cmd.exe as written, already quoted. */
|
|
5
|
+
windowsVerbatimArguments?: boolean;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* What to spawn for `command args`, or undefined when Windows has no such
|
|
9
|
+
* command on PATH. Elsewhere the command is spawned as given, and a missing
|
|
10
|
+
* one shows up as ENOENT.
|
|
11
|
+
*/
|
|
12
|
+
export declare function toolSpawn(command: string, args: string[], platform?: NodeJS.Platform, env?: NodeJS.ProcessEnv, exists?: (file: string) => boolean): ToolSpawn | undefined;
|
|
13
|
+
/** The file Windows would run for `command`: each PATH folder, each PATHEXT extension. */
|
|
14
|
+
export declare function findOnWindowsPath(command: string, env: NodeJS.ProcessEnv, exists: (file: string) => boolean): string | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* One argument for a batch file started by cmd.exe. First quote it the way
|
|
17
|
+
* the program's own parser expects (CommandLineToArgvW), then caret-escape
|
|
18
|
+
* every cmd character twice: once for the `cmd /c` line, and once more
|
|
19
|
+
* because the batch file passes it on with %*, which cmd parses again.
|
|
20
|
+
*/
|
|
21
|
+
export declare function cmdArgument(arg: string): string;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How to start another tool's CLI (`code`, `claude`) without a shell.
|
|
3
|
+
*
|
|
4
|
+
* On Windows these are often batch files (`code.cmd`, and npm's `claude.cmd`
|
|
5
|
+
* shim). Node's spawn searches PATH only for .com and .exe, and refuses to
|
|
6
|
+
* start a .cmd or .bat at all without a shell (CVE-2024-27980). So we find the
|
|
7
|
+
* file ourselves and, for a batch file, run it through cmd.exe with every
|
|
8
|
+
* argument escaped for cmd. This doesn't lean on how Node or Bun resolve
|
|
9
|
+
* commands, so the npm install and the standalone binary behave the same.
|
|
10
|
+
*/
|
|
11
|
+
import { existsSync } from 'node:fs';
|
|
12
|
+
import * as path from 'node:path';
|
|
13
|
+
import { CliError } from './cli.js';
|
|
14
|
+
/** Characters cmd.exe treats specially, each escaped with a caret. */
|
|
15
|
+
const CMD_META = /([ !"%&()*,;<>?[\]^`|])/g;
|
|
16
|
+
/**
|
|
17
|
+
* What to spawn for `command args`, or undefined when Windows has no such
|
|
18
|
+
* command on PATH. Elsewhere the command is spawned as given, and a missing
|
|
19
|
+
* one shows up as ENOENT.
|
|
20
|
+
*/
|
|
21
|
+
export function toolSpawn(command, args, platform = process.platform, env = process.env, exists = existsSync) {
|
|
22
|
+
if (platform !== 'win32')
|
|
23
|
+
return { command, args };
|
|
24
|
+
const file = findOnWindowsPath(command, env, exists);
|
|
25
|
+
if (!file)
|
|
26
|
+
return undefined;
|
|
27
|
+
if (!/\.(cmd|bat)$/i.test(file))
|
|
28
|
+
return { command: file, args };
|
|
29
|
+
// A line break ends cmd's line, and no escaping can stop that.
|
|
30
|
+
if (args.some((arg) => /[\0\n\r]/.test(arg))) {
|
|
31
|
+
throw new CliError(`Can't pass a line break to ${path.win32.basename(file)} through cmd.exe.`);
|
|
32
|
+
}
|
|
33
|
+
// /s strips the outer quotes and runs the rest as one line.
|
|
34
|
+
const line = [file.replace(CMD_META, '^$1'), ...args.map((arg) => cmdArgument(arg))].join(' ');
|
|
35
|
+
return {
|
|
36
|
+
command: env.ComSpec ?? env.COMSPEC ?? 'cmd.exe',
|
|
37
|
+
args: ['/d', '/s', '/c', `"${line}"`],
|
|
38
|
+
windowsVerbatimArguments: true,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/** The file Windows would run for `command`: each PATH folder, each PATHEXT extension. */
|
|
42
|
+
export function findOnWindowsPath(command, env, exists) {
|
|
43
|
+
const exts = (env.PATHEXT ?? env.Pathext ?? '.COM;.EXE;.BAT;.CMD').split(';').filter(Boolean);
|
|
44
|
+
const dirs = (env.PATH ?? env.Path ?? '').split(';').filter(Boolean);
|
|
45
|
+
const hasExt = exts.some((ext) => command.toLowerCase().endsWith(ext.toLowerCase()));
|
|
46
|
+
const names = hasExt ? [command] : exts.map((ext) => command + ext.toLowerCase());
|
|
47
|
+
for (const dir of dirs) {
|
|
48
|
+
for (const name of names) {
|
|
49
|
+
const candidate = path.win32.join(dir.replaceAll('"', ''), name);
|
|
50
|
+
if (exists(candidate))
|
|
51
|
+
return candidate;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* One argument for a batch file started by cmd.exe. First quote it the way
|
|
58
|
+
* the program's own parser expects (CommandLineToArgvW), then caret-escape
|
|
59
|
+
* every cmd character twice: once for the `cmd /c` line, and once more
|
|
60
|
+
* because the batch file passes it on with %*, which cmd parses again.
|
|
61
|
+
*/
|
|
62
|
+
export function cmdArgument(arg) {
|
|
63
|
+
const quoted = `"${arg.replaceAll(/(\\*)"/g, '$1$1\\"').replace(/(\\*)$/, '$1$1')}"`;
|
|
64
|
+
return quoted.replace(CMD_META, '^$1').replace(CMD_META, '^$1');
|
|
65
|
+
}
|