Go to file
Hongming Wang db6b196631 feat(connect): M1.2 — heartbeat + activity poll loops
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>
2026-04-30 03:15:51 -07:00
.claude docs: add CLAUDE.md, known-issues.md, and .claude/settings.json (#2) 2026-04-20 23:10:40 +00:00
.github/workflows fix(ci): sync auto-promote workflow (ff-only, no-gates mode) 2026-04-24 08:35:20 -07:00
bin fix(cli): align rootCmd.Use to goreleaser binary name 2026-04-22 05:36:07 +00:00
cmd/molecule feat(cli): add --force flag to molecule init 2026-04-23 21:17:36 +00:00
internal feat(connect): M1.2 — heartbeat + activity poll loops 2026-04-30 03:15:51 -07:00
.gitignore chore: gitignore credentials for molecule-cli 2026-04-16 09:18:55 -07:00
.goreleaser.yaml chore(cli): add .goreleaser.yaml and resolve KI-004 2026-04-21 10:33:08 +00:00
CLAUDE.md feat: implement full CLI command tree 2026-04-23 18:44:24 +00:00
go.mod feat(connect): M1.1 — Backend interface + connect skeleton + mock backend 2026-04-30 02:05:12 -07:00
go.sum feat: implement full CLI command tree 2026-04-21 01:18:24 +00:00
known-issues.md feat: implement full CLI command tree 2026-04-23 18:44:24 +00:00
pr-description-draft-cli-full.md fix(cli): align rootCmd.Use to goreleaser binary name 2026-04-22 05:36:07 +00:00
README.md feat: initial CLI (extracted from molecule-monorepo/platform/cmd/cli) 2026-04-16 03:15:58 -07:00

molecule-cli (molecli)

Go TUI dashboard for Molecule AI — real-time workspace monitoring, event log, health overview, delete/filter operations.

Install

go install github.com/Molecule-AI/molecule-cli/cmd/molecli@latest

Or download a binary from Releases.

Usage

export MOLECLI_URL=http://localhost:8080  # or your platform URL
molecli

Features

  • Real-time workspace status (online/offline/degraded/paused)
  • Event log with filtering
  • Workspace CRUD operations
  • Agent session management
  • Memory/skill inspection
  • A2A chat interface

License

Business Source License 1.1 — © Molecule AI.