Skip to content

Latest commit

 

History

History
112 lines (81 loc) · 4.63 KB

cli.md

File metadata and controls

112 lines (81 loc) · 4.63 KB

cli.py

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

Overview

cli.py is the issue_sync command-line front door (anchor §11.4.300). It mirrors workable items from the tracker database out to the Issues of each declared upstream, and reports drift the other way.

It is a Python module inside the scripts/issue_sync/ package, normally invoked as part of that package (for example python3 -m issue_sync.cli ...) rather than as a standalone script.

Subcommands:

Subcommand Purpose
plan Dry run (the default). Show what would change.
apply Write. Requires --apply.
verify Three-valued check: in sync / drift / cannot determine.
status Report current sync state.

Everything is three-valued: 0 in sync or done, 1 drift or failure, 2 cannot determine — and 2 is never a pass.

Two defaults matter:

  • The mechanism is OFF by default. A missing or disabled config exits 0 with disabled. Absence of a declaration is not an error; it is "not opted in".
  • Dry run is the default. Writing requires an explicit --apply.

Prerequisites

  • python3 and PyYAML (the config loader requires it).
  • A .workable-items-sync.yaml declaring scope and legs. Absent ⇒ disabled.
  • The workable-items DB (the source of truth, §11.4.93).
  • Tokens are read by variable name (see credentials.py in this package) and are never printed.

Usage examples

# dry run against one target (the default: writes nothing)
python3 -m issue_sync.cli plan --target github/vasic-digital/constitution

# several targets
python3 -m issue_sync.cli plan \
  --target github/vasic-digital/constitution \
  --target gitlab/vasic-digital/constitution

# actually write
python3 -m issue_sync.cli apply --apply --target github/vasic-digital/constitution

# three-valued verification
python3 -m issue_sync.cli verify --target github/vasic-digital/constitution

# current state
python3 -m issue_sync.cli status

Exit codes

Code Meaning
0 In sync / done. Also the code for a missing or disabled config (disabled).
1 Drift or failure.
2 Cannot determine — never a pass.

2 is the code to treat seriously. A target whose owning-repo visibility cannot be resolved is undetermined, and undetermined blocks. It never defaults to public.

Edge cases

  • No config file. Exits 0 with disabled. Default-OFF by design.
  • A config that fails validation. An invalid declaration is never "on" — treated as disabled/invalid rather than partially applied.
  • An unknown host in --target. The leg is reported as unknown-host rather than guessed; see registry.py.
  • Undetermined visibility. Blocks (2); the visibility resolver refuses to assume public.
  • A missing token variable. The credential is absent by name; nothing is printed and the leg cannot authenticate — it must not be reported as synced.
  • apply without --apply. Stays a dry run. Dropping the flag by accident cannot write.
  • Multiple --target values. Repeatable; each form is HOST/OWNER/REPO.

Internal behaviour

  1. Parses the subcommand and the repeatable --target list.
  2. Loads and validates .workable-items-sync.yaml; missing/disabled ⇒ exit 0 disabled.
  3. Builds one leg per target: resolve the adapter via registry.make(...) against the host map, which is data (config/forge/hosts.tsv), not a hardcoded switch.
  4. Resolves the owning repository's visibility live from the target's repo_info; undetermined blocks.
  5. Delegates planning/applying to engine, and inbound work to inbound.
  6. Reports per-leg outcomes and exits 0 / 1 / 2.

The module imports config, credentials, redact, registry, store, engine, inbound, visibility and the adapter base — it is the composition root of the package.

Related scripts

Delegates to engine.py (plan/apply/verify), inbound.py (intake), config.py (validation), registry.py + adapters/* (per-host transport), visibility.py (visibility and routing), store.py (DB access), redact.py (pre-write redaction).

Facade alternative with the full bidirectional pipeline: pipeline.py (subcommands plan, apply, pull, reconcile, verify, run, init-context, stage).

See also docs/scripts/pipeline.md, docs/scripts/engine.md, docs/scripts/config.md, docs/scripts/registry.md and docs/scripts/visibility.md.

Last verified

2026-12-04 — python3 -c "import ast;ast.parse(open('scripts/issue_sync/cli.py').read())" → exit 0. python3 -m issue_sync.cli with no subcommand exits 2 (argparse usage error).