Skip to content

Latest commit

 

History

History
107 lines (77 loc) · 4.4 KB

labelctl.md

File metadata and controls

107 lines (77 loc) · 4.4 KB

labelctl.sh

Revision: 1 Last modified: 2026-12-04T19:00:00Z

Overview

labelctl.sh is the bash entry point to the constitution label-sync system (§11.4.182 labels plus real-time sync).

It exists because the real implementation is Go (labelctl and label-busd), and a consumer project should not need a manual build step after a constitution pull. So this wrapper does three things:

  1. builds the Go binaries when they are missing or stale;
  2. otherwise skips straight through;
  3. execs the requested binary, becoming that process.

"Stale" is not a guess: it is bincache.sh's ls_bin_stale, which keys on a digest of this module's Go sources recorded in the cache's .source-digest stamp. A different source tree, or uncommitted/newer sources, triggers a rebuild. Every consuming project therefore behaves identically after a pull without anyone remembering to rebuild.

Prerequisites

  • bash.
  • A Go toolchain only when a build is needed; a prebuilt binary is used when the toolchain is absent.
  • bincache.sh beside it (sourced; a missing bincache.sh exits 2).
  • The Go sources for labelctl / label-busd.

Environment variables (names only):

Variable Meaning
LABEL_SYNC_DIR State dir. Default $HOME/.local/state/constitution-label-sync.
LABEL_SYNC_BIN Binary cache dir. Default is per checkout: ${XDG_CACHE_HOME:-$HOME/.cache}/constitution-label-sync/bin-<hash of this module's path> (see bincache.sh).
LABEL_SYNC_LABELER Canonical labeler. Default: sibling ../multitrack/track_branch_label.sh.

Usage examples

# any labelctl argument is passed straight through
bash scripts/label-sync/labelctl.sh list --text

# run the daemon
bash scripts/label-sync/labelctl.sh busd

# build only, then print the bin directory
bash scripts/label-sync/labelctl.sh --build

# print the bin directory without building
bash scripts/label-sync/labelctl.sh --bin-dir

Exit codes

Code Meaning
0 OK — the exec'd binary succeeded, or --build / --bin-dir completed.
1 A finding or invalid input, from the binary.
2 Cannot determine: no Go toolchain and no prebuilt binary, the build failed, or a usage error. 2 is never a pass.

2 is the code that matters operationally. A label-sync that cannot run is not a label-sync that works, so the wrapper refuses rather than silently continuing unlabelled.

Edge cases

  • No Go toolchain and no prebuilt binary. 2. Cannot determine the label state; must not be read as success.
  • A failed build. 2, with the build output surfaced.
  • Binaries present and not stale. No build; straight to exec. This is the common steady-state path, so it stays cheap.
  • A different source tree. The per-checkout cache key means checkout A cannot run checkout B's binary — the defect (review-2 finding 13) that a single shared cache caused.
  • Uncommitted or newer Go sources. Detected by the source digest → rebuild.
  • bincache.sh missing. 2 immediately, naming the missing file.
  • LABEL_SYNC_LABELER pointing at a missing labeler. Surfaced by the binary, which owns that resolution.

Internal behaviour

  1. Sources bincache.sh (exit 2 if absent).
  2. Handles the two no-exec flags: --bin-dir prints the cache directory and exits 0; --build builds and prints it.
  3. Otherwise resolves the cache directory and asks ls_bin_stale whether labelctl / label-busd need rebuilding; if both are fresh, skips the build.
  4. Builds when needed, recording the .source-digest stamp so the next run can tell.
  5. execs the requested binary with the caller's arguments, so the exit status is the binary's own.

Related scripts

Sources scripts/label-sync/bincache.sh.

Called by scripts/label-sync/hooks/label-sync-lib.sh (via ls_ctl) and scripts/label-sync/mcp/label-mcp.sh.

Related: scripts/label-sync/install_label_sync.sh (wires the hooks that call this), scripts/multitrack/track_branch_label.sh (the default canonical labeler).

Cross-reference: docs/label-sync/CONTRACT.md.

See also docs/scripts/bincache.md, docs/scripts/label-sync-lib.md and docs/scripts/label-mcp.md.

Last verified

2026-12-04 — bash -n scripts/label-sync/labelctl.sh → exit 0. bash scripts/label-sync/labelctl.sh --bin-dir prints the per-checkout binary cache directory and exits 0 without building anything.