couchloop-eq-mcp 2.0.2 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/README.md +11 -12
  2. package/dist/clients/shrinkChatClient.d.ts +38 -38
  3. package/dist/db/client.d.ts +11 -19
  4. package/dist/db/client.d.ts.map +1 -1
  5. package/dist/db/client.js +30 -62
  6. package/dist/db/client.js.map +1 -1
  7. package/dist/index.js +8 -5
  8. package/dist/index.js.map +1 -1
  9. package/dist/resources/journey-status.d.ts.map +1 -1
  10. package/dist/resources/journey-status.js +10 -12
  11. package/dist/resources/journey-status.js.map +1 -1
  12. package/dist/resources/session-summary.d.ts.map +1 -1
  13. package/dist/resources/session-summary.js +33 -33
  14. package/dist/resources/session-summary.js.map +1 -1
  15. package/dist/resources/user-context.d.ts.map +1 -1
  16. package/dist/resources/user-context.js +26 -41
  17. package/dist/resources/user-context.js.map +1 -1
  18. package/dist/server/http-mcp.js +2 -2
  19. package/dist/server/index.d.ts.map +1 -1
  20. package/dist/server/index.js +8 -9
  21. package/dist/server/index.js.map +1 -1
  22. package/dist/server/sse.d.ts.map +1 -1
  23. package/dist/server/sse.js +17 -17
  24. package/dist/server/sse.js.map +1 -1
  25. package/dist/tools/check-versions.d.ts +7 -7
  26. package/dist/tools/checkpoint.d.ts +1 -8
  27. package/dist/tools/checkpoint.d.ts.map +1 -1
  28. package/dist/tools/checkpoint.js +47 -49
  29. package/dist/tools/checkpoint.js.map +1 -1
  30. package/dist/tools/couchloop-v2.d.ts.map +1 -1
  31. package/dist/tools/couchloop-v2.js +15 -4
  32. package/dist/tools/couchloop-v2.js.map +1 -1
  33. package/dist/tools/detect-build-context.d.ts +1 -1
  34. package/dist/tools/generate-upgrade-report.d.ts +2 -2
  35. package/dist/tools/guard.d.ts +3 -3
  36. package/dist/tools/index.d.ts +2 -4
  37. package/dist/tools/index.d.ts.map +1 -1
  38. package/dist/tools/index.js +2 -4
  39. package/dist/tools/index.js.map +1 -1
  40. package/dist/tools/insight.d.ts +10 -49
  41. package/dist/tools/insight.d.ts.map +1 -1
  42. package/dist/tools/insight.js +78 -91
  43. package/dist/tools/insight.js.map +1 -1
  44. package/dist/tools/intent-router.d.ts.map +1 -1
  45. package/dist/tools/intent-router.js +12 -7
  46. package/dist/tools/intent-router.js.map +1 -1
  47. package/dist/tools/journey.d.ts +5 -5
  48. package/dist/tools/journey.d.ts.map +1 -1
  49. package/dist/tools/journey.js +47 -39
  50. package/dist/tools/journey.js.map +1 -1
  51. package/dist/tools/pre-review-code.d.ts +2 -2
  52. package/dist/tools/prevent-ai-errors.d.ts +3 -3
  53. package/dist/tools/primary-tools.d.ts +37 -190
  54. package/dist/tools/primary-tools.d.ts.map +1 -1
  55. package/dist/tools/primary-tools.js +204 -302
  56. package/dist/tools/primary-tools.js.map +1 -1
  57. package/dist/tools/protect-files.d.ts +1 -1
  58. package/dist/tools/sendMessage.d.ts.map +1 -1
  59. package/dist/tools/sendMessage.js +52 -38
  60. package/dist/tools/sendMessage.js.map +1 -1
  61. package/dist/tools/session-manager.d.ts.map +1 -1
  62. package/dist/tools/session-manager.js +88 -70
  63. package/dist/tools/session-manager.js.map +1 -1
  64. package/dist/tools/session.d.ts +7 -86
  65. package/dist/tools/session.d.ts.map +1 -1
  66. package/dist/tools/session.js +68 -72
  67. package/dist/tools/session.js.map +1 -1
  68. package/dist/tools/smart-context.d.ts +1 -1
  69. package/dist/tools/status.d.ts +9 -2
  70. package/dist/tools/status.d.ts.map +1 -1
  71. package/dist/tools/status.js +113 -64
  72. package/dist/tools/status.js.map +1 -1
  73. package/dist/tools/verify.d.ts +4 -4
  74. package/dist/tools/verify.js.map +1 -1
  75. package/dist/types/auth.d.ts +2 -2
  76. package/dist/types/checkpoint.d.ts +4 -4
  77. package/dist/types/file-protection.d.ts +2 -2
  78. package/dist/types/insight.d.ts +10 -10
  79. package/dist/types/journey.d.ts +40 -12
  80. package/dist/types/journey.d.ts.map +1 -1
  81. package/dist/types/journey.js +2 -0
  82. package/dist/types/journey.js.map +1 -1
  83. package/dist/types/session.d.ts +10 -10
  84. package/dist/workflows/engine.d.ts +2 -2
  85. package/dist/workflows/engine.d.ts.map +1 -1
  86. package/dist/workflows/engine.js +81 -82
  87. package/dist/workflows/engine.js.map +1 -1
  88. package/dist/workflows/index.d.ts +4 -4
  89. package/package.json +2 -10
@@ -2,146 +2,133 @@
2
2
  * MCP Tools - Public API
3
3
  *
4
4
  * This module exports only the PRIMARY tools that users should see.
5
- * All granular tools are internal engines used by these primary tools.
5
+ * Consolidated from 10 4 tools for clarity and reduced LLM misrouting.
6
6
  *
7
- * PUBLIC TOOLS (10):
8
- * 0. couchloop - Intent router (discoverability layer for loose commands)
9
- * 1. guard - Invisible per-turn governance (called automatically by companion skill)
10
- * 2. verify - Pre-delivery verification (catches AI hallucinations, validates packages)
11
- * 2. status - Dashboard (session progress, history, context, protection)
12
- * 3. conversation - AI conversation with guided journeys and session memory
13
- * 4. brainstorm - Dev thinking partner (reflective questioning, architecture, trade-offs)
14
- * 5. code_review - Complete code analysis (security, quality, AI errors)
15
- * 6. package_audit - Complete dependency audit (validation, versions, upgrades)
16
- * 7. remember - Smart context capture (checkpoints, insights, decisions)
17
- * 8. protect - File protection and safety features
7
+ * PUBLIC TOOLS (4):
8
+ * 1. memory - HERO: save & recall insights, checkpoints, decisions (Supabase-backed)
9
+ * 2. conversation - Emotional support, guided journeys, crisis detection (shrink-chat backend)
10
+ * 3. review - Unified: code review + package audit + pre-delivery verification
11
+ * 4. status - Dashboard (session progress, history, context, preferences)
12
+ *
13
+ * INTERNAL (auto-triggered, not user-facing):
14
+ * - guard - Per-response governance (runs in withPolicy wrapper)
15
+ *
16
+ * REMOVED:
17
+ * - couchloop - Router added latency; LLMs route directly with good descriptions
18
+ * - brainstorm - Returned static system prompt; LLMs brainstorm natively
19
+ * - protect - Broken on Railway (read-only /app filesystem)
18
20
  */
19
- // V2 Orchestration imports
20
- import { couchloopV2Tool } from './couchloop-v2.js';
21
- import { registerTools } from './intent-router.js';
21
+ import { z } from 'zod';
22
22
  import { ToolRegistry } from '../core/registry/registry.js';
23
- // Legacy tool imports (will be registered in V2 registry)
23
+ // Tool handler imports
24
24
  import { sendMessage } from './sendMessage.js';
25
25
  import { createSession, resumeSession } from './session.js';
26
26
  import { endSession } from './session-manager.js';
27
27
  import { handleComprehensiveCodeReview } from './comprehensive-code-review.js';
28
28
  import { handleComprehensivePackageAudit } from './comprehensive-package-audit.js';
29
29
  import { handleSmartContext } from './smart-context.js';
30
- import { protectFiles, getProtectionStatus, listBackups, rollbackFile, enableCodeFreeze, disableCodeFreeze, } from './protect-files.js';
31
30
  import { listJourneys, getJourneyStatus } from './journey.js';
32
31
  import { getCheckpoints } from './checkpoint.js';
33
32
  import { getInsights, getUserContext } from './insight.js';
34
- import { verifyTool } from './verify.js';
33
+ import { handleVerify } from './verify.js';
35
34
  import { statusTool } from './status.js';
36
- import { guardTool } from './guard.js';
37
35
  import { runToolWithPolicy } from '../policy/index.js';
38
36
  import { logger } from '../utils/logger.js';
39
37
  // ============================================================
40
- // PRIMARY TOOL DEFINITIONS
41
- // These are the only tools visible to users
38
+ // PRIMARY TOOL DEFINITIONS (4 public tools)
42
39
  // ============================================================
43
- // Brainstorm system prompt - reflective questioning to help developers arrive at their own solutions
44
- const BRAINSTORM_SYSTEM_PROMPT = `You are a reflective thinking partner for developers. Your primary role is to ask insightful questions that help developers discover their own best solution — but you also provide concrete analysis when they've narrowed down options.
45
-
46
- DETECT THE MODE:
47
- 1. EXPLORATION: User has a vague idea or open-ended problem → Ask questions to help them think
48
- 2. COMPARISON: User presents 2-3 specific options (e.g., "Redis vs Memcached?") → Clarify context briefly, then provide analysis
49
-
50
- FOR EXPLORATION MODE:
51
- - Ask clarifying questions before suggesting anything
52
- - Surface assumptions they may not have questioned
53
- - Break complex problems into smaller, answerable pieces
54
- - Ask 1-3 focused questions per response (not a barrage)
55
-
56
- QUESTION PATTERNS:
57
- 1. SCOPE: "What problem are you really trying to solve?" / "Who is this for?"
58
- 2. CONSTRAINTS: "What's your timeline?" / "What existing systems does this need to work with?"
59
- 3. TRADE-OFFS: "If you had to choose between X and Y, which matters more?"
60
- 4. ASSUMPTIONS: "What are you assuming about the user?" / "Have you validated that?"
61
- 5. DECOMPOSITION: "What's the riskiest part?" / "What could you build first to learn more?"
62
-
63
- FOR COMPARISON MODE (user asks "A vs B?" or "should I use X or Y?"):
64
- 1. Ask 1-2 quick clarifying questions about their specific context (scale, team experience, existing stack)
65
- 2. Then provide a structured comparison:
66
- - Key differences that matter for their use case
67
- - When to choose each option
68
- - Your recommendation given what you know about their context
69
- - Caveats or "it depends" factors they should verify
70
- 3. Be direct. Don't just list pros/cons — give them an actionable recommendation with reasoning.
71
-
72
- RESPONSE STYLE:
73
- - Start with understanding, not solutioning
74
- - Summarize their thinking back periodically
75
- - When they present options, acknowledge you'll help them decide (not just explore forever)
76
- - Be concise — developers want signal, not fluff
77
-
78
- Remember: The best solutions come from the developer's own understanding of their context. Your job is to help them think clearly AND give them useful analysis when they're ready for it.`;
79
- const conversationTool = {
40
+ // ── 1. MEMORY (hero feature registered first) ─────────────────────────────
41
+ // Zod schemas for handler validation (CLAUDE.md Key Invariant #1)
42
+ const MemoryInputSchema = z.object({
43
+ action: z.enum(['save', 'recall', 'list']).optional(),
44
+ content: z.unknown().optional(),
45
+ type: z.string().optional(),
46
+ tags: z.array(z.string()).optional(),
47
+ session_id: z.string().optional(),
48
+ auth: z.record(z.unknown()).optional(),
49
+ });
50
+ const ConversationInputSchema = z.object({
51
+ action: z.enum(['send', 'start', 'end', 'resume', 'status']).optional(),
52
+ message: z.string().optional(),
53
+ journey: z.string().optional(),
54
+ session_id: z.string().optional(),
55
+ auth: z.record(z.unknown()).optional(),
56
+ });
57
+ const memoryTool = {
80
58
  definition: {
81
- name: 'conversation',
82
- description: 'Start or continue an AI conversation with built-in crisis detection, guided self-reflection journeys, and session memory. Includes brainstorm mode for dev ideation. Triggers: "end session", "start session", "wrap up", "done for now", "talk", "chat", "feeling", "stressed", "help me", "brainstorm", "think through", "map out feature".',
59
+ name: 'memory',
60
+ description: 'Save and retrieve context, insights, checkpoints, and decisions across conversations. Prevents AI amnesia. Use action "save" to store, "recall" to retrieve, "list" to browse.',
83
61
  annotations: {
84
62
  readOnlyHint: false,
85
63
  destructiveHint: false,
86
64
  idempotentHint: false,
87
- openWorldHint: true,
65
+ openWorldHint: false,
88
66
  },
89
67
  inputSchema: {
90
68
  type: 'object',
91
69
  properties: {
92
- message: {
70
+ content: {
93
71
  type: 'string',
94
- description: 'Your message',
72
+ description: 'What to save or search for when recalling',
95
73
  },
96
74
  action: {
97
75
  type: 'string',
98
- enum: ['send', 'start', 'end', 'resume', 'status'],
99
- description: 'Action: send (default), start new session, end session, resume previous, or get status',
76
+ enum: ['save', 'recall', 'list'],
77
+ description: 'save: store new context. recall: retrieve previously stored insights/checkpoints/decisions. list: browse all saved items.',
100
78
  },
101
- journey: {
79
+ type: {
102
80
  type: 'string',
103
- description: 'Optional journey to follow (e.g., "daily-reflection")',
81
+ enum: ['checkpoint', 'insight', 'decision', 'requirement', 'constraint', 'pattern'],
82
+ description: 'Type of context (for save action — affects categorization)',
83
+ },
84
+ tags: {
85
+ type: 'array',
86
+ items: { type: 'string' },
87
+ description: 'Tags for categorization (for save action)',
104
88
  },
105
89
  session_id: {
106
90
  type: 'string',
107
- description: 'Session ID (auto-managed if not provided)',
91
+ description: 'Session to associate with',
92
+ },
93
+ auth: {
94
+ type: 'object',
95
+ description: 'Authentication context for user identification',
108
96
  },
109
97
  },
110
- required: ['message'],
98
+ required: [],
111
99
  },
112
100
  },
113
101
  handler: async (args) => {
114
- const action = args.action || 'send';
102
+ const parsed = MemoryInputSchema.parse(args);
103
+ const action = parsed.action ?? 'save';
104
+ const sessionId = parsed.session_id;
105
+ const auth = parsed.auth;
115
106
  switch (action) {
116
- case 'start':
117
- return createSession({
118
- journey_slug: args.journey,
119
- context: args.message,
120
- });
121
- case 'end':
122
- return endSession(args.session_id);
123
- case 'resume':
124
- return resumeSession({ session_id: args.session_id });
125
- case 'status':
126
- if (args.session_id) {
127
- return getJourneyStatus({ session_id: args.session_id });
128
- }
129
- return listJourneys({});
130
- case 'send':
107
+ case 'recall': {
108
+ const checkpointData = await getCheckpoints({ session_id: sessionId, auth });
109
+ const insightData = await getInsights({ session_id: sessionId, limit: 10, auth });
110
+ const userContext = await getUserContext({ include_recent_insights: true, include_session_history: true, auth });
111
+ return { checkpoints: checkpointData, insights: insightData, user_context: userContext };
112
+ }
113
+ case 'list':
114
+ return getInsights({ session_id: sessionId, limit: 20, auth });
115
+ case 'save':
131
116
  default:
132
- return sendMessage({
133
- message: args.message,
134
- session_id: args.session_id,
135
- save_checkpoint: true,
136
- include_memory: true,
117
+ return handleSmartContext({
118
+ content: parsed.content,
119
+ type: parsed.type || 'insight',
120
+ tags: parsed.tags,
121
+ session_id: parsed.session_id,
122
+ auth,
137
123
  });
138
124
  }
139
125
  },
140
126
  };
141
- const brainstormTool = {
127
+ // ── 2. CONVERSATION ──────────────────────────────────────────────────────────
128
+ const conversationTool = {
142
129
  definition: {
143
- name: 'brainstorm',
144
- description: 'Dev thinking partner for architecture decisions, feature design, trade-offs, and technical exploration. Asks reflective questions to help you arrive at your own best solution, then provides concrete analysis when you\'ve narrowed options. Triggers: "brainstorm", "think through", "map out", "help me design", "I have an idea", "flesh out", "trade-offs", "pros and cons", "should I use X or Y".',
130
+ name: 'conversation',
131
+ description: 'Emotional support, guided self-reflection journeys, and wellness conversations with crisis detection. Routes to therapeutic AI backend.',
145
132
  annotations: {
146
133
  readOnlyHint: false,
147
134
  destructiveHint: false,
@@ -153,63 +140,65 @@ const brainstormTool = {
153
140
  properties: {
154
141
  message: {
155
142
  type: 'string',
156
- description: 'What you want to think through — a feature idea, architecture question, technology comparison, or any decision',
143
+ description: 'Your message for the therapeutic conversation',
157
144
  },
158
- session_id: {
145
+ action: {
159
146
  type: 'string',
160
- description: 'Session ID to maintain brainstorm context across messages',
147
+ enum: ['send', 'start', 'end', 'resume', 'status'],
148
+ description: 'send (default), start new session, end session, resume previous, or get status',
161
149
  },
162
- },
163
- required: ['message'],
164
- },
165
- },
166
- handler: async (args) => {
167
- const message = String(args.message || '');
168
- // brainstorm must NOT route through shrink-chat (therapeutic backend).
169
- // Return instructions directly so the host LLM (Claude/ChatGPT) responds in brainstorm mode.
170
- return {
171
- mode: 'brainstorm',
172
- instructions: BRAINSTORM_SYSTEM_PROMPT,
173
- respond_to: message,
174
- directive: `You are now in BRAINSTORM MODE. Follow the instructions above precisely. Do not respond therapeutically. Respond directly to: "${message}"`,
175
- };
176
- },
177
- };
178
- const codeReviewTool = {
179
- definition: {
180
- name: 'code_review',
181
- description: 'Complete code review: security vulnerabilities (SQL injection, XSS, secrets), code quality (console.logs, TODOs, error handling), code smells (complexity, bloat), and AI-generated errors (hallucinated APIs, build context issues). One call, full analysis. Triggers: "review", "check code", "analyze", "security check", "lint", "find bugs", "is this safe".',
182
- annotations: {
183
- readOnlyHint: true,
184
- destructiveHint: false,
185
- idempotentHint: true,
186
- openWorldHint: false,
187
- },
188
- inputSchema: {
189
- type: 'object',
190
- properties: {
191
- code: {
150
+ journey: {
192
151
  type: 'string',
193
- description: 'Code to review',
152
+ description: 'Optional journey to follow (e.g., "daily-reflection")',
194
153
  },
195
- language: {
154
+ session_id: {
196
155
  type: 'string',
197
- description: 'Programming language (auto-detected if not specified)',
156
+ description: 'Session ID (auto-managed if not provided)',
198
157
  },
199
- auto_fix: {
200
- type: 'boolean',
201
- description: 'Attempt to auto-fix issues (default: false)',
158
+ auth: {
159
+ type: 'object',
160
+ description: 'Authentication context for user identification',
202
161
  },
203
162
  },
204
- required: ['code'],
163
+ required: ['message'],
205
164
  },
206
165
  },
207
- handler: handleComprehensiveCodeReview,
166
+ handler: async (args) => {
167
+ const parsed = ConversationInputSchema.parse(args);
168
+ const action = parsed.action ?? 'send';
169
+ const auth = parsed.auth;
170
+ switch (action) {
171
+ case 'start':
172
+ return createSession({
173
+ journey_slug: parsed.journey,
174
+ context: parsed.message,
175
+ auth,
176
+ });
177
+ case 'end':
178
+ return endSession(parsed.session_id, auth);
179
+ case 'resume':
180
+ return resumeSession({ session_id: parsed.session_id, auth });
181
+ case 'status':
182
+ if (parsed.session_id) {
183
+ return getJourneyStatus({ session_id: parsed.session_id, auth });
184
+ }
185
+ return listJourneys({});
186
+ case 'send':
187
+ default:
188
+ return sendMessage({
189
+ message: parsed.message,
190
+ session_id: parsed.session_id,
191
+ save_checkpoint: true,
192
+ include_memory: true,
193
+ });
194
+ }
195
+ },
208
196
  };
209
- const packageAuditTool = {
197
+ // ── 3. REVIEW (unified: code + packages + verify) ───────────────────────────
198
+ const reviewTool = {
210
199
  definition: {
211
- name: 'package_audit',
212
- description: 'Complete dependency audit: validates packages exist and are legitimate (catches typosquatting), checks for outdated versions and security vulnerabilities, generates upgrade reports with migration guides and breaking changes. Triggers: "audit", "check dependencies", "outdated", "vulnerable packages", "upgrade", "npm audit", "security scan".',
200
+ name: 'review',
201
+ description: 'Unified code review, package audit, and pre-delivery verification. Use mode to select: "code" for security/quality/AI-error analysis, "packages" for dependency audit and validation, "verify" for hallucination and fact checking, "full" for all checks.',
213
202
  annotations: {
214
203
  readOnlyHint: true,
215
204
  destructiveHint: false,
@@ -219,175 +208,106 @@ const packageAuditTool = {
219
208
  inputSchema: {
220
209
  type: 'object',
221
210
  properties: {
222
- packages: {
223
- type: 'array',
224
- items: { type: 'string' },
225
- description: 'Package names to audit',
226
- },
227
- registry: {
211
+ mode: {
228
212
  type: 'string',
229
- enum: ['npm', 'pypi', 'maven', 'cargo', 'go', 'nuget', 'gem'],
230
- description: 'Package registry (default: npm)',
213
+ enum: ['code', 'packages', 'verify', 'full'],
214
+ description: 'code: security vulnerabilities, code smells, AI-generated errors. packages: validate existence, audit versions, find vulnerabilities. verify: pre-delivery hallucination/fact check. full: all checks.',
231
215
  },
232
- },
233
- required: ['packages'],
234
- },
235
- },
236
- handler: handleComprehensivePackageAudit,
237
- };
238
- const rememberTool = {
239
- definition: {
240
- name: 'remember',
241
- description: 'Capture and preserve important context from conversations. Automatically routes to the right storage: checkpoints for progress, insights for realizations, context for technical decisions. Prevents AI amnesia across conversations. Triggers: "save", "remember this", "checkpoint", "note", "don\'t forget", "keep track", "save progress", "log this".',
242
- annotations: {
243
- readOnlyHint: false,
244
- destructiveHint: false,
245
- idempotentHint: false,
246
- openWorldHint: false,
247
- },
248
- inputSchema: {
249
- type: 'object',
250
- properties: {
251
216
  content: {
252
217
  type: 'string',
253
- description: 'What to remember',
218
+ description: 'Code to review, content to verify, or general input for analysis',
254
219
  },
255
- type: {
256
- type: 'string',
257
- enum: ['checkpoint', 'insight', 'decision', 'requirement', 'constraint', 'pattern'],
258
- description: 'Type of context (affects where it\'s stored)',
259
- },
260
- tags: {
220
+ packages: {
261
221
  type: 'array',
262
222
  items: { type: 'string' },
263
- description: 'Tags for categorization',
264
- },
265
- action: {
266
- type: 'string',
267
- enum: ['save', 'recall', 'list'],
268
- description: 'Action: save (default), recall previous context, or list saved items',
269
- },
270
- session_id: {
271
- type: 'string',
272
- description: 'Session to associate with',
223
+ description: 'Package names to audit (for packages mode)',
273
224
  },
274
- },
275
- required: ['content'],
276
- },
277
- },
278
- handler: async (args) => {
279
- const action = args.action || 'save';
280
- const sessionId = args.session_id;
281
- switch (action) {
282
- case 'recall': {
283
- // Get checkpoints and insights
284
- const checkpoints = await getCheckpoints({ session_id: sessionId });
285
- const insights = await getInsights({ session_id: sessionId, limit: 10 });
286
- const userContext = await getUserContext({ include_recent_insights: true, include_session_history: true });
287
- return {
288
- checkpoints,
289
- insights,
290
- user_context: userContext,
291
- };
292
- }
293
- case 'list':
294
- return getInsights({ session_id: sessionId, limit: 20 });
295
- case 'save':
296
- default:
297
- return handleSmartContext({
298
- content: args.content,
299
- type: args.type || 'insight',
300
- tags: args.tags,
301
- session_id: args.session_id,
302
- });
303
- }
304
- },
305
- };
306
- const protectTool = {
307
- definition: {
308
- name: 'protect',
309
- description: 'File protection and safety: prevent accidental deletions, create automatic backups, rollback changes, enable code freeze mode. Essential for safe AI-assisted development. Triggers: "backup", "protect", "freeze", "rollback", "undo", "restore", "safe mode".',
310
- annotations: {
311
- readOnlyHint: false,
312
- destructiveHint: false,
313
- idempotentHint: false,
314
- openWorldHint: false,
315
- },
316
- inputSchema: {
317
- type: 'object',
318
- properties: {
319
- action: {
320
- type: 'string',
321
- enum: ['check', 'backup', 'rollback', 'freeze', 'unfreeze', 'status', 'history'],
322
- description: 'Action to perform',
323
- },
324
- path: {
225
+ language: {
325
226
  type: 'string',
326
- description: 'File path (for check, backup, rollback)',
227
+ description: 'Programming language (auto-detected if not specified)',
327
228
  },
328
- operation: {
229
+ registry: {
329
230
  type: 'string',
330
- enum: ['delete', 'overwrite', 'move'],
331
- description: 'Operation type (for check)',
231
+ enum: ['npm', 'pypi', 'maven', 'cargo', 'go', 'nuget', 'gem'],
232
+ description: 'Package registry (default: npm)',
332
233
  },
333
- backup_id: {
334
- type: 'string',
335
- description: 'Backup ID (for rollback)',
234
+ auto_fix: {
235
+ type: 'boolean',
236
+ description: 'Attempt to auto-fix issues (default: false, code mode only)',
336
237
  },
337
238
  },
338
- required: ['action'],
239
+ required: ['mode'],
339
240
  },
340
241
  },
341
242
  handler: async (args) => {
342
- const action = args.action;
343
- // path is required for check and backup — validate before delegating
344
- if ((action === 'check' || action === 'backup') && !args.path) {
345
- return {
346
- success: false,
347
- error: `path is required for action='${action}'`,
348
- action,
349
- };
350
- }
351
- switch (action) {
352
- case 'check':
353
- return protectFiles({
354
- operation: args.operation,
355
- path: args.path,
243
+ const mode = args.mode;
244
+ switch (mode) {
245
+ case 'code':
246
+ if (!args.content) {
247
+ return { success: false, error: 'content is required for code review mode' };
248
+ }
249
+ return handleComprehensiveCodeReview({
250
+ code: args.content,
251
+ language: args.language,
252
+ auto_fix: args.auto_fix,
356
253
  });
357
- case 'status':
358
- return getProtectionStatus({});
359
- case 'history':
360
- return listBackups({});
361
- case 'rollback':
362
- return rollbackFile({ backup_id: args.backup_id });
363
- case 'freeze':
364
- return enableCodeFreeze({});
365
- case 'unfreeze':
366
- return disableCodeFreeze({});
367
- case 'backup':
368
- // Create a backup by doing a protected check
369
- return protectFiles({
370
- operation: 'overwrite',
371
- path: args.path,
254
+ case 'packages':
255
+ if (!args.packages) {
256
+ return { success: false, error: 'packages array is required for packages mode' };
257
+ }
258
+ return handleComprehensivePackageAudit({
259
+ packages: args.packages,
260
+ registry: args.registry,
372
261
  });
262
+ case 'verify':
263
+ if (!args.content) {
264
+ return { success: false, error: 'content is required for verify mode' };
265
+ }
266
+ return handleVerify({
267
+ type: 'all',
268
+ content: args.content,
269
+ language: args.language,
270
+ registry: args.registry,
271
+ });
272
+ case 'full': {
273
+ const results = {};
274
+ if (args.content) {
275
+ results.code_review = await handleComprehensiveCodeReview({
276
+ code: args.content,
277
+ language: args.language,
278
+ auto_fix: args.auto_fix,
279
+ });
280
+ results.verification = await handleVerify({
281
+ type: 'all',
282
+ content: args.content,
283
+ language: args.language,
284
+ });
285
+ }
286
+ if (args.packages) {
287
+ results.package_audit = await handleComprehensivePackageAudit({
288
+ packages: args.packages,
289
+ registry: args.registry,
290
+ });
291
+ }
292
+ if (!args.content && !args.packages) {
293
+ return { success: false, error: 'content or packages required for full mode' };
294
+ }
295
+ return { success: true, mode: 'full', results };
296
+ }
373
297
  default:
374
- return { error: `Unknown action: ${action}` };
298
+ return { success: false, error: `Unknown mode: ${mode}. Use: code, packages, verify, or full` };
375
299
  }
376
300
  },
377
301
  };
378
302
  // ============================================================
379
- // EXPORT ONLY PRIMARY TOOLS
303
+ // EXPORT ONLY PRIMARY TOOLS (4 tools)
380
304
  // ============================================================
381
305
  // ─────────────────────────────────────────────────────────────────────────────
382
306
  // Policy wrapper helpers
383
307
  // ─────────────────────────────────────────────────────────────────────────────
384
308
  /**
385
309
  * Wrap a tool handler so every call goes through:
386
- * execute → sanitize → verify-if-required → normalize → log
387
- *
388
- * The wrapped handler is used for BOTH direct MCP calls and intent-router
389
- * (couchloop) delegated calls, since registerTools() stores references to
390
- * these same handler functions.
310
+ * execute → sanitize → guard-if-clinical → verify-if-required → normalize → log
391
311
  */
392
312
  function withPolicy(toolName, handler, routedVia = 'direct') {
393
313
  return async (args, _routedVia) => {
@@ -402,30 +322,21 @@ function withPolicy(toolName, handler, routedVia = 'direct') {
402
322
  };
403
323
  }
404
324
  export async function setupTools() {
405
- // Register tools with V2 registry for health tracking
406
325
  const registry = ToolRegistry.getInstance();
407
- // Domain-specific tools — handlers wrapped with the policy layer.
326
+ // 4 public tools — memory first (hero feature), then conversation, review, status
408
327
  const rawDomainTools = [
409
- guardTool,
410
- verifyTool,
411
- statusTool,
328
+ memoryTool,
412
329
  conversationTool,
413
- brainstormTool,
414
- codeReviewTool,
415
- packageAuditTool,
416
- rememberTool,
417
- protectTool,
330
+ reviewTool,
331
+ statusTool,
418
332
  ];
419
333
  const domainTools = rawDomainTools.map((tool) => {
420
334
  const wrappedHandler = withPolicy(tool.definition.name, tool.handler);
421
- // Register real handler into V2 registry.
422
- // Uses existing metadata if already registered (from initializeToolRegistry),
423
- // otherwise falls back to a minimal metadata stub so health tracking still works.
424
335
  const toolName = tool.definition.name;
425
336
  const existing = registry.getTool(toolName);
426
337
  const metadata = existing?.metadata ?? {
427
338
  toolName,
428
- version: '2.0.0',
339
+ version: '2.1.0',
429
340
  capabilities: [],
430
341
  latencyProfile: { p50Ms: 500, p95Ms: 1000 },
431
342
  constraints: { idempotent: false, safeParallel: false, supportsCache: false },
@@ -437,18 +348,9 @@ export async function setupTools() {
437
348
  handler: wrappedHandler,
438
349
  };
439
350
  });
440
- // Register domain tools for legacy compatibility (will be removed later)
441
- registerTools(domainTools);
442
- // V2 ORCHESTRATION: couchloopV2 replaces the old intent router
443
- // It now handles routing through the new modular pipeline:
444
- // Request → Classify → Policy → Plan → Execute → Compose
445
- const tools = [
446
- couchloopV2Tool, // V2 orchestration with 100% rollout!
447
- ...domainTools,
448
- ];
449
- logger.info(`🚀 V2 ORCHESTRATION ACTIVE: ${tools.length} primary MCP tools`);
450
- logger.info('Architecture: Request → Classify → Policy → Plan → Execute → Compose');
451
- logger.info('Performance: 60%+ direct routing, 33% faster P95 latency');
351
+ // No router tool LLMs route directly with clear descriptions
352
+ const tools = [...domainTools];
353
+ logger.info(`Registered ${tools.length} public MCP tools: ${tools.map(t => t.definition.name).join(', ')}`);
452
354
  return tools;
453
355
  }
454
356
  // Also export for internal use