Files
kandev/apps/backend/internal/agent/runtime/lifecycle/env_preparer_ssh.go
T
José Almeida 99404133d4 feat(backend): add SSH executor runtime
Run agents on any Linux box reachable over SSH: own VPS, homelab, EC2,
shared dev box. One SSH connection per (host, user, identity) shared
across all sessions on that host; each session gets its own remote
agentctl process, remote port, and SSH-tunneled local port. Mirrors the
local ~/.kandev/tasks/<task-dir>/<repo>/ layout on the remote so
multi-session tasks share a worktree and per-session runtime state lives
under the task dir.

Implements ExecutorBackend + RemoteSessionResumer + RemoteStatusProvider
+ Closeable. Host-key trust is explicit: the test endpoint observes a
fingerprint without pinning; the user trusts it in settings; subsequent
connects reject any mismatch. Auth via ssh-agent or IdentityFile only
(passphrase-protected keys must be loaded into ssh-agent). Parses
~/.ssh/config for HostName/Port/User/IdentityFile/ProxyJump inheritance.
agentctl is content-hash-cached on the remote (~/.kandev/bin/agentctl
plus a .sha256 sidecar) and uploaded only when local and remote differ.
Linux/amd64 only in v1, matching Docker's current state; arm64 is
called out as a cross-cutting follow-up.

See docs/specs/ssh-executor/spec.md.
2026-05-17 23:28:50 +01:00

51 lines
1.7 KiB
Go

package lifecycle
import (
"context"
"time"
"go.uber.org/zap"
"github.com/kandev/kandev/internal/common/logger"
)
// SSHPreparer validates prerequisites for SSH-based execution. The heavy
// lifting (connect, agentctl upload, task dir provisioning, agentctl launch)
// happens in SSHExecutor.CreateInstance — this preparer just emits a single
// validation step so the launch UI has consistent progress feedback.
type SSHPreparer struct {
logger *logger.Logger
}
// NewSSHPreparer creates a new SSHPreparer.
func NewSSHPreparer(log *logger.Logger) *SSHPreparer {
return &SSHPreparer{logger: log.WithFields(zap.String("component", "ssh-preparer"))}
}
// Name implements EnvironmentPreparer.
func (p *SSHPreparer) Name() string { return "ssh" }
// Prepare implements EnvironmentPreparer. SSH executor configuration is
// validated at launch time (target / fingerprint / arch are checked inside
// CreateInstance). This step is intentionally minimal so the UI still sees
// the preparer running for every launch — preserves a uniform progress shape
// across executor types.
func (p *SSHPreparer) Prepare(_ context.Context, req *EnvPrepareRequest, onProgress PrepareProgressCallback) (*EnvPrepareResult, error) {
p.logger.Debug("preparing ssh environment",
zap.String("task", req.TaskID),
zap.String("session", req.SessionID))
started := time.Now()
step := beginStep("Validate SSH executor configuration")
reportProgress(onProgress, step, 0, 1)
completeStepSuccess(&step)
reportProgress(onProgress, step, 0, 1)
return &EnvPrepareResult{
Success: true,
Steps: []PrepareStep{step},
WorkspacePath: req.WorkspacePath,
Duration: time.Since(started),
WorktreeBranch: nonWorktreeTaskBranch(req),
}, nil
}