Skip to content

refactor(scripts): extract shared bash helpers into lib/#157

Merged
NagyVikt merged 1 commit into
mainfrom
agent/refactor-shell-helper-lib
May 16, 2026
Merged

refactor(scripts): extract shared bash helpers into lib/#157
NagyVikt merged 1 commit into
mainfrom
agent/refactor-shell-helper-lib

Conversation

@NagyVikt
Copy link
Copy Markdown
Contributor

Summary

  • New scripts/codex-fleet/lib/agents.shderive_aid / email_to_id. Header documents the cross-language sync requirement with rust/fleet-data/src/fleet.rs::derive_agent_id (lines 105-118).
  • New scripts/codex-fleet/lib/ui-helpers.shstrip_ansi, ios_visible_len, pct_color, ios_status_chip_label.
  • Both libs use a __CODEX_FLEET_LIB_*_SH=1 double-source guard and define functions only (no side effects).
  • Sourced from fleet-tick.sh, cap-swap-daemon.sh, cap-probe.sh — removed inline duplicates.

Behavior

  • Eliminates 3 separate implementations of the email→id rule (1 bash + 2 python).
  • Eliminates inline copies of the ui helpers.
  • Bonus perf: the previous cap-swap-daemon.sh / cap-probe.sh spawned a python3 process per email→id call; the unified bash implementation removes that subprocess.

Notes

  • The initial brief named full-bringup.sh, plan-tree-anim.sh, and claude-supervisor.sh as duplicators — they don't contain these helpers (and claude-supervisor.sh doesn't exist). The actual duplicators were fleet-tick.sh, cap-swap-daemon.sh, cap-probe.sh.
  • waves-anim.sh / watcher-board.sh / review-anim.sh redefine strip_ansi + the IOS_* palette; not touched here. Worth a follow-up dedup pass.

Test plan

  • bash -n clean on all 5 touched files
  • Double-source guard verified under set -u
  • FLEET_TICK_SOURCE_ONLY=1 source-and-call: all helpers produce identical output to pre-refactor
  • shellcheck — not installed locally
  • scripts/codex-fleet/test/test-status-chips.sh fails on this branch — also fails on main (pre-existing regression unrelated to this PR)

🤖 Generated with Claude Code

Move duplicated helpers out of fleet-tick.sh, cap-swap-daemon.sh, and
cap-probe.sh into two sourced libraries:

- scripts/codex-fleet/lib/agents.sh: derive_aid (and email_to_id alias),
  the canonical email -> agent-id derivation. Replaces the inline bash
  copy in fleet-tick.sh and the two python3 copies in cap-swap-daemon.sh
  and cap-probe.sh. Functionally identical (verified against
  alice@gmail.com, bob@magnoliavilag.hu, carol@gitguardex.com,
  dave@pipacsclub.org, eve+x@example.co.uk). Documents the cross-language
  sync requirement with rust/fleet-data/src/fleet.rs::derive_agent_id.
- scripts/codex-fleet/lib/ui-helpers.sh: strip_ansi, ios_visible_len,
  pct_color, ios_status_chip_label. Pulled out of fleet-tick.sh.

Both libs use a __CODEX_FLEET_LIB_*_SH guard so double-sourcing is a
no-op and are set -u safe. Functions only, no top-level side effects.
Scripts source them via "$(dirname "${BASH_SOURCE[0]}")/lib/..." so
invocation from any cwd resolves correctly.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@NagyVikt NagyVikt merged commit cff98c8 into main May 16, 2026
2 checks passed
@NagyVikt NagyVikt deleted the agent/refactor-shell-helper-lib branch May 16, 2026 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant