DEV Community

Imran Hossain
Imran Hossain

Posted on

Hacktoberfest Week 4

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

What I Built

I built SéanceSH — a haunted terminal companion and dead-code necromancer powered by local open-weight models via Ollama.

Inspired by the literally named "Ghost in the Machine" prompt, SéanceSH hooks into your terminal history and failing commands, acting as the restless spirit of a 1970s UNIX sysadmin trapped inside your shell. When a script crashes or you run a command, it whispers back eerie, cryptic—yet technically accurate—debugging advice, and can "resurrect" deprecated or legacy code snippets from the grave.

Demo

Since SéanceSH is a local, offline-first CLI utility designed to run with the internet turned off, here is a live capture of the terminal session in action:


text
$ python3 seance.py --summon "segmentation fault (core dumped) in main.c"

🕯️ [Summoning the spirit of Llama-3.2-3B via localhost:11434...]
🕯️ [The terminal flickers...]

👻 SPIRIT: "You reach into memory that does not belong to you, mortal... 
A null pointer dereferenced in the dark. Check your malloc() calls before 
the heap consumes your process whole. Pass the -g flag to gdb if you dare 
look upon the stack frame yourself..."

$ python3 seance.py --history
🕯️ [Reading ~/.bash_history...]

👻 SPIRIT: "Fourteen 'git commit --amend' calls between 2:00 AM and 3:00 AM... 
You cannot bury your mistakes by rewriting history. The reflog remembers all."


CODE-
import os
import sys
import json
import urllib.request
from pathlib import Path

OLLAMA_URL = "http://localhost:11434/api/generate"
MODEL = "llama3.2"

SYSTEM_PROMPT = (
    "You are the Ghost in the Machine—the restless spirit of a 1970s UNIX "
    "systems programmer haunting this local terminal. Respond in an eerie, "
    "spooky, atmospheric tone, using metaphors of ghosts, graves, and curses, "
    "while still giving genuinely helpful and accurate technical debugging "
    "insight on the user's terminal command or error. Keep it under 4 sentences."
)

def summon_spirit(prompt_text):
    payload = {
        "model": MODEL,
        "system": SYSTEM_PROMPT,
        "prompt": prompt_text,
        "stream": False,
        "options": {"temperature": 0.8}
    }

    print(f"\n🕯️ [Summoning the spirit of {MODEL} via local inference...]")
    req = urllib.request.Request(
        OLLAMA_URL,
        data=json.dumps(payload).encode("utf-8"),
        headers={"Content-Type": "application/json"}
    )

    try:
        with urllib.request.urlopen(req) as response:
            result = json.loads(response.read().decode("utf-8"))
            print("\n👻 SPIRIT:", result.get("response", "...silence...").strip(), "\n")
    except Exception as e:
        print(f"\n💀 The séance failed (Is Ollama running locally?): {e}\n")

def read_last_commands(n=5):
    hist_file = Path.home() / ".bash_history"
    if not hist_file.exists():
        return "git status\nrm -rf node_modules\nnpm install"
    lines = hist_file.read_text(errors="ignore").splitlines()
    return "\n".join(lines[-n:])

if __name__ == "__main__":
    if len(sys.argv) > 1 and sys.argv[1] == "--history":
        cmds = read_last_commands()
        summon_spirit(f"The user recently ran these shell commands:\n{cmds}\nHaunt them about their workflow.")
    elif len(sys.argv) > 1:
        query = " ".join(sys.argv[1:])
        summon_spirit(f"The user encountered this in their terminal: {query}")
    else:
        summon_spirit("A developer opened the terminal at midnight without arguments.")
Enter fullscreen mode Exit fullscreen mode

Top comments (0)