Overview
The main module serves as the CLI entry point for the Longshot orchestrator. It loads environment variables, initializes logging and tracing, creates the orchestrator instance, and manages the full execution lifecycle. Location:packages/orchestrator/src/main.ts
Key Functions
main()
The primary entry point that orchestrates the entire execution flow.
- Loads environment variables from
.envfile - Configures log level from
LOG_LEVELenv var - Enables file logging and tracing
- Creates orchestrator instance with comprehensive callbacks
- Runs the orchestrator with the user’s request
- Handles graceful shutdown on SIGINT/SIGTERM
- Exits with code 1 if finalization fails
LOG_LEVEL- Sets logging verbosity (debug, info, warn, error)LONGSHOT_PROMPTS_ROOT- Override directory for prompt files
formatDuration()
Utility function for human-readable duration formatting.
Duration in milliseconds
5m 30s or 1500ms
Orchestrator Callbacks
The main module registers extensive callbacks to monitor orchestrator progress:Task Lifecycle
onTaskCreated - Logs when new tasks are created
taskId, parentId, description (first 200 chars)
onTaskCompleted - Logs task completion with metrics
Iteration Progress
onIterationComplete - Called after each planning iteration
Reconciler Events
onSweepComplete - Called after each reconciler sweep
Finalization Phase
onFinalizationStart - Marks start of finalization
onFinalizationAttempt - Called for each finalization attempt
onFinalizationComplete - Final finalization status
Metrics Updates
onMetricsUpdate - Periodic metrics snapshot including merge queue stats
Usage Example
Output Files
The main module creates three log files in the current working directory:longshot-{timestamp}.log- Debug-level file logstrace-{timestamp}.jsonl- NDJSON trace spans for observabilityllm-detail-{timestamp}.jsonl- LLM request/response details
Exit Codes
Run completed successfully with all checks passing
Run failed finalization (build failed, tests failed, or branches unmerged)
Request Input
The orchestrator accepts a request as the first command-line argument:Shutdown Handling
- Stops the orchestrator (planner, workers, reconciler)
- Writes final summary logs
- Closes file logging and tracing handles
- Exits with appropriate code