@indigoai-us/hq-cli 5.345.255 → 5.345.258

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 (63) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/README.md +21 -0
  3. package/assets/scaffold/core/scripts/handoff-finalize.sh +981 -46
  4. package/assets/scaffold/core/scripts/hq-delegate-bundle.sh +51 -2
  5. package/assets/scaffold/core/scripts/hq-delegate-send.sh +49 -6
  6. package/assets/scaffold/core/scripts/hq-delegate-transfer.sh +20 -0
  7. package/assets/scaffold/core/scripts/hq-delegate-verify.sh +56 -10
  8. package/assets/scaffold/core/scripts/lib/fingerprint.sh +423 -0
  9. package/assets/scaffold/core/scripts/rebuild-companies-index.sh +10 -1
  10. package/assets/scaffold/core/scripts/rebuild-company-knowledge-index.sh +10 -1
  11. package/assets/scaffold/core/scripts/rebuild-projects-index.sh +10 -1
  12. package/assets/scaffold/core/scripts/register-project.sh +110 -19
  13. package/contracts/host-canary-release.json +7 -7
  14. package/dist/command-catalog.generated.d.ts +1 -1
  15. package/dist/command-catalog.generated.js +1 -1
  16. package/dist/commands/cloud.js +4 -1
  17. package/dist/commands/core-delegate-w1b.js +107 -16
  18. package/dist/commands/core-delegate.d.ts +7 -0
  19. package/dist/commands/core-delegate.js +66 -2
  20. package/dist/commands/core-handoff-fast.d.ts +1 -1
  21. package/dist/commands/core-handoff-fast.js +2 -2
  22. package/dist/commands/core-handoff.d.ts +3 -1
  23. package/dist/commands/core-handoff.js +1407 -177
  24. package/dist/commands/core-register-project-native.js +1 -1
  25. package/dist/commands/core.js +2 -2
  26. package/dist/commands/files.d.ts +2 -0
  27. package/dist/commands/files.js +34 -5
  28. package/dist/commands/keyed-sync-pull.d.ts +7 -3
  29. package/dist/commands/keyed-sync-pull.js +90 -22
  30. package/dist/commands/team-sync.js +1 -1
  31. package/dist/lib/company-skill-wrapper.js +72 -4
  32. package/dist/lib/daemon/requests.d.ts +14 -1
  33. package/dist/lib/daemon/requests.js +17 -3
  34. package/dist/lib/daemon/run.js +44 -2
  35. package/dist/lib/daemon/supervisor.d.ts +11 -0
  36. package/dist/lib/daemon/supervisor.js +33 -0
  37. package/dist/lib/daemon/sync-perf-telemetry.d.ts +85 -0
  38. package/dist/lib/daemon/sync-perf-telemetry.js +206 -0
  39. package/dist/lib/daemon/windows-relaunch.d.ts +55 -0
  40. package/dist/lib/daemon/windows-relaunch.js +72 -0
  41. package/dist/lib/doctor/checks/replay-recorder.js +3 -3
  42. package/dist/lib/flag-snapshot-file.d.ts +47 -1
  43. package/dist/lib/flag-snapshot-file.js +143 -20
  44. package/dist/lib/hook-engine/coverage.d.ts +82 -8
  45. package/dist/lib/hook-engine/coverage.js +192 -14
  46. package/dist/lib/index-render/companies.js +3 -2
  47. package/dist/lib/index-render/index.js +2 -1
  48. package/dist/lib/index-render/session-scope.d.ts +2 -3
  49. package/dist/lib/index-render/session-scope.js +2 -5
  50. package/dist/lib/index-render/shared.d.ts +7 -0
  51. package/dist/lib/index-render/shared.js +9 -0
  52. package/dist/lib/mesh/live/company-flag-refresh.js +2 -2
  53. package/dist/lib/work-context/windows-acl.d.ts +14 -0
  54. package/dist/lib/work-context/windows-acl.js +26 -0
  55. package/dist/utils/cli-telemetry.d.ts +26 -7
  56. package/dist/utils/cli-telemetry.js +70 -13
  57. package/dist/utils/git.js +1 -1
  58. package/dist/utils/resident-package-preload.js +4 -0
  59. package/dist/utils/sync-perf-telemetry-flag.d.ts +26 -0
  60. package/dist/utils/sync-perf-telemetry-flag.js +32 -0
  61. package/dist/utils/telemetry-opt-out.d.ts +13 -0
  62. package/dist/utils/telemetry-opt-out.js +19 -0
  63. package/package.json +8 -8
@@ -0,0 +1,423 @@
1
+ # shellcheck shell=bash
2
+ # hq-core: public
3
+ # fingerprint.sh - explicit HQ-Fingerprint trailer for commits that skip hooks.
4
+ #
5
+ # SOURCED, never executed: . "$HQ_ROOT/core/scripts/lib/fingerprint.sh"
6
+ # Bash 3.2 safe, set -euo pipefail safe, no jq/python/node of its own.
7
+ #
8
+ # HQ scripts that commit session work with --no-verify (the run-project
9
+ # orchestrator, handoff-finalize, handoff-knowledge-commit) never reach the
10
+ # commit-msg hook that stamps HQ-Fingerprint, so they pass the trailer to
11
+ # `git commit` themselves. The autosave hook does not: a fingerprint marks
12
+ # work a session produced, never the session saving itself.
13
+ #
14
+ # hq_fingerprint_trailer_args [hq_root]
15
+ # Prints two lines, `--trailer` and `HQ-Fingerprint: <value>`, when
16
+ # `${HQ_FINGERPRINT_BIN:-hq} fingerprint self --json --offline` returns a
17
+ # non-null fingerprint within HQ_FINGERPRINT_TIMEOUT_SECS (default 2).
18
+ # Prints nothing, and returns 0, in every other case: the setting is
19
+ # `enabled: false`, there is no session id, hq is missing or older than
20
+ # HQ_FINGERPRINT_MIN_HQ_CLI, the call times out or fails, the fingerprint
21
+ # is null or malformed, or this git has no --trailer.
22
+ #
23
+ # hq_fingerprint_trailer_load [hq_root]
24
+ # Runs hq_fingerprint_trailer_args and stores its lines in the global
25
+ # array HQ_FINGERPRINT_TRAILER_ARGS (empty when nothing was printed).
26
+ #
27
+ # Calling pattern (use this one everywhere; it keeps the value as one argv
28
+ # word and is safe under `set -u` with an empty array on Bash 3.2):
29
+ #
30
+ # hq_fingerprint_trailer_load "$HQ_ROOT"
31
+ # git commit -m "..." ${HQ_FINGERPRINT_TRAILER_ARGS[@]+"${HQ_FINGERPRINT_TRAILER_ARGS[@]}"}
32
+ #
33
+ # Cost: the builder is a full node boot, so it runs at most once per session
34
+ # however many callers ask. The result is
35
+ # cached in workspace/sessions/<session id>/fingerprint-trailer.cache, keyed by
36
+ # the session id and the hq-cli version. A null or failed result is cached for
37
+ # the rest of the session too, so a later `hq login` takes effect in the next
38
+ # session. The session id comes from the same environment variables, in the
39
+ # same order, as core/scripts/lib/session-id.sh. With no session id there is
40
+ # no cache key, so nothing is printed and the builder never runs.
41
+ #
42
+ # The hq-cli version floor alone does not decide whether hq can build a
43
+ # fingerprint: an install at or above the floor is also probed once, by running
44
+ # the builder, and the answer is cached per hq binary in
45
+ # ~/.hq/cache/fingerprint-cli-<cksum>.cache. The key is the resolved binary
46
+ # path, its mtime and its version, so a new hq install (or reinstall) is probed
47
+ # again; any answer also expires after HQ_FINGERPRINT_CAPABILITY_TTL_SECS
48
+ # (default 86400, 24 h). A negative answer (unknown command, non-zero exit,
49
+ # timeout, no JSON) is cached the same way, so an hq without `hq fingerprint`
50
+ # costs one node boot per install per day across all sessions, not one per
51
+ # session. The cache is per machine rather than per session for exactly that
52
+ # reason: a per-session cache would make every new session pay the boot again.
53
+ # When ~/.hq/cache cannot be written the probe still runs, and the per-session
54
+ # trailer cache still limits it to once per session.
55
+ #
56
+ # hq_fp_cli_version
57
+ # Prints the installed hq-cli version (read from its package.json, no node
58
+ # spawn) and returns 0, or returns 1 when hq is missing or unreadable.
59
+ #
60
+ # hq_fp_cli_capable
61
+ # Returns 0 when the installed hq-cli is at or above the floor and its
62
+ # cached (or fresh) probe says it ships `hq fingerprint`, 1 otherwise.
63
+ # Prints nothing; its only side effect is the per-binary cache file.
64
+ #
65
+ # HQ_FINGERPRINT_BIN overrides the builder command. It is a space-separated
66
+ # command: it is word-split with no quote handling, so it cannot hold a path
67
+ # that contains spaces (put such a binary on PATH or behind a wrapper script).
68
+ # Setting it bypasses the hq-cli version floor and the capability probe; tests
69
+ # and the pre-release live check use it.
70
+ #
71
+ # The setting is read from personal/settings/fingerprint.yaml, then
72
+ # core/settings/fingerprint.yaml (`enabled: true|false`, top-level key only). A
73
+ # missing file or key means enabled. The builder is offline, so no commit path
74
+ # gains a network call.
75
+
76
+ # First hq-cli version that ships `hq fingerprint`. An older install is skipped
77
+ # without spawning anything; a newer one still has to pass the capability probe.
78
+ # PLACEHOLDER: 5.345.131 is not a released builder version. The senior sets the
79
+ # real hq-cli tag here before the hq-core release.
80
+ HQ_FINGERPRINT_MIN_HQ_CLI="5.345.131"
81
+
82
+ HQ_FINGERPRINT_TRAILER_ARGS=()
83
+
84
+ _HQ_FP_LIB_DIR="${BASH_SOURCE[0]%/*}"
85
+ [ "$_HQ_FP_LIB_DIR" != "${BASH_SOURCE[0]}" ] || _HQ_FP_LIB_DIR="."
86
+ _HQ_FP_CACHE_SCHEMA="hq-fingerprint-trailer.v2"
87
+ _HQ_FP_CLI_CACHE_SCHEMA="hq-fingerprint-cli.v1"
88
+
89
+ _hq_fp_yaml_scalar() { # file key
90
+ local line=""
91
+ [ -f "$1" ] || return 1
92
+ line="$(grep -E "^$2:[[:space:]]*" "$1" 2>/dev/null | head -n 1)" || return 1
93
+ [ -n "$line" ] || return 1
94
+ printf '%s' "${line#*:}" | sed -E 's/[[:space:]]*#.*$//; s/^[[:space:]]+//; s/[[:space:]]+$//'
95
+ }
96
+
97
+ _hq_fp_enabled() { # hq_root
98
+ local v=""
99
+ v="$(_hq_fp_yaml_scalar "$1/personal/settings/fingerprint.yaml" enabled)" \
100
+ || v="$(_hq_fp_yaml_scalar "$1/core/settings/fingerprint.yaml" enabled)" \
101
+ || v=""
102
+ v="$(printf '%s' "$v" | tr -d "\"'" | tr '[:upper:]' '[:lower:]')"
103
+ case "$v" in
104
+ false|no|off|0) return 1 ;;
105
+ esac
106
+ return 0
107
+ }
108
+
109
+ # Sets _HQ_FP_SID to the first valid session id in the environment, using the
110
+ # precedence and charset of core/scripts/lib/session-id.sh. Returns 1 when none.
111
+ _hq_fp_session_id() {
112
+ local var val
113
+ _HQ_FP_SID=""
114
+ for var in HQ_SESSION_ID CLAUDE_CODE_SESSION_ID CLAUDE_SESSION_ID \
115
+ CODEX_SESSION_ID CODEX_THREAD_ID GROK_SESSION_ID; do
116
+ val="${!var:-}"
117
+ val="${val//[[:space:]]/}"
118
+ [ -n "$val" ] || continue
119
+ case "$val" in
120
+ .|..|*[!A-Za-z0-9._-]*) continue ;;
121
+ esac
122
+ _HQ_FP_SID="$val"
123
+ return 0
124
+ done
125
+ return 1
126
+ }
127
+
128
+ # Sets _HQ_FP_VERSION to the installed hq-cli version, read from the package's
129
+ # package.json with no node spawn, _HQ_FP_CLI_CMD to the hq command on PATH and
130
+ # _HQ_FP_CLI_PATH to the file it resolves to. Returns 1 when hq is missing or
131
+ # the version cannot be read that way (the caller then skips the builder).
132
+ _hq_fp_read_cli() {
133
+ local cmd="" resolved="" dir="" parent="" version=""
134
+ _HQ_FP_VERSION=""
135
+ _HQ_FP_CLI_CMD=""
136
+ _HQ_FP_CLI_PATH=""
137
+ if ! declare -F _hq_cli_floor_package_version >/dev/null 2>&1; then
138
+ [ -f "$_HQ_FP_LIB_DIR/hq-cli-floor.sh" ] || return 1
139
+ # shellcheck source=hq-cli-floor.sh
140
+ . "$_HQ_FP_LIB_DIR/hq-cli-floor.sh" 2>/dev/null || return 1
141
+ fi
142
+ cmd="$(command -v hq 2>/dev/null)" || return 1
143
+ [ -n "$cmd" ] || return 1
144
+ resolved="$(_hq_cli_floor_resolve_executable "$cmd" 2>/dev/null)" || return 1
145
+ dir="${resolved%/*}"
146
+ while [ -n "$dir" ] && [ "$dir" != / ]; do
147
+ if [ -f "$dir/package.json" ]; then
148
+ version="$(_hq_cli_floor_package_version "$dir/package.json" 2>/dev/null)" || version=""
149
+ if [ -n "$version" ]; then
150
+ _HQ_FP_VERSION="$version"
151
+ _HQ_FP_CLI_CMD="$cmd"
152
+ _HQ_FP_CLI_PATH="$resolved"
153
+ return 0
154
+ fi
155
+ fi
156
+ parent="${dir%/*}"
157
+ [ -n "$parent" ] || parent="/"
158
+ [ "$parent" != "$dir" ] || break
159
+ dir="$parent"
160
+ done
161
+ return 1
162
+ }
163
+
164
+ hq_fp_cli_version() {
165
+ _hq_fp_read_cli || return 1
166
+ printf '%s\n' "$_HQ_FP_VERSION"
167
+ }
168
+
169
+ # Sets _HQ_FP_CLI_CACHE to the per-machine capability cache file for the binary
170
+ # _hq_fp_read_cli found, and _HQ_FP_CLI_KEY to its key (resolved path, mtime,
171
+ # version). Returns 1 when there is no HOME or the mtime cannot be read.
172
+ _hq_fp_cli_cache_path() {
173
+ local mtime="" sum=""
174
+ _HQ_FP_CLI_KEY=""
175
+ _HQ_FP_CLI_CACHE=""
176
+ [ -n "${HOME:-}" ] || return 1
177
+ mtime="$(stat -c %Y "$_HQ_FP_CLI_PATH" 2>/dev/null)" \
178
+ || mtime="$(stat -f %m "$_HQ_FP_CLI_PATH" 2>/dev/null)" \
179
+ || mtime=""
180
+ case "$mtime" in ''|*[!0-9]*) return 1 ;; esac
181
+ _HQ_FP_CLI_KEY="$_HQ_FP_CLI_PATH|$mtime|$_HQ_FP_VERSION"
182
+ sum="$(printf '%s' "$_HQ_FP_CLI_KEY" | cksum 2>/dev/null)" || return 1
183
+ sum="${sum%% *}"
184
+ case "$sum" in ''|*[!0-9]*) return 1 ;; esac
185
+ _HQ_FP_CLI_CACHE="$HOME/.hq/cache/fingerprint-cli-$sum.cache"
186
+ return 0
187
+ }
188
+
189
+ # Reads the cached capability for the current binary. Returns 0 for capable,
190
+ # 1 for incapable, 2 when there is no fresh entry.
191
+ _hq_fp_cli_cache_read() {
192
+ local ttl="${HQ_FINGERPRINT_CAPABILITY_TTL_SECS:-86400}"
193
+ local c_schema="" c_key="" c_result="" c_stamp="" now=""
194
+ case "$ttl" in ''|*[!0-9]*) ttl=86400 ;; esac
195
+ _hq_fp_cli_cache_path || return 2
196
+ [ -f "$_HQ_FP_CLI_CACHE" ] || return 2
197
+ {
198
+ IFS= read -r c_schema || c_schema=""
199
+ IFS= read -r c_key || c_key=""
200
+ IFS= read -r c_result || c_result=""
201
+ IFS= read -r c_stamp || c_stamp=""
202
+ } <"$_HQ_FP_CLI_CACHE" 2>/dev/null || true
203
+ [ "$c_schema" = "$_HQ_FP_CLI_CACHE_SCHEMA" ] || return 2
204
+ [ "$c_key" = "$_HQ_FP_CLI_KEY" ] || return 2
205
+ case "$c_stamp" in ''|*[!0-9]*) return 2 ;; esac
206
+ now="$(date +%s 2>/dev/null)" || return 2
207
+ case "$now" in ''|*[!0-9]*) return 2 ;; esac
208
+ [ $((now - c_stamp)) -lt "$ttl" ] || return 2
209
+ case "$c_result" in
210
+ capable) return 0 ;;
211
+ incapable) return 1 ;;
212
+ esac
213
+ return 2
214
+ }
215
+
216
+ # Best effort: a capability that cannot be cached only costs the next session
217
+ # one probe. Write to a temp file and rename so readers never see half.
218
+ _hq_fp_cli_cache_write() { # capable|incapable
219
+ local tmp=""
220
+ [ -n "$_HQ_FP_CLI_CACHE" ] || _hq_fp_cli_cache_path || return 0
221
+ mkdir -p "${_HQ_FP_CLI_CACHE%/*}" 2>/dev/null || return 0
222
+ tmp="$_HQ_FP_CLI_CACHE.$$"
223
+ if printf '%s\n' "$_HQ_FP_CLI_CACHE_SCHEMA" "$_HQ_FP_CLI_KEY" "$1" \
224
+ "$(date +%s 2>/dev/null || echo 0)" >"$tmp" 2>/dev/null; then
225
+ mv -f "$tmp" "$_HQ_FP_CLI_CACHE" 2>/dev/null || rm -f "$tmp" 2>/dev/null || true
226
+ fi
227
+ return 0
228
+ }
229
+
230
+ # Probes the binary _hq_fp_read_cli found by running the builder once, records
231
+ # the capability in the per-machine cache, and leaves the builder's result in
232
+ # _HQ_FP_VALUE so a caller that wanted a trailer does not boot node twice.
233
+ _hq_fp_cli_probe() { # limit_secs
234
+ _hq_fp_build "$1" "$_HQ_FP_CLI_CMD"
235
+ [ "$_HQ_FP_PROBED" = 1 ] || return 1
236
+ if [ "$_HQ_FP_CAPABLE" = 1 ]; then
237
+ _hq_fp_cli_cache_write capable
238
+ return 0
239
+ fi
240
+ _hq_fp_cli_cache_write incapable
241
+ return 1
242
+ }
243
+
244
+ hq_fp_cli_capable() {
245
+ local limit="${HQ_FINGERPRINT_TIMEOUT_SECS:-2}" rc=0
246
+ case "$limit" in ''|*[!0-9]*) limit=2 ;; esac
247
+ _hq_fp_read_cli || return 1
248
+ hq_cli_version_ge "$_HQ_FP_VERSION" "$HQ_FINGERPRINT_MIN_HQ_CLI" 2>/dev/null || return 1
249
+ _hq_fp_cli_cache_read || rc=$?
250
+ case "$rc" in
251
+ 0) return 0 ;;
252
+ 1) return 1 ;;
253
+ esac
254
+ _hq_fp_cli_probe "$limit" >/dev/null 2>&1
255
+ }
256
+
257
+ # Stops a builder that overran: TERM, a short grace period, then KILL, so a
258
+ # builder that ignores TERM cannot hold the caller until the hook timeout.
259
+ _hq_fp_stop() { # pid
260
+ local pid="$1" grace=0
261
+ pkill -TERM -P "$pid" 2>/dev/null || true
262
+ kill -TERM "$pid" 2>/dev/null || true
263
+ while kill -0 "$pid" 2>/dev/null && [ "$grace" -lt 5 ]; do
264
+ sleep 0.05
265
+ grace=$((grace + 1))
266
+ done
267
+ if kill -0 "$pid" 2>/dev/null; then
268
+ pkill -KILL -P "$pid" 2>/dev/null || true
269
+ kill -KILL "$pid" 2>/dev/null || true
270
+ fi
271
+ wait "$pid" 2>/dev/null || true
272
+ }
273
+
274
+ # Runs the builder once and sets _HQ_FP_VALUE to a well-formed fingerprint, or
275
+ # to "" for every failure. Sets _HQ_FP_PROBED=1 when the command actually ran
276
+ # (or timed out), and _HQ_FP_CAPABLE=1 when it exited 0 with a "fingerprint"
277
+ # key in its JSON, whether that value is a string or null.
278
+ _hq_fp_build() { # limit_secs command [args...]
279
+ local limit="$1" tmp="" pid="" waited=0 max_ms=0 out="" value="" help=""
280
+ shift
281
+ _HQ_FP_VALUE=""
282
+ _HQ_FP_PROBED=0
283
+ _HQ_FP_CAPABLE=0
284
+ # `git commit --trailer` needs git 2.32+; an older git must keep committing.
285
+ # Capture the help text first: piping into `grep -q` lets git die of SIGPIPE,
286
+ # which fails the check in callers running under `set -o pipefail`.
287
+ help="$(git commit -h 2>&1 || true)"
288
+ case "$help" in
289
+ *--trailer*) ;;
290
+ *) return 0 ;;
291
+ esac
292
+ command -v "$1" >/dev/null 2>&1 || return 0
293
+ max_ms=$((limit * 1000))
294
+ tmp="$(mktemp "${TMPDIR:-/tmp}/hq-fingerprint.XXXXXX" 2>/dev/null)" || return 0
295
+
296
+ # Portable timeout (no GNU `timeout` on macOS): run the builder in the
297
+ # background with stdout in a file, never on our own stdout, so a caller's
298
+ # $(...) cannot be held open by a hung child. Poll, then stop it on overrun.
299
+ # The first checks come after a few ms, so a fast builder is not charged a
300
+ # full 100 ms tick; the interval grows to 100 ms for a slow one.
301
+ ( exec "$@" fingerprint self --json --offline >"$tmp" 2>/dev/null </dev/null ) &
302
+ pid=$!
303
+ _HQ_FP_PROBED=1
304
+ while kill -0 "$pid" 2>/dev/null; do
305
+ if [ "$waited" -ge "$max_ms" ]; then
306
+ _hq_fp_stop "$pid"
307
+ rm -f "$tmp"
308
+ return 0
309
+ fi
310
+ if [ "$waited" -lt 20 ]; then
311
+ sleep 0.005
312
+ waited=$((waited + 5))
313
+ elif [ "$waited" -lt 200 ]; then
314
+ sleep 0.02
315
+ waited=$((waited + 20))
316
+ else
317
+ sleep 0.1
318
+ waited=$((waited + 100))
319
+ fi
320
+ done
321
+ if ! wait "$pid" 2>/dev/null; then
322
+ rm -f "$tmp"
323
+ return 0
324
+ fi
325
+ out="$(tr -d '\r\n' <"$tmp" 2>/dev/null)" || out=""
326
+ rm -f "$tmp"
327
+
328
+ case "$out" in
329
+ *'"fingerprint"'*) _HQ_FP_CAPABLE=1 ;;
330
+ *) return 0 ;;
331
+ esac
332
+ value="$(printf '%s' "$out" | sed -n -E 's/.*"fingerprint"[[:space:]]*:[[:space:]]*"([^"]*)".*/\1/p')" || value=""
333
+ [ -n "$value" ] || return 0
334
+ # Only a well-formed token becomes a trailer; anything else is ignored.
335
+ case "$value" in
336
+ hqfp[0-9]*:*) ;;
337
+ *) return 0 ;;
338
+ esac
339
+ case "$value" in
340
+ *[!A-Za-z0-9:._@+/=-]*) return 0 ;;
341
+ esac
342
+ _HQ_FP_VALUE="$value"
343
+ return 0
344
+ }
345
+
346
+ hq_fingerprint_trailer_args() {
347
+ local root="${1:-}" bin="${HQ_FINGERPRINT_BIN:-}" limit="${HQ_FINGERPRINT_TIMEOUT_SECS:-2}"
348
+ local key="" cache_dir="" cache="" c_schema="" c_key="" c_result="" cache_tmp="" rc=0
349
+ if [ -z "$root" ]; then
350
+ root="$(cd "$_HQ_FP_LIB_DIR/../../.." 2>/dev/null && pwd -P)" || return 0
351
+ fi
352
+ _hq_fp_enabled "$root" || return 0
353
+ _hq_fp_session_id || return 0
354
+ case "$limit" in ''|*[!0-9]*) limit=2 ;; esac
355
+
356
+ if [ -n "$bin" ]; then
357
+ key="bin:$bin"
358
+ else
359
+ _hq_fp_read_cli || return 0
360
+ hq_cli_version_ge "$_HQ_FP_VERSION" "$HQ_FINGERPRINT_MIN_HQ_CLI" 2>/dev/null || return 0
361
+ key="hq-cli:$_HQ_FP_VERSION"
362
+ fi
363
+
364
+ cache_dir="$root/workspace/sessions/$_HQ_FP_SID"
365
+ cache="$cache_dir/fingerprint-trailer.cache"
366
+ if [ -f "$cache" ]; then
367
+ {
368
+ IFS= read -r c_schema || c_schema=""
369
+ IFS= read -r c_key || c_key=""
370
+ IFS= read -r c_result || c_result=""
371
+ } <"$cache" 2>/dev/null || true
372
+ if [ "$c_schema" = "$_HQ_FP_CACHE_SCHEMA" ] && [ "$c_key" = "$key" ]; then
373
+ case "$c_result" in
374
+ value:hqfp*)
375
+ printf '%s\n' "--trailer" "HQ-Fingerprint: ${c_result#value:}"
376
+ return 0
377
+ ;;
378
+ none) return 0 ;;
379
+ esac
380
+ fi
381
+ fi
382
+
383
+ if [ -n "$bin" ]; then
384
+ # shellcheck disable=SC2086
385
+ _hq_fp_build "$limit" $bin
386
+ else
387
+ _hq_fp_cli_cache_read || rc=$?
388
+ case "$rc" in
389
+ 0) _hq_fp_build "$limit" "$_HQ_FP_CLI_CMD" ;;
390
+ 1) _HQ_FP_VALUE="" ;;
391
+ *) _hq_fp_cli_probe "$limit" || true ;;
392
+ esac
393
+ fi
394
+
395
+ # Best effort: a cache that cannot be written only costs the next call a
396
+ # builder run. Write to a temp file and rename so readers never see half.
397
+ if mkdir -p "$cache_dir" 2>/dev/null; then
398
+ cache_tmp="$cache.$$"
399
+ if [ -n "$_HQ_FP_VALUE" ]; then
400
+ c_result="value:$_HQ_FP_VALUE"
401
+ else
402
+ c_result="none"
403
+ fi
404
+ if printf '%s\n' "$_HQ_FP_CACHE_SCHEMA" "$key" "$c_result" >"$cache_tmp" 2>/dev/null; then
405
+ mv -f "$cache_tmp" "$cache" 2>/dev/null || rm -f "$cache_tmp" 2>/dev/null || true
406
+ fi
407
+ fi
408
+
409
+ [ -n "$_HQ_FP_VALUE" ] || return 0
410
+ printf '%s\n' "--trailer" "HQ-Fingerprint: $_HQ_FP_VALUE"
411
+ return 0
412
+ }
413
+
414
+ hq_fingerprint_trailer_load() {
415
+ local line=""
416
+ HQ_FINGERPRINT_TRAILER_ARGS=()
417
+ while IFS= read -r line; do
418
+ [ -n "$line" ] && HQ_FINGERPRINT_TRAILER_ARGS+=("$line")
419
+ done <<EOF
420
+ $(hq_fingerprint_trailer_args "${1:-}")
421
+ EOF
422
+ return 0
423
+ }
@@ -18,6 +18,11 @@
18
18
 
19
19
  set -euo pipefail
20
20
 
21
+ # This help is the `hq core rebuild-index` help, byte for byte (the published
22
+ # core command check compares the two). The company scope paragraph describes
23
+ # that command: it reads the session and plans the rebuild before any write.
24
+ # This loose script does not read the session; run directly it keeps its own
25
+ # argument grammar below.
21
26
  for arg in "$@"; do
22
27
  if [[ "$arg" == "--help" || "$arg" == "-h" ]]; then
23
28
  printf '%s\n' \
@@ -25,7 +30,11 @@ for arg in "$@"; do
25
30
  '' \
26
31
  'Regenerate company root INDEX.md files. Without --company, all companies are regenerated.' \
27
32
  '--company <slug> regenerates only that company'\''s index.' \
28
- 'Company-scoped writes require the cli.rebuild-index-company-scope flag.'
33
+ 'Company-scoped writes require the cli.rebuild-index-company-scope flag.' \
34
+ '' \
35
+ 'Company scope: in a company-bound session, a run with no company rebuilds only the bound companies' \
36
+ '(core/scripts/hq-session.sh get company_slugs), and a company outside that set is refused.' \
37
+ 'An unbound session keeps the every-company rebuild (or pass --company <slug>); --all-companies states that explicitly.'
29
38
  exit 0
30
39
  fi
31
40
  done
@@ -16,12 +16,21 @@
16
16
 
17
17
  set -euo pipefail
18
18
 
19
+ # This help is the `hq core rebuild-index` help, byte for byte (the published
20
+ # core command check compares the two). The company scope paragraph describes
21
+ # that command: it reads the session and plans the rebuild before any write.
22
+ # This loose script does not read the session; run directly it keeps its own
23
+ # argument grammar below.
19
24
  for arg in "$@"; do
20
25
  if [[ "$arg" == "--help" || "$arg" == "-h" ]]; then
21
26
  printf '%s\n' \
22
27
  'Usage: hq core rebuild-index company-knowledge [<company> | --company <company>] [--accept]' \
23
28
  '' \
24
- 'With a company, rebuild only that company'\''s index. Without a company, retain the all-company rebuild. Help performs no writes.'
29
+ 'With a company, rebuild only that company'\''s index. Without a company, retain the all-company rebuild. Help performs no writes.' \
30
+ '' \
31
+ 'Company scope: in a company-bound session, a run with no company rebuilds only the bound companies' \
32
+ '(core/scripts/hq-session.sh get company_slugs), and a company outside that set is refused.' \
33
+ 'An unbound session keeps the every-company rebuild (or pass --company <slug>); --all-companies states that explicitly.'
25
34
  exit 0
26
35
  fi
27
36
  done
@@ -8,12 +8,21 @@
8
8
 
9
9
  set -euo pipefail
10
10
 
11
+ # This help is the `hq core rebuild-index` help, byte for byte (the published
12
+ # core command check compares the two). The company scope paragraph describes
13
+ # that command: it reads the session and plans the rebuild before any write.
14
+ # This loose script does not read the session; run directly it keeps its own
15
+ # argument grammar below.
11
16
  for arg in "$@"; do
12
17
  if [[ "$arg" == "--help" || "$arg" == "-h" ]]; then
13
18
  printf '%s\n' \
14
19
  'Usage: hq core rebuild-index projects [<company> | --company <company>] [--accept]' \
15
20
  '' \
16
- 'With a company, rebuild only that company'\''s index. Without a company, retain the all-company rebuild. Help performs no writes.'
21
+ 'With a company, rebuild only that company'\''s index. Without a company, retain the all-company rebuild. Help performs no writes.' \
22
+ '' \
23
+ 'Company scope: in a company-bound session, a run with no company rebuilds only the bound companies' \
24
+ '(core/scripts/hq-session.sh get company_slugs), and a company outside that set is refused.' \
25
+ 'An unbound session keeps the every-company rebuild (or pass --company <slug>); --all-companies states that explicitly.'
17
26
  exit 0
18
27
  fi
19
28
  done