Skip to content

Capture-hook cleanup: duplicated timestamp format, redundant onboard greps, per-call subshell fork #16

Description

@jsirish

Three cleanup findings from the v0.5.0 (#5/#6/#7) review, deliberately deferred rather than fixed inline in that PR - each is a real duplication-drift risk but low severity, and given how many rounds of regex fixes that PR already went through, further mechanical edits under the same time pressure felt like the wrong call. Tracking here for a calmer follow-up pass.

  1. Duplicated timestamp format string (hooks/_lib.sh tl_err/tl_append_line, plus inline uses in session-flush.sh/session-precompact.sh): date '+%Y-%m-%d %H:%M:%S' is spelled out identically in 4 places. A future format change (e.g. adding a timezone offset) risks being applied to 3 of 4 sites. Fix: a shared tl_now() helper.

  2. session-onboard.sh's per-buffer loop runs 3 separate grep passes (total, promptonly, session-ended) over the same file. Correctness is fine; it's 3x the file reads/forks needed. Fix: a single awk pass computing all three, or one grep with multiple -e patterns feeding sort | uniq -c.

  3. _auth_scheme (command path) and _auth_scheme_prose (prompt path) duplicate the same bearer/basic/token regex literals, differing only in the length quantifier. A fix to the shared parts (e.g. tightening the base64 character class) applied to one during a future bugfix is easy to forget applying to the other. Fix: parameterize as _auth_scheme($min) called with different thresholds.

Also related to tl_jq_redact_defs being invoked via $(tl_jq_redact_defs) (a subshell + external cat per hook call, just to interpolate static jq text) - considered converting it to a plain shell variable to avoid the fork entirely, but the def text's comments contain many apostrophes that would need escaping for single-quote-safe variable assignment; that mechanical transform carries its own risk and deserves a dedicated, careful pass rather than a rushed edit.

Low priority - none of these are correctness bugs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions