Task · SKT-0005.03

Harden env helper scripts and secret-file replacement

Description

The shipped setup helpers abort when replacing the sole line in an env file, interpolate arbitrary keys into regular expressions, and can leave a secret-bearing .env.tmp inside the repository. Make them safe for agent-driven repeated setup.

Acceptance Criteria

Definition of Done

Implementation Plan

  1. Add failing automated cases for sole-line replacement, invalid/metacharacter keys, duplicate cleanup, modes, and interrupted replacement behavior.
  2. Harden set-env.sh and add-secret.sh with literal validated keys and safe mode-preserving atomic replacement.
  3. Replace the CONTROL_TOKEN .env.tmp recipe in initial-setup with the safe helper workflow.
  4. Run the focused helper test suite and shell syntax checks.

Implementation Notes

Wave 1 started. File owner: env-helper lane owns the two helper scripts, focused helper tests, and plugins/synthkit/skills/initial-setup/SKILL.md. It must not touch .env.example or marketplace metadata.

Implementation complete pending integrated review/gate. Both env helpers now validate literal keys before target access, replace duplicate and sole-line entries, use mode-0600 atomic temporary files with cleanup, and preserve targets on validation/write failure. initial-setup generates CONTROL_TOKEN through add-secret.sh rather than .env.tmp. TDD reproduced the prior failures; bash syntax checks and 19 focused helper cases passed. Full gate remains root-owned.

Integrated evidence: CodeRabbit reviews used 4 of the authorized 8. Valid findings fixed: jq false-output false pass, newline/value mangling, empty DRY_RUN safe default, helper test CI wiring, polling flake margin, pipefail for token generation, repeated-setup guard, and same-filesystem atomic temp placement. Two minor telemetry-sourcing findings were dismissed because they concerned synthkit control-API fields and verbatim moved dashboard guidance, not invented telemetry. Final review reported zero findings. make gate and the 26-blueprint dry-run inventory passed.

Final Summary

Landed in 9c93f5c: both env helpers now validate literal keys/round-trippable values, atomically replace mode-0600 files on the target filesystem, clean interruption/failure temps, and keep secret generation pipefail-safe. Twenty-seven helper cases run in local and CI test paths; clean CodeRabbit review 4, make gate, and dry-run inventory passed.

References

View the source file on GitHub