DEV Community

Akshara A
Akshara A

Posted on Edited on

The Autonomous 100% local CLI Agent That Codes While You Sleep

Hacktoberfest Open-Source AI Challenge: Ghost in the Machine Submission πŸ‘»πŸŒΌ

This is a submission for the Hacktoberfest Open-Source AI Challenge Week 4: Ghost in the Machine

Night Ghost πŸ‘»: The Autonomous Agent That Codes While You Sleep

"I stopped halfway" β†’ "I woke up further ahead."


What I Built

Every developer and indie hacker knows the evening exhaustion of leaving code half-finished. You hit a wall at 11 PM: functions lack edge-case tests, helper logic is duplicated, and your working tree is messy. By the time you wake up the next morning, context and momentum have vanished. The first hour of your day is spent re-orienting: "Where was I? What broke? What was I about to test?"

Night Ghost is an open-source, 100% local CLI agent powered by Ollama designed to bridge that evening-to-morning gap. It is quite literally a benevolent ghost in your machine:

  • 100% Local & Offline: All inference runs directly on your machine through Ollama. No source code, diffs, or credentials ever leave your device.
  • Air-Gapped Egress: The test runner actively blocks network access during test runs.
  • Deterministic Guardrails: Security and path boundaries are enforced in Python code, not by trusting system prompts.
  1. In the Evening: You drop a quick task note before closing your laptop:
   nightghost note "Add unit tests for charge() edge cases and clean up duplicated currency rounding"
   nightghost sleep
Enter fullscreen mode Exit fullscreen mode
  1. Overnight (While You Sleep): Night Ghost wakes up (triggered via local cron/timer), reads your note and recent diffs, creates an isolated branch (nightghost/YYYY-MM-DD), and runs an autonomous, test-gated pipeline:
    • Plans small, verification-gated steps.
    • Proposes test additions and safe, behavior-preserving cleanups.
    • Evaluates every write against strict security guardrails in Python code.
    • Runs your test suite (pytest) in a sandboxed, offline environment.
    • Commits every verified step (ghost: <step>). If any test regresses, it automatically rolls back.
    • Compiles a transparent morning report from measured execution logs.
  2. In the Morning: You open your laptop, review the factual report and the clean diff, and decide whether to merge or discard:
   nightghost report
   git diff main..nightghost/2026-11-01
Enter fullscreen mode Exit fullscreen mode

Demo

1. Terminal Workflow (Local CLI)

Watch Night Ghost wake up, analyze the task, run tests, and commit progress autonomously:

$ cd demo_project
$ nightghost status

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Property                       β”‚ Value                β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Current Git Branch             β”‚ main                 β”‚
β”‚ Uncommitted Changes            β”‚ Clean                β”‚
β”‚ Scheduled Time                 β”‚ 01:00                β”‚
β”‚ Configured Model               β”‚ gemma4:e2b (ollama)  β”‚
β”‚ Test Command                   β”‚ pytest -q            β”‚
β”‚ Ollama Server                  β”‚ Online               β”‚
β”‚ Model Status                   β”‚ Ready (Installed)    β”‚
β”‚ Kill Switch (.nightghost/STOP) β”‚ Disengaged (Ready)   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

$ nightghost note "Add comprehensive unit tests for payment edge cases"
$ nightghost run

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ Overnight Run ──────────┐
β”‚ Night Ghost Active                β”‚
β”‚ Model: gemma4:e2b (ollama)        β”‚
β”‚ Mode: LIVE RUN                    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

[OK] Pipeline completed!
Branch: nightghost/2026-10-31
Steps Planned: 2
Steps Executed: 2
Elapsed: 142.7s

$ nightghost report
Enter fullscreen mode Exit fullscreen mode

2. Sample Morning Report Output

Every claim in the morning report is compiled directly from actions.jsonl and git diff statsβ€”not model hallucinations:

# Night Ghost Report: 2026-10-31
Task: "Add comprehensive unit tests for charge() and refund() edge cases"
Branch: nightghost/2026-10-31 (2 commits, 2 files, +38 / -6)
Model: gemma4:e2b (local) | Runtime: 2m 22s

## Result at a glance
[PASS] Tests: 2 -> 6 passing (0 failing)

## What I did
1. Added unit tests for charge() negative amounts raising ValueError: commit a1f4d92
2. Added unit tests for refund() invalid transaction IDs: commit 8c2b1e4

## Needs your judgment
- None. All committed changes are self-contained and behavior-preserving.

## Skipped / failed
- None. All attempted steps passed validation.

## Blocked by guardrails
- None. All file and command requests adhered to security rules.

## How to review
git diff main..nightghost/2026-10-31
nightghost discard   # to throw it all away
Enter fullscreen mode Exit fullscreen mode

3. Dry-Run Simulation Mode

Night Ghost also provides a simulation mode so you can preview planned steps and check baseline tests without writing files or making commits:

nightghost run --dry-run
nightghost report
Enter fullscreen mode Exit fullscreen mode

Code

Architecture at a Glance

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Task note  │──▢│  Planner  │──▢│  Executor    │──▢│  Reporter   β”‚
│ + config   │   │ (Open LLM)│   │ (LLM + tools)│   │ (log→MD)    │
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                        β”‚
                  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                  β–Ό                     β–Ό                     β–Ό
            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
            β”‚ Guardrailβ”‚         β”‚ Test Runnerβ”‚        β”‚ Git Managerβ”‚
            β”‚ (paths,  β”‚         β”‚ (sandboxed β”‚        β”‚ (branch,   β”‚
            β”‚  budgets)β”‚         β”‚  subproc)  β”‚        β”‚  commits)  β”‚
            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                        β”‚
                                  β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”
                                  β”‚ Local LLM  β”‚
                                  β”‚ (Ollama)   β”‚
                                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Enter fullscreen mode Exit fullscreen mode

Key Engineering Components:

  • Guardrail Engine (guardrail.py): All writes are path-checked in deterministic code (resolving symlinks and ..). Denylist precedence protects .env*, migrations/**, *.pem, *.key, and lockfiles. Detects secrets and blocks command injection vectors (;, &&, |, backticks, $(), newlines).
  • Assertion Tampering Protection: Hard rule preventing models from "fixing" tests by weakening them. If an existing test assertion is altered or deleted, the write is instantly rejected with EXISTING_ASSERTION_MODIFIED.
  • Git Isolation (gitmanager.py): Never touches main or leaves your working tree dirty. Snapshots uncommitted work with git stash create, works on nightghost/YYYY-MM-DD, makes atomic ghost: <step> commits, and supports one-command rollback with nightghost discard.
  • Test Runner (testrunner.py): Runs pytest in a sandboxed subprocess with proxy poisoning (http_proxy=http://127.0.0.1:0, PIP_NO_INDEX=1) to enforce zero network egress.
  • Test Suite: 33 automated tests (pytest) covering every denial path, symlink escape, budget constraint, and pipeline execution.

How I Built It

100% Local Inference via Ollama

  • Zero Cloud Dependence: Night Ghost is built strictly for 100% local, offline execution using Ollama. It runs completely disconnected from the internet, communicating over localhost:11434.
  • Open-Weight Coder Models: Fully tested and optimized with open models including:
    • Gemma 4 (gemma4:e2b / gemma4:e4b): Ultra-efficient reasoning on modest consumer hardware.
    • Qwen 2.5 Coder (qwen2.5-coder:14b / 7b): Deep context understanding and accurate test generation.
    • Llama 3 / DeepSeek-Coder-V2: Advanced multi-file refactoring.

The Agent Harness

  • Python 3.11+, Typer, and Rich for a terminal UI.
  • Pydantic v2 and PyYAML for strict schema validation in nightghost.yaml.
  • Jinja2 for compiling transparent morning reports from JSONL action logs.

Why Does Open Innovation Matter?

  1. 100% Local Code Privacy via Ollama: Developers cannot and should not send their proprietary codebases, uncommitted diffs, or corporate repositories to third-party closed cloud APIs while they sleep. Open innovation makes running open-weight models 100% locally via Ollama viable on everyday laptops, ensuring not a single byte of code or credentials ever leaves your machine.
  2. Deterministic Security Over Model Promises: Closed-source agent frameworks often rely on "system prompt polite requests" not to touch sensitive files. Night Ghost enforces security in deterministic open-source codeβ€”every path check, symlink resolution, and assertion integrity check is auditable, testable, and mathematically verified.
  3. No Per-Token Metering: An autonomous multi-turn overnight loop executing dozens of test iterations would rack up unpredictable API bills on closed models. Running open-weight models 100% locally via Ollama empowers indie developers to run autonomous agents overnight completely free.

The Spirit of It

There is a distinct, quiet magic in closing your laptop with a half-solved problem, going to sleep, and waking up with your morning coffee to find:

[PASS] Tests: 2 -> 6 passing (0 failing)
1. Added unit tests for charge() negative amounts: commit a1f4d92
Enter fullscreen mode Exit fullscreen mode

The dreaded edge cases you didn't have the energy to write at midnight are written, tested green, and neatly committed on an isolated branch. You didn't lose your morning momentumβ€”you woke up further ahead. That is the spirit of a benevolent Ghost in the Machine.


Prize Categories

  • Hacktoberfest Open-Source AI Challenge Week 4: Ghost in the Machine
  • Best Use of Open-Weight Models (Ollama / Gemma / Llama / Qwen)
  • Developer Productivity & Autonomous Developer Tooling

Top comments (0)