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>
After this PR `molecule connect <id>` actually does something useful:
the default `--backend claude-code` runs `claude -p` as a subprocess
per inbound message, capturing stdout as the reply. The general
`--backend exec --backend-opt cmd="..."` lets operators bridge to any
program that reads stdin and writes stdout (Ollama, custom Python,
shell pipelines).
What's in:
- `internal/backends/exec/exec.go` — generic exec backend.
- cmd (required): shell command, run via /bin/sh -c (or cmd /c).
- timeout (default 60s): per-message wall clock; subprocess is
killed on timeout and the dispatcher keeps the message queued.
- pass_meta (default false): when true, populates env with
MOLECULE_WORKSPACE_ID / CALLER_ID / MESSAGE_ID / TASK_ID / METHOD.
- Stdin = joined text parts; stdout = reply text.
- Stderr is captured + surfaced in error messages so operators can
see what their command printed.
- Honours ctx cancellation — SIGTERM kills the subprocess immediately.
- `internal/backends/claudecode/claudecode.go` — thin shorthand.
Translates {bin, args, timeout, pass_meta} into the equivalent exec
config. Defaults: bin=claude, timeout=5m, pass_meta=true.
Reusing exec means timeout/stdin/env handling stays in one place.
- `internal/cmd/connect.go` — registers both backends so `--help`
shows them and the default `--backend claude-code` works without
flag tuning.
Test plan:
- exec: cmd-required, bad-timeout, zero-timeout, echo-stdin-to-stdout,
text-only-part-concat, non-zero-exit-surfaces-stderr, timeout-kills-
runaway, pass_meta-injects-env, no-pass_meta-leaves-env-untouched,
parent-env-inherited-when-pass_meta-off, ctx-cancel-kills-command.
- claude-code: registered, bin/args translation produces "echo -p hello",
bad-timeout-surfaces, default-config-builds.
- All Unix tests gated on `requireUnix(t)` — Windows-shell semantics
diverge; cross-platform coverage is M3 work (brew/scoop/winget).
- Full suite green under -race.
UX after this PR:
# default — Claude Code on PATH
molecule connect ws_01HF... --token $T
# custom handler
molecule connect ws_01HF... --backend exec \
--backend-opt cmd="python myhandler.py"
# different model via Claude Code
molecule connect ws_01HF... \
--backend-opt args="--model claude-sonnet-4-6"
# CI smoke
molecule connect ws_01HF... --backend mock --backend-opt reply=ok
Out of scope (M1.4 + later):
- M1.4: GoReleaser tag-triggered release.yml workflow
- stdio backend (one persistent subprocess + line-delimited JSON-RPC)
— moved to M2 since exec covers the common case
- openai / mcp backends — M4 per RFC
RFC: https://github.com/Molecule-AI/molecule-cli/issues/10
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Implements the runtime side of `molecule connect <id>`. After this PR
the CLI can actually attach to an external workspace and round-trip
inter-agent messages through any registered backend.
What's in:
- `internal/connect/client.go` — platform-API client with bearer auth.
Endpoints: POST /registry/register (delivery_mode=poll, no URL),
POST /registry/heartbeat, GET /workspaces/:id/activity?type=a2a_receive,
POST /workspaces/:id/a2a (reply target).
Errors split into TransientError (network/5xx — retry with backoff)
and PermanentError (4xx — abort with clear message).
- `internal/connect/state.go` — atomic cursor persistence at
~/.config/molecule/state/<workspace-id>.json. Mode 0o600 (owner-only)
from day 1 because future state additions may include rotated tokens.
Atomic write-then-rename so a crash mid-write can never produce a
half-written cursor.
- `internal/connect/connect.go` — Run() orchestrator. Wires register-
with-bounded-retry, then heartbeat goroutine + poll goroutine.
Both respect ctx cancellation for clean SIGTERM.
Robustness contract per RFC #10:
* Cursor advances AFTER successful dispatch — crash mid-batch
re-delivers, never drops.
* 410 on cursor lookup → reset to "" and re-fetch (don't deadlock
on a pruned cursor).
* Heartbeat permanent error stops the heartbeat loop only; poll
loop keeps running so the operator sees "stopped" + reason in
logs and can SIGTERM.
* Backend dispatch is sequential within a batch (avoids out-of-
order replies for in-flight conversations).
* Inter-agent reply path: POST envelope to /workspaces/<source>/a2a.
* Canvas-origin reply (source_id == nil) logs + skips for now —
M1.3 wires that via the task_update activity convention.
- `internal/cmd/connect.go` — runConnect now actually calls
connect.Run() (was a placeholder ctx-wait in M1.1).
Test plan:
- httptest workspace-server stub covers register / heartbeat / activity
/ a2a reply endpoints.
- TestRun_RoundTrip_AgentReply: end-to-end ping → mock backend → pong
reply lands at source, cursor saved.
- TestRun_CanvasOriginMessageNotReplied: source_id=nil → backend fires
but no reply post; cursor still advances.
- TestRun_CursorPruned410ResetsAndContinues: server returns 410 once,
cursor resets to "", next poll dispatches the fresh row.
- TestRun_PermanentRegisterErrorAborts: 401 surfaces immediately.
- TestRun_TransientRegisterErrorRetries: 503 then 200 → register
succeeds on second attempt.
- TestRun_OptionsValidation: missing Backend / WorkspaceID surface
before any I/O.
- State: round-trip, file mode 0o600, atomic-rename leaves no .tmp
artifacts, corrupted file surfaces error.
- All tests green under -race.
Out of scope (next PRs in this stack):
- M1.3: claude-code backend (canvas-origin reply convention rides
with this)
- M1.4: GoReleaser tag-triggered release.yml workflow
- Push-mode (--mode push currently surfaces a clear "M4" error)
RFC: https://github.com/Molecule-AI/molecule-cli/issues/10
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
First step toward `molecule connect <id>` — the out-of-box external-
runtime workspace connector specified in RFC #10.
What's in this PR (foundational, ~300 LOC of code + matching tests):
- `internal/backends.Backend` — the seam every concrete handler
implements: HandleA2A(ctx, Request) → Response, Close(). Two methods,
no inheritance, no surprise side effects. Concurrency-safe by
contract (poll dispatch may parallelise).
- Request/Response/Part/Config types — lossless JSON-RPC mirror so
backends can re-issue downstream without re-parsing.
- Compile-time registry — `Register("name", factory)` from each
backend's init(); `Build(name, cfg)` selects at runtime. Panics
on duplicate registration so drift fails loudly at startup, not
on first message.
- `mock` backend — single-template echo for CI smoke + tests + demos.
`--backend-opt reply="<template>"` with `%s` for inbound text.
- `molecule connect <workspace-id>` cobra command — flag surface,
validation, --dry-run for smoke. Loops (heartbeat, activity poll,
dispatch) land in M1.2 in internal/connect/.
Coverage:
- Registry: duplicate-name panic, empty-name panic, nil-factory panic,
Build unknown-name error includes registered list.
- Mock: default template, custom template, text-part concatenation,
Final=true on terminal response.
- Connect: --backend-opt KEY=VALUE parser (incl. value with =),
flag validation (missing token, bad mode, bad opt, unknown
backend), --dry-run happy path.
All tests pass under -race.
Out of scope (subsequent M1 PRs):
- M1.2: heartbeat + activity poll loops in internal/connect/
- M1.3: claude-code backend (wraps molecule-mcp-claude-channel)
- M1.4: GoReleaser tag-triggered release.yml workflow
RFC: https://github.com/Molecule-AI/molecule-cli/issues/10
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The yaml-output-support refactor removed the combined json/yaml if-block
but left a dangling `}` that closed runPlatformHealth prematurely,
putting the tabwriter block outside the function body.
Removes the stray brace at line 137. CI vet was failing with:
platform.go:138:2: syntax error: non-declaration statement outside function body
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The `--output yaml` flag was accepted but aliased to JSON since
printYAML() was never defined. Add printYAML() using gopkg.in/yaml.v3
(already an indirect dep via viper) and split all output format
branches into explicit json/yaml/table paths.
Affected commands: workspace list/create/inspect/audit,
agent list/inspect/peers, platform audit/health.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Allows re-scaffolding an existing molecule.yaml without manual deletion.
Exit code 1 preserved for existing file without --force (usage error path).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Change rootCmd Use/Short/Long from 'mol' to 'molecule'
- Register initCmd in root so 'molecule init' works
- Update viper config name lookup from 'mol' to 'molecule'
- Fix config init/set to write molecule.yaml instead of mol.yaml
- Update all user-facing strings mol→molecule
Fixes TestCLI_Version, TestCLI_Init, TestCLI_ConfigInit, TestCLI_Completion_GeneratesScript
v.SafeWriteConfig() was called without a local viper instance.
Create a fresh viper scoped to the target config file, read any
existing values, set the new key, then atomically write via SafeWriteConfig.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
viper.Viper has no Marshal method in v1.21. Use SafeWriteConfig instead
which atomically writes only explicitly-set keys to the config file.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- workspace.go: remove no-op _ = workspaceID (workspaceID consumed in runHTTP call)
- molecule_test.go: replace hardcoded /workspace/repos/clone-cli path with
dynamic exe-based resolution so tests pass when built by CI
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Wires shell completion for all 4 shells via Cobra's built-in generators.
Covers the remaining item from the implementation status checklist.
Adds:
- internal/cmd/completion.go: cobra.GenXxxCompletion wrappers with
usage examples for each shell
- 5 new integration tests in cmd/molecule/molecule_test.go:
- TestCLI_Completion_Help (4 shells × help flag)
- TestCLI_Completion_GeneratesScript (4 shells × script output)
- TestCLI_Completion_InvalidShell (exit code 2 on bad shell)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
All test.Fatalf messages referenced "mol <subcommand>" but the binary
is now "molecule". Also fix configSet to use os.WriteFile atomic write
instead of viper.WriteConfig (avoids file-permission edge cases).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Rename all user-facing "mol" references to "molecule" to match the
published binary name (binary: molecule in .goreleaser.yaml):
- root.go: Use string, versionInfo, viper config name, flag descriptions
- init.go: section comment, Short, Long, cfgPath, scaffolded message
- config.go: Long description, Shorts, configFile, WriteFile, Stat check
- molecule_test.go: binary name, version output check, mol.yaml → molecule.yaml
Also fix test helper to use runtime.GOEXE instead of hardcoded /tmp/go/bin/go.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
rootCmd.Use was "mol" while .goreleaser.yaml sets binary: "molecule".
Align to "molecule" to match the published binary name, test
invocations, and docs. Also fix test helper to use runtime.GOEXE
instead of hardcoded /tmp/go/bin/go.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add `mol init` command (internal/cmd/init.go): scaffolds mol.yaml
in the current directory with commented config sections and
environment variable documentation. Exits with a clear "next steps"
message. Checks for existing mol.yaml before overwriting.
- Register initCmd in root.go alongside the other command groups.
- Add 2 integration tests: TestCLI_Init (scaffolding + output)
and TestCLI_Init_AlreadyExists (error path).
- Update CLAUDE.md command reference to list mol init and note it
is checked off the stub repo checklist.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>