This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Test: deno task test
Sync: deno task sync
Dry Run: deno task dry-run
Check Environment: deno task check
Validate APIs: deno task validate
Setup Guide: deno task setup
Format: deno fmt (configured for 2-space indents, 80-char lines, semicolons)
Lint: deno lint
Available deno tasks:
deno task test- Run unit testsdeno task sync- Run real sync with production datadeno task dry-run- Run sync with real data in dry-run mode (no changes made)deno task check- Check environment configurationdeno task validate- Validate API structure and mock compatibilitydeno task setup- Show Val Town configuration guide
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 identifierGOOGLE_SERVICE_ACCOUNT_JSON: Base64-encoded Google service account JSONGCAL_CALENDAR_ID: Primary calendar IDGCAL_HISTORY_CALENDAR_ID: (Optional) Calendar for overdue itemsTIMEZONE: Timezone for operations (default: America/New_York)
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
βββ main.ts # Entry point for sync execution
βββ dry-run.ts # Dry run mode for testing
βββ *.test.ts # Comprehensive test suite
scripts/
βββ check.ts # Environment configuration checker
βββ validate.ts # API structure validator
βββ setup.ts # Val Town setup guide
βββ show-*.ts # Debug scripts for data inspection
βββ api-validator.ts # API structure validation
βββ val-town-config.ts # Val Town deployment helpers
βββ README.md # Script documentation
- Development Tasks: Use
deno taskcommands for environment checks, API validation, and testing - Debug Scripts: Helper scripts in
scripts/directory for data inspection:show-gcal.ts- View Google Calendar eventsshow-linear.ts- View Linear issuesshow-canonical.ts- View canonical projectionshow-all.ts- Complete data flow analysis
- Val Town Deployment: Use
scripts/val-town-config.tsfor deployment helpers