Files
pad/internal/store/migrations/069_workspace_source.sql
T
xarmian 584ac9a806 fix(web): treat CLI/MCP-created workspaces as agent-connected (BUG-1557) (#781)
`pad init` connects an agent (installs the skill, stores credentials) and
creates a workspace, but the web UI still showed the "connect an agent"
banner and onboarding launchpad. The only signal for "agent connected" was
has_agent_activity — an item existing with source cli/mcp — and a fresh
pad-init workspace has zero items, so the UI nagged to connect an agent the
user already had.

Give the server a truthful signal: a workspace created through an agent
surface already has an agent wired up before it creates its first item. Add
a `source` column to workspaces (web/cli/mcp), attributed authoritatively
server-side from the request auth shape (actorFromRequest) — never from the
request body, so a web client can't spoof "cli" to self-suppress the
prompts. The dashboard ORs source in (cli,mcp) into has_agent_activity when
the cheap item check comes up empty.

- migrations 069 (sqlite) / 047 (postgres): workspaces.source NOT NULL
  DEFAULT '' (legacy rows stay "unknown", never treated as agent-created)
- models.Workspace.Source + WorkspaceCreate.Source (json:"-", server-set)
- thread source through the CreateWorkspace INSERT + all 7 workspace scan
  sites (workspaces.go, workspace_members.go)
- handleCreateWorkspace derives source from actorFromRequest
- OnboardingLaunchpad step 1 collapses to "Agent connected" when the agent
  is already wired up, shifting emphasis to "tell it to set up"

Web modal and cloud-signup auto-create flows are unchanged and still
correctly prompt to connect (source web / empty).

Tests: store source round-trip across reads; dashboard reports
agent-connected for a cli-created workspace with zero items; web-created
stays not-connected until an agent item exists; a web body-spoofed source
is ignored.

Claude-Session: https://claude.ai/code/session_01HxBkAMiFBtCRJ2tKSCt3ST
2026-07-01 23:25:24 -04:00

20 lines
1.1 KiB
SQL

-- Add `source` to workspaces: record how a workspace was created (web UI /
-- CLI / MCP). Drives the dashboard's has_agent_activity signal — a workspace
-- created through an agent surface (`pad init`, `pad workspace init`, MCP
-- pad_workspace.create) already has an agent wired up before that agent
-- creates its first item, so the "connect an agent" banner should not fire
-- for it (BUG-1557).
--
-- Existing rows predate this tracking, so they default to '' ("unknown /
-- legacy origin") — deliberately NOT 'web', since many pre-existing
-- workspaces were created via `pad init` (CLI). An empty value means
-- "provenance unknown" and is never treated as agent-created. New workspaces
-- set 'web' | 'cli' | 'mcp' explicitly at creation time.
--
-- SQLite has no `ADD COLUMN IF NOT EXISTS`, so this is a bare ADD COLUMN. The
-- migration runner tolerates the "duplicate column name" error for
-- `ALTER TABLE ... ADD COLUMN`, so a partially-applied re-run is idempotent.
-- Adding a NOT NULL column is legal here only because a constant DEFAULT is
-- supplied.
ALTER TABLE workspaces ADD COLUMN source TEXT NOT NULL DEFAULT '';