molecule-cli/internal/cmd/init.go
claude-ceo-assistant 76f37d928f
All checks were successful
Release Go binaries / test (pull_request) Successful in 1m37s
Release Go binaries / release (pull_request) Has been skipped
fix(post-suspension): vanity import path go.moleculesai.app/cli (closes molecule-ai/internal#71 phase 2)
Migrates go.mod + 22 Go imports + README + comments + generated config
templates off the dead github.com/Molecule-AI/ identity onto the vanity
host go.moleculesai.app, owned by us.

Surfaces touched:
- go.mod module declaration: github.com/Molecule-AI/molecule-cli ->
  go.moleculesai.app/cli
- Every Go import statement under cmd/ + internal/
- README install section: rewritten to lead with the vanity install
  command (the previous text was migration-in-progress hedging)
- Comment URLs in internal/backends/backend.go + internal/cmd/connect.go
  (https://github.com/Molecule-AI/molecule-cli/issues/10) -> point at
  git.moleculesai.app/molecule-ai/molecule-cli
- Generated config templates in internal/cmd/init.go +
  internal/cmd/config.go: header URL updated so new users land on the
  live SCM
- Adds internal/lint/import_path_lint_test.go — structural test that
  walks every *.go / *.mod / Dockerfile / *.md / *.sh / *.yml in the
  module and rejects future references to github.com/Molecule-AI/ or
  Molecule-AI/molecule-monorepo. Mutation-tested before commit.

Test plan
- go build ./... clean
- go test ./... green (cmd/molecule + 5 internal packages + new lint
  gate, all pass)
- TestNoLegacyGitHubImportPaths fails on injected canary, passes on
  clean tree (no tautology)

Open dependency
- go.moleculesai.app responder must be deployed before
  'go install go.moleculesai.app/cli/cmd/molecule@latest' works
  externally. Internal builds + 'go build ./cmd/molecule' from a fresh
  clone work today (self-referential module path).
- Responder code prepared (worker.js, vendor-portable for CF Workers /
  Vercel Edge); deploy tracked separately under internal#71 phase 1.

Pairs with parallel migrations of plugin-gh-identity (#3) +
molecule-controlplane + molecule-core under the same internal#71 sweep.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 22:26:45 +00:00

104 lines
3.1 KiB
Go

package cmd
import (
"fmt"
"os"
"path/filepath"
"github.com/spf13/cobra"
)
// ---------------------------------------------------------------------------
// molecule init — bootstrap workspace setup
// ---------------------------------------------------------------------------
var (
initForce bool
)
var initCmd = &cobra.Command{
Use: "init",
Short: "Bootstrap workspace and scaffold a molecule.yaml config file",
Long: `Scaffold a default molecule.yaml in the current directory.
This is the primary entry point for new users. Run once in a project
to create a configuration file that can be checked into version control.
All values can be overridden by environment variables
(MOLECULE_API_URL, MOLECULE_RUNTIME_URL, etc.).
After init, run 'molecule --config molecule.yaml workspace list' to verify your setup.`,
RunE: runInit,
}
func init() {
initCmd.Flags().BoolVar(&initForce, "force", false, "Replace existing molecule.yaml")
}
func runInit(cmd *cobra.Command, _ []string) error {
cfgPath := "molecule.yaml"
if _, err := os.Stat(cfgPath); err == nil {
if initForce {
content := `# molecule CLI configuration — https://git.moleculesai.app/molecule-ai/molecule-cli
#
# All values can be overridden by environment variables:
# MOLECULE_API_URL, MOLECULE_RUNTIME_URL, MOL_OUTPUT, MOL_VERBOSE, etc.
#
# Environment variables always take precedence over this file.
# Platform API base URL (env: MOLECULE_API_URL)
# api_url: https://api.molecule.ai
# Workspace runtime URL for dev/proxy mode (env: MOLECULE_RUNTIME_URL)
# runtime_url: https://runtime.molecule.ai
# Output format: table | json | yaml (env: MOL_OUTPUT)
# output: table
# Verbose logging: true | false (env: MOL_VERBOSE)
# verbose: false
`
if err := os.WriteFile(cfgPath, []byte(content), 0o644); err != nil {
return fmt.Errorf("init: write %s: %w", cfgPath, err)
}
absPath, _ := filepath.Abs(cfgPath)
fmt.Printf("Replaced %s\n", absPath)
return nil
}
return fmt.Errorf("init: %s already exists — not overwriting (use --force to replace)", cfgPath)
}
content := `# molecule CLI configuration — https://git.moleculesai.app/molecule-ai/molecule-cli
#
# All values can be overridden by environment variables:
# MOLECULE_API_URL, MOLECULE_RUNTIME_URL, MOL_OUTPUT, MOL_VERBOSE, etc.
#
# Environment variables always take precedence over this file.
# Platform API base URL (env: MOLECULE_API_URL)
# api_url: https://api.molecule.ai
# Workspace runtime URL for dev/proxy mode (env: MOLECULE_RUNTIME_URL)
# runtime_url: https://runtime.molecule.ai
# Output format: table | json | yaml (env: MOL_OUTPUT)
# output: table
# Verbose logging: true | false (env: MOL_VERBOSE)
# verbose: false
`
if err := os.WriteFile(cfgPath, []byte(content), 0o644); err != nil {
return fmt.Errorf("init: write %s: %w", cfgPath, err)
}
absPath, _ := filepath.Abs(cfgPath)
fmt.Printf("Scaffolded %s\n", absPath)
fmt.Println()
fmt.Println("Next steps:")
fmt.Println(" 1. Edit molecule.yaml with your platform URL")
fmt.Println(" 2. Run molecule --config molecule.yaml workspace list")
fmt.Println(" 3. For full reference: molecule --help")
return nil
}