simcast-host 0.0.0-stage → 0.9.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/LICENSE +21 -0
- package/README.md +72 -2
- package/bin/simcast-host.js +11 -0
- package/package.json +28 -4
- package/proto/idb.proto +1816 -0
- package/src/agent/admin.js +87 -0
- package/src/agent/awake.js +136 -0
- package/src/agent/bonjour.js +172 -0
- package/src/agent/build.js +24 -0
- package/src/agent/checks.js +618 -0
- package/src/agent/clean.js +419 -0
- package/src/agent/cli.js +617 -0
- package/src/agent/clients.js +475 -0
- package/src/agent/exec.js +163 -0
- package/src/agent/live.js +709 -0
- package/src/agent/macinfo.js +75 -0
- package/src/agent/pairing.js +123 -0
- package/src/agent/paths.js +23 -0
- package/src/agent/recipes/expo.js +134 -0
- package/src/agent/recipes/index.js +66 -0
- package/src/agent/recipes/kit.js +124 -0
- package/src/agent/record.js +133 -0
- package/src/agent/runtime.js +166 -0
- package/src/agent/screen.js +285 -0
- package/src/agent/server.js +577 -0
- package/src/agent/service.js +119 -0
- package/src/agent/setup.js +283 -0
- package/src/agent/sim.js +129 -0
- package/src/agent/stalls.js +32 -0
- package/src/agent/state.js +121 -0
- package/src/agent/tunnel.js +464 -0
- package/src/common.js +119 -0
|
@@ -0,0 +1,618 @@
|
|
|
1
|
+
// What `simcast-host setup` and `doctor` look at. Each check only probes the
|
|
2
|
+
// Mac; it never changes anything. A fix is data (the commands to run and
|
|
3
|
+
// whether they need sudo), and setup.js decides whether to run it.
|
|
4
|
+
//
|
|
5
|
+
// A check: { id, title, in: ['setup','doctor'], needs: [ids], level: 'fail'|'warn',
|
|
6
|
+
// check(ctx) -> { ok, detail, data?, status? } (status overrides the level when not ok)
|
|
7
|
+
// manual?: string | (ctx, result) -> string what the user has to do by hand
|
|
8
|
+
// fix?: { sudo, slow?, confirm?, what, commands(ctx, result) -> [[cmd, ...args] | step] | null } }
|
|
9
|
+
// A step is { text, run: async () => exitCode }: work done in-process (a checked
|
|
10
|
+
// download), shown as `text`.
|
|
11
|
+
// `ctx.results` holds the results so far by id, so a check can use an earlier one's data.
|
|
12
|
+
import crypto from 'node:crypto';
|
|
13
|
+
import fs from 'node:fs';
|
|
14
|
+
import os from 'node:os';
|
|
15
|
+
import path from 'node:path';
|
|
16
|
+
import { fileURLToPath } from 'node:url';
|
|
17
|
+
import { VERSION } from '../common.js';
|
|
18
|
+
import { run } from './exec.js';
|
|
19
|
+
import { loadAgentConfig, saveAgentConfig } from './state.js';
|
|
20
|
+
import { hostAppRunning } from './live.js';
|
|
21
|
+
import { developerDir, freeDiskGB, macosVersion, probe } from './macinfo.js';
|
|
22
|
+
import { AGENT_LABEL, HOST_BIN, HOST_NAMES, LOG_FILE, isMac, uid } from './paths.js';
|
|
23
|
+
import { agentHealth as health, agentPort, readStatus } from './runtime.js';
|
|
24
|
+
import { listDevices } from './sim.js';
|
|
25
|
+
|
|
26
|
+
const AGENT_BIN = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..', 'bin', 'simcast-host.js');
|
|
27
|
+
const MIN_MACOS = 14;
|
|
28
|
+
const MIN_NODE = 20;
|
|
29
|
+
const LOW_DISK_GB = 25;
|
|
30
|
+
|
|
31
|
+
// ---- small probes -------------------------------------------------------------
|
|
32
|
+
|
|
33
|
+
// Exit code and output of a command; 127 when it isn't installed.
|
|
34
|
+
async function tryRun(cmd, args) {
|
|
35
|
+
try {
|
|
36
|
+
const r = await run(cmd, args, { capture: true });
|
|
37
|
+
return { code: r.code, out: r.stdout.toString().trim(), tail: r.tail };
|
|
38
|
+
} catch {
|
|
39
|
+
return { code: 127, out: '', tail: [] };
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const brewPresent = async () => (await tryRun('brew', ['--version'])).code === 0;
|
|
44
|
+
const IDB_FORMULA = 'facebook/fb/idb-companion';
|
|
45
|
+
// Apple silicon only: facebook/idb publishes no Intel build outside Homebrew.
|
|
46
|
+
const IDB_URL = 'https://github.com/facebook/idb/releases/download/v1.7.8/idb-companion.macos-arm64.tar.gz';
|
|
47
|
+
const NO_BREW_INTEL = 'idb_companion has no download for Intel Macs. Install Homebrew, then run simcast-host setup again: https://brew.sh';
|
|
48
|
+
|
|
49
|
+
// Adds a folder to agent.json extraPath, which agentEnv() puts on every tool's PATH.
|
|
50
|
+
function addExtraPath(dir) {
|
|
51
|
+
// loadAgentConfig, not a bare read: on a fresh Mac setup runs before the agent
|
|
52
|
+
// ever has, and an agent.json without a port would leave it unable to listen.
|
|
53
|
+
const cfg = loadAgentConfig();
|
|
54
|
+
const list = [].concat(cfg.extraPath || []);
|
|
55
|
+
if (!list.includes(dir)) saveAgentConfig({ ...cfg, extraPath: [...list, dir] });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// The idb_companion release tarball, checked against its .sha256 asset, unpacked into HOST_BIN.
|
|
59
|
+
async function downloadIdbCompanion() {
|
|
60
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'simcast-idb-'));
|
|
61
|
+
const tgz = path.join(tmp, 'idb.tar.gz');
|
|
62
|
+
const sum = path.join(tmp, 'idb.sha256');
|
|
63
|
+
try {
|
|
64
|
+
for (const [file, url] of [[tgz, IDB_URL], [sum, `${IDB_URL}.sha256`]]) {
|
|
65
|
+
const r = await run('curl', ['-fsSL', '-o', file, url]);
|
|
66
|
+
if (r.code !== 0) {
|
|
67
|
+
console.log(` Could not download ${url} (curl exited with ${r.code}).`);
|
|
68
|
+
return r.code || 1;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const want = fs.readFileSync(sum, 'utf8').trim().split(/\s+/)[0].toLowerCase();
|
|
72
|
+
const got = crypto.createHash('sha256').update(fs.readFileSync(tgz)).digest('hex');
|
|
73
|
+
if (want !== got) {
|
|
74
|
+
console.log(` The download's checksum (${got}) does not match the published one (${want}); nothing was installed.`);
|
|
75
|
+
return 1;
|
|
76
|
+
}
|
|
77
|
+
const staging = `${HOST_BIN}.new`;
|
|
78
|
+
fs.rmSync(staging, { recursive: true, force: true });
|
|
79
|
+
fs.mkdirSync(staging, { recursive: true });
|
|
80
|
+
const r = await run('tar', ['-xzf', tgz, '-C', staging]);
|
|
81
|
+
if (r.code !== 0) {
|
|
82
|
+
fs.rmSync(staging, { recursive: true, force: true });
|
|
83
|
+
console.log(` Could not unpack the download (tar exited with ${r.code}).`);
|
|
84
|
+
return r.code;
|
|
85
|
+
}
|
|
86
|
+
// ponytail: HOST_BIN holds only idb_companion and its bundles, so it is replaced whole.
|
|
87
|
+
fs.rmSync(HOST_BIN, { recursive: true, force: true });
|
|
88
|
+
fs.renameSync(staging, HOST_BIN);
|
|
89
|
+
addExtraPath(HOST_BIN);
|
|
90
|
+
return 0;
|
|
91
|
+
} finally {
|
|
92
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// `gem install --user-install` puts pod in Gem.user_dir/bin; that folder goes on the agent's PATH.
|
|
97
|
+
async function addGemBin() {
|
|
98
|
+
const r = await tryRun('ruby', ['-e', 'print Gem.user_dir']);
|
|
99
|
+
if (r.code !== 0 || !r.out) {
|
|
100
|
+
console.log(" Could not ask Ruby where it installs user gems (ruby -e 'print Gem.user_dir').");
|
|
101
|
+
return r.code || 1;
|
|
102
|
+
}
|
|
103
|
+
addExtraPath(path.join(r.out, 'bin'));
|
|
104
|
+
return 0;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async function simctlJson(kind) {
|
|
108
|
+
const r = await tryRun('xcrun', ['simctl', 'list', kind, '-j']);
|
|
109
|
+
if (r.code !== 0) return null;
|
|
110
|
+
try {
|
|
111
|
+
return JSON.parse(r.out)[kind] || null;
|
|
112
|
+
} catch {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function compareVersions(a, b) {
|
|
118
|
+
const pa = String(a || '').split(/[^\d]+/).filter(Boolean).map(Number);
|
|
119
|
+
const pb = String(b || '').split(/[^\d]+/).filter(Boolean).map(Number);
|
|
120
|
+
for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
|
|
121
|
+
const d = (pa[i] || 0) - (pb[i] || 0);
|
|
122
|
+
if (d) return d;
|
|
123
|
+
}
|
|
124
|
+
return 0;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function xcodeAppVersion(app) {
|
|
128
|
+
for (const file of ['version.plist', 'Info.plist']) {
|
|
129
|
+
try {
|
|
130
|
+
const xml = fs.readFileSync(path.join(app, 'Contents', file), 'utf8');
|
|
131
|
+
const m = /<key>CFBundleShortVersionString<\/key>\s*<string>([^<]+)<\/string>/.exec(xml);
|
|
132
|
+
if (m) return m[1];
|
|
133
|
+
} catch { /* not readable: try the next one */ }
|
|
134
|
+
}
|
|
135
|
+
return /Xcode[-_ ]?(\d+(?:\.\d+)*)/i.exec(path.basename(app))?.[1] || null;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Every Xcode on the Mac, newest first (Spotlight, then /Applications/Xcode*.app).
|
|
139
|
+
async function findXcodeApps() {
|
|
140
|
+
const found = await probe('mdfind', ["kMDItemCFBundleIdentifier == 'com.apple.dt.Xcode'"]);
|
|
141
|
+
let apps = (found || '').split('\n').map((s) => s.trim()).filter((s) => s.endsWith('.app'));
|
|
142
|
+
if (!apps.length) {
|
|
143
|
+
try {
|
|
144
|
+
apps = fs.readdirSync('/Applications').filter((n) => /^Xcode.*\.app$/.test(n)).map((n) => `/Applications/${n}`);
|
|
145
|
+
} catch {
|
|
146
|
+
apps = [];
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
const list = [...new Set(apps)].map((app, i) => ({ app, version: xcodeAppVersion(app), i }));
|
|
150
|
+
list.sort((a, b) => compareVersions(b.version, a.version) || a.i - b.i);
|
|
151
|
+
return list.map(({ app, version }) => ({ app, version }));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// launchctl print gui/<uid>/<label> answers 0 for a loaded job.
|
|
155
|
+
async function launchdLoaded(label) {
|
|
156
|
+
return (await tryRun('launchctl', ['print', `gui/${uid()}/${label}`])).code === 0;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const plural = (n, word) => `${n} ${word}${n === 1 ? '' : 's'}`;
|
|
160
|
+
|
|
161
|
+
// The newest non-Pro/Max iPhone the newest iOS runtime supports, e.g. "iPhone 17".
|
|
162
|
+
function pickIphone(types) {
|
|
163
|
+
const iphones = types.map((t, i) => ({ ...t, i }))
|
|
164
|
+
.filter((t) => /^iPhone\b/.test(t.name) && !/\b(Pro|Max)\b/.test(t.name) && (!t.productFamily || t.productFamily === 'iPhone'));
|
|
165
|
+
const rank = (t) => {
|
|
166
|
+
const m = /^iPhone (\d+)(\S*)/.exec(t.name);
|
|
167
|
+
return [m ? Number(m[1]) : 0, m && !m[2] && !/\bPlus\b/.test(t.name) ? 1 : 0, t.i];
|
|
168
|
+
};
|
|
169
|
+
iphones.sort((a, b) => {
|
|
170
|
+
const ra = rank(a), rb = rank(b);
|
|
171
|
+
return rb[0] - ra[0] || rb[1] - ra[1] || rb[2] - ra[2];
|
|
172
|
+
});
|
|
173
|
+
return iphones[0] || null;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function iosRuntimes(runtimes) {
|
|
177
|
+
return (runtimes || [])
|
|
178
|
+
.filter((r) => (r.platform === 'iOS' || /SimRuntime\.iOS-/.test(r.identifier || '')) && r.isAvailable !== false)
|
|
179
|
+
.sort((a, b) => compareVersions(b.version, a.version));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
async function pmsetValue(key) {
|
|
183
|
+
const out = await probe('pmset', ['-g']);
|
|
184
|
+
const m = out && new RegExp(`^\\s*${key}\\s+(\\d+)`, 'm').exec(out);
|
|
185
|
+
return m ? Number(m[1]) : null;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// ---- the checks -----------------------------------------------------------------
|
|
189
|
+
|
|
190
|
+
const BOTH = ['setup', 'doctor'];
|
|
191
|
+
const DOCTOR = ['doctor'];
|
|
192
|
+
|
|
193
|
+
export const CHECKS = [
|
|
194
|
+
{
|
|
195
|
+
id: 'macos',
|
|
196
|
+
title: 'macOS',
|
|
197
|
+
in: BOTH,
|
|
198
|
+
needs: [],
|
|
199
|
+
level: 'fail',
|
|
200
|
+
async check() {
|
|
201
|
+
if (!isMac()) return { ok: false, detail: `This is ${process.platform}, not a Mac.` };
|
|
202
|
+
const v = await macosVersion();
|
|
203
|
+
if (!v) return { ok: false, detail: 'Could not read the macOS version (sw_vers failed).' };
|
|
204
|
+
if (compareVersions(v, String(MIN_MACOS)) < 0) return { ok: false, detail: `macOS ${v} is too old; Xcode needs macOS ${MIN_MACOS} or later.` };
|
|
205
|
+
return { ok: true, detail: `macOS ${v}` };
|
|
206
|
+
},
|
|
207
|
+
manual: `Update macOS to version ${MIN_MACOS} or later in System Settings > General > Software Update.`,
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
id: 'node',
|
|
211
|
+
title: 'Node.js',
|
|
212
|
+
in: BOTH,
|
|
213
|
+
needs: [],
|
|
214
|
+
level: 'fail',
|
|
215
|
+
async check() {
|
|
216
|
+
const major = Number(process.versions.node.split('.')[0]);
|
|
217
|
+
if (major < MIN_NODE) return { ok: false, detail: `Node ${process.versions.node} is too old; simcast-host needs Node ${MIN_NODE} or later.` };
|
|
218
|
+
return { ok: true, detail: `Node ${process.versions.node}` };
|
|
219
|
+
},
|
|
220
|
+
manual: 'Update Node: brew upgrade node, or install the latest LTS from nodejs.org',
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
id: 'xcode-app',
|
|
224
|
+
title: 'Xcode',
|
|
225
|
+
in: BOTH,
|
|
226
|
+
needs: ['macos'],
|
|
227
|
+
level: 'fail',
|
|
228
|
+
async check() {
|
|
229
|
+
const apps = await findXcodeApps();
|
|
230
|
+
// The Xcode builds use: xcode-select -p without /Contents/Developer.
|
|
231
|
+
// Without one (or only the Command Line Tools), the newest found.
|
|
232
|
+
const app = /^(.+\.app)\/Contents\/Developer\/?$/.exec((await developerDir()) || '')?.[1];
|
|
233
|
+
const selected = app ? { app, version: xcodeAppVersion(app) } : null;
|
|
234
|
+
if (!apps.length && !selected) return { ok: false, detail: 'Xcode is not installed.', data: { apps } };
|
|
235
|
+
const newest = apps[0];
|
|
236
|
+
const shown = selected || newest;
|
|
237
|
+
const others = apps.filter((a) => a.app !== shown.app).length;
|
|
238
|
+
const more = others ? ` (and ${plural(others, 'other')})` : '';
|
|
239
|
+
return { ok: true, detail: `${shown.app}${shown.version ? `, version ${shown.version}` : ''}${more}`, data: { apps, newest } };
|
|
240
|
+
},
|
|
241
|
+
manual: 'Install Xcode from the App Store (or developer.apple.com/xcode), then run simcast-host setup again.',
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
id: 'xcode-select',
|
|
245
|
+
title: 'Xcode selected',
|
|
246
|
+
in: BOTH,
|
|
247
|
+
needs: ['xcode-app'],
|
|
248
|
+
level: 'fail',
|
|
249
|
+
async check(ctx) {
|
|
250
|
+
const dir = await developerDir();
|
|
251
|
+
const newest = ctx.results['xcode-app']?.data?.newest?.app;
|
|
252
|
+
if (!dir) return { ok: false, detail: 'No Xcode is selected for command-line builds.', data: { newest } };
|
|
253
|
+
if (dir.includes('CommandLineTools')) return { ok: false, detail: `Only the Command Line Tools are selected (${dir}), not Xcode.`, data: { newest, dir } };
|
|
254
|
+
return { ok: true, detail: dir, data: { dir } };
|
|
255
|
+
},
|
|
256
|
+
fix: {
|
|
257
|
+
sudo: true,
|
|
258
|
+
what: 'Select Xcode for command-line builds',
|
|
259
|
+
commands: (ctx, result) => {
|
|
260
|
+
const app = result.data?.newest || ctx.results['xcode-app']?.data?.newest?.app;
|
|
261
|
+
return app ? [['xcode-select', '-s', app]] : null;
|
|
262
|
+
},
|
|
263
|
+
},
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
id: 'xcode-license',
|
|
267
|
+
title: 'Xcode license',
|
|
268
|
+
in: BOTH,
|
|
269
|
+
needs: ['xcode-select'],
|
|
270
|
+
level: 'fail',
|
|
271
|
+
async check() {
|
|
272
|
+
const r = await tryRun('xcodebuild', ['-license', 'check']);
|
|
273
|
+
return r.code === 0 ? { ok: true, detail: 'Accepted' } : { ok: false, detail: 'The Xcode license has not been accepted.' };
|
|
274
|
+
},
|
|
275
|
+
fix: { sudo: true, what: 'Accept the Xcode license', commands: () => [['xcodebuild', '-license', 'accept']] },
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
id: 'xcode-first-launch',
|
|
279
|
+
title: 'Xcode components',
|
|
280
|
+
in: BOTH,
|
|
281
|
+
needs: ['xcode-license'],
|
|
282
|
+
level: 'fail',
|
|
283
|
+
async check() {
|
|
284
|
+
const r = await tryRun('xcodebuild', ['-checkFirstLaunchStatus']);
|
|
285
|
+
return r.code === 0 ? { ok: true, detail: 'Installed' } : { ok: false, detail: "Xcode's first-launch components are not installed." };
|
|
286
|
+
},
|
|
287
|
+
fix: { sudo: true, what: "Install Xcode's first-launch components", commands: () => [['xcodebuild', '-runFirstLaunch']] },
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
id: 'ios-runtime',
|
|
291
|
+
title: 'iOS Simulator runtime',
|
|
292
|
+
in: BOTH,
|
|
293
|
+
needs: ['xcode-first-launch'],
|
|
294
|
+
level: 'fail',
|
|
295
|
+
async check() {
|
|
296
|
+
const runtimes = await simctlJson('runtimes');
|
|
297
|
+
if (!runtimes) return { ok: false, detail: 'Could not list simulator runtimes (xcrun simctl failed).' };
|
|
298
|
+
const ios = iosRuntimes(runtimes);
|
|
299
|
+
if (!ios.length) return { ok: false, detail: 'No iOS Simulator runtime is installed.' };
|
|
300
|
+
const more = ios.length > 1 ? ` (and ${plural(ios.length - 1, 'other')})` : '';
|
|
301
|
+
return { ok: true, detail: `${ios[0].name}${more}`, data: { newest: ios[0] } };
|
|
302
|
+
},
|
|
303
|
+
fix: {
|
|
304
|
+
sudo: false,
|
|
305
|
+
slow: true,
|
|
306
|
+
what: 'Download the iOS Simulator runtime, about 8 GB',
|
|
307
|
+
commands: () => [['xcodebuild', '-downloadPlatform', 'iOS']],
|
|
308
|
+
},
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
id: 'cocoapods',
|
|
312
|
+
title: 'CocoaPods',
|
|
313
|
+
in: BOTH,
|
|
314
|
+
needs: ['macos'],
|
|
315
|
+
level: 'fail',
|
|
316
|
+
async check() {
|
|
317
|
+
const r = await tryRun('pod', ['--version']);
|
|
318
|
+
if (r.code === 0) return { ok: true, detail: `pod ${r.out.split('\n')[0]}` };
|
|
319
|
+
return { ok: false, detail: r.code === 127 ? 'CocoaPods is not installed.' : 'pod is installed but does not run.', data: { brew: await brewPresent() } };
|
|
320
|
+
},
|
|
321
|
+
fix: {
|
|
322
|
+
sudo: false,
|
|
323
|
+
what: 'Install CocoaPods',
|
|
324
|
+
// Without Homebrew: the system Ruby's user gems, so no admin password.
|
|
325
|
+
commands: (ctx, result) => (result.data?.brew === false
|
|
326
|
+
? [['gem', 'install', '--user-install', 'cocoapods'], { text: "add Ruby's user gem bin folder to the agent's PATH", run: addGemBin }]
|
|
327
|
+
: [['brew', 'install', 'cocoapods']]),
|
|
328
|
+
},
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
id: 'idb-companion',
|
|
332
|
+
title: 'idb_companion (live view)',
|
|
333
|
+
in: BOTH,
|
|
334
|
+
needs: ['macos'],
|
|
335
|
+
level: 'warn',
|
|
336
|
+
async check() {
|
|
337
|
+
const r = await tryRun('idb_companion', ['--version']);
|
|
338
|
+
if (r.code === 0) return { ok: true, detail: `idb_companion ${r.out.split('\n')[0]}` };
|
|
339
|
+
const brew = await brewPresent();
|
|
340
|
+
// Homebrew since 2026-05 refuses formulae from a tap nobody trusted.
|
|
341
|
+
const trust = brew && (await tryRun('brew', ['trust', '--help'])).code === 0;
|
|
342
|
+
const intel = !brew && (await tryRun('uname', ['-m'])).out === 'x86_64';
|
|
343
|
+
return { ok: false, detail: 'idb_companion is not installed, so simcast view has no live screen.', data: { brew, trust, intel } };
|
|
344
|
+
},
|
|
345
|
+
fix: {
|
|
346
|
+
sudo: false,
|
|
347
|
+
what: 'Install idb_companion',
|
|
348
|
+
commands: (ctx, result) => {
|
|
349
|
+
if (result.data?.intel) return null;
|
|
350
|
+
if (result.data?.brew === false) return [{ text: `curl -fsSL ${IDB_URL} (checksum checked) into ~/.simcast/bin`, run: downloadIdbCompanion }];
|
|
351
|
+
return [
|
|
352
|
+
['brew', 'tap', 'facebook/fb'],
|
|
353
|
+
...(result.data?.trust ? [['brew', 'trust', '--formula', IDB_FORMULA]] : []),
|
|
354
|
+
['brew', 'install', IDB_FORMULA],
|
|
355
|
+
];
|
|
356
|
+
},
|
|
357
|
+
},
|
|
358
|
+
manual: (ctx, result) => (result.data?.intel ? NO_BREW_INTEL : null),
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
id: 'default-simulator',
|
|
362
|
+
title: 'iPhone simulator',
|
|
363
|
+
in: BOTH,
|
|
364
|
+
needs: ['ios-runtime'],
|
|
365
|
+
level: 'fail',
|
|
366
|
+
async check() {
|
|
367
|
+
let devices;
|
|
368
|
+
try {
|
|
369
|
+
devices = await listDevices();
|
|
370
|
+
} catch {
|
|
371
|
+
return { ok: false, detail: 'Could not list simulators (xcrun simctl failed).' };
|
|
372
|
+
}
|
|
373
|
+
const iphones = devices.filter((d) => /^iPhone\b/.test(d.name));
|
|
374
|
+
if (iphones.length) {
|
|
375
|
+
const more = iphones.length > 1 ? ` (and ${plural(iphones.length - 1, 'other')})` : '';
|
|
376
|
+
return { ok: true, detail: `${iphones[0].name}, ${iphones[0].runtime}${more}` };
|
|
377
|
+
}
|
|
378
|
+
const runtime = iosRuntimes(await simctlJson('runtimes'))[0] || null;
|
|
379
|
+
const all = await simctlJson('devicetypes') || [];
|
|
380
|
+
const supported = runtime?.supportedDeviceTypes?.length
|
|
381
|
+
? runtime.supportedDeviceTypes.map((t) => all.find((d) => d.identifier === t.identifier) || t)
|
|
382
|
+
: all;
|
|
383
|
+
const type = pickIphone(supported);
|
|
384
|
+
return { ok: false, detail: 'There is no iPhone simulator.', data: { runtime, type } };
|
|
385
|
+
},
|
|
386
|
+
fix: {
|
|
387
|
+
sudo: false,
|
|
388
|
+
what: 'Create an iPhone simulator',
|
|
389
|
+
commands: (ctx, result) => {
|
|
390
|
+
const { runtime, type } = result.data || {};
|
|
391
|
+
return runtime && type ? [['xcrun', 'simctl', 'create', type.name, type.identifier, runtime.identifier]] : null;
|
|
392
|
+
},
|
|
393
|
+
},
|
|
394
|
+
manual: (ctx, result) => (result.data && !result.data.type
|
|
395
|
+
? 'Create an iPhone simulator in Xcode: Window > Devices and Simulators > Simulators > +.'
|
|
396
|
+
: null),
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
id: 'service',
|
|
400
|
+
title: 'Agent service',
|
|
401
|
+
in: BOTH,
|
|
402
|
+
needs: ['macos'],
|
|
403
|
+
level: 'fail',
|
|
404
|
+
async check() {
|
|
405
|
+
const port = agentPort();
|
|
406
|
+
const [h, loaded] = await Promise.all([health(port), launchdLoaded(AGENT_LABEL)]);
|
|
407
|
+
const data = { port, loaded, running: h?.version || null };
|
|
408
|
+
if (h && !HOST_NAMES.includes(h.name)) {
|
|
409
|
+
return { ok: false, detail: `Port ${port} is used by something else, not simcast-host.`, data };
|
|
410
|
+
}
|
|
411
|
+
if (h && loaded) return { ok: true, detail: `Running on port ${port} (LaunchAgent)`, data };
|
|
412
|
+
if (h) return { ok: false, status: 'warn', detail: `Running on port ${port}, but not as a service, so it won't start at login.`, data };
|
|
413
|
+
if (loaded) return { ok: false, detail: `${AGENT_LABEL} is loaded but nothing answers on port ${port}. See ${LOG_FILE}.`, data };
|
|
414
|
+
return { ok: false, detail: `The agent is not running (nothing answers on port ${port}).`, data };
|
|
415
|
+
},
|
|
416
|
+
fix: {
|
|
417
|
+
sudo: false,
|
|
418
|
+
what: 'Start the agent at login (the LaunchAgent)',
|
|
419
|
+
settleMs: 15000, // the agent takes a moment to answer /health
|
|
420
|
+
// install writes the plist and (re)loads it:
|
|
421
|
+
// also the cure for a loaded job that exited because another agent held the port.
|
|
422
|
+
commands: () => [[process.execPath, AGENT_BIN, 'install']],
|
|
423
|
+
},
|
|
424
|
+
manual: (ctx, result) => (result.data?.loaded ? `Look at ${LOG_FILE}, then run: simcast-host install` : null),
|
|
425
|
+
},
|
|
426
|
+
{
|
|
427
|
+
id: 'agent-version',
|
|
428
|
+
title: 'Agent version',
|
|
429
|
+
in: DOCTOR,
|
|
430
|
+
needs: ['service'],
|
|
431
|
+
level: 'warn',
|
|
432
|
+
async check(ctx) {
|
|
433
|
+
const running = ctx.results.service?.data?.running || (await health())?.version;
|
|
434
|
+
if (!running) return { ok: false, detail: 'The running agent did not say its version.' };
|
|
435
|
+
if (running === VERSION) return { ok: true, detail: VERSION };
|
|
436
|
+
return { ok: false, detail: `The running agent is ${running}, but ${VERSION} is installed.`, data: { running } };
|
|
437
|
+
},
|
|
438
|
+
manual: 'Restart it: simcast-host install',
|
|
439
|
+
},
|
|
440
|
+
{
|
|
441
|
+
// What the running agent wrote to its status file (bonjour.js). Whether
|
|
442
|
+
// dns-sd under launchd needs Local Network is not known yet, so a failure
|
|
443
|
+
// points there, and at pairing by address.
|
|
444
|
+
id: 'bonjour',
|
|
445
|
+
title: 'Bonjour',
|
|
446
|
+
in: DOCTOR,
|
|
447
|
+
needs: ['service'],
|
|
448
|
+
level: 'warn',
|
|
449
|
+
async check() {
|
|
450
|
+
const b = readStatus()?.bonjour;
|
|
451
|
+
// An agent older than 0.7 reports nothing; agent-version warns about that.
|
|
452
|
+
if (!b) return { ok: true, detail: 'Not reported by the running agent' };
|
|
453
|
+
if (b.state === 'registered') return { ok: true, detail: `Advertised as "${b.name}", so PCs on this network find the Mac by itself` };
|
|
454
|
+
if (b.state === 'off') return { ok: true, detail: 'Off (agent.json "bonjour": false or SIMCAST_BONJOUR=0): PCs pair by address' };
|
|
455
|
+
if (b.state === 'starting') return { ok: false, detail: 'Not registered yet: PCs can\'t find this Mac by itself.', data: { state: b.state } };
|
|
456
|
+
return { ok: false, detail: `Registering "${b.name || 'this Mac'}" failed, so PCs can't find this Mac by itself.`, data: { state: b.state } };
|
|
457
|
+
},
|
|
458
|
+
manual: 'On the Mac, turn on node in System Settings › Privacy & Security › Local Network, then run: simcast-host install. '
|
|
459
|
+
+ 'Or pair by address from the PC: simcast pair <mac-ip>',
|
|
460
|
+
},
|
|
461
|
+
{
|
|
462
|
+
id: 'wake-for-network',
|
|
463
|
+
title: 'Wake for network access',
|
|
464
|
+
in: BOTH,
|
|
465
|
+
needs: ['macos'],
|
|
466
|
+
level: 'warn',
|
|
467
|
+
async check() {
|
|
468
|
+
const womp = await pmsetValue('womp');
|
|
469
|
+
if (womp === null) return { ok: true, detail: 'Not offered on this Mac' };
|
|
470
|
+
return womp ? { ok: true, detail: 'On' } : { ok: false, detail: 'Off: the PC cannot reach this Mac while it sleeps.' };
|
|
471
|
+
},
|
|
472
|
+
fix: { sudo: true, confirm: true, what: 'Turn on wake for network access', commands: () => [['pmset', '-a', 'womp', '1']] },
|
|
473
|
+
},
|
|
474
|
+
{
|
|
475
|
+
id: 'autorestart',
|
|
476
|
+
title: 'Restart after power failure',
|
|
477
|
+
in: DOCTOR,
|
|
478
|
+
needs: ['macos'],
|
|
479
|
+
level: 'warn',
|
|
480
|
+
async check() {
|
|
481
|
+
const v = await pmsetValue('autorestart');
|
|
482
|
+
if (v === null) return { ok: true, detail: 'Not offered on this Mac' };
|
|
483
|
+
return v ? { ok: true, detail: 'On' } : { ok: false, detail: 'Off: after a power cut the Mac stays off until someone presses the power button.' };
|
|
484
|
+
},
|
|
485
|
+
fix: { sudo: true, confirm: true, what: 'Restart automatically after a power failure', commands: () => [['pmset', '-a', 'autorestart', '1']] },
|
|
486
|
+
},
|
|
487
|
+
{
|
|
488
|
+
id: 'reboot-login',
|
|
489
|
+
title: 'Back after a restart',
|
|
490
|
+
in: DOCTOR,
|
|
491
|
+
needs: ['macos'],
|
|
492
|
+
level: 'warn',
|
|
493
|
+
async check() {
|
|
494
|
+
const fv = await probe('fdesetup', ['status']);
|
|
495
|
+
if (fv && /\bOn\b/.test(fv)) {
|
|
496
|
+
return { ok: false, detail: 'FileVault is on, so after a restart the Mac waits at the login screen and the agent does not start.', data: { fileVault: true } };
|
|
497
|
+
}
|
|
498
|
+
const user = await probe('defaults', ['read', '/Library/Preferences/com.apple.loginwindow', 'autoLoginUser']);
|
|
499
|
+
if (!user) return { ok: false, detail: 'Automatic login is off, so after a restart the agent waits until someone logs in.', data: { fileVault: false } };
|
|
500
|
+
return { ok: true, detail: `Logs in automatically as ${user}` };
|
|
501
|
+
},
|
|
502
|
+
manual: (ctx, result) => (result.data?.fileVault
|
|
503
|
+
? 'Log in on the Mac after each restart, or turn FileVault off in System Settings > Privacy & Security and then turn on automatic login.'
|
|
504
|
+
: 'Turn on automatic login in System Settings > Users & Groups, or log in on the Mac after each restart.'),
|
|
505
|
+
},
|
|
506
|
+
{
|
|
507
|
+
id: 'disk',
|
|
508
|
+
title: 'Free disk space',
|
|
509
|
+
in: DOCTOR,
|
|
510
|
+
needs: [],
|
|
511
|
+
level: 'warn',
|
|
512
|
+
async check() {
|
|
513
|
+
const gb = await freeDiskGB();
|
|
514
|
+
if (gb === null) return { ok: false, detail: 'Could not read the free space (df failed).' };
|
|
515
|
+
if (gb < LOW_DISK_GB) return { ok: false, detail: `Only ${gb} GB free; builds and simulator runtimes need ${LOW_DISK_GB} GB or more.`, data: { gb } };
|
|
516
|
+
return { ok: true, detail: `${gb} GB free` };
|
|
517
|
+
},
|
|
518
|
+
manual: 'Free up space: simcast-host clean (add --xcode-derived-data to also clear Xcode\'s build folder).',
|
|
519
|
+
},
|
|
520
|
+
{
|
|
521
|
+
id: 'host-app',
|
|
522
|
+
title: 'Simulator app',
|
|
523
|
+
in: DOCTOR,
|
|
524
|
+
needs: ['macos'],
|
|
525
|
+
level: 'warn',
|
|
526
|
+
async check() {
|
|
527
|
+
const app = await hostAppRunning();
|
|
528
|
+
if (!app) return { ok: true, detail: 'Not open' };
|
|
529
|
+
return { ok: false, detail: `${app} is open, so simcast view gets no picture of the simulators it shows.`, data: { app } };
|
|
530
|
+
},
|
|
531
|
+
manual: (ctx, result) => `Quit ${result.data?.app || 'Simulator'} on the Mac while you use simcast view.`,
|
|
532
|
+
},
|
|
533
|
+
];
|
|
534
|
+
|
|
535
|
+
const byId = new Map(CHECKS.map((c) => [c.id, c]));
|
|
536
|
+
export const checkById = (id) => byId.get(id);
|
|
537
|
+
|
|
538
|
+
// "a,b" or ['a', 'b,c'] -> ['a', 'b', 'c'].
|
|
539
|
+
export function idList(value) {
|
|
540
|
+
if (value == null) return null;
|
|
541
|
+
return [].concat(value).flatMap((v) => String(v).split(',')).map((s) => s.trim()).filter(Boolean);
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
export const passed = (r) => r && (r.status === 'ok' || r.status === 'warn');
|
|
545
|
+
|
|
546
|
+
function textOf(value, ctx, result) {
|
|
547
|
+
return (typeof value === 'function' ? value(ctx, result) : value) || null;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
// Runs one check against the results so far in ctx.results, and stores its result there.
|
|
551
|
+
export async function runCheck(check, ctx) {
|
|
552
|
+
const blockers = check.needs.filter((id) => ctx.results[id] && !passed(ctx.results[id]));
|
|
553
|
+
let result;
|
|
554
|
+
if (blockers.length) {
|
|
555
|
+
const titles = blockers.map((id) => byId.get(id)?.title || id).join(', ');
|
|
556
|
+
result = { id: check.id, title: check.title, status: 'skipped', detail: `Waiting for: ${titles}`, data: {} };
|
|
557
|
+
} else {
|
|
558
|
+
let r;
|
|
559
|
+
try {
|
|
560
|
+
r = await check.check(ctx);
|
|
561
|
+
} catch (err) {
|
|
562
|
+
r = { ok: false, detail: `The check itself failed: ${err.message}` };
|
|
563
|
+
}
|
|
564
|
+
const status = r.ok ? 'ok' : r.status || check.level;
|
|
565
|
+
result = { id: check.id, title: check.title, status, detail: r.detail || '', data: r.data || {} };
|
|
566
|
+
}
|
|
567
|
+
result.fix = null;
|
|
568
|
+
result.manual = null;
|
|
569
|
+
if (result.status !== 'ok') {
|
|
570
|
+
if (check.fix) {
|
|
571
|
+
let commands = null;
|
|
572
|
+
try {
|
|
573
|
+
commands = check.fix.commands(ctx, result);
|
|
574
|
+
} catch {
|
|
575
|
+
commands = null;
|
|
576
|
+
}
|
|
577
|
+
// A skipped check keeps its fix even without commands: they're worked out
|
|
578
|
+
// once what it waits for is done.
|
|
579
|
+
if (commands?.length || result.status === 'skipped') {
|
|
580
|
+
result.fix = { commands: commands?.length ? commands : null, sudo: !!check.fix.sudo, slow: !!check.fix.slow };
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
if (result.status !== 'skipped') result.manual = textOf(check.manual, ctx, result);
|
|
584
|
+
}
|
|
585
|
+
ctx.results[check.id] = result;
|
|
586
|
+
return result;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
// The checks for a scope ('setup' | 'doctor'), narrowed by only/skip (id lists).
|
|
590
|
+
export function selectChecks({ scope, only, skip } = {}) {
|
|
591
|
+
const onlyIds = idList(only);
|
|
592
|
+
const skipIds = new Set(idList(skip) || []);
|
|
593
|
+
return CHECKS.filter((c) => (!scope || c.in.includes(scope))
|
|
594
|
+
&& (!onlyIds || onlyIds.includes(c.id))
|
|
595
|
+
&& !skipIds.has(c.id));
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
export function unknownIds(...lists) {
|
|
599
|
+
return lists.flatMap((l) => idList(l) || []).filter((id) => !byId.has(id));
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
export function newContext() {
|
|
603
|
+
return { results: {} };
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
// Runs the checks in order. A check whose `needs` ran and did not pass is
|
|
607
|
+
// skipped (a need that wasn't selected doesn't block).
|
|
608
|
+
export async function runChecks({ scope, only, skip, ctx = newContext() } = {}) {
|
|
609
|
+
ctx.results ||= {};
|
|
610
|
+
const results = [];
|
|
611
|
+
for (const check of selectChecks({ scope, only, skip })) results.push(await runCheck(check, ctx));
|
|
612
|
+
return results;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
// The shape `--json` prints (no internal data).
|
|
616
|
+
export function publicResult({ id, title, status, detail, fix, manual }) {
|
|
617
|
+
return { id, title, status, detail, fix, manual };
|
|
618
|
+
}
|