Automated Research Assistant System
An AI-driven agent manager for scientific research automation, powered by Claude Code's headless mode and MCP tools. Now with Slack integration!
Features โข Installation โข Usage โข TUI โข Slack โข Examples
NightShift is a working prototype that automates research tasks using Claude Code in headless mode. The system uses a "task planner" agent to analyze requests, select appropriate tools, and execute tasks through a staged approval workflow.
graph TD
A[User Request] --> B[Task Planner Agent]
B --> C{Analyzes task<br/>Selects MCP tools<br/>Estimates resources}
C --> D[Task Queue<br/>STAGED]
D --> E{User Approval}
E --> F[Executor Agent<br/>Claude headless]
F --> G{Executes with tools<br/>Tracks file changes}
G --> H[Notification + Results]
style A fill:#e1f5ff
style B fill:#fff4e1
style D fill:#ffe1f5
style F fill:#fff4e1
style H fill:#e1ffe1
nightshift/
โโโ core/ # Core system components
โ โโโ agent_manager.py # Orchestrates Claude headless processes
โ โโโ task_planner.py # Plans tasks using Claude
โ โโโ task_queue.py # SQLite-backed task queue
โ โโโ logger.py # Comprehensive logging
โ โโโ file_tracker.py # Monitors file changes
โ โโโ notifier.py # Task completion notifications (Terminal + Slack)
โ โโโ config.py # Configuration management
โโโ integrations/ # Third-party integrations (NEW!)
โ โโโ slack_client.py # Slack API wrapper
โ โโโ slack_handler.py # Slack event routing
โ โโโ slack_server.py # Flask webhook server
โ โโโ slack_formatter.py # Block Kit message formatting
โ โโโ slack_metadata.py # Task metadata persistence
โ โโโ slack_middleware.py # Request verification
โโโ interfaces/ # User interfaces
โ โโโ cli.py # Command-line interface
โ โโโ tui/ # Interactive terminal UI
โ โโโ app.py # Application factory
โ โโโ controllers.py # Business logic layer
โ โโโ widgets.py # Custom prompt_toolkit controls
โ โโโ keybindings.py # Keyboard shortcuts
โ โโโ layout.py # UI layout composition
โ โโโ models.py # Data structures
โโโ config/ # Configuration files
โโโ claude-code-tools-reference.md # MCP tools reference
All NightShift data is stored in ~/.nightshift/:
~/.nightshift/
โโโ config/
โ โโโ slack_config.json # Slack credentials (secure)
โโโ database/
โ โโโ nightshift.db # Task queue database
โโโ logs/
โ โโโ nightshift_YYYYMMDD.log # Execution logs
โโโ output/
โ โโโ task_XXX_output.json # Task outputs
โ โโโ task_XXX_files.json # File change tracking
โโโ notifications/
โ โโโ task_XXX_notification.json # Completion summaries
โโโ slack_metadata/
โโโ task_XXX_slack.json # Slack context (channel, user, thread)
|
|
cd nightshift
pip install -e .This installs all required dependencies including:
- Claude Code CLI (via Claude Agent SDK)
- prompt-toolkit (for interactive TUI)
- Slack SDK (for Slack integration)
- Flask (for webhook server)
- Rich (for beautiful terminal output)
Optional: For Slack integration, you'll also need:
- A Slack workspace and app
- Bot token and signing secret (get via
nightshift slack-setup) - ngrok or similar for local testing (see SLACK_QUICK_START.md)
๐ Submit a task
# Submit and wait for approval
nightshift submit "Download and summarize arxiv paper 2510.13997 using Gemini"
# Auto-approve and execute immediately
nightshift submit "Download arxiv paper 2510.13997" --auto-approve๐ View task queue
# View all tasks
nightshift queue
# Filter by status
nightshift queue --status staged
nightshift queue --status completedโ Approve and execute
nightshift approve task_3acf60c6โ๏ธ Revise a plan
# Request changes to a staged task plan
nightshift revise task_3acf60c6 "Use Claude instead of Gemini for summarization"
# Revise again with more feedback
nightshift revise task_3acf60c6 "Also save the summary as a PDF file"๐ View results
# Basic info
nightshift results task_3acf60c6
# Show full output (raw JSON)
nightshift results task_3acf60c6 --show-output๐๏ธ Display execution (NEW!)
# View task execution in human-readable format
# Shows Claude's responses, tool calls, and results as they happened
nightshift display task_3acf60c6This command parses the stream-json output and displays it like an actual Claude session:
- ๐ฌ Claude's messages and reasoning
- ๐ง Tool calls with parameters
- โ Tool results and errors
- ๐ Token usage and cost statistics
Perfect for debugging and understanding what happened during execution!
โ Cancel a task
nightshift cancel task_3acf60c6๐๏ธ Clear all data
# With confirmation
nightshift clear
# Skip confirmation
nightshift clear --confirmโจ๏ธ Shell Autocomplete (NEW!)
# Auto-detect shell and install completion
nightshift completion --install
# Show instructions for specific shell
nightshift completion --shell zsh
nightshift completion --shell bash
nightshift completion --shell fish
# Reload your shell
source ~/.zshrc # or ~/.bashrc for bashWhat gets autocompleted:
- โ
Commands:
nightshift sub<TAB>โnightshift submit - โ
Subcommands:
nightshift executor st<TAB>โnightshift executor start - โ
Options:
nightshift queue --st<TAB>โnightshift queue --status - โ
Status values:
nightshift queue --status <TAB>โ shows all status options - โ
Task IDs (dynamic):
nightshift approve task_<TAB>โ shows all staged tasks - โ
Context-aware task filtering:
approveandreviseโ only STAGED taskscancelโ only STAGED or COMMITTED taskspause,resume,killโ only RUNNING or PAUSED tasksresults,display,watchโ all tasks
Supported shells: Bash (4.4+), Zsh, Fish, PowerShell
This significantly improves CLI usability by reducing typos and helping discover available commands!
๐ Concurrent Execution (NEW!)
# Start executor service (processes tasks in background)
nightshift executor start
# Start with custom settings
nightshift executor start --workers 5 --poll-interval 2.0
# Check executor status
nightshift executor status
# Stop executor service
nightshift executor stop
# Submit task with custom timeout (default: 900s / 15 minutes)
nightshift submit "Download paper" --timeout 300
# Submit and execute synchronously (wait for completion)
nightshift submit "Quick task" --auto-approve --syncHow it works:
- Executor polls the queue for
COMMITTEDtasks and executes them concurrently - Configure max workers (default: 3) and poll interval (default: 1.0s)
- Each task has a configurable timeout to prevent runaway executions
- Tasks can be submitted from multiple terminals/Slack simultaneously
- Executor can be controlled from any terminal using PID file tracking
Benefits:
- โก Multiple tasks execute in parallel
- ๐ Submit tasks while others are running
- ๐ฏ No blocking - submit and move on
- ๐ก๏ธ Timeouts prevent hanging tasks
NightShift includes a full-featured interactive terminal interface for task management.
โจ๏ธ Keybindings
| Key | Action |
|---|---|
j / โ |
Move down in task list |
k / โ |
Move up in task list |
Enter / a |
Approve selected task |
r |
Reject/cancel task |
e |
Review/edit task plan (opens $EDITOR) |
d |
Delete task |
Tab |
Cycle detail tabs (overview/execution/files/summary) |
: |
Enter command mode |
q |
Quit |
Command mode (:):
:queue [status]- Filter tasks by status:submit <description>- Submit new task:submit! <description>- Submit and auto-approve:refresh- Refresh task list:help- Show available commands:quit- Exit TUI
NightShift can be controlled entirely through Slack, allowing you to submit tasks, approve them with buttons, and receive detailed completion notifications - all without leaving Slack!
๐ Setup (5 minutes)
-
Create Slack App (if not already done)
- Go to https://api.slack.com/apps
- Create a new app for your workspace
- Add bot token scopes:
commands,chat:write,chat:write.public,files:write - Install to workspace and copy the Bot Token
-
Configure NightShift
nightshift slack-setup
Follow prompts to enter your bot token and signing secret.
-
Start Server
nightshift slack-server
-
Expose with ngrok (for testing)
ngrok http 5000
Copy the ngrok URL and update your Slack app settings:
- Slash Commands URL:
https://YOUR-NGROK-URL/slack/commands - Interactivity URL:
https://YOUR-NGROK-URL/slack/interactions
- Slash Commands URL:
๐ Full guide: SLACK_QUICK_START.md
๐ Submit a task
/nightshift submit "download and summarize arxiv paper 2510.13997"
What happens:
- ๐ Immediate response: "Planning task... (30-120s)"
- ๐ Approval message appears with buttons
- โ Click "Approve" โ Task executes
- ๐จ Completion notification with results
๐ View queue
/nightshift queue
/nightshift queue staged
Shows all tasks or filtered by status.
๐ Check status
/nightshift status task_abc123
Shows current status, creation time, and output path.
๐๏ธ Process control
/nightshift pause task_abc123
/nightshift resume task_abc123
/nightshift kill task_abc123
/nightshift cancel task_abc123
Control running and queued tasks.
Every approval message includes:
- โ Approve - Execute the task
- โ Reject - Cancel the task
- โน๏ธ Details - View full task details (ephemeral message)
When a task completes, you'll receive a detailed notification showing:
- What you asked for - Original task description
- What NightShift found/created - Claude's actual response (first 1000 chars)
- What NightShift did - List of files created/modified/deleted
- Execution metrics - Time, tokens, status
- Full results path - Link to complete output file
You: /nightshift submit "fetch today's top 3 BBC headlines"
NightShift: ๐ Planning task... This may take 30-120 seconds.
[30s later]
NightShift: ๐ฏ Task Plan: task_abc123
Description: Fetch today's main headlines from the BBC news website...
Tools: WebFetch
Estimated: ~800 tokens, ~20s
[โ
Approve] [โ Reject] [โน๏ธ Details]
You: *clicks โ
Approve*
NightShift: โ
Task task_abc123 approved by @you
โณ Executing...
[20s later]
NightShift: โ
Task SUCCESS: task_abc123
What you asked for:
Fetch today's top 3 BBC headlines
What NightShift found/created:
Here are today's top 3 BBC headlines:
1. Breaking: Major Political Development - Prime Minister announces...
2. International Crisis Update - Tensions rise as...
3. Technology Breakthrough - Scientists discover...
Status: SUCCESS
Execution Time: 21.5s
Tokens Used: 465
๐ Full results: ~/.nightshift/output/task_abc123_output.json
๐ Full documentation: TESTING_SLACK_INTEGRATION.md
$ nightshift submit "Download arxiv paper 2510.13997 and summarize using Gemini"
Planning task...
โ Task created: task_3acf60c6
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ Task Plan โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ Tools needed: mcp__arxiv__download, Read, mcp__gemini__ask, Write โ
โ Estimated: ~3500 tokens, ~90s โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โธ Status: STAGED (waiting for approval)
Run 'nightshift approve task_3acf60c6' to execute
Or 'nightshift revise task_3acf60c6 "feedback"' to request changes
$ nightshift approve task_3acf60c6
โ Task approved: task_3acf60c6
โถ Executing...
[... execution logs ...]
โ Task completed successfully!
Token usage: 3017
Execution time: 122.9s
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
## โ
Task Completed: task_3acf60c6
**Description:** Download the ArXiv paper with ID 2510.13997...
**Status:** SUCCESS
**Execution Time:** 122.9s
**Token Usage:** 3017
### File Changes
**Created (2):**
- โจ 2510.13997.pdf
- โจ arxiv_2510.13997_summary.md
**Results:** output/task_3acf60c6_output.json
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ$ nightshift submit "Download the mcp-handley-lab repository from the handley-lab GitHub organization and create a pull request addressing issue #50"
Planning task...
โ Task created: task_7d2a1f9b
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ Task Plan โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ Tools needed: Bash, Read, Write, Edit, Glob, Grep โ
โ Estimated: ~2000 tokens, ~120s โ
โ Reasoning: Clone repo, analyze issue, implement fix, create PR โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โธ Status: STAGED (waiting for approval)
Run 'nightshift approve task_7d2a1f9b' to execute
$ nightshift approve task_7d2a1f9b
โ Task approved: task_7d2a1f9b
โถ Executing...
[... cloning repository ...]
[... analyzing issue #50 ...]
[... implementing fix ...]
[... creating pull request ...]
โ Task completed successfully!
Token usage: 1847
Execution time: 98.3s
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
## โ
Task Completed: task_7d2a1f9b
**Description:** Download the mcp-handley-lab repository...
**Status:** SUCCESS
**Execution Time:** 98.3s
**Token Usage:** 1847
### File Changes
**Created (1):**
- โจ mcp-handley-lab/ (repository directory)
**Modified (3):**
- ๐ mcp-handley-lab/src/fix_file.py
- ๐ mcp-handley-lab/tests/test_fix.py
- ๐ mcp-handley-lab/README.md
**Pull Request:** https://github.com/handley-lab/mcp-handley-lab/pull/123
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ$ nightshift submit "Analyze the latest trends in quantum computing"
Planning task...
โ Task created: task_9b4e2c1a
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ Task Plan โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ Enhanced prompt: Search for and analyze recent quantum computing papers โ
โ Tools needed: WebSearch, Write โ
โ Estimated: ~1500 tokens, ~60s โ
โ Reasoning: Use web search to find trends, compile analysis โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โธ Status: STAGED (waiting for approval)
Run 'nightshift approve task_9b4e2c1a' to execute
Or 'nightshift revise task_9b4e2c1a "feedback"' to request changes
$ nightshift revise task_9b4e2c1a "Focus on arxiv papers from 2024, not web search"
Revising plan based on feedback...
โ Plan revised: task_9b4e2c1a
โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ Revised Plan โโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ Revised prompt: Search arxiv for quantum computing papers from 2024... โ
โ Tools needed: mcp__arxiv__search, Read, mcp__gemini__ask, Write โ
โ Estimated: ~2500 tokens, ~120s โ
โ Changes: Switched from WebSearch to ArXiv tools, added Gemini for โ
โ analysis, increased time estimate for paper processing โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
Status: STAGED (waiting for approval)
Run 'nightshift approve task_9b4e2c1a' to execute
Or 'nightshift revise task_9b4e2c1a "more feedback"' to revise again
$ nightshift approve task_9b4e2c1a
โ Task approved: task_9b4e2c1a
โถ Executing...
[... execution with revised plan ...]
โ Task completed successfully!Technical Details
- ๐ฏ Task planner uses
claude -pwith--json-schemato ensure structured output - โ๏ธ Executor uses
claude -pwith--verbose --output-format stream-json - ๐ธ File tracking takes snapshots before/after execution
- โฑ๏ธ Configurable timeouts per task (default: 900s / 15 minutes)
- ๐ All Claude calls are subprocess executions (no SDK)
- ๐ ThreadPoolExecutor for concurrent task execution (not ProcessPoolExecutor, since Claude CLI already spawns subprocesses)
- ๐๏ธ SQLite WAL mode for concurrent database access
- ๐ Atomic task acquisition with
BEGIN IMMEDIATEto prevent race conditions - ๐ PID file tracking for cross-process executor control
- ๐ HMAC-SHA256 signature verification for all webhook requests
- โฐ Timestamp-based replay attack prevention (5-minute window)
- ๐ฆ Rate limiting: 10/min for commands, 20/min for interactions
- ๐งต Threading support for async planning and execution
- ๐พ Metadata persistence for tracking Slack context (channel, user, thread)
- ๐ฆ Block Kit formatting for rich interactive messages
- Credentials stored in
~/.nightshift/config/(never in git) - Request body caching for signature verification
- DM channel detection (use user_id instead of channel_id)
- Graceful error handling with user feedback
Built with Claude Code โข Powered by MCP
Made with โค๏ธ for researchers and developers