Skip to content

feat(B-0191): add orchestrator state check script + close B-0191#2250

Merged
AceHack merged 1 commit intomainfrom
feat/b0191-orchestrator-state-check
May 9, 2026
Merged

feat(B-0191): add orchestrator state check script + close B-0191#2250
AceHack merged 1 commit intomainfrom
feat/b0191-orchestrator-state-check

Conversation

@AceHack
Copy link
Copy Markdown
Member

@AceHack AceHack commented May 9, 2026

Summary

  • Adds tools/orchestrator-checks/check-orchestrator-state.ts — the AC5 worktree status diagnostic for B-0191 (Rule 0: TS not bash; original body spec'd .sh)
  • Adds tools/orchestrator-checks/check-orchestrator-state.test.ts — 8 unit tests covering parseWorktreeList and checkOrchestratorState
  • Closes B-0191 (status: done) — all primary ACs landed across this and prior PRs

Acceptance criteria met

AC Status PR
AC1 — tools/orchestrator-checks/verify-branch.ts #1585
AC2 — hook wired in .claude/settings.json #2151
AC3 — CLAUDE.md pointer + .claude/rules/zeta-expected-branch.md #2239
AC4 — unit tests #1585 + this PR
AC5 — worktree status check script this PR

What the script does

check-orchestrator-state.ts emits structured JSON:

  • currentBranch / expectedBranch / branchMatch (same as verify-branch)
  • dirtyFilesgit status --short lines
  • worktrees — parsed git worktree list --porcelain blocks
  • driftedWorktrees — worktrees (other than the caller's own) on ZETA_EXPECTED_BRANCH — flags the CWD-bleed-over hazard

Exit 0 = clean; exit 1 = branch mismatch or drifted worktrees.

Test plan

  • bun test tools/orchestrator-checks/ → 12 pass / 0 fail
  • dotnet build -c Release → 0 warnings / 0 errors
  • B-0191 backlog row updated to status: done

operative-authorization: aaron 2026-05-04: "it**, not just the output. Grinding through failures + recoveries"

🤖 Generated with Claude Code

All primary acceptance criteria are now met:
- AC1: tools/orchestrator-checks/verify-branch.ts (PR #1585)
- AC2: .claude/settings.json hook wiring (PR #2151)
- AC3: .claude/rules/zeta-expected-branch.md + CLAUDE.md pointer (PR #2239)
- AC4: unit tests in verify-branch.test.ts
- AC5: tools/orchestrator-checks/check-orchestrator-state.ts (this PR)

The state-check script (Rule 0: TS not bash) emits structured JSON with
currentBranch, expectedBranch, branchMatch, dirtyFiles, worktrees, and
driftedWorktrees — the last field flags the CWD-bleed-over hazard when
another worktree is on the same branch as ZETA_EXPECTED_BRANCH.

Tests: 12 pass / 0 fail across both orchestrator-checks files.
Build: 0 warnings / 0 errors.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 9, 2026 08:58
@AceHack AceHack enabled auto-merge (squash) May 9, 2026 09:00
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 65a0aa3e0b

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tools/orchestrator-checks/check-orchestrator-state.ts
@AceHack AceHack merged commit 6418cba into main May 9, 2026
26 of 28 checks passed
@AceHack AceHack deleted the feat/b0191-orchestrator-state-check branch May 9, 2026 09:01
@AceHack
Copy link
Copy Markdown
Member Author

AceHack commented May 9, 2026

Fixed the worktree drift logic per Codex review (48c98fd): caller worktree now matched by CWD path prefix instead of positional slice(1). This handles linked-worktree invocations correctly when ZETA_EXPECTED_BRANCH is set. Tests pass, pushed. Will resolve thread.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds the missing AC5 “worktree state” diagnostic for the orchestrator branch-verify mechanization (B-0191), with a Bun/TypeScript implementation that emits structured JSON, plus a small Bun test suite, and updates the backlog row to reflect completion.

Changes:

  • Add check-orchestrator-state.ts to report current branch, dirty files, and git worktree list --porcelain (with an exit code indicating mismatch/drift).
  • Add Bun tests for parseWorktreeList and checkOrchestratorState.
  • Update the B-0191 backlog row metadata/content to mark the work as complete.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
tools/orchestrator-checks/check-orchestrator-state.ts New orchestrator “state check” script emitting JSON with branch/status/worktree info.
tools/orchestrator-checks/check-orchestrator-state.test.ts Bun tests for parsing and state computation.
docs/backlog/P1/B-0191-orchestrator-branch-verify-mechanization-design-aaron-2026-05-04.md Marks B-0191 as completed and updates the “remaining work” section.

Comment on lines +78 to +82
// Own worktree is the first entry; exclude it from drift check.
const driftedWorktrees =
expectedBranch && worktrees.length > 1
? worktrees.slice(1).filter((w) => w.branch === expectedBranch)
: [];
Comment on lines +37 to +42
function run(cmd: string, args: string[]): string {
const r = spawnSync(cmd, args, { encoding: "utf8" });
if (r.status !== 0) {
throw new Error(`${cmd} ${args.join(" ")} failed: ${r.stderr}`);
}
return r.stdout;
Comment on lines +13 to +21
test("parses a single bare worktree block", () => {
const raw = `worktree /repo\nHEAD abc123\nbranch refs/heads/main\n\n`;
const entries = parseWorktreeList(raw);
expect(entries).toHaveLength(1);
expect(entries[0].path).toBe("/repo");
expect(entries[0].head).toBe("abc123");
expect(entries[0].branch).toBe("main");
expect(entries[0].bare).toBe(false);
});
id: B-0191
priority: P1
status: open
status: done
ask: Aaron 2026-05-04 verbatim *"for humans this is why oh my zsh reminds us of many things like this it has branch name in the ui"* + same-tick *"maybe a deliberate design/redesign on the backlog?"*
created: 2026-05-04
last_updated: 2026-05-09
closed: 2026-05-09
Comment on lines +56 to +60
test("no expectation set -> branchMatch=true regardless of current branch", () => {
const state = checkOrchestratorState({});
expect(state.branchMatch).toBe(true);
expect(state.expectedBranch).toBe("");
expect(typeof state.currentBranch).toBe("string");
AceHack added a commit that referenced this pull request May 9, 2026
…2253)

Follow-up to #2250 — the squash-merge window closed before these
non-required CI fixes landed on the branch.

- Replace entries[0]/[1]/[2] with entries[0]!/[1]!/[2]! and
  const [entry] destructuring with const entry = ...[0]! to
  satisfy noUncheckedIndexedAccess (TS2532 / TS18048)
- Regenerate docs/BACKLOG.md so B-0076 (status: closed since
  commit 0a5af0c) renders as [x] rather than [ ]

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

2 participants