Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: goenv build build-cli build-server build-amikalog build-akfs clean test test-unit test-integration test-contract test-e2e test-e2e-api test-expensive test-all coverage vet fmt fmtcheck lint shellcheck ci setup
.PHONY: goenv build build-cli build-server build-amikad build-amikalog build-akfs clean test test-unit test-integration test-contract test-e2e test-e2e-api test-expensive test-all coverage vet fmt fmtcheck lint shellcheck ci setup

GO_DIR = go
UNIT_PACKAGES = $$(go -C $(GO_DIR) list ./... | grep -Ev '/test/(integration|contract)($$|/)')
Expand All @@ -10,7 +10,7 @@ export GOTMPDIR := $(CURDIR)/.gotmp
goenv:
mkdir -p "$(GOCACHE)" "$(GOTMPDIR)"

build: build-cli build-server build-amikalog build-akfs
build: build-cli build-server build-amikad build-amikalog build-akfs

build-cli: goenv
mkdir -p dist
Expand All @@ -20,6 +20,10 @@ build-server: goenv
mkdir -p dist
go -C $(GO_DIR) build -o $(CURDIR)/dist/amika-server ./cmd/amika-server

build-amikad: goenv
mkdir -p dist
go -C $(GO_DIR) build -o $(CURDIR)/dist/amikad ./cmd/amikad

build-amikalog: goenv
mkdir -p dist
go -C $(GO_DIR) build -o $(CURDIR)/dist/amikalog ./cmd/amikalog
Expand Down
35 changes: 35 additions & 0 deletions go/cmd/amika/plumbing.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"github.com/gofixpoint/amika/go/internal/runmode"
"github.com/gofixpoint/amika/go/internal/ssh"
"github.com/spf13/cobra"
)

var plumbingCmd = &cobra.Command{
Use: "plumbing",
Short: "Internal machine-facing commands",
Hidden: true,
}

var sshStdioProxyCmd = &cobra.Command{
Use: "ssh-stdio-proxy <host>",
Short: "Proxy standard IO to one SSH transport",
Hidden: true,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return ssh.ProxySession(
cmd.Context(),
runmode.NewRemoteClient(),
ssh.WebSocketDialer{},
args[0],
cmd.InOrStdin(),
cmd.OutOrStdout(),
)
},
}

func init() {
rootCmd.AddCommand(plumbingCmd)
plumbingCmd.AddCommand(sshStdioProxyCmd)
}
2 changes: 2 additions & 0 deletions go/cmd/amika/sandbox/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func New() *cobra.Command {
sandboxCmd.AddCommand(sandboxListCmd)
sandboxCmd.AddCommand(sandboxConnectCmd)
sandboxCmd.AddCommand(sandboxSSHCmd)
sandboxCmd.AddCommand(sandboxSSHV2Cmd)
sandboxCmd.AddCommand(sandboxCodeCmd)
sandboxCmd.AddCommand(sandboxAgentSendCmd)

Expand Down Expand Up @@ -65,6 +66,7 @@ func New() *cobra.Command {
sandboxSSHCmd.Flags().BoolP("t", "t", false, "Force pseudo-terminal allocation (like ssh -t)")
sandboxSSHCmd.Flags().Bool("revoke", false, "Revoke SSH access for the sandbox")
sandboxSSHCmd.Flags().Bool("print", false, "Print the SSH connection string instead of connecting")
sandboxSSHV2Cmd.Flags().BoolP("t", "t", false, "Force pseudo-terminal allocation (like ssh -t)")
sandboxCodeCmd.Flags().String("editor", "cursor", "Editor or agent to open: \"cursor\", \"claude\", or \"codex\"")
sandboxCodeCmd.Flags().String("path", "", "Override the remote path to open (absolute, or relative to the sandbox workspace root)")
sandboxAgentSendCmd.Flags().Bool("no-wait", false, "Send the instruction and return immediately without waiting for a response")
Expand Down
85 changes: 85 additions & 0 deletions go/cmd/amika/sandbox/sandbox_ssh_v2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package sandboxcmd

import (
"fmt"
"os"

"github.com/gofixpoint/amika/go/internal/basedir"
"github.com/gofixpoint/amika/go/internal/output"
"github.com/gofixpoint/amika/go/internal/runmode"
"github.com/gofixpoint/amika/go/internal/ssh"
"github.com/spf13/cobra"
)

var sandboxSSHV2Cmd = &cobra.Command{
Use: "sshv2 [flags] <name> [-- <command>...]",
Short: "SSH through the beta direct WebSocket transport",
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if runmode.Resolve(cmd) == runmode.Local {
return fmt.Errorf("direct WebSocket SSH requires a remote sandbox")
}
if err := runmode.RequireAuth(runmode.Remote, runmode.DefaultAuthChecker); err != nil {
return err
}
if err := output.RejectFlag(cmd); err != nil {
return err
}
target, err := getRemoteTarget(cmd)
if err != nil {
return err
}
client, err := getRemoteClient(target)
if err != nil {
return err
}
sandbox, err := client.GetSandbox(args[0])
if err != nil {
return err
}
alias, err := ssh.BuildSessionAlias(sandbox.Name, sandbox.ID)
if err != nil {
return err
}
paths := basedir.New("")
state, err := ssh.LoadState(paths)
if err != nil {
return err
}
var sessionConfig ssh.SessionConfig
if state.SessionConfig != nil {
sessionConfig = *state.SessionConfig
} else {
identityFile, err := paths.SSHIdentityFile()
if err != nil {
return err
}
knownHostsFile, err := paths.SSHKnownHostsFile()
if err != nil {
return err
}
sessionConfig = ssh.SessionConfig{
IdentityFile: identityFile,
KnownHostsFile: knownHostsFile,
ProxyCommand: "amika plumbing ssh-stdio-proxy %h",
}
}
identityInfo, err := os.Stat(sessionConfig.IdentityFile)
if err != nil || !identityInfo.Mode().IsRegular() || identityInfo.Mode().Perm()&0o077 != 0 {
return fmt.Errorf("SSH identity is missing or unsafe; run \"amika secret ssh-keygen\"")
}
if err := ssh.ConfigureSession(paths, sessionConfig); err != nil {
return err
}
if _, err := ssh.PrepareSessionHost(
client,
ssh.FileHostKeyPinStore{Path: sessionConfig.KnownHostsFile},
sandbox.ID,
alias,
); err != nil {
return err
}
forcePTY, _ := cmd.Flags().GetBool("t")
return ssh.ExecSessionSSH(alias, forcePTY, args[1:])
},
}
4 changes: 4 additions & 0 deletions go/cmd/amika/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -1011,12 +1011,16 @@ func init() {
rootCmd.AddCommand(secretCmd)
secretCmd.AddCommand(newSecretExtractCmd())
secretCmd.AddCommand(newSecretPushCmd())
secretCmd.AddCommand(newSSHKeygenCmd())
addProviderCommands(secretCmd, claudeProvider, false)
addProviderCommands(secretCmd, codexProvider, false)

rootCmd.AddCommand(secretsAliasCmd)
secretsAliasCmd.AddCommand(newSecretExtractCmd())
secretsAliasCmd.AddCommand(newSecretPushCmd())
sshKeygenAlias := newSSHKeygenCmd()
sshKeygenAlias.Hidden = true
secretsAliasCmd.AddCommand(sshKeygenAlias)
addProviderCommands(secretsAliasCmd, claudeProvider, true)
addProviderCommands(secretsAliasCmd, codexProvider, true)
}
74 changes: 74 additions & 0 deletions go/cmd/amika/ssh_keygen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package main

import (
"fmt"
"strings"

"github.com/gofixpoint/amika/go/internal/apiclient"
"github.com/gofixpoint/amika/go/internal/basedir"
"github.com/gofixpoint/amika/go/internal/output"
"github.com/gofixpoint/amika/go/internal/runmode"
"github.com/gofixpoint/amika/go/internal/ssh"
"github.com/spf13/cobra"
)

func newSSHKeygenCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "ssh-keygen",
Short: "Create or import a user-owned SSH key",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
if err := runmode.RequireAuth(runmode.Remote, runmode.DefaultAuthChecker); err != nil {
return err
}
format, err := output.FormatFrom(cmd)
if err != nil {
return err
}
name, _ := cmd.Flags().GetString("name")
if strings.TrimSpace(name) == "" {
return fmt.Errorf("--name must not be empty")
}
paths := basedir.New("")
identityPath, err := paths.SSHIdentityFile()
if err != nil {
return err
}
importPath, _ := cmd.Flags().GetString("import")
var publicKey string
if importPath == "" {
publicKey, err = ssh.GenerateIdentity(identityPath)
} else {
identityPath, publicKey, err = ssh.ImportIdentity(importPath)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Resolve imported identities to an absolute path

When --import is given a relative path such as id_ed25519.pub, ImportIdentity returns the matching relative private-key path, but the subsequent ConfigureSession call rejects it because RenderSessionConfig requires filepath.IsAbs. The documented import mode therefore fails for an otherwise valid keypair in the current directory; convert the imported path to an absolute path before persisting the session configuration.

Useful? React with 👍 / 👎.

}
if err != nil {
return err
}
knownHostsPath, err := paths.SSHKnownHostsFile()
if err != nil {
return err
}
if err := ssh.ConfigureSession(paths, ssh.SessionConfig{
IdentityFile: identityPath,
KnownHostsFile: knownHostsPath,
ProxyCommand: "amika plumbing ssh-stdio-proxy %h",
}); err != nil {
return err
}
summary, err := runmode.NewRemoteClient().CreateSSHPublicKey(
apiclient.CreateSSHPublicKeyRequest{Name: name, PublicKey: publicKey},
)
if err != nil {
return err
}
if format.IsJSON() {
return format.JSON(cmd.OutOrStdout(), summary)
}
fmt.Fprintf(cmd.OutOrStdout(), "SSH public key %q uploaded; private key remains at %s.\n", summary.Name, identityPath)
return nil
},
}
cmd.Flags().String("import", "", "Import an existing .pub file instead of generating a key")
cmd.Flags().String("name", "default", "Name for the uploaded public key")
return cmd
}
27 changes: 27 additions & 0 deletions go/cmd/amikad/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Package main runs the Amika sandbox daemon.
package main

import (
"context"
"errors"
"fmt"
"os"
"os/signal"
"syscall"

"github.com/gofixpoint/amika/go/internal/amikad"
)

func main() {
ctx, stop := signal.NotifyContext(
context.Background(),
os.Interrupt,
syscall.SIGTERM,
)
defer stop()
cmd := amikad.NewCommand(amikad.NewProductionOperations())
if err := cmd.ExecuteContext(ctx); err != nil && !errors.Is(err, context.Canceled) {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
5 changes: 4 additions & 1 deletion go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ go 1.25.3

require (
github.com/BurntSushi/toml v1.6.0
github.com/coder/websocket v1.8.15
github.com/danielgtaylor/huma/v2 v2.37.2
github.com/santhosh-tekuri/jsonschema/v6 v6.0.2
github.com/spf13/cobra v1.10.2
github.com/spf13/pflag v1.0.10
golang.org/x/crypto v0.53.0
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
golang.org/x/text v0.34.0 // indirect
golang.org/x/sys v0.46.0 // indirect
golang.org/x/text v0.38.0 // indirect
)
12 changes: 10 additions & 2 deletions go/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/BurntSushi/toml v1.6.0 h1:dRaEfpa2VI55EwlIW72hMRHdWouJeRF7TPYhI+AUQjk=
github.com/BurntSushi/toml v1.6.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/coder/websocket v1.8.15 h1:6B2JPeOGlpff2Uz6vOEH1Vzpi0iUz20A+lPVhPHtNUA=
github.com/coder/websocket v1.8.15/go.mod h1:NX3SzP+inril6yawo5CQXx8+fk145lPDC6pumgx0mVg=
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/danielgtaylor/huma/v2 v2.37.2 h1:Nf9vjy2sxBJFaupPlthXL/Hy2+LurfVbaKHmCMEI7xE=
github.com/danielgtaylor/huma/v2 v2.37.2/go.mod h1:95S04G/lExFRYlBkKaBaZm9lVmxRmqX9f2CgoOZ11AM=
Expand Down Expand Up @@ -28,8 +30,14 @@ github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk=
golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA=
golang.org/x/crypto v0.53.0 h1:QZ4Muo8THX6CizN2vPPd5fBGHyogrdK9fG4wLPFUsto=
golang.org/x/crypto v0.53.0/go.mod h1:DNLU434OwVakk9PzuwV8w62mAJpRJL3vsgcfp4Qnsio=
golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw=
golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/term v0.44.0 h1:0rLvDRCtNj0gZkyIXhCyOb2OAzEhLVqc4B+hrsBhrmc=
golang.org/x/term v0.44.0/go.mod h1:7ze4MdzUzLXpSAoFP1H0bOI9aXDqveSvatT5vKcFh2Y=
golang.org/x/text v0.38.0 h1:sXmwo9DwP3OK9EZ7PqAdaooSGozfl/3a6/xJcbzPRhE=
golang.org/x/text v0.38.0/go.mod h1:YXZt3QhHUKYT53r2lLKFIVi6Ao1jdzrTR/KQ09qyxF4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
12 changes: 12 additions & 0 deletions go/internal/amikad/background_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build !windows

package amikad

import (
"os/exec"
"syscall"
)

func configureBackgroundProcess(command *exec.Cmd) {
command.SysProcAttr = &syscall.SysProcAttr{Setsid: true}
}
7 changes: 7 additions & 0 deletions go/internal/amikad/background_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build windows

package amikad

import "os/exec"

func configureBackgroundProcess(_ *exec.Cmd) {}
Loading