nightme

module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2026 License: MIT

README

nightme

Sleep tight, code all night.

Status Go License

nightme is a single-process daemon that bridges AI Coding CLIs (Claude Code / Codex / OpenCode) to IM channels (Feishu / WhatsApp / Web UI), so you can drop "write X for me" into a chat at night and collect the result in the morning.

Status: v0.1.0 — M3 done. The Feishu round-trip is in place with structured logging, panic recovery, and CI. See docs/PLAN.md for the roadmap.

Screenshot

Coming in v0.2 — see #X.

Install

Requires Go 1.22+ and GOPROXY configured for the proxy you use (https://goproxy.cn,direct works on mainland China).

go install github.com/cnlangzi/nightme/cmd/nightme@v0.1.0

Or build from source:

git clone https://github.com/cnlangzi/nightme.git
cd nightme
go build -o bin/nightme ./cmd/nightme

Quick Start

1. Local Bridge smoke test
./bin/nightme test --workspace /tmp --agent /bin/echo --args hello

The test command forwards stdin to the agent and writes agent output to stdout. Send SIGINT (Ctrl+C) to detach (the child CLI survives), or pass --cleanup to kill it instead:

./bin/nightme test --cleanup --workspace /tmp --agent /bin/echo --args hello

Inspect persisted sessions:

./bin/nightme list           # human-readable table
./bin/nightme list --json    # machine-readable
2. Feishu channel
# (Optional) Copy and edit the example config
cp configs/nightme.example.yaml ~/.config/nightme/config.yaml

# One-click Feishu registration (scan the QR code)
./bin/nightme auth login feishu

# Start the daemon
./bin/nightme run

In a 1:1 Feishu chat with the bot:

/cwd /tmp             # bind this chat to a workspace
/run claude           # spawn the CLI in that workspace
hello                 # plain text flows to the agent
/kill                 # stop the CLI (session preserved)
/help                 # list every nightme command

nightme run defaults to detaching session CLIs on shutdown (default keeps state across daemon restarts). Pass --cleanup to kill them all on SIGINT/SIGTERM — convenient for CI or one-shot scripts:

./bin/nightme run --cleanup

Features (v0.1.0)

Feature Status Description
F-19 PTY backend PTY-backed byte pipe for any CLI
F-21 Agent modes 🟡 stubs ACP / PTY (SDK stub in v0.2)
F-22 Feishu auth One-click QR registration
F-08 Feishu channel WebSocket adapter + IM rendering
F-20 Gateway Slash router (/cwd /run /kill /help)
F-05 Process registry JSON persistence (mode 0600)
F-10 Session list nightme list CLI
F-23 Panic recovery Recover → CodeGenericError
F-24 Structured log slog + secret redaction
F-25 --cleanup Kill vs detach on shutdown

Architecture

nightme is a thin pipeline. Each message walks three layers:

┌─────────────┐    ┌─────────────┐    ┌─────────────┐
│  Channel    │ →  │  Gateway    │ →  │  Session    │
│  (Feishu)   │ ←  │  (router)   │ ←  │  + Bridge   │
└─────────────┘    └─────────────┘    └─────────────┘
                                          ↓
                                     Agent CLI (PTY)
  • Channel owns the transport (Feishu WebSocket today; adapter pattern so WhatsApp / Web TTY can drop in).
  • Gateway routes inbound messages: slash commands are handled in-process; everything else is forwarded to the live session.
  • Session binds a chat to a workspace and an AgentSession handle. The handle is owned by a Bridge (PTY today; ACP tomorrow).
  • Registry persists the session table as JSON (mode 0600, atomic rename).

See docs/SPEC.md for the long form and docs/PRD.md for the product framing.

Configuration

nightme reads YAML from ~/.config/nightme/config.yaml (or $NIGHTME_CONFIG if set). Every field can be overridden by a NIGHTME_<SECTION>_<KEY> environment variable. See configs/nightme.example.yaml for the full schema and docs/SPEC.md §6 for the resolution rules.

Logs are written to ~/.local/share/nightme/nightme.log (mode 0600) as JSON; any attribute whose key contains secret, token, or password is automatically rewritten to ***REDACTED***.

Development

go test -race ./...      # race-tested, ~219 tests
go vet ./...             # 0 warnings required by CI
go build ./...           # must succeed for CI

CI runs on GitHub Actions (.github/workflows/ci.yml) for every push and pull request. Coverage artifacts are uploaded on pushes to main.

Project layout
cmd/nightme/              # cobra CLI (test, list, auth, run)
configs/                  # example YAML config
docs/                     # PRD / SPEC / FEATURES / PLAN / feat/*
internal/
  agent/                  # Agent / AgentSession / Event interfaces + registry
    ptyagent/             #   PTY-mode agent (default for v0.1)
  auth/                   # Provider interface + Feishu one-click flow
  bridge/                 # Bridge abstraction (ACP / SDK / PTY)
    acp/  pty/  sdk/      #   three backend implementations
  channel/                # Channel interface and Feishu adapter/renderer
    feishu/               #   WebSocket receive + IM message rendering
  config/                 # YAML loader + NIGHTME_* env overrides
  errors/                 # CodedError + ExitCode (M3)
  gateway/                # Slash command router + 4 default handlers
  logging/                # slog + secret redaction (M3)
  registry/               # JSON-backed process registry (0600, atomic writes)
  session/                # Session + MemoryManager + Restore / Persist
Exit codes
Code Meaning
0 Success
1 Generic / unmapped error
2 Config error
3 Auth error
4 Channel error
5 Session error
6 Agent error
7 Bridge error
8 Validation error
9 Not found

Documentation

Doc What
docs/PRD.md Product definition — what / why / for whom
docs/SPEC.md Technical architecture — components, data flow, NFRs
docs/FEATURES.md Feature index — every F-XX in one table
docs/PLAN.md Implementation roadmap — M0 → M1 → M2 → M3
docs/feat/ Per-feature design docs (F-01, F-04, F-05, F-10, …)
docs/E2E_TESTING.md Manual Feishu round-trip + troubleshooting
CHANGELOG.md Version history

License

MIT — see LICENSE for the full text.

Directories

Path Synopsis
cmd
nightme command
Package main — `nightme auth` subcommand tree.
Package main — `nightme auth` subcommand tree.
internal
agent
Package agent defines the abstract Agent interface that wraps any AI Coding CLI behind a single structured event stream.
Package agent defines the abstract Agent interface that wraps any AI Coding CLI behind a single structured event stream.
agent/acpagent
Package acpagent implements agent.Agent for CLIs that speak the Agent Client Protocol over their stdio stream.
Package acpagent implements agent.Agent for CLIs that speak the Agent Client Protocol over their stdio stream.
agent/ptyagent
Package ptyagent implements agent.Agent for CLI tools that expose no structured protocol — they are spawned inside a PTY and the bytes are forwarded as AgentEvents.
Package ptyagent implements agent.Agent for CLI tools that expose no structured protocol — they are spawned inside a PTY and the bytes are forwarded as AgentEvents.
auth
Package auth defines the per-channel credential onboarding contract.
Package auth defines the per-channel credential onboarding contract.
auth/feishu
Package feishu implements auth.Provider for the Feishu (飞书) channel.
Package feishu implements auth.Provider for the Feishu (飞书) channel.
bridge/acp
Package acp implements the Agent Client Protocol client transport.
Package acp implements the Agent Client Protocol client transport.
bridge/claudecode
Package claudecode implements bridge.Agent for Anthropic's Claude Code CLI using its stream-json mode.
Package claudecode implements bridge.Agent for Anthropic's Claude Code CLI using its stream-json mode.
bridge/pty
Package pty wraps aymanbagabas/go-pty behind a minimal Bridge interface so the rest of nightme does not depend on the underlying library.
Package pty wraps aymanbagabas/go-pty behind a minimal Bridge interface so the rest of nightme does not depend on the underlying library.
bridge/sdk
Package sdk contains adapters for vendor SDKs that expose a native structured agent session.
Package sdk contains adapters for vendor SDKs that expose a native structured agent session.
channel
Package channel defines the protocol-neutral boundary between nightme and an instant-messaging backend.
Package channel defines the protocol-neutral boundary between nightme and an instant-messaging backend.
channel/feishu
Package feishu implements the Feishu channel adapter.
Package feishu implements the Feishu channel adapter.
config
Package config loads nightme configuration from a YAML file and applies environment-variable overrides.
Package config loads nightme configuration from a YAML file and applies environment-variable overrides.
errors
Package errors defines nightme's unified error code surface.
Package errors defines nightme's unified error code surface.
gateway
Package gateway routes incoming chat messages to slash commands registered by nightme, or to a fallback handler (typically the session manager forwarding text to the live agent).
Package gateway routes incoming chat messages to slash commands registered by nightme, or to a fallback handler (typically the session manager forwarding text to the live agent).
heartbeat
Package heartbeat provides event-driven heartbeat for long-running agent sessions.
Package heartbeat provides event-driven heartbeat for long-running agent sessions.
registry
Package registry is a JSON-backed process registry for nightme.
Package registry is a JSON-backed process registry for nightme.
session
Package session — InputBuffer: in-memory queue of user messages arriving while Claude is busy.
Package session — InputBuffer: in-memory queue of user messages arriving while Claude is busy.
version
Package version holds the build-time identity of nightme.
Package version holds the build-time identity of nightme.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL