Commit graph

4 commits

Author SHA1 Message Date
Rasmus Widing
68e7db0466
feat: Phase 5 - CLI binary distribution (#325)
* docs: Add Phase 5 CLI binary distribution plan

- Create detailed implementation plan for binary distribution
- Add Phase 5.0: Bundle defaults for binary (depends on #322)
- Add Phase 5.1-5.7: Build scripts, GitHub Actions, curl install,
  Homebrew formula, Windows docs, version command, release guide
- Update research doc with Phase 6 (auto-update command)
- Renumber dashboard to Phase 7, workflow builder to Phase 8
- Mark Phases 1-4 as complete in research doc

* feat: Phase 5 - CLI binary distribution

Implement standalone binary distribution for Archon CLI:

- Bundle default commands and workflows into binaries at compile time
- Add build scripts for cross-platform compilation (macOS/Linux, ARM64/x64)
- Create GitHub Actions release workflow triggered on version tags
- Add curl install script with checksum verification
- Create Homebrew formula for macOS/Linux installation
- Update version command to show platform, build type, and database info
- Add developer release guide documentation
- Update README with CLI installation instructions

Binary compilation uses Bun's --compile flag to create standalone
executables that include the Bun runtime and all dependencies.
Default workflows and commands are imported as text at compile time
and embedded directly into the binary.

* fix: Pin Dockerfile to Bun 1.3.4 to match lockfile version

The Docker build was failing because oven/bun:1-slim resolved to 1.3.6
while the lockfile was created with 1.3.4, causing --frozen-lockfile to fail.

* docs: Clarify binary vs source builds for default commands/workflows

* fix: Address PR review issues for CLI binary distribution

Security fixes:
- install.sh: Require SKIP_CHECKSUM=true to bypass checksum verification
  instead of silently skipping (addresses security vulnerability)
- install.sh: Show actual error output when version check fails instead
  of falsely reporting success

Validation improvements:
- checksums.sh: Validate all 4 expected binaries exist before generating
  checksums to prevent releasing incomplete builds
- build-binaries.sh: Verify binary exists and has reasonable size (>1MB)
  after each build step
- update-homebrew.sh: Validate extracted checksums are non-empty and
  look like valid SHA256 hashes (64 hex chars)
- update-homebrew.sh: Fix sed patterns to use URL context for updating
  checksums on subsequent runs

Bug fixes:
- homebrew/archon.rb: Fix test to expect exit code 0 (success) instead
  of 1 for `archon version`
- loader.ts: Log error when bundled workflow fails to parse (indicates
  build-time corruption)

Test coverage:
- Add bundled-defaults.test.ts for isBinaryBuild() and content validation
- Add connection.test.ts for getDatabaseType() function
- Add binary build bundled workflow tests to loader.test.ts
- Add binary build bundled command tests to executor.test.ts

All 959 tests pass.
2026-01-21 23:51:51 +02:00
Rasmus Widing
718e01b162
feat: Phase 1 - Monorepo structure with @archon/core and @archon/server packages (#311)
* feat: Add workspace root configuration for Bun monorepo

Configure the root package.json, tsconfig.json, and eslint.config.mjs
for a Bun workspaces monorepo structure with packages/* workspace pattern.

- Convert root package.json to workspace root with workspaces: ["packages/*"]
- Update scripts to use bun --filter for cross-package commands
- Update tsconfig.json to serve as base config for packages to extend
- Update eslint.config.mjs for monorepo paths (packages/*/src/**)
- Update .gitignore for packages/*/node_modules and dist directories

* feat: Create @archon/core package with shared business logic

Extract all shared business logic into @archon/core package:

- types/ - Core TypeScript interfaces (IPlatformAdapter, IAssistantClient, etc.)
- utils/ - Shared utilities (git, auth, formatting, paths, etc.)
- config/ - YAML config loading (loadConfig, loadGlobalConfig, loadRepoConfig)
- state/ - Session state machine (TransitionTrigger, session transitions)
- db/ - PostgreSQL operations (conversations, codebases, sessions, etc.)
- clients/ - AI SDK wrappers (ClaudeClient, CodexClient, factory)
- isolation/ - Git worktree management (WorktreeProvider)
- workflows/ - YAML workflow engine (loader, executor, router, logger)
- services/ - Background services (cleanup-service)
- orchestrator/ - Message orchestration (handleMessage)
- handlers/ - Slash command processing (handleCommand, parseCommand)
- test/ - Test mocks and setup utilities

Package exports are organized with submodule paths for tree-shaking:
- @archon/core - Main exports
- @archon/core/db/* - Database operations
- @archon/core/utils/* - Utility functions
- @archon/core/workflows - Workflow types and functions

All 924 tests pass with the new structure.

* feat: Create @archon/server package with platform adapters

Extract platform-specific code into @archon/server package:

- adapters/ - Platform integrations (Telegram, Slack, Discord, GitHub, Test)
- index.ts - Express server entry point with health checks and webhook handlers
- scripts/ - Setup utilities (setup-auth.ts)

The server package depends on @archon/core via workspace:* reference
and imports shared business logic using @archon/core package paths.

Imports updated to use @archon/core:
- Types: import type { IPlatformAdapter } from '@archon/core'
- DB: import * as conversationDb from '@archon/core/db/conversations'
- Utils: import { handleMessage, ConversationLockManager } from '@archon/core'

Added .env symlink to packages/server/.env for dotenv compatibility.

* chore: Update bun.lock for workspace dependencies

Regenerated lockfile after restructuring to Bun workspaces with
@archon/core and @archon/server packages.

* docs: Update documentation for monorepo structure

Update CLAUDE.md, docs/architecture.md, and docs/new-developer-guide.md to reflect the new Bun monorepo structure introduced in PR #311.

Changes:
- Updated directory structure to show packages/core and packages/server
- Added import patterns section showing @archon/core and @archon/server usage
- Updated all file path references from src/* to packages/*/src/*
- Updated test command examples
- Clarified package split (core: business logic, server: adapters + HTTP)

* fix: Address PR review feedback - imports and auth naming

CLAUDE.md:
- Add typed imports guidance (always use `import type` for types,
  specific named imports for values, avoid generic `import *`)

packages/core/src/index.ts:
- Alias all auth parseAllowedUserIds functions with platform prefix:
  - parseTelegramAllowedUserIds (returns number[])
  - parseSlackAllowedUserIds (returns string[])
  - parseDiscordAllowedUserIds (returns string[])
  - parseGitHubAllowedUsers (already aliased)
- Alias isUserAuthorized as isTelegramUserAuthorized for consistency
- Update JSDoc to mention isolation is extensible for containers/VMs

packages/core/src/db/index.ts:
- Update JSDoc to not overstate naming conflicts (db modules have
  distinct function names)

packages/core/src/clients/index.ts:
- Clarify when to use submodule path vs main package

packages/server/src/adapters/telegram.ts:
- Update to use new aliased auth function names

* fix: Update CI and bunfig.toml for monorepo structure

- Update bunfig.toml test root from ./src to ./packages
- Update preload path to packages/core/src/test/setup.ts
- Update CI workflow test paths for packages/core and packages/server

* fix: Run factory tests in isolation to avoid mock.module pollution

Bun's mock.module() pollutes the global module registry, causing factory tests
to fail when run after claude.test.ts or codex.test.ts (which mock the clients).

Test execution order now:
1. Factory tests first (before any mock.module calls)
2. Client tests (claude, codex) that use mock.module
3. All other tests (db, utils, handlers, etc.)
4. Orchestrator tests last (also uses mock.module)

* fix: Run command-handler tests in isolation to avoid mock pollution

The command-handler tests use mock.module() for database mocks, which causes
test isolation issues when run in the same Bun process as other tests.

Test execution order now:
1. Factory tests (no mocks)
2. Client tests (claude, codex) with mock.module
3. Command-handler tests with mock.module (isolated from step 2)
4. All other tests (db, utils, config, etc.)
5. Orchestrator tests last (also uses mock.module)
2026-01-20 19:08:38 +02:00
Rasmus Widing
c85622fbbb
Migrate from Node.js/npm/Jest to Bun runtime (#85)
* Migrate from Node.js/npm/Jest to Bun runtime

- Replace npm with bun for package management (bun.lock)
- Replace Jest with bun:test for testing
- Update tsconfig for Bun (ESNext module, bundler resolution)
- Update Dockerfile to use oven/bun:1-slim
- Update CI workflow to use oven-sh/setup-bun@v2
- Remove dynamic import hack from codex.ts (direct ESM imports)
- Fix test mocking for Bun (export execFileAsync, use spyOn)
- Update all documentation (CLAUDE.md, README.md, CONTRIBUTING.md)

All 395 tests pass, type-check passes, E2E validated with curl.

* ci: retrigger CI build

* fix: make execFileAsync a function for better Bun mockability

* fix: ensure execFileAsync returns string not Buffer

* fix: rename _execFileAsync to comply with naming convention

* fix: make mkdirAsync mockable for Bun tests

* fix: update engines to bun>=1.0.0 and add mkdirAsync mock

* fix: pin Bun to 1.3.4 in CI to fix mock.module test failures

Newer Bun versions have different mock.module() behavior that causes
cross-test module pollution, resulting in 71 test failures in CI while
tests pass locally. Pinning to 1.3.4 ensures consistent behavior.

* fix: run orchestrator tests last to avoid mock.module pollution

Bun's mock.module() pollutes the global module cache, causing tests to
fail when orchestrator.test.ts (which mocks command-handler and factory)
runs before those modules' own test files.

Fix by running tests in two batches:
1. All tests except orchestrator
2. Orchestrator tests last

This ensures orchestrator's mocks don't affect other test files.
2025-12-16 15:34:58 +02:00
Cole Medin
41415d7e7f feat: implement telegram + claude mvp with generic architecture
- Add generic IPlatformAdapter and IAssistantClient interfaces for extensibility
- Implement TelegramAdapter with streaming/batch modes
- Implement ClaudeClient with session persistence and resume capability
- Create TestAdapter for autonomous validation via HTTP endpoints
- Add PostgreSQL database with 3-table schema (conversations, codebases, sessions)
- Implement slash command system (/clone, /status, /getcwd, /setcwd, /reset, /help)
- Add Docker containerization with docker-compose (with-db profile for local PostgreSQL)
- Fix Claude Agent SDK spawn error (install bash, pass PATH environment variable)
- Fix workspace volume mount to use /workspace in container
- Add comprehensive documentation and health check endpoints

Architecture highlights:
- Platform-agnostic design allows adding Slack, GitHub, etc. via IPlatformAdapter
- AI-agnostic design allows adding Codex, etc. via IAssistantClient
- Orchestrator uses dependency injection with interface types
- Session persistence survives container restarts
- Working directory + codebase context determine Claude behavior

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-10 19:35:50 -06:00