Files
deepseek-harness/packages/session/session-persistence-sqlite/resources/sql/derived/session-tools.sql
T
Magolor 6da7ed3f6e refactor(session): keep the SQLite store's SQL in versioned .sql resources
The schema and every static statement of the SQLite Session store were
string literals in TypeScript, and the upgrade step from the frame layout
executed whatever the current schema constant held. They now live under
resources/sql: schema/vN.sql is the whole schema of one version and is
not edited once released, upgrade/A-to-B holds the statements of one
upgrade step, and store/ and derived/ hold the statements of the store
and of the derived-table runtime. src/sql.ts is their only reader.

Two internal views, segment_extents and session_heads, replace the SQL
fragments the store shared by string interpolation. Transaction control,
connection pragmas and the DDL generated from a derivation stay inline.
2026-11-25 18:47:26 +08:00

10 lines
776 B
SQL

-- Body of the session_tools view: each tool call of a Session with its result when stored. A result can sit in a
-- later Segment than its call, and the lookup is correlated so a filter on one Session never reads another's results.
SELECT p.session_id, c.seq, c.time, c.tool, c.turn, c.step, r.seq AS result_seq,
r.is_error, r.error_code, r.time - c.time AS duration_ms
FROM sessions p JOIN segment_paths m ON m.segment_id = p.head_segment_id
JOIN tool_calls c ON c.segment_id = m.member_id AND c.seq < m.end_seq
LEFT JOIN tool_results r ON r.call_seq = c.seq
AND r.segment_id IN (SELECT member_id FROM segment_paths WHERE segment_id = p.head_segment_id)
AND r.seq < (SELECT end_seq FROM segment_paths WHERE segment_id = p.head_segment_id AND member_id = r.segment_id)