Archon/bunfig.toml
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

10 lines
334 B
TOML

# Bun configuration for Remote Agentic Coding Platform
[test]
# Only discover tests in packages/ - prevents finding duplicates in workspace/worktrees
root = "./packages"
# Run preload script before tests (now in @archon/core)
preload = ["./packages/core/src/test/setup.ts"]
# Coverage output
coverage = true
coverageDir = "coverage"