跳到正文
DEV Community· jaya v·· 3 小時前AI 評分21

Haunted Terminal:為 Shell 帶來一個 Poltergeist

👻 Haunted Terminal: A Poltergeist for Your Shell 🖥️✨

AI 導讀

Haunted Terminal 是一款輕量級 CLI 工具,會攔截 Shell 指令並在本機執行,再透過 Google Gemini / Backboard 生成一則扮演 Poltergeist 的諷刺短評。每條指令及其評論都會自動儲存至 MongoDB Atlas,記錄終端機的使用歷程。

正文

jaya v

Hacktoberfest Open-Source AI Challenge: Ghost in the Machine Submission 👻🌼

Inspiration 🎃

For this year's "Ghost in the Machine" Hacktoberfest challenge, I wanted to blend the spooky energy of Halloween with everyday developer life. What's scarier than staring at a blank command line, dreading a cryptic error code or a production typo?

Meet the Haunted Terminal—a lightweight CLI tool that intercepts your everyday shell commands, executes them locally, and uses AI to channel an ancient, sarcastic digital poltergeist that whispers eerie (and often mocking) commentary back at you.

What It Built 🛠️

The Haunted Terminal acts as a custom shell wrapper. Here is how it brings the machine to life:

  1. Command Interception: You type normal commands (ls, git status, npm run build), and the tool runs them safely via Python's subprocess.
  2. The Spirit's Voice: It sends your command and its output to an AI model (powered by Google Gemini / Backboard) to generate a unique, 1-character-in-character poltergeist remark.
  3. The Séance Log: Every single command and haunting commentary is automatically stored in a MongoDB Atlas database, keeping a permanent ledger of your terminal's haunting history.

Demo Screenshot

(Insert screenshot of your Haunted Terminal running and showing the spooky red text commentary)

How It Works (Code Snippet) 👻

Here is a quick look at how the core haunting loop works using Python and pymongo:


python
import os
import subprocess
from pymongo import MongoClient
import google.generativeai as genai

# Connect to MongoDB Atlas
client = MongoClient(os.environ.get("MONGO_URI"))
db = client["haunted_db"]
collection = db["seance_logs"]

def consult_the_spirit(command, output):
    prompt = f"You are a sarcastic digital ghost haunting a developer's terminal. The user ran: `{command}` with output: `{output[:300]}`. Whisper a short, spooky 1-sentence comment."
    # AI generation logic here...
    return "The spirits are watching your syntax closely..."

來源:DEV Community · dev.to