@nomac/cli 0.25.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nomac/cli",
3
- "version": "0.25.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
@@ -38,10 +38,10 @@ Store screenshots start the phone with `device: "iphone-pro-max"` (6.9-inch,
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
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
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.25.0 mcp`.
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
@@ -81,7 +81,12 @@ background (`NOMAC_NO_AUTO_UPDATE=1` turns it off; `nomac update` now).
81
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. Every Mac gets a 20 GB
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
85
90
  drive at `~/drive`, on one Mac at a time: the first gets the account's
86
91
  default drive, a second a new drive of its own, and `nomac status` and
87
92
  `~/NOMAC.md` name it. To keep an agent's work apart, give it a drive:
package/src/cli.mjs CHANGED
@@ -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
- const description = rest.join(" ").trim();
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": {
@@ -62,8 +62,13 @@ const HELP = `Nomac cloud Mac sessions
62
62
  folder (accounts that bought credit, while a Mac is spare), with
63
63
  a drive of its own while the first has the default. Without it,
64
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.
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)
67
72
  nomac ssh-config [--alias nomac] [--print]
68
73
  name this folder's Mac in your SSH config (Host nomac), for
69
74
  VS Code or Cursor Remote-SSH, Claude Code SSH sessions, ssh nomac,
@@ -119,6 +124,8 @@ const options = {
119
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.
120
125
  "baseline-on-mac": { type: "boolean" },
121
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" },
122
129
  };
123
130
  /** --permit com.example.App=camera,microphone (or =all), as the permissions option. */
124
131
  export function permitOption(values) {
@@ -213,7 +220,9 @@ const startRejections = new Set(["invalid_request", "invalid_public_key", "profi
213
220
  "weekly_time_unavailable", "weekly_time_expired", "insufficient_compute_credit", "insufficient_credit", "compute_account_blocked",
214
221
  "session_limit_reached", "organization_not_found", "compute_unavailable", "unauthenticated", "invalid_origin",
215
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.
216
- "drive_in_use", "drive_limit_reached", "drive_not_found"]);
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"]);
217
226
  export async function sessionAccess(id, request = api) {
218
227
  sessionId(id);
219
228
  const access = await request("POST", `/api/v1/mac/sessions/${id}/access`);
@@ -489,7 +498,9 @@ export async function hostedSessionCommand(command, argv, { store = sessionStore
489
498
  catch (error) { throw new CliError(error.message); }
490
499
  const { values, positionals } = parsed;
491
500
  if (values.help) return print(command === "desktop" ? DESKTOP_HELP : HELP);
492
- const wait = ["start", "attach", "stop"].includes(command) ? integer(values.wait, command === "stop" ? 60 : 300, 0, command === "stop" ? 300 : 600, "--wait (seconds)") : 0;
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;
493
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.");
494
505
  // The image the last read reported (macOS, Xcodes, Simulators), for start's summary.
495
506
  let lastImage;
@@ -504,7 +515,9 @@ export async function hostedSessionCommand(command, argv, { store = sessionStore
504
515
  ? `Cost: ${usd(result.session?.cost?.accrued_microunits)} (${perHour(result.session)}billed per minute while the Mac was ready). Credit left: nomac credits`
505
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`;
506
517
  const next = result.session.state === "ready" ? `${result.project ? `${projectLine(result.project)}\n` : ""}Next: nomac sync . → nomac ssh`
507
- : result.session.failure_code === "capacity_unavailable" ? "No Mac was free within 5 minutes; nothing was charged. Run nomac start again in a few minutes."
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"
508
521
  : result.session.state === "queued" ? "Waiting for a free Mac (waiting is free). Check again: nomac start"
509
522
  : ["stopped", "failed"].includes(result.session.state) ? `${result.session.drive ? "The drive saves in the background (nomac drive shows it). " : ""}Start another: nomac start`
510
523
  : result.session.state === "stopping" ? "Stopping. Check: nomac status"
@@ -628,7 +641,8 @@ export async function hostedSessionCommand(command, argv, { store = sessionStore
628
641
  */
629
642
  async function liveSessions({ runs = false } = {}) {
630
643
  const answer = await request("GET", "/api/v1/mac/sessions");
631
- return (Array.isArray(answer?.sessions) ? answer.sessions : []).filter(s => ["queued", "provisioning", "ready"].includes(s.state) && (s.purpose === "run") === runs);
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);
632
646
  }
633
647
  /** This folder now uses that Mac: a fresh key of its own, then ready() adds it once the Mac is ready. */
634
648
  async function attachTo(view) {
@@ -930,7 +944,7 @@ export async function hostedSessionCommand(command, argv, { store = sessionStore
930
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) });
931
945
  }
932
946
  if (command === "start") {
933
- if (positionals.length) throw new CliError("Usage: nomac start [--wait SECONDS] [--drive NAME] [--reuse] [--json]");
947
+ if (positionals.length) throw new CliError("Usage: nomac start [--wait SECONDS] [--drive NAME] [--reuse] [--queue SECONDS] [--json]");
934
948
  let local = store.load();
935
949
  if (local && local.mode !== "hosted") throw new CliError("An existing Mac workspace is attached.");
936
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"]) };
@@ -972,7 +986,7 @@ export async function hostedSessionCommand(command, argv, { store = sessionStore
972
986
  await run("ssh-keygen", ["-q", "-t", "ed25519", "-N", "", "-C", "nomac-session", "-f", identity]);
973
987
  local = { mode: "hosted", state: "requesting", outcomeUnknown: false, identity, requestKey: values["request-key"] ?? `cli-${randomUUID()}`,
974
988
  request: { profile: "standard", public_key: readFileSync(`${identity}.pub`, "utf8").trim(), limits, ...(access ? { access } : {}), ...(values.parallel ? { parallel: true } : {}),
975
- ...(values.reuse ? { reuse: true } : {}), ...(purpose ? { purpose } : {}) },
989
+ ...(values.reuse ? { reuse: true } : {}), ...(purpose ? { purpose } : {}), ...(queue ? { queue_seconds: queue } : {}) },
976
990
  ...previousDrive(store.load()) };
977
991
  if (values.drive === "account") delete local.folderDrive;
978
992
  store.save(local); store.saveBaseline({});
@@ -980,8 +994,18 @@ export async function hostedSessionCommand(command, argv, { store = sessionStore
980
994
  if (!local.id) {
981
995
  const previouslyUncertain = local.outcomeUnknown !== false;
982
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
+ };
983
1007
  let result;
984
- try { result = await request("POST", "/api/v1/mac/sessions", { idempotencyKey: local.requestKey, body: local.request }); }
1008
+ try { result = await send(); }
985
1009
  catch (error) {
986
1010
  if (!previouslyUncertain && startRejections.has(error.code) && Number.isInteger(error.status) && error.status >= 400 && error.status <= 503) {
987
1011
  local.state = "failed"; local.rejection = error.code; store.save(local);
@@ -992,12 +1016,12 @@ export async function hostedSessionCommand(command, argv, { store = sessionStore
992
1016
  // choice made by its id.
993
1017
  if (error.code === "session_limit_reached") {
994
1018
  const running = (await liveSessions().catch(() => [])).map(s => s.id);
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);
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);
996
1020
  }
997
1021
  // The drive this start named is on a running Mac (LIM-394): the server names it; this folder moves there only when asked.
998
1022
  // A nomac run Mac that has it (details.runs) is never offered: its run stops it when the command ends.
999
1023
  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);
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);
1001
1025
  }
1002
1026
  throw error;
1003
1027
  }
@@ -1027,8 +1051,9 @@ export async function hostedSessionCommand(command, argv, { store = sessionStore
1027
1051
  }
1028
1052
  const local = localSession();
1029
1053
  if (command === "stop") {
1030
- if (positionals.length) throw new CliError("Usage: nomac stop [--wait SECONDS] [--json]");
1031
- saveView(local, (await request("DELETE", `/api/v1/mac/sessions/${sessionId(local.id)}`)).session);
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);
1032
1057
  const deadline = now() + wait * 1000;
1033
1058
  while (!["stopped", "failed"].includes(local.state) && now() < deadline) { await sleep(1000); await refresh(local); }
1034
1059
  return output({ session: local.snapshot, feedback_request: FEEDBACK_REQUEST });
package/src/mac-tools.mjs CHANGED
@@ -20,8 +20,9 @@ export const MAC_TOOLS = [
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; 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." },
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
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." },
25
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" },
26
27
  drive_from: { type: "string", description: "A drive of the account to copy into the drive made for this Mac (its last save)" },
27
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 })) },
@@ -47,7 +48,7 @@ export const MAC_TOOLS = [
47
48
  const url = desktopUrl(session_id), opened = open ? openUrl(url) : false;
48
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." });
49
50
  } },
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: "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" : ""}`)) },
51
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 })) },
52
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 }) => {
53
54
  const given = [local_path, content, content_base64].filter(v => v !== undefined).length;
package/src/mcp.mjs CHANGED
@@ -24,7 +24,7 @@ const INSTRUCTIONS = [
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
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).",
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.",
package/src/run.mjs CHANGED
@@ -21,8 +21,9 @@ export const RUN_HELP = `nomac run [options] -- command args
21
21
  --pull PATH after the command, copy PATH (relative to the project folder) here;
22
22
  repeat it for more
23
23
  --no-sync upload nothing (the command fetches what it needs)
24
- --queue SECONDS how long to wait for a Mac when the account runs as many as it may
25
- (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.
26
27
  --max-cost DOLLARS what this run may spend at most (5 by default)
27
28
  --drive NAME run with that drive at ~/drive (made empty the first time), so caches
28
29
  and build products carry over to the next run with the same name; a
@@ -129,8 +130,10 @@ export async function runCommand(argv, {
129
130
  // Without --drive the run's Mac has none; with it, that named drive (LIM-394), never the default or one NoMac made.
130
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)))
131
132
  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",
133
- ...(values["max-cost"] ? ["--max-cost", values["max-cost"]] : [])];
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"]] : [])];
134
137
  const until = now() + queue * 1000;
135
138
  let started;
136
139
  for (let waited = false; ; waited = true) {
@@ -140,13 +143,15 @@ export async function runCommand(argv, {
140
143
  try { started = await step("start", start, { purpose: "run" }); break; }
141
144
  catch (error) {
142
145
  // The account already runs as many Macs as it may: a pipeline waits its turn, a bounded time.
143
- if (!["session_limit_reached", "drive_in_use"].includes(error?.code) || now() >= until) throw error;
146
+ if (!["session_limit_reached", "drive_in_use", "queue_full"].includes(error?.code) || now() >= until) throw error;
144
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)`
145
148
  : `the account runs as many Macs as it may; waiting for one to stop (up to ${Math.ceil((until - now()) / 1000)} s more)`);
146
149
  await sleep(15_000);
147
150
  }
148
151
  }
149
- if (started?.session?.state !== "ready") throw new CliError(`The Mac did not become ready (it is ${started?.session?.state ?? "unknown"}).`);
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}` : ""}).`);
150
155
  // With a drive the project folder is the one earlier runs left there: this folder replaces what differs and removes what
151
156
  // it no longer has (its build caches, in folders sync skips, stay).
152
157
  if (!values["no-sync"]) { say("uploading this folder"); await step("sync", [".", ...(values.drive ? ["--overwrite", "--delete", "--baseline-on-mac"] : [])]); }