create-merlin-brain 3.8.2 → 3.10.0

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 (138) hide show
  1. package/bin/install.cjs +126 -21
  2. package/dist/server/api/client.d.ts.map +1 -1
  3. package/dist/server/api/client.js +11 -7
  4. package/dist/server/api/client.js.map +1 -1
  5. package/dist/server/cost/classifier.d.ts +22 -0
  6. package/dist/server/cost/classifier.d.ts.map +1 -0
  7. package/dist/server/cost/classifier.js +137 -0
  8. package/dist/server/cost/classifier.js.map +1 -0
  9. package/dist/server/cost/tracker.d.ts +34 -0
  10. package/dist/server/cost/tracker.d.ts.map +1 -0
  11. package/dist/server/cost/tracker.js +81 -0
  12. package/dist/server/cost/tracker.js.map +1 -0
  13. package/dist/server/lang/detector.d.ts +17 -0
  14. package/dist/server/lang/detector.d.ts.map +1 -0
  15. package/dist/server/lang/detector.js +144 -0
  16. package/dist/server/lang/detector.js.map +1 -0
  17. package/dist/server/lang/rules.d.ts +21 -0
  18. package/dist/server/lang/rules.d.ts.map +1 -0
  19. package/dist/server/lang/rules.js +70 -0
  20. package/dist/server/lang/rules.js.map +1 -0
  21. package/dist/server/server.d.ts.map +1 -1
  22. package/dist/server/server.js +74 -26
  23. package/dist/server/server.js.map +1 -1
  24. package/dist/server/tools/adaptive.d.ts.map +1 -1
  25. package/dist/server/tools/adaptive.js +2 -1
  26. package/dist/server/tools/adaptive.js.map +1 -1
  27. package/dist/server/tools/agents-index.d.ts.map +1 -1
  28. package/dist/server/tools/agents-index.js +6 -3
  29. package/dist/server/tools/agents-index.js.map +1 -1
  30. package/dist/server/tools/agents.d.ts.map +1 -1
  31. package/dist/server/tools/agents.js +10 -5
  32. package/dist/server/tools/agents.js.map +1 -1
  33. package/dist/server/tools/auto-teach.d.ts.map +1 -1
  34. package/dist/server/tools/auto-teach.js +2 -1
  35. package/dist/server/tools/auto-teach.js.map +1 -1
  36. package/dist/server/tools/behaviors.d.ts.map +1 -1
  37. package/dist/server/tools/behaviors.js +8 -4
  38. package/dist/server/tools/behaviors.js.map +1 -1
  39. package/dist/server/tools/config-sync.d.ts.map +1 -1
  40. package/dist/server/tools/config-sync.js +8 -4
  41. package/dist/server/tools/config-sync.js.map +1 -1
  42. package/dist/server/tools/context.d.ts.map +1 -1
  43. package/dist/server/tools/context.js +66 -7
  44. package/dist/server/tools/context.js.map +1 -1
  45. package/dist/server/tools/cost.d.ts +7 -0
  46. package/dist/server/tools/cost.d.ts.map +1 -0
  47. package/dist/server/tools/cost.js +53 -0
  48. package/dist/server/tools/cost.js.map +1 -0
  49. package/dist/server/tools/discoveries.d.ts.map +1 -1
  50. package/dist/server/tools/discoveries.js +8 -11
  51. package/dist/server/tools/discoveries.js.map +1 -1
  52. package/dist/server/tools/lite.d.ts.map +1 -1
  53. package/dist/server/tools/lite.js +8 -4
  54. package/dist/server/tools/lite.js.map +1 -1
  55. package/dist/server/tools/project.d.ts.map +1 -1
  56. package/dist/server/tools/project.js +14 -7
  57. package/dist/server/tools/project.js.map +1 -1
  58. package/dist/server/tools/route.d.ts.map +1 -1
  59. package/dist/server/tools/route.js +145 -31
  60. package/dist/server/tools/route.js.map +1 -1
  61. package/dist/server/tools/sights-index.d.ts.map +1 -1
  62. package/dist/server/tools/sights-index.js +4 -2
  63. package/dist/server/tools/sights-index.js.map +1 -1
  64. package/dist/server/tools/smart-route.d.ts +12 -0
  65. package/dist/server/tools/smart-route.d.ts.map +1 -0
  66. package/dist/server/tools/smart-route.js +156 -0
  67. package/dist/server/tools/smart-route.js.map +1 -0
  68. package/dist/server/tools/verification.d.ts.map +1 -1
  69. package/dist/server/tools/verification.js +2 -1
  70. package/dist/server/tools/verification.js.map +1 -1
  71. package/files/agents/code-organization-supervisor.md +1 -0
  72. package/files/agents/context-guardian.md +1 -0
  73. package/files/agents/docs-keeper.md +1 -0
  74. package/files/agents/dry-refactor.md +1 -0
  75. package/files/agents/elite-code-refactorer.md +1 -0
  76. package/files/agents/hardening-guard.md +1 -0
  77. package/files/agents/implementation-dev.md +1 -0
  78. package/files/agents/merlin-api-designer.md +1 -0
  79. package/files/agents/merlin-codebase-mapper.md +4 -0
  80. package/files/agents/merlin-debugger.md +1 -0
  81. package/files/agents/merlin-executor.md +1 -0
  82. package/files/agents/merlin-frontend.md +1 -0
  83. package/files/agents/merlin-integration-checker.md +1 -0
  84. package/files/agents/merlin-migrator.md +1 -0
  85. package/files/agents/merlin-milestone-auditor.md +1 -0
  86. package/files/agents/merlin-performance.md +1 -0
  87. package/files/agents/merlin-planner.md +1 -0
  88. package/files/agents/merlin-researcher.md +4 -0
  89. package/files/agents/merlin-reviewer.md +1 -0
  90. package/files/agents/merlin-security.md +1 -0
  91. package/files/agents/merlin-verifier.md +1 -0
  92. package/files/agents/merlin-work-verifier.md +1 -0
  93. package/files/agents/merlin.md +19 -3
  94. package/files/agents/ops-railway.md +1 -0
  95. package/files/agents/orchestrator-retrofit.md +1 -0
  96. package/files/agents/product-spec.md +1 -0
  97. package/files/agents/remotion.md +1 -0
  98. package/files/agents/system-architect.md +1 -0
  99. package/files/agents/tests-qa.md +1 -0
  100. package/files/commands/merlin/help.md +11 -0
  101. package/files/commands/merlin/loop-recipes.md +73 -0
  102. package/files/hooks/agent-sync.sh +3 -0
  103. package/files/hooks/check-file-size.sh +12 -0
  104. package/files/hooks/config-change.sh +43 -0
  105. package/files/hooks/instructions-loaded.sh +34 -0
  106. package/files/hooks/session-start.sh +52 -2
  107. package/files/hooks/worktree-create.sh +44 -0
  108. package/files/hooks/worktree-remove.sh +36 -0
  109. package/files/loop/lib/agents.sh +3 -0
  110. package/files/loop/lib/blend-handoff.sh +3 -0
  111. package/files/loop/lib/blend-learn.sh +3 -0
  112. package/files/loop/lib/blend-parallel.sh +3 -0
  113. package/files/loop/lib/blend-verify.sh +3 -0
  114. package/files/loop/lib/blend.sh +3 -0
  115. package/files/loop/lib/boot.sh +3 -0
  116. package/files/loop/lib/context.sh +3 -0
  117. package/files/loop/lib/discuss.sh +3 -0
  118. package/files/loop/lib/modes.sh +3 -0
  119. package/files/loop/lib/progress.sh +3 -0
  120. package/files/loop/lib/safety.sh +3 -0
  121. package/files/loop/lib/session-end.sh +3 -0
  122. package/files/loop/lib/sights.sh +3 -0
  123. package/files/loop/lib/state.sh +3 -0
  124. package/files/loop/lib/teams.sh +3 -0
  125. package/files/loop/lib/timeout.sh +3 -0
  126. package/files/loop/lib/tui.sh +3 -0
  127. package/files/loop/lib/workflow-gen.sh +3 -0
  128. package/files/loop/lib/workflow-run.sh +3 -0
  129. package/files/loop/lib/workflow.sh +3 -0
  130. package/files/loop/merlin-loop.sh +3 -0
  131. package/files/loop/merlin-session.sh +3 -0
  132. package/package.json +2 -1
  133. package/rules/go.md +38 -0
  134. package/rules/java.md +36 -0
  135. package/rules/python.md +38 -0
  136. package/rules/rust.md +34 -0
  137. package/rules/swift.md +35 -0
  138. package/rules/typescript.md +38 -0
@@ -20,11 +20,13 @@ import { registerAdaptiveTools } from './tools/adaptive.js';
20
20
  import { registerAgentTools } from './tools/agents.js';
21
21
  import { registerDiscoveryTools } from './tools/discoveries.js';
22
22
  import { registerRouteTools } from './tools/route.js';
23
+ import { registerCostTools } from './tools/cost.js';
23
24
  import { registerLiteTools, getOrInitLiteClient, enhanceFromCloud } from './tools/lite.js';
24
25
  import { registerConfigSyncTools } from './tools/config-sync.js';
25
26
  import { registerSightsIndexTools } from './tools/sights-index.js';
26
27
  import { registerAgentsIndexTools } from './tools/agents-index.js';
27
28
  import { registerAutoTeachTools, assessContextConfidence, buildTeachBackPrompt } from './tools/auto-teach.js';
29
+ import { registerSmartRouteTools } from './tools/smart-route.js';
28
30
  import { wrapResponse, getStats, getCompactStats, formatSaveNotification, markSessionStatusShown } from './stats.js';
29
31
  import { coachWrap, recordToolCall } from './session-coach.js';
30
32
  /** Load saved config from ~/.merlin/config.json */
@@ -272,8 +274,9 @@ export function createServer() {
272
274
  // ============================================================
273
275
  // TOOLS
274
276
  // ============================================================
277
+ // ── CORE tool: always loaded, used at every session start ──────────────
275
278
  // Tool: merlin_get_brief
276
- server.tool('merlin_get_brief', 'Get structured project brief for session start. Returns ~500 token summary: product, architecture, status, APIs. Call this after selecting a repo to understand the full picture.', {
279
+ server.tool('merlin_get_brief', 'Get structured project brief at session start. Returns ~500-token summary covering product purpose, tech stack, architecture, active tasks, shipped APIs, and coding rules. Call after selecting a repo to orient yourself before coding, planning, or reviewing.', {
277
280
  repoUrl: z.string().optional().describe('GitHub URL of the repository (uses selected repo if omitted)'),
278
281
  }, async ({ repoUrl }) => {
279
282
  try {
@@ -402,8 +405,9 @@ export function createServer() {
402
405
  };
403
406
  }
404
407
  });
408
+ // ── CORE tool: MANDATORY before every file edit or code modification ────
405
409
  // Tool: merlin_get_context
406
- server.tool('merlin_get_context', `MANDATORY before ANY file edit or creation. Call this BEFORE every code change — not just once per session, but before EACH file you modify. Returns codebase context, existing patterns, and related files in ~2 seconds. Without this, you WILL duplicate existing code or break established patterns. Re-call every few minutes even for the same task the codebase changes.`, {
410
+ server.tool('merlin_get_context', `MANDATORY before every file edit, code modification, or feature implementation. Call before EACH file you modify — not just once per session. Returns codebase conventions, relevant file locations, how-to guide, anti-patterns, and auto-apply behavior patterns for the given task. Without this, you WILL duplicate existing code or break established patterns. Re-call every few minutes the codebase changes. Works in both cloud (Sights) and local Lite mode.`, {
407
411
  task: z.string().describe('What you want to know or do (e.g., "how does profile creation work", "add authentication", "where is the payment logic")'),
408
412
  repoUrl: z.string().optional().describe('GitHub URL of the repository (auto-detected from git if omitted)'),
409
413
  }, async ({ task, repoUrl }) => {
@@ -614,8 +618,9 @@ export function createServer() {
614
618
  };
615
619
  }
616
620
  });
621
+ // ── CORE tool: always loaded, used before reading or modifying any file ─
617
622
  // Tool: merlin_find_files
618
- server.tool('merlin_find_files', 'Find files by purpose or layer. Call this BEFORE creating new files to check if something similar already exists. Re-fetch before editing — files change frequently. Returns file paths with descriptions.', {
623
+ server.tool('merlin_find_files', 'Find files by purpose, description, or architectural layer (routes, services, models, utils, components, hooks, middleware, etc.). Returns file paths, exports, and what to modify for specific tasks. Call BEFORE creating new files to check if something similar already exists. ALWAYS re-fetch before editing — files may have changed. Use this to locate existing functions before adding duplicates.', {
619
624
  query: z.string().describe('What you are looking for (e.g., "authentication", "database models", "API routes", "payment handling")'),
620
625
  layer: z.string().optional().describe('Filter by layer (routes, services, models, utils, components, etc.)'),
621
626
  repoUrl: z.string().optional().describe('GitHub URL of the repository (auto-detected from git if omitted)'),
@@ -706,8 +711,9 @@ export function createServer() {
706
711
  };
707
712
  }
708
713
  });
714
+ // ── DEFERRED tool: loaded on-demand for style/rule questions ────────────
709
715
  // Tool: merlin_get_conventions
710
- server.tool('merlin_get_conventions', 'Get coding conventions and anti-patterns for the repository.', {
716
+ server.tool('merlin_get_conventions', 'Get all coding conventions, anti-patterns, style rules, naming guidelines, and change guides for the repository. Use when reviewing code quality, enforcing standards, understanding what patterns to avoid, or learning how to make specific types of changes. Returns category-organized rules with examples and example files.', {
711
717
  repoUrl: z.string().optional().describe('GitHub URL of the repository (auto-detected from git if omitted)'),
712
718
  }, async ({ repoUrl }) => {
713
719
  try {
@@ -801,8 +807,9 @@ export function createServer() {
801
807
  };
802
808
  }
803
809
  });
810
+ // ── DEFERRED tool: loaded on-demand for onboarding/orientation ──────────
804
811
  // Tool: merlin_quickstart
805
- server.tool('merlin_quickstart', 'Get a 60-second overview of the codebase. Use this when first working with a repository.', {
812
+ server.tool('merlin_quickstart', 'Get a 60-second overview and onboarding guide for the codebase. Returns the project quickstart document covering repo structure, entry points, dev commands, and key concepts. Use when first working with an unfamiliar repository, introducing a new team member, or needing a fast orientation without digging into code.', {
806
813
  repoUrl: z.string().optional().describe('GitHub URL of the repository (auto-detected from git if omitted)'),
807
814
  }, async ({ repoUrl }) => {
808
815
  try {
@@ -858,8 +865,9 @@ export function createServer() {
858
865
  };
859
866
  }
860
867
  });
868
+ // ── CORE tool: always loaded, used for searching documentation ──────────
861
869
  // Tool: merlin_search
862
- server.tool('merlin_search', 'Search project documentation for patterns, flows, and implementations. Call this when you need to understand how something works before changing it. Wiki updates in real-time — always search fresh, never assume earlier results are still accurate.', {
870
+ server.tool('merlin_search', 'Search project documentation, wiki, and knowledge base by keyword or concept. Returns matching documentation sections, guides, and explanations that update in real-time as the team commits code. Use to find API docs, architecture notes, setup instructions, or any documented behavior. Complements merlin_get_context for targeted keyword search. Wiki updates in real-time — always fetch fresh.', {
863
871
  query: z.string().describe('What you want to find (e.g., "profile creation flow", "authentication", "payment API")'),
864
872
  repoUrl: z.string().optional().describe('GitHub URL of the repository (auto-detected from git if omitted)'),
865
873
  }, async ({ query, repoUrl }) => {
@@ -909,8 +917,9 @@ export function createServer() {
909
917
  };
910
918
  }
911
919
  });
920
+ // ── DEFERRED tool: loaded on-demand for listing available Sights ─────────
912
921
  // Tool: merlin_list_repos
913
- server.tool('merlin_list_repos', 'List all repositories you have analyzed on Merlin.', {}, async () => {
922
+ server.tool('merlin_list_repos', 'List all repositories you have connected and analyzed on Merlin Sights. Returns repo names, GitHub URLs, analysis status (completed/pending/failed), and creation dates. Use to discover which Sights are available, find the URL for merlin_select_repo, or audit your connected repositories.', {}, async () => {
914
923
  try {
915
924
  const repos = await client.getRepositories();
916
925
  if (repos.length === 0) {
@@ -972,8 +981,9 @@ export function createServer() {
972
981
  };
973
982
  }
974
983
  });
984
+ // ── CORE tool: always loaded, used to connect a specific repo ───────────
975
985
  // Tool: merlin_select_repo
976
- server.tool('merlin_select_repo', 'Select which Merlin Sight to use for this session. Call this at the start of every session to explicitly connect to a repository. This takes precedence over auto-detection.', {
986
+ server.tool('merlin_select_repo', 'Explicitly select which Merlin Sight (analyzed repository) to use for this session. Overrides auto-detection from git remote. Call when auto-detection picks the wrong repo, when working on a repo with multiple remotes, or when the auto-detected repo is not connected to Sights. Takes a GitHub URL and sets it as the active Sight for all subsequent tool calls.', {
977
987
  repoUrl: z.string().describe('GitHub URL of the repository to use (e.g., "github.com/user/repo" or full URL)'),
978
988
  projectDir: z.string().optional().describe('Local project directory path (helps when auto-detection fails). Get via Bash(pwd).'),
979
989
  }, async ({ repoUrl, projectDir }) => {
@@ -1062,8 +1072,9 @@ export function createServer() {
1062
1072
  };
1063
1073
  }
1064
1074
  });
1075
+ // ── CORE tool: MANDATORY first call at every session start ──────────────
1065
1076
  // Tool: merlin_get_selected_repo
1066
- server.tool('merlin_get_selected_repo', 'CALL THIS FIRST at session start. Connects to Merlin Sights and returns repository info. Must be called before any other work.', {}, async () => {
1077
+ server.tool('merlin_get_selected_repo', 'CALL THIS FIRST at every session start. Connects to Merlin Sights, auto-detects the current repository from git remote, returns repository info (name, URL, analysis status), available Sights list, and repo root path for file operations. Must be called before any other Merlin tool. Without this, context tools cannot resolve the correct codebase.', {}, async () => {
1067
1078
  // Mark session status as shown - this is the required first call
1068
1079
  markSessionStatusShown();
1069
1080
  recordToolCall('merlin_get_selected_repo');
@@ -1193,8 +1204,9 @@ export function createServer() {
1193
1204
  throw error;
1194
1205
  }
1195
1206
  });
1207
+ // ── DEFERRED tool: loaded on-demand for polling analysis completion ──────
1196
1208
  if (hasCloudApi && !coreOnly) { // Tool: merlin_check_repo_status
1197
- server.tool('merlin_check_repo_status', 'Check if a repository analysis is complete. Use after merlin_connect_repo to poll for completion. Returns status: pending, analyzing, completed, or failed.', {
1209
+ server.tool('merlin_check_repo_status', 'Poll whether a repository analysis is complete after calling merlin_connect_repo. Returns status: pending, analyzing, completed, or failed, plus estimated time remaining. Use in a loop with 30-second intervals after connecting a new repo until status is "completed" before using context tools.', {
1198
1210
  repoUrl: z.string().optional().describe('GitHub URL of the repository (uses selected repo if omitted)'),
1199
1211
  }, async ({ repoUrl }) => {
1200
1212
  try {
@@ -1295,8 +1307,9 @@ export function createServer() {
1295
1307
  }
1296
1308
  });
1297
1309
  } // end cloud: merlin_check_repo_status
1310
+ // ── DEFERRED tool: loaded on-demand for onboarding new repositories ──────
1298
1311
  // Tool: merlin_connect_repo
1299
- server.tool('merlin_connect_repo', 'Connect a new repository to Merlin Sights for analysis. Use this when working on a repo that is not yet in Sights. Analysis takes 2-5 minutes.', {
1312
+ server.tool('merlin_connect_repo', 'Connect and submit a new GitHub repository to Merlin Sights for analysis and indexing. Use when working on a repo not yet in Sights analysis takes 2-5 minutes. After connecting, poll with merlin_check_repo_status until completed, then use merlin_get_context and merlin_find_files as normal.', {
1300
1313
  repoUrl: z.string().describe('GitHub URL of the repository (e.g., "https://github.com/user/repo")'),
1301
1314
  branch: z.string().optional().default('main').describe('Branch to analyze (default: main)'),
1302
1315
  }, async ({ repoUrl, branch }) => {
@@ -1469,8 +1482,9 @@ export function createServer() {
1469
1482
  };
1470
1483
  }
1471
1484
  });
1485
+ // ── DEFERRED tool: loaded on-demand for change impact assessment ─────────
1472
1486
  // Tool: merlin_impact_analysis
1473
- server.tool('merlin_impact_analysis', 'CALL BEFORE modifying any file. Analyzes what could break if you change a specific file. Returns dependent files that might need updates. Prevents cascading breakage.', {
1487
+ server.tool('merlin_impact_analysis', 'Analyze what could break if you modify a specific file. Returns all dependent files, importers, and downstream consumers that may need updates. Use before refactoring, renaming exports, changing function signatures, or modifying shared utilities to prevent cascading breakage.', {
1474
1488
  filePath: z.string().describe('The file path you plan to modify (e.g., "src/services/user.ts")'),
1475
1489
  repoUrl: z.string().optional().describe('GitHub URL of the repository (auto-detected from git if omitted)'),
1476
1490
  }, async ({ filePath, repoUrl }) => {
@@ -1499,8 +1513,9 @@ export function createServer() {
1499
1513
  };
1500
1514
  }
1501
1515
  });
1516
+ // ── DEFERRED tool: loaded on-demand for finding existing patterns ─────────
1502
1517
  if (hasCloudApi && !coreOnly) { // Tool: merlin_similar_code
1503
- server.tool('merlin_similar_code', 'Find similar implementations in the codebase BEFORE writing new code. Prevents duplicating existing patterns. Use this when implementing anything — there is likely an existing pattern to follow.', {
1518
+ server.tool('merlin_similar_code', 'Find similar existing implementations in the codebase before writing new code. Returns matching patterns, functions, or components already built that serve similar purposes. Use when implementing anything new — there is likely an existing pattern to follow or extend. Prevents duplicating code and enforces DRY principles.', {
1504
1519
  description: z.string().describe('What you\'re trying to implement (e.g., "API endpoint with authentication", "database query with pagination", "React form with validation")'),
1505
1520
  repoUrl: z.string().optional().describe('GitHub URL of the repository (auto-detected from git if omitted)'),
1506
1521
  }, async ({ description, repoUrl }) => {
@@ -1530,8 +1545,9 @@ export function createServer() {
1530
1545
  }
1531
1546
  });
1532
1547
  } // end cloud: merlin_similar_code
1548
+ // ── DEFERRED tool: loaded on-demand for getting real code patterns ────────
1533
1549
  if (hasCloudApi && !coreOnly) { // Tool: merlin_code_examples
1534
- server.tool('merlin_code_examples', 'Get real code examples from this codebase for common tasks. Shows actual patterns used in this project.', {
1550
+ server.tool('merlin_code_examples', 'Get real code examples extracted from this codebase for specific tasks. Returns actual patterns, templates, and snippets used in production. Use when you need to see how a pattern is really implemented (not just described) — e.g., "add endpoint", "add test", "error handling", "database query".', {
1535
1551
  task: z.string().optional().describe('Specific task (e.g., "add endpoint", "add test", "error handling"). Leave empty for all examples.'),
1536
1552
  repoUrl: z.string().optional().describe('GitHub URL of the repository (auto-detected from git if omitted)'),
1537
1553
  }, async ({ task, repoUrl }) => {
@@ -1561,8 +1577,9 @@ export function createServer() {
1561
1577
  }
1562
1578
  });
1563
1579
  } // end cloud: merlin_code_examples
1580
+ // ── DEFERRED tool: loaded on-demand for natural language codebase Q&A ──
1564
1581
  // Tool: merlin_ask
1565
- server.tool('merlin_ask', 'Ask ANY question about the codebase in natural language. Uses AI-powered semantic search + RAG to find relevant context and generate accurate answers with source citations. Perfect for questions like "How does authentication work?", "Where should I add a new API endpoint?", "Why is X structured this way?"', {
1582
+ server.tool('merlin_ask', 'Ask any natural language question about the codebase and get an AI-generated answer with source citations. Uses semantic search and RAG to find relevant context across documentation, code, and conventions. Use when you need a direct answer with explanation rather than raw files e.g., "how does authentication work?", "where is billing handled?", "where should I add a new API endpoint?", "why is X structured this way?".', {
1566
1583
  question: z.string().describe('Your question in natural language (e.g., "How does the payment flow work?", "Where is user validation handled?", "What patterns are used for error handling?")'),
1567
1584
  quick: z.boolean().optional().default(false).describe('If true, returns a faster but shorter answer without detailed sources'),
1568
1585
  repoUrl: z.string().optional().describe('GitHub URL of the repository (auto-detected from git if omitted)'),
@@ -1629,8 +1646,9 @@ export function createServer() {
1629
1646
  // ============================================================
1630
1647
  // AGENT MEMORY - Write Tools
1631
1648
  // ============================================================
1649
+ // ── DEFERRED tool: loaded on-demand for persisting cross-session data ────
1632
1650
  // Tool: merlin_write_state
1633
- server.tool('merlin_write_state', 'Write state to Merlin cloud. Use for persisting PROJECT.md, ROADMAP.md, STATE.md, or any planning artifacts for cross-session memory.', {
1651
+ server.tool('merlin_write_state', 'Persist arbitrary state to Merlin cloud storage for cross-session and cross-agent memory. Use to save project artifacts (PROJECT.md, ROADMAP.md, STATE.md), planning data, decisions, agent outputs, or any data that needs to survive context resets. Supports optimistic locking via version parameter to prevent concurrent overwrites.', {
1634
1652
  key: z.string().describe('State key (e.g., "project", "roadmap", "state", "phase_3")'),
1635
1653
  value: z.any().describe('The state data to store (will be JSON serialized)'),
1636
1654
  agentId: z.string().optional().describe('Agent identifier for tracking who wrote the state'),
@@ -1687,8 +1705,9 @@ export function createServer() {
1687
1705
  };
1688
1706
  }
1689
1707
  });
1708
+ // ── DEFERRED tool: loaded on-demand for restoring cross-session data ─────
1690
1709
  // Tool: merlin_read_state
1691
- server.tool('merlin_read_state', 'Read state from Merlin cloud. Use to restore cross-session memory like PROJECT.md, ROADMAP.md, or STATE.md.', {
1710
+ server.tool('merlin_read_state', 'Read previously persisted state from Merlin cloud storage. Use to restore cross-session memory like PROJECT.md, ROADMAP.md, STATE.md, agent outputs, or any data saved with merlin_write_state. Returns the stored value and metadata (version, last updated, written by).', {
1692
1711
  key: z.string().describe('State key to read (e.g., "project", "roadmap", "state")'),
1693
1712
  repoUrl: z.string().optional().describe('GitHub URL of the repository (auto-detected from git if omitted)'),
1694
1713
  }, async ({ key, repoUrl }) => {
@@ -1730,8 +1749,9 @@ export function createServer() {
1730
1749
  };
1731
1750
  }
1732
1751
  });
1752
+ // ── DEFERRED tool: loaded on-demand for auditing stored state ─────────────
1733
1753
  // Tool: merlin_list_state
1734
- server.tool('merlin_list_state', 'List all state keys stored for this repository. Shows what cross-session memory is available.', {
1754
+ server.tool('merlin_list_state', 'List all state keys stored in Merlin cloud for this repository. Returns key names, last-updated timestamps, and sizes. Use to discover what cross-session memory is available (PROJECT.md, ROADMAP.md, checkpoints, agent outputs, etc.) before reading specific keys with merlin_read_state.', {
1735
1755
  repoUrl: z.string().optional().describe('GitHub URL of the repository (auto-detected from git if omitted)'),
1736
1756
  }, async ({ repoUrl }) => {
1737
1757
  try {
@@ -1775,8 +1795,9 @@ export function createServer() {
1775
1795
  };
1776
1796
  }
1777
1797
  });
1798
+ // ── DEFERRED tool: loaded on-demand for team activity logging ─────────────
1778
1799
  if (hasCloudApi && !coreOnly) { // Tool: merlin_log_activity
1779
- server.tool('merlin_log_activity', 'Log an activity event to the team timeline. Use for tracking progress, milestones, and decisions.', {
1800
+ server.tool('merlin_log_activity', 'Log an activity event to the shared team timeline for audit trail and visibility. Use to record task completions, phase transitions, milestone achievements, decisions made, or any significant progress event. Events appear on the Merlin dashboard team timeline for coordination.', {
1780
1801
  eventType: z.string().describe('Event type (e.g., "phase_started", "task_completed", "blocker_hit", "decision_made")'),
1781
1802
  eventData: z.any().optional().describe('Additional event data (JSON object)'),
1782
1803
  agentId: z.string().describe('Agent identifier for tracking'),
@@ -1824,8 +1845,9 @@ export function createServer() {
1824
1845
  }
1825
1846
  });
1826
1847
  } // end cloud: merlin_log_activity
1848
+ // ── DEFERRED tool: loaded on-demand for syncing task state to cloud ───────
1827
1849
  if (hasCloudApi && !coreOnly) { // Tool: merlin_sync_task
1828
- server.tool('merlin_sync_task', 'Sync a task to Merlin cloud. Use to track work items, their status, and dependencies for team visibility.', {
1850
+ server.tool('merlin_sync_task', 'Sync a task (create or update) to Merlin cloud for team visibility and cross-agent coordination. Use to track work items with status (pending/in_progress/completed/blocked), dependencies (blockedBy/blocks), phase, plan, and owner agent. Tasks appear on the Merlin dashboard and can be queried by other agents.', {
1829
1851
  title: z.string().describe('Task title'),
1830
1852
  status: z.enum(['pending', 'in_progress', 'completed', 'blocked', 'skipped']).optional().describe('Task status'),
1831
1853
  description: z.string().optional().describe('Task description'),
@@ -1891,8 +1913,9 @@ export function createServer() {
1891
1913
  }
1892
1914
  });
1893
1915
  } // end cloud: merlin_sync_task
1916
+ // ── DEFERRED tool: loaded on-demand for viewing cloud task state ──────────
1894
1917
  if (hasCloudApi && !coreOnly) { // Tool: merlin_get_tasks
1895
- server.tool('merlin_get_tasks', 'Get tasks synced to Merlin. Shows work items from all agents for team coordination.', {
1918
+ server.tool('merlin_get_tasks', 'Retrieve tasks synced to Merlin cloud. Filter by status (pending/in_progress/completed/blocked), phase, or plan. Returns work items from all agents for team coordination and planning. Use to see what tasks exist before creating duplicates, check what others are working on, or audit overall progress.', {
1896
1919
  status: z.string().optional().describe('Filter by status (pending, in_progress, completed, blocked)'),
1897
1920
  phase: z.string().optional().describe('Filter by phase'),
1898
1921
  plan: z.string().optional().describe('Filter by plan'),
@@ -1954,8 +1977,9 @@ export function createServer() {
1954
1977
  }
1955
1978
  });
1956
1979
  } // end cloud: merlin_get_tasks
1980
+ // ── DEFERRED tool: loaded on-demand for escalating blockers to humans ────
1957
1981
  if (hasCloudApi && !coreOnly) { // Tool: merlin_report_blocker
1958
- server.tool('merlin_report_blocker', 'Report a blocker that requires human attention. The blocker will appear in the team dashboard for resolution.', {
1982
+ server.tool('merlin_report_blocker', 'Report a blocker or impediment that requires human attention, decision, or external action. Creates a visible alert on the team dashboard with severity level and context. Use when you hit an auth requirement, need a human decision point, encounter a critical error you cannot resolve, or need clarification before proceeding. Types: human_verify, auth_required, clarification, decision_point, external, error.', {
1959
1983
  title: z.string().describe('Brief description of the blocker'),
1960
1984
  blockerType: z.enum(['human_verify', 'auth_required', 'clarification', 'decision_point', 'external', 'error', 'other']).describe('Type of blocker'),
1961
1985
  description: z.string().optional().describe('Detailed description'),
@@ -2007,8 +2031,9 @@ export function createServer() {
2007
2031
  }
2008
2032
  });
2009
2033
  } // end cloud: merlin_report_blocker
2034
+ // ── DEFERRED tool: loaded on-demand for checking pending blockers ─────────
2010
2035
  if (hasCloudApi && !coreOnly) { // Tool: merlin_get_blockers
2011
- server.tool('merlin_get_blockers', 'Get open blockers awaiting resolution. Check before starting work to see if there are issues to resolve.', {
2036
+ server.tool('merlin_get_blockers', 'Get open blockers or impediments awaiting resolution. Returns blockers reported by any agent with status, severity, type, and context. Check at session start or before starting work to see if there are critical issues or human-required decisions pending. Filter by status: open, resolved, or all.', {
2012
2037
  status: z.string().optional().default('open').describe('Filter by status (open, resolved, all)'),
2013
2038
  repoUrl: z.string().optional().describe('GitHub URL of the repository (auto-detected from git if omitted)'),
2014
2039
  }, async ({ status, repoUrl }) => {
@@ -2059,8 +2084,9 @@ export function createServer() {
2059
2084
  }
2060
2085
  });
2061
2086
  } // end cloud: merlin_get_blockers
2087
+ // ── DEFERRED tool: loaded on-demand for human-in-the-loop checkpoints ────
2062
2088
  if (hasCloudApi && !coreOnly) { // Tool: merlin_create_checkpoint
2063
- server.tool('merlin_create_checkpoint', 'Create a checkpoint requiring human verification or decision. Pauses agent work until human responds.', {
2089
+ server.tool('merlin_create_checkpoint', 'Create a verification checkpoint that signals a human review is needed before work continues. Use for human_verify, auth_gate, decision_point, approval, or review situations. Includes a summary of what was built and a checklist of items for the human to verify. The checkpoint appears on the dashboard and can be resolved to resume work.', {
2064
2090
  title: z.string().describe('Checkpoint title'),
2065
2091
  checkpointType: z.enum(['human_verify', 'auth_gate', 'decision_point', 'approval', 'review']).describe('Type of checkpoint'),
2066
2092
  description: z.string().optional().describe('Detailed description'),
@@ -2118,8 +2144,9 @@ export function createServer() {
2118
2144
  }
2119
2145
  });
2120
2146
  } // end cloud: merlin_create_checkpoint
2147
+ // ── DEFERRED tool: loaded on-demand for team coordination overview ────────
2121
2148
  if (hasCloudApi && !coreOnly) { // Tool: merlin_get_team_state
2122
- server.tool('merlin_get_team_state', 'Get consolidated team state: active sessions, pending checkpoints, open blockers, task summary. Use at session start to see what others are working on.', {
2149
+ server.tool('merlin_get_team_state', 'Get consolidated team coordination state: active agent sessions, pending human checkpoints, open blockers, task summary counts (pending/in-progress/completed), and saved planning artifacts. Use at session start to see what other agents are working on, what decisions are pending, and what state is available for resuming work.', {
2123
2150
  repoUrl: z.string().optional().describe('GitHub URL of the repository (auto-detected from git if omitted)'),
2124
2151
  }, async ({ repoUrl }) => {
2125
2152
  try {
@@ -2213,8 +2240,9 @@ export function createServer() {
2213
2240
  }
2214
2241
  });
2215
2242
  } // end cloud: merlin_get_team_state
2243
+ // ── DEFERRED tool: loaded on-demand for session lifecycle management ──────
2216
2244
  if (hasCloudApi && !coreOnly) { // Tool: merlin_update_session
2217
- server.tool('merlin_update_session', 'Update your session status. Use to track your work progress and enable pause/resume across context resets.', {
2245
+ server.tool('merlin_update_session', 'Update your current session status and progress metadata for team visibility and pause/resume support. Records current phase, plan, task, completion count, and health score. Use to mark your session as active/paused/completed and track progress so other agents or humans can see where you are in the workflow.', {
2218
2246
  sessionId: z.string().describe('Unique session identifier'),
2219
2247
  agentId: z.string().describe('Agent identifier'),
2220
2248
  status: z.enum(['active', 'paused', 'completed', 'abandoned']).optional().describe('Session status'),
@@ -2545,6 +2573,26 @@ export function createServer() {
2545
2573
  });
2546
2574
  } // end free: registerRouteTools
2547
2575
  // ============================================================
2576
+ if (!coreOnly) {
2577
+ // SMART ROUTE TOOLS - Discovery-first agent routing
2578
+ // ============================================================
2579
+ registerSmartRouteTools({
2580
+ server,
2581
+ client,
2582
+ resolveRepoId,
2583
+ });
2584
+ } // end free: registerSmartRouteTools
2585
+ // ============================================================
2586
+ if (!coreOnly) {
2587
+ // COST TOOLS - Session cost tracking and model routing savings
2588
+ // ============================================================
2589
+ registerCostTools({
2590
+ server,
2591
+ client,
2592
+ resolveRepoId,
2593
+ });
2594
+ } // end free: registerCostTools
2595
+ // ============================================================
2548
2596
  if (hasCloudApi && !coreOnly) {
2549
2597
  // PUBLIC SIGHTS INDEX - Browse open source analyzed codebases
2550
2598
  // ============================================================