@devicecloud.dev/dcd 5.10.0 → 5.11.0-beta.10
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 +75 -3
- package/dist/commands/cloud.d.ts +1 -1
- package/dist/commands/cloud.js +7 -6
- package/dist/commands/device.d.ts +36 -0
- package/dist/commands/device.js +1151 -0
- package/dist/commands/live.d.ts +2 -0
- package/dist/commands/live.js +10 -1
- package/dist/commands/login.js +2 -17
- package/dist/commands/mcp.d.ts +13 -0
- package/dist/commands/mcp.js +180 -0
- package/dist/commands/upload.js +2 -8
- package/dist/config/flags/device.flags.d.ts +1 -1
- package/dist/config/flags/device.flags.js +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/gateways/device-gateway.d.ts +88 -0
- package/dist/gateways/device-gateway.js +140 -0
- package/dist/index.js +4 -0
- package/dist/mcp/bridge.d.ts +52 -0
- package/dist/mcp/bridge.js +288 -0
- package/dist/mcp/tools/run-cloud-test.d.ts +13 -0
- package/dist/mcp/tools/run-cloud-test.js +18 -8
- package/dist/methods.d.ts +24 -0
- package/dist/methods.js +147 -169
- package/dist/services/device-validation.service.js +1 -1
- package/dist/services/execution-plan.service.d.ts +27 -0
- package/dist/services/execution-plan.service.js +9 -1
- package/dist/services/metadata-extractor.service.d.ts +13 -0
- package/dist/services/metadata-extractor.service.js +35 -1
- package/dist/services/moropo.service.js +1 -1
- package/dist/services/results-polling.service.js +1 -1
- package/dist/types/domain/device-session.types.d.ts +211 -0
- package/dist/types/domain/device-session.types.js +5 -0
- package/dist/types/domain/device.types.d.ts +0 -2
- package/dist/types/domain/device.types.js +0 -2
- package/dist/types.d.ts +11 -0
- package/dist/utils/app-upload.d.ts +19 -0
- package/dist/utils/app-upload.js +63 -0
- package/dist/utils/auth.d.ts +0 -8
- package/dist/utils/auth.js +31 -27
- package/dist/utils/b2-retry.d.ts +49 -0
- package/dist/utils/b2-retry.js +77 -0
- package/dist/utils/browser.d.ts +16 -0
- package/dist/utils/browser.js +48 -0
- package/dist/utils/compatibility.d.ts +5 -7
- package/dist/utils/compatibility.js +5 -13
- package/dist/utils/device-artifacts.d.ts +55 -0
- package/dist/utils/device-artifacts.js +211 -0
- package/dist/utils/device-bundle.d.ts +35 -0
- package/dist/utils/device-bundle.js +162 -0
- package/dist/utils/device-matrix.js +1 -1
- package/dist/utils/device-output.d.ts +81 -0
- package/dist/utils/device-output.js +204 -0
- package/dist/utils/device-run.d.ts +29 -0
- package/dist/utils/device-run.js +113 -0
- package/dist/utils/mcp-install.d.ts +50 -0
- package/dist/utils/mcp-install.js +132 -0
- package/dist/utils/progress.d.ts +4 -0
- package/dist/utils/progress.js +45 -21
- package/package.json +2 -2
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { DeviceApiError, DeviceGateway } from '../gateways/device-gateway.js';
|
|
2
|
+
import { CliError, logger } from './cli.js';
|
|
3
|
+
import { colors, formatUrl } from './styling.js';
|
|
4
|
+
import { ui } from './ui.js';
|
|
5
|
+
/**
|
|
6
|
+
* Exit codes for `dcd device` (dcd docs/device-v1-plan.md, section 4.2).
|
|
7
|
+
* Scripts and agents branch on these, so they are a contract.
|
|
8
|
+
*/
|
|
9
|
+
export const DEVICE_EXIT = {
|
|
10
|
+
ok: 0,
|
|
11
|
+
/** Called wrongly: a bad flag, a bad value, or no session to pick. */
|
|
12
|
+
usage: 1,
|
|
13
|
+
/** It ran and failed: a flow or action failed, or the API could not do it. */
|
|
14
|
+
failed: 2,
|
|
15
|
+
/** A limit: concurrency, spend cap or rate limit. */
|
|
16
|
+
limit: 3,
|
|
17
|
+
/** The session has ended, or there is no such session. */
|
|
18
|
+
gone: 4,
|
|
19
|
+
};
|
|
20
|
+
const LIMIT_CODES = new Set(['LIVE_CONCURRENCY_LIMIT', 'LIVE_RATE_LIMITED', 'LIVE_SPEND_CAP']);
|
|
21
|
+
const GONE_CODES = new Set(['LIVE_NOT_FOUND', 'LIVE_SESSION_ENDED']);
|
|
22
|
+
const USAGE_CODES = new Set([
|
|
23
|
+
'LIVE_INVALID_ACTION',
|
|
24
|
+
'LIVE_INVALID_APP',
|
|
25
|
+
'LIVE_SESSION_REQUIRED',
|
|
26
|
+
]);
|
|
27
|
+
export function deviceExitCode(error) {
|
|
28
|
+
if (error instanceof DeviceApiError) {
|
|
29
|
+
if (error.code && GONE_CODES.has(error.code))
|
|
30
|
+
return DEVICE_EXIT.gone;
|
|
31
|
+
if (error.code && LIMIT_CODES.has(error.code))
|
|
32
|
+
return DEVICE_EXIT.limit;
|
|
33
|
+
if (error.code && USAGE_CODES.has(error.code))
|
|
34
|
+
return DEVICE_EXIT.usage;
|
|
35
|
+
if (error.status === 404)
|
|
36
|
+
return DEVICE_EXIT.gone;
|
|
37
|
+
if (error.status === 429)
|
|
38
|
+
return DEVICE_EXIT.limit;
|
|
39
|
+
if ([400, 401, 403].includes(error.status))
|
|
40
|
+
return DEVICE_EXIT.usage;
|
|
41
|
+
return DEVICE_EXIT.failed;
|
|
42
|
+
}
|
|
43
|
+
if (error instanceof CliError)
|
|
44
|
+
return error.exitCode;
|
|
45
|
+
return DEVICE_EXIT.failed;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Runs one `dcd device` command and prints its result: one envelope under
|
|
49
|
+
* --json, readable text otherwise. Errors leave with the matching exit code.
|
|
50
|
+
* Under --json the error is printed here, as an envelope, so the top-level
|
|
51
|
+
* handler's `{ status, error }` never appears.
|
|
52
|
+
*/
|
|
53
|
+
export async function runDeviceCommand(json, fn) {
|
|
54
|
+
let outcome;
|
|
55
|
+
try {
|
|
56
|
+
outcome = await fn();
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
const exitCode = deviceExitCode(error);
|
|
60
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
61
|
+
if (!json)
|
|
62
|
+
throw new CliError(message, exitCode);
|
|
63
|
+
const envelope = {
|
|
64
|
+
ok: false,
|
|
65
|
+
session: error instanceof DeviceApiError ? error.session : null,
|
|
66
|
+
data: null,
|
|
67
|
+
error: { code: error instanceof DeviceApiError ? error.code : null, message },
|
|
68
|
+
};
|
|
69
|
+
logger.json(envelope);
|
|
70
|
+
logger.fail(message, exitCode);
|
|
71
|
+
}
|
|
72
|
+
if (json) {
|
|
73
|
+
const envelope = {
|
|
74
|
+
ok: !outcome.failure,
|
|
75
|
+
...(outcome.session !== undefined && { session: outcome.session }),
|
|
76
|
+
data: outcome.data,
|
|
77
|
+
error: outcome.failure ?? null,
|
|
78
|
+
};
|
|
79
|
+
logger.json(envelope);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
outcome.print();
|
|
83
|
+
}
|
|
84
|
+
if (outcome.failure)
|
|
85
|
+
logger.fail(outcome.failure.message, DEVICE_EXIT.failed);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Progress for a person, on stderr, so stdout carries only the result. Off
|
|
89
|
+
* under --json. These are plain lines, never a spinner, so they read the same
|
|
90
|
+
* in a terminal, a CI log or an agent's tool output.
|
|
91
|
+
*/
|
|
92
|
+
export function deviceProgress(json) {
|
|
93
|
+
return (message) => {
|
|
94
|
+
if (!json)
|
|
95
|
+
process.stderr.write(`${message}\n`);
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* The default-session rule: `<id>` may be left out when the org has exactly
|
|
100
|
+
* one open session. With none, or several, the command is a usage error and
|
|
101
|
+
* lists what there is to choose from.
|
|
102
|
+
*/
|
|
103
|
+
export async function resolveSessionId(apiUrl, auth, given) {
|
|
104
|
+
const id = given?.trim();
|
|
105
|
+
if (id)
|
|
106
|
+
return id;
|
|
107
|
+
const { sessions } = await DeviceGateway.list(apiUrl, auth);
|
|
108
|
+
if (sessions.length === 1)
|
|
109
|
+
return sessions[0].id;
|
|
110
|
+
if (sessions.length === 0) {
|
|
111
|
+
throw new CliError('No open device session. Start one with `dcd device start --platform ios|android`.', DEVICE_EXIT.usage);
|
|
112
|
+
}
|
|
113
|
+
const candidates = sessions
|
|
114
|
+
.map((s) => ` ${s.id} ${s.platform} ${s.state}${s.client_label ? ` ${s.client_label}` : ''}`)
|
|
115
|
+
.join('\n');
|
|
116
|
+
throw new CliError(`${sessions.length} device sessions are open. Name one:\n${candidates}`, DEVICE_EXIT.usage);
|
|
117
|
+
}
|
|
118
|
+
export function formatSeconds(seconds) {
|
|
119
|
+
if (seconds < 60)
|
|
120
|
+
return `${seconds}s`;
|
|
121
|
+
const minutes = Math.floor(seconds / 60);
|
|
122
|
+
const rest = seconds % 60;
|
|
123
|
+
return rest ? `${minutes}m ${rest}s` : `${minutes}m`;
|
|
124
|
+
}
|
|
125
|
+
/** The rows that describe a session, for {@link ui.fields}. */
|
|
126
|
+
export function sessionFields(session) {
|
|
127
|
+
const fields = [
|
|
128
|
+
['session', colors.highlight(session.id)],
|
|
129
|
+
['state', session.release_reason ? `${session.state} (${session.release_reason})` : session.state],
|
|
130
|
+
['platform', session.platform],
|
|
131
|
+
];
|
|
132
|
+
if (session.model)
|
|
133
|
+
fields.push(['model', session.model]);
|
|
134
|
+
if (session.client_label)
|
|
135
|
+
fields.push(['client', session.client_label]);
|
|
136
|
+
if (session.queue) {
|
|
137
|
+
const position = session.queue.position === null ? '' : `#${session.queue.position}`;
|
|
138
|
+
const eta = session.queue.eta_s === null ? '' : `, about ${formatSeconds(session.queue.eta_s)}`;
|
|
139
|
+
fields.push(['queue', `${position || 'waiting'}${eta} (${session.queue.reason.replaceAll('_', ' ')})`]);
|
|
140
|
+
}
|
|
141
|
+
if (session.time_remaining_s !== null) {
|
|
142
|
+
fields.push(['time left', formatSeconds(session.time_remaining_s)]);
|
|
143
|
+
}
|
|
144
|
+
if (session.idle_remaining_s !== null) {
|
|
145
|
+
fields.push(['idle timeout', `in ${formatSeconds(session.idle_remaining_s)}`]);
|
|
146
|
+
}
|
|
147
|
+
if (session.cost_so_far_usd !== null) {
|
|
148
|
+
fields.push(['cost so far', `$${session.cost_so_far_usd.toFixed(2)}`]);
|
|
149
|
+
}
|
|
150
|
+
if (session.last_crash) {
|
|
151
|
+
fields.push(['last crash', colors.error(`${session.last_crash.summary} (${session.last_crash.at})`)]);
|
|
152
|
+
}
|
|
153
|
+
fields.push(['monitor', formatUrl(session.monitor_url)]);
|
|
154
|
+
return fields;
|
|
155
|
+
}
|
|
156
|
+
/** A session as a branch group, with its warnings after it. */
|
|
157
|
+
export function printSession(session) {
|
|
158
|
+
logger.log(ui.branch(ui.fields(sessionFields(session))));
|
|
159
|
+
for (const warning of session.warnings)
|
|
160
|
+
logger.log(ui.warn(warning));
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* An API timestamp for a person: how far off it is and the local time, e.g.
|
|
164
|
+
* "in 12m (14:32)" or "3m ago (14:17)". The text as given when unreadable.
|
|
165
|
+
*/
|
|
166
|
+
export function formatWhen(iso, now = Date.now()) {
|
|
167
|
+
const at = Date.parse(iso);
|
|
168
|
+
if (!Number.isFinite(at))
|
|
169
|
+
return iso;
|
|
170
|
+
const clock = new Date(at).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
|
171
|
+
const seconds = Math.round((at - now) / 1000);
|
|
172
|
+
if (Math.abs(seconds) < 5)
|
|
173
|
+
return `now (${clock})`;
|
|
174
|
+
return seconds > 0
|
|
175
|
+
? `in ${formatSeconds(seconds)} (${clock})`
|
|
176
|
+
: `${formatSeconds(-seconds)} ago (${clock})`;
|
|
177
|
+
}
|
|
178
|
+
/** Where the hand-over stands, in a few words. */
|
|
179
|
+
export function humanState(human) {
|
|
180
|
+
if (human.human_in_control)
|
|
181
|
+
return 'a person has control';
|
|
182
|
+
if (human.waiting)
|
|
183
|
+
return 'waiting for a person';
|
|
184
|
+
if (human.handed_back)
|
|
185
|
+
return 'handed back';
|
|
186
|
+
return 'no help asked for';
|
|
187
|
+
}
|
|
188
|
+
/** The rows that describe a request for a person, for {@link ui.fields}. */
|
|
189
|
+
export function humanFields(human, now = Date.now()) {
|
|
190
|
+
const fields = [['state', humanState(human)]];
|
|
191
|
+
if (human.reason)
|
|
192
|
+
fields.push(['reason', human.reason]);
|
|
193
|
+
if (human.since)
|
|
194
|
+
fields.push(['asked', formatWhen(human.since, now)]);
|
|
195
|
+
if (human.waiting && human.expires_at) {
|
|
196
|
+
fields.push(['ends', `${formatWhen(human.expires_at, now)} unless they hand it back`]);
|
|
197
|
+
}
|
|
198
|
+
if (human.handed_back && human.handed_back_at) {
|
|
199
|
+
fields.push(['handed back', formatWhen(human.handed_back_at, now)]);
|
|
200
|
+
}
|
|
201
|
+
if (human.handed_back)
|
|
202
|
+
fields.push(['note', human.note ?? colors.dim('none')]);
|
|
203
|
+
return fields;
|
|
204
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { DeviceCommandResult, DeviceFlowResult } from '../types/domain/device-session.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* What `dcd device run` shows a person: one row per flow and a short summary.
|
|
4
|
+
*
|
|
5
|
+
* The API passes on the runner's report as text in `result.output` (a pass)
|
|
6
|
+
* or `result.error` (a failure). For a directory that report is Maestro's
|
|
7
|
+
* JSON: `{ success, device_id, total_flows, total_commands_executed,
|
|
8
|
+
* results: [{ file, success, error, message }], env_vars, message }`. For one
|
|
9
|
+
* flow it is the same without `results`. Newer APIs also send
|
|
10
|
+
* `result.flows`, which is used when present. None of the runner's own
|
|
11
|
+
* fields (device_id, command counts, env_vars) are shown.
|
|
12
|
+
*/
|
|
13
|
+
export interface RunReport {
|
|
14
|
+
flows: DeviceFlowResult[];
|
|
15
|
+
/** The runner's one-line summary, e.g. "Some flows failed to execute". */
|
|
16
|
+
message: null | string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The flows a run reported, or null when the result carries no report the
|
|
20
|
+
* CLI can read (plain text): then the text is shown as it came.
|
|
21
|
+
*/
|
|
22
|
+
export declare function parseRunReport(result: DeviceCommandResult): null | RunReport;
|
|
23
|
+
/** The failure message for a failed run: each failing flow and why. */
|
|
24
|
+
export declare function runFailureMessage(result: DeviceCommandResult, report: null | RunReport): string;
|
|
25
|
+
/**
|
|
26
|
+
* Print a run's result for a person. `label` names a flow the report does not
|
|
27
|
+
* (a single flow's report has no file name).
|
|
28
|
+
*/
|
|
29
|
+
export declare function printRunResult(log: (line: string) => void, passed: boolean, result: DeviceCommandResult, label: string): void;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { colors } from './styling.js';
|
|
2
|
+
import { ui } from './ui.js';
|
|
3
|
+
function isRecord(value) {
|
|
4
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
5
|
+
}
|
|
6
|
+
function text(value) {
|
|
7
|
+
return typeof value === 'string' && value.trim() ? value.trim() : null;
|
|
8
|
+
}
|
|
9
|
+
function toFlow(raw, file) {
|
|
10
|
+
const success = raw.success === true;
|
|
11
|
+
return {
|
|
12
|
+
file: text(raw.file) ?? file,
|
|
13
|
+
success,
|
|
14
|
+
// A failed flow's reason is in `error`; some reports only have `message`.
|
|
15
|
+
error: text(raw.error) ?? (success ? null : text(raw.message)),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/** The runner's JSON report in `body`, or null when it is not one. */
|
|
19
|
+
function parseRunnerJson(body) {
|
|
20
|
+
if (!body || !body.trimStart().startsWith('{'))
|
|
21
|
+
return null;
|
|
22
|
+
let parsed;
|
|
23
|
+
try {
|
|
24
|
+
parsed = JSON.parse(body);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
if (!isRecord(parsed))
|
|
30
|
+
return null;
|
|
31
|
+
if (Array.isArray(parsed.results)) {
|
|
32
|
+
return {
|
|
33
|
+
flows: parsed.results.filter((r) => isRecord(r)).map((r) => toFlow(r, null)),
|
|
34
|
+
message: text(parsed.message),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
if (typeof parsed.success !== 'boolean')
|
|
38
|
+
return null;
|
|
39
|
+
// One flow: the report is that flow's result.
|
|
40
|
+
return { flows: [toFlow(parsed, null)], message: text(parsed.message) };
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The flows a run reported, or null when the result carries no report the
|
|
44
|
+
* CLI can read (plain text): then the text is shown as it came.
|
|
45
|
+
*/
|
|
46
|
+
export function parseRunReport(result) {
|
|
47
|
+
if (Array.isArray(result.flows)) {
|
|
48
|
+
return { flows: result.flows.map((f) => toFlow({ ...f }, null)), message: null };
|
|
49
|
+
}
|
|
50
|
+
return parseRunnerJson(result.error) ?? parseRunnerJson(result.output);
|
|
51
|
+
}
|
|
52
|
+
/** The failure message for a failed run: each failing flow and why. */
|
|
53
|
+
export function runFailureMessage(result, report) {
|
|
54
|
+
if (!report)
|
|
55
|
+
return result.error || 'The flow failed.';
|
|
56
|
+
const failed = report.flows.filter((f) => !f.success);
|
|
57
|
+
if (failed.length === 0)
|
|
58
|
+
return report.message ?? 'The flow failed.';
|
|
59
|
+
return failed
|
|
60
|
+
.map((f) => `${f.file ?? 'flow'}: ${f.error ?? 'failed'}`)
|
|
61
|
+
.join('; ');
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Print a run's result for a person. `label` names a flow the report does not
|
|
65
|
+
* (a single flow's report has no file name).
|
|
66
|
+
*/
|
|
67
|
+
export function printRunResult(log, passed, result, label) {
|
|
68
|
+
printOutcome(log, passed, result, label);
|
|
69
|
+
// What the app showed after the failure: why an assertion missed.
|
|
70
|
+
if (!passed && result.screen_text?.length) {
|
|
71
|
+
log(ui.section('On screen after the failure'));
|
|
72
|
+
log(ui.branch(result.screen_text.map((t) => `"${t}"`)));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function printOutcome(log, passed, result, label) {
|
|
76
|
+
const report = parseRunReport(result);
|
|
77
|
+
if (!report || report.flows.length === 0) {
|
|
78
|
+
log(passed ? ui.success('Flow passed') : `${ui.statusSymbol('FAILED')} Flow failed`);
|
|
79
|
+
if (report) {
|
|
80
|
+
if (report.message)
|
|
81
|
+
log(ui.note(report.message));
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
// Plain text, not a report the CLI can read: show it as it came.
|
|
85
|
+
if (result.output) {
|
|
86
|
+
log(ui.section('Output'));
|
|
87
|
+
log(result.output);
|
|
88
|
+
}
|
|
89
|
+
if (result.error) {
|
|
90
|
+
log(ui.section('Error'));
|
|
91
|
+
log(colors.error(result.error));
|
|
92
|
+
}
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const { flows } = report;
|
|
96
|
+
const failed = flows.filter((f) => !f.success).length;
|
|
97
|
+
const total = flows.length;
|
|
98
|
+
let summary;
|
|
99
|
+
if (total === 1)
|
|
100
|
+
summary = passed ? 'Flow passed' : 'Flow failed';
|
|
101
|
+
else if (failed === 0)
|
|
102
|
+
summary = `${total} flows passed`;
|
|
103
|
+
else
|
|
104
|
+
summary = `${failed} of ${total} flows failed`;
|
|
105
|
+
log(passed && failed === 0 ? ui.success(summary) : `${ui.statusSymbol('FAILED')} ${summary}`);
|
|
106
|
+
const rows = flows.map((f) => [
|
|
107
|
+
f.file ?? label,
|
|
108
|
+
f.success
|
|
109
|
+
? ui.statusWord('PASSED')
|
|
110
|
+
: `${ui.statusWord('FAILED')}${f.error ? ` ${colors.error(f.error)}` : ''}`,
|
|
111
|
+
]);
|
|
112
|
+
log(ui.branch(ui.fields(rows)));
|
|
113
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type InstallMethod } from './cli.js';
|
|
2
|
+
/** The server's name in every client's config. */
|
|
3
|
+
export declare const SERVER_NAME = "devicecloud";
|
|
4
|
+
export declare const MCP_CLIENTS: readonly ["claude-code", "claude-desktop", "cursor", "vscode"];
|
|
5
|
+
export type McpClient = (typeof MCP_CLIENTS)[number];
|
|
6
|
+
export declare const CLIENT_LABELS: Record<McpClient, string>;
|
|
7
|
+
export interface ServerLaunch {
|
|
8
|
+
command: string;
|
|
9
|
+
args: string[];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The command that starts `dcd mcp` from this install. The standalone binary
|
|
13
|
+
* is one file. An npm install is node plus the CLI's script; both are named
|
|
14
|
+
* by full path, so a different node on PATH, or none, doesn't matter.
|
|
15
|
+
*/
|
|
16
|
+
export declare function serverLaunch(opts: {
|
|
17
|
+
installMethod: InstallMethod;
|
|
18
|
+
execPath: string;
|
|
19
|
+
scriptPath: string | undefined;
|
|
20
|
+
readOnly: boolean;
|
|
21
|
+
}): ServerLaunch;
|
|
22
|
+
/**
|
|
23
|
+
* The `node` on PATH that is this same node, else `execPath`. execPath is
|
|
24
|
+
* the resolved file, which can be a versioned folder (Homebrew's Cellar) that
|
|
25
|
+
* an upgrade removes; the PATH entry (/opt/homebrew/bin/node) survives it.
|
|
26
|
+
*/
|
|
27
|
+
export declare function stableNodePath(execPath: string, pathEnv?: string | undefined, platform?: NodeJS.Platform): string;
|
|
28
|
+
/**
|
|
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 here.
|
|
31
|
+
*/
|
|
32
|
+
export declare function clientConfigPath(client: McpClient, platform?: NodeJS.Platform, home?: string, env?: NodeJS.ProcessEnv): string | undefined;
|
|
33
|
+
/** The `mcpServers` block Claude Desktop and Cursor read, with ours in it. */
|
|
34
|
+
export declare function mcpServersSnippet(launch: ServerLaunch): {
|
|
35
|
+
mcpServers: Record<string, ServerLaunch>;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Add our entry to a client's JSON config and write it back, keeping every
|
|
39
|
+
* other key. Returns whether an entry was already there (and is replaced).
|
|
40
|
+
* A file that isn't plain JSON (comments, say) is left alone.
|
|
41
|
+
*/
|
|
42
|
+
export declare function writeClientConfig(file: string, launch: ServerLaunch): {
|
|
43
|
+
replaced: boolean;
|
|
44
|
+
};
|
|
45
|
+
/** `claude mcp add` arguments, at user scope so it works in every project. */
|
|
46
|
+
export declare function claudeCodeAddArgs(launch: ServerLaunch): string[];
|
|
47
|
+
/** `code --add-mcp` arguments, which add the server to the VS Code user profile. */
|
|
48
|
+
export declare function vscodeAddArgs(launch: ServerLaunch): string[];
|
|
49
|
+
/** A command line to show a person, quoting the parts that need it. */
|
|
50
|
+
export declare function shellLine(command: string, args: string[]): string;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What `dcd mcp install` writes: how an MCP client starts this dcd, and the
|
|
3
|
+
* config entry each client wants.
|
|
4
|
+
*
|
|
5
|
+
* Desktop apps (Claude Desktop, Cursor) are usually started from the Dock or
|
|
6
|
+
* Start menu, so they don't read the shell rc that put dcd on PATH. Every
|
|
7
|
+
* entry therefore names this dcd by its full path, never a bare `dcd`.
|
|
8
|
+
*/
|
|
9
|
+
import { existsSync, mkdirSync, readFileSync, realpathSync, renameSync, writeFileSync } from 'node:fs';
|
|
10
|
+
import * as os from 'node:os';
|
|
11
|
+
import * as path from 'node:path';
|
|
12
|
+
import { CliError } from './cli.js';
|
|
13
|
+
/** The server's name in every client's config. */
|
|
14
|
+
export const SERVER_NAME = 'devicecloud';
|
|
15
|
+
export const MCP_CLIENTS = ['claude-code', 'claude-desktop', 'cursor', 'vscode'];
|
|
16
|
+
export const CLIENT_LABELS = {
|
|
17
|
+
'claude-code': 'Claude Code',
|
|
18
|
+
'claude-desktop': 'Claude Desktop',
|
|
19
|
+
cursor: 'Cursor',
|
|
20
|
+
vscode: 'VS Code',
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* The command that starts `dcd mcp` from this install. The standalone binary
|
|
24
|
+
* is one file. An npm install is node plus the CLI's script; both are named
|
|
25
|
+
* by full path, so a different node on PATH, or none, doesn't matter.
|
|
26
|
+
*/
|
|
27
|
+
export function serverLaunch(opts) {
|
|
28
|
+
const tail = ['mcp', ...(opts.readOnly ? ['--read-only'] : [])];
|
|
29
|
+
if (opts.installMethod === 'binary')
|
|
30
|
+
return { command: opts.execPath, args: tail };
|
|
31
|
+
if (!opts.scriptPath || /\.[cm]?ts$/.test(opts.scriptPath)) {
|
|
32
|
+
throw new CliError('Run `dcd mcp install` from an installed dcd, not from source: the config it writes must start a built dcd.');
|
|
33
|
+
}
|
|
34
|
+
if (opts.scriptPath.split(/[/\\]/).includes('_npx')) {
|
|
35
|
+
throw new CliError('This dcd runs from the npx cache, which gets cleared, so a config pointing at it would stop working. Install dcd (curl -fsSL https://get.devicecloud.dev/install.sh | sh, or npm install -g @devicecloud.dev/dcd), then run `dcd mcp install`.');
|
|
36
|
+
}
|
|
37
|
+
return { command: opts.execPath, args: [opts.scriptPath, ...tail] };
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The `node` on PATH that is this same node, else `execPath`. execPath is
|
|
41
|
+
* the resolved file, which can be a versioned folder (Homebrew's Cellar) that
|
|
42
|
+
* an upgrade removes; the PATH entry (/opt/homebrew/bin/node) survives it.
|
|
43
|
+
*/
|
|
44
|
+
export function stableNodePath(execPath, pathEnv = process.env.PATH, platform = process.platform) {
|
|
45
|
+
const exe = platform === 'win32' ? 'node.exe' : 'node';
|
|
46
|
+
let target;
|
|
47
|
+
try {
|
|
48
|
+
target = realpathSync(execPath);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return execPath;
|
|
52
|
+
}
|
|
53
|
+
for (const dir of (pathEnv ?? '').split(path.delimiter)) {
|
|
54
|
+
if (!dir)
|
|
55
|
+
continue;
|
|
56
|
+
const candidate = path.join(dir, exe);
|
|
57
|
+
try {
|
|
58
|
+
if (realpathSync(candidate) === target)
|
|
59
|
+
return candidate;
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
// not there
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return execPath;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* 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 here.
|
|
70
|
+
*/
|
|
71
|
+
export function clientConfigPath(client, platform = process.platform, home = os.homedir(), env = process.env) {
|
|
72
|
+
if (client === 'cursor')
|
|
73
|
+
return path.join(home, '.cursor', 'mcp.json');
|
|
74
|
+
if (client !== 'claude-desktop')
|
|
75
|
+
return undefined;
|
|
76
|
+
if (platform === 'darwin') {
|
|
77
|
+
return path.join(home, 'Library', 'Application Support', 'Claude', 'claude_desktop_config.json');
|
|
78
|
+
}
|
|
79
|
+
if (platform === 'win32') {
|
|
80
|
+
const appData = env.APPDATA ?? path.join(home, 'AppData', 'Roaming');
|
|
81
|
+
return path.join(appData, 'Claude', 'claude_desktop_config.json');
|
|
82
|
+
}
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
/** The `mcpServers` block Claude Desktop and Cursor read, with ours in it. */
|
|
86
|
+
export function mcpServersSnippet(launch) {
|
|
87
|
+
return { mcpServers: { [SERVER_NAME]: launch } };
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Add our entry to a client's JSON config and write it back, keeping every
|
|
91
|
+
* other key. Returns whether an entry was already there (and is replaced).
|
|
92
|
+
* A file that isn't plain JSON (comments, say) is left alone.
|
|
93
|
+
*/
|
|
94
|
+
export function writeClientConfig(file, launch) {
|
|
95
|
+
let config = {};
|
|
96
|
+
if (existsSync(file)) {
|
|
97
|
+
const text = readFileSync(file, 'utf8');
|
|
98
|
+
if (text.trim()) {
|
|
99
|
+
try {
|
|
100
|
+
const parsed = JSON.parse(text);
|
|
101
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
102
|
+
throw new Error('not an object');
|
|
103
|
+
config = parsed;
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
throw new CliError(`${file} isn't plain JSON, so it was left as it is. Add this to it by hand:\n${JSON.stringify(mcpServersSnippet(launch), null, 2)}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const servers = config.mcpServers && typeof config.mcpServers === 'object' && !Array.isArray(config.mcpServers)
|
|
111
|
+
? config.mcpServers
|
|
112
|
+
: {};
|
|
113
|
+
const replaced = SERVER_NAME in servers;
|
|
114
|
+
config.mcpServers = { ...servers, [SERVER_NAME]: launch };
|
|
115
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
116
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
117
|
+
writeFileSync(tmp, `${JSON.stringify(config, null, 2)}\n`);
|
|
118
|
+
renameSync(tmp, file);
|
|
119
|
+
return { replaced };
|
|
120
|
+
}
|
|
121
|
+
/** `claude mcp add` arguments, at user scope so it works in every project. */
|
|
122
|
+
export function claudeCodeAddArgs(launch) {
|
|
123
|
+
return ['mcp', 'add', '--scope', 'user', SERVER_NAME, '--', launch.command, ...launch.args];
|
|
124
|
+
}
|
|
125
|
+
/** `code --add-mcp` arguments, which add the server to the VS Code user profile. */
|
|
126
|
+
export function vscodeAddArgs(launch) {
|
|
127
|
+
return ['--add-mcp', JSON.stringify({ name: SERVER_NAME, ...launch })];
|
|
128
|
+
}
|
|
129
|
+
/** A command line to show a person, quoting the parts that need it. */
|
|
130
|
+
export function shellLine(command, args) {
|
|
131
|
+
return [command, ...args].map((part) => (/^[\w@%+=:,./-]+$/.test(part) ? part : `'${part.replaceAll("'", String.raw `'\''`)}'`)).join(' ');
|
|
132
|
+
}
|
package/dist/utils/progress.d.ts
CHANGED
|
@@ -4,9 +4,13 @@ declare class Action {
|
|
|
4
4
|
private _lastPrinted;
|
|
5
5
|
private interactive;
|
|
6
6
|
start(title: string, initialStatus?: string, _opts?: unknown): void;
|
|
7
|
+
/** End the action as a success: `✓ message`. */
|
|
7
8
|
stop(message?: string): void;
|
|
9
|
+
/** End the action as a failure: `✗ message`. */
|
|
10
|
+
fail(message?: string): void;
|
|
8
11
|
set status(value: string);
|
|
9
12
|
get status(): string;
|
|
13
|
+
private finish;
|
|
10
14
|
private print;
|
|
11
15
|
}
|
|
12
16
|
export declare const ux: {
|
package/dist/utils/progress.js
CHANGED
|
@@ -10,9 +10,20 @@
|
|
|
10
10
|
* non-interactive environments we skip the spinner entirely and instead print a
|
|
11
11
|
* plain line once per *distinct* status, so CI logs show real progress without
|
|
12
12
|
* the flood.
|
|
13
|
+
*
|
|
14
|
+
* Styling: the spinner uses the CLI's own palette (cyan braille frames) rather
|
|
15
|
+
* than clack's magenta default, and no `│` guide bar, since the rest of the CLI
|
|
16
|
+
* is a `⏺`/`⎿` tree rather than a clack session. The final line is written by
|
|
17
|
+
* us, not clack, so it carries the same `✓` / `✗` symbols as every other
|
|
18
|
+
* command (see STYLE_GUIDE.md).
|
|
13
19
|
*/
|
|
14
20
|
import * as p from '@clack/prompts';
|
|
15
21
|
import { isCI } from './ci.js';
|
|
22
|
+
import { colors, symbols } from './styling.js';
|
|
23
|
+
// Braille dots where the terminal can draw them, plain ASCII otherwise.
|
|
24
|
+
const FRAMES = p.unicode
|
|
25
|
+
? ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']
|
|
26
|
+
: ['-', '\\', '|', '/'];
|
|
16
27
|
class Action {
|
|
17
28
|
current = null;
|
|
18
29
|
_status = '';
|
|
@@ -23,37 +34,30 @@ class Action {
|
|
|
23
34
|
}
|
|
24
35
|
start(title, initialStatus, _opts) {
|
|
25
36
|
this._status = initialStatus ?? '';
|
|
26
|
-
const line = initialStatus ? `${title}
|
|
37
|
+
const line = initialStatus ? `${title} ${colors.dim('·')} ${initialStatus}` : title;
|
|
27
38
|
if (!this.interactive()) {
|
|
28
39
|
this.current = null;
|
|
29
40
|
this.print(line);
|
|
30
41
|
return;
|
|
31
42
|
}
|
|
32
43
|
if (this.current) {
|
|
33
|
-
this.current.
|
|
44
|
+
this.current.clear();
|
|
34
45
|
}
|
|
35
|
-
this.current = p.spinner(
|
|
46
|
+
this.current = p.spinner({
|
|
47
|
+
delay: 80,
|
|
48
|
+
frames: FRAMES,
|
|
49
|
+
styleFrame: colors.highlight,
|
|
50
|
+
withGuide: false,
|
|
51
|
+
});
|
|
36
52
|
this.current.start(line);
|
|
37
53
|
}
|
|
54
|
+
/** End the action as a success: `✓ message`. */
|
|
38
55
|
stop(message) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
this._lastPrinted = '';
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
if (!this.current) {
|
|
48
|
-
if (message) {
|
|
49
|
-
// eslint-disable-next-line no-console
|
|
50
|
-
console.log(message);
|
|
51
|
-
}
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
this.current.stop(message ?? '');
|
|
55
|
-
this.current = null;
|
|
56
|
-
this._status = '';
|
|
56
|
+
this.finish(symbols.success, message);
|
|
57
|
+
}
|
|
58
|
+
/** End the action as a failure: `✗ message`. */
|
|
59
|
+
fail(message) {
|
|
60
|
+
this.finish(symbols.error, message);
|
|
57
61
|
}
|
|
58
62
|
set status(value) {
|
|
59
63
|
this._status = value;
|
|
@@ -70,6 +74,26 @@ class Action {
|
|
|
70
74
|
get status() {
|
|
71
75
|
return this._status;
|
|
72
76
|
}
|
|
77
|
+
// Erase the spinner (if one is live) and print the final line ourselves, so
|
|
78
|
+
// the symbol matches the rest of the CLI instead of clack's `◇`.
|
|
79
|
+
finish(symbol, message) {
|
|
80
|
+
const line = message ? `${symbol} ${message}` : '';
|
|
81
|
+
if (!this.interactive()) {
|
|
82
|
+
if (line)
|
|
83
|
+
this.print(line);
|
|
84
|
+
this.current = null;
|
|
85
|
+
this._status = '';
|
|
86
|
+
this._lastPrinted = '';
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
this.current?.clear();
|
|
90
|
+
this.current = null;
|
|
91
|
+
this._status = '';
|
|
92
|
+
if (line) {
|
|
93
|
+
// eslint-disable-next-line no-console
|
|
94
|
+
console.log(line);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
73
97
|
// Emit a line only when it differs from the previous one, so repeated polls
|
|
74
98
|
// with no state change stay quiet.
|
|
75
99
|
print(line) {
|
package/package.json
CHANGED
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"test:unit": "node scripts/test-runner.mjs --unit",
|
|
69
69
|
"typecheck": "tsc --noEmit -p tsconfig.test.json"
|
|
70
70
|
},
|
|
71
|
-
"version": "5.
|
|
71
|
+
"version": "5.11.0-beta.10",
|
|
72
72
|
"bugs": {
|
|
73
73
|
"url": "https://discord.gg/gm3mJwcNw8"
|
|
74
74
|
},
|
|
@@ -109,7 +109,7 @@
|
|
|
109
109
|
"ws@>=8.0.0 <8.21.0": "8.21.0",
|
|
110
110
|
"esbuild@<0.28.1": ">=0.28.1",
|
|
111
111
|
"qs@<6.16.0": "6.16.0",
|
|
112
|
-
"fast-uri@>=3.0.0 <3.1.
|
|
112
|
+
"fast-uri@>=3.0.0 <3.1.9": "3.1.9",
|
|
113
113
|
"hono@>=4.0.0 <4.13.11": "4.13.11",
|
|
114
114
|
"source-map-js@<1.2.2": "1.2.2",
|
|
115
115
|
"micromatch>picomatch": "^2.3.2",
|