@indigoai-us/hq-cli 5.345.238 → 5.345.241

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 (106) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/assets/scaffold/core/scripts/hq-delegate-repo.sh +7 -1
  3. package/assets/scaffold/core/scripts/hq-delegate-secrets.sh +95 -20
  4. package/assets/scaffold/core/scripts/hq-delegate-transfer.sh +57 -9
  5. package/dist/command-catalog.generated.d.ts +185 -3
  6. package/dist/command-catalog.generated.js +228 -3
  7. package/dist/command-registration-plan.d.ts +6 -0
  8. package/dist/command-registration-plan.js +1 -0
  9. package/dist/commands/cloud-off-gate.d.ts +2 -1
  10. package/dist/commands/cloud-off-gate.js +17 -4
  11. package/dist/commands/cloud.d.ts +17 -2
  12. package/dist/commands/cloud.js +126 -24
  13. package/dist/commands/core-delegate-w1b.js +35 -10
  14. package/dist/commands/core-delegate.d.ts +2 -1
  15. package/dist/commands/core-delegate.js +207 -48
  16. package/dist/commands/deploy-comments.js +8 -2
  17. package/dist/commands/deploy-events.d.ts +40 -0
  18. package/dist/commands/deploy-events.js +300 -0
  19. package/dist/commands/doctor.d.ts +4 -4
  20. package/dist/commands/doctor.js +2 -2
  21. package/dist/commands/feedback.js +2 -3
  22. package/dist/commands/keyed-sync-pull.d.ts +12 -0
  23. package/dist/commands/keyed-sync-pull.js +151 -0
  24. package/dist/commands/library-add.d.ts +5 -2
  25. package/dist/commands/library-add.js +22 -9
  26. package/dist/commands/mcp-registration.d.ts +4 -18
  27. package/dist/commands/mcp-registration.js +9 -29
  28. package/dist/commands/mesh.d.ts +4 -0
  29. package/dist/commands/mesh.js +25 -5
  30. package/dist/commands/pack-install.d.ts +2 -3
  31. package/dist/commands/pack-install.js +6 -8
  32. package/dist/commands/secrets.d.ts +3 -4
  33. package/dist/commands/secrets.js +3 -20
  34. package/dist/hq-cloud-sync-runner/bin/sync-runner.js +307 -232
  35. package/dist/hq-cloud-sync-runner/package.json +1 -1
  36. package/dist/lib/bot/api.d.ts +2 -1
  37. package/dist/lib/bot/api.js +2 -15
  38. package/dist/lib/capacity/collectors/claude-oauth.d.ts +0 -2
  39. package/dist/lib/capacity/collectors/claude-oauth.js +0 -5
  40. package/dist/lib/core-utils/delegate-helper-paths.d.ts +26 -0
  41. package/dist/lib/core-utils/delegate-helper-paths.js +33 -0
  42. package/dist/lib/daemon/jq-provision.d.ts +63 -0
  43. package/dist/lib/daemon/jq-provision.js +155 -0
  44. package/dist/lib/daemon/lanes-reconcile-guard.d.ts +4 -3
  45. package/dist/lib/daemon/lanes-reconcile-guard.js +4 -4
  46. package/dist/lib/daemon/mesh-owner.d.ts +4 -0
  47. package/dist/lib/daemon/mesh-owner.js +20 -0
  48. package/dist/lib/daemon/ops/policy.d.ts +3 -0
  49. package/dist/lib/daemon/ops/policy.js +32 -4
  50. package/dist/lib/daemon/run.js +1 -0
  51. package/dist/lib/daemon/server.d.ts +6 -0
  52. package/dist/lib/daemon/server.js +5 -0
  53. package/dist/lib/daemon/verified-jq.d.ts +96 -0
  54. package/dist/lib/daemon/verified-jq.js +337 -0
  55. package/dist/lib/doctor/checks/jq.js +16 -0
  56. package/dist/lib/doctor/deep/executor.d.ts +7 -0
  57. package/dist/lib/doctor/deep/executor.js +1 -1
  58. package/dist/lib/doctor/deep/parity.js +1 -27
  59. package/dist/lib/doctor/deep/sandbox.d.ts +2 -2
  60. package/dist/lib/doctor/deep/sandbox.js +3 -19
  61. package/dist/lib/doctor/fix/refresh-sync-handoff.js +52 -21
  62. package/dist/lib/doctor/fixtures/discover.d.ts +2 -0
  63. package/dist/lib/doctor/fixtures/discover.js +1 -1
  64. package/dist/lib/doctor/json-output.d.ts +1 -1
  65. package/dist/lib/doctor/registry.d.ts +6 -7
  66. package/dist/lib/doctor/registry.js +6 -7
  67. package/dist/lib/doctor/report.d.ts +9 -10
  68. package/dist/lib/doctor/report.js +4 -4
  69. package/dist/lib/flag-registry-worker-source.generated.d.ts +1 -1
  70. package/dist/lib/flag-registry-worker-source.generated.js +1 -1
  71. package/dist/lib/jq/install.d.ts +27 -0
  72. package/dist/lib/jq/install.js +156 -0
  73. package/dist/lib/lanes/outpost-dispatch.d.ts +1 -1
  74. package/dist/lib/lanes/outpost-dispatch.js +13 -13
  75. package/dist/lib/lanes/outpost-pruner-install.js +1 -1
  76. package/dist/lib/mesh/live/daemon/doctor.js +7 -1
  77. package/dist/lib/mesh/live/daemon/install.d.ts +4 -0
  78. package/dist/lib/mesh/live/daemon/install.js +10 -0
  79. package/dist/lib/mesh/live/daemon/run.js +17 -0
  80. package/dist/lib/mesh/live/emit-retry.d.ts +20 -2
  81. package/dist/lib/mesh/live/emit-retry.js +57 -4
  82. package/dist/lib/mesh/live/emit.js +25 -4
  83. package/dist/lib/mesh/live/flush.d.ts +2 -0
  84. package/dist/lib/mesh/live/flush.js +21 -8
  85. package/dist/lib/mesh/live/spool.d.ts +9 -1
  86. package/dist/lib/mesh/live/spool.js +41 -29
  87. package/dist/lib/sync-core/rollout-state.d.ts +9 -1
  88. package/dist/lib/sync-core/rollout-state.js +34 -4
  89. package/dist/lib/windows/jq.d.ts +4 -0
  90. package/dist/lib/windows/jq.js +10 -39
  91. package/dist/lib/workers-registry/index.js +7 -11
  92. package/dist/utils/callback-port-busy.d.ts +2 -2
  93. package/dist/utils/callback-port-busy.js +2 -2
  94. package/dist/utils/cli-network-lifecycle.js +1 -0
  95. package/dist/utils/client-health-contract.d.ts +2 -0
  96. package/dist/utils/client-health-contract.js +1 -1
  97. package/dist/utils/client-health.js +1 -9
  98. package/dist/utils/cognito-config.js +5 -0
  99. package/dist/utils/cognito-session.d.ts +4 -6
  100. package/dist/utils/cognito-session.js +4 -24
  101. package/dist/utils/incomplete-install-error.js +1 -11
  102. package/dist/utils/install-tree-torn.d.ts +11 -0
  103. package/dist/utils/install-tree-torn.js +1 -1
  104. package/dist/utils/resident-package-preload.js +2 -1
  105. package/docs/anywhere-runtime.md +8 -0
  106. package/package.json +9 -9
package/CHANGELOG.md CHANGED
@@ -2,6 +2,31 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [5.345.241] — 2026-11-20
6
+ - 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
+ - `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.
8
+ - `hq core delegate secrets` (and the secrets step of `hq core delegate run`) now applies the same safeguards as the hq-core helper. It reads secret names from `--env-schema` first, then the project's `.env.schema`, then `prd.json` `metadata.secrets`, and uses the repo's `.env.schema` only when the project declares nothing. In that case the plan names the repo schema and warns. A `metadata.secrets` entry that is not a secret name, a missing `--env-schema` file, or an unreadable schema now stops the step with nothing granted. Before sharing anything, every name is checked against `hq secrets list`; if any name is missing, nothing is shared. Agent and person-uid recipients share through the `grantPrincipal` the grant step recorded, and are refused when there is none.
9
+ - `hq core delegate grant` in transfer mode now grants the same permission on every narrower ACL rule under the project prefix (for example `projects/<name>/design/*`) and verifies each one. Before this change, the recipient kept the older, narrower permission there while the manifest said "granted". `hq core delegate transfer` now uses the delegation id as the Work Mesh session id when no session id is set, which ends the SESSION_OWNER_MISMATCH failures from the shared "delegate" session. It also resolves an email recipient to a person uid and moves project ownership and open stories with `hq mesh project reassign`, recording `confirmed`, `not-registered` or `unconfirmed` the same way the hq-core helper does.
10
+ - Added `hq deploy events enable|list|reply|watch` for the owner side of site events on a deployed app: turn events on or off, list them, reply to a visitor or mark an event handled, and watch for new events as one JSON line each. The watcher keeps a cursor file so a restart does not repeat events, and it signs in again on every poll. Each command takes `--company <slug>` or `--personal`. `hq deploy comments list` now accepts `--personal` to read comments on a personal app. These replace the `/deploy` skill's own copies of these API calls (US-033).
11
+ - When `hq feedback update` cannot store a PR or lane link, the error no longer says the server may not support work links; the server has supported them since October 2026. The error still reports the server's message and the ticket's current state.
12
+ - Run Grok SubagentStop through the native event dispatcher with parity checks for normal output and session bookkeeping; keep opt-in trace diagnostics visible.
13
+ - Give the macOS Claude host canary disposable sign-in directories and report sign-in failures and unrelated sessions separately.
14
+ - Read native Stop inputs through checked Windows handles while keeping store writes disabled; preserve checkpoint blocks and refuse unreadable registries.
15
+ - Refuse untrusted Windows DACL write/delete grants and unsafe session inputs; evaluate Stop against checked session bytes even if its file is replaced.
16
+ - Permit default Windows ancestor create-child grants while rejecting replacement rights; respect ordered DACL denies and isolate Windows fixtures from shared CI scratch permissions.
17
+ - hq-hook on Windows: credential checks no longer hang on drive paths when realpath is unavailable; unresolved paths are refused and credential blocking stays on. Drive prefixes survive path normalization, settings scripts resolve under verbatim roots, and the six Windows unit failures are fixed.
18
+ - Allow read-only `hq sync pull` with `HQ_API_KEY`, an explicit company UID and trusted `--company-slug`, without a Cognito session. Validate complete inventory before staging downloads and preserve unlisted local files.
19
+ - `hq mesh daemon status` reports the mesh service as running when `hq daemon` runs it, on macOS, Linux and Windows, instead of saying the retired `ai.getindigo.hq-mesh-daemon` unit is not installed. It still reports the retired unit on an install where `hq daemon` does not run the mesh service.
20
+ - In direct mode the Work Mesh service now writes one log line when a delivery cycle finds queued events and claims none of them, naming the reason (HQ Anywhere switched off by the operator, or HQ Anywhere reading as off for the person or machine with no queued event from a company-bound session) and the queued count. The line is written once per reason and again after a cycle that delivered something, and the reason is also kept in the service's last flush result.
21
+ - Work Mesh live reporting no longer deletes queued events when a queue file cannot be read. A claim file the flush cannot read, or whose events cannot be put back on the spool, is now kept and retried on the next flush, and claim files are read in chunks so a very large one still loads. `hq mesh emit` and the emit retry path no longer replace `emit-retry.jsonl` after a failed read: unsent events are appended to it, the failure is logged, and `hq mesh daemon doctor` reports the file as unreadable.
22
+ - Make the `hq doctor --fix` refresh spawn lock takeover atomic, so two processes can no longer both take over a dead holder's lock.
23
+ - Drain stdin in the skill command script test fixture so the shell parity check gets the fixture's result.
24
+ - Stop manual sync with a clear error when the sync engine rollout state is unreadable or invalid, protecting vaults from being synced by the wrong engine.
25
+ - `hq sync pull --all`, `hq sync push --all` and the single-company sync commands skip a company whose sync scope lookup fails, with a short message naming the company and the error class, instead of syncing it unscoped. Other companies keep syncing, and the run still exits 1. A lookup refused for sign-in reasons shows the sign-in fix. This takes @indigoai-us/hq-cloud 6.18.117, whose scope resolver now fails closed instead of answering "all" on a failed lookup.
26
+ - Fixed Outpost lane commands and generated worktree-pruner services to call `hq runners`, while retaining the `hq lanes` compatibility alias and scheduled-run classification for pruner timers.
27
+ - Windows hook acceptance checks can load Beaker trial reports for the exact tested commit. A submitted report now fails on missing acceptance evidence (corpus, both architectures, signed-off engine timings) and prints failed native event outcomes; only an absent report stays pending.
28
+ - Preserve literal backslashes and quotes in generated worker registry paths and metadata.
29
+
5
30
  ## [5.345.238] — 2026-11-19
6
31
  - Publish the warm CLI test fixture atomically before executing it on Unix.
7
32
  - Internal: The hq-hook PR test shards run under cargo-nextest, one process per test across all cores.
@@ -60,7 +60,13 @@ REPO_REL="$(jq -r '.repo.path // empty' "$MANIFEST")"
60
60
  BRANCH="$(jq -r '.repo.branch // empty' "$MANIFEST")"
61
61
  [ -n "$REPO_REL" ] || die "manifest repo block has no path"
62
62
 
63
- REPO_DIR="$HQ_ROOT/$REPO_REL"
63
+ # repo.path is HQ-root-relative (repos/private/x) or, for a project whose PRD
64
+ # names a repo outside the HQ tree, absolute (feedback_6ea99712). Prefixing the
65
+ # root to an absolute path produced "<root>//Users/...".
66
+ case "$REPO_REL" in
67
+ /*|[A-Za-z]:[\\/]*) REPO_DIR="$REPO_REL" ;;
68
+ *) REPO_DIR="$HQ_ROOT/$REPO_REL" ;;
69
+ esac
64
70
  [ -d "$REPO_DIR/.git" ] || git -C "$REPO_DIR" rev-parse --git-dir >/dev/null 2>&1 \
65
71
  || die "not a git repository: $REPO_DIR"
66
72
 
@@ -9,13 +9,19 @@
9
9
  # [--env-schema <path>]
10
10
  #
11
11
  # Behavior:
12
- # - derives required secret NAMES from the project's / repo's .env.schema
13
- # (--env-schema overrides discovery); no schema -> records secrets: []
14
- # and says so plainly rather than guessing at credentials
12
+ # - derives required secret NAMES from, in order: --env-schema, the project
13
+ # folder's .env.schema, prd.json metadata.secrets, then the repo's
14
+ # .env.schema (the widest source, used only when the project declares
15
+ # nothing); no source -> records secrets: [] and says so plainly rather
16
+ # than guessing at credentials. The plan output names the source.
17
+ # - before sharing anything, every name is checked against
18
+ # `hq secrets list --company <co>` (names only); one missing name aborts
19
+ # the whole step with nothing shared
15
20
  # - without --yes: prints a full-prose confirmation listing every name and
16
21
  # the principal, then exits 2 granting nothing — this step is a privilege
17
22
  # handover and gets its own confirmation, separate from the file grants
18
- # - with --yes: hq secrets share <NAME> --with <principal> --permission read
23
+ # - with --yes: hq secrets --company <co> share <NAME> --with <principal>
24
+ # --permission read (agent/person uids use the grant step's grantPrincipal)
19
25
  # per name, then records the names (and only the names) in the manifest
20
26
  # - --no-secrets: skips everything, records {secrets: [], secretsSkipped: true}
21
27
  #
@@ -57,6 +63,23 @@ PROJECT="$(jq -r '.project.name // empty' "$MANIFEST")"
57
63
  [ -n "$COMPANY" ] || die "manifest has no company"
58
64
  [ -n "$PRINCIPAL" ] || die "manifest has no to.principal"
59
65
 
66
+ # Secret-ACL principals must be an email, grp_<id>, out_<id>, or @all. An
67
+ # agent (agt_...) or person uid (prs_...) is rejected by `hq secrets share`, so
68
+ # share with the principal the grant step resolved and recorded in
69
+ # .grantPrincipal: the per-agent delegation group (grp_dlg...) for an agent,
70
+ # the mapped email for a person uid. The grant step runs first.
71
+ SHARE_PRINCIPAL="$PRINCIPAL"
72
+ case "$PRINCIPAL" in
73
+ agt_*|prs_*)
74
+ RECORDED="$(jq -r '.grantPrincipal // empty' "$MANIFEST" | tr -d '\r')"
75
+ case "$PRINCIPAL:$RECORDED" in
76
+ agt_*:grp_dlg*) SHARE_PRINCIPAL="$RECORDED" ;;
77
+ prs_*:?*@?*) SHARE_PRINCIPAL="$RECORDED" ;;
78
+ *) SHARE_PRINCIPAL="" ;;
79
+ esac
80
+ ;;
81
+ esac
82
+
60
83
  update_manifest() { # jq-filter
61
84
  local tmp
62
85
  tmp="$(mktemp)"
@@ -73,27 +96,46 @@ fi
73
96
 
74
97
  # --- discover the env schema --------------------------------------------------
75
98
 
76
- if [ -z "$ENV_SCHEMA" ]; then
99
+ # Narrowest declaration first. A project-scoped source (the project folder's
100
+ # .env.schema or prd.json metadata.secrets) names what this lane needs; the
101
+ # repo's .env.schema names everything the whole repo needs and is only used
102
+ # when the project declares nothing.
103
+ SOURCE_KIND="" SOURCE_PATH="" NAMES=""
104
+ NAME_RE='^[A-Z][A-Z0-9_]*(/[A-Z][A-Z0-9_]+)*$'
105
+ names_from_schema() { # schema-path -> stdout (KEY= lines; comments and blanks ignored)
106
+ grep -E '^[A-Z][A-Z0-9_]*(/[A-Z][A-Z0-9_]+)*=' "$1" | cut -d= -f1 | sort -u
107
+ }
108
+ PROJECT_DIR="$HQ_ROOT/companies/$COMPANY/projects/$PROJECT"
109
+ if [ -n "$ENV_SCHEMA" ]; then
110
+ [ -f "$ENV_SCHEMA" ] || die "--env-schema not found: $ENV_SCHEMA"
111
+ SOURCE_KIND="--env-schema"; SOURCE_PATH="$ENV_SCHEMA"
112
+ NAMES="$(names_from_schema "$ENV_SCHEMA")"
113
+ elif [ -f "$PROJECT_DIR/.env.schema" ]; then
114
+ SOURCE_KIND="project .env.schema"; SOURCE_PATH="$PROJECT_DIR/.env.schema"
115
+ NAMES="$(names_from_schema "$SOURCE_PATH")"
116
+ elif [ -f "$PROJECT_DIR/prd.json" ] \
117
+ && jq -e '(.metadata.secrets // null) | type == "array" and length > 0' "$PROJECT_DIR/prd.json" >/dev/null 2>&1; then
118
+ SOURCE_KIND="prd.json metadata.secrets"; SOURCE_PATH="$PROJECT_DIR/prd.json"
119
+ NAMES="$(jq -r '.metadata.secrets[] | if type == "object" then (.name // empty) else . end' "$SOURCE_PATH" | sort -u)"
120
+ BAD="$(printf '%s\n' "$NAMES" | grep -v -E "$NAME_RE" || true)"
121
+ [ -z "$BAD" ] || die "prd.json metadata.secrets has an entry that is not a secret name: $(printf '%s' "$BAD" | tr '\n' ' ')— nothing granted"
122
+ else
77
123
  REPO_REL="$(jq -r '.repo.path // empty' "$MANIFEST")"
78
- for candidate in \
79
- "$HQ_ROOT/companies/$COMPANY/projects/$PROJECT/.env.schema" \
80
- "${REPO_REL:+$HQ_ROOT/$REPO_REL/.env.schema}"; do
81
- [ -n "$candidate" ] && [ -f "$candidate" ] && { ENV_SCHEMA="$candidate"; break; }
82
- done
124
+ if [ -n "$REPO_REL" ] && [ -f "$HQ_ROOT/$REPO_REL/.env.schema" ]; then
125
+ SOURCE_KIND="repo .env.schema"; SOURCE_PATH="$HQ_ROOT/$REPO_REL/.env.schema"
126
+ NAMES="$(names_from_schema "$SOURCE_PATH")"
127
+ fi
83
128
  fi
84
129
 
85
- if [ -z "$ENV_SCHEMA" ] || [ ! -f "$ENV_SCHEMA" ]; then
130
+ if [ -z "$SOURCE_PATH" ]; then
86
131
  update_manifest '.secrets = [] | .secretsSkipped = false'
87
- echo "hq-delegate-secrets: no .env.schema found for this project or its repo — no secret names to grant. If the project needs credentials, add an .env.schema and re-run, or grant them manually with 'hq secrets share'."
132
+ echo "hq-delegate-secrets: no .env.schema found for this project or its repo, and prd.json declares no metadata.secrets — no secret names to grant. If the project needs credentials, add a project .env.schema (or prd.json metadata.secrets) and re-run, or grant them manually with 'hq secrets share'."
88
133
  exit 0
89
134
  fi
90
135
 
91
- # --- parse names (KEY= lines; comments and blanks ignored) --------------------
92
-
93
- NAMES="$(grep -E '^[A-Z][A-Z0-9_]*(/[A-Z][A-Z0-9_]+)*=' "$ENV_SCHEMA" | cut -d= -f1 | sort -u)"
94
136
  if [ -z "$NAMES" ]; then
95
137
  update_manifest '.secrets = [] | .secretsSkipped = false'
96
- echo "hq-delegate-secrets: $ENV_SCHEMA declares no secret names — nothing to grant"
138
+ echo "hq-delegate-secrets: $SOURCE_PATH declares no secret names — nothing to grant"
97
139
  exit 0
98
140
  fi
99
141
  NAME_COUNT="$(printf '%s\n' "$NAMES" | wc -l | tr -d ' ')"
@@ -102,10 +144,23 @@ NAME_COUNT="$(printf '%s\n' "$NAMES" | wc -l | tr -d ' ')"
102
144
 
103
145
  echo "Secret access handover — this grants the recipient the ability to use these credentials."
104
146
  echo
105
- echo "The following $NAME_COUNT secret name(s), declared by $(basename "$ENV_SCHEMA") for project '$PROJECT', will be shared with read permission to '$PRINCIPAL' in company '$COMPANY':"
147
+ echo "Source: $SOURCE_KIND ($SOURCE_PATH)"
148
+ if [ "$SOURCE_KIND" = "repo .env.schema" ]; then
149
+ echo "The project declares no secrets of its own, so the repo-wide schema is used. Narrow it with a project .env.schema or prd.json metadata.secrets if the lane needs fewer."
150
+ fi
151
+ echo
152
+ echo "The following $NAME_COUNT secret name(s), declared by $(basename "$SOURCE_PATH") for project '$PROJECT', will be shared with read permission to '$PRINCIPAL' in company '$COMPANY':"
106
153
  echo
107
154
  printf '%s\n' "$NAMES" | sed 's/^/ - /'
108
155
  echo
156
+ if [ "$SHARE_PRINCIPAL" != "$PRINCIPAL" ]; then
157
+ if [ -n "$SHARE_PRINCIPAL" ]; then
158
+ echo "Access flows through '$SHARE_PRINCIPAL', the principal the grant step resolved for '$PRINCIPAL'."
159
+ else
160
+ echo "Access will flow through the principal the grant step records for '$PRINCIPAL' (run hq-delegate-grant.sh --yes first)."
161
+ fi
162
+ echo
163
+ fi
109
164
  echo "Only the names are granted and recorded; no secret value is read, printed, or transmitted by this step. The recipient consumes them through 'hq run' / 'hq secrets exec'."
110
165
 
111
166
  if [ "$YES" -ne 1 ]; then
@@ -116,10 +171,30 @@ fi
116
171
 
117
172
  # --- grant each name (names only — never a value read) ------------------------
118
173
 
174
+ [ -n "$SHARE_PRINCIPAL" ] \
175
+ || die "recipient '$PRINCIPAL' cannot be a secret-ACL principal and the manifest has no usable grantPrincipal — run hq-delegate-grant.sh --yes first; nothing granted"
176
+
177
+ # Every name must exist in the company vault before any share runs, so a
178
+ # typo or an undeclared secret never leaves a partial grant behind. Names
179
+ # only: `hq secrets list` prints no values.
180
+ LISTED="$(hq secrets list --company "$COMPANY" 2>/dev/null)" \
181
+ || die "could not list secret names for company '$COMPANY' (hq secrets list failed) — nothing granted"
182
+ MISSING=""
183
+ while IFS= read -r name; do
184
+ [ -n "$name" ] || continue
185
+ printf '%s\n' "$LISTED" | awk -v n="$name" '$1 == n { found = 1 } END { exit !found }' \
186
+ || MISSING="$MISSING $name"
187
+ done <<EOF
188
+ $NAMES
189
+ EOF
190
+ if [ -n "$MISSING" ]; then
191
+ die "these name(s) from $SOURCE_KIND do not exist in company '$COMPANY':${MISSING} — nothing granted; add them with 'hq secrets set' or remove them from $SOURCE_PATH, then re-run"
192
+ fi
193
+
119
194
  printf '%s\n' "$NAMES" | while IFS= read -r name; do
120
- hq secrets share "$name" --with "$PRINCIPAL" --permission read --company "$COMPANY" \
121
- || die "failed to grant '$name' to '$PRINCIPAL' — aborting; manifest not updated"
122
- echo "hq-delegate-secrets: granted read on '$name' to '$PRINCIPAL'"
195
+ hq secrets --company "$COMPANY" share "$name" --with "$SHARE_PRINCIPAL" --permission read \
196
+ || die "failed to grant '$name' to '$SHARE_PRINCIPAL' — aborting; manifest not updated"
197
+ echo "hq-delegate-secrets: granted read on '$name' to '$SHARE_PRINCIPAL'"
123
198
  done
124
199
 
125
200
  NAMES_JSON="$(printf '%s\n' "$NAMES" | jq -R . | jq -cs .)"
@@ -14,9 +14,11 @@
14
14
  # 2. prd.json metadata gains owner, delegatedFrom, delegatedAt; for a
15
15
  # brainstorm-stage project the same three keys land in the
16
16
  # brainstorm.md frontmatter (owner, delegated_from, delegated_at)
17
- # 3. work-mesh: `done` event closes the delegator's in-progress thread and
18
- # broadcasts the reassignment; silently skipped when the helper is
19
- # unavailable (local/offline installs) — the transfer still succeeds
17
+ # 3. work-mesh: a thread note broadcasts the reassignment and
18
+ # `hq mesh project reassign` transfers project ownership and the
19
+ # delegator's open stories; manifest workMeshOwnership becomes
20
+ # "confirmed" only on a server receipt naming the recipient. Silently
21
+ # skipped when hq is unavailable — the transfer still succeeds
20
22
  # 4. a dated "Delegated" stanza is appended to the project journal naming
21
23
  # the recipient, delegation id, and transferred scope
22
24
  #
@@ -166,17 +168,63 @@ else
166
168
  fi
167
169
 
168
170
  # --- 3. work mesh: close the delegator's thread, broadcast reassignment ------
171
+ MESH_OWNERSHIP="unconfirmed"
172
+ TO_UID="$(jq -r '.to.uid // .to.personUid // .to.agentUid // .to.principal // empty' "$MANIFEST")"
173
+ MESH_PROJECT="$PROJECT"
174
+ if [ "$STAGE" = prd ]; then
175
+ MESH_PROJECT="$(jq -r --arg p "$PROJECT" '.metadata.workMeshProjectId // .metadata.projectId // $p' "$PRD_ABS" 2>/dev/null || printf '%s' "$PROJECT")"
176
+ fi
169
177
  # Silently tolerated when unavailable (local/offline installs no-op).
170
178
 
171
179
  if command -v hq >/dev/null 2>&1; then
172
180
  # `--session-id` is the CLI option (hq-cli 5.157+ rejects `--session` with
173
181
  # "unknown option"); --company-slug/--project attribute the note to the
174
182
  # delegated project.
175
- hq mesh session note --enqueue --session-id "${HQ_SESSION_ID:-delegate}" --seq 1 \
183
+ #
184
+ # The session id must be unique per delegation. The mesh keys session
185
+ # ownership on (company, sessionId): a shared literal such as "delegate" is
186
+ # owned by whoever ran the first delegation in the company, and every later
187
+ # delegator is rejected with SESSION_OWNER_MISMATCH even as company owner.
188
+ MESH_SESSION_ID="${HQ_SESSION_ID:-$DELEGATION_ID}"
189
+ hq mesh session note --enqueue --session-id "$MESH_SESSION_ID" --seq 1 \
176
190
  --harness claude-code --adapter-version 1.0.0 \
177
191
  --company-slug "$COMPANY" --project "$PROJECT" \
178
192
  --summary "Delegated to $DISPLAY ($PRINCIPAL) — delegation $DELEGATION_ID; ownership transferred" \
179
193
  || echo "hq-delegate-transfer: mesh note failed; authoritative mesh ownership remains unconfirmed" >&2
194
+
195
+ # Authoritative transfer: `hq mesh project reassign` moves project thread
196
+ # ownership and the delegator's open stories to the recipient. Confirmed only
197
+ # when the server answers with the recipient as owner; an older CLI or server
198
+ # (unknown command, 404) leaves ownership "unconfirmed" and the run continues.
199
+ # PROJECT_VIEW_NOT_FOUND or PROJECT_THREAD_NOT_FOUND (any stage, PRD or
200
+ # brainstorm) means the project was never registered on the board:
201
+ # there is nothing to reassign, so that is "not-registered", not "unconfirmed".
202
+ # The mesh directory matches uids, not emails. A recipient resolved by
203
+ # hq-delegate-resolve.sh is often known only by email, so look up the
204
+ # personUid from company membership first. If that fails, the email is
205
+ # passed through and the reassign reports unconfirmed as before.
206
+ case "$TO_UID" in
207
+ *@*)
208
+ RESOLVED_UID="$(hq people resolve "$TO_UID" --company "$COMPANY" --membership-only --json 2>/dev/null \
209
+ | jq -r 'select(.status == "found") | .person.personUid // empty' 2>/dev/null || true)"
210
+ case "$RESOLVED_UID" in prs_*) TO_UID="$RESOLVED_UID" ;; esac
211
+ ;;
212
+ esac
213
+ REASSIGN_ERR="$(mktemp)"
214
+ REASSIGN_OUT="$(hq mesh project reassign "$MESH_PROJECT" --company "$COMPANY" \
215
+ --to "$TO_UID" --include-open-stories \
216
+ --note "Delegated via /delegate ($DELEGATION_ID)" --json 2>"$REASSIGN_ERR" || true)"
217
+ REASSIGN_ERR_TEXT="$(cat "$REASSIGN_ERR" 2>/dev/null || true)"
218
+ rm -f "$REASSIGN_ERR"
219
+ if printf '%s' "$REASSIGN_OUT" | jq -e --arg to "$TO_UID" \
220
+ '(.ok != false) and ((.ownerUid // "") != "") and ((.ownerUid == $to) or ($to | test("@")))' >/dev/null 2>&1; then
221
+ MESH_OWNERSHIP="confirmed"
222
+ elif printf '%s\n%s' "$REASSIGN_OUT" "$REASSIGN_ERR_TEXT" | grep -Eq 'PROJECT_(VIEW|THREAD)_NOT_FOUND'; then
223
+ MESH_OWNERSHIP="not-registered"
224
+ echo "hq-delegate-transfer: project $MESH_PROJECT has no Work Mesh board; local ownership is authoritative; nothing to reassign. To track it on the board, register it with \`hq mesh project register\` (see \`hq mesh project --help\`)" >&2
225
+ else
226
+ echo "hq-delegate-transfer: hq mesh project reassign did not confirm; Work Mesh ownership remains unconfirmed" >&2
227
+ fi
180
228
  fi
181
229
 
182
230
  # --- 4. journal: one dated stanza per delegation id --------------------------
@@ -203,9 +251,9 @@ if ! grep -qF "$DELEGATION_ID" "$JOURNAL_FILE"; then
203
251
  echo "- To: $DISPLAY ($PRINCIPAL)"
204
252
  echo "- Transferred scope: $SCOPE"
205
253
  if [ "$STAGE" = prd ]; then
206
- echo "- Local board and PRD ownership updated; Work Mesh ownership is unconfirmed. Existing delegator access is unchanged."
254
+ echo "- Local board and PRD ownership updated; Work Mesh ownership is $MESH_OWNERSHIP. Existing delegator access is unchanged."
207
255
  else
208
- echo "- Brainstorm-stage project (no PRD yet). Local board and brainstorm.md ownership updated; Work Mesh ownership is unconfirmed. Existing delegator access is unchanged."
256
+ echo "- Brainstorm-stage project (no PRD yet). Local board and brainstorm.md ownership updated; Work Mesh ownership is $MESH_OWNERSHIP. Existing delegator access is unchanged."
209
257
  fi
210
258
  } >> "$JOURNAL_FILE"
211
259
  fi
@@ -213,11 +261,11 @@ fi
213
261
  # --- record on the manifest ---------------------------------------------------
214
262
 
215
263
  TMP_MANIFEST="$(mktemp)"
216
- jq --arg now "$NOW" '.ownershipTransferredAt = $now | .workMeshOwnership = "unconfirmed"' "$MANIFEST" > "$TMP_MANIFEST" \
264
+ jq --arg now "$NOW" --arg mesh "$MESH_OWNERSHIP" '.ownershipTransferredAt = $now | .workMeshOwnership = $mesh' "$MANIFEST" > "$TMP_MANIFEST" \
217
265
  && mv "$TMP_MANIFEST" "$MANIFEST"
218
266
 
219
267
  if [ "$STAGE" = prd ]; then
220
- echo "hq-delegate-transfer: ownership of '$PROJECT' transferred to $DISPLAY ($PRINCIPAL) — local board, PRD, and journal updated; Work Mesh ownership unconfirmed"
268
+ echo "hq-delegate-transfer: ownership of '$PROJECT' transferred to $DISPLAY ($PRINCIPAL) — local board, PRD, and journal updated; Work Mesh ownership $MESH_OWNERSHIP"
221
269
  else
222
- echo "hq-delegate-transfer: ownership of '$PROJECT' (brainstorm stage) transferred to $DISPLAY ($PRINCIPAL) — local board, brainstorm.md, and journal updated; Work Mesh ownership unconfirmed"
270
+ echo "hq-delegate-transfer: ownership of '$PROJECT' (brainstorm stage) transferred to $DISPLAY ($PRINCIPAL) — local board, brainstorm.md, and journal updated; Work Mesh ownership $MESH_OWNERSHIP"
223
271
  fi
@@ -943,6 +943,10 @@ export declare const COMMAND_CATALOG: readonly [{
943
943
  readonly helpText: readonly [];
944
944
  readonly arguments: readonly [];
945
945
  readonly options: readonly [{
946
+ readonly flags: "--company-slug <slug>";
947
+ readonly description: "Trusted local layout slug; required with HQ_API_KEY and --company cmp_…";
948
+ readonly hidden: false;
949
+ }, {
946
950
  readonly flags: "--hq-root <path>";
947
951
  readonly description: "Local HQ tree root (default: <runtime-path>)";
948
952
  readonly hidden: false;
@@ -8620,7 +8624,7 @@ export declare const COMMAND_CATALOG: readonly [{
8620
8624
  readonly arguments: readonly [];
8621
8625
  readonly options: readonly [{
8622
8626
  readonly flags: "--size <size>";
8623
- readonly description: "Outpost size: small | medium | large | xlarge. Without it, a terminal shows a menu with prices and medium preselected; a script gets the default, $100/month";
8627
+ readonly description: "Outpost size: small | medium | large | xlarge. Without it, a terminal shows a menu with prices and small ($100/month) preselected; a script sends no size and is billed the small price";
8624
8628
  readonly hidden: false;
8625
8629
  }, {
8626
8630
  readonly flags: "--runtime <runtime>";
@@ -8696,7 +8700,7 @@ export declare const COMMAND_CATALOG: readonly [{
8696
8700
  readonly hidden: false;
8697
8701
  }, {
8698
8702
  readonly flags: "--size <size>";
8699
- readonly description: "small, medium, large or xlarge (the server default is medium)";
8703
+ readonly description: "small, medium, large or xlarge (without it, the Outpost is billed the small price, $100/month)";
8700
8704
  readonly hidden: false;
8701
8705
  }, {
8702
8706
  readonly flags: "--note <text>";
@@ -21626,7 +21630,7 @@ export declare const COMMAND_CATALOG: readonly [{
21626
21630
  readonly options: readonly [];
21627
21631
  readonly subcommands: readonly [{
21628
21632
  readonly name: "list";
21629
- readonly description: "List comments on an app in your org";
21633
+ readonly description: "List comments on an app in your org, or on a personal app with --personal";
21630
21634
  readonly aliases: readonly [];
21631
21635
  readonly hidden: false;
21632
21636
  readonly helpOption: true;
@@ -21643,6 +21647,10 @@ export declare const COMMAND_CATALOG: readonly [{
21643
21647
  readonly flags: "--company <slug>";
21644
21648
  readonly description: "use this company instead of the active company";
21645
21649
  readonly hidden: false;
21650
+ }, {
21651
+ readonly flags: "--personal";
21652
+ readonly description: "read a personal app (personal deploy scope) instead of a company app";
21653
+ readonly hidden: false;
21646
21654
  }, {
21647
21655
  readonly flags: "--json";
21648
21656
  readonly description: "print the API comment array as JSON";
@@ -21715,6 +21723,180 @@ export declare const COMMAND_CATALOG: readonly [{
21715
21723
  }];
21716
21724
  readonly subcommands: readonly [];
21717
21725
  }];
21726
+ }, {
21727
+ readonly name: "events";
21728
+ readonly description: "Read and answer site events that visitors send from your deployed apps";
21729
+ readonly aliases: readonly [];
21730
+ readonly hidden: false;
21731
+ readonly helpOption: true;
21732
+ readonly helpCommand: true;
21733
+ readonly usage: "[options] [command]";
21734
+ readonly helpText: readonly [];
21735
+ readonly arguments: readonly [];
21736
+ readonly options: readonly [];
21737
+ readonly subcommands: readonly [{
21738
+ readonly name: "enable";
21739
+ readonly description: "Turn site events on (or off with --off) for an app";
21740
+ readonly aliases: readonly [];
21741
+ readonly hidden: false;
21742
+ readonly helpOption: true;
21743
+ readonly helpCommand: false;
21744
+ readonly usage: "[options] <app-id>";
21745
+ readonly helpText: readonly [];
21746
+ readonly arguments: readonly [{
21747
+ readonly name: "app-id";
21748
+ readonly required: true;
21749
+ readonly variadic: false;
21750
+ readonly description: "";
21751
+ }];
21752
+ readonly options: readonly [{
21753
+ readonly flags: "--company <slug>";
21754
+ readonly description: "company owning the app";
21755
+ readonly hidden: false;
21756
+ }, {
21757
+ readonly flags: "--personal";
21758
+ readonly description: "use personal scope";
21759
+ readonly hidden: false;
21760
+ }, {
21761
+ readonly flags: "--off";
21762
+ readonly description: "turn site events off; stored events are kept";
21763
+ readonly hidden: false;
21764
+ }, {
21765
+ readonly flags: "--json";
21766
+ readonly description: "print {ok, appId, eventsEnabled} as JSON";
21767
+ readonly hidden: false;
21768
+ }];
21769
+ readonly subcommands: readonly [];
21770
+ }, {
21771
+ readonly name: "list";
21772
+ readonly description: "List site events on an app";
21773
+ readonly aliases: readonly [];
21774
+ readonly hidden: false;
21775
+ readonly helpOption: true;
21776
+ readonly helpCommand: false;
21777
+ readonly usage: "[options] <app-id>";
21778
+ readonly helpText: readonly [];
21779
+ readonly arguments: readonly [{
21780
+ readonly name: "app-id";
21781
+ readonly required: true;
21782
+ readonly variadic: false;
21783
+ readonly description: "";
21784
+ }];
21785
+ readonly options: readonly [{
21786
+ readonly flags: "--company <slug>";
21787
+ readonly description: "company owning the app";
21788
+ readonly hidden: false;
21789
+ }, {
21790
+ readonly flags: "--personal";
21791
+ readonly description: "use personal scope";
21792
+ readonly hidden: false;
21793
+ }, {
21794
+ readonly flags: "--after <event-id>";
21795
+ readonly description: "only events after this event id";
21796
+ readonly hidden: false;
21797
+ }, {
21798
+ readonly flags: "--status <status>";
21799
+ readonly description: "new or handled";
21800
+ readonly hidden: false;
21801
+ }, {
21802
+ readonly flags: "--limit <n>";
21803
+ readonly description: "maximum number of events";
21804
+ readonly hidden: false;
21805
+ }, {
21806
+ readonly flags: "--json";
21807
+ readonly description: "print the API response ({events, nextAfter}) as JSON";
21808
+ readonly hidden: false;
21809
+ }];
21810
+ readonly subcommands: readonly [];
21811
+ }, {
21812
+ readonly name: "reply";
21813
+ readonly description: "Reply to a site event and/or set its status";
21814
+ readonly aliases: readonly [];
21815
+ readonly hidden: false;
21816
+ readonly helpOption: true;
21817
+ readonly helpCommand: false;
21818
+ readonly usage: "[options] <app-id> <event-id>";
21819
+ readonly helpText: readonly [];
21820
+ readonly arguments: readonly [{
21821
+ readonly name: "app-id";
21822
+ readonly required: true;
21823
+ readonly variadic: false;
21824
+ readonly description: "";
21825
+ }, {
21826
+ readonly name: "event-id";
21827
+ readonly required: true;
21828
+ readonly variadic: false;
21829
+ readonly description: "";
21830
+ }];
21831
+ readonly options: readonly [{
21832
+ readonly flags: "--company <slug>";
21833
+ readonly description: "company owning the app";
21834
+ readonly hidden: false;
21835
+ }, {
21836
+ readonly flags: "--personal";
21837
+ readonly description: "use personal scope";
21838
+ readonly hidden: false;
21839
+ }, {
21840
+ readonly flags: "--text <reply>";
21841
+ readonly description: "reply text the page shows";
21842
+ readonly hidden: false;
21843
+ }, {
21844
+ readonly flags: "--status <status>";
21845
+ readonly description: "new or handled";
21846
+ readonly hidden: false;
21847
+ }, {
21848
+ readonly flags: "--json";
21849
+ readonly description: "print {ok, id, status, reply} as JSON";
21850
+ readonly hidden: false;
21851
+ }];
21852
+ readonly subcommands: readonly [];
21853
+ }, {
21854
+ readonly name: "watch";
21855
+ readonly description: "Poll for new site events and print one JSON line per event";
21856
+ readonly aliases: readonly [];
21857
+ readonly hidden: false;
21858
+ readonly helpOption: true;
21859
+ readonly helpCommand: false;
21860
+ readonly usage: "[options] <app-id>";
21861
+ readonly helpText: readonly [];
21862
+ readonly arguments: readonly [{
21863
+ readonly name: "app-id";
21864
+ readonly required: true;
21865
+ readonly variadic: false;
21866
+ readonly description: "";
21867
+ }];
21868
+ readonly options: readonly [{
21869
+ readonly flags: "--company <slug>";
21870
+ readonly description: "company owning the app";
21871
+ readonly hidden: false;
21872
+ }, {
21873
+ readonly flags: "--personal";
21874
+ readonly description: "use personal scope";
21875
+ readonly hidden: false;
21876
+ }, {
21877
+ readonly flags: "--cursor-file <path>";
21878
+ readonly description: "file that stores the last reported event id";
21879
+ readonly hidden: false;
21880
+ }, {
21881
+ readonly flags: "--label <name>";
21882
+ readonly description: "name used in the output lines (default: the app id)";
21883
+ readonly hidden: false;
21884
+ }, {
21885
+ readonly flags: "--interval <seconds>";
21886
+ readonly description: "seconds between polls, at least 30";
21887
+ readonly hidden: false;
21888
+ readonly defaultValue: "30";
21889
+ }, {
21890
+ readonly flags: "--status <status>";
21891
+ readonly description: "new or handled (default: new)";
21892
+ readonly hidden: false;
21893
+ }, {
21894
+ readonly flags: "--once";
21895
+ readonly description: "poll once and exit";
21896
+ readonly hidden: false;
21897
+ }];
21898
+ readonly subcommands: readonly [];
21899
+ }];
21718
21900
  }, {
21719
21901
  readonly name: "list";
21720
21902
  readonly description: "List deploy apps in your company, optionally filtered by name or subdomain";