Class: Insika::ToolTraceStore
- Inherits:
-
Object
- Object
- Insika::ToolTraceStore
- Defined in:
- lib/insika/tool_trace_store.rb
Overview
Per-session TOOL-CALL trace, for debugging in the Studio (FOLLOWUP §3.1). One
record per session in the raw backend (scope "tool_traces") — RUNTIME data, next
to sessions/tasks, NOT config (hence the raw store:, like SessionStore,
not the ConfigStore). A capped LIST of entries; ToolEnvelope writes one
per call (name + model args + result + status + ms). Serves
/studio/sessions/:id.
SECURITY lives HERE (the store owns it): the screen is for the operator, but the
args/response may carry PII/credentials. Every write goes through mask (values of
sensitive keys become a sentinel) + clip (truncates large fields). The ephemeral
data_tool_call event (name+status, 0 leakage) still goes to the live cards;
THIS is the durable, richer record, behind the Studio login.
Constant Summary collapse
- SCOPE =
"tool_traces"- MAX_PER_SESSION =
tail per session (avoids growing without bound)
200- MAX_FIELD_CHARS =
cap per args/result field
2_000- SECRET_KEY_RE =
/token|secret|authorization|password|passwd|api[-_]?key|bearer|cookie/i
Instance Method Summary collapse
-
#clear(session_id) ⇒ Object
Discards a session's trace (cleanup).
-
#for_session(session_id) ⇒ Object
-> [Hash] session entries in chronological order.
-
#initialize(store:) ⇒ ToolTraceStore
constructor
A new instance of ToolTraceStore.
-
#record(session_id:, entry:) ⇒ Object
Writes a (sanitized) entry into the session.
Constructor Details
#initialize(store:) ⇒ ToolTraceStore
Returns a new instance of ToolTraceStore.
24 25 26 |
# File 'lib/insika/tool_trace_store.rb', line 24 def initialize(store:) @store = store end |
Instance Method Details
#clear(session_id) ⇒ Object
Discards a session's trace (cleanup). -> bool (did it exist?).
44 |
# File 'lib/insika/tool_trace_store.rb', line 44 def clear(session_id) = @store.delete(SCOPE, session_id.to_s) |
#for_session(session_id) ⇒ Object
-> [Hash] session entries in chronological order. [] if none.
41 |
# File 'lib/insika/tool_trace_store.rb', line 41 def for_session(session_id) = @store.get(SCOPE, session_id.to_s) || [] |
#record(session_id:, entry:) ⇒ Object
Writes a (sanitized) entry into the session. Missing session_id -> no-op. ToolEnvelope already guards, but so does this: the trace NEVER breaks the turn.
30 31 32 33 34 35 36 37 38 |
# File 'lib/insika/tool_trace_store.rb', line 30 def record(session_id:, entry:) sid = session_id.to_s return if sid.empty? list = (@store.get(SCOPE, sid) || []) + [sanitize(entry)] @store.set(SCOPE, sid, list.last(MAX_PER_SESSION)) rescue StandardError nil end |