Repository navigation
feat(native): repair the hack.local DNS route to the native relay - #316
Merged
Merged
Conversation
…mands A warm, image-only, unrouted `up` or `restart` with no hooks now runs four directory-xattr storage proofs instead of six. Each proof is three fresh helper containers. - The warm enrollment tail (no new volume) reuses the effect-entry proof of the same generation under the same lease. It uses the existing adjacentProof record, which needs a byte-identical material binding, so any receipt write in between forces a full proof. - Finalization skips the second proof pass when there is no route, after hook, or new or saved file material. In that case the completion step only reads. Proof reuse stays within one command and one lease. Nothing is persisted, so every command still opens with a full proof. Each performed verification proof now emits a passive `storage.proof` phase-trace span. The hosted native-config-compose scenario uses it to assert four proofs on each of two consecutive warm ups. Refs: HACK-1123 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sed file The HACK-1211 experiment produced two iterations per Bun version: one focused pass and one full `bun test` that started on a 600 s estimate and overran the 30-minute budget, because the full suite takes 30-35 minutes on hosted macOS. - Never start an iteration whose estimate exceeds the remaining budget. The estimate is a conservative prior (focused 120 s, full 2400 s) until a run completes, then the longest completed run times 1.2. A command that does not fit is recorded once in summary.json `skippedForBudget` and leaves the rotation. Deadline stops remain a safety net (`overrun`). - Add `--mode=focused|full|alternate` (default focused: only tests/native-https-owner.test.ts) and `--role=baseline|candidate`. - The workflow gains a validated `mode` dispatch input; the label-triggered matched pair uses focused with baseline/candidate roles. Full mode needs a budget of at least 40 minutes. The job timeout stays budget + 15. - summary.json gains per-command counts (iterations, passes, crashes, other failures, overruns, skipped-for-budget) and a one-line verdict such as "baseline 0/97 focused crashes". - The shared classifier also treats exit 134 (SIGABRT) and 138 (SIGBUS) as crash exits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Native `up` emitted a `--ready` goal for every compose service, including
services in profiles that were not selected. The runtime does not schedule
inactive services and refuses readiness for them ("Readiness includes
inactive or unknown services."), so any project with an unused profile
failed with graph_readiness.
Build readiness goals only for services the reviewed plan marks active,
and ignore dependency edges declared by inactive services so they cannot
raise an active service's goal. The runtime refusal stays as a guard; a
contract test now proves it still rejects inactive and unknown services.
Bridge pool capacity keeps counting inactive routed services: it is sized
before the profile-aware review and must remain an upper bound.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On macOS, print one closed hint line on stderr when a command opens or prints a browser URL or dev host ending in .local (hack open, hack branch open, hack status/projects, and Doctor's browser check). Browsers other than Safari need the macOS Local Network permission once for .local names (Apple TN3179), even when Hack's resolver answers with loopback. The hint is shown at most once per command, never on other platforms, never for non-.local hosts, and never inside --json payloads. Hack does not read or change the permission. Document the name-based rule, the Safari exemption and the alternatives (OAuth alias, or a custom suffix under hack.gy) in the macOS browser guide, and link it from the init and native domain docs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Under the native backend on macOS, `hack doctor` reports a `native hack.local route` check (JSON `hackLocalRoute`) and `hack doctor --fix` proposes and, after confirmation plus the native administrator prompt, rewrites only the Hack-managed `address=/.hack.local/<old>` dnsmasq line to 127.0.0.1 in place. It creates /etc/resolver/hack.local with `nameserver 127.0.0.1` only when missing. Preconditions are closed refusal reasons: verified relay owner listening on 127.0.0.1, a single exact managed line, a Hack-written target, a dead old target (bounded :443 probe), a Hack-owned resolver, no pending receipt, and unchanged inputs across authorization. A private receipt (old/new line, whole-file hashes, timestamps) is published before effects; failures restore the earlier line. Rollback via `hack global dns deactivate --domain hack.local` restores the exact earlier bytes, verifies the hash and recovers interrupted repairs. `hack global dns preview|activate|deactivate` without --domain no longer targets a built-in default; it stops with a usage message naming `hack doctor --fix` and the rollback command. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Rollback of a receipt whose dnsmasq.conf changed (or names another path) no longer refuses forever: after a plain confirmation it marks the receipt released and writes nothing else, so a pending receipt can always be cleared. - Keep a leading BOM when reading DNS files, so rewrites keep every byte and receipt hashes equal the raw file hashes. - Hold an exclusive lock for repair and rollback; refuse with busy. - Repair refuses with restart-unavailable before any effect; rollback restores the file even when dnsmasq cannot be restarted and says so. Automatic cleanup restarts only when something changed and reports "nothing was changed" when the failure came first. - Accept only the managed single-line form for a receipt's old line, and control-free absolute paths; diagnostics name lines by number and replace control characters. - Cover the rollback non-interactive, recheck, restore, path, lock, file owner/link and private-directory guards with focused tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…k.local repair The hack.local repair now refuses with closed reasons instead of acting on DNS data it never inspected or throwing raw read errors: - uninspected-config-source: dnsmasq.conf or a dnsmasq.d include loads conf-file, conf-script, addn-hosts, hostsdir, servers-file, or a conf-dir other than <brew>/etc/dnsmasq.d,*.conf. The scan is shared with the scoped DNS plan (findUninspectedDnsmasqSource), which now also refuses servers-file and conf-script. - unreadable-config: a DNS file is a symlink (O_NOFOLLOW), invalid UTF-8, linked or oversized. Inspection and rollback refuse without echoing the read error or file content. Adds tests for the conf-file repro, every source directive, unreadable main and include files, rollback of an unreadable file, and the three defense-in-depth guards: the post-write hash recheck in restore, replaceManagedLine with zero or two matches, and the null resolver identity guard before removal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Only `hack open --json` exercised the hint, so dropping it from the human open path, branch open, projects/status or either doctor path left tests green. Run `hack open`, `hack branch open`, `hack projects` and `hack status` from source with process.platform preloaded as darwin, stub `open` and `docker` on a hermetic PATH, and an isolated HOME/state, asserting one hint for a .local dev host and none for a non-.local host. Doctor probes Docker, resolvers, the keychain and /usr/bin/curl, so its compose and native tails now share `reportDoctorResults` with an injectable hint, and each path's targets come from exported builders that are tested directly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add a source CLI regression for a first up with new file material and no saved file material: finalization keeps its completion step, the second finalize pass, and the post-completion file-mount readiness check. The test fails when the retirement condition keeps only the saved-files arm. Native-compose CLI harnesses now give the child a private HOME under the fixture root instead of the contributor's HOME. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Conflicted files: none. The plain merge applied cleanly; no generated files needed hand resolution, and the generation and reference tests pass on the merged tree. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Conflicted files: none. The plain merge resolved automatically. This PR's change set (native readiness goals, the bridge capacity comment and the project_contract.rs guard test) does not overlap witness reuse or merge train 2. Regenerated plugins and docs/reference/cli.md were byte-equal to the merged tree. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-hint-b11 Conflicted files: none. The merge applied cleanly; src/commands/doctor.ts and src/commands/project.ts auto-merged with both sides' changes kept. Regenerated surfaces (generate:agent-plugins, docs:cli-reference) produced no further changes. src/agents/integration-revision.ts, src/agents/integration-ownership.ts and the checked-in renders match the predecessor branch, and their tests pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…pair-b11 Conflicted files: none. Git auto-merged docs/guides/init-project.md, docs/guides/native-candidate.md and src/commands/doctor.ts, keeping both sides' content. Regenerated plugins (generate:agent-plugins) and docs/reference/cli.md (docs:cli-reference); both produced no further changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Re-parents onto next after the previous stacked PR squashed in; next's tree equals d0c8884, which this branch already contains, so the branch tree is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Found 1 test failure on Blacksmith runners: Failure
|
roodboi
added a commit
that referenced
this pull request
Oct 13, 2026
## Problem On a real macOS desktop Terminal, the native candidate built from `next` at 63b614f ran `hack-v5 doctor --fix`. It showed the hack.local repair confirmation (#316), and the user answered yes. The output then printed `sudo: a password is required` without ever showing a password prompt. The repair then reported `Repair refused (declined): The hack.local repair was not authorized; nothing changed.` ## Root cause - **The spinner erased the prompt.** `handleNativeDoctor` starts one clack spinner ("Checking the active native HTTPS root...") and keeps it running through every check, including the `--fix` repairs. The spinner redraws every 80 ms with `ESC[1G ESC[J` (go to column 1, erase to the end of the screen). sudo's `Password:` prompt was erased within one frame. I reproduced this in a pseudo-terminal with a fake `sudo` on `PATH`: the transcript shows `Password:` followed at once by `ESC[1G ESC[J` and a new spinner frame. - **Process groups were not the cause.** `runWithTerminalGroup` correctly made the sudo child the terminal's foreground process group: in the reproduction, `tpgid == pgid` for the sudo child. - **No `sudo -n` ran before the prompt.** Every `sudo -n` step in the repair (resolver script, launchctl kickstart, cache flush) runs only after `authorize` succeeds, and its stderr is captured to files. - **Where the message came from.** In sudo 1.9.17p2 (the version on m3), `log_auth_failure` prints `a password is required` for any authentication failure without `FLAG_BAD_PASSWORD`. That includes a first password read that was interrupted or timed out (`AUTH_INTR` with `ntries == 0`). So the user, seeing only a spinner, was left at an invisible prompt until the 120 s `run` timeout (or an interrupt) cancelled it. sudo then printed that line. - **Why it said "declined".** `authorize` returned `false` for any non-zero `sudo -v` exit, and the repair mapped `false` to `declined`. ## Fix - `src/lib/terminal-handoff.ts`: `pausableSpinner` and `withTerminalHandoff`. A repair claims the terminal at its first prompt. The spinner is erased and stays off through the administrator prompt and every later `sudo -n` step, then resumes once (also on throw). Doctor uses this for both the hack.local repair and the native CA repair (extracted as `repairNativeCaTrustCheck`). Repairs were already run one at a time; no doctor step runs at the same time as a repair. - `src/lib/admin-authorization.ts`: one shared `sudo -v` helper for the hack.local repair/rollback, the native CA repair and native `global dns activate/deactivate`. It refuses before running sudo when Hack is not the terminal's foreground job. It classifies a failure as `timed-out`, `interrupted` or `rejected` and never uses `-n`. - The hack.local `authorize` dependency now returns `approved | declined | authorization- failed`. A new closed refusal, `authorization-failed`, names the cause and suggests `Run "sudo -v" in this terminal first, then rerun: …`. Only answering no is `declined`. The CA repair and DNS activation throw errors that name the cause and include the same hint, instead of "was not completed" or "was denied". - `docs/guides/native-candidate.md`: documents that the spinner pauses, the new refusal reason, and the sudo message. ## Validation - Focused suites, `tests/integration-ownership.test.ts`, the native DNS activate/deactivate/host suites, `global-command.macos`, `doctor-command` and `prerelease-plan`: 229 pass, 2 skip, 0 fail. - `bun run --cwd packages/cli typecheck`: clean. `bun run --cwd packages/cli check`: 0 errors. Its 34 warnings are all in files this PR does not touch; the changed files have no diagnostics. - Tests inject runners, terminal-foreground state and spinners. They never run real sudo or osascript, and never touch system files or the keychain. They cover: - the spinner is paused before the prompt and resumed after; - the prompt runs before every privileged `sudo -n` step; - a failed `sudo -v` is `authorization-failed`, not `declined`; - a no at the confirmation never reaches sudo; - a non-interactive run declines without prompting or pausing; - a background run refuses before sudo. - Mutation check: I made 13 targeted changes that each break the fix (skip the handoff in either repair, map a failure to `declined`, prompt for sudo before confirming, drop the foreground check, pass `-n`, misclassify a timeout, never resume the spinner, prepare the restart before authorizing, install after a failed prompt). The tests caught all 13. - Manual check in a pseudo-terminal with a fake `sudo` (not real sudo): before the fix, the spinner wiped `Password:`. After the fix, `Password:` stays visible and the spinner resumes only after sudo exits. ## Remaining gaps - Not yet run against real sudo in a desktop Terminal. Rebuild the candidate from this branch and run `doctor --fix` on m3 to confirm the real prompt (or Touch ID sheet, since `pam_tid` is enabled there) is visible and the repair completes. - Draft only; not merged or released. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Product decision (2026-10-12): keep
hack.localas the default dev-host root. Under the native backend, the HTTPS relay listens on 127.0.0.1, but a Docker-era install routes.hack.localto Docker Caddy (address=/.hack.local/172.30.0.2). This adds an authorized, reversible native repair.hack doctoron macOS adds anative hack.local routecheck.--jsoncarries ahackLocalRouteobject (status, closed reason, old/new line, resolver action, relay port, receipt state, next command). Details name lines by number. They never repeat file contents, and control characters are replaced.hack doctor --fix): rewrites only the single Hack-managedaddress=/.hack.local/<old>line to127.0.0.1in place. It never adds a second line..hack,.hack.gyand every other byte stay the same, including a leading UTF-8 BOM. It creates/etc/resolver/hack.local(nameserver 127.0.0.1) only when the file is missing.relay-not-verified: the relay owner must be verified viainspectActiveNativeHttpsOwner, and its receipted port must accept a TCP connection on 127.0.0.1.no-managed-line,unmanaged-line: exactly one exact-format line must exist, with no include-dir or subdomain claims.foreign-target: the target must be one Hack wrote (172.30.0.2 or ::1).old-target-live: the old target must not answer on :443 within 1.5 s.foreign-resolverpending-receipt,invalid-receiptnon-interactive: this refusal nameshack doctor --fix.declinedbusy: another repair or rollback holds the lock.restart-unavailable: the dnsmasq launchd job cannot be restarted safely. This is checked after the prompt and before any effect.inputs-changed: everything is inspected again after the prompt.confirmSafeplussudo -vfor the macOS prompt, then boundedsudo -nsteps throughrunNativeDnsAttachedCommand. The resolver is created with the existing privileged resolver script, which is now exported asrunPrivilegedResolverOperation. dnsmasq restarts through the verified launchd job (prepareNativeDnsLaunchdRestart), then the DNS cache is flushed and live DNS is verified with dig and dscacheutil. Hack never handles a password.<native-home>/native-dns/hack-local-route.json(0600, in a 0700 directory owned by the user). It records the old and new line, the SHA-256 of the exact file bytes before and after, the resolver action and identity, and timestamps. It is published aspendingbefore any effect and becomesappliedafter live verification. Its old line must be one of the managed single-line forms, and its paths must be absolute and free of control characters. Repair and rollback hold an exclusive lock (hack-local-route.json.lock, published withlink(); a lock whose holder pid no longer exists is taken over once).rolled-back. It never overwrites a concurrent edit: that case keeps the receiptpending.hack global dns deactivate --domain hack.localneeds a terminal (non-interactiveotherwise, naming the command). It restores the exact earlier line and verifies the whole-file hash. It removes the resolver only if the repair created it and its identity still matches, then restarts dnsmasq. If dnsmasq is not running or the job is ambiguous, it still restores the file and says that dnsmasq was not restarted. A receipt whose line does not reproduce its own hashes refuses withinvalid-receiptand is never written.dnsmasq.confchanged after the repair (for example a Docker-erahack doctor --fixrewrote the roots), or the receipt names another path. The rollback command then never writes the file. After a plain confirmation (no administrator prompt) it marks the receiptreleasedand leavesdnsmasq.confand any resolver as they are. That clears apendingreceipt, and Doctor inspects the current file again.hack global dns preview|activate|deactivatewith no--domainresolved tohack.local, which the planner always refuses. Now a built-in default gives a closedCliUsageErrorthat names--domain <custom>,hack doctor --fixand the rollback command. A configured customdefault_domainstill works as documented.preview --domain hack.localshows the repair proposal without changing anything.activate --domain hack.localpoints tohack doctor --fix.docs/guides/native-candidate.mdanddocs/guides/init-project.mdare updated, including the recovery path for a drifted receipt and a note that a non-443HACK_NATIVE_HTTPS_PORTstill needs the port in*.hack.localURLs.docs/reference/cli.mdis regenerated (summary changes only; no change in this rework).Rework after verification (head 81a8720)
This rework addresses each verifier finding on efb278e:
readStableNativeDnsFilenow decodes withignoreBOM: true, so strings round-trip to the exact bytes. Receipt hashes equal the raw file hashes, and rollback restores identical bytes (checked withBuffer.compare).unmanaged-lineandforeign-targetdetails no longer repeat the line or the target. Every human message and doctor message goes throughprintable().restart-unavailable, and rollback reports a skipped restart instead of throwing. A pre-write failure no longer reports "automatic restore failed".dev:ino.next(3c7cf39). The only conflict was an additive one indoctor.ts(envKeyandhackLocalRoutefields), and both were kept.Validation
All on the pushed head 81a8720 (merged with
next):tests/native-hack-local-route.test.ts(34 tests) injects file roots in a temp directory and a fake privileged runner. The runner refuses paths outside the temp resolver directory and assertssudo -n. Relay, probe, restart, flush and verify are also fakes. Owner checks use an injectedownerUidseam. In addition to the earlier coverage, the tests cover:currentnon-interactiveanddeclinedrestart-unavailable, and rollback with no restartbusylock and takeover of a stale lockdnsmasq.conftests/native-hack-local-route.test.ts,tests/native-hack-local-route-cli.test.tsandtests/native-ca-doctor-cli.test.ts: 40 pass.tests/integration-ownership.test.tsandtests/agent-plugin-generation.test.ts: 25 pass.bun run --cwd packages/cli typecheck: exit 0.bun run --cwd packages/cli check: exit 0 with 34 warnings, none in changed files. An explicit biome check of the 8 changed TS files reports no diagnostics.bun run docs:cli-referenceproduces no diff. No consumer guidance changed, so no plugin regeneration was needed.Gaps
/etc/resolvermust already exist for resolver creation. The privileged script does not create the directory. Machines with a prior v4 install already have it.hack doctor --fixorhack global installstill rewrites all three roots to whichever target answers, which can undo the native repair. This is documented, and the receipt can now be released afterwards.hack doctor --fixwithout--browser-urlstill reports the existing CA-repair error. The DNS repair runs independently.🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.