@nomac/cli 0.24.0 → 0.26.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 +26 -16
- package/src/cli.mjs +7 -5
- package/src/hosted-sessions.mjs +184 -39
- package/src/mac-tools.mjs +15 -7
- package/src/mcp.mjs +14 -14
- package/src/phone-tools.json +3 -3
- package/src/run.mjs +30 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nomac/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.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.26.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.26.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,13 +78,23 @@ 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.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
`
|
|
84
|
+
that bought credit while NoMac has a Mac to spare. To wait for the running Mac
|
|
85
|
+
instead, `nomac start --queue 1800` (MCP `queue_seconds`, 300 to 3600) waits in
|
|
86
|
+
line, free, and starts in its turn; `nomac run` waits 10 minutes by default
|
|
87
|
+
(`--queue`). A refused start names the running Mac, who started it and its last
|
|
88
|
+
command. `nomac stop` asks for `--confirm` while another API key sent the Mac a
|
|
89
|
+
command or opened SSH to it in the last 5 minutes. Every Mac gets a 20 GB
|
|
90
|
+
drive at `~/drive`, on one Mac at a time: the first gets the account's
|
|
91
|
+
default drive, a second a new drive of its own, and `nomac status` and
|
|
92
|
+
`~/NOMAC.md` name it. To keep an agent's work apart, give it a drive:
|
|
93
|
+
`nomac start --drive NAME` (made empty the first time; the folder asks for it
|
|
94
|
+
again at its next start), `--drive-from default` to start it as a copy, and
|
|
95
|
+
`--reuse` to be given the running Mac that has it. `nomac drive` lists the
|
|
96
|
+
drives. A Mac running a `nomac run` command is never offered to attach: it
|
|
97
|
+
stops when its command ends.
|
|
88
98
|
If start returns `insufficient_credit`, buy credit as in step 1, then retry
|
|
89
99
|
with the same request key.
|
|
90
100
|
Keep the same request key and arguments after uncertain responses; inspect
|
|
@@ -106,7 +116,7 @@ See the screen with `nomac screenshot` (saves
|
|
|
106
116
|
`nomac-screenshot.jpg`; `--simulator` for the iOS Simulator) or MCP
|
|
107
117
|
`screenshot_mac`, which returns an image you can look at. Record a video for
|
|
108
118
|
the human with `nomac record`, do the work, then `nomac record stop` (saves the
|
|
109
|
-
MP4 and prints a share link); MCP `
|
|
119
|
+
MP4 and prints a share link); MCP `mac_recording` (with `nomac mcp`, `start_mac_recording` and `stop_mac_recording`).
|
|
110
120
|
Commands drive any app with AppleScript without a permission prompt. For real
|
|
111
121
|
keyboard and mouse, also on the lock screen and in password dialogs, use
|
|
112
122
|
`nomac input type TEXT`, `nomac input click X Y`, `nomac unlock` (MCP
|
|
@@ -192,7 +202,7 @@ the human, then call again.
|
|
|
192
202
|
|
|
193
203
|
## When stuck
|
|
194
204
|
|
|
195
|
-
`report_issue` with the
|
|
205
|
+
`report_issue` with the Mac's `session_id` (and `job_id`) files a support ticket with full
|
|
196
206
|
context auto-attached (deduped, so safe to call). Its optional `email` requests
|
|
197
207
|
a direct resolution update; without it, read replies with the same tool. If the
|
|
198
208
|
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)
|
|
@@ -181,17 +181,19 @@ export async function main(argv) {
|
|
|
181
181
|
return view;
|
|
182
182
|
}
|
|
183
183
|
case "feedback": {
|
|
184
|
-
// A note for NoMac, about this folder's last Mac when there is one (nomac stop asks for it).
|
|
185
|
-
|
|
184
|
+
// A note for NoMac, about this folder's last Mac when there is one (nomac stop asks for it). --json is the flag
|
|
185
|
+
// every command takes, never part of the note (November 8, 2026: an agent's note arrived ending in "--json").
|
|
186
|
+
const json = rest.includes("--json");
|
|
187
|
+
const description = rest.filter(arg => arg !== "--json").join(" ").trim();
|
|
186
188
|
if (isHelp(rest) || description.length < 10) {
|
|
187
|
-
const usage = 'Usage: nomac feedback "what got in your way, failed, was missing or was slow"\n A person at NoMac reads it and answers. Leave out code, secrets and personal data.';
|
|
189
|
+
const usage = 'Usage: nomac feedback "what got in your way, failed, was missing or was slow" [--json]\n A person at NoMac reads it and answers. Leave out code, secrets and personal data.';
|
|
188
190
|
if (isHelp(rest)) return console.log(usage);
|
|
189
191
|
throw new CliError("feedback usage", usage);
|
|
190
192
|
}
|
|
191
193
|
const { sessionStore } = await import("./session-store.mjs");
|
|
192
194
|
const last = sessionStore().load();
|
|
193
195
|
const answer = await api("POST", "/api/v1/report-issue", { body: { description, kind: "feedback", ...(last?.mode === "hosted" && last.id ? { session_id: last.id } : {}) } });
|
|
194
|
-
console.log(answer.note ?? `Sent (${answer.ticket_id}).`);
|
|
196
|
+
console.log(json ? JSON.stringify(answer, null, 2) : answer.note ?? `Sent (${answer.ticket_id}).`);
|
|
195
197
|
return answer;
|
|
196
198
|
}
|
|
197
199
|
case "whoami": {
|
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,15 +47,28 @@ 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
|
-
|
|
57
|
-
|
|
58
|
-
A Mac running a nomac run command is never named or attached.
|
|
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, who started it and its last command: nomac attach ID
|
|
66
|
+
uses it. A Mac running a nomac run command is never named or attached.
|
|
67
|
+
nomac start --queue SECONDS wait in line (300-3600 s, free) instead of being refused: for the
|
|
68
|
+
account's running Mac to stop, the drive asked for, or a free Mac.
|
|
69
|
+
It starts in its turn; nomac start or nomac status checks again.
|
|
70
|
+
nomac stop --confirm stop the Mac even though another API key sent it a command or
|
|
71
|
+
opened SSH to it in the last 5 minutes (another agent may be on it)
|
|
59
72
|
nomac ssh-config [--alias nomac] [--print]
|
|
60
73
|
name this folder's Mac in your SSH config (Host nomac), for
|
|
61
74
|
VS Code or Cursor Remote-SSH, Claude Code SSH sessions, ssh nomac,
|
|
@@ -107,8 +120,12 @@ const options = {
|
|
|
107
120
|
"no-open": { type: "boolean" }, simulator: { type: "boolean" }, output: { type: "string", short: "o" }, max: { type: "string" },
|
|
108
121
|
prompts: { type: "string" }, gatekeeper: { type: "string" }, copy: { type: "boolean" }, app: { type: "boolean" },
|
|
109
122
|
right: { type: "boolean" }, double: { type: "boolean" }, "no-screenshot": { type: "boolean" },
|
|
110
|
-
permit: { type: "string", multiple: true }, reset: { type: "boolean" }, drive: { type: "string" },
|
|
123
|
+
permit: { type: "string", multiple: true }, reset: { type: "boolean" }, drive: { type: "string" }, "drive-from": { type: "string" }, reuse: { type: "boolean" },
|
|
124
|
+
// nomac run's own (not in the help): keep what sync sent in the drive, since each run starts from a fresh local state.
|
|
125
|
+
"baseline-on-mac": { type: "boolean" },
|
|
111
126
|
parallel: { type: "boolean" }, alias: { type: "string" }, print: { type: "boolean" },
|
|
127
|
+
// Wait in line (LIM-390): start --queue SECONDS waits for the account's limit, the drive or a free Mac; stop --confirm stops a Mac another API key is using.
|
|
128
|
+
queue: { type: "string" }, confirm: { type: "boolean" },
|
|
112
129
|
};
|
|
113
130
|
/** --permit com.example.App=camera,microphone (or =all), as the permissions option. */
|
|
114
131
|
export function permitOption(values) {
|
|
@@ -125,14 +142,28 @@ const oneOf = (value, allowed, flag) => {
|
|
|
125
142
|
if (!allowed.includes(value)) throw new CliError(`${flag} takes ${allowed.join(" or ")}.`);
|
|
126
143
|
return value;
|
|
127
144
|
};
|
|
128
|
-
/**
|
|
129
|
-
|
|
145
|
+
/** A drive's name as the server takes it (LIM-394): "default", one you choose, or one NoMac made (drive-2). */
|
|
146
|
+
const DRIVE_NAME = /^[A-Za-z0-9][A-Za-z0-9._:@-]{0,63}$/;
|
|
147
|
+
export function driveNameOption(value, flag) {
|
|
148
|
+
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"}.`);
|
|
149
|
+
return value;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* The access the person chose, or none: the server's defaults then apply (fully open). At a start --drive also takes a
|
|
153
|
+
* drive's name and --drive-from a drive to copy (LIM-394); saved defaults take only account or none.
|
|
154
|
+
*/
|
|
155
|
+
function accessOption(values, { start = false } = {}) {
|
|
130
156
|
const permissions = permitOption(values.permit);
|
|
131
|
-
if (
|
|
157
|
+
if (!start && values["drive-from"] !== undefined) throw new CliError("--drive-from belongs to a start: nomac start --drive NAME --drive-from default.");
|
|
158
|
+
if (values.prompts === undefined && values.gatekeeper === undefined && values.drive === undefined && values["drive-from"] === undefined && !permissions) return undefined;
|
|
159
|
+
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.");
|
|
132
160
|
return {
|
|
133
161
|
...(values.prompts !== undefined ? { prompts: oneOf(values.prompts, ["auto", "ask"], "--prompts") } : {}),
|
|
134
162
|
...(values.gatekeeper !== undefined ? { gatekeeper: oneOf(values.gatekeeper, ["off", "on"], "--gatekeeper") } : {}),
|
|
135
|
-
...(values.drive !== undefined ? { drive:
|
|
163
|
+
...(values.drive !== undefined ? { drive: start && !["account", "none"].includes(values.drive) ? driveNameOption(values.drive, "--drive")
|
|
164
|
+
: !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)."); })()
|
|
165
|
+
: oneOf(values.drive, ["account", "none"], "--drive") } : {}),
|
|
166
|
+
...(values["drive-from"] !== undefined ? { drive_from: driveNameOption(values["drive-from"], "--drive-from") } : {}),
|
|
136
167
|
...(permissions ? { permissions } : {}),
|
|
137
168
|
};
|
|
138
169
|
}
|
|
@@ -187,7 +218,11 @@ const validRequestKey = value => typeof value === "string" && /^[A-Za-z0-9_.:-]{
|
|
|
187
218
|
// unreadable response or idempotency conflict may still own a real session.
|
|
188
219
|
const startRejections = new Set(["invalid_request", "invalid_public_key", "profile_unavailable", "session_cap_too_low",
|
|
189
220
|
"weekly_time_unavailable", "weekly_time_expired", "insufficient_compute_credit", "insufficient_credit", "compute_account_blocked",
|
|
190
|
-
"session_limit_reached", "organization_not_found", "compute_unavailable", "unauthenticated", "invalid_origin"
|
|
221
|
+
"session_limit_reached", "organization_not_found", "compute_unavailable", "unauthenticated", "invalid_origin",
|
|
222
|
+
// 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.
|
|
223
|
+
"drive_in_use", "drive_limit_reached", "drive_not_found",
|
|
224
|
+
// LIM-390: the account has as many starts waiting in line as it may.
|
|
225
|
+
"queue_full"]);
|
|
191
226
|
export async function sessionAccess(id, request = api) {
|
|
192
227
|
sessionId(id);
|
|
193
228
|
const access = await request("POST", `/api/v1/mac/sessions/${id}/access`);
|
|
@@ -376,8 +411,40 @@ export function macLine(image) {
|
|
|
376
411
|
const xcode = others.length ? `Xcode ${image.xcode} (default) and ${others.map(x => `Xcode ${x.version} (${x.path})`).join(" and ")}` : `Xcode ${image.xcode}`;
|
|
377
412
|
return `Mac: macOS ${image.macos.split(" ")[0]}, ${xcode}${(image.simulator_runtimes ?? []).map(r => `, ${r} Simulator`).join("")}`;
|
|
378
413
|
}
|
|
379
|
-
/**
|
|
380
|
-
|
|
414
|
+
/**
|
|
415
|
+
* 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
|
|
416
|
+
* another Mac had the account's one drive (LIM-383).
|
|
417
|
+
*/
|
|
418
|
+
const driveElsewhereLine = (holder, limit) => limit
|
|
419
|
+
? `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.`
|
|
420
|
+
: `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.`;
|
|
421
|
+
/** The account's drives; from a site before LIM-394 (no /api/v1/mac/drives), its one drive as the default. */
|
|
422
|
+
export async function fetchDrives(request) {
|
|
423
|
+
try { return await request("GET", "/api/v1/mac/drives"); }
|
|
424
|
+
catch (error) {
|
|
425
|
+
if (error?.status !== 404) throw error;
|
|
426
|
+
const answer = await request("GET", "/api/v1/mac/drive");
|
|
427
|
+
return { drives: answer.drive ? [{ name: "default", default: true, ...answer.drive }] : [], limit: 1, available: answer.available, message: answer.message };
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
/** nomac drive: the account's drives, one line each, then how to use them (LIM-394). */
|
|
431
|
+
export function driveList(answer) {
|
|
432
|
+
const drives = answer.drives ?? [];
|
|
433
|
+
if (!drives.length) return answer.message;
|
|
434
|
+
const width = Math.max(...drives.map(d => d.name.length));
|
|
435
|
+
const today = new Date().toISOString().slice(0, 10);
|
|
436
|
+
const where = d => d.in_use ? `on ${d.in_use.session_id} now` : d.saving ? "saving its last session"
|
|
437
|
+
: `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`;
|
|
438
|
+
return [`Drives: ${drives.length} of at most ${answer.limit ?? 10}, each at ~/drive on one Mac at a time.`,
|
|
439
|
+
...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}` : ""}`),
|
|
440
|
+
"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");
|
|
441
|
+
}
|
|
442
|
+
/** 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. */
|
|
443
|
+
export function driveLine(d) {
|
|
444
|
+
const which = !d.name || d.default !== false ? `${d.path}` : `${d.path}, drive ${d.name}`;
|
|
445
|
+
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.` : ""}` : "";
|
|
446
|
+
return `Drive: ${which}, kept between sessions${d.source === "r2" ? " (downloaded to this Mac before boot)" : ""}.${again}`;
|
|
447
|
+
}
|
|
381
448
|
export function statusSummary(session, image) {
|
|
382
449
|
const lines = [`${session.id}: ${session.state}`];
|
|
383
450
|
if (macLine(image)) lines.push(macLine(image));
|
|
@@ -389,11 +456,13 @@ export function statusSummary(session, image) {
|
|
|
389
456
|
}
|
|
390
457
|
const d = session.drive;
|
|
391
458
|
if (d && ["mounted", "saving", "saved", "unavailable", "not_saved"].includes(d.state)) {
|
|
392
|
-
lines.push(d.state === "mounted" ?
|
|
459
|
+
lines.push(d.state === "mounted" ? driveLine(d)
|
|
393
460
|
: d.state === "saving" ? "Drive: saving this session's changes." : d.state === "saved" ? `Drive: saved (version ${d.saved_version}).`
|
|
394
461
|
: d.state === "not_saved" ? `Drive: this session's changes were not saved. ${d.message ?? ""}`.trim() : `Drive: not attached. ${d.message ?? ""}`.trim());
|
|
395
462
|
}
|
|
396
|
-
|
|
463
|
+
// Waiting for a Mac that is stopping, so this one starts from its save (LIM-394).
|
|
464
|
+
if (d && d.state === "waiting" && d.message) lines.push(/^Drive /.test(d.message) ? d.message : `Drive: ${d.message}`);
|
|
465
|
+
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));
|
|
397
466
|
if (session.state === "ready" && session.access) {
|
|
398
467
|
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).`);
|
|
399
468
|
}
|
|
@@ -429,7 +498,9 @@ export async function hostedSessionCommand(command, argv, { store = sessionStore
|
|
|
429
498
|
catch (error) { throw new CliError(error.message); }
|
|
430
499
|
const { values, positionals } = parsed;
|
|
431
500
|
if (values.help) return print(command === "desktop" ? DESKTOP_HELP : HELP);
|
|
432
|
-
|
|
501
|
+
// --queue: the start waits in line on NoMac's side (LIM-390); --wait may then cover the whole line, for a script or CI job.
|
|
502
|
+
const queue = command === "start" && values.queue !== undefined ? integer(values.queue, 0, 300, 3600, "--queue (seconds in line)") : undefined;
|
|
503
|
+
const wait = ["start", "attach", "stop"].includes(command) ? integer(values.wait, command === "stop" ? 60 : 300, 0, command === "stop" ? 300 : 600 + (queue ?? 0), "--wait (seconds)") : 0;
|
|
433
504
|
if (command === "start" && values["request-key"] !== undefined && !validRequestKey(values["request-key"])) throw new CliError("Use a request key of 8–128 letters, digits, underscores, periods, colons or hyphens.");
|
|
434
505
|
// The image the last read reported (macOS, Xcodes, Simulators), for start's summary.
|
|
435
506
|
let lastImage;
|
|
@@ -444,15 +515,21 @@ export async function hostedSessionCommand(command, argv, { store = sessionStore
|
|
|
444
515
|
? `Cost: ${usd(result.session?.cost?.accrued_microunits)} (${perHour(result.session)}billed per minute while the Mac was ready). Credit left: nomac credits`
|
|
445
516
|
: `Cost so far: ${usd(result.session?.cost?.accrued_microunits)} (${perHour(result.session)}billed per minute while the Mac is ready). Credit left: nomac credits`;
|
|
446
517
|
const next = result.session.state === "ready" ? `${result.project ? `${projectLine(result.project)}\n` : ""}Next: nomac sync . → nomac ssh`
|
|
447
|
-
: result.session.failure_code === "capacity_unavailable" ?
|
|
518
|
+
: result.session.failure_code === "capacity_unavailable" ? `No Mac was free within ${Math.round((result.session.queue_seconds ?? 300) / 60)} minutes; nothing was charged. Run nomac start again in a few minutes${(result.session.queue_seconds ?? 0) < 3600 ? ", or with --queue SECONDS to wait longer" : ""}.`
|
|
519
|
+
: result.session.failure_code === "queue_expired" ? `Waited ${Math.round((result.session.queue_seconds ?? 300) / 60)} minutes in line while the account's other Macs kept running; nothing was charged. Use one (nomac attach), or start again${(result.session.queue_seconds ?? 0) < 3600 ? " with a longer --queue" : ""}.`
|
|
520
|
+
: result.session.state === "queued" && (result.session.in_line || result.session.queue_seconds) ? "Waiting in line (free); it starts in its turn. Check again: nomac start"
|
|
448
521
|
: result.session.state === "queued" ? "Waiting for a free Mac (waiting is free). Check again: nomac start"
|
|
449
522
|
: ["stopped", "failed"].includes(result.session.state) ? `${result.session.drive ? "The drive saves in the background (nomac drive shows it). " : ""}Start another: nomac start`
|
|
450
523
|
: result.session.state === "stopping" ? "Stopping. Check: nomac status"
|
|
451
524
|
: "Check: nomac status";
|
|
452
525
|
// A ready Mac says what is on it, as nomac status does.
|
|
453
526
|
const mac = result.session.state === "ready" && macLine(lastImage) ? `${macLine(lastImage)}\n` : "";
|
|
454
|
-
const elsewhere = !result.session.drive && result.session.drive_held_by && ["queued", "provisioning", "ready"].includes(result.session.state)
|
|
455
|
-
|
|
527
|
+
const elsewhere = !result.session.drive && (result.session.drive_held_by || result.session.drive_limit) && ["queued", "provisioning", "ready"].includes(result.session.state)
|
|
528
|
+
? `${driveElsewhereLine(result.session.drive_held_by, result.session.drive_limit)}\n` : "";
|
|
529
|
+
// A drive other than the default: which one, how it was made, and how to get it again (the server's own words).
|
|
530
|
+
const drive = result.session.drive && result.session.drive.default === false && ["queued", "provisioning", "ready"].includes(result.session.state)
|
|
531
|
+
? `${result.session.drive.message ? (/^Drive /.test(result.session.drive.message) ? result.session.drive.message : `Drive: ${result.session.drive.message}`) : driveLine(result.session.drive)}\n` : "";
|
|
532
|
+
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}` : ""}`);
|
|
456
533
|
return result;
|
|
457
534
|
};
|
|
458
535
|
const saveView = (local, view) => {
|
|
@@ -500,7 +577,9 @@ export async function hostedSessionCommand(command, argv, { store = sessionStore
|
|
|
500
577
|
const path = String(job?.stdout ?? "").trim();
|
|
501
578
|
if (job?.exit_code === 0 && path.startsWith("/Users/agent/drive/src/") && !path.slice(23).includes("/")) {
|
|
502
579
|
// The same folder on the drive as last time: what was synced there then is still there.
|
|
503
|
-
|
|
580
|
+
// Only on the same drive (LIM-394: a folder's next Mac may have another one, where none of it is).
|
|
581
|
+
const kept = local.driveBaselines?.[local.snapshot?.drive?.id];
|
|
582
|
+
if (kept?.path === path) store.saveBaseline(kept.baseline);
|
|
504
583
|
Object.assign(local, { workspace: validateWorkspace(path), workspaceOnDrive: true });
|
|
505
584
|
} else {
|
|
506
585
|
// The drive itself refused (full, or not writable): this session works in ~/workspace, and says so.
|
|
@@ -547,14 +626,23 @@ export async function hostedSessionCommand(command, argv, { store = sessionStore
|
|
|
547
626
|
/** Where this folder's project is on the Mac, once a ready Mac has decided it. */
|
|
548
627
|
const project = local => local.state === "ready" && local.workspaceDecided ? { project: { path: local.workspace, on_drive: Boolean(local.workspaceOnDrive) } } : {};
|
|
549
628
|
/** The last session's folder on the drive and what was synced to it, for the next session to pick up. */
|
|
550
|
-
|
|
629
|
+
// 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
|
|
630
|
+
// Macs may alternate between drives, or a start may be refused in between); and the drive this folder was told to use
|
|
631
|
+
// (nomac start --drive NAME), which its next start asks for again. At most 10 drives' baselines are kept.
|
|
632
|
+
const previousDrive = old => {
|
|
633
|
+
const baselines = { ...(old?.driveBaselines ?? {}) };
|
|
634
|
+
if (old?.workspaceOnDrive && old.snapshot?.drive?.id) baselines[old.snapshot.drive.id] = { path: old.workspace, baseline: store.baseline() };
|
|
635
|
+
const kept = Object.fromEntries(Object.entries(baselines).slice(-10));
|
|
636
|
+
return { ...(Object.keys(kept).length ? { driveBaselines: kept } : {}), ...(old?.folderDrive ? { folderDrive: old.folderDrive } : {}) };
|
|
637
|
+
};
|
|
551
638
|
/**
|
|
552
639
|
* The account's running Macs, newest first: queued, starting or ready. A Mac nomac run started for one command
|
|
553
640
|
* (purpose run) is left out, or only those with runs: its run stops it when the command ends (LIM-383).
|
|
554
641
|
*/
|
|
555
642
|
async function liveSessions({ runs = false } = {}) {
|
|
556
643
|
const answer = await request("GET", "/api/v1/mac/sessions");
|
|
557
|
-
|
|
644
|
+
// A start waiting in line (in_line, LIM-390) is not running yet: never named or attached.
|
|
645
|
+
return (Array.isArray(answer?.sessions) ? answer.sessions : []).filter(s => ["queued", "provisioning", "ready"].includes(s.state) && !s.in_line && (s.purpose === "run") === runs);
|
|
558
646
|
}
|
|
559
647
|
/** This folder now uses that Mac: a fresh key of its own, then ready() adds it once the Mac is ready. */
|
|
560
648
|
async function attachTo(view) {
|
|
@@ -700,11 +788,21 @@ export async function hostedSessionCommand(command, argv, { store = sessionStore
|
|
|
700
788
|
return desktop(local, { values, print });
|
|
701
789
|
}
|
|
702
790
|
if (command === "drive") {
|
|
703
|
-
|
|
704
|
-
const
|
|
791
|
+
// The account's drives (LIM-394): list them, empty one (the default unless named), or rename one.
|
|
792
|
+
const usage = "Usage: nomac drive [--json] | nomac drive reset [NAME] | nomac drive rename OLD NEW";
|
|
793
|
+
const [verb, ...names] = positionals;
|
|
794
|
+
if (verb !== undefined && !["reset", "rename"].includes(verb)) throw new CliError(usage);
|
|
795
|
+
if ((verb === "reset" && names.length > 1) || (verb === "rename" && names.length !== 2)) throw new CliError(usage);
|
|
796
|
+
names.forEach(name => driveNameOption(name, "nomac drive"));
|
|
797
|
+
const path = name => `/api/v1/mac/drives/${encodeURIComponent(name)}`;
|
|
798
|
+
// A site before LIM-394 has only the default drive (/api/v1/mac/drive): reset of the default still works there.
|
|
799
|
+
const old = error => error?.status === 404 && (!names[0] || names[0] === "default");
|
|
800
|
+
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; })
|
|
801
|
+
: verb === "rename" ? await request("PATCH", path(names[0]), { body: { name: names[1] } })
|
|
802
|
+
: await fetchDrives(request);
|
|
705
803
|
if (values.json) { print(JSON.stringify(answer, null, 2)); return answer; }
|
|
706
|
-
|
|
707
|
-
print(
|
|
804
|
+
if (verb) { print(answer.message); return answer; }
|
|
805
|
+
print(driveList(answer));
|
|
708
806
|
return answer;
|
|
709
807
|
}
|
|
710
808
|
if (command === "defaults") {
|
|
@@ -721,7 +819,7 @@ export async function hostedSessionCommand(command, argv, { store = sessionStore
|
|
|
721
819
|
const e = answer.effective, apps = Object.entries(e.permissions ?? {});
|
|
722
820
|
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"}.`,
|
|
723
821
|
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).",
|
|
724
|
-
e.drive === "none" ? "Macs start without
|
|
822
|
+
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).",
|
|
725
823
|
"A start's own --prompts, --permit or --drive wins for that Mac. nomac defaults --reset goes back to fully open."].join("\n"));
|
|
726
824
|
return answer;
|
|
727
825
|
}
|
|
@@ -846,11 +944,12 @@ export async function hostedSessionCommand(command, argv, { store = sessionStore
|
|
|
846
944
|
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) });
|
|
847
945
|
}
|
|
848
946
|
if (command === "start") {
|
|
849
|
-
if (positionals.length) throw new CliError("Usage: nomac start [--wait SECONDS] [--json]");
|
|
947
|
+
if (positionals.length) throw new CliError("Usage: nomac start [--wait SECONDS] [--drive NAME] [--reuse] [--queue SECONDS] [--json]");
|
|
850
948
|
let local = store.load();
|
|
851
949
|
if (local && local.mode !== "hosted") throw new CliError("An existing Mac workspace is attached.");
|
|
852
950
|
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"]) };
|
|
853
|
-
|
|
951
|
+
let access = accessOption(values, { start: true });
|
|
952
|
+
const named = value => value !== undefined && !["account", "none"].includes(value);
|
|
854
953
|
// Older CLIs persisted invalid keys before contacting the API. Such a key
|
|
855
954
|
// cannot pass server validation and therefore cannot have allocated a VM.
|
|
856
955
|
if (local && !local.id && !validRequestKey(local.requestKey)) { local.state = "failed"; store.save(local); }
|
|
@@ -870,22 +969,43 @@ export async function hostedSessionCommand(command, argv, { store = sessionStore
|
|
|
870
969
|
}
|
|
871
970
|
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.");
|
|
872
971
|
if (otherAccess()) {
|
|
873
|
-
throw new CliError("This session was started with different --prompts, --gatekeeper or --
|
|
972
|
+
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.");
|
|
874
973
|
}
|
|
875
974
|
}
|
|
876
975
|
if (!local || ["stopped", "failed"].includes(local.state)) {
|
|
976
|
+
// The drive this folder was told to use before (LIM-394), for a new request only: asked for again by its current name
|
|
977
|
+
// (looked up by id, so a rename keeps it), unless this start names a drive, turns it off, or copies one (--drive-from
|
|
978
|
+
// makes a new drive). --drive account forgets it. A request already sent is repeated as it was.
|
|
979
|
+
const remembered = values.drive === undefined && values["drive-from"] === undefined ? store.load()?.folderDrive : undefined;
|
|
980
|
+
if (remembered) {
|
|
981
|
+
const known = (await fetchDrives(request).catch(() => ({ drives: [] }))).drives?.find?.(d => d.id === remembered.id);
|
|
982
|
+
access = { ...(access ?? {}), drive: known?.name ?? remembered.name };
|
|
983
|
+
}
|
|
984
|
+
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.");
|
|
877
985
|
const identity = join(store.directory, `id_ed25519_${randomUUID()}`);
|
|
878
986
|
await run("ssh-keygen", ["-q", "-t", "ed25519", "-N", "", "-C", "nomac-session", "-f", identity]);
|
|
879
987
|
local = { mode: "hosted", state: "requesting", outcomeUnknown: false, identity, requestKey: values["request-key"] ?? `cli-${randomUUID()}`,
|
|
880
|
-
request: { profile: "standard", public_key: readFileSync(`${identity}.pub`, "utf8").trim(), limits, ...(access ? { access } : {}), ...(values.parallel ? { parallel: true } : {}),
|
|
988
|
+
request: { profile: "standard", public_key: readFileSync(`${identity}.pub`, "utf8").trim(), limits, ...(access ? { access } : {}), ...(values.parallel ? { parallel: true } : {}),
|
|
989
|
+
...(values.reuse ? { reuse: true } : {}), ...(purpose ? { purpose } : {}), ...(queue ? { queue_seconds: queue } : {}) },
|
|
881
990
|
...previousDrive(store.load()) };
|
|
991
|
+
if (values.drive === "account") delete local.folderDrive;
|
|
882
992
|
store.save(local); store.saveBaseline({});
|
|
883
993
|
}
|
|
884
994
|
if (!local.id) {
|
|
885
995
|
const previouslyUncertain = local.outcomeUnknown !== false;
|
|
886
996
|
local.outcomeUnknown = true; store.save(local); // A crash after dispatch must reconcile this intent.
|
|
997
|
+
// A site from before LIM-390 does not know queue_seconds (an unrecognized field, refused before anything is made): the
|
|
998
|
+
// start is asked again without it, and waits as that site lets it (nomac run then waits on this side, as before).
|
|
999
|
+
const send = async () => {
|
|
1000
|
+
try { return await request("POST", "/api/v1/mac/sessions", { idempotencyKey: local.requestKey, body: local.request }); }
|
|
1001
|
+
catch (error) {
|
|
1002
|
+
if (error.code !== "invalid_request" || !local.request.queue_seconds || !/queue_seconds/.test(error.message ?? "")) throw error;
|
|
1003
|
+
delete local.request.queue_seconds; store.save(local);
|
|
1004
|
+
return request("POST", "/api/v1/mac/sessions", { idempotencyKey: local.requestKey, body: local.request });
|
|
1005
|
+
}
|
|
1006
|
+
};
|
|
887
1007
|
let result;
|
|
888
|
-
try { result = await
|
|
1008
|
+
try { result = await send(); }
|
|
889
1009
|
catch (error) {
|
|
890
1010
|
if (!previouslyUncertain && startRejections.has(error.code) && Number.isInteger(error.status) && error.status >= 400 && error.status <= 503) {
|
|
891
1011
|
local.state = "failed"; local.rejection = error.code; store.save(local);
|
|
@@ -896,12 +1016,28 @@ export async function hostedSessionCommand(command, argv, { store = sessionStore
|
|
|
896
1016
|
// choice made by its id.
|
|
897
1017
|
if (error.code === "session_limit_reached") {
|
|
898
1018
|
const running = (await liveSessions().catch(() => [])).map(s => s.id);
|
|
899
|
-
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);
|
|
1019
|
+
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"}\n or wait in line ${values.parallel && /a Mac to spare/.test(error.message ?? "") ? "for a Mac to spare: nomac start --parallel --queue 1800" : `for ${running.length === 1 ? "it" : "one"} to stop: nomac start${values.parallel ? " --parallel" : ""} --queue 1800`}`, error.status, error.code, error.details);
|
|
1020
|
+
}
|
|
1021
|
+
// The drive this start named is on a running Mac (LIM-394): the server names it; this folder moves there only when asked.
|
|
1022
|
+
// A nomac run Mac that has it (details.runs) is never offered: its run stops it when the command ends.
|
|
1023
|
+
if (error.code === "drive_in_use" && error.details?.running?.[0]) {
|
|
1024
|
+
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\n or wait in line for it: nomac start --drive ${error.details.drive ?? local.request.access?.drive} --queue 1800`, error.status, error.code, error.details);
|
|
900
1025
|
}
|
|
901
1026
|
throw error;
|
|
902
1027
|
}
|
|
1028
|
+
// reuse: the running Mac with this drive is the answer, so this folder attaches to it, as the person asked.
|
|
1029
|
+
if (result.reused) {
|
|
1030
|
+
const drive = local.request.access?.drive, abandoned = local.identity;
|
|
1031
|
+
local = await attachTo(result.session);
|
|
1032
|
+
for (const file of [abandoned, `${abandoned}.pub`]) rmSync(file, { force: true });
|
|
1033
|
+
if (drive) { local.folderDrive = { id: result.session.drive?.id, name: result.session.drive?.name ?? drive }; store.save(local); }
|
|
1034
|
+
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) });
|
|
1035
|
+
}
|
|
903
1036
|
// The start's warning (what the Mac allows, how to opt out) is shown with every start of this session.
|
|
904
1037
|
if (result.warning) local.warning = result.warning;
|
|
1038
|
+
// A drive this folder named is remembered by id, so its next start asks for it again even after a rename (LIM-394).
|
|
1039
|
+
const asked = local.request.access?.drive;
|
|
1040
|
+
if (asked && !["account", "none"].includes(asked) && result.session.drive?.id) local.folderDrive = { id: result.session.drive.id, name: result.session.drive.name ?? asked };
|
|
905
1041
|
saveView(local, result.session);
|
|
906
1042
|
}
|
|
907
1043
|
const deadline = now() + wait * 1000;
|
|
@@ -915,8 +1051,9 @@ export async function hostedSessionCommand(command, argv, { store = sessionStore
|
|
|
915
1051
|
}
|
|
916
1052
|
const local = localSession();
|
|
917
1053
|
if (command === "stop") {
|
|
918
|
-
if (positionals.length) throw new CliError("Usage: nomac stop [--wait SECONDS] [--json]");
|
|
919
|
-
|
|
1054
|
+
if (positionals.length) throw new CliError("Usage: nomac stop [--wait SECONDS] [--confirm] [--json]");
|
|
1055
|
+
// --confirm: stop it even though another API key sent it a command in the last minutes (confirm_required, LIM-390).
|
|
1056
|
+
saveView(local, (await request("DELETE", `/api/v1/mac/sessions/${sessionId(local.id)}${values.confirm ? "?confirm=true" : ""}`)).session);
|
|
920
1057
|
const deadline = now() + wait * 1000;
|
|
921
1058
|
while (!["stopped", "failed"].includes(local.state) && now() < deadline) { await sleep(1000); await refresh(local); }
|
|
922
1059
|
return output({ session: local.snapshot, feedback_request: FEEDBACK_REQUEST });
|
|
@@ -924,7 +1061,15 @@ export async function hostedSessionCommand(command, argv, { store = sessionStore
|
|
|
924
1061
|
await ready(local);
|
|
925
1062
|
if (command === "sync") {
|
|
926
1063
|
if (positionals.length > 1 || (positionals[0] && resolve(positionals[0]) !== store.project)) throw new CliError("Run nomac sync . from the attached project.");
|
|
1064
|
+
// nomac run --drive (LIM-394): what earlier runs sent is kept on the drive, so this run sends only what changed, and
|
|
1065
|
+
// removes what the repository deleted since; a run without a drive has nothing to keep.
|
|
1066
|
+
const kept = values["baseline-on-mac"] && local.workspaceOnDrive ? `"$HOME"/drive/.nomac/sync/${shellQuote(`${basename(local.workspace)}.json`)}` : undefined;
|
|
1067
|
+
if (kept) {
|
|
1068
|
+
const read = await run("ssh", [...sshArgs(local), local.target, `cat ${kept} 2>/dev/null || true`]).catch(() => ({ stdout: "" }));
|
|
1069
|
+
try { const saved = JSON.parse(String(read.stdout ?? "") || "{}"); if (saved && typeof saved === "object" && !Array.isArray(saved)) store.saveBaseline(saved); } catch { /* unreadable: start from nothing */ }
|
|
1070
|
+
}
|
|
927
1071
|
const result = await syncProject(local, store, { overwrite: values.overwrite, dryRun: values["dry-run"], deleteMissing: values.delete, run });
|
|
1072
|
+
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())) });
|
|
928
1073
|
if (!values.json) { print(describeSync(result)); return result; }
|
|
929
1074
|
return output(result);
|
|
930
1075
|
}
|
package/src/mac-tools.mjs
CHANGED
|
@@ -14,20 +14,28 @@ 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, who started it and its last command, to use; or wait for it with queue_seconds." },
|
|
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
|
+
queue_seconds: { type: "integer", minimum: 300, maximum: 3600, description: "Wait in line up to this long, free, while the account runs as many Macs as it may, the drive asked for is on another Mac, or no Mac is free: the Mac starts in its turn (poll get_mac_session). For CI and scripts that queue work." },
|
|
26
|
+
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" },
|
|
27
|
+
drive_from: { type: "string", description: "A drive of the account to copy into the drive made for this Mac (its last save)" },
|
|
25
28
|
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
29
|
{ 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
30
|
{ 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
31
|
{ 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
|
-
|
|
32
|
+
{ 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" } }),
|
|
33
|
+
// A site before LIM-394 has only /api/v1/mac/drive, the one drive.
|
|
34
|
+
handler: async ({ name } = {}) => text(await api("GET", name ? `/api/v1/mac/drives/${encodeURIComponent(name)}` : "/api/v1/mac/drives")
|
|
35
|
+
.catch(error => { if (error?.status === 404 && (!name || name === "default")) return api("GET", "/api/v1/mac/drive"); throw error; })) },
|
|
36
|
+
{ 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" } }),
|
|
37
|
+
handler: async ({ name } = {}) => text(await api("DELETE", `/api/v1/mac/drives/${encodeURIComponent(name ?? "default")}`)
|
|
38
|
+
.catch(error => { if (error?.status === 404 && (!name || name === "default")) return api("DELETE", "/api/v1/mac/drive"); throw error; })) },
|
|
31
39
|
{ 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
40
|
{ 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
41
|
{ 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 +48,8 @@ export const MAC_TOOLS = [
|
|
|
40
48
|
const url = desktopUrl(session_id), opened = open ? openUrl(url) : false;
|
|
41
49
|
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
50
|
} },
|
|
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:
|
|
51
|
+
{ 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. Answers confirm_required when another API key sent it a command in the last 5 minutes (another agent may be working on it): confirm true stops it anyway, only if it is yours and finished.", inputSchema: schema({ session_id: session, confirm: { type: "boolean", description: "true: stop it even though another API key sent it a command in the last 5 minutes (confirm_required)" } }, ["session_id"]), handler: async ({ confirm, ...args }) => text(await api("DELETE", `${base(args)}${confirm ? "?confirm=true" : ""}`)) },
|
|
52
|
+
{ 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
53
|
{ 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
54
|
const given = [local_path, content, content_base64].filter(v => v !== undefined).length;
|
|
47
55
|
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
|
|
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: start_mac while one runs answers session_limit_reached naming it, who started it and its last command; use it if it is yours; parallel: true starts a second; queue_seconds waits.",
|
|
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,16 +13,22 @@ 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, and your agents are never offered
|
|
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
|
|
22
23
|
--no-sync upload nothing (the command fetches what it needs)
|
|
23
|
-
--queue SECONDS how long to wait for a Mac when the account runs as many as it
|
|
24
|
-
(600 by default; 0 fails at once)
|
|
24
|
+
--queue SECONDS how long to wait in line for a Mac when the account runs as many as it
|
|
25
|
+
may, or none is free (600 by default, up to 3600; 0 fails at once). Runs
|
|
26
|
+
start in the order they asked.
|
|
25
27
|
--max-cost DOLLARS what this run may spend at most (5 by default)
|
|
28
|
+
--drive NAME run with that drive at ~/drive (made empty the first time), so caches
|
|
29
|
+
and build products carry over to the next run with the same name; a
|
|
30
|
+
drive is on one Mac at a time, so a run whose drive another run has
|
|
31
|
+
waits for it like a Mac (--queue)
|
|
26
32
|
The command is one argv; for a shell line: nomac run -- bash -lc 'pod install && make test'.
|
|
27
33
|
Nothing is read from stdin. Needs NOMAC_API_KEY (a CI secret) or nomac login, and the
|
|
28
34
|
OpenSSH client (ssh, ssh-keygen). A cancelled job (SIGTERM, SIGINT, SIGHUP) stops the Mac.
|
|
@@ -33,7 +39,7 @@ export const RUN_HELP = `nomac run [options] -- command args
|
|
|
33
39
|
|
|
34
40
|
const options = {
|
|
35
41
|
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" },
|
|
42
|
+
queue: { type: "string" }, "max-cost": { type: "string" }, drive: { type: "string" }, help: { type: "boolean", short: "h" },
|
|
37
43
|
};
|
|
38
44
|
/** A command's limit: the CLI waits a minute past it (up to the gateway's hour), so it sees the command end. */
|
|
39
45
|
const MAX_TIMEOUT = 3540;
|
|
@@ -54,7 +60,8 @@ function whole(value, fallback, min, max, what) {
|
|
|
54
60
|
/**
|
|
55
61
|
* nomac run: start, sync, exec and pull as those commands do them, under a session state of the run's own (a fresh
|
|
56
62
|
* directory, removed after, marked ephemeral so the folder's SSH config entry is left alone), always with --parallel and
|
|
57
|
-
*
|
|
63
|
+
* 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
|
|
64
|
+
* or drive someone uses; with one, what earlier runs sent is kept on that drive. Its Mac is marked purpose run, so agents
|
|
58
65
|
* are never offered it (refusals, attach, calls without a session id). The Mac is stopped with one API call (no
|
|
59
66
|
* folder lock to wait for) at the end, after any failure, and on the first SIGTERM or SIGINT (later ones, such as npm
|
|
60
67
|
* forwarding the same signal, are ignored), which then exits 143 or 130. Returns the command's exit code.
|
|
@@ -120,8 +127,13 @@ export async function runCommand(argv, {
|
|
|
120
127
|
|
|
121
128
|
try {
|
|
122
129
|
// The Mac lives a little past the command's limit (the start, the upload, the pull), and stops at the end anyway.
|
|
123
|
-
|
|
124
|
-
|
|
130
|
+
// Without --drive the run's Mac has none; with it, that named drive (LIM-394), never the default or one NoMac made.
|
|
131
|
+
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)))
|
|
132
|
+
throw new CliError("--drive names a drive of the run's own, like ci-cache (not default, account, none or drive-N).");
|
|
133
|
+
// --queue waits in NoMac's line (LIM-390: first come, first served, at least 5 minutes), and the start waits that long too.
|
|
134
|
+
const line = queue ? Math.max(300, queue) : 0;
|
|
135
|
+
const start = ["--wait", String(600 + line), "--parallel", "--drive", values.drive ?? "none", "--max-duration", String(Math.min(28_800, timeout + 1800)), "--idle-timeout", "900",
|
|
136
|
+
...(line ? ["--queue", String(line)] : []), ...(values["max-cost"] ? ["--max-cost", values["max-cost"]] : [])];
|
|
125
137
|
const until = now() + queue * 1000;
|
|
126
138
|
let started;
|
|
127
139
|
for (let waited = false; ; waited = true) {
|
|
@@ -131,13 +143,18 @@ export async function runCommand(argv, {
|
|
|
131
143
|
try { started = await step("start", start, { purpose: "run" }); break; }
|
|
132
144
|
catch (error) {
|
|
133
145
|
// The account already runs as many Macs as it may: a pipeline waits its turn, a bounded time.
|
|
134
|
-
if (
|
|
135
|
-
say(
|
|
146
|
+
if (!["session_limit_reached", "drive_in_use", "queue_full"].includes(error?.code) || now() >= until) throw error;
|
|
147
|
+
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)`
|
|
148
|
+
: `the account runs as many Macs as it may; waiting for one to stop (up to ${Math.ceil((until - now()) / 1000)} s more)`);
|
|
136
149
|
await sleep(15_000);
|
|
137
150
|
}
|
|
138
151
|
}
|
|
139
|
-
if (started?.session?.state !== "ready") throw new CliError(
|
|
140
|
-
|
|
152
|
+
if (started?.session?.state !== "ready") throw new CliError(started?.session?.failure_code === "queue_expired" || started?.session?.failure_code === "capacity_unavailable"
|
|
153
|
+
? `No Mac was free for this run within ${Math.round(line / 60) || 5} minutes in line, so it ended with nothing charged: the account's other Macs kept running, or none was free. Try again later${line < 3600 ? ", or with a longer --queue (up to 3600)" : ""}.`
|
|
154
|
+
: `The Mac did not become ready (it is ${started?.session?.state ?? "unknown"}${started?.session?.failure_code ? `, ${started.session.failure_code}` : ""}).`);
|
|
155
|
+
// With a drive the project folder is the one earlier runs left there: this folder replaces what differs and removes what
|
|
156
|
+
// it no longer has (its build caches, in folders sync skips, stay).
|
|
157
|
+
if (!values["no-sync"]) { say("uploading this folder"); await step("sync", [".", ...(values.drive ? ["--overwrite", "--delete", "--baseline-on-mac"] : [])]); }
|
|
141
158
|
say(`running ${command.join(" ").slice(0, 200)}`);
|
|
142
159
|
// A key of its own: after a lost connection the same command is asked for again (it keeps running), never run twice.
|
|
143
160
|
const exec = ["--wait", String(timeout + 60), "--timeout", String(timeout), "--request-key", `run-${randomUUID()}`, "--", ...command];
|