Skip to content

feat: bggrep tool + bgtail delta tailing - #4

Merged
lloydsk merged 4 commits into
mainfrom
lloydsk/bggrep-delta
Sep 10, 2026
Merged

feat: bggrep tool + bgtail delta tailing#4
lloydsk merged 4 commits into
mainfrom
lloydsk/bggrep-delta

Conversation

@lloydsk

@lloydsk lloydsk commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #1 (project-local jobs dir) — review/merge that first; this branch contains its commits plus the new work below.

What

Two context-efficiency features for reading job logs:

bggrep — capped in-extension pattern search

  • Regex search over a job's log: line-numbered matches (grep -n style), optional context lines with …[N lines skipped]… gap markers, capped at 50 matches + the ~8KB condenser budget.
  • Runs inside the extension with native fs access, so it works on any jobs dir — including global logs that project-sandboxed tools (ctx_execute_file) cannot reach. That gap repeatedly forced agents into uncapped raw greps; bggrep closes it.
  • With no pattern, a generic failure-signature default is used — deliberately a convenience only (overridden by passing your own pattern): a general-audience tool across languages/task types misses more than it catches, so heuristics are never load-bearing.
  • Record-first log resolution (correct across mid-session config changes), same as bgtail.

bgtail delta tailing

  • First read for a job: full last-N tail (unchanged semantics).
  • Repeat reads: only lines appended since your last read, with a +N new lines header — polling a running job never re-pays context for lines already seen; a no-change poll returns a single tiny line.
  • Bookmark = high-water mark (total content lines + byte size at read time); deliberately-skipped prefix lines are never replayed as "new"; a shrunken/replaced log (detected by line count or bytes) resets to a full tail with a note; raw: true keeps the verbatim last-N window but still advances the bookmark; bookmarks are in-memory only — a session restart starts fresh.
  • The /bgtail slash command inherits everything via the shared core.

Testing

tsc clean; 51/51 node:test — 8 new: bggrep (line numbers + explicit/default/no-match, context windows + gap markers, invalid-pattern error, 50-match cap, record preference) and delta tailing (full→new→none sequence, raw-advances-bookmark, byte-level shrink reset). The delta rewrite also fixed a regression caught by existing tests: the exit marker is now filtered before the window is sliced, so "last N lines" keeps meaning the last N content lines.

Docs

README tools table + two-tier read model; SKILL.md tools table + reading guidance.

bggrep: capped in-extension regex search over job logs — line-numbered
matches, optional context with gap markers, 50-match + ~8KB condenser caps;
works on any jobs dir (native fs), closing the gap where project-sandboxed
tools cannot reach global logs; generic failure-pattern default is a
convenience only, always overridable.

bgtail delta tailing: first read = full last-N tail (unchanged); repeat
reads return only lines appended since the last read (high-water bookmark of
content lines + bytes); shrunken/replaced logs reset to a full tail; raw:true
keeps the verbatim window but advances the bookmark. Exit marker now filtered
before slicing so last-N means last N content lines.
… sandbox gap

Rationale captured in the three places that steer behavior: the run-bg skill
(rules + why-not section), the README read-model section, and the bggrep
tool's prompt guidelines. Never bash-grep a bgrun log; plain grep only for
one-off searches known to be tiny.
…ty-log

bgtail delta: store the first content line in the bookmark — append-only
logs never mutate line 0, so a changed first line means the log was replaced
or rotated; catches same-line-count/same-size replacements the shrink checks
cannot see. Also normalize CRLF (stray \r broke nothing but leaked into
output), clamp lines to >= 1 (slice(-0) pitfall), and drop an unreachable
body branch.

bggrep: empty log now reports 'in 0 lines' (was 'in 1 lines' via
''.split('\n') === ['']); CRLF normalized so $-anchored patterns match;
context clamped to >= 0 (negative context dropped the match lines
themselves); schema minimums added for lines/context.

appendExcludePattern: skip ../-prefixed patterns (unreachable via the
walk-up today, defense-in-depth for future callers/symlinks).

Docs: ~2KB/line cap now documented alongside ~8KB in README + SKILL.md.
Tests: +6 (replacement reset, CRLF, empty+notFound, context+cap, clamps) — 57 total.
@lloydsk

lloydsk commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator Author

Supersedes #2 (closed unintentionally when #1's base branch was deleted — GitHub's stacked-PR lock prevented retargeting). Same branch, rebased cleanly onto main; the review findings and their fixes (f7808cf→237e706) are documented in #2.

@lloydsk
lloydsk merged commit cb9a1f5 into main Sep 10, 2026
1 check passed
@lloydsk
lloydsk deleted the lloydsk/bggrep-delta branch September 10, 2026 16:41
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.

1 participant