Skip to content

^R D3: migrate copilot prefix-scrub + token-handoff invariants to Go (29 checks)#409

Merged
omkhar merged 1 commit into
mainfrom
d3/copilot-token-handoff-go
Jul 6, 2026
Merged

^R D3: migrate copilot prefix-scrub + token-handoff invariants to Go (29 checks)#409
omkhar merged 1 commit into
mainfrom
d3/copilot-token-handoff-go

Conversation

@omkhar

@omkhar omkhar commented Jul 6, 2026

Copy link
Copy Markdown
Owner

D3 (migrate verify-invariants.sh to Go) — increment 12 of N (larger batch). Follows #398-#408. Migrates 29 copilot prefix-scrub + token-handoff invariant checks (former lines 8240-8310), replacing a 71-line shell block.

What

  • internal/workcellhardening: new CheckCopilotTokenHandoff(rootDir) reusing evaluate() + existing kinds + targetFile (no new kinds). 29 checks across scripts/workcell (×15), provider-wrapper.sh (×7), development-wrapper.sh (×4), home-control-plane.sh (×1), container-smoke.sh (×2).
  • cmd/workcell-citools: new workcell-copilot-token-handoff subcommand.
  • scripts/verify-invariants.sh: block replaced by go_verify_citools workcell-copilot-token-handoff "${ROOT_DIR}" || exit 1. Stopped at line 8310 (topical seam; next guard reads a Go source file).

Wrinkles handled (parity)

  • copilot_wrapper loop: 2 wrappers × 4 probes emitted wrapper-major to match the shell's first-failure order; probes A/B kindPresent, C/D (duplicate OIDC/EXP loops) kindAbsent; basename interpolated into each message.
  • Two-file grep (token must not reach COPILOT_HOME): two ordered kindAbsent checks over the two files sharing the one message.
  • Multi-probe || guards: ordered checks sharing each guard's message, spanning different files via per-check targetFile (incl. function_block_contains_fixedkindFunctionBlock).

All needles unescaped byte-exact and verified as substrings of their real files; real repo → exit 0. Crafted violations across every category → exit 1 byte-identical. Real-repo assertion + a count=29 guard protect transcription.

Validation

go build/vet/gofmt, full go test ./... (table-driven, 12 failing fixtures + real-repo assertion), shellcheck -x, shfmt -d — all green. 4 files / 650 lines.

🤖 Generated with Claude Code

…avior-preserving)

Migrate the contiguous Copilot prefix-scrub + token-handoff invariant
cluster (scripts/verify-invariants.sh lines 8240-8310, 29 checks) to
internal/workcellhardening.CheckCopilotTokenHandoff, following the merged
D3 pattern (evaluate + kinds + per-check targetFile).

Scope stops at line 8310: the next guard (8311) reads a Go source file
(internal/host/hoststate/hoststate.go), a natural topical seam, and
including it would exceed ~30 checks.

- copilot_wrapper prefix-scrub loop (8 checks): emitted wrapper-major
  (provider then development) to reproduce the shell's first-failure
  order; two affirmative probes (kindPresent) + two duplicate-loop
  probes (kindAbsent), message interpolates basename(wrapper).
- Two-file COPILOT_HOME token-copy guard: two ordered kindAbsent checks
  (provider-wrapper.sh then home-control-plane.sh) sharing one message.
- Multi-probe || guards (no-auth classifier, handoff-dir, write-site
  re-check, leaf permissions, consumed marker): ordered checks sharing
  each guard's message; function-block probes span scripts/workcell,
  provider-wrapper.sh, and scripts/container-smoke.sh (new path const).

Replace the migrated block with:
  go_verify_citools workcell-copilot-token-handoff "${ROOT_DIR}" || exit 1

Tests: table-driven happy path + failing fixture per category + a
real-repo assertion (all 29 needles/paths byte-exact) + a count guard.
Parity: subcommand on real repo exits 0; crafted violations across the
loop, the two-file grep, multi-probe guards, and a different target file
exit 1 with byte-identical messages.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@omkhar

omkhar commented Jul 6, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: aa69994119

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

@omkhar omkhar merged commit 749206b into main Jul 6, 2026
13 of 14 checks passed
@omkhar omkhar deleted the d3/copilot-token-handoff-go branch July 6, 2026 03:17
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