feat(usage): tool usage logging for auto-compact#224
Conversation
All subagents need bash to run git diff, flicknote get, ls, etc. The ttal tools config was missing it while claude-code config had it.
Adds a new ToolUsage ent schema and internal/usage package that logs ttal command invocations to SQLite (messages.db). Logging is fire-and- forget and skips silently when TTAL_AGENT_NAME is unset (human context). Commands instrumented: explore, task route, task execute, send, task add. Includes Summary() query helper grouped by subcommand+target for use in the upcoming auto-compact feature.
PR Review: feat(usage): add tool usage logging for auto-compact session summariesCritical IssuesNone. Important Issues1. [log.go:57-68] Driver double-wrap creates a resource leak on
drv, err := entsql.Open("sqlite", dbDSN)
if err != nil {
return nil, err
}
client := ent.NewClient(ent.Driver(drv))2. [log.go:65]
Fix: pass the bounded context into func open(ctx context.Context) (*ent.Client, error) { ... }
// then: client.Schema.Create(ctx)3. [log.go:65] This migrates all ent tables — including 4. [log.go:27-30] Silent Write failures are logged ( client, err := open()
if err != nil {
log.Printf("[usage] open error: %v", err)
return
}Suggestions
Strengths
VERDICT: NEEDS_WORKThe unbounded |
…pen error log - Replace entsql.OpenDB double-wrap with direct ent.NewClient(ent.Driver(drv)) to eliminate driver resource leak on Schema.Create failure - Remove Schema.Create from open() — daemon owns schema init; CLI logging is fire-and-forget and silently skips if tables don't exist yet - Add log.Printf on open() failure to match write-error diagnostic level - Document "command attempted" semantics in Log() godoc - Document non-fatal (nil, err) contract on Summary() for unavailable DB
Triage UpdateFixed
|
Re-review: fix(usage): remove double-wrap, drop Schema.Create from open(), add open error logFixed
RemainingNone. VERDICT: LGTM |
Summary
ToolUsageent schema (internal/ent/schema/tool_usage.go) with fields: agent, team, command, subcommand, target, created_atinternal/usagepackage with fire-and-forgetLog()andSummary()query helperexplore,task route,task execute,send,task addLogging skips silently when
TTAL_AGENT_NAMEis unset (human context). TheSummary()function groups by subcommand+target and returns counts, ready for the auto-compact session summary feature.Test plan
TTAL_AGENT_NAME=test-agentand runttal explore "test" --web→ verify row intool_usagestable viasqlite3 ~/.ttal/messages.db "SELECT * FROM tool_usages"TTAL_AGENT_NAME→ verify no row, no errorttal task add,ttal send,ttal task route,ttal task execute→ verify rows logged per command