Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.
Python agent-orchestrationaiai-agentschatopsdiscordlangchainmcpmicrosoft-teamsmulti-agentopen-sourceopenaiself-hostedslack
feat(switchdash): persist remote-host setup plans (CHOO-1809)
switch-worker-louis-remotef2b4007be2c3
diff --git a/dash/apps/switchdash-desktop/drizzle/0045_remote_host_setup_plans.sql b/dash/apps/switchdash-desktop/drizzle/0045_remote_host_setup_plans.sqlnew file mode 100644index 000000000..672720c84--- /dev/null+++ b/dash/apps/switchdash-desktop/drizzle/0045_remote_host_setup_plans.sql@@ -0,0 +1,21 @@+/*+ Remote-host setup plans (CHOO-1809).++ Onboarding a remote host is a sequence — check and install each prerequisite in+ turn — and until now that sequence lived only in renderer state. Nothing+ survived a reload, so a failure partway through left no record of what had+ already succeeded and no way to resume.++ One row per onboarded host. `steps` holds the JSON-serialised step list; it is+ read and written whole, and validated on read rather than trusted. Purely+ additive: no existing table is touched and nothing is backfilled, because a+ host with no row simply has no plan yet.+*/+CREATE TABLE `remote_host_setup_plans` (+ `ssh_host` text PRIMARY KEY NOT NULL,+ `status` text DEFAULT 'idle' NOT NULL,+ `steps` text NOT NULL,+ `current_step_id` text,+ `created_at` text DEFAULT CURRENT_TIMESTAMP NOT NULL,+ `updated_at` text DEFAULT CURRENT_TIMESTAMP NOT NULL+);diff --git a/dash/apps/switchdash-desktop/drizzle/meta/0045_snapshot.json b/dash/apps/switchdash-desktop/drizzle/meta/0045_snapshot.jsonnew file mode 100644index 000000000..91e0aa525--- /dev/null+++ b/dash/apps/switchdash-desktop/drizzle/meta/0045_snapshot.json@@ -0,0 +1,929 @@+{+ "version": "6",+ "dialect": "sqlite",+ "id": "ce5528fd-0837-495c-81eb-812635d13826",+ "prevId": "0accfa68-741f-4f75-9b40-7a47c434091e",+ "tables": {+ "agents": {+ "name": "agents",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "location_id": {+ "name": "location_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "provider_id": {+ "name": "provider_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "switch_agent_id": {+ "name": "switch_agent_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "api_endpoint": {+ "name": "api_endpoint",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "server_id": {+ "name": "server_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "auto_approve": {+ "name": "auto_approve",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": false+ },+ "created_at": {+ "name": "created_at",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "CURRENT_TIMESTAMP"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "CURRENT_TIMESTAMP"+ }+ },+ "indexes": {+ "idx_agents_location_id": {+ "name": "idx_agents_location_id",+ "columns": [+ "location_id"+ ],+ "isUnique": false+ },+ "idx_agents_server_id": {+ "name": "idx_agents_server_id",+ "columns": [+ "server_id"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "agents_location_id_locations_id_fk": {+ "name": "agents_location_id_locations_id_fk",+ "tableFrom": "agents",+ "tableTo": "locations",+ "columnsFrom": [+ "location_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "agents_server_id_switch_servers_id_fk": {+ "name": "agents_server_id_switch_servers_id_fk",+ "tableFrom": "agents",+ "tableTo": "switch_servers",+ "columnsFrom": [+ "server_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "app_secrets": {+ "name": "app_secrets",+ "columns": {+ "key": {+ "name": "key",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "secret": {+ "name": "secret",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {+ "idx_app_secrets_key": {+ "name": "idx_app_secrets_key",+ "columns": [+ "key"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "app_settings": {+ "name": "app_settings",+ "columns": {+ "key": {+ "name": "key",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "value": {+ "name": "value",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "CURRENT_TIMESTAMP"+ }+ },+ "indexes": {+ "idx_app_settings_key": {+ "name": "idx_app_settings_key",+ "columns": [+ "key"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "kv": {+ "name": "kv",+ "columns": {+ "key": {+ "name": "key",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "value": {+ "name": "value",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "CURRENT_TIMESTAMP"+ }+ },+ "indexes": {+ "idx_kv_key": {+ "name": "idx_kv_key",+ "columns": [+ "key"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "location_settings": {+ "name": "location_settings",+ "columns": {+ "location_id": {+ "name": "location_id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "base_settings_json": {+ "name": "base_settings_json",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'{}'"+ },+ "shareable_settings_json": {+ "name": "shareable_settings_json",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'{}'"+ },+ "legacy_config_migrated_at": {+ "name": "legacy_config_migrated_at",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "CURRENT_TIMESTAMP"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "CURRENT_TIMESTAMP"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "location_settings_location_id_locations_id_fk": {+ "name": "location_settings_location_id_locations_id_fk",+ "tableFrom": "location_settings",+ "tableTo": "locations",+ "columnsFrom": [+ "location_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "locations": {+ "name": "locations",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "ssh_host": {+ "name": "ssh_host",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "''"+ },+ "dir": {+ "name": "dir",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "CURRENT_TIMESTAMP"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "CURRENT_TIMESTAMP"+ }+ },+ "indexes": {+ "idx_locations_host_dir": {+ "name": "idx_locations_host_dir",+ "columns": [+ "ssh_host",+ "dir"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "messages": {+ "name": "messages",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "session_id": {+ "name": "session_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "content": {+ "name": "content",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "sender": {+ "name": "sender",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "timestamp": {+ "name": "timestamp",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "CURRENT_TIMESTAMP"+ },+ "metadata": {+ "name": "metadata",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "idx_messages_session_id": {+ "name": "idx_messages_session_id",+ "columns": [+ "session_id"+ ],+ "isUnique": false+ },+ "idx_messages_timestamp": {+ "name": "idx_messages_timestamp",+ "columns": [+ "timestamp"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "messages_session_id_sessions_id_fk": {+ "name": "messages_session_id_sessions_id_fk",+ "tableFrom": "messages",+ "tableTo": "sessions",+ "columnsFrom": [+ "session_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "remote_host_reachability": {+ "name": "remote_host_reachability",+ "columns": {+ "ssh_host": {+ "name": "ssh_host",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'unknown'"+ },+ "last_error": {+ "name": "last_error",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "last_checked_at": {+ "name": "last_checked_at",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "last_reachable_at": {+ "name": "last_reachable_at",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "consecutive_failures": {+ "name": "consecutive_failures",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": 0+ },+ "updated_at": {+ "name": "updated_at",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "CURRENT_TIMESTAMP"+ }+ },+ "indexes": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "remote_host_setup_plans": {+ "name": "remote_host_setup_plans",+ "columns": {+ "ssh_host": {+ "name": "ssh_host",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'idle'"+ },+ "steps": {+ "name": "steps",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "current_step_id": {+ "name": "current_step_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "CURRENT_TIMESTAMP"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "CURRENT_TIMESTAMP"+ }+ },+ "indexes": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "remote_hosts": {+ "name": "remote_hosts",+ "columns": {+ "ssh_host": {+ "name": "ssh_host",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "CURRENT_TIMESTAMP"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "CURRENT_TIMESTAMP"+ }+ },+ "indexes": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "session_room_connections": {+ "name": "session_room_connections",+ "columns": {+ "session_id": {+ "name": "session_id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "room_id": {+ "name": "room_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "room_name": {+ "name": "room_name",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "switch_agent_id": {+ "name": "switch_agent_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "updated_at": {+ "name": "updated_at",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "CURRENT_TIMESTAMP"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "session_room_connections_session_id_sessions_id_fk": {+ "name": "session_room_connections_session_id_sessions_id_fk",+ "tableFrom": "session_room_connections",+ "tableTo": "sessions",+ "columnsFrom": [+ "session_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "sessions": {+ "name": "sessions",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "agent_id": {+ "name": "agent_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "config": {+ "name": "config",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "shell_id": {+ "name": "shell_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'system'"+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "agent_session_id": {+ "name": "agent_session_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "agent_status": {+ "name": "agent_status",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "agent_status_seen": {+ "name": "agent_status_seen",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": 1+ },+ "is_initial_session": {+ "name": "is_initial_session",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "is_pinned": {+ "name": "is_pinned",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": 0+ },+ "archived_at": {+ "name": "archived_at",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "last_interacted_at": {+ "name": "last_interacted_at",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "status_changed_at": {+ "name": "status_changed_at",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "CURRENT_TIMESTAMP"+ },+ "created_at": {+ "name": "created_at",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "CURRENT_TIMESTAMP"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "CURRENT_TIMESTAMP"+ }+ },+ "indexes": {+ "idx_sessions_agent_id": {+ "name": "idx_sessions_agent_id",+ "columns": [+ "agent_id"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "sessions_agent_id_agents_id_fk": {+ "name": "sessions_agent_id_agents_id_fk",+ "tableFrom": "sessions",+ "tableTo": "agents",+ "columnsFrom": [+ "agent_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "switch_servers": {+ "name": "switch_servers",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "gateway_url": {+ "name": "gateway_url",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "api_url": {+ "name": "api_url",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "managed": {+ "name": "managed",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": false+ },+ "management_kind": {+ "name": "management_kind",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "ssh_host": {+ "name": "ssh_host",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "CURRENT_TIMESTAMP"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "CURRENT_TIMESTAMP"+ }+ },+ "indexes": {+ "idx_switch_servers_gateway_url": {+ "name": "idx_switch_servers_gateway_url",+ "columns": [+ "gateway_url"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ }+ },+ "views": {},+ "enums": {},+ "_meta": {+ "schemas": {},+ "tables": {},+ "columns": {}+ },+ "internal": {+ "indexes": {}+ }+}\ No newline at end of filediff --git a/dash/apps/switchdash-desktop/drizzle/meta/_journal.json b/dash/apps/switchdash-desktop/drizzle/meta/_journal.jsonindex 5ce5ca53e..8bac21179 100644--- a/dash/apps/switchdash-desktop/drizzle/meta/_journal.json+++ b/dash/apps/switchdash-desktop/drizzle/meta/_journal.json@@ -316,6 +316,13 @@"when": 1785224671278,"tag": "0044_session_room_connections","breakpoints": true+ },+ {+ "idx": 45,+ "version": "6",+ "when": 1785420507192,+ "tag": "0045_remote_host_setup_plans",+ "breakpoints": true}]}diff --git a/dash/apps/switchdash-desktop/src/main/core/remote-hosts/setup/setup-plan-store.ts b/dash/apps/switchdash-desktop/src/main/core/remote-hosts/setup/setup-plan-store.tsnew file mode 100644index 000000000..bece11ec8--- /dev/null+++ b/dash/apps/switchdash-desktop/src/main/core/remote-hosts/setup/setup-plan-store.ts@@ -0,0 +1,150 @@+/**+ * Persistence for remote-host setup plans (CHOO-1809).+ *+ * Plans are validated on the way in from SQLite rather than trusted. A row we+ * cannot parse raises: silently returning "no plan" would be read by every+ * caller as "this host has nothing outstanding", which is the most dangerous+ * possible misreading of a corrupt record.+ */++import { eq } from 'drizzle-orm';+import { db } from '@main/db/client';+import { remoteHostSetupPlans, type RemoteHostSetupPlanRow } from '@main/db/schema';+import type {+ DependencyCheckOutcome,+ HostSetupPlan,+ HostSetupPlanStatus,+ HostSetupStep,+ HostSetupStepKind,+ HostSetupStepState,+} from '@shared/core/remote-hosts/setup';++const PLAN_STATUSES: HostSetupPlanStatus[] = ['idle', 'running', 'halted', 'complete'];+const STEP_STATES: HostSetupStepState[] = [+ 'pending',+ 'checking',+ 'installing',+ 'satisfied',+ 'failed',+ 'skipped',+ 'blocked',+];+const STEP_KINDS: HostSetupStepKind[] = [+ 'core-dependency',+ 'agent-cli',+ 'agent-plugin',+ 'gh-auth',+];+const OUTCOMES: DependencyCheckOutcome[] = [+ 'satisfied',+ 'missing',+ 'not-running',+ 'wrong-version',+ 'unknown',+];++function oneOf<T extends string>(allowed: T[], raw: unknown, field: string, sshHost: string): T {+ const match = allowed.find((value) => value === raw);+ if (!match) {+ throw new Error(+ `Invalid ${field} '${String(raw)}' in the persisted setup plan for host ${sshHost}`+ );+ }+ return match;+}++function nullableString(raw: unknown): string | null {+ return typeof raw === 'string' ? raw : null;+}++function toStep(raw: unknown, sshHost: string): HostSetupStep {+ if (typeof raw !== 'object' || raw === null) {+ throw new Error(`Malformed setup step in the persisted plan for host ${sshHost}`);+ }+ const value = raw as Record<string, unknown>;+ if (typeof value.id !== 'string') {+ throw new Error(`Setup step without an id in the persisted plan for host ${sshHost}`);+ }+ return {+ id: value.id,+ kind: oneOf(STEP_KINDS, value.kind, 'step kind', sshHost),+ name: typeof value.name === 'string' ? value.name : value.id,+ state: oneOf(STEP_STATES, value.state, 'step state', sshHost),+ outcome: value.outcome == null ? null : oneOf(OUTCOMES, value.outcome, 'outcome', sshHost),+ version: nullableString(value.version),+ error: nullableString(value.error),+ output: nullableString(value.output),+ optional: value.optional === true,+ dependsOn: Array.isArray(value.dependsOn)+ ? value.dependsOn.filter((id): id is string => typeof id === 'string')+ : [],+ updatedAt:+ typeof value.updatedAt === 'string' ? value.updatedAt : new Date(0).toISOString(),+ };+}++function toPlan(row: RemoteHostSetupPlanRow): HostSetupPlan {+ let parsed: unknown;+ try {+ parsed = JSON.parse(row.steps);+ } catch (error) {+ throw new Error(+ `Could not parse the persisted setup plan for host ${row.sshHost}: ${+ error instanceof Error ? error.message : String(error)+ }`+ );+ }+ if (!Array.isArray(parsed)) {+ throw new Error(`Persisted setup plan for host ${row.sshHost} is not a list of steps`);+ }++ return {+ sshHost: row.sshHost,+ status: oneOf(PLAN_STATUSES, row.status, 'plan status', row.sshHost),+ steps: parsed.map((step) => toStep(step, row.sshHost)),+ currentStepId: row.currentStepId,+ createdAt: row.createdAt,+ updatedAt: row.updatedAt,+ };+}++export async function getSetupPlan(sshHost: string): Promise<HostSetupPlan | null> {+ const [row] = await db+ .select()+ .from(remoteHostSetupPlans)+ .where(eq(remoteHostSetupPlans.sshHost, sshHost))+ .limit(1);+ return row ? toPlan(row) : null;+}++export async function listSetupPlans(): Promise<HostSetupPlan[]> {+ const rows = await db.select().from(remoteHostSetupPlans);+ return rows.map(toPlan);+}++export async function saveSetupPlan(plan: HostSetupPlan): Promise<void> {+ const values = {+ sshHost: plan.sshHost,+ status: plan.status,+ steps: JSON.stringify(plan.steps),+ currentStepId: plan.currentStepId,+ createdAt: plan.createdAt,+ updatedAt: plan.updatedAt,+ };+ await db+ .insert(remoteHostSetupPlans)+ .values(values)+ .onConflictDoUpdate({+ target: remoteHostSetupPlans.sshHost,+ set: {+ status: values.status,+ steps: values.steps,+ currentStepId: values.currentStepId,+ updatedAt: values.updatedAt,+ },+ });+}++export async function deleteSetupPlan(sshHost: string): Promise<void> {+ await db.delete(remoteHostSetupPlans).where(eq(remoteHostSetupPlans.sshHost, sshHost));+}diff --git a/dash/apps/switchdash-desktop/src/main/db/schema.ts b/dash/apps/switchdash-desktop/src/main/db/schema.tsindex 1d6f697e9..0cd0f4dcb 100644--- a/dash/apps/switchdash-desktop/src/main/db/schema.ts+++ b/dash/apps/switchdash-desktop/src/main/db/schema.ts@@ -222,6 +222,37 @@ export const remoteHostReachability = sqliteTable('remote_host_reachability', {.default(sql`CURRENT_TIMESTAMP`),});+/**+ * A remote host's setup run (CHOO-1809). Onboarding is a sequence — check and+ * install each prerequisite in turn — and a sequence that cannot be resumed is+ * a sequence that strands the host the first time step 3 fails. Persisting the+ * plan is what makes "continue where you left off" possible across an app+ * restart, and what lets the host list say *why* a host is not ready without+ * re-probing it.+ *+ * `steps` is the JSON-serialised HostSetupStep[]. It is stored as one document+ * rather than a child table because it is only ever read and written whole, and+ * its shape is owned by the shared setup model rather than by SQL. It is+ * validated on read — a row we cannot parse raises instead of silently+ * degrading to "no plan", which would read as "nothing left to do".+ */+export const remoteHostSetupPlans = sqliteTable('remote_host_setup_plans', {+ /** The `~/.ssh/config` Host alias. One plan per host. */+ sshHost: text('ssh_host').primaryKey(),+ /** One of HostSetupPlanStatus — 'idle' | 'running' | 'halted' | 'complete'. */+ status: text('status').notNull().default('idle'),+ /** JSON-encoded HostSetupStep[]. */+ steps: text('steps').notNull(),+ /** The step in flight, or the one that halted the run. */+ currentStepId: text('current_step_id'),+ createdAt: text('created_at')+ .notNull()+ .default(sql`CURRENT_TIMESTAMP`),+ updatedAt: text('updated_at')+ .notNull()+ .default(sql`CURRENT_TIMESTAMP`),+});+export const sessions = sqliteTable('sessions',{@@ -346,3 +377,5 @@ export type RemoteHostRow = typeof remoteHosts.$inferSelect;export type RemoteHostInsert = typeof remoteHosts.$inferInsert;export type RemoteHostReachabilityRow = typeof remoteHostReachability.$inferSelect;export type RemoteHostReachabilityInsert = typeof remoteHostReachability.$inferInsert;+export type RemoteHostSetupPlanRow = typeof remoteHostSetupPlans.$inferSelect;+export type RemoteHostSetupPlanInsert = typeof remoteHostSetupPlans.$inferInsert;diff --git a/dash/apps/switchdash-desktop/src/main/db/tests/migrations/0045-remote-host-setup-plans.test.ts b/dash/apps/switchdash-desktop/src/main/db/tests/migrations/0045-remote-host-setup-plans.test.tsnew file mode 100644index 000000000..2775cf45b--- /dev/null+++ b/dash/apps/switchdash-desktop/src/main/db/tests/migrations/0045-remote-host-setup-plans.test.ts@@ -0,0 +1,96 @@+/**+ * Migration 0045 — adds the `remote_host_setup_plans` table (CHOO-1809), which+ * persists a remote host's onboarding run so it can be resumed after a restart.+ * Applies all migrations on a fresh schema and asserts the table exists and+ * round-trips a plan, including a halted one with its failure detail intact —+ * the case the table exists for.+ */++import { openFixture } from '@tooling/utils/db';+import { eq } from 'drizzle-orm';+import { afterEach, describe, expect, it } from 'vitest';+import { remoteHostSetupPlans } from '@main/db/schema';++describe('migration 0045: remote host setup plans', () => {+ let fixture: Awaited<ReturnType<typeof openFixture>>;++ afterEach(() => {+ fixture?.close();+ });++ it('creates the remote_host_setup_plans table with the expected columns', async () => {+ fixture = await openFixture('empty');++ const columns = fixture.sqlite+ .prepare(`PRAGMA table_info('remote_host_setup_plans')`)+ .all() as { name: string }[];+ const columnNames = columns.map((c) => c.name);++ expect(columnNames).toContain('ssh_host');+ expect(columnNames).toContain('status');+ expect(columnNames).toContain('steps');+ expect(columnNames).toContain('current_step_id');+ expect(columnNames).toContain('created_at');+ expect(columnNames).toContain('updated_at');+ });++ it('defaults a new plan to idle', async () => {+ fixture = await openFixture('empty');++ await fixture.db+ .insert(remoteHostSetupPlans)+ .values({ sshHost: 'dev-vm', steps: '[]' });++ const [row] = await fixture.db+ .select()+ .from(remoteHostSetupPlans)+ .where(eq(remoteHostSetupPlans.sshHost, 'dev-vm'));++ expect(row!.status).toBe('idle');+ expect(row!.currentStepId).toBeNull();+ });++ it('round-trips a halted plan with its failure detail', async () => {+ fixture = await openFixture('empty');+ const steps = JSON.stringify([+ { id: 'git', kind: 'core-dependency', state: 'satisfied', outcome: 'satisfied' },+ {+ id: 'node',+ kind: 'core-dependency',+ state: 'failed',+ outcome: 'missing',+ error: 'apt-get failed',+ output: 'E: Unable to locate package',+ },+ { id: 'tmux', kind: 'core-dependency', state: 'blocked', outcome: null },+ ]);++ await fixture.db.insert(remoteHostSetupPlans).values({+ sshHost: 'dev-vm',+ status: 'halted',+ steps,+ currentStepId: 'node',+ });++ const [row] = await fixture.db+ .select()+ .from(remoteHostSetupPlans)+ .where(eq(remoteHostSetupPlans.sshHost, 'dev-vm'));++ expect(row!.status).toBe('halted');+ expect(row!.currentStepId).toBe('node');+ const parsed = JSON.parse(row!.steps) as { id: string; state: string; output?: string }[];+ expect(parsed.map((s) => s.state)).toEqual(['satisfied', 'failed', 'blocked']);+ expect(parsed[1]!.output).toBe('E: Unable to locate package');+ });++ it('keeps one plan per host', async () => {+ fixture = await openFixture('empty');++ await fixture.db.insert(remoteHostSetupPlans).values({ sshHost: 'dev-vm', steps: '[]' });++ await expect(+ fixture.db.insert(remoteHostSetupPlans).values({ sshHost: 'dev-vm', steps: '[]' })+ ).rejects.toThrow();+ });+});