actions-state-and-secrets
Use when persisting values across a GitHub Action's pre/main/post phase boundary, handling a Redacted secret anywhere in @effected/github-actions, deciding whether a value belongs in ActionState or ActionOutputs, framing a blob with metadata for a cache or object store, reaping a detached child process, or rendering an Action's top-level failure. Also use when: ActionState, Redacted secret, BlobEnvelope, Secret.forChildEnv, Secret.forRunnerFile, Secret.forSigning, Secret.adopt, DryRun, DetachedProcess, GITHUB_STATE, ChildEnv PATH prepend
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 8
- Forks
- 2
01 前言 Front Matter
- name
- actions-state-and-secrets
- description
- Use when persisting values across a GitHub Action's pre/main/post phase boundary, handling a Redacted secret anywhere in @effected/github-actions, deciding whether a value belongs in ActionState or ActionOutputs, framing a blob with metadata for a cache or object store, reaping a detached child process, or rendering an Action's top-level failure. Also use when: ActionState, Redacted secret, BlobEnvelope, Secret.forChildEnv, Secret.forRunnerFile, Secret.forSigning, Secret.adopt, DryRun, DetachedProcess, GITHUB_STATE, ChildEnv PATH prepend
02 资源文件 3
- 参考文档references/cross-phase-state.md7.7 KB
- 参考文档references/detached-processes.md5.6 KB
- 参考文档references/secrets.md7.7 KB
03 SKILL.md 正文
Actions state and secrets
Everything in @effected/github-actions that crosses a phase boundary, or that must not leak. Each phase (pre/main/post) is a separate process; GitHub's own mechanism for carrying a value between them is a write-only file (GITHUB_STATE) whose entries the runner republishes to the next phase as STATE_<key> environment variables. That asymmetry — write through a file, read through the environment — is why ActionState is a service rather than a pair of helper functions.
For general Effect v4 service/layer shape, typed errors, Cause, and Scope, see effect-v4-services-layers, effect-v4-idioms, effect-v4-schema. This skill carries only the Actions-specific instance of those rules.
What you have
| Construct | Import | Reach for it when |
|---|---|---|
ActionState.save / .get / .getOptional |
import { ActionState } from "@effected/github-actions" |
round-tripping an ordinary, non-secret value across pre/main/post |
ActionState.saveSecret |
same | persisting a value that came from a Redacted across the phase boundary |
Secret.forChildEnv / .forRunnerFile / .forSigning / .adopt |
import { Secret } from "@effected/github-actions" |
the one module that turns a Redacted into a plaintext string, masking first |
DryRun.guard |
import { DryRun } from "@effected/github-actions" |
running a mutation for real, or logging and returning a fallback in a rehearsal |
DetachedProcess.reap |
import { DetachedProcess } from "@effected/github-actions" |
signalling a child process by a pid read back out of GITHUB_STATE |
ChildEnv.prependPath |
import { ChildEnv } from "@effected/github-actions" |
safely extending a spawned child's PATH across platforms |
BlobEnvelope |
import { BlobEnvelope } from "@effected/github-actions" |
framing bytes with caller-owned metadata before they reach a cache or blob store — full treatment in actions-cache-and-artifacts' references/blob-stores.md |
Standards
- Choose
ActionStatevsActionOutputsmechanically, not stylistically.ActionStatecrossespre → main → postof the same action and never persists past the run;ActionOutputscrosses one step to a later step (possibly a different action) viawith:outputs. A provisioned token or a detached child's pid is state; a value the workflow author wired intosteps.<id>.outputs.<name>is an output. - Design every state field's encoded form as plain JSON. Use
Schema.OptionFromNullOr, neverSchema.Option, for an optional field — the latter's encoded form is anOptioninstance, not a JSON primitive, and the failure lands one phase later than the mistake. - Call
saveSecretfor anything that came from aRedacted, ever; call plainsavefor everything else. OnlysaveSecretmasks before persisting.GITHUB_STATEis plaintext by GitHub's protocol, so the mask coupled to the write is the only defense a persisted secret gets. - Let
Secret.tsbe the only place aRedactedbecomes a string. When a genuine third need for a raw secret shows up, add a member toSecretrather than granting an exception elsewhere — masking and declassifying are the same call by design. - Give
DryRun.guarda real fallback, always. The fallback is required, not optional, so a rehearsal's return value is a design decision, not an afterthought. - Validate a pid on the way out of
ActionState, and again inDetachedProcess.reap. A pid that crosses a text-file boundary has already lost whatever type safety it had; guard it at both ends rather than trusting the second guard alone. - Audit every ported error channel for whether it can actually fire. A channel wrapped around a body that can never throw is worse than no channel — delete the reason from the signature, or write a test that fires it.
Footguns
-
An
Optionfield encoded withSchema.Optioninstead ofSchema.OptionFromNullOrreports success inmainand fails to decode inpost— the mistake and its failure land in different phases. Seereferences/cross-phase-state.md. -
DetachedProcess.reaptakes a plainnumber: an absent state key, a truncated file, or a bad parse all decode to0, andprocess.kill(0, …)signals the caller's entire process group. Seereferences/detached-processes.md. -
envpassed to a spawn call withoutextendEnv: truereplaces the child's whole environment, including thePATHa caller meant to extend. Seereferences/detached-processes.md. -
BlobEnvelope's wire format, five-reason error union, and why a legacy raw blob decodes as a clean miss rather than garbage live inactions-cache-and-artifacts, not here — don't re-derive the frame shape from this skill's description alone. -
A
Schema.Redactedfield persisted as JSON round-trips to the literal string<redacted>. This is core Effect behavior, not a kit choice, and it is silent — the write succeeds, the read succeeds, and the value is garbage. Probed (Schema.Redactedencode → an object whoseJSON.stringifyis"<redacted>";Schema.RedactedFromValueencode →"s3cret"):Schema.Redacted(Schema.String) encode -> a Redacted object JSON.stringify of that -> "<redacted>" Schema.RedactedFromValue(Schema.String) encode -> "s3cret" (the real value)Redacted's owntoString/toJSONare what emit the sentinel, so anything that serializes aRedacted—JSON.stringify, a log line, a state field — gets<redacted>rather than the secret. That is the right default and the reason it exists. But it meansSchema.Redactedis the wrong schema for a value you intend to read back: useSchema.RedactedFromValue, whose encoded form is the underlying value (and which takesdisallowEncodewhen you want the write to fail loudly instead). In an Actions context that round trip isActionState.saveSecreton the way in — it masks before persisting — andActionState.get/getOptionalon the way back out. One consumer lost real time to a token-theft theory before finding the sentinel was simply the encoder's output.
Additional resources
- references/cross-phase-state.md —
ActionState's full shape and round-trip mechanics, theActionState-vs-ActionOutputsdecision table in full,DryRun's safe-default contract, and the failure-channel discipline that decides demote-vs-die before aCauseever reachesAction.run. Load when: designing a state bundle, choosing between state and outputs, or auditing an error channel. - references/secrets.md —
Secret's four members in full, the v4 fact that keeps the seam small (HttpClientRequest.bearerTokenaccepting aRedacteddirectly), the structural scan that proves onlySecret.tsunwraps one, and@effected/commands'Redactionfor value-based scrubbing. Load when: adding a new place a secret needs to leaveRedacted, or reviewing a suspected leak. - references/detached-processes.md —
DetachedProcess.reap's bare-pid guard and its test discipline,ProcessId's validating constructor, andChildEnv's three PATH-prepending traps (extendEnv, Windows casing,.cmdshim shells). Load when: spawning or reaping a detached child process, or prepending to a child'sPATH.
04 同仓库更多 Skills
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.
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.
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.
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.
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.
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.