@catalyst-cloud/cli 0.16.28 → 0.16.30

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.
Files changed (38) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +3 -3
  3. package/dist/args.js +15 -0
  4. package/dist/capabilities.js +2 -0
  5. package/dist/cli-version.js +41 -0
  6. package/dist/cli.js +23 -0
  7. package/dist/lease.js +302 -0
  8. package/dist/onboard-existing.js +12 -3
  9. package/dist/onboard-next.js +39 -0
  10. package/dist/onboard-projects.js +3 -3
  11. package/dist/onboard-repositories.js +10 -3
  12. package/dist/onboard-runner-disk.js +345 -0
  13. package/dist/onboard-runner.js +52 -0
  14. package/dist/onboard-ui.js +5 -1
  15. package/dist/onboard.js +11 -0
  16. package/dist/ready.js +47 -1
  17. package/dist/runner.js +19 -2
  18. package/dist/setup-onboard-copy.js +41 -2
  19. package/dist/watch/consumer.js +1 -0
  20. package/dist/watch.js +2 -1
  21. package/package.json +1 -1
  22. package/skills/catalyst-github/SKILL.md +1 -1
  23. package/skills/catalyst-linear/SKILL.md +1 -1
  24. package/skills/catalyst-onboard/SKILL.md +1 -1
  25. package/skills/catalyst-onboard/references/reading-ready.md +1 -0
  26. package/skills/run-this-project/SKILL.md +1 -1
  27. package/skills/run-this-project/references/stalls-and-escalation.md +1 -1
  28. package/skills/unstick/SKILL.md +1 -1
  29. package/skills/what-needs-me/SKILL.md +1 -1
  30. package/skills/what-this-repo-needs/SKILL.md +1 -1
  31. package/skills/whats-happening/SKILL.md +1 -1
  32. package/skills/whats-happening/references/what-runs-next.md +1 -1
  33. package/skills/whats-happening/references/why-is-it-stuck.md +1 -1
  34. package/vendor/self-host/darwin-thoughts-custody/manifest.json +2 -2
  35. package/vendor/self-host/darwin-thoughts-custody/verifier.mjs +90 -31
  36. package/vendor/self-host/host-disk-sample.py +57 -0
  37. package/vendor/self-host/launchd/dev.catalystcloud.host-disk.plist +18 -0
  38. package/vendor/self-host/provenance.json +6 -4
package/dist/runner.js CHANGED
@@ -8,6 +8,7 @@ import { loadConfig } from "./config.js";
8
8
  import { CliError, UsageError } from "./errors.js";
9
9
  import { onboardStateRoot } from "./onboard.js";
10
10
  import { dockerRunnerEngine, RUNNER_PROJECT, RUNNER_SESSION_NETWORK } from "./onboard-runner.js";
11
+ import { HOST_DISK_LABEL, hostDiskAgentOutput } from "./onboard-runner-disk.js";
11
12
  import { EGRESS_ARTIFACTS, NATIVE_EGRESS_DIR } from "./onboard-runner-egress.js";
12
13
  import { stdinIsTty } from "./prompt.js";
13
14
  import { apiClient } from "./transport.js";
@@ -23,7 +24,7 @@ const COMPOSE_VOLUMES = ["supervisor-state", "host-credential"].map(v => `${RUNN
23
24
  const COMPOSE_FILES = ["compose.yaml", "compose.darwin-thoughts.yaml"];
24
25
  /** Files setup writes into the runner directory. The work folders are listed separately. */
25
26
  const SETUP_FILES = [...COMPOSE_FILES, ".env", "key-request.json"];
26
- const SETUP_DIRS = ["session-egress", "host-disk"];
27
+ const SETUP_DIRS = ["session-egress", "host-disk", "host-disk-sampler"];
27
28
  /** Repository checkouts, the thoughts checkout and their locks: kept unless the owner says so. */
28
29
  const WORK_DIRS = ["slots", "thoughts", "locks"];
29
30
  const DARWIN_SIBLINGS = ["darwin-thoughts-custody", "darwin-thoughts-requests", "darwin-thoughts-responses"];
@@ -68,6 +69,20 @@ const exists = (path) => { try {
68
69
  catch {
69
70
  return false;
70
71
  } };
72
+ /** Setup's disk sampler publishes into this runner's own host-disk bind; a same-label agent that
73
+ * writes elsewhere is its operator's, as setup treats it (CTC-5929). */
74
+ function samplerIsSetups(text, runnerDir) {
75
+ const output = hostDiskAgentOutput(text);
76
+ if (!output || !runnerDir || basename(output) !== "space.json")
77
+ return false;
78
+ const real = (path) => { try {
79
+ return realpathSync(path);
80
+ }
81
+ catch {
82
+ return path;
83
+ } };
84
+ return real(dirname(output)) === real(join(runnerDir, "host-disk"));
85
+ }
71
86
  /** The onboarding engine's reads, through this command's own runner. */
72
87
  function dockerEnvRun(run) {
73
88
  return (args, options) => run("docker", args, { input: options.input, timeoutMs: options.timeoutMs });
@@ -512,7 +527,9 @@ async function uninstall(args, ctx, deps, inst) {
512
527
  for (const agent of darwinAgents) {
513
528
  let ours = false;
514
529
  try {
515
- ours = owned(agent.plist, uid, "file") && readFileSync(agent.plist, "utf8").includes(`<string>${agent.label}</string>`);
530
+ const text = readFileSync(agent.plist, "utf8");
531
+ ours = owned(agent.plist, uid, "file") && text.includes(`<string>${agent.label}</string>`) &&
532
+ (agent.label !== HOST_DISK_LABEL || samplerIsSetups(text, runnerDir));
516
533
  }
517
534
  catch { /* unreadable */ }
518
535
  if (!ours) {
@@ -1,4 +1,4 @@
1
- import { dependencySettled, ONBOARD_DEPENDENCIES, ONBOARD_STEPS, ONBOARD_TITLES, } from "./onboard.js";
1
+ import { dependencySettled, stepSatisfied, ONBOARD_DEPENDENCIES, ONBOARD_STEPS, ONBOARD_TITLES, } from "./onboard.js";
2
2
  import { dispatchStageName, onboardReasonText } from "./onboard-next.js";
3
3
  /** The step numbers `--json` reports. People read SETUP_PART_NUMBERS instead (CTC-4680). */
4
4
  export const SETUP_NUMBERS = {
@@ -385,6 +385,9 @@ moment = "end") {
385
385
  {
386
386
  // A member's own skip (no --team) is theirs to finish, so it is never counted done.
387
387
  mark: memberOwnSkip(step) ? "act" : setupStepView(step, journal).mark,
388
+ // CTC-5932: a skipped step finishes its row only when it was skipped by choice. A skipped
389
+ // connection is still owed, so a part never reads "done" over it.
390
+ settled: step.state !== "skipped" || stepSatisfied(step),
388
391
  working: step.state !== "done" && CLOUD_WORK.has(step.reason ?? ""),
389
392
  kind: setupWaitsOnAdmin(step, journal)
390
393
  ? "admin"
@@ -400,7 +403,8 @@ moment = "end") {
400
403
  const part = progress[Number(key.split(":")[0])];
401
404
  part.total++;
402
405
  const own = steps.filter((s) => s.kind === "own");
403
- if (own.length === steps.length && own.every((s) => s.mark === "done" || s.mark === "skip"))
406
+ if (own.length === steps.length &&
407
+ own.every((s) => s.mark === "done" || (s.mark === "skip" && s.settled)))
404
408
  part.done++;
405
409
  else if (own.some((s) => s.mark === "act" || s.mark === "fail")) {
406
410
  part.needs++;
@@ -416,6 +420,41 @@ moment = "end") {
416
420
  }
417
421
  return progress;
418
422
  }
423
+ /** The connections part 2 makes, each approved by a person in a browser. */
424
+ const BROWSER_CONNECTIONS = [
425
+ "linear.workspace",
426
+ "linear.personal",
427
+ "github.install",
428
+ "github.personal",
429
+ ];
430
+ /**
431
+ * CTC-5932: what a run that could not ask anyone left out, said plainly, with the command that
432
+ * resumes it. Empty when nothing was left out. A runner chosen or declined by flag is the person's
433
+ * choice and is not repeated back.
434
+ */
435
+ export function unattendedSkipLines(journal, options = {}) {
436
+ const inScope = (id) => !options.scope || options.scope.includes(id);
437
+ const step = (id) => journal.steps.find((s) => s.id === id);
438
+ const lines = [];
439
+ const runner = step("runner");
440
+ if (options.runner === undefined &&
441
+ inScope("runner") &&
442
+ runner?.state === "skipped" &&
443
+ runner.reason === "runner_not_selected")
444
+ lines.push("Setup ran without questions, so it chose no runner: this computer will not run tickets.", "To add one, run in a terminal: catalyst setup --runner");
445
+ const open = BROWSER_CONNECTIONS.filter((id) => inScope(id) && step(id)?.state !== "done");
446
+ // Name only the providers still open, so a re-run with Linear connected never calls it skipped.
447
+ const providers = [
448
+ ...(open.some((id) => id.startsWith("linear.")) ? ["Linear"] : []),
449
+ ...(open.some((id) => id.startsWith("github.")) ? ["GitHub"] : []),
450
+ ];
451
+ const both = providers.length > 1;
452
+ if (open.length)
453
+ lines.push(`${providers.join(" and ")} ${both ? "were" : "was"} skipped, because ${both ? "they need" : "it needs"} you in a browser. Not connected: ${open
454
+ .map((id) => TITLES[id] ?? ONBOARD_TITLES[id])
455
+ .join(", ")}.`, `To connect ${both ? "them" : "it"}, run in a terminal: catalyst setup`);
456
+ return lines;
457
+ }
419
458
  /**
420
459
  * The tracker's rows: on the first screen (`plan`, the part about to start), at a boundary
421
460
  * (`next`, the part about to start), or at the end. A part with no rows in this run is left out.
@@ -112,6 +112,7 @@ export function createLiveEventsClient(sdk, opts) {
112
112
  baseUrl: opts.baseUrl,
113
113
  accountId: opts.accountId,
114
114
  auth: opts.auth,
115
+ connectParams: () => opts.cliVersion ? { cli_version: opts.cliVersion } : undefined,
115
116
  reseed: reseedHead,
116
117
  getCursor: () => state?.cursor ?? null,
117
118
  onChange: (frame) => {
package/dist/watch.js CHANGED
@@ -4,7 +4,7 @@
4
4
  // an issue reference to its project through GET /api/v1/issues/:ref, cached in memory.
5
5
  import { spawn } from "node:child_process";
6
6
  import { flagList, flagString } from "./args.js";
7
- import { apiBase, requireConfig, watchCursorPathFor } from "./config.js";
7
+ import { apiBase, requireConfig, readManifest, watchCursorPathFor } from "./config.js";
8
8
  import { loadContract } from "./contract.js";
9
9
  import { CliError, UsageError } from "./errors.js";
10
10
  import { apiClient } from "./transport.js";
@@ -136,6 +136,7 @@ export async function runWatch(ctx, cfg, opts, deps = {}) {
136
136
  return createLiveEventsClient(sdk, {
137
137
  baseUrl: apiBase(cfg),
138
138
  accountId: cfg.account,
139
+ cliVersion: readManifest().version,
139
140
  auth: authStrategyFor(ctx, cfg),
140
141
  getToken: () => bearerFor(ctx, cfg),
141
142
  cursorFile: opts.cursorFile ?? watchCursorPathFor(ctx.home),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@catalyst-cloud/cli",
3
- "version": "0.16.28",
3
+ "version": "0.16.30",
4
4
  "description": "Set up Catalyst Cloud, check your tickets and manage your account from the command line.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -4,7 +4,7 @@ description: >-
4
4
  Catalyst's GitHub: show a ticket's pull request with its checks, reviews and review threads, say whether it is mergeable under this repository's policy, and explain what a PR accumulates as the ticket moves (the branch, the draft, the rewrite, the force-pushes, the labels, the queue). Use when someone asks "show me the PR", "what are the checks saying", "why hasn't it merged", "what does the queue need", "what does that label mean", or wants the branch and merge conventions Catalyst follows.
5
5
  allowed-tools: Bash(catalyst:*) Bash(npx -p @catalyst-cloud/cli catalyst:*)
6
6
  ---
7
- <!-- vendored-from: @catalyst-cloud/catalyst-skills@0.16.28 — written in this repository for customer accounts -->
7
+ <!-- vendored-from: @catalyst-cloud/catalyst-skills@0.16.30 — written in this repository for customer accounts -->
8
8
 
9
9
  # Catalyst's GitHub
10
10
 
@@ -4,7 +4,7 @@ description: >-
4
4
  Catalyst's view of Linear on the customer's own cloud account. Reads a ticket with its comments, relations, labels, linked pull requests and agent sessions inline, from the cloud API by default, with local replica reads available as an explicit opt-in, always naming the source; searches tickets, PRs, projects and initiatives; writes comments, card moves, labels and new tickets through the account's agent proxy as the app actor, with every route, stage id, label id and marker read from the account's contract. Knows what a ticket accumulates as Catalyst works it (phase-outcome comments, the document per phase, the agent session, the labels, the single blocks relation, the bookkeeping marker, the eyes acknowledgement). Use when a person says "show me the ticket", "what did Catalyst write on it", "comment on it", "move it", "label it" or "file a ticket". Not for raising a decision for a human (what-needs-me) and not for pull requests (catalyst-github).
5
5
  allowed-tools: Bash(catalyst:*) Bash(npx -p @catalyst-cloud/cli catalyst:*)
6
6
  ---
7
- <!-- vendored-from: @catalyst-cloud/catalyst-skills@0.16.28 — written in this repository for customer accounts -->
7
+ <!-- vendored-from: @catalyst-cloud/catalyst-skills@0.16.30 — written in this repository for customer accounts -->
8
8
 
9
9
  # Catalyst Linear
10
10
 
@@ -4,7 +4,7 @@ description: >-
4
4
  Set up Catalyst Cloud and say whether setup is working. Walks a person from nothing to their first ticket running, one step at a time: the coding account, the project, the integrations and connected accounts, each repository's settings file, then one real ticket moving. Also logs this machine in, reads the readiness verdict with who can fix each failure, and checks the optional local replica. Use when someone says "set me up", "onboard me", "I just signed up", "get me started", "what do I do first", "log me in", "which account is this machine on", "am I set up", "what is missing", "why does nothing happen" or "is the replica running", when a login expired, or when a skill script exits 2 saying this machine is not connected. Does every step a key can do through the catalyst CLI, hands over the exact page for the steps only a browser can do, and never claims a step it did not watch succeed.
5
5
  allowed-tools: Bash(catalyst:*) Bash(npx -p @catalyst-cloud/cli catalyst:*)
6
6
  ---
7
- <!-- vendored-from: @catalyst-cloud/catalyst-skills@0.16.28 — written in this repository for customer accounts -->
7
+ <!-- vendored-from: @catalyst-cloud/catalyst-skills@0.16.30 — written in this repository for customer accounts -->
8
8
 
9
9
  # Onboard me
10
10
 
@@ -64,6 +64,7 @@ Each failing line prints its own fix.
64
64
  | `cliRelease` | the CLI is not behind the newest release; a note |
65
65
  | `skillsRelease` | the skill files are not behind the newest bundle; "could not run" means the registry was unreachable |
66
66
  | `sdk` | the SDK loads, so the replica and the watch are available; reads work through the API meanwhile |
67
+ | `runner:disk` | when this machine runs Catalyst's work, the disk Docker uses has a fresh measurement with at least 25 GiB free (`CATALYST_HOST_FREE_FLOOR_GIB` changes the amount), so it can take work. A failing line says how much is free or why there is no measurement, with its fix, usually `catalyst setup --runner`; on a Mac that command also starts the LaunchAgent that measures the disk. A note means `ready` could not verify the installation to read it. Absent when this machine does not run Catalyst's work |
67
68
  | `replica` | the optional replica is fresh; a note (`references/local-sync.md`) |
68
69
 
69
70
  ## Setting up one team at a time
@@ -4,7 +4,7 @@ description: >-
4
4
  Own one Catalyst Cloud project end to end until it closes. Use when the person says "run this project for me", "own this until it ships", "keep this moving", or hands you a project id or a set of tickets to drive. Subscribes to the account's event stream for the scope through the catalyst CLI, reacts to each change in the same turn, makes tickets ready and moves them to dispatch, parks what should stop, chases stalls, escalates inward, and keeps one status summary current. Writes to Linear as the app actor; never polls.
5
5
  allowed-tools: Bash(catalyst:*) Bash(npx -p @catalyst-cloud/cli catalyst:*)
6
6
  ---
7
- <!-- vendored-from: @catalyst-cloud/catalyst-skills@0.16.28 — written in this repository for customer accounts -->
7
+ <!-- vendored-from: @catalyst-cloud/catalyst-skills@0.16.30 — written in this repository for customer accounts -->
8
8
 
9
9
  # Run this project
10
10
 
@@ -24,7 +24,7 @@ Quote a reason the table does not know as the explainer spelled it.
24
24
 
25
25
  ## Shared causes are one note
26
26
 
27
- When several tickets are offered and nothing takes them, or the explainer names a routing, slot, provider or image condition, the cause is shared (coding-account headroom, a provider outage, a paused repository, a bad runner image). Write one summary line naming the condition and the tickets it holds. `catalyst accounts` reads coding-account status; enrolling or pausing one is the settings page.
27
+ When several tickets are offered and nothing takes them, or the explainer names a routing, slot, provider or image condition, the cause is shared (coding-account headroom, a provider outage, a paused repository, a bad runner image). Write one summary line naming the condition and the tickets it holds. For a paused repository, `catalyst repo status` says who paused it, when and why; put that in the line, and leave resuming (`catalyst repo resume <owner/name>`) to a workspace owner or admin. `catalyst accounts` reads coding-account status; enrolling or pausing one is the settings page.
28
28
 
29
29
  ## Escalate inward
30
30
 
@@ -4,7 +4,7 @@ description: >-
4
4
  Get a stuck Catalyst Cloud ticket moving again. Use when the person asks "why is this parked and can you release it?", "unpark this", "get things flowing again", "the outage is over, retry what failed", or hands you a ticket that is not moving. Reads why nothing runs and what holds the ticket through the catalyst CLI, decides whether the recorded cause is fixed, previews the release, releases every governor holding the ticket the right way (or one failure class across a team), and raises an ask only for what a person has to do. Never releases a cause it cannot show changed without saying so.
5
5
  allowed-tools: Bash(catalyst:*) Bash(npx -p @catalyst-cloud/cli catalyst:*)
6
6
  ---
7
- <!-- vendored-from: @catalyst-cloud/catalyst-skills@0.16.28 — written in this repository for customer accounts -->
7
+ <!-- vendored-from: @catalyst-cloud/catalyst-skills@0.16.30 — written in this repository for customer accounts -->
8
8
 
9
9
  # Unstick
10
10
 
@@ -4,7 +4,7 @@ description: >-
4
4
  The human's decision inbox on Catalyst Cloud, and the one way an agent raises a decision on their behalf. Use when the person asks "what needs me?", "what am I blocking?", or when active work is gated on a choice only they can make. Lists open asks ranked by how much open work each one holds, files an ask through the cloud's ask route with the account's own template, and records the answer so the held work releases. Never answers as the human, never duplicates an open ask.
5
5
  allowed-tools: Bash(catalyst:*) Bash(npx -p @catalyst-cloud/cli catalyst:*)
6
6
  ---
7
- <!-- vendored-from: @catalyst-cloud/catalyst-skills@0.16.28 — written in this repository for customer accounts -->
7
+ <!-- vendored-from: @catalyst-cloud/catalyst-skills@0.16.30 — written in this repository for customer accounts -->
8
8
 
9
9
  # What needs me
10
10
 
@@ -4,7 +4,7 @@ description: >-
4
4
  What environment variable names does this repository need, and where does each one come from? Scans the repository offline (no login, no network) and lists the names in three groups (build/test, deploy-only, bindings), each with where it was found, what uses it, and where a local value would come from. Never reads a value or prints one. Also checks the environment variable table in `.catalyst/catalyst.toml` offline. Use when someone asks "what does catalyst.env.json mean", "what env vars does this repo need", "why does the container need this", or before reviewing or writing the declaration.
5
5
  allowed-tools: Bash(catalyst:*) Bash(npx -p @catalyst-cloud/cli catalyst:*)
6
6
  ---
7
- <!-- vendored-from: @catalyst-cloud/catalyst-skills@0.16.28 — written in this repository for customer accounts -->
7
+ <!-- vendored-from: @catalyst-cloud/catalyst-skills@0.16.30 — written in this repository for customer accounts -->
8
8
 
9
9
  # What this repository needs
10
10
 
@@ -4,7 +4,7 @@ description: >-
4
4
  Use for "what's happening?", "what machines do we have?", "how much capacity do we have?", "where are we?", "why is that stuck?", "what closed?", "what's next?", "how does this work?", "why did it do that?", "how does it prioritise?" and "what does this setting do, where is it set?" in Catalyst Cloud, or asks for something to be done rather than known. Reads the contract via catalyst CLI. Read-only: route work/decisions, never answer as the human.
5
5
  allowed-tools: Bash(catalyst:*) Bash(npx -p @catalyst-cloud/cli catalyst:*)
6
6
  ---
7
- <!-- vendored-from: @catalyst-cloud/catalyst-skills@0.16.28 — written in this repository for customer accounts -->
7
+ <!-- vendored-from: @catalyst-cloud/catalyst-skills@0.16.30 — written in this repository for customer accounts -->
8
8
 
9
9
  # What's happening
10
10
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Queues update within seconds. Dispatch sorts by priority, created time, identifier; mid-ladder tickets precede them by phases completed. Order never grants eligibility.
4
4
 
5
- An operator sets the repository concurrency cap, default 20, displayed in settings. Pause means zero, preserving the cap. Teams share capacity, including comment-wake.
5
+ An operator sets the repository concurrency cap, default 20, displayed in settings. Pause means zero, preserving the cap. Any member reads which repositories are paused, by whom, when and why with `catalyst repo status`; a workspace owner or admin pauses one with `catalyst repo pause <owner/name> --reason <why>` and resumes it with `catalyst repo resume <owner/name>`. Teams share capacity, including comment-wake.
6
6
 
7
7
  WIP limits starts per project, one Linear team across repositories: project setting, operator's account value, then 12; zero prevents starts. Members read `catalyst project wip-limit get --team <KEY>`; owners/admins use `set <n>` or set default. Only first phases are held; later phases continue. Count live tickets past dispatch or granted a first phase, including waits/blocks/parks; exclude never-started, backlog and local-lane. Idle at the limit means started tickets wait; use unstick, catalyst-github or what-needs-me.
8
8
 
@@ -25,7 +25,7 @@ Automatic waits, where no one acts: `retry_backoff`, `lease_held`, `intake_lease
25
25
  | `waiting_on` | the person, with their own login: unrepairable PR merge gate; read merge-wait comment for hold/review owed, using catalyst-github |
26
26
  | `externally_claimed` | the person, with their own login: outside worker owns it; worker/person removes local-lane label |
27
27
  | `environment_check_required` / `environment_check_failed` / `environment_check_expired` / `environment_check_hash_mismatch` | absent/failed/aged/changed environment check; a workspace owner or admin, in settings, runs or fixes it |
28
- | `repo_paused` | an operator resumes repository |
28
+ | `repo_paused` | the repository is paused; `catalyst repo status` says by whom, when and why; a workspace owner or admin, in settings or with `catalyst repo resume <owner/name>`, resumes it |
29
29
  | `scope_overlap` | the person, with their own login: declared files overlap running work; choose order or wait |
30
30
  | `human_owned_pr` | the person, with their own login: only its human owner closes, merges or hands it over; release refused |
31
31
  | `review_not_converging` | the person, with their own login: read findings through catalyst-github, comment; release refused |
@@ -4,7 +4,7 @@
4
4
  "inputs": {
5
5
  "packages/host-isolation/src/darwin-thoughts-producer.ts": "038fb63d8121fb1665ec31869f45604aedd96dd7d9b15a415d578fea9a0ad507",
6
6
  "packages/protocol/src/darwin-thoughts-custody.ts": "3515efc22b0a3cfb512ff1acaf649c6eafb978b894c724fabb01c325aea51075",
7
- "packages/host-isolation/src/darwin-thoughts-custody.ts": "8165e058f6bed990fe35ce30685db0f4634746c3b22d51f81a9c77cd9745735f",
7
+ "packages/host-isolation/src/darwin-thoughts-custody.ts": "305e5ddfa3786f6db6b55b9e62b07e28370fb59bf0cd3660011321225dfcba7e",
8
8
  "deploy/self-host/darwin-thoughts-custody/producer-entry.ts": "27c8ff591c8dc4d1a4c65dd154157df5191ead1fb0af673bfd7099d5226d37bc",
9
9
  "deploy/self-host/darwin-thoughts-custody/verifier-entry.ts": "80bc1e72943e43bc33d76ba205bd79751f58ca34d622e35f7e50e3b661f65464",
10
10
  "deploy/self-host/darwin-thoughts-custody/generate.ts": "bfe1bef175fa8243be0558e1ddee6ddbcfbd622922e3a5df850e8621f18e7b26",
@@ -13,6 +13,6 @@
13
13
  "deploy/self-host/darwin-thoughts-custody/service.plist.in": "66e9a2c175d2500b1f7130e7c04a5ed07f22bc7425661777f514fa3f2a816496"
14
14
  },
15
15
  "artifactSha256": "0e0f1bbdac23813e8ee57b6eb4ae3dfd24c3f1c51ebe0c3d119a1448734ea05e",
16
- "verifierSha256": "322b838917b9f7e1d9b7d9705a75143697ca093553bf0dcca7e7f5d4a88bbdc0",
16
+ "verifierSha256": "0229509c107ec7a509a7bdbb7fa19d21f06a3f9075e53f4890f6d316d518518b",
17
17
  "verifierDeclarationsSha256": "624428ced2eb18b045b761b49e20b7f52c0fc6c3132689571103ece7b4a1083f"
18
18
  }
@@ -457,7 +457,57 @@ function cleanPath(path) {
457
457
  throw failure("directory");
458
458
  }
459
459
  }
460
- function directory(path, privateChannel = false) {
460
+ var DARWIN_THOUGHTS_UNSAFE_DIRECTORY_SUBCHECKS = [
461
+ "not_directory",
462
+ "authority_changed",
463
+ "special_bits",
464
+ "group_other_write",
465
+ "owner_rwx",
466
+ "private_bits",
467
+ "private_owner",
468
+ "bootstrap_other_bits"
469
+ ];
470
+ var BOOTSTRAP_LEVELS = [
471
+ ["thoughts_root", "thoughts_tenant", "thoughts_owner", "thoughts_repository"],
472
+ ["locks_root", "locks_tenant"],
473
+ ["requests_root", "requests_tenant", "requests_owner", "requests_repository"],
474
+ ["responses_root", "responses_tenant", "responses_owner", "responses_repository"]
475
+ ];
476
+ var DARWIN_THOUGHTS_DIRECTORY_ROLES = [
477
+ "requests_channel",
478
+ "responses_channel",
479
+ "checkout",
480
+ "lock",
481
+ "git",
482
+ "thoughts_root_wait",
483
+ "locks_root_wait",
484
+ ...BOOTSTRAP_LEVELS.flat()
485
+ ];
486
+ function bootstrapRole(index, level) {
487
+ const role = BOOTSTRAP_LEVELS[index]?.[level];
488
+ if (!role)
489
+ throw failure("bootstrap_path");
490
+ return role;
491
+ }
492
+ function unsafeDirectory(role, subcheck) {
493
+ if (!DARWIN_THOUGHTS_DIRECTORY_ROLES.includes(role) || !DARWIN_THOUGHTS_UNSAFE_DIRECTORY_SUBCHECKS.includes(subcheck))
494
+ return failure("unsafe_directory");
495
+ return failure(`unsafe_directory:${role}:${subcheck}`);
496
+ }
497
+ function darwinThoughtsUnsafeDirectorySubcheck(stat, privateChannel) {
498
+ if ((stat.mode & 0o7000n) !== 0n)
499
+ return "special_bits";
500
+ if ((stat.mode & 0o022n) !== 0n)
501
+ return "group_other_write";
502
+ if ((stat.mode & 0o700n) !== 0o700n)
503
+ return "owner_rwx";
504
+ if (privateChannel && (stat.mode & 0o077n) !== 0n)
505
+ return "private_bits";
506
+ if (privateChannel && stat.uid !== 0n && stat.uid !== 10001n)
507
+ return "private_owner";
508
+ return;
509
+ }
510
+ function directory(path, role, privateChannel = false) {
461
511
  return guarded(() => {
462
512
  cleanPath(path);
463
513
  const named = fs.lstatSync(path, { bigint: true });
@@ -465,17 +515,21 @@ function directory(path, privateChannel = false) {
465
515
  try {
466
516
  const opened = fs.fstatSync(fd, { bigint: true });
467
517
  const after = fs.lstatSync(path, { bigint: true });
468
- if (!opened.isDirectory() || !sameDirectoryAuthority(named, opened) || !sameDirectoryAuthority(opened, after) || (opened.mode & 0o7022n) !== 0n || (opened.mode & 0o700n) !== 0o700n || privateChannel && ((opened.mode & 0o077n) !== 0n || opened.uid !== 0n && opened.uid !== 10001n)) {
469
- throw failure("unsafe_directory");
470
- }
518
+ if (!opened.isDirectory())
519
+ throw unsafeDirectory(role, "not_directory");
520
+ if (!sameDirectoryAuthority(named, opened) || !sameDirectoryAuthority(opened, after))
521
+ throw unsafeDirectory(role, "authority_changed");
522
+ const subcheck = darwinThoughtsUnsafeDirectorySubcheck(opened, privateChannel);
523
+ if (subcheck)
524
+ throw unsafeDirectory(role, subcheck);
471
525
  return opened;
472
526
  } finally {
473
527
  fs.closeSync(fd);
474
528
  }
475
529
  });
476
530
  }
477
- function currentIdentity(path, logicalPath) {
478
- const stat = directory(path);
531
+ function currentIdentity(path, logicalPath, role) {
532
+ const stat = directory(path, role);
479
533
  return {
480
534
  path: logicalPath,
481
535
  device: stat.dev.toString(),
@@ -534,7 +588,7 @@ function isInitialGuestOwnerProjection(before, current, stagedFile) {
534
588
  return before.dev === current.dev && before.ino === current.ino && before.mode === current.mode && before.uid === 0n && before.gid === 0n && current.uid === 10001n && current.gid === 10001n && process.getuid?.() === 10001 && process.geteuid?.() === 10001 && process.getgid?.() === 10001 && stagedFile.uid === 10001n && stagedFile.gid === 10001n;
535
589
  }
536
590
  function receiveStagingChannel(path, before, stagedFile, observedAncestors) {
537
- const current = directory(path, true);
591
+ const current = directory(path, "requests_channel", true);
538
592
  if (sameDirectoryAuthority(before, current))
539
593
  return current;
540
594
  if (!isInitialGuestOwnerProjection(before, current, stagedFile))
@@ -549,16 +603,20 @@ function receiveStagingChannel(path, before, stagedFile, observedAncestors) {
549
603
  function receiveWaitingResponseChannel(path, before, stagedFile, observedAncestors, responsePath, bootstrapRoots, authenticatePresentResponse, bootstrapProjection) {
550
604
  const maxPasses = bootstrapRoots ? 4 : 2;
551
605
  for (let pass = 0;pass < maxPasses; pass += 1) {
552
- const current = directory(path, true);
553
- const projections = [{ path, before, current, privateChannel: true }];
554
- for (const root of bootstrapRoots ? [bootstrapRoots.thoughtsRoot, bootstrapRoots.locksRoot] : []) {
606
+ const current = directory(path, "responses_channel", true);
607
+ const projections = [{ path, role: "responses_channel", before, current, privateChannel: true }];
608
+ for (const [root, role] of bootstrapRoots ? [
609
+ [bootstrapRoots.thoughtsRoot, "thoughts_root_wait"],
610
+ [bootstrapRoots.locksRoot, "locks_root_wait"]
611
+ ] : []) {
555
612
  const captured = observedAncestors.find((ancestor) => ancestor.path === root);
556
613
  if (!captured)
557
614
  throw failure("ancestor_identity");
558
615
  projections.push({
559
616
  path: root,
617
+ role,
560
618
  before: captured.stat,
561
- current: directory(root),
619
+ current: directory(root, role),
562
620
  privateChannel: false
563
621
  });
564
622
  }
@@ -589,7 +647,7 @@ function receiveWaitingResponseChannel(path, before, stagedFile, observedAncesto
589
647
  checkAncestors(observedAncestors.filter((ancestor) => !projections.some((projection) => projection.path === ancestor.path)), bootstrapProjection);
590
648
  let resample = false;
591
649
  for (const projection of projections) {
592
- const next = directory(projection.path, projection.privateChannel);
650
+ const next = directory(projection.path, projection.role, projection.privateChannel);
593
651
  if (sameDirectoryAuthority(projection.current, next))
594
652
  continue;
595
653
  if (!receiveProjection(projection.current, next, stagedFile))
@@ -660,9 +718,10 @@ function checkBootstrapDirectories(paths, allowMissing) {
660
718
  throw failure("bootstrap_path");
661
719
  let current = root;
662
720
  const components = ["", ...leaf.slice(root.length + 1).split("/")];
663
- for (const component of components) {
721
+ for (const [level, component] of components.entries()) {
664
722
  if (component)
665
723
  current = join(current, component);
724
+ const role = bootstrapRole(index, level);
666
725
  try {
667
726
  fs.lstatSync(current);
668
727
  } catch (error) {
@@ -670,11 +729,11 @@ function checkBootstrapDirectories(paths, allowMissing) {
670
729
  break;
671
730
  throw failure("bootstrap_directory", error);
672
731
  }
673
- const stat = directory(current, index >= 2);
732
+ const stat = directory(current, role, index >= 2);
674
733
  if (stat.uid !== 0n && stat.uid !== 10001n)
675
734
  throw failure("bootstrap_owner");
676
735
  if ((stat.mode & 0o007n) !== 0n)
677
- throw failure("unsafe_directory");
736
+ throw unsafeDirectory(role, "bootstrap_other_bits");
678
737
  }
679
738
  }
680
739
  }
@@ -695,21 +754,21 @@ async function exchange(options, bootstrap) {
695
754
  issuedAtMs,
696
755
  expiresAtMs: options.deadlineMs
697
756
  }));
698
- let requests = directory(options.requestDir, true);
699
- let responses = directory(options.responseDir, true);
757
+ let requests = directory(options.requestDir, "requests_channel", true);
758
+ let responses = directory(options.responseDir, "responses_channel", true);
700
759
  const creationPaths = bootstrap ? bootstrapPaths(authority, options.tenant, options.repository) : [];
701
760
  if (bootstrap)
702
761
  checkBootstrapDirectories(creationPaths, true);
703
762
  else {
704
- currentIdentity(options.checkoutPath, targets.checkoutSource);
705
- currentIdentity(options.lockPath, targets.lockSource);
763
+ currentIdentity(options.checkoutPath, targets.checkoutSource, "checkout");
764
+ currentIdentity(options.lockPath, targets.lockSource, "lock");
706
765
  }
707
766
  const gitPath = join(options.checkoutPath, ".git");
708
767
  if (options.gitPath !== undefined && options.gitPath !== gitPath)
709
768
  throw failure("git_path");
710
769
  const initialGitPresent = options.gitPath !== undefined || gitPresent(gitPath);
711
770
  if (initialGitPresent)
712
- currentIdentity(gitPath, join(targets.checkoutSource, ".git"));
771
+ currentIdentity(gitPath, join(targets.checkoutSource, ".git"), "git");
713
772
  const aliasAncestors = guarded(() => ancestors([
714
773
  options.requestDir,
715
774
  options.responseDir,
@@ -745,11 +804,11 @@ async function exchange(options, bootstrap) {
745
804
  authority,
746
805
  request,
747
806
  nowMs: now(),
748
- engineCheckout: currentIdentity(options.checkoutPath, targets.checkoutSource),
749
- engineLock: currentIdentity(options.lockPath, targets.lockSource)
807
+ engineCheckout: currentIdentity(options.checkoutPath, targets.checkoutSource, "checkout"),
808
+ engineLock: currentIdentity(options.lockPath, targets.lockSource, "lock")
750
809
  };
751
810
  if (gitPresent(gitPath))
752
- expectation.engineGit = currentIdentity(gitPath, join(targets.checkoutSource, ".git"));
811
+ expectation.engineGit = currentIdentity(gitPath, join(targets.checkoutSource, ".git"), "git");
753
812
  verifyDarwinThoughtsCustodyResponse(bytes, expectation);
754
813
  };
755
814
  const projection = () => {
@@ -789,7 +848,7 @@ async function exchange(options, bootstrap) {
789
848
  }
790
849
  requests = receiveStagingChannel(options.requestDir, requests, owned, aliasAncestors);
791
850
  checkAncestors(aliasAncestors);
792
- if (!sameDirectoryAuthority(requests, directory(options.requestDir, true)))
851
+ if (!sameDirectoryAuthority(requests, directory(options.requestDir, "requests_channel", true)))
793
852
  throw failure("channel_identity");
794
853
  try {
795
854
  fs.lstatSync(finalPath);
@@ -814,11 +873,11 @@ async function exchange(options, bootstrap) {
814
873
  throw failure("ancestor_identity");
815
874
  requests = receivedRequest.stat;
816
875
  }
817
- for (const [path, expected] of [
818
- [options.requestDir, requests],
819
- [options.responseDir, responses]
876
+ for (const [path, role, expected] of [
877
+ [options.requestDir, "requests_channel", requests],
878
+ [options.responseDir, "responses_channel", responses]
820
879
  ]) {
821
- const current = directory(path, true);
880
+ const current = directory(path, role, true);
822
881
  if (!sameDirectoryAuthority(current, expected))
823
882
  throw failure("channel_identity");
824
883
  }
@@ -841,11 +900,11 @@ async function exchange(options, bootstrap) {
841
900
  authority,
842
901
  request,
843
902
  nowMs: 0,
844
- engineCheckout: currentIdentity(options.checkoutPath, targets.checkoutSource),
845
- engineLock: currentIdentity(options.lockPath, targets.lockSource)
903
+ engineCheckout: currentIdentity(options.checkoutPath, targets.checkoutSource, "checkout"),
904
+ engineLock: currentIdentity(options.lockPath, targets.lockSource, "lock")
846
905
  };
847
906
  if (receivedGitPresent)
848
- expectation.engineGit = currentIdentity(gitPath, join(targets.checkoutSource, ".git"));
907
+ expectation.engineGit = currentIdentity(gitPath, join(targets.checkoutSource, ".git"), "git");
849
908
  checkAncestors(aliasAncestors, projection());
850
909
  checkAncestors(receivedGitAncestors, projection());
851
910
  expectation.nowMs = now();
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env python3
2
+ """Publish native filesystem headroom for a supervisor inside a VM."""
3
+ import argparse
4
+ import json
5
+ import os
6
+ from pathlib import Path
7
+ import sys
8
+ import tempfile
9
+ import time
10
+
11
+
12
+ def publish(path: Path, output: Path) -> dict:
13
+ filesystem = os.statvfs(path)
14
+ sample = {
15
+ "schemaVersion": 1,
16
+ "path": str(path.resolve(strict=True)),
17
+ "observedAtMs": time.time_ns() // 1_000_000,
18
+ "availableBytes": filesystem.f_bavail * filesystem.f_frsize,
19
+ "totalBytes": filesystem.f_blocks * filesystem.f_frsize,
20
+ }
21
+ output.parent.mkdir(parents=True, exist_ok=True)
22
+ temporary = None
23
+ try:
24
+ with tempfile.NamedTemporaryFile(mode="w", dir=output.parent, delete=False) as stream:
25
+ temporary = Path(stream.name)
26
+ json.dump(sample, stream)
27
+ stream.write("\n")
28
+ stream.flush()
29
+ os.fsync(stream.fileno())
30
+ os.fchmod(stream.fileno(), 0o644)
31
+ os.replace(temporary, output)
32
+ temporary = None
33
+ finally:
34
+ if temporary is not None:
35
+ temporary.unlink(missing_ok=True)
36
+ return sample
37
+
38
+
39
+ if __name__ == "__main__":
40
+ parser = argparse.ArgumentParser(description=__doc__)
41
+ parser.add_argument("--path", required=True, type=Path, help="Native filesystem backing the VM disk")
42
+ parser.add_argument("--output", required=True, type=Path, help="Sample in a read-only supervisor bind")
43
+ parser.add_argument("--interval", type=float, help="Publish every INTERVAL seconds until stopped")
44
+ args = parser.parse_args()
45
+ if args.interval is None:
46
+ publish(args.path, args.output)
47
+ sys.exit(0)
48
+ if args.interval <= 0:
49
+ parser.error("--interval must be positive")
50
+ # launchd keeps this loop alive instead of firing a timer: an agent bootstrapped over SSH can
51
+ # leave every StartInterval launch pended (CTC-5929), and the supervisor then refuses all work.
52
+ while True:
53
+ try:
54
+ publish(args.path, args.output)
55
+ except OSError as error:
56
+ print(f"host-disk sample failed: {error}", file=sys.stderr, flush=True)
57
+ time.sleep(args.interval)
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>Label</key><string>dev.catalystcloud.host-disk</string>
6
+ <key>ProgramArguments</key>
7
+ <array>
8
+ <string>__PYTHON__</string>
9
+ <string>__SCRIPT__</string>
10
+ <string>--path</string><string>__PATH__</string>
11
+ <string>--output</string><string>__OUTPUT__</string>
12
+ <string>--interval</string><string>10</string>
13
+ </array>
14
+ <key>RunAtLoad</key><true/>
15
+ <key>KeepAlive</key><true/>
16
+ <key>ThrottleInterval</key><integer>10</integer>
17
+ </dict>
18
+ </plist>