molecule-cli/internal/cmd/http.go
Molecule AI SDK-Dev 3eabe3c780 feat: implement full CLI command tree
Implement the core CLI for molecule-cli:

- cmd/molecule/main.go: entry point calling cmd.Execute()
- internal/cmd/root.go: cobra root with global flags (--api-url,
  --verbose, --output, --config), registers all 4 command groups
- internal/cmd/workspace.go: 7 subcommands (list, create, inspect,
  delete, restart, audit, delegate)
- internal/cmd/agent.go: 4 subcommands (list, inspect, send, peers)
- internal/cmd/platform.go: 2 subcommands (audit, health)
- internal/cmd/config.go: 5 subcommands (list, get, set, init, view)
- internal/cmd/http.go: runHTTP helper shared by agent send and
  workspace delegate
- internal/client/platform.go: control plane HTTP client with
  workspace/agent/health/audit operations

All 18 subcommands wire to platform API via MOLECULE_API_URL.
Binary builds to ./bin/mol. Resolves KI-001, KI-002 (partial),
KI-003.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-21 01:18:24 +00:00

34 lines
685 B
Go

package cmd
import (
"fmt"
"io"
"net/http"
"strings"
"time"
)
// runHTTP does a raw HTTP call.
func runHTTP(method, url string, body []byte) ([]byte, error) {
req, err := http.NewRequest(method, url, strings.NewReader(string(body)))
if err != nil {
return nil, err
}
if body != nil {
req.Header.Set("Content-Type", "application/json")
}
resp, err := httpClient().Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
b, _ := io.ReadAll(resp.Body)
if resp.StatusCode >= 400 {
return nil, fmt.Errorf("HTTP %d — %s", resp.StatusCode, string(b))
}
return b, nil
}
func httpClient() *http.Client {
return &http.Client{Timeout: 30 * time.Second}
}