Skip to content

refactor(skills): line-scoped shellcheck directives and no load-time module code - #73

Merged
chapati23 merged 4 commits into
mainfrom
refactor-shell-modules
Nov 26, 2026
Merged

chapati23 merged 4 commits into
mainfrom
refactor-shell-modules

Conversation

@chapati23

Copy link
Copy Markdown
Contributor

tl;dr

Shared shell helpers silenced lint warnings for whole files and ran work as soon as they loaded, against this repository's shell rules. This PR narrows each silenced warning to its one line and moves the load-time work into named steps that the PR watcher calls in the same order. Nothing changes for you.

The Problem

  • About 31 babysit-pr and address-feedback modules had file-wide shellcheck disable directives, which also hide later code.
  • Three babysit-pr modules ran their flow when sourced; AGENTS.md "Shell scripts" allows only definitions at load.

The Solution

  • Each directive sits on the line it excuses and names its reader; unneeded ones are gone.
  • The modules define prefixed functions of at most 50 lines (main_loop_*, repo_trust_hooks_*, gh_bound_install), which babysit-prs.sh calls in the old order.
  • Hooks are still sourced at top level, in global scope; the trust functions are read-only before the first hook loads.
  • Must not: change how a hook's set -e or the pin checks around each checkout hook behave.

Risk

  • 🚪 Door: two-way. Revert the merge commit; no state or data changes.
  • 💥 Blast Radius: every babysit-pr watch and address-feedback reply run that uses these skills.
  • 👀 Watch: the first watch after merge still reports ALL_PRS_CLEARED or DEADLINE.

Validation

  • Gates at 3b7710a: shellcheck 144 files ✓, pnpm check:shell (ratchet vs origin/main) ✓, validate-skills 27 ✓, pnpm test:scripts 482 ✓, trunk check ✓, test-skills.sh 62 runs ✓ (5 eval-creator runs needed its pinned psutil; rerun with it ✓), test-link-skills.sh 154 ✓, under /bin/bash 3.2 154 ✓
  • bash 3.2 (at b84ec11): 42 of 43 shell tests pass with bash 3.2 first on PATH.
  • Failed (pre-existing): gh-timeout.test.sh under bash 3.2 (about 600 s against a 7 s margin, "could not read checks twice"); fails the same way on base 0b01f6c.
  • Review: Codex review → 2 findings: 1 fixed (directive scope in repo-trust-preflight.sh), 1 declined (see Deferrals).
  • Not proven: a watch during an in-place skills update.

Deferrals

  • Declined: Codex P2, rename main-loop.sh so an old entry point fails closed during an in-place update. Such an update mixes versions of every module; renaming one file covers one of three.

Ship Checklist

  • PR title is a Conventional Commits header, type: summary or type(scope): summary, as commitlint.config.mjs enforces for commits
  • Performed a self-review of my own changes
  • node scripts/validate-skills.mjs and the affected test suites pass
  • Nothing in the diff breaks the public-readership rules in AGENTS.md
  • Body is about 250 words, 400 at most, excluding this checklist

🤖 Generated with Claude Code

https://claude.ai/code/session_013qZ16z2jrxp57w1mwaZtzP

chapati23 and others added 4 commits November 26, 2026 11:22
The babysit-pr and address-feedback modules carried file-wide
`# shellcheck disable=...` directives. A file-wide directive also silences
code written later, which the AGENTS.md "Shell scripts" rules forbid.

Each directive now sits on the assignment or command it excuses and names
the module that needs it. Where a directive no longer excused anything, it
is gone. Two jq-definition files start with a no-op `:` so that the
directives under it stay scoped to one assignment each. Header comments
that described the removed directives now name the globals instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013qZ16z2jrxp57w1mwaZtzP
Three babysit-pr modules ran code when sourced. main-loop.sh ran the
watch loop, repo-trust-hooks.sh discovered, pinned and sourced the hooks,
and gh-bound.sh checked for perl and installed the bounded gh. The
AGENTS.md "Shell scripts" rules require that a module only defines
functions and constants.

Each flow is now a set of named functions of at most 50 lines, with the
module name as prefix. babysit-prs.sh calls them where the source line
ran the flow before: gh_bound_install, the repo_trust_hooks_* steps and
main_loop_run. The hook files are still sourced at top level, now in
babysit-prs.sh, so each runs in global scope as before. The
repo_trust_hooks_* functions are read-only before the first hook loads,
so a hook cannot replace a check that runs after it. live-watch.md
describes the new call order.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013qZ16z2jrxp57w1mwaZtzP
…split

The Codex review of the module split found three differences from the
code that ran at top level:

- main_loop_poll_pass ran on the left of `||`, which turns off a hook's
  `set -e` inside the pass. It now runs on its own line and sets
  PASS_CUT_SHORT, which the loop checks after it.
- A hook that unsets `hook` stopped the watch under `set -u` before the
  pins were verified again. The call now passes `${hook-}`.
- The `:` that kept the jq-defs directives line-scoped ran at load and
  could reach a hook-defined `:`. An empty function now holds that place
  and runs nothing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013qZ16z2jrxp57w1mwaZtzP
The SC2034 directive above the REPO_TRUST_REREAD_SECONDS `case` covered
the whole statement, so an unused assignment in a later arm would also
pass shellcheck. It now sits on the one assignment it excuses. Found by
the Codex review of this branch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013qZ16z2jrxp57w1mwaZtzP
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T13:10:23.011120Z 3b7710a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Claude finished @chapati23's task in 4m 30s —— View job


Review: ✅ LGTM

  • Gather context (AGENTS.md rules, diff)
  • Review shellcheck directive scoping changes
  • Review load-time → named-function refactor (babysit-pr)
  • Check bash 3.2 / shell modularity compliance
  • Post findings

Verdict: LGTM. This is a careful, mechanical refactor that does exactly what the title/body claim, with no behavior changes I could find.

What I checked:

  1. Directive scoping. The jq-defs.sh files in both babysit-pr and address-feedback/codex-threads add a tiny no-op function (_jq_defs_directive_scope, _codex_threads_jq_directive_scope) as the file's first "command" specifically so ShellCheck's file-wide-directive rule (a directive before the first command applies to the whole file) no longer swallows everything that follows — each # shellcheck disable=SC2034 then only covers the one assignment under it. threads.sh uses the same trick by reordering THREADS_QUERY after review_threads(). Every remaining disable I checked (gh-bound.sh:62 SC2016, state.sh SC2140, repo-trust/*.sh SC2034) now names its reader and sits on the exact line it excuses, matching the AGENTS.md "Shell scripts" rule.
  2. Removed disables in address-feedback/tests/*.test.sh. Four test files dropped their file-wide SC2034 entirely rather than relabeling it. That's correct, not an oversight: .shellcheckrc's source-path makes ShellCheck trace into lib/reply-and-resolve-fixture.sh's run(), which directly reads ${GH_WITHDRAWN:-0} etc. as real bash, so the assignment's use is visible cross-file. codex-threads-edge-cases.test.sh keeps (and relabels) its disable for GH_EMPTY_COMMENTS because that variable's only "use" is inside a heredoc written out as a stub script body — invisible to ShellCheck's static trace — so the disable is still needed there. Nice attention to the actual tool semantics rather than a blanket find/replace.
  3. Load-time → function refactor (main-loop.sh, repo-trust-hooks.sh, gh-bound.sh). Traced the full control flow against the original flat scripts:
    • main-loop.sh's while true body is now main_loop_run, broken into main_loop_deadline_gate / _poll_pass / _recount_adopted / _exit_if_terminal / _deadline_after_pass / _final_poll / _announce / _heartbeat / _sleep, called in the original order. Each call sits on its own line (not after &&/||), so a hook's set -e still propagates exactly as when this ran inline — confirmed this holds given none of the calls sit inside a test construct.
    • repo-trust-hooks.sh splits into repo_trust_hooks_discover/pin/select/admit/verify_after/finish, with discover marking all six readonly -f on its first line so a sourced checkout hook can't redefine a trust check that runs after it. babysit-prs.sh now does the hook-sourcing loop itself, at top level, calling admit/verify_after by argument ("$1") rather than a shared global, which sidesteps a collision with the loop's own hook variable.
    • gh-bound.sh's gh_bound_install reproduces the "no perl → no bound" path faithfully: bounded_run is now always defined but unset -f'd when perl is missing, landing on the same end state (gh_call_limit defined, bounded_run/gh undefined, nothing marked readonly) as the original early-return behavior.
    • Confirmed no test directly sources repo-trust-hooks.sh or gh-bound.sh standalone, so the new readonly -f calls can't collide with a second sourcing in the same process (tests drive babysit-prs.sh as a subprocess per the AGENTS.md black-box rule).
  4. Docs. references/live-watch.md was updated to describe the main_loop_run entry point and that repo_trust_hooks_* now gates which hook loads, consistent with the code.
  5. Function sizes all look comfortably under the 50-line limit, and the baseline file (scripts/shell-size-baseline.txt) wasn't touched, consistent with the PR's validation claims (pnpm check:shell clean, no new exemptions).

No P1/P2/P3 findings to list — nothing I could construct a concrete failure scenario for. The one thing I couldn't independently verify is running shellcheck/pnpm check:shell myself (no shell execution permission in this review context beyond read-only git diff), so I relied on manual trace of the ShellCheck scoping rules and the PR's own stated validation output.

@chapati23

Copy link
Copy Markdown
Contributor Author

Claude review at 3b7710a: no findings, so nothing to fix. The PR body lists the two findings from the earlier local Codex pass: the directive scope in repo-trust-preflight.sh is fixed in 3b7710a, and the main-loop.sh rename is declined, with the reason under Deferrals.

@chapati23
chapati23 merged commit edebb6c into main Nov 26, 2026
5 checks passed
@chapati23
chapati23 deleted the refactor-shell-modules branch November 26, 2026 13:51
chapati23 added a commit that referenced this pull request Nov 26, 2026
…#75)

* fix(babysit-pr): treat a clean Claude review summary as informational

The watcher counted every claude-code-action summary as unanswered
top-level feedback, so a PR with an LGTM review stayed FEEDBACK_GATE_PENDING
until someone replied (agents #73 and #74). The summary is free-form model
text, so the review prompt now asks for one exact last line on a clean
review, and the watcher drops a github-actions[bot] summary only with the
action's header, that last line and no [P1]-[P3] tag.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013qZ16z2jrxp57w1mwaZtzP

* fix(babysit-pr): require the whole clean shape of a Claude summary

The local Codex review found that a summary with an untagged finding and
the result line cleared the gate. A clean summary now holds only the
header, blank lines and checklist items before that line; anything else
stays actionable. Logins may carry a managed-user shortcode, and the watch
runbook states one rule for Claude summaries instead of two.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013qZ16z2jrxp57w1mwaZtzP

* fix(babysit-pr): a clean Claude summary is the header and one line

The second local Codex review found that an open checklist item could
carry an unanswered request past the gate, and that the prompt did not
describe the whole accepted body. A clean summary is now the action's
header and rule plus the result line and nothing else, and both prompts
ask for exactly that body.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013qZ16z2jrxp57w1mwaZtzP

* fix(babysit-pr): accept a Claude header without a duration

The pinned claude-code-action leaves out " in <time>" when it has no
timing, and writes the time only as "Ns" or "Nm Ns". The header match now
makes that clause optional and accepts only those two forms (third local
Codex review).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013qZ16z2jrxp57w1mwaZtzP

* style(babysit-pr): apply prettier to exact-feedback-formats.md

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013qZ16z2jrxp57w1mwaZtzP

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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