AGENT SKILL

github-app-tokens

Use when a GitHub credential needs to come into existence, live somewhere, and die — constructing a client from a plain token or a GitHub App, or wiring GitHubToken's provision/read/clientLayer/dispose lifecycle across an Action's pre/main/post phases.

License 许可
MIT
最近更新
2026-11-14
Stars
★ 8
Forks
2

01 前言 Front Matter

name
github-app-tokens
description
Use when a GitHub credential needs to come into existence, live somewhere, and die — constructing a client from a plain token or a GitHub App, or wiring GitHubToken's provision/read/clientLayer/dispose lifecycle across an Action's pre/main/post phases.
when_to_use
GitHubApp, installation token, App JWT, appClientLayer, cachedToken, cachedClientLayer, InstallationTokenStore, PKCS#1 private key, token bridge, GitHubTokenError, botIdentity, TokenPermissionError, revoke on release, acquireUseRelease token, GITHUB_STATE persisted token, plain GITHUB_TOKEN input

02 资源文件 2

03 SKILL.md 正文

GitHub App tokens: the credential lifecycle

Two packages, one lifecycle: how a GitHub credential comes into existence, where it lives, and when it dies. @effected/github mints and revokes; @effected/github-actions persists a mint across a process boundary and guarantees it dies exactly once. For the request surface itself (client.request, GitHubError, pagination) see github-api. For wiring Action.run and ActionRunOptions.layer, see actions-runtime. For the Secret seam and ActionState, see actions-state-and-secrets.

What you have

Construct Import Reach for it when
GitHubClient.layerFromToken import { GitHubClient } from "@effected/github" You already hold a Redacted<string> token
GitHubClient.layerFromConfig @effected/github The workflow's own runner-issued token is enough
GitHubApp (.token, .scopedToken, .revoke, .identity, .botUser, .installations, .clientLayer, .appClientLayer, .cachedToken, .cachedClientLayer) @effected/github Minting/revoking an installation token directly, outside an Action's process boundary; speaking as the app itself; reusing a token across request scopes through an InstallationTokenStore
TokenPermissions @effected/github Comparing a token's granted scopes against what a program requires
BotIdentity @effected/github Rendering a DCO trailer, or naming the bot identity behind a token
GitHubToken (.provision, .read, .botIdentity, .clientLayer, .dispose) import { GitHubToken } from "@effected/github-actions" Bridging an App-minted token across an Action's pre/main/post process boundary

Standards

  • Pick the plain-token path first. GitHubClient.layerFromConfig() needs no ActionState, no GitHubApp, no revoke lifecycle — reach for App auth only when the runner's own token can't provide a permission or a distinct bot identity your program needs.
  • GitHubApp.clientLayer lives on GitHubApp, not GitHubClient. A layer-family static belongs to the module that owns the dependency it needs; putting it on GitHubClient would drag the JWT signer into every token-only consumer's bundle. See references/client-construction.md.
  • Use GitHubToken, never GitHubApp.scopedToken/.clientLayer, inside an Action. Both revoke on their Scope's close, and in an Action the scope closes at the end of pre — before main runs a single request. GitHubToken persists the mint through GITHUB_STATE instead.
  • Build a layerTest from the member-usage table, not from a stack trace. Each GitHubToken member touches an exact, documented set of ActionState/ActionOutputs/GitHubApp members — stub exactly those. See references/token-lifecycle.md.
  • Verify required scope at pre, not by waiting for a 403 in main. Set GitHubToken.provision's required option every time — leaving it unset skips verification silently.
  • Revoke the mint on any provisioning failure. provision is an acquire-use-release: a scope-verification or persistence failure revokes the just-minted token rather than leaving an hour of unreferenced access live for a retried pre.
  • post disposes unconditionally, wrapped double-netted. dispose() is already a no-op with nothing to revoke, but still wrap the call in catch + catchDefect — a post phase must never turn a green run red over a token it was only trying to clean up.
  • Never reintroduce @octokit/rest or @octokit/auth-app. A small, zero-dependency JWT signer plus one typed route call covers what minting an installation token actually needs; both larger dependencies were deliberately dropped.

Footguns

  • An installation token lives about an hour and nothing can re-mint one after pre — the only credential that could is the App's private key, and persisting that through GITHUB_STATE (plaintext by GitHub's own protocol) would trade an hour-long token for a permanent one. A phase expecting to outlive the hour calls provision itself.
  • The scope-verification field is named required, not permissions — permissions is the field on the minted token. A double or migration script that writes permissions on ProvisionOptions compiles clean and silently skips verification. See references/token-lifecycle.md.
  • Masking must happen before persistence — the ordering is structural in provision, not a convention a caller has to remember; get it backwards in a hand-rolled variant and a plaintext token reaches GITHUB_STATE unmasked.
  • dispose reads with getOptional, never get — a post phase after a pre that failed before minting anything must be a no-op, not a typed failure.

Additional resources

  • references/token-lifecycle.md — the GitHubToken bridge in full: the member-usage table, the one-hour contract, provision/clientLayer/dispose mechanics, and the complete five-element App-auth recipe including how to add or remove it from an action. Load when: wiring App auth into an action's pre/main/post phases.
  • references/client-construction.md — the five GitHubClient constructors (token, config, installation, app JWT, cached token) in detail, why the package skips @octokit/rest/@octokit/auth-app, the GitHubApp service shape and its rotation/revocation mechanics, and the pure TokenPermissions/BotIdentity classes. Load when: constructing a client directly, or working with GitHubApp outside the GitHubToken bridge.

Pointers

  • The request surface (client.request, GitHubError's kind taxonomy, pagination, GraphQL) — github-api.
  • Wiring Action.run, ActionRuntime.layer, and the ActionRunOptions.layer type-level constraint clientLayer()'s fallible construction runs into — actions-runtime.
  • The Secret declassification seam and ActionState persistence — actions-state-and-secrets.
  • Testing doubles for any of the above (layerTest, the member-usage-table pattern, TestClock for expiry) — testing-actions.

04 同仓库更多 Skills

spencerbeggs
spencerbeggs/effected

testing-actions

Use when writing or reviewing tests for @effected/github-actions, @effected/github, @effected/sbom or @effected/commands — stubbing the GitHub API, writing a service's layerTest or makeTest double, testing the pre/main/post lifecycle through Action.run, or debugging why a test hits the real network or hangs.

★ 8
spencerbeggs
spencerbeggs/effected

supply-chain-attestation

Use when generating a CycloneDX SBOM, checking NTIA minimum elements, building an in-toto statement or a SLSA provenance predicate, signing into a Sigstore DSSE bundle, or uploading an attestation to GitHub.

★ 8
spencerbeggs
spencerbeggs/effected

structuring-an-action

Use when laying out a new GitHub Action repository on the @effected suite, deciding where a piece of code belongs (an entry point, a step, a shared service, a shim), or reviewing an existing action's file structure against the canonical shape.

★ 8
spencerbeggs
spencerbeggs/effected

running-commands-and-tools

Use when running a subprocess in Effect v4, spawning a command, capturing stdout/stderr/exit code, checking whether a CLI tool is installed or which copy to run, running a package-manager script through the project's launcher, detaching a background process, or redacting a secret from argv or captured output.

★ 8
spencerbeggs
spencerbeggs/effected

release-and-publish

Use when publishing a package to npm, reading the npm registry from Effect v4, checking whether a version is already published, cutting a release tag or GitHub release from an action, applying a release-age gate, or deriving tracking tags for GitHub Actions distribution.

★ 8
spencerbeggs
spencerbeggs/effected

hardening-a-parser-port

Use when porting or writing a recursive-descent parser, lexer, or tree-walker over untrusted text in the @effected monorepo — the class of hardening the cloud reviewer scans for on every migration. Covers stack-overflow depth guards (on EVERY recursion surface, which a facade has N of — not two), numeric bound guards that must reject NaN and non-integers, code-point range checks scoped to formats with wide escapes, prototype-pollution, control-character rejection, and the invariant that malformed input must fail through the typed error channel, never as an unhandled defect.

★ 8