nightshift-mcp 1.0.9 → 1.0.11

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