Skip to content

refactor: restructure into Bun workspaces monorepo#18

Merged
TimBeyer merged 10 commits intomainfrom
refactor/monorepo-workspaces
Mar 15, 2026
Merged

refactor: restructure into Bun workspaces monorepo#18
TimBeyer merged 10 commits intomainfrom
refactor/monorepo-workspaces

Conversation

@TimBeyer
Copy link
Owner

@TimBeyer TimBeyer commented Mar 15, 2026

Summary

  • Restructure the single-package project into a Bun workspaces monorepo with four packages, creating clean boundaries before the VM CLI is added
  • @clawctl/types — shared types, schemas, constants, pure functions (zero I/O)
  • @clawctl/templates — pure script/config generators (string in → string out)
  • @clawctl/host-core — host-side VM management library (drivers, exec, provision, registry)
  • @clawctl/cli — CLI shell (commands, Ink wizard UI, entry points)
  • Strict DAG: typestemplateshost-corecli; no cycles
  • config.ts and secrets.ts split: pure functions → types, I/O → host-core
  • Root bin/clawctl-dev symlink preserved for ergonomic PATH setup

Motivation

The host CLI (macOS, limactl, execa) and future VM CLI (Ubuntu, local OpenClaw, systemd) share types and schemas but almost no runtime code. Horizontal slicing now prevents the VM CLI from pulling in host-specific dependencies.

Test plan

  • bun test — 280 tests pass, 0 fail
  • bun run lint — clean
  • bun build --compile — produces working binary
  • bun run build:release — release build works
  • bin/clawctl-dev --version — dev wrapper works via symlink
  • Manual: clawctl create --config <path> on a fresh run

🤖 Generated with Claude Code

TimBeyer and others added 10 commits March 15, 2026 14:55
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Create packages/{types,templates,host-core,cli}/ with package.json and
tsconfig.json files. Add workspaces field to root package.json. Extract
shared compiler options into tsconfig.base.json.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move pure types, schemas, constants, and functions into packages/types/:
- types.ts (all interfaces)
- schemas/ (zod validation schemas)
- constants.ts (UBUNTU_IMAGE_URL, PROJECT_MOUNT_POINT, GATEWAY_PORT)
- bin-name.ts, providers.ts (pure constants and functions)
- config.ts pure functions (validateConfig, configToVMConfig, sanitizeConfig)
- secrets.ts pure functions (findSecretRefs, hasOpRefs, resolveEnvRefs)

Original src/ files now re-export from @clawctl/types. I/O functions
(loadConfig, resolveOpRefs) remain in src/lib/ for now.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move all template generators into packages/templates/src/:
- lima-yaml, helpers, provision scripts
- installers/ (apt, nodejs, tailscale, homebrew, op-cli, etc.)
- skills/ (secret-management, op-wrapper)
- completions/ (bash, zsh)
- exec-approvals, bootstrap-prompt

Template imports updated to use @clawctl/types. Original src/templates/
barrel files now re-export from @clawctl/templates.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move all host-side VM management code into packages/host-core/src/:
- drivers/ (VMDriver interface, LimaDriver implementation)
- exec, provision, bootstrap, verify, prereqs, credentials
- secrets-sync, infra-secrets, registry, instance-context
- require-instance, git, homebrew, tailscale, parse, shell-quote, redact
- config (loadConfig I/O), secrets (resolveOpRefs I/O)
- headless orchestration
- VM integration tests

Imports updated to use @clawctl/types and @clawctl/templates.
Original src/ files now re-export from @clawctl/host-core.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move CLI code into packages/cli/:
- bin/ (cli.tsx entry point, clawctl-dev wrapper)
- src/commands/ (all command handlers)
- src/steps/ (wizard step React components)
- src/components/ (reusable UI components)
- src/hooks/ (React hooks)
- src/app.tsx (wizard app)

Remove old src/, bin/, tests/ directories (all code now in packages/).
Update CLAUDE.md key directories and command paths.
Update task status to Resolved.

Verified: 280 tests pass, lint clean, bun build --compile works,
clawctl-dev wrapper works, release build works.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Symlink bin/clawctl-dev → packages/cli/bin/clawctl-dev so the dev
entry point stays at the repo root. Users don't need to know about
the monorepo layout to set up their PATH.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move CLI-only types (PrereqStatus, CredentialConfig, WizardStep,
ProvisioningStep) to @clawctl/cli, BIN_NAME to @clawctl/host-core,
and business logic functions (configToVMConfig, sanitizeConfig,
buildOnboardCommand) to @clawctl/host-core. Keep formatZodError and
expandTilde as internal helpers in types (used by validateConfig).

@clawctl/types now exports only: types/interfaces, schemas, constants,
provider registry data, validateConfig, and secrets utilities.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move the Ubuntu image URL out of @clawctl/types and into the only file
that uses it (lima-yaml.ts), following the project convention of
colocating constants in the template that uses them.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@TimBeyer TimBeyer merged commit 769b94b into main Mar 15, 2026
4 checks passed
@TimBeyer TimBeyer deleted the refactor/monorepo-workspaces branch March 15, 2026 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant