Skip to content

feat: add always-on command log for hooks and LLM commands#1088

Merged
max-sixty merged 6 commits intomainfrom
command-log
Feb 18, 2026
Merged

feat: add always-on command log for hooks and LLM commands#1088
max-sixty merged 6 commits intomainfrom
command-log

Conversation

@max-sixty
Copy link
Copy Markdown
Owner

@max-sixty max-sixty commented Feb 17, 2026

Summary

  • Adds always-on JSONL logging of external command executions to .git/wt-logs/commands.jsonl
  • Logs foreground hooks (with exit code + duration), background hooks (with null exit/duration), and LLM commit generation commands
  • New .external(label) builder on Cmd for automatic logging in run()/stream()
  • Lazy file/directory creation — no files created unless commands are actually logged
  • Growth control: rotates to commands.jsonl.old at 1MB (~2MB worst case)
  • Splits wt config state log display into COMMAND LOG and HOOK OUTPUT sections
  • Documents the command log in the FAQ

Example log entries (parseable with jq):

{"ts":"2026-02-17T10:23:45Z","wt":"wt merge","label":"pre-merge user:lint","cmd":"pre-commit run --all-files","exit":0,"dur_ms":12345}
{"ts":"2026-02-17T10:24:00Z","wt":"wt switch","label":"post-start user:server","cmd":"npm run dev","exit":null,"dur_ms":null}

Test plan

  • All 1052 tests pass
  • All lints pass (pre-commit run --all-files)
  • Verified lazy creation doesn't interfere with existing wt config state tests
  • Verified multi-byte UTF-8 truncation doesn't panic

This was written by Claude Code on behalf of @max-sixty

max-sixty and others added 2 commits February 17, 2026 14:25
Log hook executions and LLM commit generation to
.git/wt-logs/commands.jsonl as JSONL for post-hoc debugging.

- New command_log module with lazy file/directory creation
- .external() builder on Cmd for automatic logging in run()/stream()
- Foreground hooks logged via execute_command_in_worktree
- Background hooks logged directly with null exit/duration
- Growth control: rotates at 1MB to commands.jsonl.old

Co-Authored-By: Claude <noreply@anthropic.com>
- Replace writeln! with single write_all to prevent interleaving
  from concurrent wt processes
- Use char_indices().nth() for single-scan truncation instead of
  double-scanning with chars().count() + chars().take()

Co-Authored-By: Claude <noreply@anthropic.com>
max-sixty and others added 3 commits February 17, 2026 18:36
Commands are user-configured and can be long (especially LLM commands
with inline flags). The log rotates at 1MB so there's no cost to
being liberal with the truncation limit.

Co-Authored-By: Claude <noreply@anthropic.com>
The inner Option<CommandLog> in the Mutex was redundant since OnceLock
already handles the uninitialized case. This simplifies the lock
pattern and removes an unreachable branch that hurt coverage.

Co-Authored-By: Claude <noreply@anthropic.com>
Separate the LOG FILES display in `wt config state` into two sections:
COMMAND LOG (commands.jsonl) and HOOK OUTPUT (*.log). Update JSON output
to use `command_log` and `hook_output` keys. Document the command log in
the FAQ.

Co-Authored-By: Claude <noreply@anthropic.com>
Extract write logic into CommandLog::write() method for direct testing.
Add tests for lazy file creation, append behavior, and rotation at the
size limit. Fixes codecov/patch coverage gap.

Co-Authored-By: Claude <noreply@anthropic.com>
@max-sixty max-sixty merged commit dc83699 into main Feb 18, 2026
22 checks passed
@max-sixty max-sixty deleted the command-log branch February 18, 2026 18:24
max-sixty pushed a commit that referenced this pull request Feb 19, 2026
- Fix approved-hook-commands migration note to reference `wt config update`
  instead of the old `wt config show` command
- Add command log (commands.jsonl) documentation to `wt config state logs`
  help text — the feature was added in #1088 but help text wasn't updated
- Add documentation accuracy checklist to PR review skill so the CI
  reviewer catches stale docs in future PRs

https://claude.ai/code/session_015Dv1n6s3s79EJCsPoxByC6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants