Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
chore(clawpatch): add threat-model specs for review surfaces (#2859)
Maximilian Roos94dece43c71c
diff --git a/.config/clawpatch/features/feat_custom_approvals_storage.json b/.config/clawpatch/features/feat_custom_approvals_storage.jsonnew file mode 100644index 000000000..fcb9ac5d0--- /dev/null+++ b/.config/clawpatch/features/feat_custom_approvals_storage.json@@ -0,0 +1,69 @@+{+ "schemaVersion": 1,+ "featureId": "feat_custom_approvals_storage",+ "title": "Approvals storage: the approvals.toml trust store",+ "summary": "`approvals.toml` records which project commands the user has approved; the approval gate (feat_custom_approval_gate) consults it to decide what may run without a prompt. This feature covers the integrity of the store itself: path resolution, loading, parsing, saving, and the legacy copy from config.toml. A parse that fails open, a save that partially writes, or a path-resolution bug that reads the wrong file would let an unapproved command run or silently drop the user's approvals. `Approvals::load_from_config_file` and `copy_approved_commands_to_approvals_file` must fail closed: an error aborts, never degrades to 'nothing approved' or 'everything approved'.",+ "kind": "library",+ "source": "manual",+ "confidence": "high",+ "entrypoints": [+ {+ "path": "src/config/approvals.rs",+ "symbol": "Approvals",+ "route": null,+ "command": null+ }+ ],+ "ownedFiles": [+ {+ "path": "src/config/approvals.rs",+ "reason": "Approvals struct: load/save/path resolution for approvals.toml"+ }+ ],+ "contextFiles": [+ {+ "path": "src/commands/command_approval.rs",+ "reason": "the approval gate that consumes the store"+ },+ {+ "path": "src/config/deprecation.rs",+ "reason": "copy_approved_commands_to_approvals_file: legacy migration into the store, must fail closed"+ },+ {+ "path": "src/config/mod.rs",+ "reason": "config path resolution"+ },+ {+ "path": "CLAUDE.md",+ "reason": "Project Commands Run Only After Approval"+ }+ ],+ "tests": [+ {+ "path": "tests/integration_tests/user_hooks.rs",+ "command": "cargo test --test integration user_hooks"+ },+ {+ "path": "tests/integration_tests/custom.rs",+ "command": "cargo test --test integration custom"+ }+ ],+ "tags": [+ "rust",+ "security",+ "approval-gate",+ "serialization"+ ],+ "trustBoundaries": [+ "filesystem",+ "permissions",+ "serialization"+ ],+ "status": "pending",+ "lock": null,+ "findingIds": [],+ "patchAttemptIds": [],+ "analysisHistory": [],+ "createdAt": "2026-05-19T00:00:00.000Z",+ "updatedAt": "2026-05-19T00:00:00.000Z"+}diff --git a/.config/clawpatch/features/feat_custom_hook_logs.json b/.config/clawpatch/features/feat_custom_hook_logs.jsonnew file mode 100644index 000000000..dc41e3ab9--- /dev/null+++ b/.config/clawpatch/features/feat_custom_hook_logs.json@@ -0,0 +1,68 @@+{+ "schemaVersion": 1,+ "featureId": "feat_custom_hook_logs",+ "title": "Hook output logs: filename sanitization and log-path layout",+ "summary": "Hook stdout/stderr is persisted under `.git/wt/logs/` with per-branch and repo-wide paths. Branch names and hook names flow into filesystem paths through `sanitize_for_filename`; a sanitization gap (path separators, `..`, absolute prefixes, reserved Windows device names) means a crafted branch name could write or truncate files outside the logs tree. The top-level file-vs-directory split must stay consistent or `wt config state` mis-walks it. See CLAUDE.md > Hook Output Logs.",+ "kind": "library",+ "source": "manual",+ "confidence": "high",+ "entrypoints": [+ {+ "path": "src/commands/process.rs",+ "symbol": "HookLog",+ "route": null,+ "command": null+ }+ ],+ "ownedFiles": [+ {+ "path": "src/commands/process.rs",+ "reason": "HookLog spec: log path construction and sanitize_for_filename call sites"+ },+ {+ "path": "src/path.rs",+ "reason": "sanitize_for_filename definition: the sanitization boundary"+ },+ {+ "path": "src/commands/config/state.rs",+ "reason": "log-layout invariant: the file-vs-directory split walked by `wt config state`"+ }+ ],+ "contextFiles": [+ {+ "path": "CLAUDE.md",+ "reason": "Hook Output Logs section: log layout and sanitize_for_filename rule"+ },+ {+ "path": "src/commands/hook_commands.rs",+ "reason": "hook command resolution that produces the names written to log paths"+ }+ ],+ "tests": [+ {+ "path": "tests/integration_tests/user_hooks.rs",+ "command": "cargo test --test integration user_hooks"+ },+ {+ "path": "tests/integration_tests/hook_show.rs",+ "command": "cargo test --test integration hook_show"+ }+ ],+ "tags": [+ "rust",+ "filesystem",+ "path-traversal",+ "logging"+ ],+ "trustBoundaries": [+ "filesystem",+ "user-input"+ ],+ "status": "pending",+ "lock": null,+ "findingIds": [],+ "patchAttemptIds": [],+ "analysisHistory": [],+ "createdAt": "2026-05-19T00:00:00.000Z",+ "updatedAt": "2026-05-19T00:00:00.000Z"+}diff --git a/.config/clawpatch/features/feat_custom_network_boundary.json b/.config/clawpatch/features/feat_custom_network_boundary.jsonnew file mode 100644index 000000000..a5ec01f25--- /dev/null+++ b/.config/clawpatch/features/feat_custom_network_boundary.json@@ -0,0 +1,68 @@+{+ "schemaVersion": 1,+ "featureId": "feat_custom_network_boundary",+ "title": "Local-first network-access boundary",+ "summary": "Worktrunk is local-first: the network is touched only when the user asked for it. The audit keys on the calling command, not a fixed blocklist — an egress (`git fetch`, `git ls-remote`, `gh`, `glab`, `az`, HTTP) is a violation when it sits in a fast command or a synchronous hot path (a shell prompt) that cannot absorb the latency, or in a background TTL-cache refresh. A foreground command the user runs and waits on may reach the wire for the activity it was asked to perform. Sanctioned activities: CI status (`wt list --full`, `wt list statusline`), branch-summary and commit-message generation (`commit.generation` commands), PR/MR resolution (`wt switch pr:`/`mr:`), and the `wt config show --full` version check; plus the one detection-helper exception — the first `Repository::default_branch()` per repo may fall through to `git ls-remote`, caching into `worktrunk.default-branch`. Silent lookup fallthroughs (alias dispatch, hook context build, recovery) must stay local. See CLAUDE.md > Network Access.",+ "kind": "library",+ "source": "manual",+ "confidence": "high",+ "entrypoints": [+ {+ "path": "src/git/repository/config.rs",+ "symbol": "default_branch",+ "route": null,+ "command": null+ }+ ],+ "ownedFiles": [+ {+ "path": "src/git/repository/config.rs",+ "reason": "default_branch(): the one sanctioned ls-remote fallback and its worktrunk.default-branch cache"+ },+ {+ "path": "src/commands/statusline.rs",+ "reason": "`wt list statusline`: runs on every prompt but is not a fast command — Claude Code consumes its output asynchronously — so its CI-status egress is sanctioned; audit only that it adds no other unrequested network work"+ }+ ],+ "contextFiles": [+ {+ "path": "src/git/remote_ref/mod.rs",+ "reason": "PR/MR fetch: the legitimate user-invoked egress, must not run on background paths"+ },+ {+ "path": "src/shell_exec.rs",+ "reason": "Cmd: where external commands (git, gh, glab) spawn"+ },+ {+ "path": "src/commands/alias.rs",+ "reason": "alias dispatch must resolve locally, no fallthrough to the wire"+ },+ {+ "path": "CLAUDE.md",+ "reason": "Network Access policy and the default_branch detection-helper exception"+ }+ ],+ "tests": [+ {+ "path": "tests/integration_tests/switch.rs",+ "command": "cargo test --test integration switch"+ }+ ],+ "tags": [+ "rust",+ "network-policy",+ "performance",+ "audit"+ ],+ "trustBoundaries": [+ "network",+ "process-exec"+ ],+ "status": "pending",+ "lock": null,+ "findingIds": [],+ "patchAttemptIds": [],+ "analysisHistory": [],+ "createdAt": "2026-05-19T00:00:00.000Z",+ "updatedAt": "2026-05-20T00:00:00.000Z"+}diff --git a/.config/clawpatch/features/feat_custom_performance.json b/.config/clawpatch/features/feat_custom_performance.jsonnew file mode 100644index 000000000..fce69b8ef--- /dev/null+++ b/.config/clawpatch/features/feat_custom_performance.json@@ -0,0 +1,77 @@+{+ "schemaVersion": 1,+ "featureId": "feat_custom_performance",+ "title": "Startup latency and parallel status collection",+ "summary": "`wt` runs on the interactive path: `wt list` and `wt statusline` execute constantly, statusline on every shell prompt, so time-to-first-output (TTFP) and the parallelism of worktree-status collection are first-class concerns. The collection layer fans per-worktree git queries out across worker threads; the parallelism must be correct (independent work not serialized, no over-spawn beyond the logical CPU count, cached Repository values reused rather than re-queried) and must stream results rather than buffer. Findings here are `performance` and `concurrency` category, code-level anti-patterns (needless work, blocking I/O on the hot path, missing parallelism); the benchmarks measure the actual latency. Pair with `cargo bench --bench time_to_first_output` / `--bench list` and `cargo run -p wt-perf -- timeline` for evidence.",+ "kind": "library",+ "source": "manual",+ "confidence": "high",+ "entrypoints": [+ {+ "path": "src/commands/list/collect/mod.rs",+ "symbol": "collect",+ "route": null,+ "command": "wt list"+ }+ ],+ "ownedFiles": [+ {+ "path": "src/commands/list/collect/mod.rs",+ "reason": "collect: status-collection orchestration and result streaming"+ },+ {+ "path": "src/commands/list/collect/execution.rs",+ "reason": "parallel work-item dispatch across worker threads"+ },+ {+ "path": "src/commands/list/collect/tasks.rs",+ "reason": "per-worktree git query tasks: the units fanned out in parallel"+ }+ ],+ "contextFiles": [+ {+ "path": "src/main.rs",+ "reason": "process startup path before first output (TTFP)"+ },+ {+ "path": "src/git/repository/mod.rs",+ "reason": "RepoCache: cached values that must be reused, not re-queried per task"+ },+ {+ "path": "src/trace/emit.rs",+ "reason": "[wt-trace] timing instrumentation"+ },+ {+ "path": "CLAUDE.md",+ "reason": "Benchmarks & Traces; Repository Caching"+ },+ {+ "path": "benches/CLAUDE.md",+ "reason": "benchmark filter map and expected numbers"+ }+ ],+ "tests": [+ {+ "path": "benches/time_to_first_output.rs",+ "command": "cargo bench --bench time_to_first_output"+ },+ {+ "path": "tests/integration_tests/list.rs",+ "command": "cargo test --test integration list"+ }+ ],+ "tags": [+ "rust",+ "performance",+ "concurrency",+ "startup"+ ],+ "trustBoundaries": [],+ "status": "pending",+ "lock": null,+ "findingIds": [],+ "patchAttemptIds": [],+ "analysisHistory": [],+ "createdAt": "2026-05-19T00:00:00.000Z",+ "updatedAt": "2026-05-19T00:00:00.000Z"+}diff --git a/.config/clawpatch/features/feat_custom_prune.json b/.config/clawpatch/features/feat_custom_prune.jsonnew file mode 100644index 000000000..509d689a4--- /dev/null+++ b/.config/clawpatch/features/feat_custom_prune.json@@ -0,0 +1,70 @@+{+ "schemaVersion": 1,+ "featureId": "feat_custom_prune",+ "title": "wt step prune: worktree pruning and concurrent .git/config safety",+ "summary": "`wt step prune` scans worktrees and orphan branches and removes stale ones. As a destructive operation it must require explicit consent for force-removal, must not discard uncommitted or untracked work, and runs pre/post-remove hooks only after the approval gate clears them. Concurrent `git worktree` mutations race on `.git/config` (the Windows prune race, issue #2801) so pruning must tolerate or serialize that. Complements feat_custom_remove, which covers `wt remove` and the picker. See CLAUDE.md > Data Safety.",+ "kind": "library",+ "source": "manual",+ "confidence": "high",+ "entrypoints": [+ {+ "path": "src/commands/step/prune.rs",+ "symbol": "step_prune",+ "route": null,+ "command": "wt step prune"+ }+ ],+ "ownedFiles": [+ {+ "path": "src/commands/step/prune.rs",+ "reason": "prune entrypoint: candidate selection, age checks, removal, hook approval"+ }+ ],+ "contextFiles": [+ {+ "path": "src/git/repository/worktrees.rs",+ "reason": "worktree listing and `git worktree remove`"+ },+ {+ "path": "src/remove_dir.rs",+ "reason": "directory removal invoked by prune"+ },+ {+ "path": "src/commands/command_approval.rs",+ "reason": "approval gate for pre/post-remove hooks"+ },+ {+ "path": "src/commands/hook_plan.rs",+ "reason": "ApprovedHookPlan: prune is a gate-then-mutate operation"+ },+ {+ "path": "CLAUDE.md",+ "reason": "Data Safety invariants"+ }+ ],+ "tests": [+ {+ "path": "tests/integration_tests/step_prune.rs",+ "command": "cargo test --test integration step_prune"+ }+ ],+ "tags": [+ "rust",+ "data-safety",+ "destructive",+ "concurrency",+ "approval-gate"+ ],+ "trustBoundaries": [+ "filesystem",+ "concurrency",+ "process-exec"+ ],+ "status": "pending",+ "lock": null,+ "findingIds": [],+ "patchAttemptIds": [],+ "analysisHistory": [],+ "createdAt": "2026-05-19T00:00:00.000Z",+ "updatedAt": "2026-05-19T00:00:00.000Z"+}diff --git a/.config/clawpatch/features/feat_custom_shell_integration.json b/.config/clawpatch/features/feat_custom_shell_integration.jsonnew file mode 100644index 000000000..0760e922c--- /dev/null+++ b/.config/clawpatch/features/feat_custom_shell_integration.json@@ -0,0 +1,69 @@+{+ "schemaVersion": 1,+ "featureId": "feat_custom_shell_integration",+ "title": "Shell integration: generated wrapper code and rc-file edits",+ "summary": "`wt config shell init` emits a shell function that the user `eval`s into an interactive shell, and `wt config shell install` edits rc files in place. The emitted wrapper embeds `argv[0]`-derived data (`binary_name`) and the configured command name; anything unescaped that reaches the eval'd output is code injection into the user's shell. rc-file edits must be idempotent and must not corrupt or duplicate an existing managed block. Trust boundary: process-exec (code the shell will run) and filesystem (user rc files).",+ "kind": "library",+ "source": "manual",+ "confidence": "high",+ "entrypoints": [+ {+ "path": "src/commands/configure_shell.rs",+ "symbol": "handle_configure_shell",+ "route": null,+ "command": "wt config shell"+ }+ ],+ "ownedFiles": [+ {+ "path": "src/commands/configure_shell.rs",+ "reason": "rc-file scan/edit and managed-block detection"+ },+ {+ "path": "src/output/shell_integration.rs",+ "reason": "shell-integration prompts and install/uninstall result rendering"+ },+ {+ "path": "src/invocation.rs",+ "reason": "binary_name/invocation_path: argv[0]-derived values embedded in the emitted wrapper"+ }+ ],+ "contextFiles": [+ {+ "path": "src/cli/config.rs",+ "reason": "`wt config shell` subcommand wiring"+ },+ {+ "path": "src/commands/init.rs",+ "reason": "init-time shell-integration setup"+ }+ ],+ "tests": [+ {+ "path": "tests/integration_tests/configure_shell.rs",+ "command": "cargo test --test integration configure_shell"+ },+ {+ "path": "tests/integration_tests/shell_wrapper.rs",+ "command": "cargo test --test integration shell_wrapper"+ }+ ],+ "tags": [+ "rust",+ "security",+ "shell-integration",+ "code-injection"+ ],+ "trustBoundaries": [+ "process-exec",+ "filesystem",+ "user-input"+ ],+ "status": "pending",+ "lock": null,+ "findingIds": [],+ "patchAttemptIds": [],+ "analysisHistory": [],+ "createdAt": "2026-05-19T00:00:00.000Z",+ "updatedAt": "2026-05-19T00:00:00.000Z"+}diff --git a/.config/clawpatch/features/feat_custom_signal_handling.json b/.config/clawpatch/features/feat_custom_signal_handling.jsonnew file mode 100644index 000000000..6ecb47806--- /dev/null+++ b/.config/clawpatch/features/feat_custom_signal_handling.json@@ -0,0 +1,68 @@+{+ "schemaVersion": 1,+ "featureId": "feat_custom_signal_handling",+ "title": "Signal handling: Ctrl-C aborts every child-process loop",+ "summary": "wt installs a signal_hook SIGINT/SIGTERM handler that forwards signals to child process groups, so wt itself does not die from the user's Ctrl-C, only the current child does. Every foreground loop that runs multiple child processes (`wt step for-each`, hook pipelines, alias steps, concurrent groups) MUST abort on a signal-derived child exit instead of charging into the next iteration: otherwise one Ctrl-C against `wt merge` runs the remaining hook steps, with FailureStrategy::Warn silently swallowing each interrupt. Detect via `err.interrupt_exit_code()` (the worktrunk::git::ErrorExt trait); the check happens before any FailureStrategy branch. The structured channel is WorktrunkError::ChildProcessExited { signal }, never sniff code >= 128. See CLAUDE.md > Signal Handling.",+ "kind": "library",+ "source": "manual",+ "confidence": "high",+ "entrypoints": [+ {+ "path": "src/commands/command_executor.rs",+ "symbol": "handle_command_error",+ "route": null,+ "command": null+ }+ ],+ "ownedFiles": [+ {+ "path": "src/commands/command_executor.rs",+ "reason": "handle_command_error: enforces signal-abort for hook and alias pipelines, foreground and concurrent groups"+ },+ {+ "path": "src/commands/for_each.rs",+ "reason": "wt step for-each: per-worktree loop must break on a signal-derived child exit"+ },+ {+ "path": "src/git/error.rs",+ "reason": "ErrorExt::interrupt_exit_code and the WorktrunkError::ChildProcessExited signal channel"+ }+ ],+ "contextFiles": [+ {+ "path": "src/shell_exec.rs",+ "reason": "Cmd: spawns children into the process groups the signal handler forwards to"+ },+ {+ "path": "src/commands/command_approval.rs",+ "reason": "FailureStrategy::Warn must not swallow signal-derived errors"+ },+ {+ "path": "CLAUDE.md",+ "reason": "Signal Handling policy: every child-process loop aborts on a signal"+ }+ ],+ "tests": [+ {+ "path": "tests/integration_tests/user_hooks.rs",+ "command": "cargo test --test integration user_hooks"+ }+ ],+ "tags": [+ "rust",+ "signal-handling",+ "concurrency",+ "interrupt"+ ],+ "trustBoundaries": [+ "process-exec",+ "concurrency"+ ],+ "status": "pending",+ "lock": null,+ "findingIds": [],+ "patchAttemptIds": [],+ "analysisHistory": [],+ "createdAt": "2026-05-19T00:00:00.000Z",+ "updatedAt": "2026-05-19T00:00:00.000Z"+}diff --git a/.config/clawpatch/features/feat_custom_switch_resolve.json b/.config/clawpatch/features/feat_custom_switch_resolve.jsonindex 1b9a134ad..469282f44 100644--- a/.config/clawpatch/features/feat_custom_switch_resolve.json+++ b/.config/clawpatch/features/feat_custom_switch_resolve.json@@ -31,6 +31,22 @@"path": "src/git/remote_ref/mod.rs","reason": "remote ref parsing (PR/MR URLs)"},+ {+ "path": "src/git/remote_ref/github.rs",+ "reason": "GitHub PR fetch and owner/repo URL derivation from the forge remote"+ },+ {+ "path": "src/git/remote_ref/gitlab.rs",+ "reason": "GitLab MR fetch and project URL parsing"+ },+ {+ "path": "src/git/remote_ref/gitea.rs",+ "reason": "Gitea PR fetch and URL parsing"+ },+ {+ "path": "src/git/remote_ref/azure.rs",+ "reason": "Azure DevOps PR fetch and source-branch validation"+ },{"path": "src/git/repository/branch.rs","reason": "branch name handling"@@ -101,5 +117,5 @@}],"createdAt": "2026-05-16T21:00:00.000Z",- "updatedAt": "2026-05-17T05:12:27.656Z"+ "updatedAt": "2026-05-19T00:00:00.000Z"}diff --git a/.config/clawpatch/features/feat_custom_template_expansion.json b/.config/clawpatch/features/feat_custom_template_expansion.jsonnew file mode 100644index 000000000..6bba628a6--- /dev/null+++ b/.config/clawpatch/features/feat_custom_template_expansion.json@@ -0,0 +1,72 @@+{+ "schemaVersion": 1,+ "featureId": "feat_custom_template_expansion",+ "title": "MiniJinja template expansion of project-supplied commands",+ "summary": "Hook commands, alias steps, and `-x/--execute` bodies are MiniJinja templates rendered at runtime with a context of worktree/repo variables. The templates come from project config (a repo the user may have just cloned) and from CLI args. Risks: a rendering or escaping bug that mis-expands a variable into a command, undeclared-variable handling that silently produces an empty or wrong command, and the ShellArgs object's quoting. Expansion happens before the approval gate sees the final string, so a mismatch between what is approved and what is rendered would bypass approval. Detection must use minijinja::undeclared_variables, never substring or regex on `{{ }}`.",+ "kind": "library",+ "source": "manual",+ "confidence": "high",+ "entrypoints": [+ {+ "path": "src/commands/hook_commands.rs",+ "symbol": "expand_command_template",+ "route": null,+ "command": null+ }+ ],+ "ownedFiles": [+ {+ "path": "src/commands/hook_commands.rs",+ "reason": "expand_command_template: runtime render of hook command templates"+ },+ {+ "path": "src/config/expansion.rs",+ "reason": "variable catalog, ShellArgs minijinja object, shell-arg quoting"+ },+ {+ "path": "src/commands/alias.rs",+ "reason": "alias step template rendering"+ }+ ],+ "contextFiles": [+ {+ "path": "src/config/project.rs",+ "reason": "project config that supplies the templates"+ },+ {+ "path": "src/commands/command_approval.rs",+ "reason": "approval gate: must see the same string the renderer produces"+ },+ {+ "path": "src/cli/mod.rs",+ "reason": "-x/--execute bodies expanded as templates"+ }+ ],+ "tests": [+ {+ "path": "tests/integration_tests/step_alias.rs",+ "command": "cargo test --test integration step_alias"+ },+ {+ "path": "tests/integration_tests/user_hooks.rs",+ "command": "cargo test --test integration user_hooks"+ }+ ],+ "tags": [+ "rust",+ "user-input",+ "template-injection",+ "minijinja"+ ],+ "trustBoundaries": [+ "user-input",+ "process-exec"+ ],+ "status": "pending",+ "lock": null,+ "findingIds": [],+ "patchAttemptIds": [],+ "analysisHistory": [],+ "createdAt": "2026-05-19T00:00:00.000Z",+ "updatedAt": "2026-05-19T00:00:00.000Z"+}