Commit 8b6bb09
authored
feat(log): per-line cwd + source-aware emit label (#33)
* feat(log): per-line cwd + source-aware emit label
Two annoyances surfaced when dogfooding v0.2.0 across multiple
projects:
1. Lines in the global `~/.context-revive/hook.log` did not carry
any project context. With revive wired in 5+ repos, the same
`post-compact: forcing emit` message could be from any of them
— un-debuggable.
2. The forcing-emit log line said `post-compact:` even when the
trigger was `/clear`, because both paths shared one signal file
and `cadence_gate` had no idea which command wrote it.
Fixes:
- `log()` now prepends `[<cwd>]` after the timestamp, with a
tilde substitution for paths under $HOME. A subtle bash gotcha:
`${VAR/old/\~}` leaks the backslash; bash does NOT tilde-expand
inside parameter-substitution replacements, so the literal `~`
is correct (and was wrong on my first attempt — caught in
smoke before commit).
- `cmd_mark_compact` and `cmd_mark_clear` write `compact` / `clear`
to the signal file (was: a unix timestamp, never read). The
signal filename stays `revive-compact.signal` to keep the
on-disk path stable across upgrades.
- `cadence_gate` reads the payload, sanitizes via
`tr -cd '[:lower:]'`, and emits either `post-compact:` or
`post-clear:` accordingly. Unknown / malformed content falls
back to a neutral `post-context-loss:` label.
4 new tests cover: cwd field present in log, compact label,
clear label, malformed payload → neutral label without crashing.
* test(log): hold cwd-format regex in a variable for portability
The inline `[[ "$output" =~ \[[^]]+\]\ \[[^]]+\]\ post-compact ]]`
passed on macOS bats but failed on Ubuntu bats in CI — bash 3.2 vs
5.x differ on how literal `\[` inside the pattern is parsed. The
canonical workaround is to bind the pattern to a local variable
and reference it as `$re`. No content change to the assertion.
* fix(log): match $HOME on path boundary only (codex P2)
`${PWD/#$HOME/~}` did a string-prefix rewrite without a path
boundary check, so a checkout in `$HOME-something/...` (e.g.
HOME=/Users/alice and PWD=/Users/alice-work/project) would log
as `~-work/project` — wrong project name in a feature that
exists specifically to disambiguate projects.
Replace with a case statement that fires only on the exact
$HOME match or the `$HOME/` prefix; falls through to the
absolute path otherwise.
New test pins this: stages a sibling worktree at `$WORKDIR-other`
with HOME=$WORKDIR, runs mark-compact, and asserts the log line
does NOT contain the `~-other` splice artefact.
* test(log): clean up compact-source test setup (copilot)
Replaced the convoluted `printf > .claude/... 2>/dev/null
|| mkdir -p .claude && printf > .claude/...` with the same
two-line pattern the sibling clear-source and garbage-payload
tests already use. Bash redirect failures land on the original
stderr before `2>/dev/null` is applied, so the old form would
have leaked an error noise even when functionally correct.1 parent 0379a3e commit 8b6bb09
2 files changed
Lines changed: 82 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
57 | 68 | | |
58 | 69 | | |
59 | 70 | | |
| |||
411 | 422 | | |
412 | 423 | | |
413 | 424 | | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
414 | 431 | | |
415 | | - | |
| 432 | + | |
416 | 433 | | |
417 | 434 | | |
418 | 435 | | |
| |||
446 | 463 | | |
447 | 464 | | |
448 | 465 | | |
449 | | - | |
| 466 | + | |
450 | 467 | | |
451 | 468 | | |
452 | 469 | | |
453 | 470 | | |
454 | 471 | | |
455 | 472 | | |
456 | | - | |
| 473 | + | |
457 | 474 | | |
458 | 475 | | |
459 | 476 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1570 | 1570 | | |
1571 | 1571 | | |
1572 | 1572 | | |
| 1573 | + | |
| 1574 | + | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
| 1585 | + | |
| 1586 | + | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
| 1605 | + | |
| 1606 | + | |
| 1607 | + | |
| 1608 | + | |
| 1609 | + | |
| 1610 | + | |
| 1611 | + | |
| 1612 | + | |
| 1613 | + | |
| 1614 | + | |
| 1615 | + | |
| 1616 | + | |
| 1617 | + | |
| 1618 | + | |
| 1619 | + | |
| 1620 | + | |
| 1621 | + | |
| 1622 | + | |
| 1623 | + | |
| 1624 | + | |
| 1625 | + | |
| 1626 | + | |
| 1627 | + | |
| 1628 | + | |
| 1629 | + | |
| 1630 | + | |
| 1631 | + | |
| 1632 | + | |
| 1633 | + | |
0 commit comments