Documentation
¶
Index ¶
- Constants
- func CheckSSL(dsn string) error
- func CheckSchemaCompat(ctx context.Context, db *sql.DB) error
- func EnsureSchema(ctx context.Context, db *sql.DB, schema string) error
- func FormatISO8601(t time.Time) string
- func FormatSyncTimestamp(t time.Time) string
- func IsReadOnlyError(err error) bool
- func NormalizeLocalSyncStateTimestamps(local SyncStateStore) error
- func NormalizeLocalSyncTimestamp(value string) (string, error)
- func NormalizeSyncTimestamp(value string) (string, error)
- func Open(dsn, schema string, allowInsecure bool) (*sql.DB, error)
- func ParseSQLiteTimestamp(s string) (time.Time, bool)
- func PreviousLocalSyncTimestamp(value string) (string, error)
- func RedactDSN(dsn string) string
- func WarnInsecureSSL(dsn string)
- type PushResult
- type Store
- func (s *Store) BulkStarSessions(_ []string) error
- func (s *Store) Close() error
- func (s *Store) DB() *sql.DB
- func (s *Store) DecodeCursor(raw string) (db.SessionCursor, error)
- func (s *Store) DeleteInsight(_ int64) error
- func (s *Store) DeleteSessionIfTrashed(_ string) (int64, error)
- func (s *Store) EmptyTrash() (int, error)
- func (s *Store) EncodeCursor(endedAt, id string, total ...int) string
- func (s *Store) GetAgents(ctx context.Context, excludeOneShot, excludeAutomated bool) ([]db.AgentInfo, error)
- func (s *Store) GetAllMessages(ctx context.Context, sessionID string) ([]db.Message, error)
- func (s *Store) GetAnalyticsActivity(ctx context.Context, f db.AnalyticsFilter, granularity string) (db.ActivityResponse, error)
- func (s *Store) GetAnalyticsHeatmap(ctx context.Context, f db.AnalyticsFilter, metric string) (db.HeatmapResponse, error)
- func (s *Store) GetAnalyticsHourOfWeek(ctx context.Context, f db.AnalyticsFilter) (db.HourOfWeekResponse, error)
- func (s *Store) GetAnalyticsProjects(ctx context.Context, f db.AnalyticsFilter) (db.ProjectsAnalyticsResponse, error)
- func (s *Store) GetAnalyticsSessionShape(ctx context.Context, f db.AnalyticsFilter) (db.SessionShapeResponse, error)
- func (s *Store) GetAnalyticsSummary(ctx context.Context, f db.AnalyticsFilter) (db.AnalyticsSummary, error)
- func (s *Store) GetAnalyticsTools(ctx context.Context, f db.AnalyticsFilter) (db.ToolsAnalyticsResponse, error)
- func (s *Store) GetAnalyticsTopSessions(ctx context.Context, f db.AnalyticsFilter, metric string) (db.TopSessionsResponse, error)
- func (s *Store) GetAnalyticsVelocity(ctx context.Context, f db.AnalyticsFilter) (db.VelocityResponse, error)
- func (s *Store) GetChildSessions(ctx context.Context, parentID string) ([]db.Session, error)
- func (s *Store) GetInsight(_ context.Context, _ int64) (*db.Insight, error)
- func (s *Store) GetMachines(ctx context.Context, excludeOneShot, excludeAutomated bool) ([]string, error)
- func (s *Store) GetMessages(ctx context.Context, sessionID string, from, limit int, asc bool) ([]db.Message, error)
- func (s *Store) GetProjects(ctx context.Context, excludeOneShot, excludeAutomated bool) ([]db.ProjectInfo, error)
- func (s *Store) GetSession(ctx context.Context, id string) (*db.Session, error)
- func (s *Store) GetSessionActivity(ctx context.Context, sessionID string) (*db.SessionActivityResponse, error)
- func (s *Store) GetSessionFull(ctx context.Context, id string) (*db.Session, error)
- func (s *Store) GetSessionVersion(id string) (int, int64, bool)
- func (s *Store) GetStats(ctx context.Context, excludeOneShot, excludeAutomated bool) (db.Stats, error)
- func (s *Store) HasFTS() bool
- func (s *Store) InsertInsight(_ db.Insight) (int64, error)
- func (s *Store) ListInsights(_ context.Context, _ db.InsightFilter) ([]db.Insight, error)
- func (s *Store) ListPinnedMessages(_ context.Context, _ string) ([]db.PinnedMessage, error)
- func (s *Store) ListSessions(ctx context.Context, f db.SessionFilter) (db.SessionPage, error)
- func (s *Store) ListStarredSessionIDs(_ context.Context) ([]string, error)
- func (s *Store) ListTrashedSessions(_ context.Context) ([]db.Session, error)
- func (s *Store) PinMessage(_ string, _ int64, _ *string) (int64, error)
- func (s *Store) ReadOnly() bool
- func (s *Store) RenameSession(_ string, _ *string) error
- func (s *Store) ReplaceSessionMessages(_ string, _ []db.Message) error
- func (s *Store) RestoreSession(_ string) (int64, error)
- func (s *Store) Search(ctx context.Context, f db.SearchFilter) (db.SearchPage, error)
- func (s *Store) SearchSession(ctx context.Context, sessionID, query string) ([]int, error)
- func (s *Store) SetCursorSecret(secret []byte)
- func (s *Store) SoftDeleteSession(_ string) error
- func (s *Store) StarSession(_ string) (bool, error)
- func (s *Store) UnpinMessage(_ string, _ int64) error
- func (s *Store) UnstarSession(_ string) error
- func (s *Store) UpsertSession(_ db.Session) error
- type Sync
- type SyncStateStore
- type SyncStatus
Constants ¶
const LocalSyncTimestampLayout = "2006-01-02T15:04:05.000Z"
LocalSyncTimestampLayout uses millisecond precision to match SQLite's datetime resolution.
const MaxHeatmapDays = 366
MaxHeatmapDays is the maximum number of day entries.
Variables ¶
This section is empty.
Functions ¶
func CheckSSL ¶
CheckSSL returns an error when the PG connection string targets a non-loopback host without TLS encryption. It uses the pgx driver's own DSN parser to resolve the effective host and TLS configuration, avoiding bypasses from exotic DSN formats.
A connection is rejected when any path in the TLS negotiation chain (primary + fallbacks) permits plaintext for a non-loopback host. This rejects sslmode=disable, allow, and prefer.
func CheckSchemaCompat ¶
CheckSchemaCompat verifies that the PG schema has all columns required by query paths. This is a read-only probe that works against any PG role. Returns nil if compatible, or an error describing what is missing.
func EnsureSchema ¶
EnsureSchema creates the schema (if needed), then runs idempotent CREATE TABLE / ALTER TABLE statements. The schema parameter is the unquoted schema name (e.g. "agentsview").
After CREATE SCHEMA, all table DDL uses unqualified names because Open() sets search_path to the target schema.
func FormatISO8601 ¶
FormatISO8601 formats a time.Time to ISO-8601 UTC string for JSON API responses.
func FormatSyncTimestamp ¶
FormatSyncTimestamp formats a time as a microsecond-precision UTC ISO-8601 string for PG sync watermarks.
func IsReadOnlyError ¶
IsReadOnlyError returns true when the error indicates a PG read-only or insufficient-privilege condition (SQLSTATE 25006 or 42501). Uses pgconn.PgError for reliable SQLSTATE matching.
func NormalizeLocalSyncStateTimestamps ¶
func NormalizeLocalSyncStateTimestamps( local SyncStateStore, ) error
NormalizeLocalSyncStateTimestamps normalizes the last_push_at watermark in the local SQLite sync state to millisecond precision.
func NormalizeLocalSyncTimestamp ¶
NormalizeLocalSyncTimestamp parses a RFC3339Nano timestamp and re-formats it to millisecond precision for SQLite sync state.
func NormalizeSyncTimestamp ¶
NormalizeSyncTimestamp parses a RFC3339Nano timestamp and re-formats it to microsecond precision for PG sync.
func Open ¶
Open opens a PG connection pool, validates SSL, and sets search_path to the given schema on every connection.
The schema name is validated and quoted to prevent injection. When allowInsecure is true, non-loopback connections without TLS produce a warning instead of failing.
func ParseSQLiteTimestamp ¶
ParseSQLiteTimestamp parses an ISO-8601 text timestamp from SQLite into a time.Time. Returns zero time and false for empty strings or unparseable values.
func PreviousLocalSyncTimestamp ¶
PreviousLocalSyncTimestamp returns the timestamp 1ms before the given value, formatted at millisecond precision. This creates a non-overlapping boundary for incremental sync queries against SQLite.
func RedactDSN ¶
RedactDSN returns the host portion of the DSN for diagnostics, stripping credentials, query parameters, and path components that may contain secrets.
func WarnInsecureSSL ¶
func WarnInsecureSSL(dsn string)
WarnInsecureSSL logs a warning when the PG connection string targets a non-loopback host without TLS encryption. Uses the pgx driver's DSN parser for accurate host/TLS resolution.
Types ¶
type PushResult ¶
PushResult summarizes a push sync operation.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store wraps a PostgreSQL connection for read-only session queries.
func NewStore ¶
NewStore opens a PostgreSQL connection using the shared Open() helper and returns a read-only Store. When allowInsecure is true, non-loopback connections without TLS produce a warning instead of failing.
func (*Store) BulkStarSessions ¶
BulkStarSessions is not supported in read-only mode.
func (*Store) DB ¶
DB returns the underlying *sql.DB for operations that need direct access (e.g. schema compatibility checks).
func (*Store) DecodeCursor ¶
func (s *Store) DecodeCursor( raw string, ) (db.SessionCursor, error)
DecodeCursor parses a base64-encoded cursor string.
func (*Store) DeleteInsight ¶
DeleteInsight is not supported in read-only mode.
func (*Store) DeleteSessionIfTrashed ¶
DeleteSessionIfTrashed is not supported in read-only mode.
func (*Store) EmptyTrash ¶
EmptyTrash is not supported in read-only mode.
func (*Store) EncodeCursor ¶
EncodeCursor returns a base64-encoded, HMAC-signed cursor.
func (*Store) GetAgents ¶
func (s *Store) GetAgents( ctx context.Context, excludeOneShot, excludeAutomated bool, ) ([]db.AgentInfo, error)
GetAgents returns distinct agent names with session counts.
func (*Store) GetAllMessages ¶
GetAllMessages returns all messages for a session ordered by ordinal.
func (*Store) GetAnalyticsActivity ¶
func (s *Store) GetAnalyticsActivity( ctx context.Context, f db.AnalyticsFilter, granularity string, ) (db.ActivityResponse, error)
GetAnalyticsActivity returns session/message counts grouped by time bucket.
func (*Store) GetAnalyticsHeatmap ¶
func (s *Store) GetAnalyticsHeatmap( ctx context.Context, f db.AnalyticsFilter, metric string, ) (db.HeatmapResponse, error)
GetAnalyticsHeatmap returns daily counts with intensity levels.
func (*Store) GetAnalyticsHourOfWeek ¶
func (s *Store) GetAnalyticsHourOfWeek( ctx context.Context, f db.AnalyticsFilter, ) (db.HourOfWeekResponse, error)
GetAnalyticsHourOfWeek returns message counts bucketed by day-of-week and hour-of-day.
func (*Store) GetAnalyticsProjects ¶
func (s *Store) GetAnalyticsProjects( ctx context.Context, f db.AnalyticsFilter, ) (db.ProjectsAnalyticsResponse, error)
GetAnalyticsProjects returns per-project analytics.
func (*Store) GetAnalyticsSessionShape ¶
func (s *Store) GetAnalyticsSessionShape( ctx context.Context, f db.AnalyticsFilter, ) (db.SessionShapeResponse, error)
GetAnalyticsSessionShape returns distribution histograms for session length, duration, and autonomy ratio.
func (*Store) GetAnalyticsSummary ¶
func (s *Store) GetAnalyticsSummary( ctx context.Context, f db.AnalyticsFilter, ) (db.AnalyticsSummary, error)
GetAnalyticsSummary returns aggregate statistics.
func (*Store) GetAnalyticsTools ¶
func (s *Store) GetAnalyticsTools( ctx context.Context, f db.AnalyticsFilter, ) (db.ToolsAnalyticsResponse, error)
GetAnalyticsTools returns tool usage analytics.
func (*Store) GetAnalyticsTopSessions ¶
func (s *Store) GetAnalyticsTopSessions( ctx context.Context, f db.AnalyticsFilter, metric string, ) (db.TopSessionsResponse, error)
GetAnalyticsTopSessions returns the top 10 sessions by the given metric.
func (*Store) GetAnalyticsVelocity ¶
func (s *Store) GetAnalyticsVelocity( ctx context.Context, f db.AnalyticsFilter, ) (db.VelocityResponse, error)
GetAnalyticsVelocity computes turn cycle, first response, and throughput metrics.
func (*Store) GetChildSessions ¶
GetChildSessions returns sessions whose parent_session_id matches the given parentID.
func (*Store) GetInsight ¶
GetInsight returns nil.
func (*Store) GetMachines ¶
func (s *Store) GetMachines( ctx context.Context, excludeOneShot, excludeAutomated bool, ) ([]string, error)
GetMachines returns distinct machine names.
func (*Store) GetMessages ¶
func (s *Store) GetMessages( ctx context.Context, sessionID string, from, limit int, asc bool, ) ([]db.Message, error)
GetMessages returns paginated messages for a session.
func (*Store) GetProjects ¶
func (s *Store) GetProjects( ctx context.Context, excludeOneShot, excludeAutomated bool, ) ([]db.ProjectInfo, error)
GetProjects returns project names with session counts.
func (*Store) GetSession ¶
GetSession returns a single session by ID, excluding soft-deleted sessions.
func (*Store) GetSessionActivity ¶ added in v0.17.0
func (s *Store) GetSessionActivity( ctx context.Context, sessionID string, ) (*db.SessionActivityResponse, error)
GetSessionActivity returns time-bucketed message counts for a session, using PostgreSQL-specific timestamp functions.
func (*Store) GetSessionFull ¶
GetSessionFull returns a single session by ID including soft-deleted sessions.
func (*Store) GetSessionVersion ¶
GetSessionVersion returns the message count and a hash of updated_at for SSE change detection.
func (*Store) GetStats ¶
func (s *Store) GetStats( ctx context.Context, excludeOneShot, excludeAutomated bool, ) (db.Stats, error)
GetStats returns database statistics, counting only root sessions with messages.
func (*Store) InsertInsight ¶
InsertInsight is not supported in read-only mode.
func (*Store) ListInsights ¶
ListInsights returns an empty slice.
func (*Store) ListPinnedMessages ¶
ListPinnedMessages returns an empty slice.
func (*Store) ListSessions ¶
func (s *Store) ListSessions( ctx context.Context, f db.SessionFilter, ) (db.SessionPage, error)
ListSessions returns a cursor-paginated list of sessions.
func (*Store) ListStarredSessionIDs ¶
ListStarredSessionIDs returns an empty slice.
func (*Store) ListTrashedSessions ¶
ListTrashedSessions returns an empty slice.
func (*Store) PinMessage ¶
PinMessage is not supported in read-only mode.
func (*Store) RenameSession ¶
RenameSession is not supported in read-only mode.
func (*Store) ReplaceSessionMessages ¶
ReplaceSessionMessages is not supported in read-only mode.
func (*Store) RestoreSession ¶
RestoreSession is not supported in read-only mode.
func (*Store) Search ¶
func (s *Store) Search( ctx context.Context, f db.SearchFilter, ) (db.SearchPage, error)
Search performs ILIKE-based full-text search across messages, grouped to one result per session via DISTINCT ON, UNION'd with a session name (display_name / first_message) branch.
func (*Store) SearchSession ¶
SearchSession performs ILIKE substring search within a single session's messages, returning matching ordinals.
func (*Store) SetCursorSecret ¶
SetCursorSecret sets the HMAC key used for cursor signing.
func (*Store) SoftDeleteSession ¶
SoftDeleteSession is not supported in read-only mode.
func (*Store) StarSession ¶
StarSession is not supported in read-only mode.
func (*Store) UnpinMessage ¶
UnpinMessage is not supported in read-only mode.
func (*Store) UnstarSession ¶
UnstarSession is not supported in read-only mode.
type Sync ¶
type Sync struct {
// contains filtered or unexported fields
}
Sync manages push-only sync from local SQLite to a remote PostgreSQL database.
func New ¶
New creates a Sync instance and verifies the PG connection. The machine name must not be "local", which is reserved as the SQLite sentinel for sessions that originated on this machine. When allowInsecure is true, non-loopback connections without TLS produce a warning instead of failing.
func (*Sync) Close ¶
Close closes the PostgreSQL connection pool. Callers must ensure no Push operations are in-flight before calling Close; otherwise those operations will fail with connection errors.
func (*Sync) EnsureSchema ¶
EnsureSchema creates the schema and tables in PG if they don't already exist. It also marks the schema as initialized so subsequent Push calls skip redundant checks.
func (*Sync) Push ¶
Push syncs local sessions and messages to PostgreSQL. Only sessions modified since the last push are processed. When full is true, the per-message content heuristic is bypassed and every candidate session's messages are re-pushed unconditionally.
Known limitation: sessions that are permanently deleted from SQLite (via prune) are not propagated as deletions to PG because the local rows no longer exist at push time. Sessions soft-deleted with deleted_at are synced correctly. Use a direct PG DELETE to remove permanently pruned sessions from PG if needed.
func (*Sync) Status ¶
func (s *Sync) Status( ctx context.Context, ) (SyncStatus, error)
Status returns sync status information. Sync state reads (last_push_at) are non-fatal because these are informational watermarks stored in SQLite. PG query failures are fatal because they indicate a connectivity problem that the caller needs to know about.