@nomac/cli 0.23.1 → 0.25.0
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/package.json +1 -1
- package/skill/SKILL.md +21 -13
- package/src/cli.mjs +1 -1
- package/src/hosted-sessions.mjs +162 -30
- package/src/mac-tools.mjs +14 -7
- package/src/mcp.mjs +14 -14
- package/src/phone-tools.json +3 -3
- package/src/run.mjs +24 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nomac/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0",
|
|
4
4
|
"description": "A real cloud Mac for AI agents: Xcode, the iOS Simulator, signing, TestFlight and App Store publishing, by the minute, over MCP, SSH and HTTPS.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
package/skill/SKILL.md
CHANGED
|
@@ -37,11 +37,11 @@ Store screenshots start the phone with `device: "iphone-pro-max"` (6.9-inch,
|
|
|
37
37
|
details yourself. Poll credits until the balance appears; a checkout URL is
|
|
38
38
|
not a payment. No Apple Developer account is needed for an unsigned build.
|
|
39
39
|
Under an hour left, answers say `low_credit` with a `buy_url`: tell the
|
|
40
|
-
human before a long build (
|
|
41
|
-
2. Install `npm install -g @nomac/cli@0.
|
|
40
|
+
human before a long build (bigger refills earn bonus credit; the answer suggests how many packs).
|
|
41
|
+
2. Install `npm install -g @nomac/cli@0.25.0` (it updates itself after), run `nomac login`, and give the human
|
|
42
42
|
the printed device URL and code. With a key the human made at
|
|
43
43
|
https://nomac.app/keys: `nomac login --with-token < key.txt`, or set
|
|
44
|
-
`NOMAC_API_KEY`. MCP: `claude mcp add nomac -- npx -y @nomac/cli@0.
|
|
44
|
+
`NOMAC_API_KEY`. MCP: `claude mcp add nomac -- npx -y @nomac/cli@0.25.0 mcp`.
|
|
45
45
|
Hosted MCP: https://mcp.nomac.app/mcp with `Authorization: Bearer <nmk_key>`.
|
|
46
46
|
3. `nomac start --json`, wait until ready, `nomac sync .`, then `nomac ssh`.
|
|
47
47
|
Run commands with `nomac exec -- COMMAND`: it prints the output as it
|
|
@@ -55,16 +55,16 @@ Store screenshots start the phone with `device: "iphone-pro-max"` (6.9-inch,
|
|
|
55
55
|
it started, so keep a dev server running with `nomac exec -- nomac-service
|
|
56
56
|
start api -- npx wrangler dev` (`nomac-service logs api`, `stop api`).
|
|
57
57
|
`nomac cancel JOB_ID` stops a command. From CI or a script, `nomac run -- COMMAND`
|
|
58
|
-
does it all on a Mac of its own and stops it after. MCP equivalents are `start_mac`, `exec_mac` (also waits
|
|
59
|
-
`write_mac_file`, `read_mac_file`, `
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
they open in a browser.
|
|
58
|
+
does it all on a Mac of its own and stops it after. MCP equivalents are `start_mac`, `exec_mac` (also waits; curl in it fetches
|
|
59
|
+
a URL), `write_mac_file`, `read_mac_file`, `stop_mac`. For a file up to 2 GiB
|
|
60
|
+
from the human, or to hand them a build, use `create_mac_link` (direction
|
|
61
|
+
upload or download; with `nomac mcp`, `create_mac_upload_link` and
|
|
62
|
+
`create_mac_download_link`): it returns a url they open in a browser.
|
|
63
63
|
4. Download work with `nomac pull ./build`, or to any local path with the
|
|
64
64
|
folder on the Mac named: `nomac pull /tmp/out --from build/export`. Then
|
|
65
65
|
`nomac stop --json` and confirm `cleanup_confirmed`.
|
|
66
66
|
|
|
67
|
-
The CLI keeps the project on the
|
|
67
|
+
The CLI keeps the project on the Mac's drive, in `~/drive/src/<folder
|
|
68
68
|
name>`, which is kept between sessions; stopping deletes everything else on
|
|
69
69
|
the Mac, logs included. Download what you need from outside `~/drive` before
|
|
70
70
|
stopping. Keep the drive under 10 GB: a Mac that does not hold it yet downloads
|
|
@@ -78,10 +78,18 @@ running in the background keeps it awake while it uses the CPU. In its last
|
|
|
78
78
|
`nomac extend 60` (MCP `extend_mac`) adds an hour, up to 8 hours in all; for
|
|
79
79
|
`reason: credit`, the human adds credit. The CLI updates itself in the
|
|
80
80
|
background (`NOMAC_NO_AUTO_UPDATE=1` turns it off; `nomac update` now).
|
|
81
|
-
One-minute minimum, then
|
|
81
|
+
One-minute minimum, then billed per minute. One Mac at a time unless a second is started with --parallel; no overage.
|
|
82
82
|
For work that needs two Macs at once, `nomac start --parallel` from another
|
|
83
83
|
folder (MCP `start_mac` with `parallel: true`) starts a second, for accounts
|
|
84
|
-
that bought credit while NoMac has a Mac to spare
|
|
84
|
+
that bought credit while NoMac has a Mac to spare. Every Mac gets a 20 GB
|
|
85
|
+
drive at `~/drive`, on one Mac at a time: the first gets the account's
|
|
86
|
+
default drive, a second a new drive of its own, and `nomac status` and
|
|
87
|
+
`~/NOMAC.md` name it. To keep an agent's work apart, give it a drive:
|
|
88
|
+
`nomac start --drive NAME` (made empty the first time; the folder asks for it
|
|
89
|
+
again at its next start), `--drive-from default` to start it as a copy, and
|
|
90
|
+
`--reuse` to be given the running Mac that has it. `nomac drive` lists the
|
|
91
|
+
drives. A Mac running a `nomac run` command is never offered to attach: it
|
|
92
|
+
stops when its command ends.
|
|
85
93
|
If start returns `insufficient_credit`, buy credit as in step 1, then retry
|
|
86
94
|
with the same request key.
|
|
87
95
|
Keep the same request key and arguments after uncertain responses; inspect
|
|
@@ -103,7 +111,7 @@ See the screen with `nomac screenshot` (saves
|
|
|
103
111
|
`nomac-screenshot.jpg`; `--simulator` for the iOS Simulator) or MCP
|
|
104
112
|
`screenshot_mac`, which returns an image you can look at. Record a video for
|
|
105
113
|
the human with `nomac record`, do the work, then `nomac record stop` (saves the
|
|
106
|
-
MP4 and prints a share link); MCP `
|
|
114
|
+
MP4 and prints a share link); MCP `mac_recording` (with `nomac mcp`, `start_mac_recording` and `stop_mac_recording`).
|
|
107
115
|
Commands drive any app with AppleScript without a permission prompt. For real
|
|
108
116
|
keyboard and mouse, also on the lock screen and in password dialogs, use
|
|
109
117
|
`nomac input type TEXT`, `nomac input click X Y`, `nomac unlock` (MCP
|
|
@@ -189,7 +197,7 @@ the human, then call again.
|
|
|
189
197
|
|
|
190
198
|
## When stuck
|
|
191
199
|
|
|
192
|
-
`report_issue` with the
|
|
200
|
+
`report_issue` with the Mac's `session_id` (and `job_id`) files a support ticket with full
|
|
193
201
|
context auto-attached (deduped, so safe to call). Its optional `email` requests
|
|
194
202
|
a direct resolution update; without it, read replies with the same tool. If the
|
|
195
203
|
tool returns a Private Relay warning, explain that Apple relay addresses may
|
package/src/cli.mjs
CHANGED
|
@@ -29,7 +29,7 @@ Use it:
|
|
|
29
29
|
nomac password the Mac's login password (also $NOMAC_MAC_PASSWORD on it)
|
|
30
30
|
nomac permit APP camera grant an app privacy permissions, so it never asks
|
|
31
31
|
nomac defaults options every new Mac starts with (nomac defaults --help)
|
|
32
|
-
nomac drive the account's
|
|
32
|
+
nomac drive the account's drives: each Mac has one at ~/drive, kept between sessions
|
|
33
33
|
nomac record record a video; nomac record stop saves it with a share link
|
|
34
34
|
nomac status state, cost so far and when it stops
|
|
35
35
|
nomac extend 60 keep the Mac running another hour (8 hours in all)
|
package/src/hosted-sessions.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
-
import { chmodSync, readFileSync, watch as watchFolder, writeFileSync } from "node:fs";
|
|
2
|
+
import { chmodSync, readFileSync, rmSync, watch as watchFolder, writeFileSync } from "node:fs";
|
|
3
3
|
import { basename, join, resolve, sep } from "node:path";
|
|
4
4
|
import { parseArgs } from "node:util";
|
|
5
5
|
import { api, CliError } from "./api.mjs";
|
|
@@ -47,13 +47,23 @@ const HELP = `Nomac cloud Mac sessions
|
|
|
47
47
|
to an app by bundle ID, so it never asks
|
|
48
48
|
nomac defaults [--prompts ask] [--permit APP=camera,microphone] [--drive none] [--reset]
|
|
49
49
|
what every new Mac starts with (shows them with no options)
|
|
50
|
-
nomac drive
|
|
51
|
-
space used
|
|
52
|
-
nomac
|
|
50
|
+
nomac drive the account's drives: each Mac has one at ~/drive, kept between
|
|
51
|
+
sessions and on one Mac at a time; space used, which Mac has it
|
|
52
|
+
nomac drive reset [NAME] empty a drive (the default unless named)
|
|
53
|
+
nomac drive rename OLD NEW rename a drive (not the default)
|
|
54
|
+
nomac start --drive NAME this Mac with that drive, made empty the first time; this folder
|
|
55
|
+
asks for it again at its next start (--drive account forgets it).
|
|
56
|
+
If a running Mac has it, the start is refused and names that Mac;
|
|
57
|
+
--reuse attaches this folder to it
|
|
58
|
+
nomac start --drive NAME --drive-from default
|
|
59
|
+
a new drive that starts as a copy of another's last save
|
|
60
|
+
nomac start --drive none this Mac without a drive
|
|
53
61
|
nomac start --parallel a second Mac beside the account's running one, from another
|
|
54
|
-
folder (accounts that bought credit, while a Mac is spare)
|
|
55
|
-
|
|
56
|
-
|
|
62
|
+
folder (accounts that bought credit, while a Mac is spare), with
|
|
63
|
+
a drive of its own while the first has the default. Without it,
|
|
64
|
+
a start while the account's Mac runs elsewhere is refused and
|
|
65
|
+
names it: nomac attach ID uses it.
|
|
66
|
+
A Mac running a nomac run command is never named or attached.
|
|
57
67
|
nomac ssh-config [--alias nomac] [--print]
|
|
58
68
|
name this folder's Mac in your SSH config (Host nomac), for
|
|
59
69
|
VS Code or Cursor Remote-SSH, Claude Code SSH sessions, ssh nomac,
|
|
@@ -105,7 +115,9 @@ const options = {
|
|
|
105
115
|
"no-open": { type: "boolean" }, simulator: { type: "boolean" }, output: { type: "string", short: "o" }, max: { type: "string" },
|
|
106
116
|
prompts: { type: "string" }, gatekeeper: { type: "string" }, copy: { type: "boolean" }, app: { type: "boolean" },
|
|
107
117
|
right: { type: "boolean" }, double: { type: "boolean" }, "no-screenshot": { type: "boolean" },
|
|
108
|
-
permit: { type: "string", multiple: true }, reset: { type: "boolean" }, drive: { type: "string" },
|
|
118
|
+
permit: { type: "string", multiple: true }, reset: { type: "boolean" }, drive: { type: "string" }, "drive-from": { type: "string" }, reuse: { type: "boolean" },
|
|
119
|
+
// nomac run's own (not in the help): keep what sync sent in the drive, since each run starts from a fresh local state.
|
|
120
|
+
"baseline-on-mac": { type: "boolean" },
|
|
109
121
|
parallel: { type: "boolean" }, alias: { type: "string" }, print: { type: "boolean" },
|
|
110
122
|
};
|
|
111
123
|
/** --permit com.example.App=camera,microphone (or =all), as the permissions option. */
|
|
@@ -123,14 +135,28 @@ const oneOf = (value, allowed, flag) => {
|
|
|
123
135
|
if (!allowed.includes(value)) throw new CliError(`${flag} takes ${allowed.join(" or ")}.`);
|
|
124
136
|
return value;
|
|
125
137
|
};
|
|
126
|
-
/**
|
|
127
|
-
|
|
138
|
+
/** A drive's name as the server takes it (LIM-394): "default", one you choose, or one NoMac made (drive-2). */
|
|
139
|
+
const DRIVE_NAME = /^[A-Za-z0-9][A-Za-z0-9._:@-]{0,63}$/;
|
|
140
|
+
export function driveNameOption(value, flag) {
|
|
141
|
+
if (!DRIVE_NAME.test(value ?? "")) throw new CliError(`${flag} takes a drive's name: 1 to 64 letters, digits and . _ : @ -, starting with a letter or digit, like ${flag === "--drive" ? "feature-x (or account, or none)" : flag === "--drive-from" ? "default" : "feature-x"}.`);
|
|
142
|
+
return value;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* The access the person chose, or none: the server's defaults then apply (fully open). At a start --drive also takes a
|
|
146
|
+
* drive's name and --drive-from a drive to copy (LIM-394); saved defaults take only account or none.
|
|
147
|
+
*/
|
|
148
|
+
function accessOption(values, { start = false } = {}) {
|
|
128
149
|
const permissions = permitOption(values.permit);
|
|
129
|
-
if (
|
|
150
|
+
if (!start && values["drive-from"] !== undefined) throw new CliError("--drive-from belongs to a start: nomac start --drive NAME --drive-from default.");
|
|
151
|
+
if (values.prompts === undefined && values.gatekeeper === undefined && values.drive === undefined && values["drive-from"] === undefined && !permissions) return undefined;
|
|
152
|
+
if (values.drive === "none" && values["drive-from"] !== undefined) throw new CliError("--drive-from makes a drive, so it goes with --drive NAME (or no --drive), never --drive none.");
|
|
130
153
|
return {
|
|
131
154
|
...(values.prompts !== undefined ? { prompts: oneOf(values.prompts, ["auto", "ask"], "--prompts") } : {}),
|
|
132
155
|
...(values.gatekeeper !== undefined ? { gatekeeper: oneOf(values.gatekeeper, ["off", "on"], "--gatekeeper") } : {}),
|
|
133
|
-
...(values.drive !== undefined ? { drive:
|
|
156
|
+
...(values.drive !== undefined ? { drive: start && !["account", "none"].includes(values.drive) ? driveNameOption(values.drive, "--drive")
|
|
157
|
+
: !start && !["account", "none"].includes(values.drive) ? (() => { throw new CliError("--drive takes account or none in saved defaults: they turn the drive on or off; name a drive at each start (nomac start --drive NAME)."); })()
|
|
158
|
+
: oneOf(values.drive, ["account", "none"], "--drive") } : {}),
|
|
159
|
+
...(values["drive-from"] !== undefined ? { drive_from: driveNameOption(values["drive-from"], "--drive-from") } : {}),
|
|
134
160
|
...(permissions ? { permissions } : {}),
|
|
135
161
|
};
|
|
136
162
|
}
|
|
@@ -185,7 +211,9 @@ const validRequestKey = value => typeof value === "string" && /^[A-Za-z0-9_.:-]{
|
|
|
185
211
|
// unreadable response or idempotency conflict may still own a real session.
|
|
186
212
|
const startRejections = new Set(["invalid_request", "invalid_public_key", "profile_unavailable", "session_cap_too_low",
|
|
187
213
|
"weekly_time_unavailable", "weekly_time_expired", "insufficient_compute_credit", "insufficient_credit", "compute_account_blocked",
|
|
188
|
-
"session_limit_reached", "organization_not_found", "compute_unavailable", "unauthenticated", "invalid_origin"
|
|
214
|
+
"session_limit_reached", "organization_not_found", "compute_unavailable", "unauthenticated", "invalid_origin",
|
|
215
|
+
// LIM-394: the drive asked for is on a running Mac, the account's drives are all in use, or the drive to copy is missing.
|
|
216
|
+
"drive_in_use", "drive_limit_reached", "drive_not_found"]);
|
|
189
217
|
export async function sessionAccess(id, request = api) {
|
|
190
218
|
sessionId(id);
|
|
191
219
|
const access = await request("POST", `/api/v1/mac/sessions/${id}/access`);
|
|
@@ -374,6 +402,40 @@ export function macLine(image) {
|
|
|
374
402
|
const xcode = others.length ? `Xcode ${image.xcode} (default) and ${others.map(x => `Xcode ${x.version} (${x.path})`).join(" and ")}` : `Xcode ${image.xcode}`;
|
|
375
403
|
return `Mac: macOS ${image.macos.split(" ")[0]}, ${xcode}${(image.simulator_runtimes ?? []).map(r => `, ${r} Simulator`).join("")}`;
|
|
376
404
|
}
|
|
405
|
+
/**
|
|
406
|
+
* A Mac without a drive: since LIM-394 only when every drive of the account was on a Mac at its drive limit; before, while
|
|
407
|
+
* another Mac had the account's one drive (LIM-383).
|
|
408
|
+
*/
|
|
409
|
+
const driveElsewhereLine = (holder, limit) => limit
|
|
410
|
+
? `Drive: not on this Mac. The account keeps at most ${limit} drives and every one was on a Mac or still saving, so nothing here is kept after it stops: push or pull what you need first. A Mac started once one of those stops gets a drive.`
|
|
411
|
+
: `Drive: not on this Mac. The account's drive is on its Mac ${holder} (one Mac at a time), so nothing here is kept after it stops: push or pull what you need first. A Mac started after ${holder} stops gets the drive.`;
|
|
412
|
+
/** The account's drives; from a site before LIM-394 (no /api/v1/mac/drives), its one drive as the default. */
|
|
413
|
+
export async function fetchDrives(request) {
|
|
414
|
+
try { return await request("GET", "/api/v1/mac/drives"); }
|
|
415
|
+
catch (error) {
|
|
416
|
+
if (error?.status !== 404) throw error;
|
|
417
|
+
const answer = await request("GET", "/api/v1/mac/drive");
|
|
418
|
+
return { drives: answer.drive ? [{ name: "default", default: true, ...answer.drive }] : [], limit: 1, available: answer.available, message: answer.message };
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
/** nomac drive: the account's drives, one line each, then how to use them (LIM-394). */
|
|
422
|
+
export function driveList(answer) {
|
|
423
|
+
const drives = answer.drives ?? [];
|
|
424
|
+
if (!drives.length) return answer.message;
|
|
425
|
+
const width = Math.max(...drives.map(d => d.name.length));
|
|
426
|
+
const today = new Date().toISOString().slice(0, 10);
|
|
427
|
+
const where = d => d.in_use ? `on ${d.in_use.session_id} now` : d.saving ? "saving its last session"
|
|
428
|
+
: `used ${d.last_used_at.slice(0, 10) === today ? "today" : `on ${d.last_used_at.slice(0, 10)}`}, deleted on ${d.delete_after.slice(0, 10)} unless a Mac uses it`;
|
|
429
|
+
return [`Drives: ${drives.length} of at most ${answer.limit ?? 10}, each at ~/drive on one Mac at a time.`,
|
|
430
|
+
...drives.map(d => ` ${d.name.padEnd(width)} ${(d.used_bytes / 1e9).toFixed(1)} GB of ${Math.round(d.size_bytes / 2 ** 30)} GB, ${where(d)}${d.copied_from?.name ? `, a copy of ${d.copied_from.name}` : ""}`),
|
|
431
|
+
"A Mac that names none gets the default, or a new drive while another Mac has it. Name one: nomac start --drive NAME (add --drive-from default to start it as a copy). Empty one: nomac drive reset NAME. Rename one: nomac drive rename OLD NEW."].join("\n");
|
|
432
|
+
}
|
|
433
|
+
/** Which drive a Mac has (LIM-394): the default goes unnamed, as with one Mac; any other is named, with how to get it again. */
|
|
434
|
+
export function driveLine(d) {
|
|
435
|
+
const which = !d.name || d.default !== false ? `${d.path}` : `${d.path}, drive ${d.name}`;
|
|
436
|
+
const again = d.name && d.default === false ? ` Get it again: nomac start --drive ${d.name}.${/^drive-[0-9]+$/.test(d.name) ? ` It is deleted after 30 days unused; nomac drive rename ${d.name} NAME keeps it 90.` : ""}` : "";
|
|
437
|
+
return `Drive: ${which}, kept between sessions${d.source === "r2" ? " (downloaded to this Mac before boot)" : ""}.${again}`;
|
|
438
|
+
}
|
|
377
439
|
export function statusSummary(session, image) {
|
|
378
440
|
const lines = [`${session.id}: ${session.state}`];
|
|
379
441
|
if (macLine(image)) lines.push(macLine(image));
|
|
@@ -385,10 +447,13 @@ export function statusSummary(session, image) {
|
|
|
385
447
|
}
|
|
386
448
|
const d = session.drive;
|
|
387
449
|
if (d && ["mounted", "saving", "saved", "unavailable", "not_saved"].includes(d.state)) {
|
|
388
|
-
lines.push(d.state === "mounted" ?
|
|
450
|
+
lines.push(d.state === "mounted" ? driveLine(d)
|
|
389
451
|
: d.state === "saving" ? "Drive: saving this session's changes." : d.state === "saved" ? `Drive: saved (version ${d.saved_version}).`
|
|
390
452
|
: d.state === "not_saved" ? `Drive: this session's changes were not saved. ${d.message ?? ""}`.trim() : `Drive: not attached. ${d.message ?? ""}`.trim());
|
|
391
453
|
}
|
|
454
|
+
// Waiting for a Mac that is stopping, so this one starts from its save (LIM-394).
|
|
455
|
+
if (d && d.state === "waiting" && d.message) lines.push(/^Drive /.test(d.message) ? d.message : `Drive: ${d.message}`);
|
|
456
|
+
if (!d && (session.drive_held_by || session.drive_limit) && ["queued", "provisioning", "ready"].includes(session.state)) lines.push(driveElsewhereLine(session.drive_held_by, session.drive_limit));
|
|
392
457
|
if (session.state === "ready" && session.access) {
|
|
393
458
|
lines.push(`Open to your agent: ${session.access.prompts === "auto" ? "no administrator password prompts" : "macOS's usual prompts"}. Login password: nomac password ($NOMAC_MAC_PASSWORD on the Mac).`);
|
|
394
459
|
}
|
|
@@ -415,7 +480,9 @@ export async function hostedRequest(id, method, path, params = {}, { request = a
|
|
|
415
480
|
return transport(method, path, { ...params, gateway: access.gateway, token: access.token });
|
|
416
481
|
}
|
|
417
482
|
export async function hostedSessionCommand(command, argv, { store = sessionStore(), request = api, transport = macRequest, run = runProcess, print = console.log, sleep = ms => new Promise(r => setTimeout(r, ms)), now = Date.now,
|
|
418
|
-
stdout = data => process.stdout.write(data), stderr = data => process.stderr.write(data), exitWith = code => { process.exitCode = code; } , watch = watchFolder, stopWatching = undefined, debounceMs = 600, readInput = pipedInput
|
|
483
|
+
stdout = data => process.stdout.write(data), stderr = data => process.stderr.write(data), exitWith = code => { process.exitCode = code; } , watch = watchFolder, stopWatching = undefined, debounceMs = 600, readInput = pipedInput,
|
|
484
|
+
/** nomac run's start: "run" marks its Mac, which agents' refusals, attach and the drive then leave out (LIM-383). */
|
|
485
|
+
purpose = undefined} = {}) {
|
|
419
486
|
let parsed;
|
|
420
487
|
if (["exec", "ssh"].includes(command)) argv = withCommandSeparator(argv);
|
|
421
488
|
try { parsed = parseArgs({ args: argv, options, allowPositionals: true }); }
|
|
@@ -444,7 +511,12 @@ export async function hostedSessionCommand(command, argv, { store = sessionStore
|
|
|
444
511
|
: "Check: nomac status";
|
|
445
512
|
// A ready Mac says what is on it, as nomac status does.
|
|
446
513
|
const mac = result.session.state === "ready" && macLine(lastImage) ? `${macLine(lastImage)}\n` : "";
|
|
447
|
-
|
|
514
|
+
const elsewhere = !result.session.drive && (result.session.drive_held_by || result.session.drive_limit) && ["queued", "provisioning", "ready"].includes(result.session.state)
|
|
515
|
+
? `${driveElsewhereLine(result.session.drive_held_by, result.session.drive_limit)}\n` : "";
|
|
516
|
+
// A drive other than the default: which one, how it was made, and how to get it again (the server's own words).
|
|
517
|
+
const drive = result.session.drive && result.session.drive.default === false && ["queued", "provisioning", "ready"].includes(result.session.state)
|
|
518
|
+
? `${result.session.drive.message ? (/^Drive /.test(result.session.drive.message) ? result.session.drive.message : `Drive: ${result.session.drive.message}`) : driveLine(result.session.drive)}\n` : "";
|
|
519
|
+
print(`${result.attached ? `${result.attached}\n` : ""}${result.session.id}: ${result.session.state}\n${mac}${elsewhere}${drive}${next}\n${usage}${result.warning ? `\n${result.warning}` : ""}${result.feedback_request ? `\n\n${result.feedback_request}` : ""}`);
|
|
448
520
|
return result;
|
|
449
521
|
};
|
|
450
522
|
const saveView = (local, view) => {
|
|
@@ -492,7 +564,9 @@ export async function hostedSessionCommand(command, argv, { store = sessionStore
|
|
|
492
564
|
const path = String(job?.stdout ?? "").trim();
|
|
493
565
|
if (job?.exit_code === 0 && path.startsWith("/Users/agent/drive/src/") && !path.slice(23).includes("/")) {
|
|
494
566
|
// The same folder on the drive as last time: what was synced there then is still there.
|
|
495
|
-
|
|
567
|
+
// Only on the same drive (LIM-394: a folder's next Mac may have another one, where none of it is).
|
|
568
|
+
const kept = local.driveBaselines?.[local.snapshot?.drive?.id];
|
|
569
|
+
if (kept?.path === path) store.saveBaseline(kept.baseline);
|
|
496
570
|
Object.assign(local, { workspace: validateWorkspace(path), workspaceOnDrive: true });
|
|
497
571
|
} else {
|
|
498
572
|
// The drive itself refused (full, or not writable): this session works in ~/workspace, and says so.
|
|
@@ -539,11 +613,22 @@ export async function hostedSessionCommand(command, argv, { store = sessionStore
|
|
|
539
613
|
/** Where this folder's project is on the Mac, once a ready Mac has decided it. */
|
|
540
614
|
const project = local => local.state === "ready" && local.workspaceDecided ? { project: { path: local.workspace, on_drive: Boolean(local.workspaceOnDrive) } } : {};
|
|
541
615
|
/** The last session's folder on the drive and what was synced to it, for the next session to pick up. */
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
616
|
+
// What this folder synced to each drive it used, by drive id, kept for its next Mac with that drive (LIM-394: a folder's
|
|
617
|
+
// Macs may alternate between drives, or a start may be refused in between); and the drive this folder was told to use
|
|
618
|
+
// (nomac start --drive NAME), which its next start asks for again. At most 10 drives' baselines are kept.
|
|
619
|
+
const previousDrive = old => {
|
|
620
|
+
const baselines = { ...(old?.driveBaselines ?? {}) };
|
|
621
|
+
if (old?.workspaceOnDrive && old.snapshot?.drive?.id) baselines[old.snapshot.drive.id] = { path: old.workspace, baseline: store.baseline() };
|
|
622
|
+
const kept = Object.fromEntries(Object.entries(baselines).slice(-10));
|
|
623
|
+
return { ...(Object.keys(kept).length ? { driveBaselines: kept } : {}), ...(old?.folderDrive ? { folderDrive: old.folderDrive } : {}) };
|
|
624
|
+
};
|
|
625
|
+
/**
|
|
626
|
+
* The account's running Macs, newest first: queued, starting or ready. A Mac nomac run started for one command
|
|
627
|
+
* (purpose run) is left out, or only those with runs: its run stops it when the command ends (LIM-383).
|
|
628
|
+
*/
|
|
629
|
+
async function liveSessions({ runs = false } = {}) {
|
|
545
630
|
const answer = await request("GET", "/api/v1/mac/sessions");
|
|
546
|
-
return (Array.isArray(answer?.sessions) ? answer.sessions : []).filter(s => ["queued", "provisioning", "ready"].includes(s.state));
|
|
631
|
+
return (Array.isArray(answer?.sessions) ? answer.sessions : []).filter(s => ["queued", "provisioning", "ready"].includes(s.state) && (s.purpose === "run") === runs);
|
|
547
632
|
}
|
|
548
633
|
/** This folder now uses that Mac: a fresh key of its own, then ready() adds it once the Mac is ready. */
|
|
549
634
|
async function attachTo(view) {
|
|
@@ -689,11 +774,21 @@ export async function hostedSessionCommand(command, argv, { store = sessionStore
|
|
|
689
774
|
return desktop(local, { values, print });
|
|
690
775
|
}
|
|
691
776
|
if (command === "drive") {
|
|
692
|
-
|
|
693
|
-
const
|
|
777
|
+
// The account's drives (LIM-394): list them, empty one (the default unless named), or rename one.
|
|
778
|
+
const usage = "Usage: nomac drive [--json] | nomac drive reset [NAME] | nomac drive rename OLD NEW";
|
|
779
|
+
const [verb, ...names] = positionals;
|
|
780
|
+
if (verb !== undefined && !["reset", "rename"].includes(verb)) throw new CliError(usage);
|
|
781
|
+
if ((verb === "reset" && names.length > 1) || (verb === "rename" && names.length !== 2)) throw new CliError(usage);
|
|
782
|
+
names.forEach(name => driveNameOption(name, "nomac drive"));
|
|
783
|
+
const path = name => `/api/v1/mac/drives/${encodeURIComponent(name)}`;
|
|
784
|
+
// A site before LIM-394 has only the default drive (/api/v1/mac/drive): reset of the default still works there.
|
|
785
|
+
const old = error => error?.status === 404 && (!names[0] || names[0] === "default");
|
|
786
|
+
const answer = verb === "reset" ? await request("DELETE", path(names[0] ?? "default")).catch(error => { if (old(error)) return request("DELETE", "/api/v1/mac/drive"); throw error; })
|
|
787
|
+
: verb === "rename" ? await request("PATCH", path(names[0]), { body: { name: names[1] } })
|
|
788
|
+
: await fetchDrives(request);
|
|
694
789
|
if (values.json) { print(JSON.stringify(answer, null, 2)); return answer; }
|
|
695
|
-
|
|
696
|
-
print(
|
|
790
|
+
if (verb) { print(answer.message); return answer; }
|
|
791
|
+
print(driveList(answer));
|
|
697
792
|
return answer;
|
|
698
793
|
}
|
|
699
794
|
if (command === "defaults") {
|
|
@@ -710,7 +805,7 @@ export async function hostedSessionCommand(command, argv, { store = sessionStore
|
|
|
710
805
|
const e = answer.effective, apps = Object.entries(e.permissions ?? {});
|
|
711
806
|
print([`Every new Mac starts with: ${e.prompts === "auto" ? "no administrator password prompts, privacy prompts and password dialogs answered on the Mac" : "macOS's usual prompts"}.`,
|
|
712
807
|
apps.length ? `Permissions granted at start: ${apps.map(([app, list]) => `${app} (${list === "all" ? "all" : list.join(", ")})`).join("; ")}.` : "No app is granted permissions at start (nomac defaults --permit APP=camera,microphone).",
|
|
713
|
-
e.drive === "none" ? "Macs start without
|
|
808
|
+
e.drive === "none" ? "Macs start without a drive (nomac defaults --drive account turns drives back on)." : "Every Mac has a drive at ~/drive, kept between sessions (nomac drive lists them).",
|
|
714
809
|
"A start's own --prompts, --permit or --drive wins for that Mac. nomac defaults --reset goes back to fully open."].join("\n"));
|
|
715
810
|
return answer;
|
|
716
811
|
}
|
|
@@ -829,16 +924,18 @@ export async function hostedSessionCommand(command, argv, { store = sessionStore
|
|
|
829
924
|
return output({ session: current.snapshot, attached: `This folder already uses ${current.id}.`, ...project(current) });
|
|
830
925
|
}
|
|
831
926
|
const target = wanted ? live.find(s => s.id === wanted) : live.length === 1 ? live[0] : undefined;
|
|
927
|
+
if (!target && wanted && (await liveSessions({ runs: true }).catch(() => [])).some(s => s.id === wanted)) throw new CliError(`${wanted} runs a nomac run command (a CI job or a script), and that run stops it when the command ends, so it cannot be attached. Start a Mac of your own: nomac start`);
|
|
832
928
|
if (!target) throw new CliError(wanted ? `No running Mac ${wanted} in this account.` : live.length ? `This account has ${live.length} running Macs: name one, nomac attach ${live.map(s => s.id).join(" | ")}` : "This account has no running Mac. Start one: nomac start");
|
|
833
929
|
const local = await attachTo(target);
|
|
834
930
|
return output({ session: local.snapshot, attached: `Attached to ${local.id}, started elsewhere: ssh, sync, pull and exec work from this folder. If another agent or folder is using it, leave it running when you are done here (nomac stop stops it for everyone).`, ...project(local) });
|
|
835
931
|
}
|
|
836
932
|
if (command === "start") {
|
|
837
|
-
if (positionals.length) throw new CliError("Usage: nomac start [--wait SECONDS] [--json]");
|
|
933
|
+
if (positionals.length) throw new CliError("Usage: nomac start [--wait SECONDS] [--drive NAME] [--reuse] [--json]");
|
|
838
934
|
let local = store.load();
|
|
839
935
|
if (local && local.mode !== "hosted") throw new CliError("An existing Mac workspace is attached.");
|
|
840
936
|
const limits = { max_duration_seconds: integer(values["max-duration"], 7200, 60, 28800, "--max-duration (seconds, 8 hours at most)"), idle_timeout_seconds: integer(values["idle-timeout"], 600, 60, 3600, "--idle-timeout (seconds, 1 hour at most)"), spend_cap_microunits: budget(values["max-cost"]) };
|
|
841
|
-
|
|
937
|
+
let access = accessOption(values, { start: true });
|
|
938
|
+
const named = value => value !== undefined && !["account", "none"].includes(value);
|
|
842
939
|
// Older CLIs persisted invalid keys before contacting the API. Such a key
|
|
843
940
|
// cannot pass server validation and therefore cannot have allocated a VM.
|
|
844
941
|
if (local && !local.id && !validRequestKey(local.requestKey)) { local.state = "failed"; store.save(local); }
|
|
@@ -858,15 +955,26 @@ export async function hostedSessionCommand(command, argv, { store = sessionStore
|
|
|
858
955
|
}
|
|
859
956
|
if (values["request-key"] !== undefined && values["request-key"] !== local.requestKey) throw new CliError("A session is already attached under a different request key. Inspect it or stop it before starting another.");
|
|
860
957
|
if (otherAccess()) {
|
|
861
|
-
throw new CliError("This session was started with different --prompts, --gatekeeper or --
|
|
958
|
+
throw new CliError("This session was started with different --prompts, --gatekeeper, --permit or --drive. Stop it and start a fresh session to change them; nomac permit grants more on the running Mac.");
|
|
862
959
|
}
|
|
863
960
|
}
|
|
864
961
|
if (!local || ["stopped", "failed"].includes(local.state)) {
|
|
962
|
+
// The drive this folder was told to use before (LIM-394), for a new request only: asked for again by its current name
|
|
963
|
+
// (looked up by id, so a rename keeps it), unless this start names a drive, turns it off, or copies one (--drive-from
|
|
964
|
+
// makes a new drive). --drive account forgets it. A request already sent is repeated as it was.
|
|
965
|
+
const remembered = values.drive === undefined && values["drive-from"] === undefined ? store.load()?.folderDrive : undefined;
|
|
966
|
+
if (remembered) {
|
|
967
|
+
const known = (await fetchDrives(request).catch(() => ({ drives: [] }))).drives?.find?.(d => d.id === remembered.id);
|
|
968
|
+
access = { ...(access ?? {}), drive: known?.name ?? remembered.name };
|
|
969
|
+
}
|
|
970
|
+
if (values.reuse && !named(access?.drive)) throw new CliError("--reuse goes with a drive's name: nomac start --drive NAME --reuse gives back the running Mac that has it.");
|
|
865
971
|
const identity = join(store.directory, `id_ed25519_${randomUUID()}`);
|
|
866
972
|
await run("ssh-keygen", ["-q", "-t", "ed25519", "-N", "", "-C", "nomac-session", "-f", identity]);
|
|
867
973
|
local = { mode: "hosted", state: "requesting", outcomeUnknown: false, identity, requestKey: values["request-key"] ?? `cli-${randomUUID()}`,
|
|
868
|
-
request: { profile: "standard", public_key: readFileSync(`${identity}.pub`, "utf8").trim(), limits, ...(access ? { access } : {}), ...(values.parallel ? { parallel: true } : {})
|
|
974
|
+
request: { profile: "standard", public_key: readFileSync(`${identity}.pub`, "utf8").trim(), limits, ...(access ? { access } : {}), ...(values.parallel ? { parallel: true } : {}),
|
|
975
|
+
...(values.reuse ? { reuse: true } : {}), ...(purpose ? { purpose } : {}) },
|
|
869
976
|
...previousDrive(store.load()) };
|
|
977
|
+
if (values.drive === "account") delete local.folderDrive;
|
|
870
978
|
store.save(local); store.saveBaseline({});
|
|
871
979
|
}
|
|
872
980
|
if (!local.id) {
|
|
@@ -886,10 +994,26 @@ export async function hostedSessionCommand(command, argv, { store = sessionStore
|
|
|
886
994
|
const running = (await liveSessions().catch(() => [])).map(s => s.id);
|
|
887
995
|
if (running.length) throw new CliError(error.message, `${error.friendly ?? error.message}\n use ${running.length === 1 ? "it" : "one"} from this folder: nomac attach ${running.join(" | ")}${values.parallel ? "" : "\n a Mac of this folder's own at the same time: nomac start --parallel"}`, error.status, error.code, error.details);
|
|
888
996
|
}
|
|
997
|
+
// The drive this start named is on a running Mac (LIM-394): the server names it; this folder moves there only when asked.
|
|
998
|
+
// A nomac run Mac that has it (details.runs) is never offered: its run stops it when the command ends.
|
|
999
|
+
if (error.code === "drive_in_use" && error.details?.running?.[0]) {
|
|
1000
|
+
throw new CliError(error.message, `${error.friendly ?? error.message}\n use it from this folder: nomac attach ${error.details.running[0]}\n or be given it at the start: nomac start --drive ${error.details.drive ?? local.request.access?.drive} --reuse`, error.status, error.code, error.details);
|
|
1001
|
+
}
|
|
889
1002
|
throw error;
|
|
890
1003
|
}
|
|
1004
|
+
// reuse: the running Mac with this drive is the answer, so this folder attaches to it, as the person asked.
|
|
1005
|
+
if (result.reused) {
|
|
1006
|
+
const drive = local.request.access?.drive, abandoned = local.identity;
|
|
1007
|
+
local = await attachTo(result.session);
|
|
1008
|
+
for (const file of [abandoned, `${abandoned}.pub`]) rmSync(file, { force: true });
|
|
1009
|
+
if (drive) { local.folderDrive = { id: result.session.drive?.id, name: result.session.drive?.name ?? drive }; store.save(local); }
|
|
1010
|
+
return output({ session: local.snapshot, reused: true, attached: `Given back ${local.id}, the running Mac with drive ${drive}: ssh, sync, pull and exec work from this folder. If another agent or folder is using it, leave it running when you are done here (nomac stop stops it for everyone).`, ...project(local) });
|
|
1011
|
+
}
|
|
891
1012
|
// The start's warning (what the Mac allows, how to opt out) is shown with every start of this session.
|
|
892
1013
|
if (result.warning) local.warning = result.warning;
|
|
1014
|
+
// A drive this folder named is remembered by id, so its next start asks for it again even after a rename (LIM-394).
|
|
1015
|
+
const asked = local.request.access?.drive;
|
|
1016
|
+
if (asked && !["account", "none"].includes(asked) && result.session.drive?.id) local.folderDrive = { id: result.session.drive.id, name: result.session.drive.name ?? asked };
|
|
893
1017
|
saveView(local, result.session);
|
|
894
1018
|
}
|
|
895
1019
|
const deadline = now() + wait * 1000;
|
|
@@ -912,7 +1036,15 @@ export async function hostedSessionCommand(command, argv, { store = sessionStore
|
|
|
912
1036
|
await ready(local);
|
|
913
1037
|
if (command === "sync") {
|
|
914
1038
|
if (positionals.length > 1 || (positionals[0] && resolve(positionals[0]) !== store.project)) throw new CliError("Run nomac sync . from the attached project.");
|
|
1039
|
+
// nomac run --drive (LIM-394): what earlier runs sent is kept on the drive, so this run sends only what changed, and
|
|
1040
|
+
// removes what the repository deleted since; a run without a drive has nothing to keep.
|
|
1041
|
+
const kept = values["baseline-on-mac"] && local.workspaceOnDrive ? `"$HOME"/drive/.nomac/sync/${shellQuote(`${basename(local.workspace)}.json`)}` : undefined;
|
|
1042
|
+
if (kept) {
|
|
1043
|
+
const read = await run("ssh", [...sshArgs(local), local.target, `cat ${kept} 2>/dev/null || true`]).catch(() => ({ stdout: "" }));
|
|
1044
|
+
try { const saved = JSON.parse(String(read.stdout ?? "") || "{}"); if (saved && typeof saved === "object" && !Array.isArray(saved)) store.saveBaseline(saved); } catch { /* unreadable: start from nothing */ }
|
|
1045
|
+
}
|
|
915
1046
|
const result = await syncProject(local, store, { overwrite: values.overwrite, dryRun: values["dry-run"], deleteMissing: values.delete, run });
|
|
1047
|
+
if (kept && !values["dry-run"]) await run("ssh", [...sshArgs(local), local.target, `mkdir -p ~/drive/.nomac/sync && cat > ${kept}`], { input: Buffer.from(JSON.stringify(store.baseline())) });
|
|
916
1048
|
if (!values.json) { print(describeSync(result)); return result; }
|
|
917
1049
|
return output(result);
|
|
918
1050
|
}
|
package/src/mac-tools.mjs
CHANGED
|
@@ -14,20 +14,27 @@ const key = { type: "string", pattern: "^[A-Za-z0-9_.:-]{8,128}$" };
|
|
|
14
14
|
const schema = (properties, required = []) => ({ type: "object", properties, required, additionalProperties: false });
|
|
15
15
|
const base = args => `/api/v1/mac/sessions/${encodeURIComponent(args.session_id)}`;
|
|
16
16
|
export const MAC_TOOLS = [
|
|
17
|
-
{ name: "get_mac_checkout", description: "Get a payment link for Mac credit and open it in the human's browser on this machine. Credit is billed per minute at the hourly price get_mac_credits shows, sold in
|
|
17
|
+
{ name: "get_mac_checkout", description: "Get a payment link for Mac credit and open it in the human's browser on this machine. Credit is billed per minute at the hourly price get_mac_credits shows, sold in packs (1 to 10 per purchase; the answer gives the price), and never expires. Bigger purchases earn bonus credit: the answer's bonus_tiers and suggested_packs say what to suggest (1 pack for a first purchase), and the human decides. Call this when get_mac_credits shows too little credit or start_mac returns insufficient_credit. Then tell the human a payment page opened (or give them the returned url if opened_in_browser is false) and ask them to pay. Never enter payment details yourself. Poll get_mac_credits until the balance appears, then start the Mac. Reuse request_key after a lost response; a new key is a new purchase.", inputSchema: schema({ packs: { type: "integer", minimum: 1, maximum: 10, default: 1, description: "Number of $10 packs, 1-10. Pick from the human's budget or expected hours; 3+ packs earn bonus credit." }, open: { type: "boolean", default: true, description: "Open the link in this machine's browser." }, request_key: key }, ["request_key"]), handler: async ({ packs = 1, open = true, request_key }) => {
|
|
18
18
|
const result = await api("POST", "/api/v1/mac/credits/checkout", { body: { packs }, idempotencyKey: request_key });
|
|
19
19
|
const opened = open && result.action === "open_checkout_url" && result.url ? openUrl(result.url) : false;
|
|
20
20
|
return text({ ...result, opened_in_browser: opened });
|
|
21
21
|
} },
|
|
22
22
|
{ name: "get_mac_credits", description: "Read the prepaid Mac credit balance: spendable dollars, spendable_seconds (how long a Mac can run on it), amounts held by a running session, pricing (including bonus_tiers for bigger purchases), recent purchases and first_purchase (true until the first paid top-up). Credit never expires. If spendable_seconds is below what the task needs, call get_mac_checkout.", inputSchema: schema({}), handler: async () => text(await api("GET", "/api/v1/mac/credits")) },
|
|
23
|
-
{ name: "start_mac", description: "Allocate a full cloud Mac VM, billed per minute from prepaid credit; its answer states its price. If it returns insufficient_credit, call get_mac_checkout, have the human pay, then retry with the same request_key. Supply a stable request_key; SSH public_key is optional for HTTPS-only agents;
|
|
24
|
-
|
|
23
|
+
{ name: "start_mac", description: "Allocate a full cloud Mac VM, billed per minute from prepaid credit; its answer states its price. If it returns insufficient_credit, call get_mac_checkout, have the human pay, then retry with the same request_key. Supply a stable request_key; SSH public_key is optional for HTTPS-only agents; send both again after a lost response. Inspect the returned offer and limits. Poll get_mac_session until ready. No project pipeline is imposed; stop_mac deletes the VM and every file outside ~/drive. The Mac is fully enabled for you: macOS asks for no administrator password, and the Mac's login password is in $NOMAC_MAC_PASSWORD on it; the answer's warning says so. Each Mac gets a drive at ~/drive (20 GB), kept between sessions and on one Mac at a time: the account's default, or while another Mac has it a new drive of its own, named in the answer (get_mac_drive lists them). access drive NAME picks a drive (made empty the first time; default asks for the default itself, which answers drive_in_use while another Mac has it); drive_from copies one into a new drive; access prompts ask keeps macOS's usual prompts; drive none starts without one.", inputSchema: schema({ public_key: { type: "string" }, request_key: key, limits: { type: "object", properties: { max_duration_seconds: { type: "integer", minimum: 60, maximum: 28800 }, idle_timeout_seconds: { type: "integer", minimum: 60, maximum: 3600 }, spend_cap_microunits: { type: "string", pattern: "^[1-9][0-9]{0,17}$" } }, additionalProperties: false }, parallel: { type: "boolean", description: "true starts a second Mac beside the account's running one (accounts that bought credit, while NoMac has a Mac to spare), with a drive of its own. Without it, a start while a Mac runs answers session_limit_reached with that Mac's id, to use." },
|
|
24
|
+
reuse: { type: "boolean", description: "With access drive set to a name: when that drive is on a running Mac, answer that Mac (reused: true) instead of drive_in_use." },
|
|
25
|
+
access: { type: "object", properties: { prompts: { type: "string", enum: ["auto", "ask"] }, gatekeeper: { type: "string", enum: ["off", "on"] }, drive: { type: "string", description: "A drive's name (made empty the first time), account (the default, or a new drive while another Mac has it) or none" },
|
|
26
|
+
drive_from: { type: "string", description: "A drive of the account to copy into the drive made for this Mac (its last save)" },
|
|
25
27
|
permissions: { type: "object", description: "By bundle ID: a list of permissions (camera, microphone, contacts, calendars, reminders, photos, desktop, documents, downloads and more) or \"all\"", additionalProperties: { anyOf: [{ type: "string", enum: ["all"] }, { type: "array", items: { type: "string" }, minItems: 1 }] } } }, additionalProperties: false } }, ["request_key"]), handler: async ({ request_key, ...body }) => text(await api("POST", "/api/v1/mac/sessions", { body, idempotencyKey: request_key })) },
|
|
26
28
|
{ name: "list_mac_sessions", description: "Find existing Mac sessions, including after losing a response. Shows state, cost, limits and cleanup.", inputSchema: schema({}), handler: async () => text(await api("GET", "/api/v1/mac/sessions")) },
|
|
27
29
|
{ name: "get_mac_session", description: "Read live Mac allocation state, cost, funded time and cleanup confirmation, and once ready the credentials installed on it (secrets, signing identities and profiles, by name and path, never values) and account: the Mac's user, whether its login password is set (in $NOMAC_MAC_PASSWORD on the Mac), the access choices, and how to type and click (mac_input). queued/provisioning means wait; stopping is not yet confirmed cleanup.", inputSchema: schema({ session_id: session }, ["session_id"]), handler: async args => text(await api("GET", base(args))) },
|
|
28
30
|
{ name: "extend_mac", description: "Keep a running Mac going longer: raises its time limit by minutes (default 60), up to 8 hours since it started, and its spend cap with it. Call it when an answer's stop_notice says the Mac stops soon at its time limit or spend cap, or before a build or test that would not finish in time. It adds no credit: when stop_notice's reason is credit, the human adds some (get_mac_checkout). The Mac still bills at its hourly price while it runs.", inputSchema: schema({ session_id: session, minutes: { type: "integer", minimum: 1, maximum: 480, default: 60, description: "Minutes to add to the time limit, 1-480. Default 60." } }, ["session_id"]), handler: async ({ session_id, minutes = 60 }) => text(await api("POST", `${base({ session_id })}/extend`, { body: { minutes } })) },
|
|
29
|
-
{ name: "get_mac_drive", description: "Read the account's
|
|
30
|
-
|
|
31
|
+
{ name: "get_mac_drive", description: "Read the account's drives: each Mac has one at ~/drive (20 GB), kept between sessions and on one Mac at a time. What is there stays for the next Mac with that drive: keep projects in ~/drive/src for incremental builds; package and build caches (DerivedData, Swift packages, CocoaPods, npm) are kept there already. NoMac saves it when a Mac stops, with nothing to call. Lists each drive's name, space used, the Mac using it now, a save still in progress, recent versions, and the date it is deleted unused (90 days; 30 for a drive NoMac made for a Mac that named none). name reads one drive.", inputSchema: schema({ name: { type: "string", description: "One drive's name; without it, every drive" } }),
|
|
32
|
+
// A site before LIM-394 has only /api/v1/mac/drive, the one drive.
|
|
33
|
+
handler: async ({ name } = {}) => text(await api("GET", name ? `/api/v1/mac/drives/${encodeURIComponent(name)}` : "/api/v1/mac/drives")
|
|
34
|
+
.catch(error => { if (error?.status === 404 && (!name || name === "default")) return api("GET", "/api/v1/mac/drive"); throw error; })) },
|
|
35
|
+
{ name: "reset_mac_drive", description: "Empty one of the account's drives (the default unless name is given): everything on it is deleted, with no way back. The next Mac that names it starts with a new, empty one (for a drive-N, a new drive under a new number). Stop the Mac using it first (stop_mac). For one Mac without a drive, start_mac with access drive none instead.", inputSchema: schema({ name: { type: "string", description: "The drive to empty; without it, the default" } }),
|
|
36
|
+
handler: async ({ name } = {}) => text(await api("DELETE", `/api/v1/mac/drives/${encodeURIComponent(name ?? "default")}`)
|
|
37
|
+
.catch(error => { if (error?.status === 404 && (!name || name === "default")) return api("DELETE", "/api/v1/mac/drive"); throw error; })) },
|
|
31
38
|
{ name: "list_secrets", description: "List the account's secrets by name: variables (set in every shell and command on the Mac) and files (with their path on the Mac), whether every Mac receives them or only when asked, sizes, and secrets an agent asked for that the person has not entered yet. Values are never returned.", inputSchema: schema({}), handler: async () => text(await api("GET", "/api/v1/secrets")) },
|
|
32
39
|
{ name: "request_secret", description: "Get a link where the person enters a secret in their browser, so its value never passes through this chat: an API token, a .env value, a .p12 certificate or a config file. kind variable is one line of text, set as an environment variable on the Mac; kind file is stored at destination (under the home folder, like ~/.netrc; default ~/.nomac/secrets/<name>). Give the url to the person who holds the value; they need no NoMac account, and it works once, for 24 hours. Then list_secrets shows it, and it reaches running Macs within a minute, and new ones unless it is on_request. With a shell on this machine, the person can also run nomac secrets set NAME themselves. Never ask for a secret in the chat.", inputSchema: schema({ name: { type: "string", minLength: 1, maxLength: 128 }, kind: { type: "string", enum: ["variable", "file"] }, description: { type: "string", minLength: 1, maxLength: 500, description: "What the person should enter and why; shown to them" }, destination: { type: "string", maxLength: 256 }, delivery: { type: "string", enum: ["every_mac", "on_request"] } }, ["name", "kind", "description"]), handler: async body => text(await api("POST", "/api/v1/secrets/requests", { body })) },
|
|
33
40
|
{ name: "set_up_signing", description: "Set up App Store signing for a project on the Mac, with the App Store Connect key kept on NoMac's server: reads the project at path (its scheme, app and every extension, with entitlements), registers missing bundle IDs, switches on the capabilities Apple's API can, makes the App Store profiles, and installs them with the account's certificate in a keychain on the Mac. The project never changes. Returns a build settings file (.xcconfig) and export options with the exact xcodebuild, Flutter and fastlane commands. Creates a distribution certificate at Apple only when the account has none. Expo and Capacitor apps need their ios folder first. A step only a person can take comes back as needs_human with its link.", inputSchema: schema({ session_id: session, path: { type: "string", minLength: 1, maxLength: 1024, description: "The project folder on the Mac, relative to the workspace" }, scheme: { type: "string", minLength: 1, maxLength: 256 }, container: { type: "string", minLength: 1, maxLength: 1024 }, issuer_id: { type: "string", maxLength: 64 } }, ["session_id"]), handler: async ({ session_id, ...body }) => text(await api("POST", `${base({ session_id })}/signing`, { body })) },
|
|
@@ -40,8 +47,8 @@ export const MAC_TOOLS = [
|
|
|
40
47
|
const url = desktopUrl(session_id), opened = open ? openUrl(url) : false;
|
|
41
48
|
return text({ session_id, url, opened_in_browser: opened, message: opened ? "The desktop opened in the human's browser; they may need to sign in to nomac.app." : "Give the human this link; it opens after they sign in to nomac.app." });
|
|
42
49
|
} },
|
|
43
|
-
{ name: "stop_mac", description: "Stop billing by shutting down the VM and deleting its files. Retrieve files first. Poll get_mac_session until cleanup_confirmed; stopping only acknowledges the request.", inputSchema: schema({ session_id: session }, ["session_id"]), handler: async args => text(await api("DELETE", base(args))) },
|
|
44
|
-
{ name: "exec_mac", description: "Run any argv command in your cloud Mac workspace. Waits up to wait_seconds (default 20, max 50): a command that finishes in time returns its exit_code, stdout and stderr (first 64 KiB each, as text) in this one call, as soon as it finishes. For builds, tests and other slow commands pass wait_seconds:
|
|
50
|
+
{ name: "stop_mac", description: "Stop billing by shutting down the VM and deleting its files, except ~/drive (saved for the next Mac with that drive). Retrieve other files first. Poll get_mac_session until cleanup_confirmed; stopping only acknowledges the request.", inputSchema: schema({ session_id: session }, ["session_id"]), handler: async args => text(await api("DELETE", base(args))) },
|
|
51
|
+
{ name: "exec_mac", description: "Run any argv command in your cloud Mac workspace. Waits up to wait_seconds (default 20, max 50): a command that finishes in time returns its exit_code, stdout and stderr (first 64 KiB each, as text) in this one call, as soon as it finishes. For builds, tests and other slow commands pass wait_seconds: 40. A longer one returns its job ID: poll get_mac_job, then read_mac_output. Reuse request_key and identical arguments after lost responses; never rerun to get output. Use bash -lc explicitly for shell syntax. cwd runs it in another folder, such as ~/drive/src/app. timeout_seconds defaults to 300 and caps at 3600 (an hour) for builds and test runs; a first simulator boot takes about 90 seconds. cancel_mac_job stops a command. A command ends together with everything it started: keep a dev server running with [\"nomac-service\", \"start\", \"api\", \"--\", \"npx\", \"wrangler\", \"dev\"] (then nomac-service logs api, stop api). A command can be at most 64 KiB in total: put files on the Mac with write_mac_file (local_path, up to 2 GiB) or fetch_to_mac.", inputSchema: schema({ session_id: session, request_key: key, argv: { type: "array", items: { type: "string" }, minItems: 1 }, cwd: { type: "string", minLength: 1, maxLength: 1024, description: "The folder to run in: relative to the workspace, or ~/… and absolute paths anywhere on the Mac" }, timeout_seconds: { type: "integer", minimum: 1, maximum: 3600 }, wait_seconds: { type: "integer", minimum: 0, maximum: 50 } }, ["session_id", "request_key", "argv"]), handler: async ({ session_id, request_key, wait_seconds, ...body }) => text(await api("POST", `${base({ session_id })}/jobs?wait=${wait_seconds ?? 20}`, { body, idempotencyKey: request_key })) },
|
|
45
52
|
{ name: "write_mac_file", description: "Write a file on the Mac: local_path uploads a file from this machine, up to 2 GiB, without its content passing through you; or give content as text, or content_base64 for binary, up to 3 MiB. Relative Mac paths are in the session workspace; ~ is the home folder. Creates missing folders and replaces an existing file in one step; set executable for scripts. Safe to repeat. For a whole project use nomac sync; for larger files fetch_to_mac.", inputSchema: schema({ session_id: session, path: { type: "string", minLength: 1, maxLength: 1024 }, local_path: { type: "string" }, content: { type: "string" }, content_base64: { type: "string" }, executable: { type: "boolean" } }, ["session_id", "path"]), handler: async ({ session_id, path, local_path, content, content_base64, executable }) => {
|
|
46
53
|
const given = [local_path, content, content_base64].filter(v => v !== undefined).length;
|
|
47
54
|
if (given !== 1) return text({ error: { code: "invalid_request", message: "Give exactly one of local_path, content or content_base64." } });
|
package/src/mcp.mjs
CHANGED
|
@@ -21,14 +21,14 @@ const INSTRUCTIONS = [
|
|
|
21
21
|
"The cloud iPhone (the phone tools: phone and phone_*) builds, runs and tests an iOS app, ready in seconds, no shell: phone with action start (its answer has links.view for the person); phone_app_run with local_path (a folder here, only changes sent) or git (an https repository link) builds and runs the app, incrementally; phone_ui_look reads the screen as text, phone_ui_act taps and types by label; phone_app_logs, phone_tests_run; a long build answers with a job for phone_job_status; phone with action stop when done. The Mac (start_mac and the Mac tools) does the rest.",
|
|
22
22
|
"Use it when work needs macOS this machine lacks (Windows, Linux, a cloud sandbox): an iOS, iPadOS, watchOS, visionOS or macOS app (Swift, SwiftUI, React Native, Expo, Flutter, Capacitor), Xcode, signing, TestFlight or the App Store.",
|
|
23
23
|
"Typical flow: get_mac_credits, start_mac, poll get_mac_session until ready, put code there (exec_mac with git clone into ~/drive/src, write_mac_file, fetch_to_mac, create_mac_upload_link), run exec_mac, get results with read_mac_file or create_mac_download_link, then stop_mac.",
|
|
24
|
-
"
|
|
24
|
+
"~/drive (20 GB) is kept between sessions, on one Mac at a time (a second gets its own, named in its answer; access drive NAME picks one); the rest is deleted at stop. Clone and build in ~/drive/src/<repo> so the next session rebuilds only what changed; keep it under 10 GB (nomac-drive shows the space, nomac-drive clean frees it).",
|
|
25
25
|
"The Mac's own Simulator: simulator-use is on it (run it with exec_mac): simulator-use look reads the screen as text, simulator-use act 'tap \"Sign In\"' taps by label, simulator-use run builds and launches it, app storekit tests purchases; ~/NOMAC.md has the rest.",
|
|
26
|
-
"When an answer says low_credit (under an hour left), tell the human before a long build and offer its buy_url: a Mac stops when the credit runs out.
|
|
27
|
-
"One Mac per account at a time: start_mac while one runs answers session_limit_reached with its id, to use; parallel: true starts a second (accounts that bought credit, while NoMac has one to spare)
|
|
26
|
+
"When an answer says low_credit (under an hour left), tell the human before a long build and offer its buy_url: a Mac stops when the credit runs out.",
|
|
27
|
+
"One Mac per account at a time: start_mac while one runs answers session_limit_reached with its id, to use; parallel: true starts a second (accounts that bought credit, while NoMac has one to spare).",
|
|
28
28
|
"exec_mac returns a quick command's output in the same call; pass wait_seconds: 40 for builds and tests (a call answers within 45 s). A command still running comes back as a job: poll get_mac_job with its job_id, then read_mac_output.",
|
|
29
29
|
"Never rerun a command to get its output; after a lost response, repeat the call with the same request_key and arguments.",
|
|
30
30
|
"Write files with write_mac_file, not heredocs in exec_mac: a command is at most 64 KiB.",
|
|
31
|
-
"Shipping without the Apple key on the Mac: set_up_signing returns the files and commands that sign a build; send_to_testflight sends the signed .ipa to TestFlight; publish submits it for App Review; notarize notarizes and staples a Developer ID-signed Mac app. Never ask for a secret in the chat: request_secret gives the human a link, and every Mac receives the account's secrets.",
|
|
31
|
+
"Shipping without the Apple key on the Mac: set_up_signing returns the files and commands that sign a build; send_to_testflight sends the signed .ipa to TestFlight; publish submits it for App Review; notarize notarizes and staples a Developer ID-signed Mac app. Never ask for a secret in the chat: request_secret gives the human a link, and every Mac receives the account's secrets (on-request ones through install_secrets).",
|
|
32
32
|
"The Mac is fully enabled for you: sudo needs no password, prompts and password dialogs are answered within seconds, the screen never locks, and the login password is in $NOMAC_MAC_PASSWORD on it. nomac-permit APP camera (with exec_mac) grants an app privacy permissions before it asks. To type or click as a person would, also on the lock screen, call mac_input; when screenshot_mac reports screen_locked or a dialog, follow its next_step.",
|
|
33
33
|
"A Mac stops at its time limit (2 hours unless start_mac set max_duration_seconds), its spend cap, its idle timeout or when credit runs out; everything outside ~/drive is deleted then. In its last 15 minutes answers carry stop_notice: extend_mac keeps it running (time limit or spend cap), or the human adds credit (reason credit). Before a long build, check that it fits.",
|
|
34
34
|
"When an answer carries cli_update, this NoMac CLI is out of date: tell the human, who updates it with npm install -g @nomac/cli@latest (or nomac update) and restarts this MCP server.",
|
|
@@ -87,7 +87,7 @@ export const TOOLS = [
|
|
|
87
87
|
org: me.org,
|
|
88
88
|
connections: [],
|
|
89
89
|
next_step:
|
|
90
|
-
"No Apple connection. The human connects once with an App Store Connect API key (
|
|
90
|
+
"No Apple connection. The human connects once at https://nomac.app/dash/apple with an App Store Connect API key (about a minute).",
|
|
91
91
|
});
|
|
92
92
|
}
|
|
93
93
|
const detail = await api("GET", `/api/v1/connections/${conns.connections[0].id}`);
|
|
@@ -96,7 +96,7 @@ export const TOOLS = [
|
|
|
96
96
|
},
|
|
97
97
|
{
|
|
98
98
|
name: "set_project_connection",
|
|
99
|
-
description: "Choose an Apple connection for a project, including after key rotation. Verifies the app's bundle ID.
|
|
99
|
+
description: "Choose an Apple connection for a project, including after key rotation. Verifies the app's bundle ID.",
|
|
100
100
|
inputSchema: {
|
|
101
101
|
type: "object", properties: { project_id: { type: "string" }, connection_id: { type: "string" } },
|
|
102
102
|
required: ["connection_id"], additionalProperties: false,
|
|
@@ -106,7 +106,7 @@ export const TOOLS = [
|
|
|
106
106
|
{
|
|
107
107
|
name: "review_lint",
|
|
108
108
|
description:
|
|
109
|
-
"Review-readiness report (deterministic checks, graded green/yellow/red). Red findings block publish. Findings carry evidence + fix hints
|
|
109
|
+
"Review-readiness report (deterministic checks, graded green/yellow/red). Red findings block publish. Findings carry evidence + fix hints. Signals for fuzzy rules (4.3 distinctiveness) are evidence for YOU to judge.",
|
|
110
110
|
inputSchema: {
|
|
111
111
|
type: "object",
|
|
112
112
|
properties: { project_id: { type: "string" } },
|
|
@@ -126,7 +126,7 @@ export const TOOLS = [
|
|
|
126
126
|
description: "Current App Store metadata (app + selected iOS version localizations) from App Store Connect.",
|
|
127
127
|
inputSchema: {
|
|
128
128
|
type: "object",
|
|
129
|
-
properties: { project_id: { type: "string" }, version_string: { type: "string", description: "Defaults to the
|
|
129
|
+
properties: { project_id: { type: "string" }, version_string: { type: "string", description: "Defaults to the version of the last build sent with send_to_testflight (1.0 if none)" } },
|
|
130
130
|
additionalProperties: false,
|
|
131
131
|
},
|
|
132
132
|
handler: async (args) =>
|
|
@@ -141,7 +141,7 @@ export const TOOLS = [
|
|
|
141
141
|
properties: {
|
|
142
142
|
project_id: { type: "string" },
|
|
143
143
|
locale: { type: "string", default: "en-US" },
|
|
144
|
-
version_string: { type: "string", description: "Defaults to the
|
|
144
|
+
version_string: { type: "string", description: "Defaults to the version of the last build sent with send_to_testflight (1.0 if none); select a live version explicitly for promotional text" },
|
|
145
145
|
request_key: { type: "string", description: "Reuse the returned key to resume pending work with the original unchanged arguments" },
|
|
146
146
|
fields: { type: "object" },
|
|
147
147
|
primary_category: { type: "string" },
|
|
@@ -170,7 +170,7 @@ export const TOOLS = [
|
|
|
170
170
|
display_type: { type: "string" },
|
|
171
171
|
request_key: { type: "string", description: "Unique per replacement; reuse this key and the same images on a retry" },
|
|
172
172
|
locale: { type: "string", default: "en-US" },
|
|
173
|
-
version_string: { type: "string", description: "Defaults to the
|
|
173
|
+
version_string: { type: "string", description: "Defaults to the version of the last build sent with send_to_testflight (1.0 if none)" },
|
|
174
174
|
images: { type: "array", items: { type: "object" } },
|
|
175
175
|
},
|
|
176
176
|
required: ["display_type", "images"],
|
|
@@ -203,12 +203,12 @@ export const TOOLS = [
|
|
|
203
203
|
{
|
|
204
204
|
name: "publish",
|
|
205
205
|
description:
|
|
206
|
-
"Submit for App Store review (3-step reviewSubmissions). Takes the app's newest build on TestFlight, or build_id:
|
|
206
|
+
"Submit for App Store review (3-step reviewSubmissions). Takes the app's newest build on TestFlight, or build_id: one sent with send_to_testflight, whose answer gives project_id and build_id. Requires confirm:true with authorization for this app/version; run once without confirm first to see the staged result + any Apple blockers. Costs nothing; the review decision takes ~1-3 days. On pending, repeat unchanged arguments with the returned request_key; get_store_operation recovers a lost response.",
|
|
207
207
|
inputSchema: {
|
|
208
208
|
type: "object",
|
|
209
209
|
properties: {
|
|
210
210
|
project_id: { type: "string" },
|
|
211
|
-
build_id: { type: "string", description: "Exact NoMac build (bld_…) to attach, from send_to_testflight
|
|
211
|
+
build_id: { type: "string", description: "Exact NoMac build (bld_…) to attach, from send_to_testflight" },
|
|
212
212
|
asc_submission_id: { type: "string", description: "Exact Apple submission from get_review" },
|
|
213
213
|
resolve_rejection: { type: "boolean", default: false, description: "Assert this version rejection was fixed; mark its item ready for review" },
|
|
214
214
|
confirm: { type: "boolean", default: false },
|
|
@@ -269,7 +269,7 @@ export const TOOLS = [
|
|
|
269
269
|
{
|
|
270
270
|
name: "report_issue",
|
|
271
271
|
description:
|
|
272
|
-
"File an unknown/unfixable error with nomac support. For a Mac use session_id and optional job_id;
|
|
272
|
+
"File an unknown/unfixable error with nomac support. For a Mac use session_id and optional job_id; ref_id takes another NoMac id it concerns. Attaches account-scoped context and deduplicates repeats. An optional email requests a direct resolution update; replies are always available by calling with no description. kind feedback sends NoMac a note instead: what got in the way, failed or was missing.",
|
|
273
273
|
inputSchema: {
|
|
274
274
|
type: "object",
|
|
275
275
|
properties: {
|
|
@@ -286,7 +286,7 @@ export const TOOLS = [
|
|
|
286
286
|
kind: {
|
|
287
287
|
type: "string",
|
|
288
288
|
enum: ["problem", "feedback"],
|
|
289
|
-
description: "problem (default): an error for support to answer. feedback: a note for NoMac about what got in the way, failed or was missing; it
|
|
289
|
+
description: "problem (default): an error for support to answer. feedback: a note for NoMac about what got in the way, failed or was missing; you need not wait for it, and a person replies in the ticket. Leave out code, secrets and personal data.",
|
|
290
290
|
},
|
|
291
291
|
},
|
|
292
292
|
additionalProperties: false,
|
package/src/phone-tools.json
CHANGED
|
@@ -117,7 +117,7 @@
|
|
|
117
117
|
"secret": {
|
|
118
118
|
"description": "With git: the account secret holding a token for a private repository on github.com, gitlab.com or bitbucket.org (request_secret asks the person for it)",
|
|
119
119
|
"type": "string",
|
|
120
|
-
"pattern": "^[A-
|
|
120
|
+
"pattern": "^[A-Za-z_][A-Za-z0-9_]{0,127}$"
|
|
121
121
|
},
|
|
122
122
|
"token": {
|
|
123
123
|
"description": "With git, instead of secret: a token you already hold for the private repository, used for this fetch only and never kept (github.com, gitlab.com or bitbucket.org). Never ask a person to paste one in the chat: use secret",
|
|
@@ -369,7 +369,7 @@
|
|
|
369
369
|
"secret": {
|
|
370
370
|
"description": "With git: the account secret holding a token for a private repository on github.com, gitlab.com or bitbucket.org (request_secret asks the person for it)",
|
|
371
371
|
"type": "string",
|
|
372
|
-
"pattern": "^[A-
|
|
372
|
+
"pattern": "^[A-Za-z_][A-Za-z0-9_]{0,127}$"
|
|
373
373
|
},
|
|
374
374
|
"token": {
|
|
375
375
|
"description": "With git, instead of secret: a token you already hold for the private repository, used for this fetch only and never kept (github.com, gitlab.com or bitbucket.org). Never ask a person to paste one in the chat: use secret",
|
|
@@ -506,7 +506,7 @@
|
|
|
506
506
|
},
|
|
507
507
|
{
|
|
508
508
|
"name": "phone",
|
|
509
|
-
"description": "Cloud iPhone: Starts, reads or stops the account's NoMac phone, an iPhone Simulator on a Mac with Xcode, billed
|
|
509
|
+
"description": "Cloud iPhone: Starts, reads or stops the account's NoMac phone, an iPhone Simulator on a Mac with Xcode, billed per minute from the account's credit. start answers once it is ready (usually about 4 s); status shows its state and the cost so far; extend keeps it running longer (minutes, up to 8 hours in all); stop ends it. save, restore, states and delete_state keep the phone's apps, data, keychain and permissions by name for the account, for any of its phones of the same model and iOS.",
|
|
510
510
|
"inputSchema": {
|
|
511
511
|
"type": "object",
|
|
512
512
|
"properties": {
|
package/src/run.mjs
CHANGED
|
@@ -13,9 +13,10 @@ export const RUN_HELP = `nomac run [options] -- command args
|
|
|
13
13
|
nomac sync . does (not .git, build output, dependency folders or secret files), runs the
|
|
14
14
|
command there, copies back what --pull names (also when the command failed), and stops the
|
|
15
15
|
Mac. stdout is the command's output; nomac run's own lines go to stderr. Its exit code is
|
|
16
|
-
the command's. It never uses or stops a Mac you or your agents run, and
|
|
17
|
-
drive
|
|
18
|
-
the account's Macs
|
|
16
|
+
the command's. It never uses or stops a Mac you or your agents run, and has no drive
|
|
17
|
+
unless --drive names one, so by default nothing carries over from one run to the next.
|
|
18
|
+
While it runs it counts as one of the account's Macs, and your agents are never offered
|
|
19
|
+
it (to use, attach or stop).
|
|
19
20
|
--timeout SECONDS the command's limit, 60 to 3540 (the default)
|
|
20
21
|
--pull PATH after the command, copy PATH (relative to the project folder) here;
|
|
21
22
|
repeat it for more
|
|
@@ -23,6 +24,10 @@ export const RUN_HELP = `nomac run [options] -- command args
|
|
|
23
24
|
--queue SECONDS how long to wait for a Mac when the account runs as many as it may
|
|
24
25
|
(600 by default; 0 fails at once)
|
|
25
26
|
--max-cost DOLLARS what this run may spend at most (5 by default)
|
|
27
|
+
--drive NAME run with that drive at ~/drive (made empty the first time), so caches
|
|
28
|
+
and build products carry over to the next run with the same name; a
|
|
29
|
+
drive is on one Mac at a time, so a run whose drive another run has
|
|
30
|
+
waits for it like a Mac (--queue)
|
|
26
31
|
The command is one argv; for a shell line: nomac run -- bash -lc 'pod install && make test'.
|
|
27
32
|
Nothing is read from stdin. Needs NOMAC_API_KEY (a CI secret) or nomac login, and the
|
|
28
33
|
OpenSSH client (ssh, ssh-keygen). A cancelled job (SIGTERM, SIGINT, SIGHUP) stops the Mac.
|
|
@@ -33,7 +38,7 @@ export const RUN_HELP = `nomac run [options] -- command args
|
|
|
33
38
|
|
|
34
39
|
const options = {
|
|
35
40
|
timeout: { type: "string" }, pull: { type: "string", multiple: true }, "no-sync": { type: "boolean" },
|
|
36
|
-
queue: { type: "string" }, "max-cost": { type: "string" }, help: { type: "boolean", short: "h" },
|
|
41
|
+
queue: { type: "string" }, "max-cost": { type: "string" }, drive: { type: "string" }, help: { type: "boolean", short: "h" },
|
|
37
42
|
};
|
|
38
43
|
/** A command's limit: the CLI waits a minute past it (up to the gateway's hour), so it sees the command end. */
|
|
39
44
|
const MAX_TIMEOUT = 3540;
|
|
@@ -54,7 +59,9 @@ function whole(value, fallback, min, max, what) {
|
|
|
54
59
|
/**
|
|
55
60
|
* nomac run: start, sync, exec and pull as those commands do them, under a session state of the run's own (a fresh
|
|
56
61
|
* directory, removed after, marked ephemeral so the folder's SSH config entry is left alone), always with --parallel and
|
|
57
|
-
*
|
|
62
|
+
* with no drive unless --drive names one of its own (never the default or a drive-N), so it never takes or touches a Mac
|
|
63
|
+
* or drive someone uses; with one, what earlier runs sent is kept on that drive. Its Mac is marked purpose run, so agents
|
|
64
|
+
* are never offered it (refusals, attach, calls without a session id). The Mac is stopped with one API call (no
|
|
58
65
|
* folder lock to wait for) at the end, after any failure, and on the first SIGTERM or SIGINT (later ones, such as npm
|
|
59
66
|
* forwarding the same signal, are ignored), which then exits 143 or 130. Returns the command's exit code.
|
|
60
67
|
*/
|
|
@@ -119,23 +126,30 @@ export async function runCommand(argv, {
|
|
|
119
126
|
|
|
120
127
|
try {
|
|
121
128
|
// The Mac lives a little past the command's limit (the start, the upload, the pull), and stops at the end anyway.
|
|
122
|
-
|
|
129
|
+
// Without --drive the run's Mac has none; with it, that named drive (LIM-394), never the default or one NoMac made.
|
|
130
|
+
if (values.drive !== undefined && (!/^[A-Za-z0-9][A-Za-z0-9._:@-]{0,63}$/.test(values.drive) || ["account", "none", "default"].includes(values.drive) || /^drive-[0-9]+$/.test(values.drive)))
|
|
131
|
+
throw new CliError("--drive names a drive of the run's own, like ci-cache (not default, account, none or drive-N).");
|
|
132
|
+
const start = ["--wait", "600", "--parallel", "--drive", values.drive ?? "none", "--max-duration", String(Math.min(28_800, timeout + 1800)), "--idle-timeout", "900",
|
|
123
133
|
...(values["max-cost"] ? ["--max-cost", values["max-cost"]] : [])];
|
|
124
134
|
const until = now() + queue * 1000;
|
|
125
135
|
let started;
|
|
126
136
|
for (let waited = false; ; waited = true) {
|
|
127
137
|
if (signalled) return code;
|
|
128
138
|
say(waited ? "starting a Mac (another try)" : "starting a Mac");
|
|
129
|
-
|
|
139
|
+
// Marked as a run's Mac: an agent's refused start never names it, nomac attach never picks it, and it never takes the drive.
|
|
140
|
+
try { started = await step("start", start, { purpose: "run" }); break; }
|
|
130
141
|
catch (error) {
|
|
131
142
|
// The account already runs as many Macs as it may: a pipeline waits its turn, a bounded time.
|
|
132
|
-
if (error?.code
|
|
133
|
-
say(
|
|
143
|
+
if (!["session_limit_reached", "drive_in_use"].includes(error?.code) || now() >= until) throw error;
|
|
144
|
+
say(error.code === "drive_in_use" ? `drive ${values.drive} is on another Mac; waiting for it (up to ${Math.ceil((until - now()) / 1000)} s more)`
|
|
145
|
+
: `the account runs as many Macs as it may; waiting for one to stop (up to ${Math.ceil((until - now()) / 1000)} s more)`);
|
|
134
146
|
await sleep(15_000);
|
|
135
147
|
}
|
|
136
148
|
}
|
|
137
149
|
if (started?.session?.state !== "ready") throw new CliError(`The Mac did not become ready (it is ${started?.session?.state ?? "unknown"}).`);
|
|
138
|
-
|
|
150
|
+
// With a drive the project folder is the one earlier runs left there: this folder replaces what differs and removes what
|
|
151
|
+
// it no longer has (its build caches, in folders sync skips, stay).
|
|
152
|
+
if (!values["no-sync"]) { say("uploading this folder"); await step("sync", [".", ...(values.drive ? ["--overwrite", "--delete", "--baseline-on-mac"] : [])]); }
|
|
139
153
|
say(`running ${command.join(" ").slice(0, 200)}`);
|
|
140
154
|
// A key of its own: after a lost connection the same command is asked for again (it keeps running), never run twice.
|
|
141
155
|
const exec = ["--wait", String(timeout + 60), "--timeout", String(timeout), "--request-key", `run-${randomUUID()}`, "--", ...command];
|