docs: expand usage guide — architecture, GHA/K8s recipes, troubleshooting#14
Conversation
…ooting Closes #12. Add `docs/` at repo root with five new pages: `architecture.md` (hook model, token lifecycle per flow, cache layout, sync scheduler, TTY-aware warmup, logging + scrubbing), `github-actions.md` (Keycloak/Auth0/Okta IdP setup, reusable workflow, matrix builds, audience pinning, fork-PR limitations), `kubernetes.md` (CronJob as headline + Job/Deployment, multi-provider pods, IdP setup, RBAC, OpenShift caveats), `local-development.md` (sandbox config, plugin re-export trick, force re-auth, dev-only env subject token), and `troubleshooting.md` (symptom-keyed: model list empty, redirect_uri_mismatch, 403 model discovery, invalid_client, headless hang, token-rotation drift, provenance badge missing, ERR_PNPM_IGNORED_BUILDS). Ship `.github/workflows/opencode-run.yml` as a `workflow_call` reusable workflow consumers can pin via `uses: vymalo/opencode-oauth2/.github/workflows/opencode-run.yml@v0.x`. Slim both READMEs: root README adds a small mermaid diagram and a docs index; package README condenses the federated-identity section to short quick-references plus links to the full recipes in docs/. The canonical configuration field reference stays in the package README. Every claim traces to source — config field defaults, error event names, cache filename patterns, env-var contracts, and the isTokenValid machine-flow split were all read off packages/opencode-oauth2/src/{config,cache,oauth/*,plugin,opencode}.ts rather than guessed. All YAML/JSON snippets parse with js-yaml / JSON.parse. typecheck / test (94/94) / build all green. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request introduces comprehensive documentation for the @vymalo/opencode-oauth2 plugin, including new guides for architecture, GitHub Actions, Kubernetes, local development, and troubleshooting. The README files were updated to include a Mermaid flowchart and link to these new resources. Feedback was provided to correct a missing this. prefix in a code snippet within the architecture documentation to ensure it matches the actual implementation.
| // user flows: treat undefined expiry as VALID (cost of re-auth is high) | ||
| return !machineFlows.includes(this.server.authFlow); | ||
| } | ||
| return Date.now() + tokenExpirySkewMs < token.expiresAt; |
There was a problem hiding this comment.
The code snippet is missing the this. prefix for tokenExpirySkewMs. In the actual implementation in packages/opencode-oauth2/src/oauth/client.ts, this is a class property.
| return Date.now() + tokenExpirySkewMs < token.expiresAt; | |
| return Date.now() + this.tokenExpirySkewMs < token.expiresAt; |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dddbcd1d16
ℹ️ 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".
| if: always() | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: opencode-stdout-${{ github.run_id }}-${{ github.run_attempt }} |
There was a problem hiding this comment.
Make artifact names unique per invocation
In .github/workflows/opencode-run.yml, the uploaded artifact name is derived only from github.run_id and github.run_attempt, so every invocation of this reusable workflow within the same caller workflow run uses the same name. With actions/upload-artifact@v4, artifact names must be unique per run; if a caller uses this reusable workflow in multiple jobs or a matrix, later uploads fail with a conflict error, breaking those jobs even though opencode run succeeded.
Useful? React with 👍 / 👎.
Closes #12.
Summary
Adds a
docs/directory at the repo root with five focused pages, ships a reusableworkflow_callworkflow consumers can pin against, and slims both READMEs so the canonical configuration reference stays in the package README while the long-form recipes live alongside.Every claim in the docs was checked against the actual source — config field defaults, error event names, cache filename patterns, env-var contracts, the
isTokenValidmachine-flow split, the TTY-aware warmup detection,scrubSecretssubstring patterns, all of it — by readingpackages/opencode-oauth2/src/{config,cache,oauth/*,plugin,opencode,logging,model-discovery}.tsrather than guessing.Files added
docs/architecture.md(275 lines) — the two hooks (configat load,chat.headersper request), token lifecycle per flow with a state-machine table,isTokenValidpolicy and the machine-flow split, TTY-aware warmup detection, cache layout per OS + file shape + eviction rules, sync scheduler failure handling, structured logging events table, redaction layers (field-name +scrubSecretssubstring), and a mermaidsequenceDiagramshowing on-demand auth onopencode run.docs/github-actions.md(290 lines) — Keycloak setup walkthrough (Identity Provider, client, Token Exchange permissions, claim mapping — verified againstauth.verif.fyi/realms/camer-digital), shorter Auth0 / Okta sections with vendor-doc links, the shipped reusable workflow, a minimal worked example (workflow + committedopencode.json), matrix builds, audience pinning rationale and per-workflow audience table, fork-PR limitations with three workaround tiers (push-only,pull_request_targetwith label gating, restricted-scope reusable).docs/kubernetes.md(374 lines) —CronJobas the headline (full manifest with projected SA token volume, scheduled summarization use case),Job(minimal),Deploymentwith the kubelet-rotation-is-transparent story, multi-provider pods with multipletokenPaths and audiences, IdP setup for Keycloak/Dex including how to discover the cluster's OIDC issuer (kubectl get --raw /.well-known/openid-configuration), explicit "the SA needs no RBAC" section, honest OpenShift caveats ("don't assume parity without testing").docs/local-development.md(190 lines) —OPENCODE_CONFIG_DIR=/tmp/...sandbox, plugin re-export trick (re-export fromdist/), fixedredirectPortvs random tradeoffs per IdP, force re-auth one-liners per OS with the "Keycloak refresh preserves originally-granted scopes" rationale, dev-onlyenvsubject token source for testing federated flows without a live runner.docs/troubleshooting.md(251 lines) — symptom-keyed (8 entries):/modelsempty,redirect_uri_mismatch,model discovery failed (403),oauth_client_credentials_failed401,jwt_bearer401, headless hang, projected-token rotation drift, missing npm provenance badge,ERR_PNPM_IGNORED_BUILDS. Each entry: what's happening internally, which log event to grep for, and a curl/kubectl/jq diagnostic the reader can run..github/workflows/opencode-run.yml(124 lines) —workflow_callreusable workflow with inputs formodel,prompt,opencode-config-path,node-version,runs-on,opencode-version,plugin-version. Grantsid-token: writeso federated identity flows work; uploads stdout as an artifact.Files modified
README.md(root) — added a small mermaid block at the top, trimmed duplicated material, replaced it with a docs index table linking all five new pages.packages/opencode-oauth2/README.md— kept the canonical configuration field reference (it's THE reference; expanded the optional-fields table withnameOverrides,syncIntervalMinutes,jwksUri, and the top-levelcacheNamespace/httpTimeoutMs/tokenExpirySkewMsblock). Condensed the long Federated Identity section to short quick-reference YAML snippets plus links todocs/github-actions.mdanddocs/kubernetes.mdfor the full recipes.Verification
pnpm -r typecheck— greenpnpm -r test— 94/94 passingpnpm -r build— green.github/workflows/opencode-run.ymlparses with js-yaml (alongside the existing publish.yml and ci.yml)JSON.parsepnpm lint/pnpm format:checkfail with "No files were processed" at the workspace level — this is pre-existing onmain(Biome'sbiome.jsonexcludes.mdand the project-level scripts pass.to biome which then reports nothing to do). Spot-checkednpx biome check packages/opencode-oauth2/src/config.tsworks.Honest punts
docs/kubernetes.mdcovers the documented projected-token differences and SCC implications, then explicitly says: "the maintainer hasn't validated this end-to-end on OpenShift, so don't assume parity with upstream Kubernetes without testing." Better than fabricating.Test plan
sequenceDiagraminarchitecture.mdand theflowchart LRin root README)docs/architecture.md→../packages/opencode-oauth2/src/..., root README →docs/*.md, package README →../../docs/*.md)🤖 Generated with Claude Code