Skip to content

skills(install-tend): restructure bot-token step around scope-audit remediation - #680

Merged
max-sixty merged 6 commits into
mainfrom
install-tend-scope-remediation
Jun 10, 2026
Merged

max-sixty merged 6 commits into
mainfrom
install-tend-scope-remediation

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Step 8 of the install-tend skill previously had a single path: a full gh auth login device flow, written for first-time setup and run by the user. This PR restructures it around what the step actually does (check what gh already stores for the bot, mint a token only if needed, push it to the repo secret) so one procedure serves both fresh installs and the Bot PAT scope-audit remediation that nightly audit issues link to.

What changed:

  • State-driven routing: a keyring check routes to "stored token already good, skip to the push", "present but under-scoped, gh auth refresh" (new 8a: preserves existing scopes and hard-fails if the wrong browser account approves, so no post-hoc identity check is needed), or "absent, gh auth login" (8b, the old path with its verify step).
  • One env-var rule, stated by mechanism: commands that gh's GH_TOKEN/GITHUB_TOKEN precedence breaks carry the env -u prefix (login/refresh/switch/logout and gh api user); env-indifferent commands run bare.
  • Hardened secret push (8c): the old gh auth token | gh secret set pipe could silently blank a working secret. gh secret set accepts an empty body (cli/cli set.go reads stdin with a bare io.ReadAll) and the pipe's exit status hides the failed read, while the step's freshness check still passes. Now: capture, emptiness guard, --body.
  • Agent-run device flow: the agent runs the flow in the background and surfaces the one-time code; delegating to the user's terminal is the fallback, with the credential-store consequence spelled out (subsequent gh auth token --user reads must run in that same terminal). Device-code expiry (~15 minutes) documented.
  • Audit-issue accuracy: the nightly skill's scope-audit instruction now requires naming the repo's actual configured secret (secrets.bot_token, default TEND_BOT_TOKEN) rather than improvising a placeholder. A real audit issue invented BOT_GITHUB_TOKEN, which cost remediation time before the real secret name was identified.

The gh behavioral claims were verified against cli/cli source: the env-token guard shared by login/refresh/switch/logout, refresh's wrong-approver rejection and scope merging, the (keyring) suffix in gh auth status output, TokenForUser ignoring env vars, and gh secret set accepting an empty body.

Supersedes the unmerged install-tend-refresh-shortcut branch (093000b), whose refresh-path change is incorporated here.

This was written by Claude Code on behalf of max

🤖 Generated with Claude Code

max-sixty and others added 3 commits June 9, 2026 22:00
…emediation

Step 8 is the remediation target that nightly's PAT scope-audit issues
link to, but it only described first-time setup. Rework it:

- Split into 8a (refresh — bot already in keyring), 8b (login —
  first-time), 8c (push token to secret), routed by a `gh auth status`
  keyring check; insecure-storage entries route to 8b.
- Lead with the scope-audit arrival case: mint the broader token, update
  the `secrets.bot_token` secret from `.config/tend.yaml` (default
  TEND_BOT_TOKEN), close the issue. Audit issues may paraphrase the
  secret name, so go by the config.
- Document GH_TOKEN/GITHUB_TOKEN env precedence once up front and prefix
  keyring-mutating and identity-read commands with
  `env -u GH_TOKEN -u GITHUB_TOKEN`; `gh auth token --user` and
  `gh secret` run bare.
- Run the device flow ourselves when shell/keyring access allows
  (background it, surface the code/URL); hand it to the user only when
  we can't. Refresh needs no post-hoc identity check — a wrong-user
  approval errors and discards the credentials.
- Parameterize the secret name in 8c and the summary checklist instead
  of hardcoding TEND_BOT_TOKEN.

nightly: the scope-audit issue body must name the secret by its real
config name (`secrets.bot_token` value, default TEND_BOT_TOKEN), never a
placeholder.

Co-Authored-By: Claude Fable 5 <[email protected]>
Review fixes on top of the step-8 redesign: guard the secret push
against blanking on a failed keyring read, add a skip route when the
stored token already carries all six scopes, document device-code
expiry and the delegation credential split, prefix every env-sensitive
command, and rebuild the intro as one state-driven flow.

Co-Authored-By: Claude Fable 5 <[email protected]>

@tend-agent tend-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Verified the gh behavioral claims against cli/cli v2.92.0 — the env-token guard fires for login/refresh/switch/logout, refresh merges existing scopes and rejects mismatched users with "received credentials for …", and gh secret set's getBody blindly takes io.ReadAll(stdin) with no emptiness check. Routing logic and (keyring) source detection match status.go's output format.

One robustness note inline on 8c.

…dent

The bare [ -n ] test only halts under set -e; chain with || exit so a
failed keyring read short-circuits the secret push in any shell.

Co-Authored-By: Claude Fable 5 <[email protected]>
max-sixty and others added 2 commits June 9, 2026 22:50
- chain 8a's switch and refresh with && so a failed switch can't run
  the device flow against the wrong account
- replace the unactionable "switch away afterwards" advice in 8c's
  skip branch (the bot is the sole keyring account there) with why
  bot-stays-active is harmless under an env-token maintainer
- condition the Browser sessions claim on step 8's mint paths
- scope-merge claim now scoped to still-valid stored tokens
- delegation trigger is now testable (delegate only if running it
  yourself fails) and hands over fully substituted commands
- restore the canonical-repo caveat on the inline $REPO derivation
- pat-scope-audit.sh sync note covers multiple occurrences per file

Co-Authored-By: Claude Fable 5 <[email protected]>
@max-sixty
max-sixty merged commit 79a3fd3 into main Jun 10, 2026
4 of 5 checks passed
@max-sixty
max-sixty deleted the install-tend-scope-remediation branch June 10, 2026 07:57
@max-sixty max-sixty mentioned this pull request Jun 11, 2026
max-sixty added a commit that referenced this pull request Jun 11, 2026
Bumps the generator version to 0.1.4, syncs the lockfile, and adds the
0.1.4 CHANGELOG section (published as the GitHub Release notes on tag
push).

Notable changes since 0.1.3:

- Claude harnesses switch to `bypassPermissions` (#677)
- GitHub Releases publish from `CHANGELOG.md` on tag push (#678) — this
release is the first live exercise of that workflow
- Interactive sandbox receives GitHub Actions context env vars (#664)
- install-tend bot-token step restructured around scope-audit
remediation (#680)
- Review skill checks the rollup before APPROVE (#667);
running-in-ci/triage/ci-fix skill refinements (#661, #666, #669, #670,
#671)

> _This was written by Claude Code on behalf of max_

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Fable 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.

2 participants