Update hq

From indigoai-us/hq-core · View interactive version

Update hq is an AI agent skill from the GitHub repository indigoai-us/hq-core. Upgrade HQ from the latest hq-core release.

How to use this skill

Skill file

/update-hq — HQ Upgrade

Upgrade your HQ installation from the latest indigoai-us/hq-core release by delegating to hq rescue, the canonical drift-preserving updater. hq rescue re-syncs your HQ core to the target release using a three-way merge that preserves your local edits, takes a pre-op safety snapshot, and reports what changed.

User's input: $ARGUMENTS

Why `hq rescue`

/update-hq used to hand-roll the upgrade: fetch MIGRATION.md, parse migration sections, then three-way-merge each file one at a time over gh api. hq rescue does all of that natively and more reliably — it classifies every core path (clean / drifted / locally-added), three-way merges drift against the release, force-takes infrastructure files that must not carry conflict markers, snapshots to ~/.hq/backups first, and prints a single summary. This skill now just maps your arguments onto hq rescue flags, previews the plan, and surfaces the result.

Argument parsing

Map $ARGUMENTS onto hq rescue flags:

| User input | hq rescue flag | Meaning |

|---|---|---|

| --check / --dry-run | --check | Plan only — classify and report, change nothing on disk |

| v{X.Y.Z} (bare version) | --ref v{X.Y.Z} | Upgrade to a specific release instead of latest |

| --ref <ref> | --ref <ref> | Target tag/branch (default: latest hq-core release) |

| --staging | --staging | Use the staging release channel |

| --source <repo> | --source <repo> | Override the source repo |

| --paths <list> | --paths <list> | Narrow the rescue to comma-separated top-level paths |

| --floor-sha <sha> | --floor-sha <sha> | Pin the three-way history floor to a 40-char commit SHA |

| --no-backup | --no-backup | Skip the pre-op snapshot (default: keep it) |

| -y / --yes | -y | Skip the confirmation prompt |

| --hq-root <path> | --hq-root <path> | Operate on a specific HQ root (defaults to auto-detected) |

The legacy --from v{X.Y.Z} flag is gone — hq rescue detects the three-way history floor automatically. Pin it manually with --floor-sha only if the user explicitly asks.

Phase 1: Preflight

Verify the hq CLI is available:

command -v hq

If it is missing, hard stop and tell the user to install the HQ CLI (e.g. npm i -g @indigoai-us/hq-cli, or per their install method) before re-running /update-hq.

Phase 2: Plan (always dry-run first)

Always preview before applying. Run rescue in check mode with the user's mapped flags:

hq rescue --check {mapped-flags}

Surface the plan in plain terms: the target release, how many paths are clean vs. carry local drift vs. are locally added, and anything rescue flags for manual review.

If the user passed --check / --dry-run, stop here — report the plan and write nothing.

Before an applying run, check the incoming release's core/core.yaml from the

exact source repository and ref shown by the plan. The source address comes

from HQ_CORE_SOURCE (env var, else ~/.hq/core-source.json), which defaults

to indigoai-us/hq-core on GitHub, with indigoai-us/hq-core-staging as the

staging repo. --staging selects the staging repo, and --source or --ref

overrides those defaults. Read only the metadata file through the shared

resolver, passing --staging or --source <owner>/<repo> when the user did:

bash core/scripts/lib/hq-core-source.sh core-yaml --ref <target-ref> [--staging | --source <owner>/<repo>]

The resolver uses gh api when the source is GitHub and a plain request with

no GitHub credentials for any other host.

If bash core/scripts/lib/hq-core-source.sh print shows a source other than

the defaults, compare it with the source named in the hq rescue --check plan.

An hq CLI without HQ_CORE_SOURCE support plans from the GitHub default. If

the plan's source differs from the configured one, stop, tell the user to update

the hq CLI, and do not apply.

If the metadata file cannot be read from the planned source and ref, stop and

report that failure; do not apply the release.

If the file declares requiresHqCli, compare the installed CLI with that floor

using core/scripts/lib/hq-cli-floor.sh. If the floor is malformed, stop and

report its value. The reader accepts an HQ root, so place the fetched file under

a temporary core/core.yaml and call hq_cli_floor_required on that root. If

the CLI is older, include the required CLI upgrade in the plan. Do not install

it before the user confirms the applying run.

Phase 3: Confirm and apply

If this is not a dry run, confirm with AskUserQuestion (skip the prompt only if the user already passed -y / --yes):

  1. Apply this upgrade (recommended)
  2. Cancel

If the incoming release requires a newer CLI, run the upgrade after this

confirmation and before rescue:

npm install -g @indigoai-us/hq-cli@latest

Then check the installed version again with hq_cli_floor_check. If the

install fails or the CLI still misses the floor, stop without applying the

scaffold release and show the upgrade command. Do not run rescue until the floor

check passes.

Only after that check passes, run rescue with -y so it does not prompt again:

hq rescue -y {mapped-flags}

Keep the pre-op backup: do not pass --no-backup unless the user explicitly asked for it. hq rescue writes a snapshot under ~/.hq/backups before touching anything, which is the recovery path if a merge goes wrong.

Phase 4: Verify project hooks, repair if needed, and report

After a successful rescue, backfill policy triggers once from the updated HQ root

(the selected --hq-root, if supplied):

HQ_ROOT={hq-root} hq core migrate-policy-triggers

Run this for stable and staging updates before the hook health check. If it fails,

report the failure and stop; do not claim the update completed. This idempotent

migration also runs at SessionStart through the hash-gated

migrate-policy-triggers-if-changed.sh hook, which covers policies that arrive by

/hq-sync, a CLI update or a hand edit.

hq rescue preserves user drift and replaces release-owned paths. Its settings

reconcile can empty .claude/settings.json hook arrays and copy master-hook.sh

into .claude/settings.local.json. Restore shipped hook wiring before checking

health — a second rescue repeats the same relocate:

bash core/scripts/restore-hook-settings.sh {hq-root}
bash core/scripts/remove-stray-gate-hooks.sh {hq-root}
bash core/scripts/remove-retired-core-hooks.sh {hq-root}
bash core/scripts/check-hq-hooks.sh --root {hq-root}

After hq rescue restores the shipped hook settings, run the cleanup before the

health check. This order applies to stable updates and --staging replacements.

The cleanup removes local hook commands that point to registry scripts. It keeps

the local env and permissions sections and unrelated hooks.

hq rescue keeps files that the new release no longer ships. The retired-hook

cleanup deletes core hook files a release retired, such as the old Stop leaf

70-work-mesh-done.sh, when they still match a released copy. It keeps a file

with local edits and names it in its output; master-hook does not run that

Stop leaf either way. It also keeps a file whose folder is a symlink out of

core/hooks. Show the user every kept or could not remove line it prints,

with the file path, so they can delete or keep that file themselves. A failed

removal makes it exit 1; report that line and continue with the health check.

An update also removes the release's test files from the install. hq rescue

no longer copies test folders (the tests folders of the core scripts, the

hooks, skills and workers), fixture and hook-corpus folders, or test files

such as *.test.sh into an install; the release repository keeps them

for its own checks. On an existing install it deletes a test file the previous

release installed when the file is byte-identical to that released copy. It

keeps a test file you changed, and one whose folder links outside the HQ root,

and prints a kept (release test file ...) line for each. Show the user those

lines with the file path. When rescue reports Baseline: HEAD compare, it has

no previous release to compare with and removes no test file on that run. Eight

test files that shipped scripts run, the hook test cases that

hq doctor --deep reads, and worker skill documents named *-test.md stay

installed. This needs an hq whose rescue has the install exclusion list; an

older hq still copies the test files.

Then take out the test and tooling files the release no longer ships, which

rescue on an older hq copies in or leaves behind (the Baseline: HEAD compare

case, the CI and release scripts). Preview first:

bash core/scripts/remove-installed-test-files.sh {hq-root} --check

It lists each file it would move (would move: <path>) and exits 1 when there

is one, 0 when there is none. It scans only the release-owned trees (core/,

.claude/, .codex/, .grok/, .agents/). It uses the same rules the release runs on its

tarball (hq-cli's scripts/check-function-manifest.mjs --installed-core, hq

5.345.221 or newer, with the rules in core/scripts/release-install-excludes.rsync).

It never touches any other top-level folder or file (git, company, repo,

personal, workspace, .hq state, the user's own folders), installed packs

other than core/packages/hq-pack-cowork/, company or pack skills

(.claude/skills/<prefix>:<name>/) and their wrappers, node_modules folders,

the test files that shipped scripts run, or a file behind a linked folder

(printed as kept).

Show the user the count and the listed paths, and ask with AskUserQuestion

whether to move them. Run it only on yes:

bash core/scripts/remove-installed-test-files.sh {hq-root}

It moves each file into ~/.hq/backups/update-hq-test-files-<time>/ under its

path in the HQ root (nothing is deleted, so a file the user changed can be

copied back), removes folders the moves left empty, and runs the check again.

Report the moved N line and the backup folder. Exit 0 means the installed-core

check is clean. Exit 1 means a move failed or a file is still reported: show

those lines and continue. Exit 2 (no node, or an hq older than 5.345.221)

means nothing was moved: say so and continue with the health check.

If settings.json is missing or still invalid, repair the released .claude tree,

restore hooks again, and re-check. Keep any other mapped release flags such as

--ref / --staging; omit a user-provided --paths restriction because this

repair must include .claude:

hq rescue -y --paths .claude {mapped release flags}
bash core/scripts/restore-hook-settings.sh {hq-root}
bash core/scripts/remove-stray-gate-hooks.sh {hq-root}
bash core/scripts/remove-retired-core-hooks.sh {hq-root}
bash core/scripts/check-hq-hooks.sh --root {hq-root}

If the second check fails, stop and report its exact diagnostics; do not claim

the update completed successfully. See core/docs/hq/HOOKS-NOT-FIRING.md for

the Desktop/SDK cwd and settingSources recovery instructions.

After a real terminal CLI session, the user can additionally prove the

policy-trigger hook actually ran:

bash core/scripts/check-hq-hooks.sh --root {hq-root} --require-ledger

The affected Claude Code app/SDK runtime does not dispatch command-hook events,

even with valid project settings. settingSources: ["project"] can load native

project context but cannot make that runtime enforce shell hooks. The durable

.claude/personal-context.md import remains available there; use host-side

enforcement or terminal Claude Code for work that requires a mechanical block.

Then relay rescue's summary in plain language: what was updated, what kept

local edits, hook-health status, and anything that needs manual follow-up.

Refresh the search index so new/renamed content is findable:

qmd update 2>/dev/null || true

After the hook health check passes, check whether the one-time global HQ

runtime offer is available:

bash core/scripts/update-hq-install-offer.sh --check

The helper prints offer, answered, installed, or off. It uses the

installed hq CLI's existing hq-anywhere-runtime flag reader and the active

session's bound company. Missing or outdated CLI support, an unresolved

company UID, an unavailable flag service, or a flag value other than true all

count as off. The current reader does not evaluate person-only overrides

when no company is bound.

If the result is offer and this session can ask the user interactively, use

one AskUserQuestion with the question “Install the HQ runtime globally now?”

and these choices:

  1. Install the HQ runtime globally now
  2. No thanks

Record the answer before taking any follow-up action:

bash core/scripts/update-hq-install-offer.sh --accept
# or
bash core/scripts/update-hq-install-offer.sh --decline

Run hq install --global only when --accept prints accepted. A decline is

recorded and the offer does not repeat. If the helper reports answered or

installed, take no action. If the session is headless, non-interactive, or

cannot use AskUserQuestion, run --decline; do not install. The answer is

stored at ~/.hq/anywhere/update-hq-install-offer.json, next to the global

install records, so it survives HQ core updates. If installation fails after

acceptance, report the failure and give the user hq install --global as a

manual retry command; do not ask again.

Setup steps for users live in one page:

core/knowledge/public/hq-core/hq-anywhere-runtime.md. Point users there

instead of restating them.

Phase 5: Normalize line endings (post-rescue)

After a successful apply (skip on --check / dry-run), rewrite the worktree so tracked text is LF on disk. Existing Windows installs that already materialized CRLF do not pick up eol=lf from .gitattributes on pull alone — git status stays clean while on-disk bytes stay CRLF.

If core/scripts/normalize-eol-lf.sh exists under the HQ root (or the path passed via --hq-root), run it:

bash core/scripts/normalize-eol-lf.sh {hq-root}

Rules

See also

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.