Revision: 1 Last modified: 2026-12-04T17:48:16Z
setup.sh is two programs in one file, chosen by where it is run:
-
HOOK MODE — run from inside an installed constitution checkout (
bash submodules/constitution/scripts/setup.sh). It wires the §11.4.164 post-update auto-propagation hook so that everygit pull/git submodule updateof the constitution automatically registers new skills, installs new hooks, merges MCP configs, syntax-validates changed scripts, and installs git hooks into the consuming project. Idempotent — re-run it after every clone, or when hooks go stale. -
BOOTSTRAP MODE (added 2026-12-01) — run anywhere else, or with
--bootstrap. It installs the constitution assubmodules/constitutionwhen missing, fast-forwards it when behind, initialises the mandatory nested submodules, runs hook mode, createshelix-deps.yamlwhen missing, amends the agent instruction files with the inheritance block, verifies, and only after a successful verdict runs CodeGraphinit/syncthrough the constitution's writer entry andlumen index .when those tools exist.
Run hook mode when: you cloned a project that already contains the constitution, hooks look stale, or
--check-only reports drift. Run bootstrap mode when: you have a plain git project and want the constitution wired
in with one command (that is also what scripts/install.sh reaches).
The one thing to internalise: hook mode writes git hooks and does not install the constitution; bootstrap mode installs the constitution and then calls hook mode. Re-running either is safe.
bash4.4+,git.- Hook mode: the file must live inside a real constitution checkout (it resolves its constitution dir as
$SCRIPT_DIR/..and refuses to run elsewhere). - Bootstrap mode: a git work tree (or
--init-gitto create one), network access to at least one upstream mirror. - Optional:
codegraph,lumen,jq— each absence is reported, never faked. - Env vars (NAMES only):
CONSTITUTION_SETUP_BACKUP_STAMP— replaces the UTC stamp in the hook-backup directory name. Must match[A-Za-z0-9._-]; anything else → exit 2. Exists for deterministic tests.CONSTITUTION_AUTO_PROPAGATE=off— same effect as--auto-propagate=off.CONSTITUTION_SYNC_UPSTREAMS— same as--sync-upstreams.PROJECT_ROOT— only honoured for a STANDALONE checkout (one with no owning superproject). For an embedded constitution, an ambientPROJECT_ROOTnaming a different project is ignored with a warning.CONST_DIR— if exported and naming any directory other than this script's own checkout, the run is refused (exit 2), nothing written.
- Permissions: write access to the project's git hooks dir (
git rev-parse --git-path hooks) and, in bootstrap mode, to the project root.
# Hook mode — the normal invocation from a consuming project root
bash submodules/constitution/scripts/setup.sh
# Legacy layout (constitution/ rather than submodules/constitution/)
bash constitution/scripts/setup.sh
# Explicit project root, both spellings accepted
bash <constitution>/scripts/setup.sh --project-root /path/to/project
bash <constitution>/scripts/setup.sh --project-root=/path/to/project
# Verify only: compare the INSTALLED hooks with their sources (sha256), report drift, change nothing
bash <constitution>/scripts/setup.sh --check-only
# Record the opt-out of auto-propagation in the project's local git config
bash <constitution>/scripts/setup.sh --auto-propagate=off
# Also sync every upstream (fetches, reports; `apply` fast-forwards, never pushes)
bash <constitution>/scripts/setup.sh --sync-upstreams=ask
# Bootstrap mode
bash scripts/setup.sh --bootstrap --help # bootstrap flag list
bash scripts/setup.sh --dry-run # print the plan, write nothing
bash scripts/setup.sh --ref helixconstitution-v9 --skip-hooksWhat you should see in hook mode: a "TRUST MODEL" paragraph (printed by every run), per-step progress, and a
verdict. --check-only prints a drift report and exits 1 when anything is missing or stale.
This guide was written from source; the script was not executed — it is an installer that writes git hooks, so per this documentation pass it is documented rather than run.
| Code | Meaning |
|---|---|
0 |
ok |
1 |
failure: not a constitution, not a git work tree, a hook could not be installed or backed up, a hook-name collision, a refused core.hooksPath, the post-update hook failed, --check-only found drift, or the propagation lock is held by another run ("setup is INCOMPLETE") |
2 |
usage — including a bad CONSTITUTION_SETUP_BACKUP_STAMP value and an ambient CONST_DIR naming another directory |
Note the deliberate ordering: the post-update hook runs first; if it fails, the failure is reported, the hooks
are still installed, and the run exits 1 at the end (the pending stamp is kept and no applied ref recorded,
so a re-run retries).
Hook mode: --check-only, --project-root DIR, --project-root=DIR, --allow-global-hooks-path,
--auto-propagate=on|off, --sync-upstreams=off|check|apply|ask, -h|--help.
Bootstrap mode: --bootstrap, --ref REF, --repo-url URL, --index-timeout SEC, --ssh,
--allow-insecure-url, --init-git, --force-update, --skip-hooks, --skip-nested, --with-third-party,
--no-index, --not-constitution-repo, --dry-run, --no-color, --version, -h|--help.
--version prints setup.sh bootstrap <version> (bootstrap side). Bootstrap flag values are rejected if they look
like another flag (hs_refuse_dash), so --ref --dry-run is a usage error rather than a ref literally named
--dry-run.
- Shared hooks directory. The run is refused (exit 1, nothing written, nothing run) when
core.hooksPathis set at any scope other than local/worktree, or when the hooks dir resolves physically (every symlink followed) outside the project's git dir, common dir and work tree — unless--allow-global-hooks-path. Even with that flag the submodule consumer is never installed into a hooks dir outside the submodule's own git dir (skipped with a warning); only the project hooks are written there. - An existing, different hook. Backed up first to
$(git rev-parse --git-common-dir)/constitution-hook-backup/<UTC stamp>/<pass>/<name>(pass =constitution|project|submodule). A backup is never overwritten — a taken<name>gets<name>.N. A backup made before 2026-10-29 lives in the old<hooks>/.constitution-hook-backup/and is kept, never deleted. There is no--restoremode: restore by copying a backup back by hand. - A symlinked hook is backed up as a link (same target, never dereferenced), with a
<name>.linksidecar recordingTARGET=andABSOLUTE=. Restore withcp -P. - Any other file type (FIFO, socket, directory, device) at a hook name is refused and left in place, without ever being opened.
- Hook-name collision. When the project's
scripts/git_hooks/ships a hook with the same name as a constitution hook but different bytes, the constitution hook stays installed, the project hook is not installed, the collision is reported and the run exits1. Resolve by renaming the project hook, then re-run — never expect a silent overwrite or an alternating winner across re-runs. - A hooks dir physically inside a TRACKED directory (a committed
core.hooksPath, or.git/hookssymlinked into the work tree) is warned about — installing there would modify tracked files. - Propagation lock. Step 2c takes
<git-dir>/constitution-pending-update.lock(exclusive create). A lock whose recorded owner is provably dead (no/proc/<pid>, or a different process start time) is reclaimed with a warning; a live, unprovable, owner-less or symlink lock is never touched. When another propagation holds it,post_update_hook.shis not run, the pending stamp is kept, and setup exits1. - A branch switch / checkout / reset that moves the submodule through git's own recursion
(
submodule.recurse=true,--recurse-submodules) runs no hook at all and prints nothing (measured: git 2.53.0,checkout -Bwithsubmodule.recurse=true). Runsetup.shorpost_update_hook.shby hand after it. --check-onlyparse-checkspost_update_hook.shand compares the installedpost-mergeand submodule consumer with their sources by sha256; exits1on a parse error, a missing hook, or drift.- A recent consumer's first run can fail the §11.4.31 manifest gate (
CM-HELIX-DEPS-MANIFEST-PRESENT) becausehelix-deps.yamlis missing. Reported, hooks still installed, exit1, stamp kept so a re-run retries.
- Resolve the constitution dir as
$SCRIPT_DIR/..; refuse an ambientCONST_DIRthat names anything else. - Resolve the project root:
--project-rootwins; else the checkout's owner (its git superproject when it is a submodule, or the work tree holding it when it is a vendored plain copy); else, for a standalone checkout,PROJECT_ROOT, then the layout suffix fromscripts/lib/constitution_layout.sh. Never<project>/submodules. - Run
<constitution>/scripts/post_update_hook.sh(with any pending stamp'sOLD/NEW), and record<git-dir>/constitution-applied-refwhen it succeeds. - Install the project hooks (
post-merge, …) and, when the constitution is a real gitlink submodule, the submodule consumer as the submodule's ownpost-checkout(e.g..git/modules/<name>/hooks). - Print the trust model, the backup locations used, and a verdict.
- Bootstrap-mode extras (before/after the above as appropriate): ensure the submodule, fast-forward it, init nested
submodules gated by
helix-deps.yaml, createhelix-deps.yaml, amendCLAUDE.md/AGENTS.md/QWEN.md/GEMINI.md(or the list inagent_carriers.list) with the inheritance block at the top of the file (after a leading BOM — nothing overwritten), verify, then index.
scripts/install.sh— thecurl | bashforwarder; always invokes this script in bootstrap mode.scripts/post_update_hook.sh— the §11.4.164 hook this script installs and also invokes (STEP 4's installer lives inscripts/lib/hook_install.sh, shared with this script).scripts/install_constitution.sh— the richer installer with--upstream,--agent,--restore, backups.scripts/update.sh,scripts/update_constitution.sh— update paths (docs/scripts/update.md,docs/scripts/update_constitution.md).scripts/hooks/constitution-submodule-post-checkout,scripts/git_hooks/— the hook sources.docs/scripts/post_update_hook.md,docs/guides/setup_script.md.
2026-12-04 — source read in full (1749 lines), bash -n clean, and the flag/exit-code contract read from the
argument parsers at the two documented parse sites:
$ bash -n scripts/setup.sh && echo PARSE-OK
PARSE-OK
$ grep -n 'help)' scripts/setup.sh | head -3
748: -h|--help) hs_help; return 0 ;; # bootstrap mode
1275: -h|--help) usage; exit 0 ;; # hook modeNot executed in this pass: it writes git hooks into a project. To verify on a throwaway clone, run
bash <constitution>/scripts/setup.sh --check-only (read-only) and expect exit 0 when the installed hooks match
their sources, 1 with a named drift when they do not.