Night Agent is a local coding-agent harness that plans coding tasks, asks an LLM for file edits, applies validated patches, and optionally runs repository checks.
It supports two modes:
- Single-agent mode via
run-agent.js(one repo context at a time) - Orchestrator mode via
orchestrator.js(multi-role execution:swe1,swe2,swe3)
- Reads task instructions (
tasks.txtor role task files) - Loads runtime/config context from JSON files
- Calls an Azure OpenAI chat-completions endpoint
- Requests JSON-only patch instructions from the model
- Applies patch operations to candidate or working files
- Persists logs and state for resumable orchestration runs
- Optionally runs preflight and post-run checks (lint/tests)
| Path | Purpose |
|---|---|
run-agent.js |
Main single-agent runner: model call, file selection, patch apply, safety checks |
orchestrator.js |
Multi-role coordinator that generates/loads tasks and runs role agents |
config.json |
Base runtime config for run-agent.js |
agent-config.json |
Per-repository config map (repo paths, test commands, constraints) |
orchestrator-config.json |
Orchestrator runtime settings (plan path, state path, role map, final checks) |
orchestrator-tasks.json |
Either fixed tasks or a ceoTask prompt for plan generation |
tasks.txt |
Default single-agent task input |
logs.txt |
Execution logs written by run-agent.js |
ui/ |
React + Vite multi-repo dashboard with Start Building controls and live logs |
ui/server.mjs + ui/server/* |
Durable API runner with run persistence, repo locking, retries, cancellation, and schedule endpoints |
scripts/ |
Utility scripts (for example backend preflight) |
skills/ and .copilot/skills/ |
Skill docs and behavior definitions (smart-commit, type correction, etc.) |
run-agent.next.js / run-agent.patch.json |
Candidate output artifacts produced by runs |
- Node.js 18+ (Node 20+ recommended)
- Azure CLI logged in (
az login) - Access to the configured Azure OpenAI endpoint/model
- Git installed (needed for repository checks and commit-aware workflows)
npm install
package.jsonis currently minimal. If you add dependencies later, re-runnpm install.
- Edit
tasks.txtwith the task you want. - Confirm
config.jsonpoints to the correct repo and files. - Run:
node run-agent.jsOutputs are written to:
logs.txtrun-agent.next.js(candidate output whenapplyModeis candidate)run-agent.patch.json(generated patch instructions)
- Configure repos in
agent-config.json - Configure orchestration in
orchestrator-config.json - Define either:
- fixed
tasksinorchestrator-tasks.json, or - a high-level
ceoTaskthat the orchestrator expands into role tasks
- fixed
- Run:
node orchestrator.jsOrchestrator artifacts:
orchestrator-plan.json(generated plan when usingceoTask).orchestrator/run-state.json(resumable state).orchestrator/task-<role>.txt(role task files)
Use the React UI + API runner when you want real multi-repo execution with branch creation, retries, and push automation.
cd ui
npm install
npm run startOpen the local URL shown by Vite (typically http://localhost:5173).
The UI posts to http://localhost:8787/api/runs and streams status/logs by polling run state. It also loads defaults from GET /api/config and recent runs from GET /api/runs.
To build/preview the UI:
cd ui
npm run build
npm run previewMission: high-level objective for the runBranch prefix: prefix used when creating per-repo branchesMax retries per repo: retry limit for failing test commandsSwe3 validation repo name: repo that should receive stricter retry focusCommit message template: base commit text for auto-commit per repoRemediation command: command executed fromnight-agentroot to apply fixes between retries (for examplenode orchestrator.js)Run remediation command before test loop: applies remediation once before testing startsRe-run remediation command whenever tests fail: applies remediation between failed test attemptsPush branch when tests pass: performsgit push -u origin <branch>Repositorieslist:EnabledNamePathTest command- add/remove repo rows
When you click Start Building, the backend run does this:
- (Optional) run remediation command first (for orchestration-driven edits)
- For each enabled repo:
- verify git repo
- create a new branch (
<prefix>/<repo>-<timestamp>) - run test command with retry loop
- if enabled, run remediation command between retries
- commit changed files with the configured template
- push branch to origin (if push is enabled)
- Persist run state to disk and stream logs/per-repo status to the UI until complete/failed/cancelled
When you click Stop Run during execution, the harness sends a cancellation request, terminates active commands, and marks the run as cancelled.
POST /api/schedulescreates a recurring mission withintervalMinutesand a full run payload.GET /api/scheduleslists schedules and latest run metadata.POST /api/schedules/:id/enabledtoggles a schedule on/off.DELETE /api/schedules/:idremoves a schedule.- If a schedule ticks while one of its repos is already active, that tick is skipped safely.
Key fields:
endpoint,model: Azure OpenAI chat-completion targetrepoPath: working repository pathagentConfigPath,tasksPath,orchestratorConfigPath: config/task file locationsmaxFilesToEdit,maxPatchChanges,maxPatchChars: patch constraintsrepoMapMaxFiles,repoMapCachePath,repoMapCacheTtlMinutes: repository indexing/cache controlsmaxFileBytes: file read safety limitretryAttempts,maxIterations: execution controlapplyMode:candidateorworkingcandidateDir,targetFile,candidateFile,patchFilegit.*: branch/commit behavior flags
Defines:
activeReporepos.<name>.path- allowed paths and test/preflight commands
- optional runtime context passed through prompts
Controls:
- task/config file locations
- resume behavior
- role-to-repo mapping
- final check commands per repo
- Load config and active repo settings
- Load task text and optional instruction/context files
- Build repo map and select target files
- Call model for JSON patch instructions
- Validate and apply patch operations
- Write candidate/working outputs and logs
- Run configured checks if enabled
- Load orchestrator + agent config
- Build role tasks (from static tasks or
ceoTask) - Persist plan/state for resume support
- Run
swe1,swe2,swe3sequentially - Execute repo-level final checks
- Mark run state complete or failed
logs.txt: timestamped run-agent logs.agent-cache/: repo-map cache.agent-candidates/: candidate outputs when enabled.orchestrator/: state and role task files for orchestration.night-agent-state/: persisted UI API run records, run index, and schedule state
If a run stops mid-way, rerunning node orchestrator.js resumes from state when resume is enabled.
- Run
az login - Confirm subscription/account context
- Verify
endpointandmodelinconfig.json - Ensure token scope matches Cognitive Services resource
- Check relative paths are correct from repository root
- Prefer Windows-style paths on this environment
- Ensure target files still match expected text (
findfragments) - Reduce task scope or lower files/changes in one run
- Review configured command in
agent-config.jsonororchestrator-config.json - Run the command manually inside target repo to inspect root cause
- This repo is designed to operate primarily as a local harness.
- Keep credentials out of committed config files.
- Prefer
candidatemode when testing new prompts/flows.