This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Test: deno test --allow-env --allow-net --allow-import src/*.test.ts
Sync: deno run --allow-env --allow-net --allow-import src/sync.ts
CLI: deno run --allow-env --allow-net --allow-import src/cli.ts
Format: deno fmt (configured for 2-space indents, 80-char lines, semicolons)
Lint: deno lint
Available CLI commands:
deno task check- Check API connectivitydeno task validate- Validate configurationdeno task dry-run- Preview sync operations without executingdeno task setup-guide- Show Val Town setup instructions
This is a bidirectional sync system between Linear issues and Google Calendar events using the Declarative Reconciliation Loop (DRL) pattern. The system follows a strict Observe β Project β Diff β Actuate cycle.
- Worker (
src/worker.ts): Main orchestrator that coordinates the sync process - Projector (
src/projector.ts): Converts external data into canonical items - Diff Engine (
src/diff.ts): Computes operations needed to reach desired state - Actuator (
src/actuator.ts): Executes operations against external APIs - API Clients (
src/api-clients.ts): Handle Linear and Google Calendar API communication
The sync operates in 4 phases:
- Observe: Fetch current snapshots from Linear and Google Calendar APIs
- Project: Create canonical truth using deterministic, side-effect-free functions
- Diff: Compare canonical state with external reality to compute minimal operations
- Actuate: Execute idempotent API calls until external systems match canonical truth
The system recognizes 5 phases with specific transition rules:
| Phase | Description | Triggers |
|---|---|---|
eventOnly | GCal event without Linear match | New calendar event created |
linearOnly | Linear issue without GCal match | Issue marked as "Scheduled" |
active | Linked and syncing | Both systems have records |
completed | Linear marked done/canceled/failed | State change in Linear |
overdue | Past deadline but still active | >24h after event end |
- Stateless: No database required; all state lives in remote systems via UID linkages
- Metadata Format: Bidirectional linking via
extendedProperties(GCal) and description metadata (Linear) - Val Town Platform: Built for Val Town deployment with specific constraints
- Time Handling: Uses dayjs with timezone support, 24-hour windows for state transitions
- Dependencies: googleapis, graphql-request, dayjs, uuid (imported via deno.json)
The system expects environment variables:
LINEAR_API_KEY: Linear API tokenLINEAR_TEAM_ID: Linear team identifierGCAL_API_KEY: Google Calendar API keyGCAL_CALENDAR_ID: Primary calendar IDGCAL_HISTORY_CALENDAR_ID: (Optional) Calendar for overdue itemsTIMEZONE: Timezone for operations (default: UTC)
All core logic (worker, projector, diff, actuator) has comprehensive unit tests with 31 test cases total. Tests use Deno's built-in test framework with mocked API responses to ensure deterministic behavior.
src/
βββ types.ts # Core data models and interfaces
βββ projector.ts # Observe β Project (create canonical truth)
βββ diff.ts # Project β Diff (compute operations)
βββ actuator.ts # Diff β Actuate (execute operations)
βββ worker.ts # Main sync orchestrator
βββ api-clients.ts # Linear and Google Calendar API clients
βββ sync.ts # Entry point for sync execution
βββ cli.ts # Command-line interface
βββ *.test.ts # Comprehensive test suite
- Dry Run Mode: Use
deno task dry-runto preview operations without execution - API Validation: Use
deno task checkto verify API connectivity - Scripts: Helper scripts in
scripts/directory for data inspection