@indigoai-us/hq-cli 5.345.241 → 5.345.242

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 (116) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/assets/scaffold/core/scripts/hq-delegate-grant.sh +170 -8
  3. package/assets/scaffold/core/scripts/hq-delegate-publish.sh +21 -1
  4. package/assets/scaffold/core/scripts/lib/delegate-engine.sh +77 -0
  5. package/dist/command-catalog.generated.d.ts +28 -8
  6. package/dist/command-catalog.generated.js +33 -8
  7. package/dist/commands/cloud-off-gate.d.ts +7 -7
  8. package/dist/commands/cloud-off-gate.js +26 -38
  9. package/dist/commands/core-delegate-w1b.js +307 -26
  10. package/dist/commands/core-delegate.js +2 -0
  11. package/dist/commands/core-handoff.js +1 -1
  12. package/dist/commands/core-job-model-auth.d.ts +95 -0
  13. package/dist/commands/core-job-model-auth.js +247 -0
  14. package/dist/commands/core-job-run-native.js +280 -12
  15. package/dist/commands/core.js +1 -0
  16. package/dist/commands/files-browse.js +2 -0
  17. package/dist/commands/files.js +4 -0
  18. package/dist/commands/integrations-core.d.ts +11 -0
  19. package/dist/commands/integrations-core.js +15 -1
  20. package/dist/commands/lanes-link.js +2 -2
  21. package/dist/commands/lanes-loop.d.ts +2 -2
  22. package/dist/commands/lanes-loop.js +5 -5
  23. package/dist/commands/lanes-questions.js +1 -1
  24. package/dist/commands/lanes-stories.js +1 -1
  25. package/dist/commands/lanes.js +80 -14
  26. package/dist/commands/rescue.d.ts +3 -2
  27. package/dist/commands/rescue.js +48 -34
  28. package/dist/commands/search.d.ts +6 -0
  29. package/dist/commands/search.js +24 -4
  30. package/dist/commands/sources.js +6 -2
  31. package/dist/commands/sync-core.d.ts +8 -0
  32. package/dist/commands/sync-core.js +43 -0
  33. package/dist/hq-cloud-sync-runner/bin/sync-runner.js +1737 -1450
  34. package/dist/hq-cloud-sync-runner/package.json +1 -1
  35. package/dist/lib/capacity/accounts.d.ts +1 -1
  36. package/dist/lib/capacity/accounts.js +1 -1
  37. package/dist/lib/capacity/freshness.d.ts +1 -1
  38. package/dist/lib/capacity/freshness.js +1 -1
  39. package/dist/lib/capacity/route.js +1 -1
  40. package/dist/lib/daemon/catalog.d.ts +3 -0
  41. package/dist/lib/daemon/hook-requests.d.ts +1 -1
  42. package/dist/lib/daemon/hook-requests.js +4 -2
  43. package/dist/lib/daemon/run.js +16 -22
  44. package/dist/lib/environment/work-requirements.d.ts +1 -1
  45. package/dist/lib/environment/work-requirements.js +1 -1
  46. package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
  47. package/dist/lib/flag-registry-worker-source.generated.js +1 -1
  48. package/dist/lib/hook-engine/coverage.js +11 -3
  49. package/dist/lib/hook-engine/git-stop-config.json +510 -510
  50. package/dist/lib/hook-engine/native-precompact-compatibility.json +443 -443
  51. package/dist/lib/hook-engine/native-stop-compatibility.json +359 -359
  52. package/dist/lib/hot-channels/adapters/meetings.d.ts +1 -16
  53. package/dist/lib/hot-channels/adapters/meetings.js +3 -28
  54. package/dist/lib/hot-channels/adapters/slack.d.ts +3 -1
  55. package/dist/lib/hot-channels/adapters/slack.js +4 -1
  56. package/dist/lib/hot-channels/contract.d.ts +14 -0
  57. package/dist/lib/hot-channels/fleet-complete.d.ts +18 -2
  58. package/dist/lib/hot-channels/fleet-complete.js +29 -4
  59. package/dist/lib/hot-channels/meeting-source-ref.d.ts +17 -0
  60. package/dist/lib/hot-channels/meeting-source-ref.js +32 -0
  61. package/dist/lib/hot-channels/prompts/signals-pass.md +6 -1
  62. package/dist/lib/hot-channels/run.d.ts +10 -0
  63. package/dist/lib/hot-channels/run.js +34 -0
  64. package/dist/lib/hot-channels/signals-pass.d.ts +27 -0
  65. package/dist/lib/hot-channels/signals-pass.js +57 -2
  66. package/dist/lib/hot-channels/signals-runtime.js +3 -2
  67. package/dist/lib/lanes/accounts.js +2 -2
  68. package/dist/lib/lanes/claude-balance.d.ts +6 -0
  69. package/dist/lib/lanes/claude-balance.js +124 -0
  70. package/dist/lib/lanes/grants.js +15 -2
  71. package/dist/lib/lanes/hq-root.d.ts +1 -1
  72. package/dist/lib/lanes/hq-root.js +1 -1
  73. package/dist/lib/lanes/links.d.ts +1 -1
  74. package/dist/lib/lanes/liveness.d.ts +3 -0
  75. package/dist/lib/lanes/liveness.js +61 -7
  76. package/dist/lib/lanes/models.d.ts +1 -1
  77. package/dist/lib/lanes/models.js +1 -1
  78. package/dist/lib/lanes/questions.d.ts +1 -1
  79. package/dist/lib/lanes/questions.js +2 -2
  80. package/dist/lib/lanes/spawn.js +4 -6
  81. package/dist/lib/lanes/store.d.ts +13 -2
  82. package/dist/lib/lanes/store.js +13 -5
  83. package/dist/lib/lanes/types.d.ts +7 -7
  84. package/dist/lib/lanes/types.js +1 -1
  85. package/dist/lib/lanes/watcher-main.js +1 -1
  86. package/dist/lib/lanes/watcher.d.ts +1 -1
  87. package/dist/lib/lanes/watcher.js +1 -1
  88. package/dist/lib/onboarding/cli/onboard.js +5 -0
  89. package/dist/lib/signals/sanitize.d.ts +19 -0
  90. package/dist/lib/signals/sanitize.js +103 -7
  91. package/dist/lib/signals/steps/upload.d.ts +40 -1
  92. package/dist/lib/signals/steps/upload.js +122 -6
  93. package/dist/lib/sync-core/access-refresh.d.ts +29 -0
  94. package/dist/lib/sync-core/access-refresh.js +97 -0
  95. package/dist/lib/sync-core/company-adoption.d.ts +33 -0
  96. package/dist/lib/sync-core/company-adoption.js +223 -0
  97. package/dist/lib/sync-core/engine-home.d.ts +1 -0
  98. package/dist/lib/sync-core/engine-owned.d.ts +13 -0
  99. package/dist/lib/sync-core/engine-owned.js +38 -0
  100. package/dist/lib/sync-core/hand-back.d.ts +17 -0
  101. package/dist/lib/sync-core/hand-back.js +23 -0
  102. package/dist/lib/sync-core/post-apply-reindex.d.ts +33 -0
  103. package/dist/lib/sync-core/post-apply-reindex.js +149 -0
  104. package/dist/lib/sync-core/reconcile.d.ts +10 -0
  105. package/dist/lib/sync-core/reconcile.js +117 -12
  106. package/dist/lib/sync-core/rollout-state.d.ts +2 -0
  107. package/dist/lib/sync-core/rollout-state.js +6 -0
  108. package/dist/lib/vault-sync-switches.d.ts +14 -0
  109. package/dist/lib/vault-sync-switches.js +22 -0
  110. package/dist/lib/workers-registry/index.d.ts +1 -1
  111. package/dist/lib/workers-registry/index.js +1 -1
  112. package/dist/utils/github-tag-fallback.d.ts +16 -0
  113. package/dist/utils/github-tag-fallback.js +126 -0
  114. package/dist/utils/version-report.d.ts +2 -1
  115. package/dist/utils/version-report.js +40 -27
  116. package/package.json +8 -8
package/CHANGELOG.md CHANGED
@@ -2,6 +2,55 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [5.345.242] — 2026-11-20
6
+
7
+ - `hq lanes list` no longer reads `~/.hq/work-mesh/spool.jsonl` as one string. An 800 MB spool used to crash with Node's string-length limit; the liveness index now scans the file in 64 KiB chunks.
8
+
9
+ - Fixed (host canary, Codex): `scripts/host-canary.mjs` judges a normal Codex run on the record that answered each event. Inside an HQ root, the tracked `.codex/config.toml` adapter now stands aside for an event the new core marked answered (hq-core-staging `hq-codex-hook-adapter.sh`, hq-hook `host::answered`). So for an event reindex registered to the new core (`native` or `native+shell`), the allow, deny and token evidence now also comes from the new core's record. Before, only config.toml records counted, so the token and the injector parity checks could never both pass while both hooks shared one session ledger (US-021 c4, T5 note 422). Shell-path hooks.json records still never count, and the bash injector replay still judges the injected content.
10
+ - Internal: The credential guard corpus parity check runs as four tests side by side. Each compares every fourth payload, so together they still compare every payload.
11
+ - Fixed (delegate): in transfer mode, `hq core delegate grant` and the bundled `hq-delegate-grant.sh` now also grant the narrower ACL rules under the project that carry no grants. hq-pro's ACL tree lists those only in `masking`, not in `children`, yet each one still overrides the project grant for the keys it covers, so the recipient had no access there while the manifest said "granted". Exact-path and private-folder rules under the project are granted too. A rule the recipient already holds at the same or a higher permission is left alone, and a truncated `masking` list stops the grant instead of leaving rules unchecked.
12
+ - Fixed (delegate): the bundled `hq-delegate-grant.sh` (the fallback when the native delegate route is off) is byte-identical to hq-core-staging main again, with its new `lib/delegate-engine.sh` bundled beside it. Native `hq core delegate grant` gains the same three behaviors. A `prs_` recipient is mapped to its one email through `hq people list` and shared to that email, and the run stops if that email resolves to another person. Where the sync engine owns the company vault, the project and referenced files are pinned in `.hq/pins.json` and the grant waits for the engine's upload instead of running `hq sync push`. The full-folder push is skipped when the vault's dossier files already match, and after a full push the dossier files are pushed again with `--on-conflict overwrite`. Tests run the bundled helper's masking-rule transfer path and each new behavior side by side with native.
13
+ - Fixed (delegate): `hq core delegate publish` no longer runs `hq sync push` (the old uploader) on a company vault the new sync engine owns on this machine. It waits for the engine to upload each published file and checks its sha256 with `hq files cat` (180 s per file, `HQ_DELEGATE_ENGINE_WAIT_SECONDS`), and stops with a message naming the file that did not arrive, the wait it used, and the likely causes (an ignore rule, a symlink, or a path this machine is not granted). On a vault the old sync owns it still pushes, now only the delegation folder and the dossier files instead of the whole project folder. Publish and grant now use the same ownership rule as the sync gate, so a vault the rollout holds keeps the push path, and a failed `hq files cat` no longer counts as an upload of an empty file.
14
+ - Fixed (sync-core): a machine with a `.hqinclude` allowlist at the HQ root keeps every vault on the current sync (held, reason `hqinclude-unsupported`), because the new sync engine does not support the allowlist and would upload everything in scope.
15
+ - Changed (scaffold): the bundled `hq-delegate-grant.sh`, `hq-delegate-publish.sh` and `lib/delegate-engine.sh` are recorded as byte-identical to hq-core-staging again, pinned at the commit where staging took the held-vault and failed-read fixes (hq-core-staging#2070). The script bytes do not change.
16
+ - Tests (delegate): the Windows delegate parity tests pass again. The malformed-ACL grant test expects the `hq sync-core status --json` check that grant gained in this release (10 hq calls, 21 jq calls), and the publish parity tests compare the published manifest's checksum the way the brainstorm publish tests already do: the shell's recorded checksum must match the CRLF file jq.exe wrote, and that file must equal native's LF file once line endings are normalized. The pickup access-refresh test also sets `USERPROFILE`, which is what `os.homedir()` reads on Windows.
17
+ - Internal: The native env-file guard accepts the fixed hq-core guard script (awk reads all content, so the shell guard can no longer exit 141 on SIGPIPE) as well as the released one. Its parity tests now compare against the fixed script.
18
+ - Scheduled jobs on an Outpost report a dead Claude or Codex sign-in once, skip the per-job direct message only after the backend confirms that episode, and run again on the next schedule after that sign-in is renewed. The report opens on that CLI's own sign-in text, or when its credential file is missing. A passed expiry date does not open one. A hold whose credential still reads healthy runs again about an hour later.
19
+ - Fixed (jobs): on an Outpost, a scheduled job whose Claude or Codex credential file is missing no longer writes a sign-in hold unless the backend confirms an episode. Until then each scheduled run keeps today's behavior: it records the run status, runs remediation, sends the per-job direct message and reports the sign-in failure again. `hq core job run --help` now says the per-job direct message is skipped only after a confirmed episode.
20
+ - hq-hook and native stop pull requests move to GitHub-hosted runners when a busy Mac has no load reading, when the route job is cancelled or skipped, or when the Mac queue runs past the pages the route job reads.
21
+ - Fixed an intermittent test failure in the `hq doctor --fix` journal pull tests. The test that stops a background pull at its time limit now waits for the pull to finish exiting before it reads the result, so it no longer fails on slow CI runners. Test-only change; no behavior change for users.
22
+ - Isolate flag snapshot caches before test workers start so tests cannot change the operator's HQ Anywhere fallback setting. Reset fallback state between tests and detect machine fallback changes during each shard.
23
+ - Fixed (sync): a vault whose sync you had turned off in Settings > Sync before it moved to the new sync engine stays off when the vault returns to the current sync, both when the rollout moves it back and when the daemon falls back to the current sync because the installed engine is too old for full sync. Both paths used to turn the switch on for every vault, so a company or personal vault you had turned off started syncing again. Vaults that HQ itself turned off for the move are turned back on as before. If you turn a vault's switch on while the new engine has it, HQ now remembers that and turns the vault back on when it returns. If the settings file cannot be read when a vault moves, HQ leaves that vault off when it returns.
24
+ - Fixed (sync): a vault returning from the new sync engine goes back to the current sync only after its engine has stopped. HQ used to turn the old sync back on while the engine could still be in the middle of a cycle, so both could write to the vault at once. When the daemon falls back to the current sync for an engine that is too old, it now also clears the engine's claim on the vault, so the current sync no longer skips it until the next reconcile.
25
+ - Internal: The Grok Build lifecycle switch-rule test runs as one case per missing event and evaluator set (16 cases), with the same assertions. All 16 setups in one test went past vitest's 5-second limit on loaded CI runners.
26
+ - Updates the bundled HQ Cloud to 6.18.118. The old sync runner now stays off every vault the new sync engine owns: one-shot runs such as `/hq-sync` (`--companies`, `--company`, `--personal`) skip an engine-owned vault and report it as `company-skipped` with reason `new-sync`, and a running runner re-checks ownership before each pass, vault and file, so a vault handed to the engine mid-pass stops at its next file and a vault handed back is synced again without a restart. A vault handed back while its engine process is still running stays skipped until that process exits. `hq rescue` also keeps real folders at release link paths in place.
27
+ - From the same HQ Cloud update: `hq outposts list` now shows your personal Outposts and, grouped by company, the company Outposts you can use (`--company` lists one company's; `--json` without `--company` still lists your personal Outposts only). `hq outposts pull` accepts `--company <slug>` and `--outpost <name|id>` to download from a company Outpost, `hq outposts login-code --company` waits for the Outpost to confirm the sign-in (`--no-wait` skips the wait), and the `hq outposts request --size` help now says the server default is medium.
28
+ - Run the policy gate delivery-regex corpus test in four parallel parts per gate version so the hq-hook PR test shard finishes sooner; every case still runs.
29
+ - Record native PostToolUse master coverage for Codex and Grok on Unix.
30
+ - hq-hook on Windows: guards now compare file paths through one spelled key. A backslash, mixed-separator, verbatim (`\\?\`), uppercase, dot, parent or trailing-dot spelling of a credential, company, core, plans or HQ-root path is now decided the same way as its forward-slash spelling. On macOS and Linux a backslash stays a literal filename character.
31
+ - hq-hook on Windows: a Bash command operand with trailing dots or spaces on a path segment is now compared as the file Windows opens, through the same path key as a file-tool field. `.env.` and `.npmrc.` block like `.env` and `.npmrc`, and a company directory segment with those characters is the directory Windows opens. On macOS and Linux those names stay literal.
32
+ - hq-hook on Windows: a Bash operand whose path cannot be checked, including an unresolved 8.3 short name such as `ENV~1`, is blocked. On a volume where `.env` has that short name, Windows would open `.env`. A tilde that is not an 8.3 name, a flag, and a known-scheme URL stay allowed. On macOS and Linux those bytes stay literal.
33
+ - Fixed: `hq runners create --provider claude --outpost <company Outpost>` no longer fails with `claude_account_balance_target_host_unavailable`. A Claude lane on a company Outpost now uses the Claude account signed in on that Outpost, chosen from the accounts the Outpost reports, instead of this machine's accounts and personal Outposts. `--account auto` on a company Outpost picks from those accounts too, and the lane does not take model or effort from a same-named account on this machine. When no account is ready, the error says whether the accounts are out of quota (with the reset time) or not signed in (with the `hq outposts login` and `login-code` steps for that company and Outpost). `hq runners grant --outpost <company Outpost> --company <slug>` finds a lane that has no local record.
34
+ - Fixed (lanes): `hq lanes create` and lane starts no longer fail with "Unknown host kind" when some other lane record on the machine has a host kind this CLI does not know, such as `microvm`. Hire-grant admission, account selection and host capacity now read lanes the same way `hq lanes list` does: a record that cannot be read is skipped with a warning naming its lane id and field, and the record is left as it is. A hire still stops with `hire_grant_context_invalid` when the unreadable record is a child of the hiring lane and its state is not finished or cannot be read, so the hire grant limit holds.
35
+ - hq-hook: the native credential guard is claimed for PreToolUse on every host and answers every Read and Bash call itself, with no script hash and no hand-back to bash (US-013 c1). A Read of a Windows backslash path to a credential file (for example under `.ssh` or `.aws`) is now refused. Unquoted git path globs stay refused, as before.
36
+ - Fixed (install): the CLI starts again on Node 20.0 to 20.9. The hook-engine coverage gate read its policy files with JSON import attributes, which need Node 20.10, so `hq` failed with a SyntaxError at load (Sentry HQ-CLI-HZ). The files are now read from disk beside the module and copied into the package by the build.
37
+ - Fixed (rescue): rescue and HQ version checks use published release redirects and verified release assets when the GitHub API is unavailable, skipping pending or failed release tags.
38
+ - Commit lookups use git without API quota, and rescue prints one fallback warning per command.
39
+ - The native company scope guard now refuses three command shapes that could write into another company's folder: a zsh `printf` or `print -f` argument of a numeric conversion that is not a plain number (zsh evaluates it as arithmetic, which can run a command named in a variable's value), `busybox` or `toybox` running an applet, and GNU `parallel` (or `sem`) building command lines from its inputs. Listing busybox applets and `parallel --version` still work.
40
+ - Fixed (hooks): the new hook core no longer refuses a personal skill called through the `hq-personal:` name that `hq install-global` adds, or the core `hq-` skill of the same name, on installs that also have a company folder called `personal`. A session locked to a company still cannot load another company's skills.
41
+ - Fixed (search): `hq search --mode lexical` now runs a keyword (BM25) search. qmd calls its BM25 search "lexical", so agents asked for that mode and got an "Unknown search mode" error (Sentry HQ-CLI-J2). `--mode` now also ignores case and surrounding spaces, so `KEYWORD` or ` Hybrid ` work. Other unknown modes still fail with the list of supported modes.
42
+ - Internal: The session-lock fresh-path cost test compares the state-file entry with a fresh hook-cache entry, which allows the same read, instead of a refused entry that does less work. Its bound is scaled with the costlier baseline, from 2.0 to 1.35, with 15 pairs instead of 9, so it still catches every added cost the old check caught. The process-start and registry-request checks are unchanged.
43
+ - Fixed (signals): a bot's scheduled hot-signal-sync job runs the signals pass on the HQ Fleet Executive bot's own login again. The job runs `hq signals run` inside the running bot's HQ Fleet gateway, which sets `HQ_FLEET_HOME` to that bot's profile folder. The pass read that folder as the Fleet home, found no profile for the Executive bot, and fell back to the Claude CLI, so a Codex Executive bot failed with `claude-logged-out-codex-bot` whenever a company had documents waiting. The pass now reads a bot profile folder in `HQ_FLEET_HOME` as the Fleet home two levels up. Manual runs and `hq sources sync` are unchanged.
44
+ - Fixed (signals): `hq signals run` can upload hot-channel meeting signals. Their `source_ref` is `meeting:<id>`, where the id is the meeting bot or transcript id, not a file name. Upload now finds the one transcript in `sources/meetings/` that carries that id, then applies the same audience receipt and audience checks as `sources/meetings/<file>.md`. The signals pass now asks for the start time of the transcript line behind each signal and writes a citation only when that time matches a timed segment in the transcript, using that segment's own start and end. A signal whose transcript or audience receipt has not synced yet is retried on every later run for up to 14 days, without holding back the upload watermark; signals dropped after 14 days are named in the run record. Not being in a meeting's audience is now a permanent skip. The Slack hot channel, which reads only the vault's `sources/slack/` folder, runs without a usable Slack connection and still honours the channels the person picked on their Slack connections, including a connection that was later revoked.
45
+ - New sync: company skills, commands and workers that arrive or are removed through the new sync engine are now registered. The `sync-core` reconcile (every 10 minutes) compares the skills, commands and `worker.yaml` files under each vault the engine owns with the last run and, only when they differ, runs the same reindex the old sync ran after a pull. Before, a skill delivered by the new sync had no `<company>:<skill>` wrapper until someone ran `hq reindex`, and a removed skill left a dead wrapper. A reindex that cannot run is tried again on each reconcile and its warning is logged once. `hq sync pull` and `hq sync now` on a vault the new sync engine owns now say that the new sync is handling it and point to `hq sync-core status`; before, they said sync was off and told the user to turn the switch back on, which would have restarted the old sync on that vault. The exit code (3) is unchanged.
46
+ - Fixed (sync): a company you join on a computer that uses the new sync engine now gets set up by the engine itself. `hq daemon` (the `sync-core` unit, every 10 minutes) creates the company's folder under `companies/` and adds its `cloud_uid`, `name` and `bucket_name` entry to the companies manifest when the rollout switch is on for that company, then the engine downloads its files. Before, only a pass of the old sync wrote the folder and the entry, so with the HQ desktop app closed, or with every other vault already on the new engine, the joined company was never synced and nothing said so. An entry that is already in the manifest is never changed, the new entry is appended so the file's comments stay, and the write is retried if another writer changed the manifest meanwhile. A folder that already has files but no manifest entry is left alone with a warning, and no empty folder is created for a company the old sync or the engine has synced on this computer before. Nothing is set up on Windows, Outposts and agent machines, for a vault in `~/.hq/sync-core/skip.json`, for a company whose sync switch is off, or when the rollout switch is off (the old sync still handles the join there). Cost: one flag read per run for each membership with no local folder, and one company lookup while such a company has the switch on.
47
+ - Fixed (sync): when the new sync engine owns a company vault on this machine, commands that change what you can see in it now ask that engine to read your access at once, instead of waiting for its access re-check (up to 24 hours for some re-grants). This covers `hq files share --with`, `hq files unshare`, `hq files get` (when it pins), accepting an invite with `hq onboard join` (and a resumed join), and `hq core delegate pickup` when it records a pickup. The CLI writes `access-refresh.json` in that vault's engine home only; a failed write never fails the command and is logged only with `--verbose` or `HQ_DEBUG=1`.
48
+ - Handoff archive checks now call `hq runners list`, and additional runner diagnostics and command documentation use the canonical `hq runners` name. The `hq lanes` compatibility alias remains available.
49
+ - The new hook core now answers the repository merge hold (`lanes-repo-merge-hold`) itself on Claude Code and Codex, outside Windows. Its decisions match the released hook and that hook's own test suite. Grok, the fleet runtimes and Windows still run the shell hook.
50
+ - The native company scope guard now refuses three command shapes the released shell guard refuses: an `xargs` with an option the guard does not know or a program named by a path, a shell function after `set -a` (which exports it to child shells), and a zsh modifier such as `$p:h` on a variable whose value is known.
51
+ - hq-hook: `hq-hook run --host codex PreToolUse` now refuses a Codex `apply_patch`, `Edit` or `Write` into `core/` with the released Codex adapter's own message (`Edits to core/ are denied by hq-codex-hook-adapter.sh (<path>).`, exit 2), unless `HQ_BYPASS_CORE_PROTECT` is `1`, `true`, `TRUE`, `yes` or `YES`, and refuses an edit of a dotenv file whose new content it cannot read, or a rename into one, with the adapter's `Edit to dotenv file <path> denied by hq-codex-hook-adapter.sh: <why>` line. `hq-hook run --host grok PreToolUse` now binds a Grok subagent's company on its first tool call, as the adapter's `bind_subagent_once` did; a bind it cannot decide binds nothing and refuses the call. `codex-adapter:PreToolUse` is claimed on Codex and `grok-adapter:PreToolUse` on Grok (`hq-hook capabilities --json`), with a parity test against the v16.0.50 adapters (US-050 c1). PreToolUse stays on the old path until `master-hook:PreToolUse` and every registry hook are claimed.
52
+ - Internal: `hq-hook` now claims the local bot runtime's SubagentStop natively (`SubagentStop@fleet-local`: `fleet-local-adapter:SubagentStop` and `master-hook:SubagentStop`). master-hook's own SubagentStop work under the hq-fleet-local v0.4.33 adapter (session bind, twin dedupe, timeout journal) is done by `lifecycle_master`, at parity with the released adapter running the real master-hook. The adapter's `.claude/settings.json` SubagentStop commands go to the HQ daemon on the `fleet-local-settings` request note, as SessionEnd's do, and the daemon accepts `SubagentStop` on that note. A SubagentStop hook the claim does not name, a payload with no session id and a pinned-engine exec entry are refused natively. Hosted agents (`agents-v2`) are unchanged. The event still registers on the shell adapter until an engine reports `lifecycle-dispatch`.
53
+
5
54
  ## [5.345.241] — 2026-11-20
6
55
  - The daemon's company access check now runs only with a jq that passes a version and behavior check. A homemade or wrapper `jq` first on the daemon's PATH used to block every call with "invalid agent_id", and one that echoed its input could let calls into another company's folder through. The daemon now picks a working jq, installs its own checksum-verified jq 1.8.2 under `~/.hq/daemon/tools` when the machine has none, and blocks with a plain reason while no working jq exists. Policy checks also pass an empty agent identity so the authorizer no longer reads agent fields with jq. `hq doctor` now fails a jq whose `--version` is not `jq-1.x`. Windows hook setup and doctor repair share the same checksum-verified download installer with daemon provisioning; managed installs reject symlink destinations and unsafe writable directories.
7
56
  - `hq core delegate` now prints paths the way the hq-core helpers do on every platform: the HQ root followed by forward-slash segments. This covers the secrets schema source in the plan and the missing-name error, the repo directory in `hq core delegate repo`'s "not a git repository" error and push plan, and `board.json` in `hq core delegate transfer`'s invalid-board error. Before this fix, Windows printed backslashes and did not match the helpers. `hq core delegate repo` also uses an absolute `repo.path` (POSIX or a Windows drive path) as-is, as `hq-delegate-repo.sh` does, instead of looking for it under the HQ root.
@@ -17,6 +17,11 @@
17
17
  # 3. read each grant back with hq files acl and match grantee + permission
18
18
  # 4. advance manifest status building -> granted, stamping verifiedAt
19
19
  #
20
+ # When the new sync engine owns the company vault on this machine, the CLI
21
+ # refuses `hq sync push`. Step 1 is then skipped, and after the grants the
22
+ # helper waits for the engine to upload the dossier and referenced files
23
+ # (lib/delegate-engine.sh) before it advances the status.
24
+ #
20
25
  # Direct ACL grants ONLY — this helper never mints a share-session URL
21
26
  # (policy hq-delegate-never-inlines-secrets-or-share-urls).
22
27
  #
@@ -29,8 +34,9 @@ set -euo pipefail
29
34
 
30
35
  SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
31
36
  HQ_ROOT="${HQ_ROOT:-$(cd "$SCRIPT_DIR/../.." && pwd)}"
37
+ . "$SCRIPT_DIR/lib/delegate-engine.sh"
32
38
 
33
- usage() { sed -n '3,25p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'; }
39
+ usage() { sed -n '3,30p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'; }
34
40
  die() { echo "hq-delegate-grant: $*" >&2; exit 1; }
35
41
 
36
42
  command -v jq >/dev/null 2>&1 || die "jq is required but not installed"
@@ -85,6 +91,7 @@ PROJECT="$(jq -r '.project.name // empty' "$MANIFEST" | tr -d '\r')"
85
91
  PRINCIPAL="$(jq -r '.to.principal // empty' "$MANIFEST" | tr -d '\r')"
86
92
  DISPLAY="$(jq -r '.to.displayName // .to.principal // empty' "$MANIFEST" | tr -d '\r')"
87
93
  STATUS="$(jq -r '.status // empty' "$MANIFEST" | tr -d '\r')"
94
+ MODE="$(jq -r '.mode // empty' "$MANIFEST" | tr -d '\r')"
88
95
  [ -n "$COMPANY" ] || die "manifest has no company"
89
96
  [ -n "$PROJECT" ] || die "manifest has no project.name"
90
97
  [ -n "$PRINCIPAL" ] || die "manifest has no to.principal"
@@ -138,13 +145,42 @@ if [ -n "$BAD" ]; then
138
145
  die "prefix violates the hq-files prefix conventions (must be company-relative folder form ending in '/'): $BAD"
139
146
  fi
140
147
 
148
+ # --- person recipients named by personUid ------------------------------------
149
+ # `hq people resolve` matches names and emails only (a prs_ uid returns
150
+ # not_found), and `hq files share --with` accepts only email / grp_ / @all.
151
+ # Map the prs_ uid to its email through the structured people roster, then
152
+ # resolve and share by that email. The authoritative membership resolve below
153
+ # must return this exact personUid, or the run stops.
154
+ RESOLVE_KEY="$PRINCIPAL"
155
+ case "$PRINCIPAL" in
156
+ prs_*)
157
+ PEOPLE_JSON="$(hq people list --company "$COMPANY" --json \
158
+ | awk 'started {print; next} /^[[:space:]]*[{[]/ {started=1; print}')" \
159
+ || die "could not list people to map personUid $PRINCIPAL to an email; set to.principal to the recipient's email and re-run"
160
+ PRS_EMAILS="$(printf '%s' "$PEOPLE_JSON" | jq -r --arg uid "$PRINCIPAL" '
161
+ if type == "array" then . else (.people // error("unexpected people list shape")) end
162
+ | [.[] | select(.personUid == $uid) | .email
163
+ | select(type == "string" and length > 0) | ascii_downcase] | unique | .[]
164
+ ' | tr -d '\r')" \
165
+ || die "people list returned unexpected JSON while mapping $PRINCIPAL; set to.principal to the recipient's email and re-run"
166
+ PRS_EMAIL_COUNT="$(printf '%s' "$PRS_EMAILS" | grep -c . || true)"
167
+ [ "$PRS_EMAIL_COUNT" -eq 1 ] \
168
+ || die "personUid $PRINCIPAL maps to $PRS_EMAIL_COUNT emails in company '$COMPANY' (need exactly 1); set to.principal to the recipient's email and re-run"
169
+ RESOLVE_KEY="$PRS_EMAILS"
170
+ GRANT_PRINCIPAL="$PRS_EMAILS"
171
+ ;;
172
+ esac
173
+
141
174
  # --- plan (always printed; the only output without --yes) --------------------
142
175
 
143
176
  echo "Delegation grant plan — company '$COMPANY', recipient '$PRINCIPAL':"
144
- if [ "$GRANT_PRINCIPAL" != "$PRINCIPAL" ]; then
177
+ case "$PRINCIPAL" in
178
+ prs_*) echo " 0. Person recipient: personUid $PRINCIPAL maps to $GRANT_PRINCIPAL; grants are shared to that email" ;;
179
+ esac
180
+ if [ "${PRINCIPAL#agt_}" != "$PRINCIPAL" ]; then
145
181
  echo " 0. Agent recipient: grants flow through group $GRANT_PRINCIPAL (created if absent, containing exactly $DISPLAY)"
146
182
  fi
147
- echo " 1. Push companies/$COMPANY/projects/$PROJECT/ to the vault (on-conflict keep)"
183
+ echo " 1. Push companies/$COMPANY/projects/$PROJECT/ to the vault (on-conflict keep); where the sync engine owns the vault, pin it in .hq/pins.json and wait for its upload after the grants instead"
148
184
  jq -r '.vaultPrefixes[] | " 2. Grant \(.permission) on \(.prefix) — \(.reason // "")"' "$MANIFEST" | tr -d '\r'
149
185
  WRITE_PREFIXES="$(jq -r '.vaultPrefixes[] | select(.permission == "write") | .prefix' "$MANIFEST" | tr -d '\r')"
150
186
  if [ -n "$WRITE_PREFIXES" ]; then
@@ -165,10 +201,53 @@ fi
165
201
  # on the prefix and silently misses the file. Push every referenced
166
202
  # company-local knowledge/policy path alongside the dossier.)
167
203
 
168
- hq sync push "companies/$COMPANY/projects/$PROJECT/" --company "$COMPANY" --on-conflict keep \
169
- || die "vault push failed for companies/$COMPANY/projects/$PROJECT/"
204
+ ENGINE_OWNED=0
205
+ if hq_delegate_engine_owns_vault "$COMPANY"; then ENGINE_OWNED=1; fi
170
206
 
171
- jq -r --arg co "$COMPANY" \
207
+ # Skip the full-folder push when the vault already holds this project: a large
208
+ # project re-walks thousands of unchanged files and can exceed the foreground
209
+ # timeout. Compare the dossier files' checksums local vs vault first; any
210
+ # mismatch, missing file, or unreadable vault copy falls back to the full push.
211
+ vault_has_project() {
212
+ local f lp remote_hash local_hash compared=0
213
+ for f in prd.json README.md brainstorm.md; do
214
+ lp="$HQ_ROOT/companies/$COMPANY/projects/$PROJECT/$f"
215
+ [ -f "$lp" ] || continue
216
+ remote_hash="$(hq files cat "projects/$PROJECT/$f" --company "$COMPANY" 2>/dev/null | { sha256sum 2>/dev/null || shasum -a 256; } | cut -d ' ' -f1)" || return 1
217
+ local_hash="$({ sha256sum "$lp" 2>/dev/null || shasum -a 256 "$lp"; } | cut -d ' ' -f1)"
218
+ [ -n "$remote_hash" ] && [ "$remote_hash" = "$local_hash" ] || return 1
219
+ compared=$((compared + 1))
220
+ done
221
+ [ "$compared" -gt 0 ]
222
+ }
223
+
224
+ if [ "$ENGINE_OWNED" -eq 1 ]; then
225
+ echo "hq-delegate-grant: the sync engine owns the '$COMPANY' vault on this machine — no push; pinning the project and referenced files so the engine uploads them"
226
+ PIN_PATHS=("projects/$PROJECT/")
227
+ while IFS= read -r kpath; do
228
+ [ -n "$kpath" ] && PIN_PATHS+=("$kpath")
229
+ done < <(jq -r --arg co "$COMPANY" \
230
+ '((.knowledge // []) + (.policies // []))[] | select(startswith("companies/" + $co + "/")) | ltrimstr("companies/" + $co + "/")' \
231
+ "$MANIFEST" | tr -d '\r')
232
+ hq_delegate_engine_pin "$HQ_ROOT" "$COMPANY" "${PIN_PATHS[@]}" \
233
+ || die "could not add the project to $HQ_ROOT/.hq/pins.json for the sync engine"
234
+ elif vault_has_project; then
235
+ echo "hq-delegate-grant: vault already has companies/$COMPANY/projects/$PROJECT/ (dossier checksums match) — skipping full-folder push"
236
+ else
237
+ hq sync push "companies/$COMPANY/projects/$PROJECT/" --company "$COMPANY" --on-conflict keep \
238
+ || die "vault push failed for companies/$COMPANY/projects/$PROJECT/"
239
+ # on-conflict keep drops the delegator's fresh local edits when the vault copy
240
+ # differs. The delegator owns the dossier, so push these files again with
241
+ # overwrite, and fail the step if one cannot be pushed.
242
+ for dossier_file in prd.json README.md brainstorm.md; do
243
+ if [ -f "$HQ_ROOT/companies/$COMPANY/projects/$PROJECT/$dossier_file" ]; then
244
+ hq sync push "companies/$COMPANY/projects/$PROJECT/$dossier_file" --company "$COMPANY" --on-conflict overwrite \
245
+ || die "vault push failed for dossier file companies/$COMPANY/projects/$PROJECT/$dossier_file"
246
+ fi
247
+ done
248
+ fi
249
+
250
+ [ "$ENGINE_OWNED" -eq 1 ] || jq -r --arg co "$COMPANY" \
172
251
  '((.knowledge // []) + (.policies // []))[] | select(startswith("companies/" + $co + "/"))' \
173
252
  "$MANIFEST" | tr -d '\r' | while IFS= read -r kpath; do
174
253
  if [ -e "$HQ_ROOT/$kpath" ]; then
@@ -181,7 +260,7 @@ done
181
260
 
182
261
  # --- 1b. agent recipients: ensure the delegation group exists + contains them
183
262
 
184
- if [ "$GRANT_PRINCIPAL" != "$PRINCIPAL" ]; then
263
+ if [ "${PRINCIPAL#agt_}" != "$PRINCIPAL" ]; then
185
264
  # Group creation and add are idempotent-tolerated; confirm that the complete
186
265
  # member list is exactly this agent before any file ACL is shared.
187
266
  hq groups create "$GRANT_PRINCIPAL" --name "Delegation: $DISPLAY" --company "$COMPANY" \
@@ -206,13 +285,20 @@ case "$GRANT_PRINCIPAL" in
206
285
  @all) EXPECTED_TYPE=company-wide; EXPECTED_ID="" ;;
207
286
  *)
208
287
  RESOLVE_RC=0
209
- RESOLVED="$(hq people resolve "$PRINCIPAL" --company "$COMPANY" --json --membership-only)" || RESOLVE_RC=$?
288
+ RESOLVED="$(hq people resolve "$RESOLVE_KEY" --company "$COMPANY" --json --membership-only)" || RESOLVE_RC=$?
210
289
  if printf '%s' "$RESOLVED" | jq -e '.status == "found" and (.person.personUid | type == "string") and (.person.companyUid | type == "string")' >/dev/null; then
211
290
  [ "$RESOLVE_RC" -eq 0 ] || die "recipient resolution failed"
212
291
  EXPECTED_TYPE=person
213
292
  EXPECTED_ID="$(printf '%s' "$RESOLVED" | jq -r '.person.personUid' | tr -d '\r')"
214
293
  EXPECTED_COMPANY="$(printf '%s' "$RESOLVED" | jq -r '.person.companyUid' | tr -d '\r')"
294
+ case "$PRINCIPAL" in
295
+ prs_*) [ "$EXPECTED_ID" = "$PRINCIPAL" ] \
296
+ || die "personUid $PRINCIPAL mapped to $RESOLVE_KEY, but membership resolves that email to $EXPECTED_ID; set to.principal to the recipient's email and re-run" ;;
297
+ esac
215
298
  elif printf '%s' "$RESOLVED" | jq -e '.status == "not_found"' >/dev/null; then
299
+ case "$PRINCIPAL" in
300
+ prs_*) die "personUid $PRINCIPAL ($RESOLVE_KEY) is not an active member of company '$COMPANY'" ;;
301
+ esac
216
302
  case "$PRINCIPAL" in *@*) EXPECTED_TYPE=email; EXPECTED_ID="$(printf '%s' "$PRINCIPAL" | tr '[:upper:]' '[:lower:]' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')" ;; *) die "unresolved recipient" ;; esac
217
303
  else
218
304
  die "authoritative recipient lookup failed; update hq-cli if --membership-only is unsupported"
@@ -261,6 +347,61 @@ while [ "$i" -lt "$PREFIX_COUNT" ]; do
261
347
  fi
262
348
  done
263
349
  [ "$landed" -eq 1 ] || die "grant outcome unconfirmed for $PRINCIPAL on $PFX; retain this manifest and resume"
350
+ # Full-transfer mode: a more specific rule under the project prefix (for
351
+ # example projects/<name>/design/* or projects/<name>/design) outranks the
352
+ # root grant, so the recipient would keep the narrower permission there, or
353
+ # have none at all. Grant the same permission on every such rule and verify
354
+ # each one. The ACL tree lists rules that carry grants as .children and
355
+ # rules with no grants only as .masking, so both are read; a truncated
356
+ # masking list stops the grant rather than leave an unseen rule ungranted.
357
+ # A rule the recipient already holds at this permission or higher is left
358
+ # as it is. Only rules under the project prefix are considered, so the
359
+ # outside-project check below is defensive.
360
+ if [ "$MODE" = "transfer" ]; then
361
+ case "$PFX" in "projects/$PROJECT/"*)
362
+ if printf '%s' "$AFTER" | jq -e '.maskingTruncated == true' >/dev/null 2>&1; then
363
+ die "the ACL tree for $PFX lists too many overriding rules to check; grant them by hand, then resume"
364
+ fi
365
+ CHILD_RULES="$(printf '%s' "$AFTER" | jq -r --arg pfx "$PFX" --arg root "$ACL_PATTERN" \
366
+ --arg id "$EXPECTED_ID" --arg type "$EXPECTED_TYPE" --arg perm "$PERM" '
367
+ def rank: if . == "admin" then 3 elif . == "write" then 2 elif . == "read" then 1 else 0 end;
368
+ def holds: .granteeType == $type and .granteeId == $id and (((.permission // "") | rank) >= ($perm | rank));
369
+ def under: type == "string" and startswith($pfx) and . != $root;
370
+ ( [ (.children // [])[] | select(.sourcePrefix | under) | {p: .sourcePrefix, held: holds} ]
371
+ + [ (.masking // [])[] | select(.path | under) | {p: .path, held: ((.grantees // []) | any(holds))} ] )
372
+ | group_by(.p) | map({p: .[0].p, held: any(.[]; .held)}) | .[]
373
+ | (if .held then "held" else "grant" end) + "\t" + .p' | tr -d '\r')"
374
+ # One rule per line, read whole: a folder name with a space or a glob
375
+ # character must stay one pattern. Word-splitting it would grant on a
376
+ # path outside the project. fd 3 keeps the hq calls off the list.
377
+ while IFS="$(printf '\t')" read -r CHILD_STATE CHILD <&3; do
378
+ [ -n "$CHILD" ] || continue
379
+ case "$CHILD" in "projects/$PROJECT/"*) ;; *) die "more specific rule $CHILD is outside projects/$PROJECT/" ;; esac
380
+ if [ "$CHILD_STATE" = held ]; then
381
+ echo "hq-delegate-grant: $PRINCIPAL already holds $PERM or higher on more specific rule $CHILD"
382
+ continue
383
+ fi
384
+ CHILD_RC=0
385
+ hq files share "$CHILD" --with "$GRANT_PRINCIPAL" --permission "$PERM" --company "$COMPANY" || CHILD_RC=$?
386
+ [ "$CHILD_RC" -eq 0 ] || echo "hq-delegate-grant: share reported an error on $CHILD; checking exact grant" >&2
387
+ child_landed=0
388
+ for delay in 0 1 2; do
389
+ [ "$delay" -eq 0 ] || sleep "$delay"
390
+ if CHILD_AFTER="$(read_acl "$CHILD")" && printf '%s' "$CHILD_AFTER" | jq -e \
391
+ --arg id "$EXPECTED_ID" --arg type "$EXPECTED_TYPE" --arg perm "$PERM" \
392
+ '.exists and any(.direct[]; .granteeType == $type and .granteeId == $id and .permission == $perm)' >/dev/null; then
393
+ child_landed=1
394
+ break
395
+ fi
396
+ done
397
+ [ "$child_landed" -eq 1 ] || die "grant outcome unconfirmed for $PRINCIPAL on more specific rule $CHILD; retain this manifest and resume"
398
+ echo "hq-delegate-grant: verified $PERM on more specific rule $CHILD for $PRINCIPAL"
399
+ done 3<<EOF_CHILDREN
400
+ $CHILD_RULES
401
+ EOF_CHILDREN
402
+ ;;
403
+ esac
404
+ fi
264
405
  TMP_MANIFEST="$(mktemp)"
265
406
  jq --argjson i "$i" --arg now "$NOW" --arg id "$EXPECTED_ID" --arg type "$EXPECTED_TYPE" \
266
407
  --arg company "$EXPECTED_COMPANY" --argjson rc "$SHARE_RC" '
@@ -271,6 +412,27 @@ while [ "$i" -lt "$PREFIX_COUNT" ]; do
271
412
  i=$((i + 1))
272
413
  done
273
414
 
415
+ # --- 3b. engine-owned vault: wait for the engine's upload ---------------------
416
+ # The pins above bring the files into the engine's scope; confirm the exact
417
+ # bytes of the dossier and every referenced company file before reporting success.
418
+
419
+ if [ "$ENGINE_OWNED" -eq 1 ]; then
420
+ {
421
+ for f in prd.json README.md brainstorm.md; do
422
+ [ -f "$HQ_ROOT/companies/$COMPANY/projects/$PROJECT/$f" ] && echo "companies/$COMPANY/projects/$PROJECT/$f"
423
+ done
424
+ jq -r --arg co "$COMPANY" \
425
+ '((.project.dossier // []) + (.knowledge // []) + (.policies // []))[] | select(startswith("companies/" + $co + "/"))' \
426
+ "$MANIFEST" | tr -d '\r'
427
+ } | sort -u | while IFS= read -r kpath; do
428
+ [ -f "$HQ_ROOT/$kpath" ] || continue
429
+ expected="$(hq_delegate_sha256 < "$HQ_ROOT/$kpath")"
430
+ hq_delegate_wait_for_cloud "$COMPANY" "${kpath#"companies/$COMPANY/"}" "$expected" \
431
+ || die "the sync engine has not uploaded $kpath after $(hq_delegate_engine_wait_seconds)s ($HQ_DELEGATE_ENGINE_WAIT_CAUSES); check 'hq sync-core status', then re-run (grants are idempotent)"
432
+ done
433
+ echo "hq-delegate-grant: the sync engine uploaded the dossier; vault bytes match"
434
+ fi
435
+
274
436
  # --- 4. advance manifest status ----------------------------------------------
275
437
 
276
438
  TMP_MANIFEST="$(mktemp)"
@@ -11,6 +11,7 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
11
11
  HQ_ROOT="${HQ_ROOT:-$(cd "$SCRIPT_DIR/../.." && pwd)}"
12
12
  . "$SCRIPT_DIR/lib/secret-patterns.sh"
13
13
  . "$SCRIPT_DIR/lib/delegate-brainstorm.sh"
14
+ . "$SCRIPT_DIR/lib/delegate-engine.sh"
14
15
  die() { echo "hq-delegate-publish: $*" >&2; exit 1; }
15
16
  [ "${1:-}" = --manifest ] && [ -f "${2:-}" ] || die 'usage: --manifest <path>'
16
17
  MANIFEST="$2"
@@ -100,14 +101,33 @@ atomic_copy "$STAGE/manifest.json" "$DEST/manifest.json"
100
101
  atomic_copy "$STAGE/manifest.json" "$MANIFEST"
101
102
  # keep may preserve stale canonical content. Read-back must catch that instead
102
103
  # of overwriting concurrent changes merely to make the check pass.
103
- hq sync push "$REL/" --company "$COMPANY" --on-conflict keep || die 'final dossier push failed; resume publication'
104
+ # Push only the dossier paths, never the whole project folder: a large project
105
+ # re-walks thousands of unchanged files and exceeds the foreground timeout.
106
+ # When the new sync engine owns the vault, `hq sync push` is refused; the
107
+ # engine uploads the files and the read-back below waits for them.
108
+ ENGINE_OWNED=0
109
+ if hq_delegate_engine_owns_vault "$COMPANY"; then ENGINE_OWNED=1; fi
110
+ if [ "$ENGINE_OWNED" -eq 0 ]; then
111
+ hq sync push "$REL/delegation/$ID/" --company "$COMPANY" --on-conflict keep || die 'final dossier push failed; resume publication'
112
+ while IFS= read -r file; do
113
+ [ -n "$file" ] && [ -e "$file" ] || continue
114
+ hq sync push "${file#"$HQ_ROOT/"}" --company "$COMPANY" --on-conflict keep || die 'final dossier push failed; resume publication'
115
+ done <<EOF
116
+ $SNAPSHOT_FILES
117
+ EOF
118
+ fi
104
119
  cp "$STAGE/hashes" "$STAGE/receipts"
105
120
  jq -cn --arg key "$REL/delegation/$ID/manifest.json" --arg value "$(file_hash "$DEST/manifest.json")" '{key:$key,value:$value}' >> "$STAGE/receipts"
106
121
  while IFS= read -r row; do
107
122
  path="$(printf '%s' "$row" | jq -r '.key')"
108
123
  expected="$(printf '%s' "$row" | jq -r '.value')"
109
124
  matched=0
125
+ if [ "$ENGINE_OWNED" -eq 1 ]; then
126
+ hq_delegate_wait_for_cloud "$COMPANY" "${path#"companies/$COMPANY/"}" "$expected" && matched=1
127
+ [ "$matched" -eq 1 ] || die "the sync engine has not uploaded $path (or the vault holds other bytes) after $(hq_delegate_engine_wait_seconds)s ($HQ_DELEGATE_ENGINE_WAIT_CAUSES); check 'hq sync-core status', then resume"
128
+ fi
110
129
  for delay in 0 1 2; do
130
+ [ "$matched" -eq 0 ] || break
111
131
  [ "$delay" -eq 0 ] || sleep "$delay"
112
132
  if hq files cat "${path#"companies/$COMPANY/"}" --company "$COMPANY" > "$STAGE/remote"; then
113
133
  if [ "$(file_hash "$STAGE/remote")" = "$expected" ]; then matched=1; break; fi
@@ -0,0 +1,77 @@
1
+ # shellcheck shell=bash
2
+ # hq-core: public
3
+ # delegate-engine.sh — /delegate helpers for a company vault that the new sync
4
+ # engine (hq-syncd) owns on this machine. The CLI refuses `hq sync push` for
5
+ # such a vault, so the helpers share the folder and wait for the engine to
6
+ # upload the files instead of pushing them.
7
+ #
8
+ # Env: HQ_DELEGATE_ENGINE_WAIT_SECONDS (default 180) bounds each wait;
9
+ # HQ_DELEGATE_ENGINE_POLL_SECONDS (default 5) is the read-back interval.
10
+
11
+ hq_delegate_sha256() {
12
+ if command -v sha256sum >/dev/null 2>&1; then sha256sum | cut -d ' ' -f1; else shasum -a 256 | cut -d ' ' -f1; fi
13
+ }
14
+
15
+ # True when `hq sync-core status --json` lists <company> in full mode and not
16
+ # in `held` (the CLI's own ownership rule). A CLI without the command, or any
17
+ # read error, counts as not engine-owned, which keeps the `hq sync push` path.
18
+ hq_delegate_engine_owns_vault() {
19
+ local status
20
+ status="$(hq sync-core status --json 2>/dev/null)" || return 1
21
+ printf '%s' "$status" | jq -e --arg co "$1" \
22
+ '[(.held // [])[] | .uid | ascii_downcase] as $held
23
+ | any(.vaults[]? | select(. != null);
24
+ .kind == "company" and .phase == "full"
25
+ and ((.slug // "") | ascii_downcase) == ($co | ascii_downcase)
26
+ and ((.uid | ascii_downcase) as $uid | $held | index([$uid]) | not))' >/dev/null 2>&1
27
+ }
28
+
29
+ # HQ_DELEGATE_ENGINE_WAIT_SECONDS as whole seconds; 180 when unset or not a
30
+ # whole number.
31
+ hq_delegate_engine_wait_seconds() {
32
+ case "${HQ_DELEGATE_ENGINE_WAIT_SECONDS:-}" in
33
+ ''|*[!0-9]*) echo 180 ;;
34
+ *) echo "$((10#$HQ_DELEGATE_ENGINE_WAIT_SECONDS))" ;;
35
+ esac
36
+ }
37
+
38
+ # Why the engine may never upload a file, for the wait-failure messages.
39
+ HQ_DELEGATE_ENGINE_WAIT_CAUSES='the engine skips a file an ignore rule matches, a symlink, or a path this machine is not granted'
40
+
41
+ # hq_delegate_wait_for_cloud <company> <company-relative vault path> <sha256>
42
+ # Polls `hq files cat` until it succeeds and the vault holds exactly those
43
+ # bytes. A failed read never matches, even the hash of an empty file.
44
+ hq_delegate_wait_for_cloud() {
45
+ local company="$1" path="$2" expected="$3" got deadline tmp
46
+ deadline=$((SECONDS + $(hq_delegate_engine_wait_seconds)))
47
+ tmp="$(mktemp "${TMPDIR:-/tmp}/hq-delegate-cat.XXXXXX")" || return 1
48
+ while :; do
49
+ if hq files cat "$path" --company "$company" > "$tmp" 2>/dev/null; then
50
+ got="$(hq_delegate_sha256 < "$tmp")"
51
+ if [ "$got" = "$expected" ]; then rm -f "$tmp"; return 0; fi
52
+ fi
53
+ if [ "$SECONDS" -ge "$deadline" ]; then rm -f "$tmp"; return 1; fi
54
+ sleep "${HQ_DELEGATE_ENGINE_POLL_SECONDS:-5}"
55
+ done
56
+ }
57
+
58
+ # hq_delegate_engine_pin <hq root> <company> <company-relative path>...
59
+ # Adds the paths to <hq root>/.hq/pins.json. A member in `shared` or `custom`
60
+ # sync mode has a pull scope of explicit grants plus these pins, and the engine
61
+ # never uploads a local file outside that scope. The engine re-reads the pins
62
+ # on every cycle.
63
+ hq_delegate_engine_pin() {
64
+ local root="$1" company="$2" file tmp
65
+ shift 2
66
+ file="$root/.hq/pins.json"
67
+ mkdir -p "$root/.hq" || return 1
68
+ [ -s "$file" ] || printf '{"version":1,"pins":{}}\n' > "$file" || return 1
69
+ tmp="$(mktemp "$file.tmp.XXXXXX")" || return 1
70
+ if jq --arg co "$company" \
71
+ '.pins[$co] = (((.pins[$co] // []) + $ARGS.positional) | unique)' "$file" --args "$@" > "$tmp"; then
72
+ mv -f "$tmp" "$file"
73
+ else
74
+ rm -f "$tmp"
75
+ return 1
76
+ fi
77
+ }
@@ -6911,6 +6911,10 @@ export declare const COMMAND_CATALOG: readonly [{
6911
6911
  readonly flags: "--cloud-update";
6912
6912
  readonly description: "Cloud-update mode";
6913
6913
  readonly hidden: false;
6914
+ }, {
6915
+ readonly flags: "--verbose";
6916
+ readonly description: "Show diagnostic details when recovery fails";
6917
+ readonly hidden: false;
6914
6918
  }];
6915
6919
  readonly subcommands: readonly [];
6916
6920
  }, {
@@ -8700,7 +8704,7 @@ export declare const COMMAND_CATALOG: readonly [{
8700
8704
  readonly hidden: false;
8701
8705
  }, {
8702
8706
  readonly flags: "--size <size>";
8703
- readonly description: "small, medium, large or xlarge (without it, the Outpost is billed the small price, $100/month)";
8707
+ readonly description: "small, medium, large or xlarge (default medium; the request shows its price)";
8704
8708
  readonly hidden: false;
8705
8709
  }, {
8706
8710
  readonly flags: "--note <text>";
@@ -8886,7 +8890,7 @@ export declare const COMMAND_CATALOG: readonly [{
8886
8890
  }];
8887
8891
  }, {
8888
8892
  readonly name: "list";
8889
- readonly description: "List every Outpost you own, or a company's Outposts with --company";
8893
+ readonly description: "List your personal Outposts and, grouped by company, the company Outposts you can use. --company lists one company's Outposts";
8890
8894
  readonly aliases: readonly [];
8891
8895
  readonly hidden: false;
8892
8896
  readonly helpOption: true;
@@ -8896,11 +8900,11 @@ export declare const COMMAND_CATALOG: readonly [{
8896
8900
  readonly arguments: readonly [];
8897
8901
  readonly options: readonly [{
8898
8902
  readonly flags: "--company <slug>";
8899
- readonly description: "List the company's Outposts";
8903
+ readonly description: "List only this company's Outposts";
8900
8904
  readonly hidden: false;
8901
8905
  }, {
8902
8906
  readonly flags: "--json";
8903
- readonly description: "Emit raw JSON";
8907
+ readonly description: "Emit raw JSON (without --company: your personal Outposts only, as before)";
8904
8908
  readonly hidden: false;
8905
8909
  }];
8906
8910
  readonly subcommands: readonly [];
@@ -9386,21 +9390,21 @@ export declare const COMMAND_CATALOG: readonly [{
9386
9390
  readonly subcommands: readonly [];
9387
9391
  }, {
9388
9392
  readonly name: "pull";
9389
- readonly description: "Download one file from an Outpost through a short-lived download link (for files too large for exec output). <outpost> is the Outpost id (`primary` for your first box). The remote path must be inside the Outpost user's home or HQ dir; relative and ~ paths start at the home dir. The file is saved to [local-path], or to the remote file name in the current directory.";
9393
+ readonly description: "Download one file from an Outpost through a short-lived download link (for files too large for exec output). <outpost> is your personal Outpost id (`primary` for your first box); for a company Outpost pass --company (and --outpost when the company has more than one) instead. The remote path must be inside the Outpost user's home or HQ dir; relative and ~ paths start at the home dir. The file is saved to [local-path], or to the remote file name in the current directory.";
9390
9394
  readonly aliases: readonly [];
9391
9395
  readonly hidden: false;
9392
9396
  readonly helpOption: true;
9393
9397
  readonly helpCommand: false;
9394
- readonly usage: "[options] <outpost> <remote-path> [local-path]";
9398
+ readonly usage: "<outpost> <remote-path> [local-path] | --company <slug> [--outpost <name|id>] <remote-path> [local-path]";
9395
9399
  readonly helpText: readonly [];
9396
9400
  readonly arguments: readonly [{
9397
- readonly name: "outpost";
9401
+ readonly name: "outpost-or-path";
9398
9402
  readonly required: true;
9399
9403
  readonly variadic: false;
9400
9404
  readonly description: "";
9401
9405
  }, {
9402
9406
  readonly name: "remote-path";
9403
- readonly required: true;
9407
+ readonly required: false;
9404
9408
  readonly variadic: false;
9405
9409
  readonly description: "";
9406
9410
  }, {
@@ -9410,6 +9414,14 @@ export declare const COMMAND_CATALOG: readonly [{
9410
9414
  readonly description: "";
9411
9415
  }];
9412
9416
  readonly options: readonly [{
9417
+ readonly flags: "--company <slug>";
9418
+ readonly description: "Run on this company's Outpost (owners, admins, and members approved for it; others: hq outposts request-access)";
9419
+ readonly hidden: false;
9420
+ }, {
9421
+ readonly flags: "--outpost <name|id>";
9422
+ readonly description: "Which company Outpost, when the company has more than one";
9423
+ readonly hidden: false;
9424
+ }, {
9413
9425
  readonly flags: "--force";
9414
9426
  readonly description: "Replace the local file if it already exists";
9415
9427
  readonly hidden: false;
@@ -9550,6 +9562,10 @@ export declare const COMMAND_CATALOG: readonly [{
9550
9562
  readonly flags: "--outpost <name|id>";
9551
9563
  readonly description: "Which company Outpost, when the company has more than one";
9552
9564
  readonly hidden: false;
9565
+ }, {
9566
+ readonly flags: "--no-wait";
9567
+ readonly description: "With --company: return once HQ has the code, without waiting for the Outpost to confirm sign-in";
9568
+ readonly hidden: false;
9553
9569
  }, {
9554
9570
  readonly flags: "--json";
9555
9571
  readonly description: "Emit raw JSON";
@@ -17472,6 +17488,10 @@ export declare const COMMAND_CATALOG: readonly [{
17472
17488
  readonly flags: "--outpost <id>";
17473
17489
  readonly description: "Confirm the registered Outpost hosting a native lane";
17474
17490
  readonly hidden: false;
17491
+ }, {
17492
+ readonly flags: "--company <slug>";
17493
+ readonly description: "Company that owns the --outpost company Outpost";
17494
+ readonly hidden: false;
17475
17495
  }, {
17476
17496
  readonly flags: "--json";
17477
17497
  readonly description: "JSON on stdout (always)";