create-merlin-brain 3.8.2 → 3.9.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 (134) 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 +63 -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 +76 -13
  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/verification.d.ts.map +1 -1
  65. package/dist/server/tools/verification.js +2 -1
  66. package/dist/server/tools/verification.js.map +1 -1
  67. package/files/agents/code-organization-supervisor.md +1 -0
  68. package/files/agents/context-guardian.md +1 -0
  69. package/files/agents/docs-keeper.md +1 -0
  70. package/files/agents/dry-refactor.md +1 -0
  71. package/files/agents/elite-code-refactorer.md +1 -0
  72. package/files/agents/hardening-guard.md +1 -0
  73. package/files/agents/implementation-dev.md +1 -0
  74. package/files/agents/merlin-api-designer.md +1 -0
  75. package/files/agents/merlin-codebase-mapper.md +4 -0
  76. package/files/agents/merlin-debugger.md +1 -0
  77. package/files/agents/merlin-executor.md +1 -0
  78. package/files/agents/merlin-frontend.md +1 -0
  79. package/files/agents/merlin-integration-checker.md +1 -0
  80. package/files/agents/merlin-migrator.md +1 -0
  81. package/files/agents/merlin-milestone-auditor.md +1 -0
  82. package/files/agents/merlin-performance.md +1 -0
  83. package/files/agents/merlin-planner.md +1 -0
  84. package/files/agents/merlin-researcher.md +4 -0
  85. package/files/agents/merlin-reviewer.md +1 -0
  86. package/files/agents/merlin-security.md +1 -0
  87. package/files/agents/merlin-verifier.md +1 -0
  88. package/files/agents/merlin-work-verifier.md +1 -0
  89. package/files/agents/merlin.md +1 -0
  90. package/files/agents/ops-railway.md +1 -0
  91. package/files/agents/orchestrator-retrofit.md +1 -0
  92. package/files/agents/product-spec.md +1 -0
  93. package/files/agents/remotion.md +1 -0
  94. package/files/agents/system-architect.md +1 -0
  95. package/files/agents/tests-qa.md +1 -0
  96. package/files/commands/merlin/help.md +11 -0
  97. package/files/commands/merlin/loop-recipes.md +73 -0
  98. package/files/hooks/agent-sync.sh +3 -0
  99. package/files/hooks/check-file-size.sh +12 -0
  100. package/files/hooks/config-change.sh +43 -0
  101. package/files/hooks/instructions-loaded.sh +34 -0
  102. package/files/hooks/session-start.sh +5 -1
  103. package/files/hooks/worktree-create.sh +44 -0
  104. package/files/hooks/worktree-remove.sh +36 -0
  105. package/files/loop/lib/agents.sh +3 -0
  106. package/files/loop/lib/blend-handoff.sh +3 -0
  107. package/files/loop/lib/blend-learn.sh +3 -0
  108. package/files/loop/lib/blend-parallel.sh +3 -0
  109. package/files/loop/lib/blend-verify.sh +3 -0
  110. package/files/loop/lib/blend.sh +3 -0
  111. package/files/loop/lib/boot.sh +3 -0
  112. package/files/loop/lib/context.sh +3 -0
  113. package/files/loop/lib/discuss.sh +3 -0
  114. package/files/loop/lib/modes.sh +3 -0
  115. package/files/loop/lib/progress.sh +3 -0
  116. package/files/loop/lib/safety.sh +3 -0
  117. package/files/loop/lib/session-end.sh +3 -0
  118. package/files/loop/lib/sights.sh +3 -0
  119. package/files/loop/lib/state.sh +3 -0
  120. package/files/loop/lib/teams.sh +3 -0
  121. package/files/loop/lib/timeout.sh +3 -0
  122. package/files/loop/lib/tui.sh +3 -0
  123. package/files/loop/lib/workflow-gen.sh +3 -0
  124. package/files/loop/lib/workflow-run.sh +3 -0
  125. package/files/loop/lib/workflow.sh +3 -0
  126. package/files/loop/merlin-loop.sh +3 -0
  127. package/files/loop/merlin-session.sh +3 -0
  128. package/package.json +2 -1
  129. package/rules/go.md +38 -0
  130. package/rules/java.md +36 -0
  131. package/rules/python.md +38 -0
  132. package/rules/rust.md +34 -0
  133. package/rules/swift.md +35 -0
  134. package/rules/typescript.md +38 -0
@@ -20,6 +20,7 @@ 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';
@@ -272,8 +273,9 @@ export function createServer() {
272
273
  // ============================================================
273
274
  // TOOLS
274
275
  // ============================================================
276
+ // ── CORE tool: always loaded, used at every session start ──────────────
275
277
  // 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.', {
278
+ 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
279
  repoUrl: z.string().optional().describe('GitHub URL of the repository (uses selected repo if omitted)'),
278
280
  }, async ({ repoUrl }) => {
279
281
  try {
@@ -402,8 +404,9 @@ export function createServer() {
402
404
  };
403
405
  }
404
406
  });
407
+ // ── CORE tool: MANDATORY before every file edit or code modification ────
405
408
  // 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.`, {
409
+ 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
410
  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
411
  repoUrl: z.string().optional().describe('GitHub URL of the repository (auto-detected from git if omitted)'),
409
412
  }, async ({ task, repoUrl }) => {
@@ -614,8 +617,9 @@ export function createServer() {
614
617
  };
615
618
  }
616
619
  });
620
+ // ── CORE tool: always loaded, used before reading or modifying any file ─
617
621
  // 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.', {
622
+ 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
623
  query: z.string().describe('What you are looking for (e.g., "authentication", "database models", "API routes", "payment handling")'),
620
624
  layer: z.string().optional().describe('Filter by layer (routes, services, models, utils, components, etc.)'),
621
625
  repoUrl: z.string().optional().describe('GitHub URL of the repository (auto-detected from git if omitted)'),
@@ -706,8 +710,9 @@ export function createServer() {
706
710
  };
707
711
  }
708
712
  });
713
+ // ── DEFERRED tool: loaded on-demand for style/rule questions ────────────
709
714
  // Tool: merlin_get_conventions
710
- server.tool('merlin_get_conventions', 'Get coding conventions and anti-patterns for the repository.', {
715
+ 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
716
  repoUrl: z.string().optional().describe('GitHub URL of the repository (auto-detected from git if omitted)'),
712
717
  }, async ({ repoUrl }) => {
713
718
  try {
@@ -801,8 +806,9 @@ export function createServer() {
801
806
  };
802
807
  }
803
808
  });
809
+ // ── DEFERRED tool: loaded on-demand for onboarding/orientation ──────────
804
810
  // Tool: merlin_quickstart
805
- server.tool('merlin_quickstart', 'Get a 60-second overview of the codebase. Use this when first working with a repository.', {
811
+ 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
812
  repoUrl: z.string().optional().describe('GitHub URL of the repository (auto-detected from git if omitted)'),
807
813
  }, async ({ repoUrl }) => {
808
814
  try {
@@ -858,8 +864,9 @@ export function createServer() {
858
864
  };
859
865
  }
860
866
  });
867
+ // ── CORE tool: always loaded, used for searching documentation ──────────
861
868
  // 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.', {
869
+ 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
870
  query: z.string().describe('What you want to find (e.g., "profile creation flow", "authentication", "payment API")'),
864
871
  repoUrl: z.string().optional().describe('GitHub URL of the repository (auto-detected from git if omitted)'),
865
872
  }, async ({ query, repoUrl }) => {
@@ -909,8 +916,9 @@ export function createServer() {
909
916
  };
910
917
  }
911
918
  });
919
+ // ── DEFERRED tool: loaded on-demand for listing available Sights ─────────
912
920
  // Tool: merlin_list_repos
913
- server.tool('merlin_list_repos', 'List all repositories you have analyzed on Merlin.', {}, async () => {
921
+ 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
922
  try {
915
923
  const repos = await client.getRepositories();
916
924
  if (repos.length === 0) {
@@ -972,8 +980,9 @@ export function createServer() {
972
980
  };
973
981
  }
974
982
  });
983
+ // ── CORE tool: always loaded, used to connect a specific repo ───────────
975
984
  // 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.', {
985
+ 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
986
  repoUrl: z.string().describe('GitHub URL of the repository to use (e.g., "github.com/user/repo" or full URL)'),
978
987
  projectDir: z.string().optional().describe('Local project directory path (helps when auto-detection fails). Get via Bash(pwd).'),
979
988
  }, async ({ repoUrl, projectDir }) => {
@@ -1062,8 +1071,9 @@ export function createServer() {
1062
1071
  };
1063
1072
  }
1064
1073
  });
1074
+ // ── CORE tool: MANDATORY first call at every session start ──────────────
1065
1075
  // 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 () => {
1076
+ 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
1077
  // Mark session status as shown - this is the required first call
1068
1078
  markSessionStatusShown();
1069
1079
  recordToolCall('merlin_get_selected_repo');
@@ -1193,8 +1203,9 @@ export function createServer() {
1193
1203
  throw error;
1194
1204
  }
1195
1205
  });
1206
+ // ── DEFERRED tool: loaded on-demand for polling analysis completion ──────
1196
1207
  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.', {
1208
+ 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
1209
  repoUrl: z.string().optional().describe('GitHub URL of the repository (uses selected repo if omitted)'),
1199
1210
  }, async ({ repoUrl }) => {
1200
1211
  try {
@@ -1295,8 +1306,9 @@ export function createServer() {
1295
1306
  }
1296
1307
  });
1297
1308
  } // end cloud: merlin_check_repo_status
1309
+ // ── DEFERRED tool: loaded on-demand for onboarding new repositories ──────
1298
1310
  // 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.', {
1311
+ 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
1312
  repoUrl: z.string().describe('GitHub URL of the repository (e.g., "https://github.com/user/repo")'),
1301
1313
  branch: z.string().optional().default('main').describe('Branch to analyze (default: main)'),
1302
1314
  }, async ({ repoUrl, branch }) => {
@@ -1469,8 +1481,9 @@ export function createServer() {
1469
1481
  };
1470
1482
  }
1471
1483
  });
1484
+ // ── DEFERRED tool: loaded on-demand for change impact assessment ─────────
1472
1485
  // 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.', {
1486
+ 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
1487
  filePath: z.string().describe('The file path you plan to modify (e.g., "src/services/user.ts")'),
1475
1488
  repoUrl: z.string().optional().describe('GitHub URL of the repository (auto-detected from git if omitted)'),
1476
1489
  }, async ({ filePath, repoUrl }) => {
@@ -1499,8 +1512,9 @@ export function createServer() {
1499
1512
  };
1500
1513
  }
1501
1514
  });
1515
+ // ── DEFERRED tool: loaded on-demand for finding existing patterns ─────────
1502
1516
  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.', {
1517
+ 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
1518
  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
1519
  repoUrl: z.string().optional().describe('GitHub URL of the repository (auto-detected from git if omitted)'),
1506
1520
  }, async ({ description, repoUrl }) => {
@@ -1530,8 +1544,9 @@ export function createServer() {
1530
1544
  }
1531
1545
  });
1532
1546
  } // end cloud: merlin_similar_code
1547
+ // ── DEFERRED tool: loaded on-demand for getting real code patterns ────────
1533
1548
  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.', {
1549
+ 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
1550
  task: z.string().optional().describe('Specific task (e.g., "add endpoint", "add test", "error handling"). Leave empty for all examples.'),
1536
1551
  repoUrl: z.string().optional().describe('GitHub URL of the repository (auto-detected from git if omitted)'),
1537
1552
  }, async ({ task, repoUrl }) => {
@@ -1561,8 +1576,9 @@ export function createServer() {
1561
1576
  }
1562
1577
  });
1563
1578
  } // end cloud: merlin_code_examples
1579
+ // ── DEFERRED tool: loaded on-demand for natural language codebase Q&A ──
1564
1580
  // 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?"', {
1581
+ 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
1582
  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
1583
  quick: z.boolean().optional().default(false).describe('If true, returns a faster but shorter answer without detailed sources'),
1568
1584
  repoUrl: z.string().optional().describe('GitHub URL of the repository (auto-detected from git if omitted)'),
@@ -1629,8 +1645,9 @@ export function createServer() {
1629
1645
  // ============================================================
1630
1646
  // AGENT MEMORY - Write Tools
1631
1647
  // ============================================================
1648
+ // ── DEFERRED tool: loaded on-demand for persisting cross-session data ────
1632
1649
  // 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.', {
1650
+ 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
1651
  key: z.string().describe('State key (e.g., "project", "roadmap", "state", "phase_3")'),
1635
1652
  value: z.any().describe('The state data to store (will be JSON serialized)'),
1636
1653
  agentId: z.string().optional().describe('Agent identifier for tracking who wrote the state'),
@@ -1687,8 +1704,9 @@ export function createServer() {
1687
1704
  };
1688
1705
  }
1689
1706
  });
1707
+ // ── DEFERRED tool: loaded on-demand for restoring cross-session data ─────
1690
1708
  // 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.', {
1709
+ 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
1710
  key: z.string().describe('State key to read (e.g., "project", "roadmap", "state")'),
1693
1711
  repoUrl: z.string().optional().describe('GitHub URL of the repository (auto-detected from git if omitted)'),
1694
1712
  }, async ({ key, repoUrl }) => {
@@ -1730,8 +1748,9 @@ export function createServer() {
1730
1748
  };
1731
1749
  }
1732
1750
  });
1751
+ // ── DEFERRED tool: loaded on-demand for auditing stored state ─────────────
1733
1752
  // 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.', {
1753
+ 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
1754
  repoUrl: z.string().optional().describe('GitHub URL of the repository (auto-detected from git if omitted)'),
1736
1755
  }, async ({ repoUrl }) => {
1737
1756
  try {
@@ -1775,8 +1794,9 @@ export function createServer() {
1775
1794
  };
1776
1795
  }
1777
1796
  });
1797
+ // ── DEFERRED tool: loaded on-demand for team activity logging ─────────────
1778
1798
  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.', {
1799
+ 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
1800
  eventType: z.string().describe('Event type (e.g., "phase_started", "task_completed", "blocker_hit", "decision_made")'),
1781
1801
  eventData: z.any().optional().describe('Additional event data (JSON object)'),
1782
1802
  agentId: z.string().describe('Agent identifier for tracking'),
@@ -1824,8 +1844,9 @@ export function createServer() {
1824
1844
  }
1825
1845
  });
1826
1846
  } // end cloud: merlin_log_activity
1847
+ // ── DEFERRED tool: loaded on-demand for syncing task state to cloud ───────
1827
1848
  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.', {
1849
+ 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
1850
  title: z.string().describe('Task title'),
1830
1851
  status: z.enum(['pending', 'in_progress', 'completed', 'blocked', 'skipped']).optional().describe('Task status'),
1831
1852
  description: z.string().optional().describe('Task description'),
@@ -1891,8 +1912,9 @@ export function createServer() {
1891
1912
  }
1892
1913
  });
1893
1914
  } // end cloud: merlin_sync_task
1915
+ // ── DEFERRED tool: loaded on-demand for viewing cloud task state ──────────
1894
1916
  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.', {
1917
+ 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
1918
  status: z.string().optional().describe('Filter by status (pending, in_progress, completed, blocked)'),
1897
1919
  phase: z.string().optional().describe('Filter by phase'),
1898
1920
  plan: z.string().optional().describe('Filter by plan'),
@@ -1954,8 +1976,9 @@ export function createServer() {
1954
1976
  }
1955
1977
  });
1956
1978
  } // end cloud: merlin_get_tasks
1979
+ // ── DEFERRED tool: loaded on-demand for escalating blockers to humans ────
1957
1980
  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.', {
1981
+ 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
1982
  title: z.string().describe('Brief description of the blocker'),
1960
1983
  blockerType: z.enum(['human_verify', 'auth_required', 'clarification', 'decision_point', 'external', 'error', 'other']).describe('Type of blocker'),
1961
1984
  description: z.string().optional().describe('Detailed description'),
@@ -2007,8 +2030,9 @@ export function createServer() {
2007
2030
  }
2008
2031
  });
2009
2032
  } // end cloud: merlin_report_blocker
2033
+ // ── DEFERRED tool: loaded on-demand for checking pending blockers ─────────
2010
2034
  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.', {
2035
+ 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
2036
  status: z.string().optional().default('open').describe('Filter by status (open, resolved, all)'),
2013
2037
  repoUrl: z.string().optional().describe('GitHub URL of the repository (auto-detected from git if omitted)'),
2014
2038
  }, async ({ status, repoUrl }) => {
@@ -2059,8 +2083,9 @@ export function createServer() {
2059
2083
  }
2060
2084
  });
2061
2085
  } // end cloud: merlin_get_blockers
2086
+ // ── DEFERRED tool: loaded on-demand for human-in-the-loop checkpoints ────
2062
2087
  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.', {
2088
+ 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
2089
  title: z.string().describe('Checkpoint title'),
2065
2090
  checkpointType: z.enum(['human_verify', 'auth_gate', 'decision_point', 'approval', 'review']).describe('Type of checkpoint'),
2066
2091
  description: z.string().optional().describe('Detailed description'),
@@ -2118,8 +2143,9 @@ export function createServer() {
2118
2143
  }
2119
2144
  });
2120
2145
  } // end cloud: merlin_create_checkpoint
2146
+ // ── DEFERRED tool: loaded on-demand for team coordination overview ────────
2121
2147
  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.', {
2148
+ 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
2149
  repoUrl: z.string().optional().describe('GitHub URL of the repository (auto-detected from git if omitted)'),
2124
2150
  }, async ({ repoUrl }) => {
2125
2151
  try {
@@ -2213,8 +2239,9 @@ export function createServer() {
2213
2239
  }
2214
2240
  });
2215
2241
  } // end cloud: merlin_get_team_state
2242
+ // ── DEFERRED tool: loaded on-demand for session lifecycle management ──────
2216
2243
  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.', {
2244
+ 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
2245
  sessionId: z.string().describe('Unique session identifier'),
2219
2246
  agentId: z.string().describe('Agent identifier'),
2220
2247
  status: z.enum(['active', 'paused', 'completed', 'abandoned']).optional().describe('Session status'),
@@ -2545,6 +2572,16 @@ export function createServer() {
2545
2572
  });
2546
2573
  } // end free: registerRouteTools
2547
2574
  // ============================================================
2575
+ if (!coreOnly) {
2576
+ // COST TOOLS - Session cost tracking and model routing savings
2577
+ // ============================================================
2578
+ registerCostTools({
2579
+ server,
2580
+ client,
2581
+ resolveRepoId,
2582
+ });
2583
+ } // end free: registerCostTools
2584
+ // ============================================================
2548
2585
  if (hasCloudApi && !coreOnly) {
2549
2586
  // PUBLIC SIGHTS INDEX - Browse open source analyzed codebases
2550
2587
  // ============================================================