Add Docker Compose Lingma bootstrap support

Package the proxy for Docker Compose deployments and add Lingma bootstrap, session restore, and runtime status support for containerized remote usage.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
GitHub Actions
2026-05-07 23:56:05 +08:00
parent 86fbdbc40c
commit a4cedecca6
10 changed files with 1067 additions and 68 deletions

View File

@@ -22,24 +22,36 @@ import (
)
type fileConfig struct {
Host string `json:"host"`
Port int `json:"port"`
Backend string `json:"backend"`
Transport string `json:"transport"`
Pipe string `json:"pipe"`
WebSocketURL string `json:"websocket_url"`
RemoteBaseURL string `json:"remote_base_url"`
RemoteAuthFile string `json:"remote_auth_file"`
RemoteVersion string `json:"remote_version"`
Cwd string `json:"cwd"`
CurrentFilePath string `json:"current_file_path"`
Mode string `json:"mode"`
Model string `json:"model"`
ShellType string `json:"shell_type"`
SessionMode string `json:"session_mode"`
TimeoutSeconds int `json:"timeout"`
RemoteFallbackEnabled *bool `json:"remote_fallback_enabled"`
RemoteFallbackModels []string `json:"remote_fallback_models"`
Host string `json:"host"`
Port int `json:"port"`
Backend string `json:"backend"`
Transport string `json:"transport"`
Pipe string `json:"pipe"`
WebSocketURL string `json:"websocket_url"`
RemoteBaseURL string `json:"remote_base_url"`
RemoteAuthFile string `json:"remote_auth_file"`
RemoteVersion string `json:"remote_version"`
Cwd string `json:"cwd"`
CurrentFilePath string `json:"current_file_path"`
Mode string `json:"mode"`
Model string `json:"model"`
ShellType string `json:"shell_type"`
SessionMode string `json:"session_mode"`
TimeoutSeconds int `json:"timeout"`
RemoteFallbackEnabled *bool `json:"remote_fallback_enabled"`
RemoteFallbackModels []string `json:"remote_fallback_models"`
LingmaBootstrapEnabled *bool `json:"lingma_bootstrap_enabled"`
LingmaSourceType string `json:"lingma_source_type"`
LingmaVSIXURL string `json:"lingma_vsix_url"`
LingmaMarketplacePublisher string `json:"lingma_marketplace_publisher"`
LingmaMarketplaceExtension string `json:"lingma_marketplace_extension"`
LingmaBootstrapOutputDir string `json:"lingma_bootstrap_output_dir"`
LingmaBinaryPath string `json:"lingma_binary_path"`
LingmaBootstrapAlways *bool `json:"lingma_bootstrap_always"`
LingmaForceRefresh *bool `json:"lingma_force_refresh"`
LingmaWorkDir string `json:"lingma_work_dir"`
LingmaSessionBundle string `json:"lingma_session_bundle"`
LingmaSessionBundleFile string `json:"lingma_session_bundle_file"`
}
func main() {
@@ -47,6 +59,9 @@ func main() {
addr := fmt.Sprintf("%s:%d", cfg.Host, cfg.Port)
svc := service.New(cfg)
if err := svc.PrepareRuntime(); err != nil {
log.Fatalf("prepare runtime: %v", err)
}
warmupCtx, warmupCancel := context.WithTimeout(context.Background(), 10*time.Second)
if err := svc.Warmup(warmupCtx); err != nil {
log.Printf("warmup failed: %v", err)
@@ -91,18 +106,22 @@ func main() {
func loadConfig() (service.Config, string) {
cfg := service.Config{
Host: "127.0.0.1",
Port: 8095,
Backend: service.BackendRemote,
Transport: lingmaipc.TransportAuto,
Cwd: currentDir(),
Mode: "agent",
Model: "kmodel",
ShellType: defaultShellType(),
SessionMode: service.SessionModeAuto,
Timeout: 0,
RemoteFallbackEnabled: true,
RemoteFallbackModels: service.DefaultRemoteFallbackModels(),
Host: "127.0.0.1",
Port: 8095,
Backend: service.BackendRemote,
Transport: lingmaipc.TransportAuto,
Cwd: currentDir(),
Mode: "agent",
Model: "kmodel",
ShellType: defaultShellType(),
SessionMode: service.SessionModeAuto,
Timeout: 0,
RemoteFallbackEnabled: true,
RemoteFallbackModels: service.DefaultRemoteFallbackModels(),
LingmaBootstrapEnabled: false,
LingmaSourceType: "marketplace",
LingmaBootstrapAlways: true,
LingmaForceRefresh: false,
}
configPath, configLoaded := resolveConfigPath()
@@ -134,6 +153,18 @@ func loadConfig() (service.Config, string) {
remoteFallbackEnabled := flag.Bool("remote-fallback", cfg.RemoteFallbackEnabled, "Enable remote timeout/5xx fallback to the next available model")
remoteFallbackModels := flag.String("remote-fallback-models", strings.Join(cfg.RemoteFallbackModels, ","), "Comma-separated remote fallback model IDs")
sessionMode := flag.String("session-mode", string(cfg.SessionMode), "Session mode: auto, fresh, reuse")
lingmaBootstrap := flag.Bool("lingma-bootstrap", cfg.LingmaBootstrapEnabled, "Download/extract Lingma runtime assets before startup")
lingmaSourceType := flag.String("lingma-source-type", cfg.LingmaSourceType, "Lingma bootstrap source: marketplace or vsix")
lingmaVSIXURL := flag.String("lingma-vsix-url", cfg.LingmaVSIXURL, "Lingma VSIX URL used when bootstrap source is vsix or marketplace fallback")
lingmaMarketplacePublisher := flag.String("lingma-marketplace-publisher", cfg.LingmaMarketplacePublisher, "VS Code marketplace publisher for Lingma bootstrap")
lingmaMarketplaceExtension := flag.String("lingma-marketplace-extension", cfg.LingmaMarketplaceExtension, "VS Code marketplace extension name for Lingma bootstrap")
lingmaBootstrapOutputDir := flag.String("lingma-bootstrap-output-dir", cfg.LingmaBootstrapOutputDir, "Lingma bootstrap release output directory")
lingmaBinaryPath := flag.String("lingma-binary-path", cfg.LingmaBinaryPath, "Lingma binary output path")
lingmaBootstrapAlways := flag.Bool("lingma-bootstrap-always", cfg.LingmaBootstrapAlways, "Re-check bootstrap source at startup")
lingmaForceRefresh := flag.Bool("lingma-force-refresh", cfg.LingmaForceRefresh, "Force refresh Lingma bootstrap assets")
lingmaWorkDir := flag.String("lingma-work-dir", cfg.LingmaWorkDir, "Lingma work/cache directory used for restored session bundles")
lingmaSessionBundle := flag.String("lingma-session-bundle", cfg.LingmaSessionBundle, "Base64 tar.gz Lingma session bundle to restore before startup")
lingmaSessionBundleFile := flag.String("lingma-session-bundle-file", cfg.LingmaSessionBundleFile, "File containing a base64 tar.gz Lingma session bundle")
config := flag.String("config", valueOr(configPath, filepath.Join(currentDir(), "lingma-proxy.json")), "Path to JSON config file")
flag.Parse()
@@ -159,6 +190,18 @@ func loadConfig() (service.Config, string) {
cfg.Timeout = time.Duration(*timeoutSeconds) * time.Second
cfg.RemoteFallbackEnabled = *remoteFallbackEnabled
cfg.RemoteFallbackModels = splitCSV(*remoteFallbackModels)
cfg.LingmaBootstrapEnabled = *lingmaBootstrap
cfg.LingmaSourceType = strings.TrimSpace(*lingmaSourceType)
cfg.LingmaVSIXURL = strings.TrimSpace(*lingmaVSIXURL)
cfg.LingmaMarketplacePublisher = strings.TrimSpace(*lingmaMarketplacePublisher)
cfg.LingmaMarketplaceExtension = strings.TrimSpace(*lingmaMarketplaceExtension)
cfg.LingmaBootstrapOutputDir = strings.TrimSpace(*lingmaBootstrapOutputDir)
cfg.LingmaBinaryPath = strings.TrimSpace(*lingmaBinaryPath)
cfg.LingmaBootstrapAlways = *lingmaBootstrapAlways
cfg.LingmaForceRefresh = *lingmaForceRefresh
cfg.LingmaWorkDir = strings.TrimSpace(*lingmaWorkDir)
cfg.LingmaSessionBundle = strings.TrimSpace(*lingmaSessionBundle)
cfg.LingmaSessionBundleFile = strings.TrimSpace(*lingmaSessionBundleFile)
if configLoaded {
configPath = finalConfigPath
@@ -252,6 +295,42 @@ func overlayFileConfig(dst *service.Config, src fileConfig) {
if len(src.RemoteFallbackModels) > 0 {
dst.RemoteFallbackModels = cleanStringSlice(src.RemoteFallbackModels)
}
if src.LingmaBootstrapEnabled != nil {
dst.LingmaBootstrapEnabled = *src.LingmaBootstrapEnabled
}
if strings.TrimSpace(src.LingmaSourceType) != "" {
dst.LingmaSourceType = strings.TrimSpace(src.LingmaSourceType)
}
if strings.TrimSpace(src.LingmaVSIXURL) != "" {
dst.LingmaVSIXURL = strings.TrimSpace(src.LingmaVSIXURL)
}
if strings.TrimSpace(src.LingmaMarketplacePublisher) != "" {
dst.LingmaMarketplacePublisher = strings.TrimSpace(src.LingmaMarketplacePublisher)
}
if strings.TrimSpace(src.LingmaMarketplaceExtension) != "" {
dst.LingmaMarketplaceExtension = strings.TrimSpace(src.LingmaMarketplaceExtension)
}
if strings.TrimSpace(src.LingmaBootstrapOutputDir) != "" {
dst.LingmaBootstrapOutputDir = strings.TrimSpace(src.LingmaBootstrapOutputDir)
}
if strings.TrimSpace(src.LingmaBinaryPath) != "" {
dst.LingmaBinaryPath = strings.TrimSpace(src.LingmaBinaryPath)
}
if src.LingmaBootstrapAlways != nil {
dst.LingmaBootstrapAlways = *src.LingmaBootstrapAlways
}
if src.LingmaForceRefresh != nil {
dst.LingmaForceRefresh = *src.LingmaForceRefresh
}
if strings.TrimSpace(src.LingmaWorkDir) != "" {
dst.LingmaWorkDir = strings.TrimSpace(src.LingmaWorkDir)
}
if strings.TrimSpace(src.LingmaSessionBundle) != "" {
dst.LingmaSessionBundle = strings.TrimSpace(src.LingmaSessionBundle)
}
if strings.TrimSpace(src.LingmaSessionBundleFile) != "" {
dst.LingmaSessionBundleFile = strings.TrimSpace(src.LingmaSessionBundleFile)
}
}
func overlayEnvConfig(dst *service.Config) {
@@ -309,6 +388,42 @@ func overlayEnvConfig(dst *service.Config) {
if value := strings.TrimSpace(os.Getenv("LINGMA_REMOTE_FALLBACK_MODELS")); value != "" {
dst.RemoteFallbackModels = splitCSV(value)
}
if value, ok := envBool("LINGMA_BOOTSTRAP_ENABLED"); ok {
dst.LingmaBootstrapEnabled = value
}
if value := strings.TrimSpace(os.Getenv("LINGMA_SOURCE_TYPE")); value != "" {
dst.LingmaSourceType = value
}
if value := strings.TrimSpace(os.Getenv("LINGMA_VSIX_URL")); value != "" {
dst.LingmaVSIXURL = value
}
if value := strings.TrimSpace(os.Getenv("LINGMA_MARKETPLACE_PUBLISHER")); value != "" {
dst.LingmaMarketplacePublisher = value
}
if value := strings.TrimSpace(os.Getenv("LINGMA_MARKETPLACE_EXTENSION")); value != "" {
dst.LingmaMarketplaceExtension = value
}
if value := strings.TrimSpace(os.Getenv("LINGMA_BOOTSTRAP_OUTPUT_DIR")); value != "" {
dst.LingmaBootstrapOutputDir = value
}
if value := strings.TrimSpace(os.Getenv("LINGMA_BIN")); value != "" {
dst.LingmaBinaryPath = value
}
if value, ok := envBool("LINGMA_BOOTSTRAP_ALWAYS"); ok {
dst.LingmaBootstrapAlways = value
}
if value, ok := envBool("LINGMA_FORCE_REFRESH"); ok {
dst.LingmaForceRefresh = value
}
if value := strings.TrimSpace(os.Getenv("LINGMA_WORK_DIR")); value != "" {
dst.LingmaWorkDir = value
}
if value := strings.TrimSpace(os.Getenv("LINGMA_SESSION_BUNDLE")); value != "" {
dst.LingmaSessionBundle = value
}
if value := strings.TrimSpace(os.Getenv("LINGMA_SESSION_BUNDLE_FILE")); value != "" {
dst.LingmaSessionBundleFile = value
}
}
func parseSessionMode(value string) service.SessionMode {