Dataface Tasks

Consolidate local dispatch and review scripts behind shared implementation

IDINFRA_TOOLING-CONSOLIDATE_LOCAL_DISPATCH_AND_REVIEW_SCRIPTS_BEHIND_SHARED_IMPLEMENTATION
Statuscompleted
Priorityp2
Milestonem1-ft-analytics-analyst-pilot
Ownersr-engineer-architect
Completed bydave
Completed2026-03-22

Problem

Refactor the new local worktree dispatch and review tooling so scripts/dispatch, scripts/dispatch-kill, scripts/review, and scripts/worktree-new share more logic or move behind a single implementation surface. Reduce shell duplication around argument parsing, base resolution, worktree discovery, dry-run formatting, and error handling.

Context

Four scripts share overlapping shell patterns: - scripts/dispatch — creates/reuses worktree, runs claude -p - scripts/dispatch-kill — removes worktree and branch - scripts/review — runs claude -p on a diff (does NOT source _dispatch_lib.sh) - scripts/worktree-new — creates worktree with just install

_dispatch_lib.sh already provides slugify and find_worktree_by_branch. The remaining duplication: 1. Repo root resolution — all 4 scripts do repo_root="$(git rev-parse --show-toplevel)"; cd "$repo_root". 2. Task slug/branch/path derivation — dispatch, dispatch-kill, worktree-new each derive slug → branch_name → default path. 3. Value-arg validation — 9 occurrences of the shift; [[ $# -gt 0 ]] || { echo "Missing value for ..." }; var="$1" pattern.

Constraints: preserve CLI behavior, keep tests passing, stay anti-slop (no wrappers that don't simplify).

Possible Solutions

  1. Extend _dispatch_lib.sh with targeted helpers — add init_repo_root, resolve_task, shift_value. Each script sources the lib and calls helpers instead of inlining the pattern. Recommended: minimal change, clear savings, no new files.

  2. Rewrite all scripts in Python behind a CLI: Maximum code sharing but massive scope increase, fragile for shell-native git operations. Overkill.

  3. Generate scripts from a template: Over-engineered for 4 scripts with different flows.

Plan

Extend _dispatch_lib.sh with three helpers: - shift_value "$@" — prints $2 or errors with flag name. Replaces 9 inline checks. - init_repo_root — sets repo_root and cd's. Replaces pattern in all 4 scripts. - resolve_task "$name" — sets slug, branch_name, default_worktree_path. Replaces pattern in 3 scripts.

Files to modify: 1. scripts/_dispatch_lib.sh — add helpers 2. scripts/dispatch — use helpers 3. scripts/dispatch-kill — use helpers 4. scripts/review — source lib, use helpers 5. scripts/worktree-new — use helpers

Steps: 1. Add helpers to _dispatch_lib.sh 2. Update each script to use helpers 3. Run existing tests to verify behavior preserved 4. Update task worksheet

Implementation Progress

Added three helpers to _dispatch_lib.sh: - shift_value "$@" — replaces 9 inline value-arg validation blocks across all scripts - init_repo_root — replaces duplicated git rev-parse --show-toplevel + cd in all 4 scripts - resolve_task "$name" — replaces duplicated slug/branch/path derivation in dispatch, dispatch-kill, worktree-new

Updated all 4 scripts to use the shared helpers. scripts/review now sources _dispatch_lib.sh (previously did not).

All 5 existing tests pass (tests/scripts/test_dispatch_scripts.py).

QA Exploration

  • [x] QA exploration completed (N/A — non-UI task)

Review Feedback

  • Manager review (just review) found one functional issue in scripts/worktree-new.
  • Fixed scripts/worktree-new to call init_repo_root, restoring the repo-root cd behavior before resolve_task.
  • Confirmed the branch diff remains scoped to the intended task files and scripts.
  • Manager validation after the review fix:
  • uv run pytest tests/scripts/test_dispatch_scripts.py -q
  • [x] Review cleared