step 5 (partial): strip dropped packages from production code

Removed all references to dropped packages in non-test code.
Zero dropped imports, store refs, or model types remaining.

Major removals:
  - scheduler/ package (entire dir) — tasks moved to extension track
  - taskutil/ package (entire dir)
  - health/ package (entire dir) — provider/tool health
  - sandbox/provider_module.go — provider.complete module
  - handlers: workflow_entry, workflow_instances, workflow_forms,
    workflow_assignments, workflow_monitor, health_admin (6 files)
  - auth/session.go, middleware/session_auth.go
  - store/{postgres,sqlite}/sessions.go, tasks.go

Rewrites:
  - store/{postgres,sqlite}/health.go — kernel-only Prune
    (ws_tickets, rate_limit_counters, stale presence)
  - handlers/admin.go: 847→467 lines (stripped provider CRUD)
  - handlers/teams.go: 520→411 lines (stripped model listing)
  - sandbox/runner.go: removed ProviderResolver
  - sandbox/workflow_module.go: 216→83 lines (definition-only)
  - main.go: 1579→1325 lines (stripped dropped package init)
  - pages/pages.go: stripped channel/session lookups
  - events/types.go: stripped chat/channel/workspace event routes
  - models: stripped stale types, constants, notification types

Store interface cleanup:
  - Removed SessionStore, TaskStore from Stores struct
  - Stripped workflow assignment methods from WorkflowStore iface
  - Stripped assignment methods from PG+SQLite workflow stores
  - Updated testhelper.go table list to kernel-only

Migrations: removed 008_tasks.sql (both dialects)

-9665/+69 lines across 51 files.
This commit is contained in:
2026-03-25 21:13:01 -04:00
parent ebea16344c
commit e4b7ee98a5
55 changed files with 95 additions and 9981 deletions

View File

@@ -2,188 +2,42 @@ package sqlite
import (
"context"
"database/sql"
"time"
"switchboard-core/models"
"switchboard-core/store"
"switchboard-core/database"
)
// ── HealthStore ─────────────────────────────
type HealthStore struct{}
func NewHealthStore() *HealthStore { return &HealthStore{} }
func (s *HealthStore) UpsertWindow(ctx context.Context, w *models.ProviderHealthWindow) error {
id := store.NewID()
windowStr := w.WindowStart.Format(timeFmt)
_, err := DB.ExecContext(ctx, `
INSERT INTO provider_health (id, provider_config_id, window_start,
request_count, error_count, timeout_count, rate_limit_count,
total_latency_ms, max_latency_ms, last_error, last_error_at, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, datetime('now'))
ON CONFLICT (provider_config_id, window_start) DO UPDATE SET
request_count = provider_health.request_count + excluded.request_count,
error_count = provider_health.error_count + excluded.error_count,
timeout_count = provider_health.timeout_count + excluded.timeout_count,
rate_limit_count = provider_health.rate_limit_count + excluded.rate_limit_count,
total_latency_ms = provider_health.total_latency_ms + excluded.total_latency_ms,
max_latency_ms = MAX(provider_health.max_latency_ms, excluded.max_latency_ms),
last_error = COALESCE(excluded.last_error, provider_health.last_error),
last_error_at = COALESCE(excluded.last_error_at, provider_health.last_error_at),
updated_at = datetime('now')
`, id, w.ProviderConfigID, windowStr,
w.RequestCount, w.ErrorCount, w.TimeoutCount, w.RateLimitCount,
w.TotalLatencyMs, w.MaxLatencyMs, w.LastError, w.LastErrorAt,
)
return err
}
func (s *HealthStore) GetCurrentWindow(ctx context.Context, providerConfigID string) (*models.ProviderHealthWindow, error) {
windowStr := time.Now().UTC().Truncate(time.Hour).Format(timeFmt)
var w models.ProviderHealthWindow
var windowStartStr string
err := DB.QueryRowContext(ctx, `
SELECT id, provider_config_id, window_start,
request_count, error_count, timeout_count, rate_limit_count,
total_latency_ms, max_latency_ms, last_error, last_error_at
FROM provider_health
WHERE provider_config_id = ? AND window_start = ?
`, providerConfigID, windowStr).Scan(
&w.ID, &w.ProviderConfigID, &windowStartStr,
&w.RequestCount, &w.ErrorCount, &w.TimeoutCount, &w.RateLimitCount,
&w.TotalLatencyMs, &w.MaxLatencyMs, &w.LastError, &w.LastErrorAt,
)
if err == sql.ErrNoRows {
return nil, nil
}
if err != nil {
return nil, err
}
w.WindowStart, _ = time.Parse(timeFmt, windowStartStr)
return &w, nil
}
func (s *HealthStore) ListWindows(ctx context.Context, providerConfigID string, hours int) ([]models.ProviderHealthWindow, error) {
rows, err := DB.QueryContext(ctx, `
SELECT id, provider_config_id, window_start,
request_count, error_count, timeout_count, rate_limit_count,
total_latency_ms, max_latency_ms, last_error, last_error_at
FROM provider_health
WHERE provider_config_id = ?
ORDER BY window_start DESC
LIMIT ?
`, providerConfigID, hours)
if err != nil {
return nil, err
}
defer rows.Close()
return scanHealthRows(rows)
}
func (s *HealthStore) ListAllCurrent(ctx context.Context) ([]models.ProviderHealthWindow, error) {
windowStr := time.Now().UTC().Truncate(time.Hour).Format(timeFmt)
rows, err := DB.QueryContext(ctx, `
SELECT id, provider_config_id, window_start,
request_count, error_count, timeout_count, rate_limit_count,
total_latency_ms, max_latency_ms, last_error, last_error_at
FROM provider_health
WHERE window_start = ?
ORDER BY provider_config_id
`, windowStr)
if err != nil {
return nil, err
}
defer rows.Close()
return scanHealthRows(rows)
}
// Prune deletes stale kernel data older than the given time.
func (s *HealthStore) Prune(ctx context.Context, before time.Time) (int64, error) {
result, err := DB.ExecContext(ctx, `
DELETE FROM provider_health WHERE window_start < ?
`, before.Format(timeFmt))
if err != nil {
return 0, err
var total int64
ts := before.UTC().Format("2006-01-02 15:04:05")
res, _ := database.DB.ExecContext(ctx,
`DELETE FROM ws_tickets WHERE expires_at < ?`, ts)
if res != nil {
n, _ := res.RowsAffected()
total += n
}
DB.ExecContext(ctx, `DELETE FROM tool_health WHERE window_start < ?`, before.Format(timeFmt))
return result.RowsAffected()
}
// ── Tool Health (v0.22.4) ────────────────────
func (s *HealthStore) UpsertToolWindow(ctx context.Context, w *models.ToolHealthWindow) error {
id := store.NewID()
windowStr := w.WindowStart.Format(timeFmt)
_, err := DB.ExecContext(ctx, `
INSERT INTO tool_health (id, tool_name, window_start,
request_count, error_count, total_latency_ms, max_latency_ms,
last_error, last_error_at, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, datetime('now'))
ON CONFLICT (tool_name, window_start) DO UPDATE SET
request_count = tool_health.request_count + excluded.request_count,
error_count = tool_health.error_count + excluded.error_count,
total_latency_ms = tool_health.total_latency_ms + excluded.total_latency_ms,
max_latency_ms = MAX(tool_health.max_latency_ms, excluded.max_latency_ms),
last_error = COALESCE(excluded.last_error, tool_health.last_error),
last_error_at = COALESCE(excluded.last_error_at, tool_health.last_error_at),
updated_at = datetime('now')
`, id, w.ToolName, windowStr,
w.RequestCount, w.ErrorCount, w.TotalLatencyMs, w.MaxLatencyMs,
w.LastError, w.LastErrorAt,
)
return err
}
func (s *HealthStore) ListAllToolCurrent(ctx context.Context) ([]models.ToolHealthWindow, error) {
windowStr := time.Now().UTC().Truncate(time.Hour).Format(timeFmt)
rows, err := DB.QueryContext(ctx, `
SELECT id, tool_name, window_start,
request_count, error_count, total_latency_ms, max_latency_ms,
last_error, last_error_at
FROM tool_health
WHERE window_start = ?
ORDER BY tool_name
`, windowStr)
if err != nil {
return nil, err
res, _ = database.DB.ExecContext(ctx,
`DELETE FROM rate_limit_counters WHERE window_start < ?`, ts)
if res != nil {
n, _ := res.RowsAffected()
total += n
}
defer rows.Close()
var result []models.ToolHealthWindow
for rows.Next() {
var w models.ToolHealthWindow
var windowStartStr string
if err := rows.Scan(
&w.ID, &w.ToolName, &windowStartStr,
&w.RequestCount, &w.ErrorCount, &w.TotalLatencyMs, &w.MaxLatencyMs,
&w.LastError, &w.LastErrorAt,
); err != nil {
return nil, err
}
w.WindowStart, _ = time.Parse(timeFmt, windowStartStr)
result = append(result, w)
res, _ = database.DB.ExecContext(ctx,
`DELETE FROM user_presence WHERE last_seen < ? AND status = 'offline'`, ts)
if res != nil {
n, _ := res.RowsAffected()
total += n
}
return result, rows.Err()
}
func (s *HealthStore) DeactivateProvider(ctx context.Context, configID string) error {
_, err := DB.ExecContext(ctx, `UPDATE provider_configs SET is_active = 0 WHERE id = ?`, configID)
return err
}
func scanHealthRows(rows *sql.Rows) ([]models.ProviderHealthWindow, error) {
var result []models.ProviderHealthWindow
for rows.Next() {
var w models.ProviderHealthWindow
var windowStartStr string
if err := rows.Scan(
&w.ID, &w.ProviderConfigID, &windowStartStr,
&w.RequestCount, &w.ErrorCount, &w.TimeoutCount, &w.RateLimitCount,
&w.TotalLatencyMs, &w.MaxLatencyMs, &w.LastError, &w.LastErrorAt,
); err != nil {
return nil, err
}
w.WindowStart, _ = time.Parse(timeFmt, windowStartStr)
result = append(result, w)
}
return result, rows.Err()
return total, nil
}