Skip to content

Record data set opens and executed queries in a local JSONL log#59

Merged
Tannex merged 5 commits into
mainfrom
usage-events
Jul 20, 2026
Merged

Record data set opens and executed queries in a local JSONL log#59
Tannex merged 5 commits into
mainfrom
usage-events

Conversation

@Tannex

@Tannex Tannex commented Jul 19, 2026

Copy link
Copy Markdown
Owner

Closes #58. Stacked on #55 (shares runQuery in query.go); retarget as the chain merges.

New internal/events package following the favorites-store conventions (injectable UserConfigDir/Now, Diagnostic sink, tolerant load):

  • Append-only JSONL at cq/events.jsonl: one {"kind","time","name"/"query","outcome"} object per line. An event is one O_APPEND write — durable immediately (no debounce window) and safe under interleaved appends from several instances.
  • Bounded: compaction to the newest 1000 events triggers past 2000 lines, via temp file + rename so a crash cannot truncate the log. Corrupt lines are skipped on read.
  • Silent degradation: every failure goes to the diagnostic and nothing reaches the UI.
  • Privacy: query events store the expression text as typed, with an ok/error compile outcome — no record data, copybook contents, or field values (test-asserted).

Hooks: openSelection records successful PS/PO opens only (migrated warnings and unsupported DSORGs record nothing); runQuery records the typed expression with error on normalize/compile failure, ok on a started run. Wired through a nil-able Dependencies.Events interface; cmd/compaz constructs the default store.

Verified with package tests (append format, ordering + corrupt-line tolerance, compaction window, silent degradation), compaz hook tests, and a demo-mode terminal run against an isolated XDG_CONFIG_HOME — the resulting file:

{"kind":"open","time":"…","name":"DEMO.CUSTOMER.MASTER"}
{"kind":"query","time":"…","query":".CUST-ID","outcome":"error"}

(that error is real — bare .CUST-ID is a jq syntax error; the quoted form comes from ctrl+space.)

The Events() reader returns the retained window oldest-first for the future suggestion engine and query-history consumers.

🤖 Generated with Claude Code

https://claude.ai/code/session_01CS2LZMn2YJdebAiry2jzdP

Groundwork for the suggestion engine and query history: a new
internal/events store appends one JSON line per event — data set opens
and executed jq expressions with their compile outcome — to
cq/events.jsonl. Appends are single O_APPEND writes, durable
immediately and safe when several instances interleave; the log
compacts to the newest 1000 events once it passes 2000 lines via a
temp-file rename. Corrupt lines are skipped on read and every failure
degrades to the diagnostic, so tracking can never disturb the TUI.
Query events store the expression text as typed and nothing else.

Closes #58

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CS2LZMn2YJdebAiry2jzdP
Tannex and others added 3 commits July 20, 2026 05:55
A scanner error mid-file left read reporting ok with a truncated event
slice; compaction would then rewrite events.jsonl from that slice and
permanently drop the unread tail. A scan error now reports not-ok, so
compact leaves the file untouched.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CS2LZMn2YJdebAiry2jzdP
Member opens inside a PDS were invisible to the usage log even though
they are the most specific thing the user reaches for; they now record
as DSN(MEMBER). Submitting an invalid expression while a search was
running left the old search mutating results behind the error banner;
both compile-error paths now stop it first. The events package
documents its multi-instance contract explicitly (append-safe;
compaction can drop an event landing inside its read-then-rename
window; per-instance counters can defer compaction until the next
fresh start), countLines streams instead of loading the whole file,
and recordOpen's comment states the navigation-not-outcome semantics.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CS2LZMn2YJdebAiry2jzdP
Base automatically changed from query-console-features to main July 20, 2026 06:18
# Conflicts:
#	internal/compaz/query.go
@Tannex
Tannex merged commit 45fa9b0 into main Jul 20, 2026
4 checks passed
@Tannex
Tannex deleted the usage-events branch July 20, 2026 06:23
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.

Local usage tracking: data set opens and executed jq queries

1 participant