@vibescope/mcp-server 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/CHANGELOG.md +84 -0
  2. package/README.md +45 -2
  3. package/dist/api-client.d.ts +276 -8
  4. package/dist/api-client.js +123 -8
  5. package/dist/handlers/blockers.d.ts +11 -0
  6. package/dist/handlers/blockers.js +37 -2
  7. package/dist/handlers/bodies-of-work.d.ts +2 -0
  8. package/dist/handlers/bodies-of-work.js +30 -1
  9. package/dist/handlers/connectors.js +2 -2
  10. package/dist/handlers/decisions.d.ts +11 -0
  11. package/dist/handlers/decisions.js +37 -2
  12. package/dist/handlers/deployment.d.ts +6 -0
  13. package/dist/handlers/deployment.js +33 -5
  14. package/dist/handlers/discovery.js +27 -11
  15. package/dist/handlers/fallback.js +12 -6
  16. package/dist/handlers/file-checkouts.d.ts +1 -0
  17. package/dist/handlers/file-checkouts.js +17 -2
  18. package/dist/handlers/findings.d.ts +5 -0
  19. package/dist/handlers/findings.js +19 -2
  20. package/dist/handlers/git-issues.js +4 -2
  21. package/dist/handlers/ideas.d.ts +5 -0
  22. package/dist/handlers/ideas.js +19 -2
  23. package/dist/handlers/progress.js +2 -2
  24. package/dist/handlers/project.d.ts +1 -0
  25. package/dist/handlers/project.js +35 -2
  26. package/dist/handlers/requests.js +6 -3
  27. package/dist/handlers/roles.js +13 -2
  28. package/dist/handlers/session.d.ts +12 -0
  29. package/dist/handlers/session.js +288 -25
  30. package/dist/handlers/sprints.d.ts +2 -0
  31. package/dist/handlers/sprints.js +30 -1
  32. package/dist/handlers/tasks.d.ts +25 -2
  33. package/dist/handlers/tasks.js +228 -35
  34. package/dist/handlers/tool-docs.js +72 -5
  35. package/dist/templates/agent-guidelines.d.ts +18 -0
  36. package/dist/templates/agent-guidelines.js +207 -0
  37. package/dist/tools.js +478 -125
  38. package/dist/utils.d.ts +5 -2
  39. package/dist/utils.js +90 -51
  40. package/package.json +51 -46
  41. package/scripts/version-bump.ts +203 -0
  42. package/src/api-client.ts +371 -12
  43. package/src/handlers/__test-setup__.ts +5 -0
  44. package/src/handlers/blockers.test.ts +76 -0
  45. package/src/handlers/blockers.ts +56 -2
  46. package/src/handlers/bodies-of-work.ts +59 -1
  47. package/src/handlers/connectors.ts +2 -2
  48. package/src/handlers/decisions.test.ts +71 -2
  49. package/src/handlers/decisions.ts +56 -2
  50. package/src/handlers/deployment.test.ts +81 -0
  51. package/src/handlers/deployment.ts +38 -5
  52. package/src/handlers/discovery.ts +27 -11
  53. package/src/handlers/fallback.test.ts +11 -10
  54. package/src/handlers/fallback.ts +14 -8
  55. package/src/handlers/file-checkouts.test.ts +83 -3
  56. package/src/handlers/file-checkouts.ts +22 -2
  57. package/src/handlers/findings.test.ts +2 -2
  58. package/src/handlers/findings.ts +38 -2
  59. package/src/handlers/git-issues.test.ts +2 -2
  60. package/src/handlers/git-issues.ts +4 -2
  61. package/src/handlers/ideas.test.ts +1 -1
  62. package/src/handlers/ideas.ts +34 -2
  63. package/src/handlers/progress.ts +2 -2
  64. package/src/handlers/project.ts +47 -2
  65. package/src/handlers/requests.test.ts +38 -7
  66. package/src/handlers/requests.ts +6 -3
  67. package/src/handlers/roles.test.ts +1 -1
  68. package/src/handlers/roles.ts +20 -2
  69. package/src/handlers/session.test.ts +303 -4
  70. package/src/handlers/session.ts +348 -35
  71. package/src/handlers/sprints.ts +61 -1
  72. package/src/handlers/tasks.test.ts +0 -73
  73. package/src/handlers/tasks.ts +269 -40
  74. package/src/handlers/tool-docs.ts +77 -5
  75. package/src/handlers/types.test.ts +259 -0
  76. package/src/templates/agent-guidelines.ts +210 -0
  77. package/src/tools.ts +479 -125
  78. package/src/utils.test.ts +7 -5
  79. package/src/utils.ts +95 -51
@@ -0,0 +1,259 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import {
3
+ success,
4
+ error,
5
+ isSuccess,
6
+ isError,
7
+ type HandlerResult,
8
+ type SuccessResult,
9
+ type ErrorResult,
10
+ } from './types.js';
11
+
12
+ describe('success', () => {
13
+ it('should create a success result with simple data', () => {
14
+ const result = success({ message: 'hello' });
15
+ expect(result.result).toEqual({ message: 'hello' });
16
+ expect(result.isError).toBeUndefined();
17
+ });
18
+
19
+ it('should create a success result with string data', () => {
20
+ const result = success('test string');
21
+ expect(result.result).toBe('test string');
22
+ });
23
+
24
+ it('should create a success result with number data', () => {
25
+ const result = success(42);
26
+ expect(result.result).toBe(42);
27
+ });
28
+
29
+ it('should create a success result with boolean data', () => {
30
+ const result = success(true);
31
+ expect(result.result).toBe(true);
32
+ });
33
+
34
+ it('should create a success result with null data', () => {
35
+ const result = success(null);
36
+ expect(result.result).toBeNull();
37
+ });
38
+
39
+ it('should create a success result with undefined data', () => {
40
+ const result = success(undefined);
41
+ expect(result.result).toBeUndefined();
42
+ });
43
+
44
+ it('should create a success result with array data', () => {
45
+ const result = success([1, 2, 3]);
46
+ expect(result.result).toEqual([1, 2, 3]);
47
+ });
48
+
49
+ it('should create a success result with nested object data', () => {
50
+ const data = {
51
+ tasks: [{ id: '1', title: 'Task 1' }],
52
+ total_count: 1,
53
+ metadata: { page: 1, limit: 10 },
54
+ };
55
+ const result = success(data);
56
+ expect(result.result).toEqual(data);
57
+ });
58
+
59
+ it('should preserve type information', () => {
60
+ interface TaskData {
61
+ id: string;
62
+ title: string;
63
+ }
64
+ const result: SuccessResult<TaskData> = success({ id: '1', title: 'Test' });
65
+ expect(result.result.id).toBe('1');
66
+ expect(result.result.title).toBe('Test');
67
+ });
68
+ });
69
+
70
+ describe('error', () => {
71
+ it('should create an error result with message only', () => {
72
+ const result = error('Something went wrong');
73
+ expect(result.result.error).toBe('Something went wrong');
74
+ expect(result.isError).toBe(true);
75
+ });
76
+
77
+ it('should create an error result with message and details', () => {
78
+ const result = error('Validation failed', { field: 'title', reason: 'too long' });
79
+ expect(result.result.error).toBe('Validation failed');
80
+ expect(result.result.field).toBe('title');
81
+ expect(result.result.reason).toBe('too long');
82
+ expect(result.isError).toBe(true);
83
+ });
84
+
85
+ it('should handle empty details object', () => {
86
+ const result = error('Error message', {});
87
+ expect(result.result.error).toBe('Error message');
88
+ expect(result.isError).toBe(true);
89
+ });
90
+
91
+ it('should handle complex details', () => {
92
+ const result = error('Multiple errors', {
93
+ errors: ['error1', 'error2'],
94
+ count: 2,
95
+ nested: { key: 'value' },
96
+ });
97
+ expect(result.result.error).toBe('Multiple errors');
98
+ expect(result.result.errors).toEqual(['error1', 'error2']);
99
+ expect(result.result.count).toBe(2);
100
+ expect(result.result.nested).toEqual({ key: 'value' });
101
+ });
102
+
103
+ it('should always set isError to true', () => {
104
+ const result1 = error('error1');
105
+ const result2 = error('error2', { detail: 'info' });
106
+ expect(result1.isError).toBe(true);
107
+ expect(result2.isError).toBe(true);
108
+ });
109
+ });
110
+
111
+ describe('isSuccess', () => {
112
+ it('should return true for success results', () => {
113
+ const result = success({ data: 'test' });
114
+ expect(isSuccess(result)).toBe(true);
115
+ });
116
+
117
+ it('should return true for success results with various data types', () => {
118
+ expect(isSuccess(success('string'))).toBe(true);
119
+ expect(isSuccess(success(123))).toBe(true);
120
+ expect(isSuccess(success(null))).toBe(true);
121
+ expect(isSuccess(success([]))).toBe(true);
122
+ expect(isSuccess(success({}))).toBe(true);
123
+ });
124
+
125
+ it('should return false for error results', () => {
126
+ const result = error('Something failed');
127
+ expect(isSuccess(result)).toBe(false);
128
+ });
129
+
130
+ it('should return false for error results with details', () => {
131
+ const result = error('Validation error', { field: 'name' });
132
+ expect(isSuccess(result)).toBe(false);
133
+ });
134
+
135
+ it('should narrow type correctly for success', () => {
136
+ const result: HandlerResult<{ id: string }> = success({ id: '123' });
137
+ if (isSuccess(result)) {
138
+ // TypeScript should know result.result is { id: string }
139
+ expect(result.result.id).toBe('123');
140
+ }
141
+ });
142
+
143
+ it('should work with explicitly typed results', () => {
144
+ const successResult: SuccessResult<number> = { result: 42 };
145
+ const errorResult: ErrorResult = { result: { error: 'fail' }, isError: true };
146
+
147
+ expect(isSuccess(successResult)).toBe(true);
148
+ expect(isSuccess(errorResult)).toBe(false);
149
+ });
150
+ });
151
+
152
+ describe('isError', () => {
153
+ it('should return true for error results', () => {
154
+ const result = error('Something failed');
155
+ expect(isError(result)).toBe(true);
156
+ });
157
+
158
+ it('should return true for error results with details', () => {
159
+ const result = error('Validation error', { field: 'name', code: 'INVALID' });
160
+ expect(isError(result)).toBe(true);
161
+ });
162
+
163
+ it('should return false for success results', () => {
164
+ const result = success({ data: 'test' });
165
+ expect(isError(result)).toBe(false);
166
+ });
167
+
168
+ it('should return false for success results with various data types', () => {
169
+ expect(isError(success('string'))).toBe(false);
170
+ expect(isError(success(123))).toBe(false);
171
+ expect(isError(success(null))).toBe(false);
172
+ expect(isError(success([]))).toBe(false);
173
+ expect(isError(success({}))).toBe(false);
174
+ });
175
+
176
+ it('should narrow type correctly for error', () => {
177
+ const result: HandlerResult<unknown> = error('Task not found');
178
+ if (isError(result)) {
179
+ // TypeScript should know result.result.error is string
180
+ expect(result.result.error).toBe('Task not found');
181
+ }
182
+ });
183
+
184
+ it('should work with explicitly typed results', () => {
185
+ const successResult: SuccessResult<number> = { result: 42 };
186
+ const errorResult: ErrorResult = { result: { error: 'fail' }, isError: true };
187
+
188
+ expect(isError(successResult)).toBe(false);
189
+ expect(isError(errorResult)).toBe(true);
190
+ });
191
+ });
192
+
193
+ describe('HandlerResult type usage', () => {
194
+ it('should work with discriminated union pattern', () => {
195
+ function processResult(result: HandlerResult<string>): string {
196
+ if (isSuccess(result)) {
197
+ return `Success: ${result.result}`;
198
+ } else {
199
+ return `Error: ${result.result.error}`;
200
+ }
201
+ }
202
+
203
+ expect(processResult(success('hello'))).toBe('Success: hello');
204
+ expect(processResult(error('failed'))).toBe('Error: failed');
205
+ });
206
+
207
+ it('should handle async handler patterns', async () => {
208
+ async function mockHandler(): Promise<HandlerResult<{ id: string }>> {
209
+ return success({ id: '123' });
210
+ }
211
+
212
+ const result = await mockHandler();
213
+ expect(isSuccess(result)).toBe(true);
214
+ if (isSuccess(result)) {
215
+ expect(result.result.id).toBe('123');
216
+ }
217
+ });
218
+
219
+ it('should handle error handler patterns', async () => {
220
+ async function mockErrorHandler(): Promise<HandlerResult<{ id: string }>> {
221
+ return error('Not found', { id: '123' });
222
+ }
223
+
224
+ const result = await mockErrorHandler();
225
+ expect(isError(result)).toBe(true);
226
+ if (isError(result)) {
227
+ expect(result.result.error).toBe('Not found');
228
+ expect(result.result.id).toBe('123');
229
+ }
230
+ });
231
+ });
232
+
233
+ describe('edge cases', () => {
234
+ it('should handle result with isError explicitly set to false', () => {
235
+ const result: SuccessResult<string> = { result: 'data', isError: false };
236
+ expect(isSuccess(result)).toBe(true);
237
+ expect(isError(result)).toBe(false);
238
+ });
239
+
240
+ it('should handle result without isError property', () => {
241
+ const result: SuccessResult<string> = { result: 'data' };
242
+ expect(isSuccess(result)).toBe(true);
243
+ expect(isError(result)).toBe(false);
244
+ });
245
+
246
+ it('should handle success with error-like data', () => {
247
+ // A success result that happens to contain an error message in its data
248
+ const result = success({ error: 'This is not an error result', data: 'some data' });
249
+ expect(isSuccess(result)).toBe(true);
250
+ expect(isError(result)).toBe(false);
251
+ });
252
+
253
+ it('should handle empty string error message', () => {
254
+ const result = error('');
255
+ expect(result.result.error).toBe('');
256
+ expect(result.isError).toBe(true);
257
+ expect(isError(result)).toBe(true);
258
+ });
259
+ });
@@ -0,0 +1,210 @@
1
+ /**
2
+ * Agent Guidelines Template
3
+ *
4
+ * This template contains the essential CLAUDE.md content that should be included
5
+ * in every project using Vibescope for agent tracking. These guidelines ensure
6
+ * agents follow proper workflows and maintain visibility.
7
+ */
8
+
9
+ export const AGENT_GUIDELINES_TEMPLATE = `# Vibescope Agent Guidelines
10
+
11
+ ## Quick Start
12
+
13
+ \`\`\`
14
+ start_work_session(git_url: "https://github.com/YOUR/REPO", model: "opus")
15
+ \`\`\`
16
+
17
+ **IMPORTANT:** Always pass your model (opus/sonnet/haiku) to enable cost tracking. Check your system prompt for "You are powered by the model named..." to determine your model.
18
+
19
+ This returns your persona, project info, and \`next_task\`. Start working immediately.
20
+
21
+ ## CRITICAL: MCP Connection Required
22
+
23
+ **If the Vibescope MCP server fails to connect, you MUST end your session immediately.**
24
+
25
+ ### Why This Is Non-Negotiable
26
+
27
+ Working without MCP connection causes:
28
+ - **No progress visibility** - Humans can't see what you're doing
29
+ - **Lost work tracking** - Tasks aren't tracked, time is wasted
30
+ - **Workflow violations** - Other agents may conflict with your work
31
+ - **Dashboard confusion** - Project state becomes inconsistent
32
+
33
+ ### Connection Failure Handling
34
+
35
+ **If \`start_work_session\` fails or returns an error:**
36
+
37
+ 1. **Do NOT proceed with any work**
38
+ 2. **Inform the user** that MCP connection failed
39
+ 3. **End the session** - do not attempt workarounds
40
+ 4. **Provide troubleshooting steps:**
41
+ - Check if MCP server is configured: \`claude mcp list\`
42
+ - Verify API key is set: check \`.mcp.json\` or environment
43
+ - Restart Claude Code after fixing configuration
44
+
45
+ **Example error responses you might see:**
46
+ \`\`\`
47
+ Error: Failed to start session
48
+ Error: VIBESCOPE_API_KEY not set
49
+ Error: Network error connecting to Vibescope API
50
+ Error: MCP server 'vibescope' not found
51
+ \`\`\`
52
+
53
+ ### Recovery Steps
54
+
55
+ If MCP connection fails, tell the user:
56
+
57
+ \`\`\`
58
+ MCP connection to Vibescope failed. I cannot proceed without task tracking.
59
+
60
+ To fix:
61
+ 1. Run: claude mcp list (verify vibescope is configured)
62
+ 2. Check API key: ensure VIBESCOPE_API_KEY is set
63
+ 3. Restart Claude Code
64
+ 4. Try again with: start_work_session(git_url: "...")
65
+
66
+ I am ending this session to prevent untracked work.
67
+ \`\`\`
68
+
69
+ **Never "work around" a broken MCP connection.** The whole point of Vibescope is visibility and coordination. Working without it defeats the purpose.
70
+
71
+ ## Core Workflow
72
+
73
+ 1. **Start session** → \`start_work_session(git_url, model)\` - Always include your model!
74
+ 2. **Mark task in progress** → \`update_task(task_id, status: "in_progress")\` - Returns git workflow instructions!
75
+ 3. **Set up worktree** → Create isolated worktree for this task (see Git Workflow below)
76
+ 4. **Update progress** → \`update_task(task_id, progress_percentage: 50, progress_note: "...")\`
77
+ 5. **Complete task** → \`complete_task(task_id, summary: "...")\` - **MANDATORY, see below!**
78
+ 6. **Clean up** → Remove worktree, then start next task immediately
79
+
80
+ ## CRITICAL: Always Call complete_task (MANDATORY)
81
+
82
+ **You MUST call \`complete_task()\` when you finish a task.** This is not optional.
83
+
84
+ ### When to Call complete_task
85
+
86
+ Call \`complete_task()\` immediately after:
87
+ - ✅ Creating and pushing a PR
88
+ - ✅ Merging changes (for trunk-based workflow)
89
+ - ✅ Finishing any unit of work, even if no code changes
90
+
91
+ **Do NOT wait for:**
92
+ - ❌ PR to be reviewed/merged (that's what validation is for)
93
+ - ❌ User confirmation
94
+ - ❌ "Perfect" summary - a brief summary is fine
95
+
96
+ ### The Rule
97
+
98
+ \`\`\`
99
+ PR created + pushed → complete_task() → THEN worry about next steps
100
+ \`\`\`
101
+
102
+ **If you create a PR and don't call \`complete_task()\`, you have failed the workflow.**
103
+
104
+ ## CRITICAL: Git Worktrees for Multi-Agent
105
+
106
+ When multiple agents share a repository, you **MUST** use git worktrees to prevent conflicts.
107
+
108
+ **Before starting ANY task:**
109
+ \`\`\`bash
110
+ # For git-flow: ensure you're on develop first, then create worktree
111
+ git checkout develop
112
+ git pull origin develop
113
+ git worktree add ../worktree-<task-short-id> -b feature/<task-id>-<title>
114
+ cd ../worktree-<task-short-id>
115
+ \`\`\`
116
+
117
+ **After task is merged:**
118
+ \`\`\`bash
119
+ git worktree remove ../worktree-<task-short-id>
120
+ \`\`\`
121
+
122
+ **Why?** Branch switching in shared repos causes file conflicts between agents. Worktrees provide isolated directories.
123
+
124
+ Run \`get_help("git")\` for full worktree documentation.
125
+
126
+ ## CRITICAL: Never Ask Permission
127
+
128
+ **You must NEVER:**
129
+ - Ask "Should I continue to the next task?" → Just continue
130
+ - Ask "Should I clear my context?" → Just clear it
131
+ - Ask "What should I do next?" → Check \`next_task\` or use fallback activities
132
+ - Say "All tasks are done, let me know what to do" → Use \`get_next_task\` or start fallback activity
133
+ - Wait for confirmation before clearing context → Just do it
134
+
135
+ **You must ALWAYS:**
136
+ - Call \`complete_task()\` immediately after creating/pushing a PR - this is non-negotiable
137
+ - Immediately start the next task after completing one
138
+ - Clear context and restart session automatically when needed
139
+ - Keep working until there are genuinely no tasks and no fallback activities
140
+
141
+ ## Continuous Work
142
+
143
+ **IMPORTANT: Never stop working!** When you complete a task:
144
+ 1. \`complete_task\` returns \`next_task\` → Start it immediately
145
+ 2. No \`next_task\`? → Call \`get_next_task(project_id)\`
146
+ 3. Still no tasks? → Start a \`fallback_activity\` (code_review, security_review, etc.)
147
+
148
+ **When context grows large or responses slow down:**
149
+ 1. Run \`/clear\` to reset conversation
150
+ 2. Immediately call \`start_work_session(git_url, model)\` to reload context
151
+ 3. Continue with \`next_task\` from the response
152
+
153
+ **Do NOT ask the user if you should clear context. Just do it.** The dashboard tracks all your progress, so nothing is lost when you clear.
154
+
155
+ ## Need Help?
156
+
157
+ Use \`get_help(topic)\` for detailed guidance:
158
+
159
+ | Topic | Description |
160
+ |-------|-------------|
161
+ | \`getting_started\` | Basic workflow overview |
162
+ | \`tasks\` | Working on tasks, progress tracking |
163
+ | \`validation\` | Cross-agent task validation |
164
+ | \`deployment\` | Deployment coordination |
165
+ | \`git\` | Git workflow configuration |
166
+ | \`blockers\` | Handling blockers |
167
+ | \`milestones\` | Breaking down complex tasks |
168
+ | \`fallback\` | Background activities when idle |
169
+ | \`session\` | Session management |
170
+ | \`topics\` | List all available topics |
171
+
172
+ ## MCP Server Not Connected?
173
+
174
+ ### Quick Setup (Claude Code)
175
+
176
+ \`\`\`bash
177
+ claude mcp add vibescope npx @vibescope/mcp-server@latest \\
178
+ --env VIBESCOPE_API_KEY=your_key
179
+ \`\`\`
180
+
181
+ ### Manual Setup
182
+
183
+ 1. Copy \`.mcp.json.example\` to \`.mcp.json\`
184
+ 2. Get \`VIBESCOPE_API_KEY\` from https://vibescope.dev/dashboard/settings
185
+ 3. Restart Claude Code
186
+ `;
187
+
188
+ /**
189
+ * Get the agent guidelines template
190
+ * @returns The full agent guidelines markdown template
191
+ */
192
+ export function getAgentGuidelinesTemplate(): string {
193
+ return AGENT_GUIDELINES_TEMPLATE;
194
+ }
195
+
196
+ /**
197
+ * Get a summary of the agent guidelines for inclusion in responses
198
+ * @returns A brief summary of key guidelines
199
+ */
200
+ export function getAgentGuidelinesSummary(): string {
201
+ return `## Essential Agent Guidelines
202
+
203
+ 1. **MCP Connection Required** - If start_work_session fails, END SESSION IMMEDIATELY
204
+ 2. **Always call complete_task()** - After creating a PR, call complete_task() right away
205
+ 3. **Use git worktrees** - Create worktrees for each task to avoid conflicts
206
+ 4. **Never ask permission** - Just continue working, clear context when needed
207
+ 5. **Continuous work** - Never stop; use get_next_task or fallback activities
208
+
209
+ For full guidelines, create a \`.claude/CLAUDE.md\` file in your project with the agent guidelines template.`;
210
+ }