nightshift-mcp 1.0.6 → 1.0.8

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