Repository navigation
Support unattended worktree identities and environment generation - #11
Conversation
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
It is a large, security-sensitive release change (private file creation, path-traversal/symlink defense, identity lifecycle, version bump) that warrants final human review despite no concrete defects being found.
Review effort: Balanced
Findings: None
What changed in this PR
This PR extends mkwt's unattended (create) automation interface so an orchestrator can give each review worktree an independent, durable identity and a generated per-worktree environment file. Previously unattended creation rejected a nonempty WORKTREE_ENV; now it accepts literal (optionally multiline) templates, substitutes {id}/{n}, writes a private 0600 file under safe relative paths, and records mkwt-identity/mkwt-env-path in each worktree's Git registration so an identity stays reserved even if the env file is renamed or deleted. It also bumps the executable to 0.3.0 and documents the caller-locking contract and new error codes.
Changes:
- Add caller-supplied
--worktree-id, automatic/{id}identity allocation, andDUPLICATE_WORKTREE_IDdetection backed by persisted Git-registration metadata. - Add unattended env-file generation with strict path/symlink validation and private permissions (
UNSAFE_ENV_PATH,ENV_PATH_COLLISION,ENV_GENERATION_FAILED,IDENTITY_FAILED); support literal multiline config values. - Bump version to
0.3.0, surfaceworktree_id/worktree_env_pathin JSON, and document the locking/recovery contract.
| File | Description |
|---|---|
bin/mkwt |
New identity helpers, allocation, env generation, multiline config parsing, --worktree-id plumbing, and human-workflow identity recording; version bump. |
tests/test_automation.py |
Extensive new integration tests covering identities, env generation, path/symlink safety, failure classification, locking, and legacy/human compatibility. |
README.md |
Documents --worktree-id, env generation, identity/locking contract, new error codes, JSON fields, and 0.3.0 pinning. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Unattended creation rejected nonempty WORKTREE_ENV, so Orchestrator could not configure an independent local database identity for each review worktree. Creation now accepts an optional --worktree-id and literal multiline environment templates, writes private files, and records identities in Git worktree registrations so changing env filenames or deleting env files cannot free an active ID.
{id} uses the explicit or automatic identity; {n} remains a separately allocated numeric slot. The CLI rejects duplicate IDs and unsafe or existing environment destinations, preserves registration and ownership information on partial failure, and adds worktree_id and worktree_env_path to JSON schema version 1. Human copy-and-append behavior remains supported. Callers must serialize repository mutations; the README specifies this contract and recovery behavior.
Prepares executable version 0.3.0 and pinned installation documentation for the tagged release. The existing v0.2.0 tag remains unchanged.
Validation: 40 Python integration tests and 4 human-workflow checks pass, along with Bash syntax and git diff checks. Coverage includes externally locked concurrent creation, duplicate identities across env filenames, moves, missing/locked worktrees, literal multiline parsing, path and file collisions, private permissions, and checkout/environment failures.
Closes #10.