molecule-cli/internal/backends/claudecode/claudecode.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

62 lines
2.1 KiB
Go

// Package claudecode implements the `claude-code` backend: a thin
// shorthand for `exec` with `cmd="claude -p"`. Each inbound A2A
// message is dispatched to a fresh `claude --print` invocation; the
// model's stdout becomes the reply.
//
// Why a separate backend instead of telling users `--backend exec
// --backend-opt cmd="claude -p"`?
//
// - The default backend is "claude-code" — copy-paste-from-canvas
// should Just Work without the operator memorising flag spelling.
// - Future versions can add Claude-Code-specific config: model
// selection, system prompt, MCP forwarding. The exec backend
// stays generic.
//
// Config keys (all optional):
//
// - bin — claude binary path. Default "claude".
// - args — extra args appended after `-p`. Default "".
// - timeout — per-message timeout. Default "5m" (Claude Code
// responses can take a while; longer than exec's 60s default).
// - pass_meta — see exec backend. Default "true" — Claude Code
// sessions benefit from knowing who sent the message.
//
// Implementation: builds the equivalent exec config under the hood.
// Reusing exec means timeout/stdin/stderr/env handling stays in one
// place; bug fixes flow to both.
package claudecode
import (
"strings"
"go.moleculesai.app/cli/internal/backends"
exec "go.moleculesai.app/cli/internal/backends/exec"
)
func init() {
backends.Register("claude-code", New)
}
// New builds a claude-code backend from cfg. Translates the
// claude-code keys to an exec backend config and delegates.
func New(cfg backends.Config) (backends.Backend, error) {
bin := cfg.Get("bin", "claude")
extra := cfg.Get("args", "")
timeout := cfg.Get("timeout", "5m")
passMeta := cfg.Get("pass_meta", "true")
// Build the underlying shell command. -p (print mode) is the
// non-interactive Claude Code mode that reads stdin and writes
// stdout once.
cmd := bin + " -p"
if strings.TrimSpace(extra) != "" {
cmd += " " + extra
}
return exec.New(backends.Config{
"cmd": cmd,
"timeout": timeout,
"pass_meta": passMeta,
})
}