Commit Graph
5 Commits
Author SHA1 Message Date
haelyra 7b9f56fb94 fix: preserve runtime history and project discovery across hook races 2026-11-19 17:34:15 -05:00
haelyra 390b8bc067 Merge PR #4016 observer launch optimization while preserving per-event log rotation 2026-11-19 15:20:18 -05:00
Jeffrey Montoya ea7e77664a fix(clv2): keep the config timestamp check, normalize observer.enabled
Address the second round of review findings:

- Cache: trust an entry only while it is newer than the repository .git/config
  as well as while git reports the stored origin, so a core.worktree change
  that moves the root is not served stale.
- observe.sh: emit observer.enabled as a literal true or false so a value
  containing a newline cannot shift the fields that follow.
- Tests: remove GIT_DIR, GIT_WORK_TREE, GIT_INDEX_FILE, GIT_COMMON_DIR and
  GIT_PREFIX from the detection test environment; add a config-change test and
  an observer.enabled newline test. Refresh the registry digest.
2026-11-18 15:38:30 -05:00
Jeffrey Montoya 155b4d254f fix(clv2): validate the detection cache against the live origin
Address the review findings on the observe hook trim:

- Cache entries store the credential-stripped origin detection read, and a hit
  compares it with `git remote get-url origin`, so included, global and
  GIT_CONFIG_* origins and a config change during detection are all caught.
- Keep the payload cwd byte for byte (a directory name may hold a newline).
- Follow a symlinked python stub outside WindowsApps on Windows-like shells.
- Run housekeeping once a day from its own per-project marker, independent of
  the detection cache.
2026-11-18 04:25:30 -05:00
montjeffrey d2db7871fe perf(clv2): cut observe hook process launches
observe.sh runs before and after every tool call and launched about 50
external processes per run. Each costs a few milliseconds on Linux/macOS
but 80-280 ms under Git Bash on Windows, where one run took 5-7 s.

- Read cwd, agent_id and observer.enabled in one Python start, and parse,
  scrub and write the observation in one more (was six). The redaction
  patterns are unchanged.
- Cache project detection per (CLV2_NO_PROJECT, CLAUDE_PROJECT_DIR, PWD)
  for the rest of the day. An entry is rejected when .git/config is not
  older than it, when the project dir or root is gone, or when the id is
  not a shape detection can produce. Worktrees, submodules and non-git
  roots are never cached. CLV2_PROJECT_CACHE=0 disables it; bash < 4.2
  skips it.
- Run the stdin-independent guards before the first interpreter start.
- Run the find/du housekeeping only when detection was not cached.
- Replace dirname/readlink/subshell calls on the hot path with builtins.

Measured on Windows 11 / Git Bash, warm cache: 5.2-5.8 s -> 1.1-1.2 s
per run. Output compared against the previous script on 19 payloads
(records, redaction, registry, counters, exit codes): identical.

Behavior changes: projects.json last_seen refreshes at least daily
instead of every call; observations.jsonl may exceed the 10 MB cap by up
to a day of records before archiving; the App Installer stub check only
follows symlinks for paths under WindowsApps.
2026-11-17 14:20:54 -05:00