nightshift-mcp 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,799 +1,799 @@
1
- # NightShift MCP
2
-
3
- **The responsible kind of multi-agent chaos.**
4
-
5
- Explicit delegation, review, and handoffs between AI models.
6
-
7
- ---
8
-
9
- An MCP (Model Context Protocol) server that enables multi-agent communication and task coordination via shared files. Designed for AI agents (Claude, Codex, Gemini, etc.) to collaborate autonomously with minimal human intervention.
10
-
11
- ## Features
12
-
13
- - **Multi-agent chat**: Structured messages with agent name, timestamp, type, and content
14
- - **Failover handling**: Seamless handoffs when an agent hits limits
15
- - **Ralph-style PRD management**: Work through user stories in prd.json with Zod-validated schemas and helpful error messages
16
- - **Progress tracking**: Shared learnings via progress.txt
17
- - **Agent spawning & orchestration**: Spawn Claude, Codex, Gemini, or Vibe as subprocesses with full lifecycle tracking
18
- - **Autonomous orchestration**: Single `orchestrate` tool runs a claim→implement→complete loop until all stories pass
19
- - **Agent status tracking**: Monitor spawned agents by PID, check exit codes, and tail output in real-time
20
- - **Smart retry**: Automatically suggests or uses a different agent when one fails
21
- - **Workflow management**: Phases, strategic decisions, and agent assignments
22
- - **Watch/polling**: Monitor for new messages with cursor-based polling
23
- - **Auto-archiving**: Archive old messages to keep the chat file manageable
24
- - **Cross-platform**: Works on Windows, Linux, and macOS (uses cross-spawn and platform-safe process management)
25
- - **Universal compatibility**: Works with any MCP-supporting tool (42 tools across 8 categories)
26
- - **Simple file-based storage**: No external services required
27
-
28
- ## Installation
29
-
30
- **Via npm (recommended):**
31
- ```bash
32
- npm install -g nightshift-mcp
33
- ```
34
-
35
- **Updating:**
36
- ```bash
37
- npm update -g nightshift-mcp
38
- ```
39
-
40
- **Or build from source:**
41
- ```bash
42
- git clone <repo-url>
43
- cd nightshift-mcp
44
- npm install
45
- npm run build
46
- npm link # makes 'nightshift-mcp' available globally
47
- ```
48
-
49
- ## Configuration
50
-
51
- ### Claude Code (`~/.claude.json`)
52
-
53
- ```json
54
- {
55
- "mcpServers": {
56
- "nightshift": {
57
- "command": "nightshift-mcp",
58
- "args": []
59
- }
60
- }
61
- }
62
- ```
63
-
64
- ### Codex (`~/.codex/config.toml`)
65
-
66
- ```toml
67
- [mcp_servers.nightshift]
68
- command = "nightshift-mcp"
69
- args = []
70
- ```
71
-
72
- The server automatically uses the current working directory for the `.robot-chat/` folder. You can override this with the `ROBOT_CHAT_PROJECT_PATH` environment variable if needed.
73
-
74
- ## Usage
75
-
76
- For agents to communicate, they must be running in the **same project directory**. The chat file is created at `<project>/.robot-chat/chat.txt` based on where each CLI is started.
77
-
78
- **Example - two agents working on the same project:**
79
-
80
- ```bash
81
- # Terminal 1
82
- cd ~/myproject
83
- claude
84
-
85
- # Terminal 2
86
- cd ~/myproject
87
- codex
88
- ```
89
-
90
- Both agents now share the same chat file and can coordinate via the nightshift tools.
91
-
92
- **Note:** If agents are started in different directories, they will have separate chat files and won't be able to communicate.
93
-
94
- ## Tools
95
-
96
- ### `read_robot_chat`
97
-
98
- Read recent messages from the chat file.
99
-
100
- **Parameters:**
101
- - `limit` (optional): Maximum messages to return (default: 20)
102
- - `agent` (optional): Filter by agent name
103
- - `type` (optional): Filter by message type
104
-
105
- **Example:**
106
- ```
107
- Read the last 10 messages from Claude
108
- ```
109
-
110
- ### `write_robot_chat`
111
-
112
- Write a message to the chat file.
113
-
114
- **Parameters:**
115
- - `agent` (required): Your agent name (e.g., "Claude", "Codex")
116
- - `type` (required): Message type
117
- - `content` (required): Message content
118
-
119
- **Message Types:**
120
- - `FAILOVER_NEEDED` - Request another agent to take over
121
- - `FAILOVER_CLAIMED` - Acknowledge taking over a task
122
- - `TASK_COMPLETE` - Mark a task as finished
123
- - `STATUS_UPDATE` - Share progress update
124
- - `HANDOFF` - Pass work to a specific agent
125
- - `INFO` - General information
126
- - `ERROR` - Error report
127
- - `QUESTION` - Ask other agents a question
128
- - `ANSWER` - Answer a question
129
-
130
- **Example:**
131
- ```
132
- Post a STATUS_UPDATE from Claude about completing the login form
133
- ```
134
-
135
- ### `check_failovers`
136
-
137
- Find unclaimed FAILOVER_NEEDED messages.
138
-
139
- **Example:**
140
- ```
141
- Check if any agent needs help with their task
142
- ```
143
-
144
- ### `claim_failover`
145
-
146
- Claim a failover request from another agent.
147
-
148
- **Parameters:**
149
- - `agent` (required): Your agent name
150
- - `originalAgent` (required): Agent who requested failover
151
- - `task` (optional): Task description
152
-
153
- **Example:**
154
- ```
155
- Claim the failover from Codex and continue working on the authentication feature
156
- ```
157
-
158
- ### `get_chat_path`
159
-
160
- Get the full path to the chat file.
161
-
162
- ### `list_agents`
163
-
164
- List all agents who have posted to the chat, with their activity stats.
165
-
166
- **Returns:**
167
- - Agent name
168
- - Last seen timestamp
169
- - Last message type
170
- - Total message count
171
-
172
- **Example:**
173
- ```
174
- Show me which agents have been active in the chat
175
- ```
176
-
177
- ### `watch_chat`
178
-
179
- Poll for new messages since a cursor position. Useful for monitoring the chat for updates.
180
-
181
- **Parameters:**
182
- - `cursor` (optional): Line number from previous watch call. Omit to get current cursor.
183
-
184
- **Returns:**
185
- - `cursor`: Updated cursor for next call
186
- - `messageCount`: Number of new messages
187
- - `messages`: Array of new messages
188
-
189
- **Example workflow:**
190
- ```
191
- 1. Call watch_chat without cursor to get initial position
192
- 2. Store the returned cursor value
193
- 3. Call watch_chat with that cursor to get new messages
194
- 4. Update your cursor with the returned value
195
- 5. Repeat step 3-4 to poll for updates
196
- ```
197
-
198
- ### `archive_chat`
199
-
200
- Archive old messages to a date-stamped file, keeping recent messages in main chat.
201
-
202
- **Parameters:**
203
- - `keepRecent` (optional): Number of messages to keep (default: 50)
204
-
205
- **Example:**
206
- ```
207
- Archive old messages, keeping the last 20
208
- ```
209
-
210
- ## Chat File Format
211
-
212
- Messages are stored in a human-readable format:
213
-
214
- ```
215
- # Robot Chat - Multi-Agent Communication
216
- # Format: [AgentName @ HH:MM] MESSAGE_TYPE
217
- # ========================================
218
-
219
- [Claude @ 14:32] STATUS_UPDATE
220
- Working on implementing the login form.
221
- Files modified: src/components/LoginForm.tsx
222
-
223
- [Codex @ 14:45] FAILOVER_NEEDED
224
- Status: Hit rate limit
225
- Current Task: Implementing user authentication
226
- Progress: 60% - login form done, need logout and session handling
227
- Files Modified: src/auth/login.tsx, src/api/auth.ts
228
-
229
- Requesting another agent continue this work.
230
-
231
- [Claude @ 14:47] FAILOVER_CLAIMED
232
- Claiming failover from Codex.
233
- Continuing task: Implementing user authentication
234
- ```
235
-
236
- ## Testing
237
-
238
- ### With MCP Inspector
239
-
240
- ```bash
241
- npx @modelcontextprotocol/inspector node /path/to/nightshift-mcp/dist/index.js /tmp/test-project
242
- ```
243
-
244
- ### Manual Testing
245
-
246
- ```bash
247
- # Set project path and run
248
- ROBOT_CHAT_PROJECT_PATH=/tmp/test-project node dist/index.js
249
- ```
250
-
251
- ## Development
252
-
253
- ```bash
254
- # Watch mode for development
255
- npm run dev
256
-
257
- # Build
258
- npm run build
259
- ```
260
-
261
- ## Ralph-Style Task Management
262
-
263
- NightShift includes Ralph-compatible PRD and progress management, enabling structured autonomous development.
264
-
265
- ### Setup
266
-
267
- 1. Create a `prd.json` in your project root:
268
-
269
- ```json
270
- {
271
- "project": "MyApp",
272
- "description": "Feature description",
273
- "userStories": [
274
- {
275
- "id": "US-001",
276
- "title": "Add database field",
277
- "description": "As a developer, I need to store the new field",
278
- "acceptanceCriteria": [
279
- "Add column to table",
280
- "Run migration",
281
- "Typecheck passes"
282
- ],
283
- "priority": 1,
284
- "passes": false,
285
- "notes": ""
286
- }
287
- ]
288
- }
289
- ```
290
-
291
- ### PRD Schema
292
-
293
- | Field | Type | Required | Default | Description |
294
- |-------|------|----------|---------|-------------|
295
- | `project` | string | no | — | Project name |
296
- | `description` | string | no | "" | Project description |
297
- | **`userStories`** | array | **yes** | — | Array of user story objects |
298
-
299
- **User Story fields:**
300
-
301
- | Field | Type | Required | Default | Description |
302
- |-------|------|----------|---------|-------------|
303
- | **`id`** | string | **yes** | — | Unique ID (e.g., "US-001") |
304
- | **`title`** | string | **yes** | — | Short title |
305
- | `description` | string | no | "" | Detailed description |
306
- | `acceptanceCriteria` | string[] | no | [] | Criteria for completion |
307
- | `priority` | number | no | 999 | Lower = higher priority |
308
- | `passes` | boolean | no | false | Whether the story is complete |
309
- | `notes` | string | no | "" | Implementation notes |
310
-
311
- ### PRD Validation
312
-
313
- NightShift validates your `prd.json` with Zod schemas and provides helpful error messages when common mistakes are detected:
314
-
315
- - Using `stories` instead of `userStories` → suggests the correct field name
316
- - Using `acceptance_criteria` instead of `acceptanceCriteria` → suggests the correct field name
317
- - Missing required fields (`id`, `title`) → identifies which story has the issue
318
- - Optional fields default gracefully (`passes` → false, `notes` → "", `acceptanceCriteria` → [])
319
-
320
- Use `nightshift_setup(showExamples: true)` for the full schema reference and examples.
321
-
322
- 2. Agents use these tools to work through stories:
323
-
324
- ### PRD Tools
325
-
326
- #### `read_prd`
327
- Read the full PRD with completion summary.
328
-
329
- #### `get_next_story`
330
- Get the highest priority incomplete story.
331
-
332
- #### `get_incomplete_stories`
333
- List all remaining work.
334
-
335
- #### `claim_story`
336
- Claim a story and notify other agents via chat.
337
-
338
- **Parameters:**
339
- - `agent` (required): Your agent name
340
- - `storyId` (optional): Specific story to claim
341
-
342
- #### `complete_story`
343
- Mark story complete, log progress, and notify via chat.
344
-
345
- **Parameters:**
346
- - `agent` (required): Your agent name
347
- - `storyId` (required): Story ID
348
- - `summary` (required): What was implemented
349
- - `filesModified` (optional): List of changed files
350
- - `learnings` (optional): Gotchas/patterns for future iterations
351
-
352
- #### `mark_story_complete`
353
- Just mark a story as complete without chat notification.
354
-
355
- **Parameters:**
356
- - `storyId` (required): Story ID
357
- - `notes` (optional): Implementation notes
358
-
359
- ### Progress Tools
360
-
361
- #### `read_progress`
362
- Read progress.txt containing learnings from all iterations.
363
-
364
- #### `append_progress`
365
- Add a timestamped progress entry.
366
-
367
- **Parameters:**
368
- - `content` (required): What was done, files changed, learnings
369
-
370
- #### `add_codebase_pattern`
371
- Add a reusable pattern to the Codebase Patterns section.
372
-
373
- **Parameters:**
374
- - `pattern` (required): The pattern (e.g., "Use sql<number> for aggregations")
375
-
376
- ### Autonomous Workflow
377
-
378
- With multiple agents working together:
379
-
380
- ```
381
- ┌─────────────────────────────────────────────────────────────┐
382
- │ NightShift Workflow │
383
- ├─────────────────────────────────────────────────────────────┤
384
- │ │
385
- │ ┌────────┐ ┌────────┐ ┌────────┐ ┌────────┐ │
386
- │ │ Claude │ │ Codex │ │ Gemini │ │ Vibe │ │
387
- │ └───┬────┘ └───┬────┘ └───┬────┘ └───┬────┘ │
388
- │ │ │ │ │ │
389
- │ └───────────┴─────┬─────┴───────────┘ │
390
- │ │ │
391
- │ ▼ │
392
- │ ┌─────────────────┐ │
393
- │ │ .robot-chat/ │ ◄── Agent coordination │
394
- │ │ chat.txt │ │
395
- │ └─────────────────┘ │
396
- │ │ │
397
- │ ┌───────────────┼───────────────┐ │
398
- │ │ │ │ │
399
- │ ▼ ▼ ▼ │
400
- │ ┌─────────┐ ┌──────────┐ ┌────────────┐ │
401
- │ │ prd.json│ │progress. │ │ Code │ │
402
- │ │ (tasks) │ │ txt │ │ Changes │ │
403
- │ └─────────┘ └──────────┘ └────────────┘ │
404
- │ │
405
- └─────────────────────────────────────────────────────────────┘
406
- ```
407
-
408
- Each agent:
409
- 1. Checks for failovers (helps stuck agents first)
410
- 2. Reads progress.txt for codebase patterns
411
- 3. Claims the next story via chat
412
- 4. Implements the story
413
- 5. Runs quality checks
414
- 6. Commits changes
415
- 7. Marks complete and logs learnings
416
- 8. Repeats until all stories pass
417
-
418
- When an agent hits limits, it posts `FAILOVER_NEEDED` and another agent claims the work.
419
-
420
- ### Completion Signal
421
-
422
- When all stories in prd.json have `passes: true` AND all bugs in bugs.json have `fixed: true`, the tools:
423
-
424
- 1. Post a `READY_TO_TEST` message to the chat
425
- 2. Return `<promise>COMPLETE</promise>`
426
-
427
- This signals to humans that work is ready for review.
428
-
429
- ## Bug Tracking
430
-
431
- When testing reveals issues, add a `bugs.json` file:
432
-
433
- ```json
434
- {
435
- "project": "MyApp",
436
- "bugs": [
437
- {
438
- "id": "BUG-001",
439
- "title": "Login fails on mobile",
440
- "description": "Login button unresponsive on iOS Safari",
441
- "stepsToReproduce": [
442
- "Open app on iOS Safari",
443
- "Enter credentials",
444
- "Tap login button",
445
- "Nothing happens"
446
- ],
447
- "priority": 1,
448
- "fixed": false
449
- }
450
- ]
451
- }
452
- ```
453
-
454
- ### Bug Tools
455
-
456
- #### `read_bugs`
457
- Read bugs.json with completion summary.
458
-
459
- #### `get_next_bug`
460
- Get highest priority unfixed bug.
461
-
462
- #### `claim_bug`
463
- Claim a bug and notify via chat.
464
-
465
- **Parameters:**
466
- - `agent` (required): Your agent name
467
- - `bugId` (optional): Specific bug to claim
468
-
469
- #### `mark_bug_fixed`
470
- Mark bug fixed, create savepoint, and notify.
471
-
472
- **Parameters:**
473
- - `agent` (required): Your agent name
474
- - `bugId` (required): Bug ID
475
- - `summary` (required): What was fixed
476
- - `filesModified` (optional): Files changed
477
-
478
- ## Savepoints (Recovery)
479
-
480
- Every completed story and fixed bug automatically creates a savepoint (git commit + tag). Use these for easy rollback if needed.
481
-
482
- ### Savepoint Tools
483
-
484
- #### `create_savepoint`
485
- Create a manual checkpoint.
486
-
487
- **Parameters:**
488
- - `label` (required): Savepoint name (e.g., "pre-refactor", "auth-working")
489
- - `message` (optional): Commit message
490
-
491
- #### `list_savepoints`
492
- List all savepoints (git tags with `savepoint/` prefix).
493
-
494
- #### `rollback_savepoint`
495
- Reset to a previous savepoint. **Warning:** Discards all changes after that point.
496
-
497
- **Parameters:**
498
- - `label` (required): Savepoint to rollback to
499
-
500
- ### Example Recovery
501
-
502
- ```bash
503
- # Something went wrong after US-003
504
- # List available savepoints
505
- list_savepoints
506
- # → savepoint/US-001, savepoint/US-002, savepoint/US-003
507
-
508
- # Rollback to after US-002
509
- rollback_savepoint("US-002")
510
- # → All changes after US-002 discarded
511
- ```
512
-
513
- ## Workflow Management
514
-
515
- NightShift includes workflow tools for tracking project phases, recording strategic decisions, and managing agent assignments.
516
-
517
- ### Workflow Tools
518
-
519
- #### `init_workflow`
520
- Initialize a new workflow with a project goal and optional custom phases.
521
-
522
- **Parameters:**
523
- - `projectGoal` (required): High-level goal of the project
524
- - `phases` (optional): Custom phases (default: research, decisions, planning, build, test, report)
525
-
526
- #### `get_workflow_state`
527
- Get the current workflow state including phase, assignments, and decisions.
528
-
529
- #### `advance_phase`
530
- Advance to the next workflow phase when the current phase's exit criteria are met.
531
-
532
- #### `set_phase`
533
- Manually set the workflow to a specific phase.
534
-
535
- **Parameters:**
536
- - `phase` (required): Target phase (research, decisions, planning, build, test, report, complete)
537
-
538
- #### `record_decision`
539
- Record a strategic decision with rationale for future reference.
540
-
541
- **Parameters:**
542
- - `topic` (required): What the decision is about
543
- - `options` (required): Options that were considered
544
- - `chosen` (required): The chosen option
545
- - `rationale` (required): Why this option was chosen
546
- - `decidedBy` (required): Agent or person who decided
547
-
548
- #### `get_decisions`
549
- Get all recorded decisions, optionally filtered by topic.
550
-
551
- #### `get_active_assignments`
552
- Get all stories currently being worked on by agents.
553
-
554
- #### `clear_assignment`
555
- Clear a story assignment (for abandonment/failover scenarios).
556
-
557
- ## Setup & Debugging
558
-
559
- NightShift includes self-service tools for setup and troubleshooting.
560
-
561
- ### `nightshift_setup`
562
-
563
- Get configuration instructions and verify project setup.
564
-
565
- **Parameters:**
566
- - `showExamples` (optional): Include prd.json and bugs.json templates
567
-
568
- **Returns:**
569
- - Project status checks (prd.json, bugs.json, git, .gitignore)
570
- - Agent configuration examples for Claude and Codex
571
- - Setup suggestions for any issues found
572
- - Example templates (if requested)
573
-
574
- **Example:**
575
- ```
576
- nightshift_setup(showExamples: true)
577
- ```
578
-
579
- ### `nightshift_debug`
580
-
581
- Diagnose issues and get troubleshooting guidance.
582
-
583
- **Checks:**
584
- - File system permissions
585
- - JSON file validation (prd.json, bugs.json)
586
- - Daemon lock status
587
- - Recent chat errors and unclaimed failovers
588
- - Agent availability
589
- - Git repository status
590
-
591
- **Example:**
592
- ```
593
- nightshift_debug
594
- # Returns detailed diagnostic report with suggested fixes
595
- ```
596
-
597
- ## Agent Spawning & Orchestration
598
-
599
- One agent can spawn others as subprocesses, enabling fully autonomous multi-agent workflows with minimal user intervention.
600
-
601
- ### Spawning Tools
602
-
603
- #### `list_available_agents`
604
- Check which agent CLIs (claude, codex, gemini, vibe) are installed and ready to run.
605
-
606
- #### `spawn_agent`
607
- Spawn another agent as a subprocess and wait for completion.
608
-
609
- **Parameters:**
610
- - `agent` (required): "claude", "codex", "gemini", or "vibe"
611
- - `prompt` (required): Task/prompt to send
612
- - `timeout` (optional): Seconds before timeout (default: 300)
613
-
614
- **Example:**
615
- ```
616
- spawn_agent(agent: "codex", prompt: "Fix the type errors in src/utils.ts")
617
- ```
618
-
619
- #### `spawn_agent_background`
620
- Spawn an agent in the background (non-blocking). Returns immediately with PID and output file path.
621
-
622
- **Parameters:**
623
- - `agent` (required): "claude", "codex", "gemini", or "vibe"
624
- - `prompt` (required): Task/prompt to send
625
-
626
- #### `delegate_story`
627
- Delegate a PRD user story to another agent with full context. On failure, returns a `retryHint` suggesting alternative available agents.
628
-
629
- **Parameters:**
630
- - `agent` (required): "claude", "codex", "gemini", or "vibe"
631
- - `storyId` (optional): Story ID to delegate (defaults to next available)
632
- - `background` (optional): Run in background (default: false)
633
-
634
- **Example:**
635
- ```
636
- delegate_story(agent: "gemini", storyId: "US-003", background: true)
637
- ```
638
-
639
- The spawned agent receives:
640
- - Full story description and acceptance criteria
641
- - Recent content from progress.txt
642
- - Recent chat messages for context
643
- - Instructions to use nightshift tools for coordination
644
-
645
- #### `delegate_research`
646
- Delegate a research or planning task to Gemini. Ideal for read-only tasks like codebase analysis, architecture planning, code review, and documentation.
647
-
648
- **Parameters:**
649
- - `task` (required): The research/planning task description
650
- - `context` (optional): Additional context to provide
651
- - `background` (optional): Run in background (default: false)
652
-
653
- ### Monitoring Tools
654
-
655
- #### `get_agent_status`
656
- Check the status of a spawned background agent by PID.
657
-
658
- **Parameters:**
659
- - `pid` (required): Process ID of the spawned agent
660
-
661
- **Returns:**
662
- - Whether the agent is still running or has exited
663
- - Exit code (if finished)
664
- - Last 30 lines of output
665
- - Story assignment (if delegated via `delegate_story`)
666
-
667
- #### `list_running_agents`
668
- List all agents spawned in the current session with their status.
669
-
670
- **Returns:** Array of agents with PID, agent type, running/exited status, elapsed time, and story assignment.
671
-
672
- ### Orchestration
673
-
674
- #### `orchestrate`
675
- Run an autonomous orchestration loop that claims stories, implements them, and marks them complete until all work is done. This is the highest-level automation tool.
676
-
677
- **Parameters:**
678
- - `agent` (optional): Your agent name (default: "NightShift")
679
- - `maxIterations` (optional): Maximum stories to process (default: 50)
680
- - `mode` (optional): "stories", "bugs", or "all" (default: "all")
681
-
682
- ### Orchestration Patterns
683
-
684
- **Fully autonomous (recommended):**
685
- ```
686
- orchestrate(agent: "Claude", mode: "all")
687
- # Runs until all stories and bugs are complete
688
- ```
689
-
690
- **Sequential delegation:**
691
- ```
692
- delegate_story(agent: "codex") # Wait for completion
693
- delegate_story(agent: "gemini") # Then delegate next
694
- ```
695
-
696
- **Parallel execution:**
697
- ```
698
- delegate_story(agent: "codex", storyId: "US-001", background: true)
699
- delegate_story(agent: "gemini", storyId: "US-002", background: true)
700
- # Work on US-003 yourself while they run in parallel
701
- # Monitor with get_agent_status or list_running_agents
702
- ```
703
-
704
- **Research then implement:**
705
- ```
706
- delegate_research(task: "Analyze auth patterns and recommend approach")
707
- # Use findings to inform implementation
708
- delegate_story(agent: "codex", storyId: "US-001")
709
- ```
710
-
711
- ## NightShift Daemon (Continuous Orchestration)
712
-
713
- For fully automated, event-driven orchestration, run the NightShift daemon:
714
-
715
- ```bash
716
- # Start the daemon
717
- nightshift-daemon
718
-
719
- # With options
720
- nightshift-daemon --verbose --max-agents 4 --health-check 1m
721
-
722
- # Preview mode (see what would happen)
723
- nightshift-daemon --dry-run --verbose
724
- ```
725
-
726
- ### How It Works
727
-
728
- The daemon provides hands-off multi-agent orchestration:
729
-
730
- 1. **Event-Driven**: Watches `prd.json` and `chat.txt` for changes
731
- 2. **Auto-Spawning**: Spawns agents for orphaned stories (up to concurrency limit)
732
- 3. **Failover Handling**: Automatically claims and reassigns failover requests
733
- 4. **Smart Retry**: Tracks failed agents per story and tries a different agent on retry
734
- 5. **Health Checks**: Periodic reconciliation as a fallback (default: every 2 min)
735
- 6. **Poison Pill Protection**: Quarantines stories that fail repeatedly
736
- 7. **Stuck Detection**: Kills agents that haven't reported activity
737
-
738
- ### Options
739
-
740
- | Flag | Description | Default |
741
- |------|-------------|---------|
742
- | `--verbose, -v` | Enable debug logging | false |
743
- | `--dry-run` | Show actions without spawning | false |
744
- | `--health-check <N>` | Health check interval (e.g., "2m", "30s") | 2m |
745
- | `--max-agents <N>` | Max concurrent agents | 3 |
746
-
747
- ### Environment
748
-
749
- - `ROBOT_CHAT_PROJECT_PATH` - Project directory (default: current directory)
750
-
751
- ### Architecture
752
-
753
- ```
754
- ┌─────────────────────────────────────────────────────────────┐
755
- │ NightShift Daemon │
756
- ├─────────────────────────────────────────────────────────────┤
757
- │ │
758
- │ ┌──────────────────────────────────────────────────┐ │
759
- │ │ File Watchers (Primary) │ │
760
- │ │ • prd.json changes → reconcile │ │
761
- │ │ • chat.txt changes → check failovers │ │
762
- │ └──────────────────────────────────────────────────┘ │
763
- │ │ │
764
- │ ▼ │
765
- │ ┌──────────────────────────────────────────────────┐ │
766
- │ │ Reconciliation Engine │ │
767
- │ │ • Find orphaned stories │ │
768
- │ │ • Spawn agents (up to max concurrency) │ │
769
- │ │ • Handle failovers │ │
770
- │ │ • Quarantine poison pills │ │
771
- │ └──────────────────────────────────────────────────┘ │
772
- │ │ │
773
- │ ▼ │
774
- │ ┌──────────────────────────────────────────────────┐ │
775
- │ │ Health Check (Fallback) │ │
776
- │ │ • Runs every 2 minutes │ │
777
- │ │ • Detects stuck agents │ │
778
- │ │ • Restarts watchers if needed │ │
779
- │ │ • Reconciles state │ │
780
- │ └──────────────────────────────────────────────────┘ │
781
- │ │
782
- └─────────────────────────────────────────────────────────────┘
783
- ```
784
-
785
- ## Multi-Agent Tips
786
-
787
- 1. **Same directory**: All agents must run in the same project directory to share chat
788
- 2. **Claim before working**: Always claim stories to prevent duplicate work
789
- 3. **Post status updates**: Keep other agents informed of progress
790
- 4. **Document learnings**: Progress.txt helps future iterations
791
- 5. **Handle failovers**: Check for and claim failovers at the start of each session
792
- 6. **Use delegation**: One orchestrating agent can spawn others for parallel work
793
- 7. **Monitor background agents**: Use `get_agent_status` and `list_running_agents` to track spawned agents
794
- 8. **Use `orchestrate` for full autonomy**: The `orchestrate` tool handles the entire claim→implement→complete loop
795
- 9. **Add `.robot-chat/` to your project's `.gitignore`**: Chat logs are ephemeral and shouldn't be committed
796
-
797
- ## License
798
-
799
- MIT
1
+ # NightShift MCP
2
+
3
+ **The responsible kind of multi-agent chaos.**
4
+
5
+ Explicit delegation, review, and handoffs between AI models.
6
+
7
+ ---
8
+
9
+ An MCP (Model Context Protocol) server that enables multi-agent communication and task coordination via shared files. Designed for AI agents (Claude, Codex, Gemini, etc.) to collaborate autonomously with minimal human intervention.
10
+
11
+ ## Features
12
+
13
+ - **Multi-agent chat**: Structured messages with agent name, timestamp, type, and content
14
+ - **Failover handling**: Seamless handoffs when an agent hits limits
15
+ - **Ralph-style PRD management**: Work through user stories in prd.json with Zod-validated schemas and helpful error messages
16
+ - **Progress tracking**: Shared learnings via progress.txt
17
+ - **Agent spawning & orchestration**: Spawn Claude, Codex, Gemini, or Vibe as subprocesses with full lifecycle tracking
18
+ - **Autonomous orchestration**: Single `orchestrate` tool runs a claim→implement→complete loop until all stories pass
19
+ - **Agent status tracking**: Monitor spawned agents by PID, check exit codes, and tail output in real-time
20
+ - **Smart retry**: Automatically suggests or uses a different agent when one fails
21
+ - **Workflow management**: Phases, strategic decisions, and agent assignments
22
+ - **Watch/polling**: Monitor for new messages with cursor-based polling
23
+ - **Auto-archiving**: Archive old messages to keep the chat file manageable
24
+ - **Cross-platform**: Works on Windows, Linux, and macOS (uses cross-spawn and platform-safe process management)
25
+ - **Universal compatibility**: Works with any MCP-supporting tool (42 tools across 8 categories)
26
+ - **Simple file-based storage**: No external services required
27
+
28
+ ## Installation
29
+
30
+ **Via npm (recommended):**
31
+ ```bash
32
+ npm install -g nightshift-mcp
33
+ ```
34
+
35
+ **Updating:**
36
+ ```bash
37
+ npm update -g nightshift-mcp
38
+ ```
39
+
40
+ **Or build from source:**
41
+ ```bash
42
+ git clone <repo-url>
43
+ cd nightshift-mcp
44
+ npm install
45
+ npm run build
46
+ npm link # makes 'nightshift-mcp' available globally
47
+ ```
48
+
49
+ ## Configuration
50
+
51
+ ### Claude Code (`~/.claude.json`)
52
+
53
+ ```json
54
+ {
55
+ "mcpServers": {
56
+ "nightshift": {
57
+ "command": "nightshift-mcp",
58
+ "args": []
59
+ }
60
+ }
61
+ }
62
+ ```
63
+
64
+ ### Codex (`~/.codex/config.toml`)
65
+
66
+ ```toml
67
+ [mcp_servers.nightshift]
68
+ command = "nightshift-mcp"
69
+ args = []
70
+ ```
71
+
72
+ The server automatically uses the current working directory for the `.robot-chat/` folder. You can override this with the `ROBOT_CHAT_PROJECT_PATH` environment variable if needed.
73
+
74
+ ## Usage
75
+
76
+ For agents to communicate, they must be running in the **same project directory**. The chat file is created at `<project>/.robot-chat/chat.txt` based on where each CLI is started.
77
+
78
+ **Example - two agents working on the same project:**
79
+
80
+ ```bash
81
+ # Terminal 1
82
+ cd ~/myproject
83
+ claude
84
+
85
+ # Terminal 2
86
+ cd ~/myproject
87
+ codex
88
+ ```
89
+
90
+ Both agents now share the same chat file and can coordinate via the nightshift tools.
91
+
92
+ **Note:** If agents are started in different directories, they will have separate chat files and won't be able to communicate.
93
+
94
+ ## Tools
95
+
96
+ ### `read_robot_chat`
97
+
98
+ Read recent messages from the chat file.
99
+
100
+ **Parameters:**
101
+ - `limit` (optional): Maximum messages to return (default: 20)
102
+ - `agent` (optional): Filter by agent name
103
+ - `type` (optional): Filter by message type
104
+
105
+ **Example:**
106
+ ```
107
+ Read the last 10 messages from Claude
108
+ ```
109
+
110
+ ### `write_robot_chat`
111
+
112
+ Write a message to the chat file.
113
+
114
+ **Parameters:**
115
+ - `agent` (required): Your agent name (e.g., "Claude", "Codex")
116
+ - `type` (required): Message type
117
+ - `content` (required): Message content
118
+
119
+ **Message Types:**
120
+ - `FAILOVER_NEEDED` - Request another agent to take over
121
+ - `FAILOVER_CLAIMED` - Acknowledge taking over a task
122
+ - `TASK_COMPLETE` - Mark a task as finished
123
+ - `STATUS_UPDATE` - Share progress update
124
+ - `HANDOFF` - Pass work to a specific agent
125
+ - `INFO` - General information
126
+ - `ERROR` - Error report
127
+ - `QUESTION` - Ask other agents a question
128
+ - `ANSWER` - Answer a question
129
+
130
+ **Example:**
131
+ ```
132
+ Post a STATUS_UPDATE from Claude about completing the login form
133
+ ```
134
+
135
+ ### `check_failovers`
136
+
137
+ Find unclaimed FAILOVER_NEEDED messages.
138
+
139
+ **Example:**
140
+ ```
141
+ Check if any agent needs help with their task
142
+ ```
143
+
144
+ ### `claim_failover`
145
+
146
+ Claim a failover request from another agent.
147
+
148
+ **Parameters:**
149
+ - `agent` (required): Your agent name
150
+ - `originalAgent` (required): Agent who requested failover
151
+ - `task` (optional): Task description
152
+
153
+ **Example:**
154
+ ```
155
+ Claim the failover from Codex and continue working on the authentication feature
156
+ ```
157
+
158
+ ### `get_chat_path`
159
+
160
+ Get the full path to the chat file.
161
+
162
+ ### `list_agents`
163
+
164
+ List all agents who have posted to the chat, with their activity stats.
165
+
166
+ **Returns:**
167
+ - Agent name
168
+ - Last seen timestamp
169
+ - Last message type
170
+ - Total message count
171
+
172
+ **Example:**
173
+ ```
174
+ Show me which agents have been active in the chat
175
+ ```
176
+
177
+ ### `watch_chat`
178
+
179
+ Poll for new messages since a cursor position. Useful for monitoring the chat for updates.
180
+
181
+ **Parameters:**
182
+ - `cursor` (optional): Line number from previous watch call. Omit to get current cursor.
183
+
184
+ **Returns:**
185
+ - `cursor`: Updated cursor for next call
186
+ - `messageCount`: Number of new messages
187
+ - `messages`: Array of new messages
188
+
189
+ **Example workflow:**
190
+ ```
191
+ 1. Call watch_chat without cursor to get initial position
192
+ 2. Store the returned cursor value
193
+ 3. Call watch_chat with that cursor to get new messages
194
+ 4. Update your cursor with the returned value
195
+ 5. Repeat step 3-4 to poll for updates
196
+ ```
197
+
198
+ ### `archive_chat`
199
+
200
+ Archive old messages to a date-stamped file, keeping recent messages in main chat.
201
+
202
+ **Parameters:**
203
+ - `keepRecent` (optional): Number of messages to keep (default: 50)
204
+
205
+ **Example:**
206
+ ```
207
+ Archive old messages, keeping the last 20
208
+ ```
209
+
210
+ ## Chat File Format
211
+
212
+ Messages are stored in a human-readable format:
213
+
214
+ ```
215
+ # Robot Chat - Multi-Agent Communication
216
+ # Format: [AgentName @ HH:MM] MESSAGE_TYPE
217
+ # ========================================
218
+
219
+ [Claude @ 14:32] STATUS_UPDATE
220
+ Working on implementing the login form.
221
+ Files modified: src/components/LoginForm.tsx
222
+
223
+ [Codex @ 14:45] FAILOVER_NEEDED
224
+ Status: Hit rate limit
225
+ Current Task: Implementing user authentication
226
+ Progress: 60% - login form done, need logout and session handling
227
+ Files Modified: src/auth/login.tsx, src/api/auth.ts
228
+
229
+ Requesting another agent continue this work.
230
+
231
+ [Claude @ 14:47] FAILOVER_CLAIMED
232
+ Claiming failover from Codex.
233
+ Continuing task: Implementing user authentication
234
+ ```
235
+
236
+ ## Testing
237
+
238
+ ### With MCP Inspector
239
+
240
+ ```bash
241
+ npx @modelcontextprotocol/inspector node /path/to/nightshift-mcp/dist/index.js /tmp/test-project
242
+ ```
243
+
244
+ ### Manual Testing
245
+
246
+ ```bash
247
+ # Set project path and run
248
+ ROBOT_CHAT_PROJECT_PATH=/tmp/test-project node dist/index.js
249
+ ```
250
+
251
+ ## Development
252
+
253
+ ```bash
254
+ # Watch mode for development
255
+ npm run dev
256
+
257
+ # Build
258
+ npm run build
259
+ ```
260
+
261
+ ## Ralph-Style Task Management
262
+
263
+ NightShift includes Ralph-compatible PRD and progress management, enabling structured autonomous development.
264
+
265
+ ### Setup
266
+
267
+ 1. Create a `prd.json` in your project root:
268
+
269
+ ```json
270
+ {
271
+ "project": "MyApp",
272
+ "description": "Feature description",
273
+ "userStories": [
274
+ {
275
+ "id": "US-001",
276
+ "title": "Add database field",
277
+ "description": "As a developer, I need to store the new field",
278
+ "acceptanceCriteria": [
279
+ "Add column to table",
280
+ "Run migration",
281
+ "Typecheck passes"
282
+ ],
283
+ "priority": 1,
284
+ "passes": false,
285
+ "notes": ""
286
+ }
287
+ ]
288
+ }
289
+ ```
290
+
291
+ ### PRD Schema
292
+
293
+ | Field | Type | Required | Default | Description |
294
+ |-------|------|----------|---------|-------------|
295
+ | `project` | string | no | — | Project name |
296
+ | `description` | string | no | "" | Project description |
297
+ | **`userStories`** | array | **yes** | — | Array of user story objects |
298
+
299
+ **User Story fields:**
300
+
301
+ | Field | Type | Required | Default | Description |
302
+ |-------|------|----------|---------|-------------|
303
+ | **`id`** | string | **yes** | — | Unique ID (e.g., "US-001") |
304
+ | **`title`** | string | **yes** | — | Short title |
305
+ | `description` | string | no | "" | Detailed description |
306
+ | `acceptanceCriteria` | string[] | no | [] | Criteria for completion |
307
+ | `priority` | number | no | 999 | Lower = higher priority |
308
+ | `passes` | boolean | no | false | Whether the story is complete |
309
+ | `notes` | string | no | "" | Implementation notes |
310
+
311
+ ### PRD Validation
312
+
313
+ NightShift validates your `prd.json` with Zod schemas and provides helpful error messages when common mistakes are detected:
314
+
315
+ - Using `stories` instead of `userStories` → suggests the correct field name
316
+ - Using `acceptance_criteria` instead of `acceptanceCriteria` → suggests the correct field name
317
+ - Missing required fields (`id`, `title`) → identifies which story has the issue
318
+ - Optional fields default gracefully (`passes` → false, `notes` → "", `acceptanceCriteria` → [])
319
+
320
+ Use `nightshift_setup(showExamples: true)` for the full schema reference and examples.
321
+
322
+ 2. Agents use these tools to work through stories:
323
+
324
+ ### PRD Tools
325
+
326
+ #### `read_prd`
327
+ Read the full PRD with completion summary.
328
+
329
+ #### `get_next_story`
330
+ Get the highest priority incomplete story.
331
+
332
+ #### `get_incomplete_stories`
333
+ List all remaining work.
334
+
335
+ #### `claim_story`
336
+ Claim a story and notify other agents via chat.
337
+
338
+ **Parameters:**
339
+ - `agent` (required): Your agent name
340
+ - `storyId` (optional): Specific story to claim
341
+
342
+ #### `complete_story`
343
+ Mark story complete, log progress, and notify via chat.
344
+
345
+ **Parameters:**
346
+ - `agent` (required): Your agent name
347
+ - `storyId` (required): Story ID
348
+ - `summary` (required): What was implemented
349
+ - `filesModified` (optional): List of changed files
350
+ - `learnings` (optional): Gotchas/patterns for future iterations
351
+
352
+ #### `mark_story_complete`
353
+ Just mark a story as complete without chat notification.
354
+
355
+ **Parameters:**
356
+ - `storyId` (required): Story ID
357
+ - `notes` (optional): Implementation notes
358
+
359
+ ### Progress Tools
360
+
361
+ #### `read_progress`
362
+ Read progress.txt containing learnings from all iterations.
363
+
364
+ #### `append_progress`
365
+ Add a timestamped progress entry.
366
+
367
+ **Parameters:**
368
+ - `content` (required): What was done, files changed, learnings
369
+
370
+ #### `add_codebase_pattern`
371
+ Add a reusable pattern to the Codebase Patterns section.
372
+
373
+ **Parameters:**
374
+ - `pattern` (required): The pattern (e.g., "Use sql<number> for aggregations")
375
+
376
+ ### Autonomous Workflow
377
+
378
+ With multiple agents working together:
379
+
380
+ ```
381
+ ┌─────────────────────────────────────────────────────────────┐
382
+ │ NightShift Workflow │
383
+ ├─────────────────────────────────────────────────────────────┤
384
+ │ │
385
+ │ ┌────────┐ ┌────────┐ ┌────────┐ ┌────────┐ │
386
+ │ │ Claude │ │ Codex │ │ Gemini │ │ Vibe │ │
387
+ │ └───┬────┘ └───┬────┘ └───┬────┘ └───┬────┘ │
388
+ │ │ │ │ │ │
389
+ │ └───────────┴─────┬─────┴───────────┘ │
390
+ │ │ │
391
+ │ ▼ │
392
+ │ ┌─────────────────┐ │
393
+ │ │ .robot-chat/ │ ◄── Agent coordination │
394
+ │ │ chat.txt │ │
395
+ │ └─────────────────┘ │
396
+ │ │ │
397
+ │ ┌───────────────┼───────────────┐ │
398
+ │ │ │ │ │
399
+ │ ▼ ▼ ▼ │
400
+ │ ┌─────────┐ ┌──────────┐ ┌────────────┐ │
401
+ │ │ prd.json│ │progress. │ │ Code │ │
402
+ │ │ (tasks) │ │ txt │ │ Changes │ │
403
+ │ └─────────┘ └──────────┘ └────────────┘ │
404
+ │ │
405
+ └─────────────────────────────────────────────────────────────┘
406
+ ```
407
+
408
+ Each agent:
409
+ 1. Checks for failovers (helps stuck agents first)
410
+ 2. Reads progress.txt for codebase patterns
411
+ 3. Claims the next story via chat
412
+ 4. Implements the story
413
+ 5. Runs quality checks
414
+ 6. Commits changes
415
+ 7. Marks complete and logs learnings
416
+ 8. Repeats until all stories pass
417
+
418
+ When an agent hits limits, it posts `FAILOVER_NEEDED` and another agent claims the work.
419
+
420
+ ### Completion Signal
421
+
422
+ When all stories in prd.json have `passes: true` AND all bugs in bugs.json have `fixed: true`, the tools:
423
+
424
+ 1. Post a `READY_TO_TEST` message to the chat
425
+ 2. Return `<promise>COMPLETE</promise>`
426
+
427
+ This signals to humans that work is ready for review.
428
+
429
+ ## Bug Tracking
430
+
431
+ When testing reveals issues, add a `bugs.json` file:
432
+
433
+ ```json
434
+ {
435
+ "project": "MyApp",
436
+ "bugs": [
437
+ {
438
+ "id": "BUG-001",
439
+ "title": "Login fails on mobile",
440
+ "description": "Login button unresponsive on iOS Safari",
441
+ "stepsToReproduce": [
442
+ "Open app on iOS Safari",
443
+ "Enter credentials",
444
+ "Tap login button",
445
+ "Nothing happens"
446
+ ],
447
+ "priority": 1,
448
+ "fixed": false
449
+ }
450
+ ]
451
+ }
452
+ ```
453
+
454
+ ### Bug Tools
455
+
456
+ #### `read_bugs`
457
+ Read bugs.json with completion summary.
458
+
459
+ #### `get_next_bug`
460
+ Get highest priority unfixed bug.
461
+
462
+ #### `claim_bug`
463
+ Claim a bug and notify via chat.
464
+
465
+ **Parameters:**
466
+ - `agent` (required): Your agent name
467
+ - `bugId` (optional): Specific bug to claim
468
+
469
+ #### `mark_bug_fixed`
470
+ Mark bug fixed, create savepoint, and notify.
471
+
472
+ **Parameters:**
473
+ - `agent` (required): Your agent name
474
+ - `bugId` (required): Bug ID
475
+ - `summary` (required): What was fixed
476
+ - `filesModified` (optional): Files changed
477
+
478
+ ## Savepoints (Recovery)
479
+
480
+ Every completed story and fixed bug automatically creates a savepoint (git commit + tag). Use these for easy rollback if needed.
481
+
482
+ ### Savepoint Tools
483
+
484
+ #### `create_savepoint`
485
+ Create a manual checkpoint.
486
+
487
+ **Parameters:**
488
+ - `label` (required): Savepoint name (e.g., "pre-refactor", "auth-working")
489
+ - `message` (optional): Commit message
490
+
491
+ #### `list_savepoints`
492
+ List all savepoints (git tags with `savepoint/` prefix).
493
+
494
+ #### `rollback_savepoint`
495
+ Reset to a previous savepoint. **Warning:** Discards all changes after that point.
496
+
497
+ **Parameters:**
498
+ - `label` (required): Savepoint to rollback to
499
+
500
+ ### Example Recovery
501
+
502
+ ```bash
503
+ # Something went wrong after US-003
504
+ # List available savepoints
505
+ list_savepoints
506
+ # → savepoint/US-001, savepoint/US-002, savepoint/US-003
507
+
508
+ # Rollback to after US-002
509
+ rollback_savepoint("US-002")
510
+ # → All changes after US-002 discarded
511
+ ```
512
+
513
+ ## Workflow Management
514
+
515
+ NightShift includes workflow tools for tracking project phases, recording strategic decisions, and managing agent assignments.
516
+
517
+ ### Workflow Tools
518
+
519
+ #### `init_workflow`
520
+ Initialize a new workflow with a project goal and optional custom phases.
521
+
522
+ **Parameters:**
523
+ - `projectGoal` (required): High-level goal of the project
524
+ - `phases` (optional): Custom phases (default: research, decisions, planning, build, test, report)
525
+
526
+ #### `get_workflow_state`
527
+ Get the current workflow state including phase, assignments, and decisions.
528
+
529
+ #### `advance_phase`
530
+ Advance to the next workflow phase when the current phase's exit criteria are met.
531
+
532
+ #### `set_phase`
533
+ Manually set the workflow to a specific phase.
534
+
535
+ **Parameters:**
536
+ - `phase` (required): Target phase (research, decisions, planning, build, test, report, complete)
537
+
538
+ #### `record_decision`
539
+ Record a strategic decision with rationale for future reference.
540
+
541
+ **Parameters:**
542
+ - `topic` (required): What the decision is about
543
+ - `options` (required): Options that were considered
544
+ - `chosen` (required): The chosen option
545
+ - `rationale` (required): Why this option was chosen
546
+ - `decidedBy` (required): Agent or person who decided
547
+
548
+ #### `get_decisions`
549
+ Get all recorded decisions, optionally filtered by topic.
550
+
551
+ #### `get_active_assignments`
552
+ Get all stories currently being worked on by agents.
553
+
554
+ #### `clear_assignment`
555
+ Clear a story assignment (for abandonment/failover scenarios).
556
+
557
+ ## Setup & Debugging
558
+
559
+ NightShift includes self-service tools for setup and troubleshooting.
560
+
561
+ ### `nightshift_setup`
562
+
563
+ Get configuration instructions and verify project setup.
564
+
565
+ **Parameters:**
566
+ - `showExamples` (optional): Include prd.json and bugs.json templates
567
+
568
+ **Returns:**
569
+ - Project status checks (prd.json, bugs.json, git, .gitignore)
570
+ - Agent configuration examples for Claude and Codex
571
+ - Setup suggestions for any issues found
572
+ - Example templates (if requested)
573
+
574
+ **Example:**
575
+ ```
576
+ nightshift_setup(showExamples: true)
577
+ ```
578
+
579
+ ### `nightshift_debug`
580
+
581
+ Diagnose issues and get troubleshooting guidance.
582
+
583
+ **Checks:**
584
+ - File system permissions
585
+ - JSON file validation (prd.json, bugs.json)
586
+ - Daemon lock status
587
+ - Recent chat errors and unclaimed failovers
588
+ - Agent availability
589
+ - Git repository status
590
+
591
+ **Example:**
592
+ ```
593
+ nightshift_debug
594
+ # Returns detailed diagnostic report with suggested fixes
595
+ ```
596
+
597
+ ## Agent Spawning & Orchestration
598
+
599
+ One agent can spawn others as subprocesses, enabling fully autonomous multi-agent workflows with minimal user intervention.
600
+
601
+ ### Spawning Tools
602
+
603
+ #### `list_available_agents`
604
+ Check which agent CLIs (claude, codex, gemini, vibe) are installed and ready to run.
605
+
606
+ #### `spawn_agent`
607
+ Spawn another agent as a subprocess and wait for completion.
608
+
609
+ **Parameters:**
610
+ - `agent` (required): "claude", "codex", "gemini", or "vibe"
611
+ - `prompt` (required): Task/prompt to send
612
+ - `timeout` (optional): Seconds before timeout (default: 300)
613
+
614
+ **Example:**
615
+ ```
616
+ spawn_agent(agent: "codex", prompt: "Fix the type errors in src/utils.ts")
617
+ ```
618
+
619
+ #### `spawn_agent_background`
620
+ Spawn an agent in the background (non-blocking). Returns immediately with PID and output file path.
621
+
622
+ **Parameters:**
623
+ - `agent` (required): "claude", "codex", "gemini", or "vibe"
624
+ - `prompt` (required): Task/prompt to send
625
+
626
+ #### `delegate_story`
627
+ Delegate a PRD user story to another agent with full context. On failure, returns a `retryHint` suggesting alternative available agents.
628
+
629
+ **Parameters:**
630
+ - `agent` (required): "claude", "codex", "gemini", or "vibe"
631
+ - `storyId` (optional): Story ID to delegate (defaults to next available)
632
+ - `background` (optional): Run in background (default: false)
633
+
634
+ **Example:**
635
+ ```
636
+ delegate_story(agent: "gemini", storyId: "US-003", background: true)
637
+ ```
638
+
639
+ The spawned agent receives:
640
+ - Full story description and acceptance criteria
641
+ - Recent content from progress.txt
642
+ - Recent chat messages for context
643
+ - Instructions to use nightshift tools for coordination
644
+
645
+ #### `delegate_research`
646
+ Delegate a research or planning task to Gemini. Ideal for read-only tasks like codebase analysis, architecture planning, code review, and documentation.
647
+
648
+ **Parameters:**
649
+ - `task` (required): The research/planning task description
650
+ - `context` (optional): Additional context to provide
651
+ - `background` (optional): Run in background (default: false)
652
+
653
+ ### Monitoring Tools
654
+
655
+ #### `get_agent_status`
656
+ Check the status of a spawned background agent by PID.
657
+
658
+ **Parameters:**
659
+ - `pid` (required): Process ID of the spawned agent
660
+
661
+ **Returns:**
662
+ - Whether the agent is still running or has exited
663
+ - Exit code (if finished)
664
+ - Last 30 lines of output
665
+ - Story assignment (if delegated via `delegate_story`)
666
+
667
+ #### `list_running_agents`
668
+ List all agents spawned in the current session with their status.
669
+
670
+ **Returns:** Array of agents with PID, agent type, running/exited status, elapsed time, and story assignment.
671
+
672
+ ### Orchestration
673
+
674
+ #### `orchestrate`
675
+ Run an autonomous orchestration loop that claims stories, implements them, and marks them complete until all work is done. This is the highest-level automation tool.
676
+
677
+ **Parameters:**
678
+ - `agent` (optional): Your agent name (default: "NightShift")
679
+ - `maxIterations` (optional): Maximum stories to process (default: 50)
680
+ - `mode` (optional): "stories", "bugs", or "all" (default: "all")
681
+
682
+ ### Orchestration Patterns
683
+
684
+ **Fully autonomous (recommended):**
685
+ ```
686
+ orchestrate(agent: "Claude", mode: "all")
687
+ # Runs until all stories and bugs are complete
688
+ ```
689
+
690
+ **Sequential delegation:**
691
+ ```
692
+ delegate_story(agent: "codex") # Wait for completion
693
+ delegate_story(agent: "gemini") # Then delegate next
694
+ ```
695
+
696
+ **Parallel execution:**
697
+ ```
698
+ delegate_story(agent: "codex", storyId: "US-001", background: true)
699
+ delegate_story(agent: "gemini", storyId: "US-002", background: true)
700
+ # Work on US-003 yourself while they run in parallel
701
+ # Monitor with get_agent_status or list_running_agents
702
+ ```
703
+
704
+ **Research then implement:**
705
+ ```
706
+ delegate_research(task: "Analyze auth patterns and recommend approach")
707
+ # Use findings to inform implementation
708
+ delegate_story(agent: "codex", storyId: "US-001")
709
+ ```
710
+
711
+ ## NightShift Daemon (Continuous Orchestration)
712
+
713
+ For fully automated, event-driven orchestration, run the NightShift daemon:
714
+
715
+ ```bash
716
+ # Start the daemon
717
+ nightshift-daemon
718
+
719
+ # With options
720
+ nightshift-daemon --verbose --max-agents 4 --health-check 1m
721
+
722
+ # Preview mode (see what would happen)
723
+ nightshift-daemon --dry-run --verbose
724
+ ```
725
+
726
+ ### How It Works
727
+
728
+ The daemon provides hands-off multi-agent orchestration:
729
+
730
+ 1. **Event-Driven**: Watches `prd.json` and `chat.txt` for changes
731
+ 2. **Auto-Spawning**: Spawns agents for orphaned stories (up to concurrency limit)
732
+ 3. **Failover Handling**: Automatically claims and reassigns failover requests
733
+ 4. **Smart Retry**: Tracks failed agents per story and tries a different agent on retry
734
+ 5. **Health Checks**: Periodic reconciliation as a fallback (default: every 2 min)
735
+ 6. **Poison Pill Protection**: Quarantines stories that fail repeatedly
736
+ 7. **Stuck Detection**: Kills agents that haven't reported activity
737
+
738
+ ### Options
739
+
740
+ | Flag | Description | Default |
741
+ |------|-------------|---------|
742
+ | `--verbose, -v` | Enable debug logging | false |
743
+ | `--dry-run` | Show actions without spawning | false |
744
+ | `--health-check <N>` | Health check interval (e.g., "2m", "30s") | 2m |
745
+ | `--max-agents <N>` | Max concurrent agents | 3 |
746
+
747
+ ### Environment
748
+
749
+ - `ROBOT_CHAT_PROJECT_PATH` - Project directory (default: current directory)
750
+
751
+ ### Architecture
752
+
753
+ ```
754
+ ┌─────────────────────────────────────────────────────────────┐
755
+ │ NightShift Daemon │
756
+ ├─────────────────────────────────────────────────────────────┤
757
+ │ │
758
+ │ ┌──────────────────────────────────────────────────┐ │
759
+ │ │ File Watchers (Primary) │ │
760
+ │ │ • prd.json changes → reconcile │ │
761
+ │ │ • chat.txt changes → check failovers │ │
762
+ │ └──────────────────────────────────────────────────┘ │
763
+ │ │ │
764
+ │ ▼ │
765
+ │ ┌──────────────────────────────────────────────────┐ │
766
+ │ │ Reconciliation Engine │ │
767
+ │ │ • Find orphaned stories │ │
768
+ │ │ • Spawn agents (up to max concurrency) │ │
769
+ │ │ • Handle failovers │ │
770
+ │ │ • Quarantine poison pills │ │
771
+ │ └──────────────────────────────────────────────────┘ │
772
+ │ │ │
773
+ │ ▼ │
774
+ │ ┌──────────────────────────────────────────────────┐ │
775
+ │ │ Health Check (Fallback) │ │
776
+ │ │ • Runs every 2 minutes │ │
777
+ │ │ • Detects stuck agents │ │
778
+ │ │ • Restarts watchers if needed │ │
779
+ │ │ • Reconciles state │ │
780
+ │ └──────────────────────────────────────────────────┘ │
781
+ │ │
782
+ └─────────────────────────────────────────────────────────────┘
783
+ ```
784
+
785
+ ## Multi-Agent Tips
786
+
787
+ 1. **Same directory**: All agents must run in the same project directory to share chat
788
+ 2. **Claim before working**: Always claim stories to prevent duplicate work
789
+ 3. **Post status updates**: Keep other agents informed of progress
790
+ 4. **Document learnings**: Progress.txt helps future iterations
791
+ 5. **Handle failovers**: Check for and claim failovers at the start of each session
792
+ 6. **Use delegation**: One orchestrating agent can spawn others for parallel work
793
+ 7. **Monitor background agents**: Use `get_agent_status` and `list_running_agents` to track spawned agents
794
+ 8. **Use `orchestrate` for full autonomy**: The `orchestrate` tool handles the entire claim→implement→complete loop
795
+ 9. **Add `.robot-chat/` to your project's `.gitignore`**: Chat logs are ephemeral and shouldn't be committed
796
+
797
+ ## License
798
+
799
+ MIT