agent-enderun 1.1.6 β†’ 1.1.8

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 (254) hide show
  1. package/ENDERUN.md +12 -9
  2. package/README.md +12 -29
  3. package/bin/run-multi-test.js +77 -0
  4. package/dist/framework-mcp/src/tools/dashboard/start_dashboard.d.ts +5 -0
  5. package/dist/framework-mcp/src/tools/dashboard/start_dashboard.js +30 -0
  6. package/dist/framework-mcp/src/tools/dashboard/start_dashboard.js.map +1 -0
  7. package/dist/framework-mcp/src/tools/definitions.js +118 -0
  8. package/dist/framework-mcp/src/tools/definitions.js.map +1 -1
  9. package/dist/framework-mcp/src/tools/file_system/batch_surgical_edit.d.ts +5 -0
  10. package/dist/framework-mcp/src/tools/file_system/batch_surgical_edit.js +51 -0
  11. package/dist/framework-mcp/src/tools/file_system/batch_surgical_edit.js.map +1 -0
  12. package/dist/framework-mcp/src/tools/file_system/replace_text.js +8 -4
  13. package/dist/framework-mcp/src/tools/file_system/replace_text.js.map +1 -1
  14. package/dist/framework-mcp/src/tools/file_system/write_file.js +3 -0
  15. package/dist/framework-mcp/src/tools/file_system/write_file.js.map +1 -1
  16. package/dist/framework-mcp/src/tools/framework/audit_deps.d.ts +6 -0
  17. package/dist/framework-mcp/src/tools/framework/audit_deps.js +42 -0
  18. package/dist/framework-mcp/src/tools/framework/audit_deps.js.map +1 -0
  19. package/dist/framework-mcp/src/tools/framework/run_tests.d.ts +5 -0
  20. package/dist/framework-mcp/src/tools/framework/run_tests.js +26 -0
  21. package/dist/framework-mcp/src/tools/framework/run_tests.js.map +1 -0
  22. package/dist/framework-mcp/src/tools/index.js +24 -0
  23. package/dist/framework-mcp/src/tools/index.js.map +1 -1
  24. package/dist/framework-mcp/src/tools/memory/get_insights.d.ts +6 -0
  25. package/dist/framework-mcp/src/tools/memory/get_insights.js +35 -0
  26. package/dist/framework-mcp/src/tools/memory/get_insights.js.map +1 -0
  27. package/dist/framework-mcp/src/tools/memory/read_memory.d.ts +6 -0
  28. package/dist/framework-mcp/src/tools/memory/read_memory.js +29 -0
  29. package/dist/framework-mcp/src/tools/memory/read_memory.js.map +1 -0
  30. package/dist/framework-mcp/src/tools/messaging/send_message.js +1 -1
  31. package/dist/framework-mcp/src/tools/messaging/send_message.js.map +1 -1
  32. package/dist/framework-mcp/src/tools/observability/check_ports.d.ts +5 -0
  33. package/dist/framework-mcp/src/tools/observability/check_ports.js +27 -0
  34. package/dist/framework-mcp/src/tools/observability/check_ports.js.map +1 -0
  35. package/dist/framework-mcp/src/tools/observability/get_health.d.ts +5 -0
  36. package/dist/framework-mcp/src/tools/observability/get_health.js +20 -0
  37. package/dist/framework-mcp/src/tools/observability/get_health.js.map +1 -0
  38. package/dist/framework-mcp/src/tools/search/get_gaps.d.ts +6 -0
  39. package/dist/framework-mcp/src/tools/search/get_gaps.js +49 -0
  40. package/dist/framework-mcp/src/tools/search/get_gaps.js.map +1 -0
  41. package/dist/framework-mcp/src/tools/search/get_map.d.ts +6 -0
  42. package/dist/framework-mcp/src/tools/search/get_map.js +44 -0
  43. package/dist/framework-mcp/src/tools/search/get_map.js.map +1 -0
  44. package/dist/framework-mcp/src/tools/search/grep_search.d.ts +5 -0
  45. package/dist/framework-mcp/src/tools/search/grep_search.js +60 -0
  46. package/dist/framework-mcp/src/tools/search/grep_search.js.map +1 -0
  47. package/dist/framework-mcp/src/tools/search/list_dir.d.ts +5 -0
  48. package/dist/framework-mcp/src/tools/search/list_dir.js +29 -0
  49. package/dist/framework-mcp/src/tools/search/list_dir.js.map +1 -0
  50. package/dist/framework-mcp/src/tools/types.d.ts +10 -5
  51. package/dist/framework-mcp/src/utils/compliance.d.ts +5 -0
  52. package/dist/framework-mcp/src/utils/compliance.js +30 -0
  53. package/dist/framework-mcp/src/utils/compliance.js.map +1 -0
  54. package/dist/framework-mcp/tests/tools/messaging/send_message.test.js +5 -5
  55. package/dist/framework-mcp/tests/tools/messaging/send_message.test.js.map +1 -1
  56. package/dist/src/cli/adapters/types.d.ts +2 -2
  57. package/dist/src/cli/adapters.d.ts +3 -3
  58. package/dist/src/cli/adapters.js +53 -79
  59. package/dist/src/cli/adapters.js.map +1 -1
  60. package/dist/src/cli/commands/check.js +52 -6
  61. package/dist/src/cli/commands/check.js.map +1 -1
  62. package/dist/src/cli/commands/init.d.ts +5 -1
  63. package/dist/src/cli/commands/init.js +186 -172
  64. package/dist/src/cli/commands/init.js.map +1 -1
  65. package/dist/src/cli/commands/orchestrate.d.ts +3 -3
  66. package/dist/src/cli/commands/orchestrate.js +14 -8
  67. package/dist/src/cli/commands/orchestrate.js.map +1 -1
  68. package/dist/src/cli/commands/status.js +3 -2
  69. package/dist/src/cli/commands/status.js.map +1 -1
  70. package/dist/src/cli/index.js +4 -3
  71. package/dist/src/cli/index.js.map +1 -1
  72. package/dist/src/cli/shims.js +6 -6
  73. package/dist/src/cli/utils/app-backend.d.ts +2 -0
  74. package/dist/src/cli/utils/app-backend.js +236 -0
  75. package/dist/src/cli/utils/app-backend.js.map +1 -0
  76. package/dist/src/cli/utils/app-docs.d.ts +3 -0
  77. package/dist/src/cli/utils/app-docs.js +59 -0
  78. package/dist/src/cli/utils/app-docs.js.map +1 -0
  79. package/dist/src/cli/utils/app-frontend.d.ts +2 -0
  80. package/dist/src/cli/utils/app-frontend.js +248 -0
  81. package/dist/src/cli/utils/app-frontend.js.map +1 -0
  82. package/dist/src/cli/utils/app-inferrer.d.ts +14 -0
  83. package/dist/src/cli/utils/app-inferrer.js +39 -0
  84. package/dist/src/cli/utils/app-inferrer.js.map +1 -0
  85. package/dist/src/cli/utils/app-types.d.ts +3 -0
  86. package/dist/src/cli/utils/app-types.js +233 -0
  87. package/dist/src/cli/utils/app-types.js.map +1 -0
  88. package/dist/src/cli/utils/app.d.ts +5 -32
  89. package/dist/src/cli/utils/app.js +5 -794
  90. package/dist/src/cli/utils/app.js.map +1 -1
  91. package/dist/src/cli/utils/memory.js +8 -4
  92. package/dist/src/cli/utils/memory.js.map +1 -1
  93. package/dist/src/modules/adapters/antigravity-cli.js +3 -3
  94. package/dist/src/modules/adapters/antigravity-cli.js.map +1 -1
  95. package/dist/src/modules/adapters/claude.js +1 -1
  96. package/dist/src/modules/adapters/claude.js.map +1 -1
  97. package/dist/src/modules/adapters/codex.js +2 -2
  98. package/dist/src/modules/adapters/codex.js.map +1 -1
  99. package/dist/src/modules/adapters/cursor.js +1 -1
  100. package/dist/src/modules/adapters/cursor.js.map +1 -1
  101. package/dist/src/modules/adapters/definitions.d.ts +9 -0
  102. package/dist/src/modules/adapters/definitions.js +124 -0
  103. package/dist/src/modules/adapters/definitions.js.map +1 -0
  104. package/dist/src/modules/adapters/gemini.js +2 -2
  105. package/dist/src/modules/adapters/gemini.js.map +1 -1
  106. package/dist/src/modules/adapters/grok.js +1 -1
  107. package/dist/src/modules/adapters/grok.js.map +1 -1
  108. package/dist/src/modules/agents/definitions.js +26 -27
  109. package/dist/src/modules/agents/definitions.js.map +1 -1
  110. package/dist/src/shared/config.d.ts +3 -3
  111. package/dist/src/shared/logger.js +8 -5
  112. package/dist/src/shared/logger.js.map +1 -1
  113. package/dist/tests/adapter.test.d.ts +1 -0
  114. package/dist/tests/adapter.test.js +128 -0
  115. package/dist/tests/adapter.test.js.map +1 -0
  116. package/dist/tests/agents-definitions.test.d.ts +1 -0
  117. package/dist/tests/agents-definitions.test.js +54 -0
  118. package/dist/tests/agents-definitions.test.js.map +1 -0
  119. package/dist/tests/approve.test.d.ts +1 -0
  120. package/dist/tests/approve.test.js +88 -0
  121. package/dist/tests/approve.test.js.map +1 -0
  122. package/dist/tests/config.test.d.ts +1 -0
  123. package/dist/tests/config.test.js +58 -0
  124. package/dist/tests/config.test.js.map +1 -0
  125. package/dist/tests/container.runner.d.ts +1 -0
  126. package/dist/tests/container.runner.js +68 -0
  127. package/dist/tests/container.runner.js.map +1 -0
  128. package/dist/tests/container.test.d.ts +1 -0
  129. package/dist/tests/container.test.js +73 -0
  130. package/dist/tests/container.test.js.map +1 -0
  131. package/dist/tests/errors.test.d.ts +1 -0
  132. package/dist/tests/errors.test.js +64 -0
  133. package/dist/tests/errors.test.js.map +1 -0
  134. package/dist/tests/fs-utils.test.d.ts +1 -0
  135. package/dist/tests/fs-utils.test.js +101 -0
  136. package/dist/tests/fs-utils.test.js.map +1 -0
  137. package/dist/tests/logger.test.d.ts +1 -0
  138. package/dist/tests/logger.test.js +81 -0
  139. package/dist/tests/logger.test.js.map +1 -0
  140. package/dist/tests/memory-utils.test.d.ts +1 -0
  141. package/dist/tests/memory-utils.test.js +173 -0
  142. package/dist/tests/memory-utils.test.js.map +1 -0
  143. package/dist/tests/orchestrate.test.d.ts +1 -0
  144. package/dist/tests/orchestrate.test.js +131 -0
  145. package/dist/tests/orchestrate.test.js.map +1 -0
  146. package/dist/tests/skills-definitions.test.d.ts +1 -0
  147. package/dist/tests/skills-definitions.test.js +34 -0
  148. package/dist/tests/skills-definitions.test.js.map +1 -0
  149. package/dist/tests/status.test.d.ts +1 -0
  150. package/dist/tests/status.test.js +105 -0
  151. package/dist/tests/status.test.js.map +1 -0
  152. package/dist/tests/string.test.d.ts +1 -0
  153. package/dist/tests/string.test.js +89 -0
  154. package/dist/tests/string.test.js.map +1 -0
  155. package/dist/tests/time.test.d.ts +1 -0
  156. package/dist/tests/time.test.js +48 -0
  157. package/dist/tests/time.test.js.map +1 -0
  158. package/dist/tests/trace.test.d.ts +1 -0
  159. package/dist/tests/trace.test.js +61 -0
  160. package/dist/tests/trace.test.js.map +1 -0
  161. package/dist/vitest.config.js +1 -0
  162. package/dist/vitest.config.js.map +1 -1
  163. package/docs/getting-started.md +4 -0
  164. package/docs/user/corporate-governance.md +25 -0
  165. package/eslint.config.js +25 -3
  166. package/framework-mcp/dist/tools/dashboard/start_dashboard.js +29 -0
  167. package/framework-mcp/dist/tools/definitions.js +118 -0
  168. package/framework-mcp/dist/tools/file_system/batch_surgical_edit.js +50 -0
  169. package/framework-mcp/dist/tools/file_system/replace_text.js +8 -4
  170. package/framework-mcp/dist/tools/file_system/write_file.js +3 -0
  171. package/framework-mcp/dist/tools/framework/audit_deps.js +41 -0
  172. package/framework-mcp/dist/tools/framework/run_tests.js +25 -0
  173. package/framework-mcp/dist/tools/index.js +24 -0
  174. package/framework-mcp/dist/tools/memory/get_insights.js +34 -0
  175. package/framework-mcp/dist/tools/memory/read_memory.js +28 -0
  176. package/framework-mcp/dist/tools/messaging/send_message.js +1 -1
  177. package/framework-mcp/dist/tools/observability/check_ports.js +26 -0
  178. package/framework-mcp/dist/tools/observability/get_health.js +19 -0
  179. package/framework-mcp/dist/tools/search/get_gaps.js +48 -0
  180. package/framework-mcp/dist/tools/search/get_map.js +43 -0
  181. package/framework-mcp/dist/tools/search/grep_search.js +59 -0
  182. package/framework-mcp/dist/tools/search/list_dir.js +28 -0
  183. package/framework-mcp/dist/utils/compliance.js +29 -0
  184. package/framework-mcp/package.json +2 -2
  185. package/framework-mcp/src/tools/dashboard/start_dashboard.ts +33 -0
  186. package/framework-mcp/src/tools/definitions.ts +118 -0
  187. package/framework-mcp/src/tools/file_system/batch_surgical_edit.ts +70 -0
  188. package/framework-mcp/src/tools/file_system/replace_text.ts +10 -4
  189. package/framework-mcp/src/tools/file_system/write_file.ts +5 -0
  190. package/framework-mcp/src/tools/framework/audit_deps.ts +49 -0
  191. package/framework-mcp/src/tools/framework/run_tests.ts +28 -0
  192. package/framework-mcp/src/tools/index.ts +24 -0
  193. package/framework-mcp/src/tools/memory/get_insights.ts +41 -0
  194. package/framework-mcp/src/tools/memory/read_memory.ts +31 -0
  195. package/framework-mcp/src/tools/messaging/send_message.ts +1 -1
  196. package/framework-mcp/src/tools/observability/check_ports.ts +30 -0
  197. package/framework-mcp/src/tools/observability/get_health.ts +24 -0
  198. package/framework-mcp/src/tools/search/get_gaps.ts +54 -0
  199. package/framework-mcp/src/tools/search/get_map.ts +48 -0
  200. package/framework-mcp/src/tools/search/grep_search.ts +65 -0
  201. package/framework-mcp/src/tools/search/list_dir.ts +34 -0
  202. package/framework-mcp/src/tools/types.ts +11 -1
  203. package/framework-mcp/src/utils/compliance.ts +37 -0
  204. package/framework-mcp/tests/tools/messaging/send_message.test.ts +5 -5
  205. package/package.json +3 -3
  206. package/src/cli/adapters/types.ts +2 -2
  207. package/src/cli/adapters.ts +57 -86
  208. package/src/cli/commands/check.ts +52 -6
  209. package/src/cli/commands/init.ts +202 -193
  210. package/src/cli/commands/orchestrate.ts +14 -8
  211. package/src/cli/commands/status.ts +3 -2
  212. package/src/cli/index.ts +4 -3
  213. package/src/cli/shims.ts +6 -6
  214. package/src/cli/utils/app-backend.ts +249 -0
  215. package/src/cli/utils/app-docs.ts +65 -0
  216. package/src/cli/utils/app-frontend.ts +257 -0
  217. package/src/cli/utils/app-inferrer.ts +53 -0
  218. package/src/cli/utils/app-types.ts +243 -0
  219. package/src/cli/utils/app.ts +5 -849
  220. package/src/cli/utils/memory.ts +8 -4
  221. package/src/modules/adapters/definitions.ts +125 -0
  222. package/src/modules/agents/definitions.ts +26 -27
  223. package/src/shared/logger.ts +8 -5
  224. package/templates/prompts/bug-fix-recipe.md +20 -0
  225. package/templates/prompts/new-feature-recipe.md +19 -0
  226. package/templates/prompts/refactoring-recipe.md +21 -0
  227. package/templates/standards/architecture-standards.md +23 -0
  228. package/templates/standards/crud-governance.md +21 -0
  229. package/templates/standards/frontend-standards.md +38 -0
  230. package/templates/standards/i18n-standards.md +17 -0
  231. package/templates/standards/logging-and-secrets.md +29 -0
  232. package/templates/standards/mobile-standards.md +24 -0
  233. package/templates/standards/quality-standards.md +31 -0
  234. package/templates/standards/security-standards.md +21 -0
  235. package/templates/standards/tailwind-standards.md +20 -0
  236. package/templates/standards/testing-standards.md +31 -0
  237. package/src/modules/adapters/antigravity-cli.ts +0 -25
  238. package/src/modules/adapters/claude.ts +0 -36
  239. package/src/modules/adapters/codex.ts +0 -22
  240. package/src/modules/adapters/cursor.ts +0 -22
  241. package/src/modules/adapters/gemini.ts +0 -27
  242. package/src/modules/adapters/grok.ts +0 -20
  243. package/templates/architecture/agents-manifest.md +0 -79
  244. package/templates/architecture/approval-flows.md +0 -61
  245. package/templates/architecture/enterprise-architecture.md +0 -69
  246. package/templates/architecture/standards/crud-governance.md +0 -46
  247. package/templates/architecture/standards/data-fetching-patterns.md +0 -13
  248. package/templates/architecture/standards/design-system.md +0 -31
  249. package/templates/architecture/standards/documentation-ownership.md +0 -21
  250. package/templates/architecture/standards/logging.md +0 -7
  251. package/templates/architecture/standards/mobile-standards.md +0 -48
  252. package/templates/architecture/standards/tech-stack.md +0 -9
  253. package/templates/backend/error-handling.md +0 -74
  254. package/templates/frontend/component-patterns.md +0 -91
@@ -12,6 +12,29 @@ export const TOOLS = [
12
12
  required: ["path"],
13
13
  },
14
14
  },
15
+ {
16
+ name: "list_dir",
17
+ description: "List the contents of a directory. Essential for codebase exploration.",
18
+ inputSchema: {
19
+ type: "object",
20
+ properties: {
21
+ path: { type: "string", description: "Path to the directory relative to project root (default: '.')" },
22
+ },
23
+ },
24
+ },
25
+ {
26
+ name: "grep_search",
27
+ description: "Perform a recursive regex search across the codebase to find functions, variables, or patterns.",
28
+ inputSchema: {
29
+ type: "object",
30
+ properties: {
31
+ pattern: { type: "string", description: "The regex pattern to search for" },
32
+ includePattern: { type: "string", description: "Optional: Filter files by extension (e.g., '.ts')" },
33
+ excludePattern: { type: "string", description: "Optional: Directory pattern to exclude (default: 'node_modules')" },
34
+ },
35
+ required: ["pattern"],
36
+ },
37
+ },
15
38
  {
16
39
  name: "write_file",
17
40
  description: "Write content to a file. Creates directories if missing.",
@@ -33,10 +56,34 @@ export const TOOLS = [
33
56
  path: { type: "string", description: "Path to the file" },
34
57
  oldText: { type: "string", description: "The exact text to find" },
35
58
  newText: { type: "string", description: "The text to replace it with" },
59
+ allowMultiple: { type: "boolean", description: "Allow multiple replacements if oldText is not unique." }
36
60
  },
37
61
  required: ["path", "oldText", "newText"],
38
62
  },
39
63
  },
64
+ {
65
+ name: "batch_surgical_edit",
66
+ description: "Perform multiple surgical text replacements across multiple files in a single batch request. More efficient for cross-cutting changes.",
67
+ inputSchema: {
68
+ type: "object",
69
+ properties: {
70
+ edits: {
71
+ type: "array",
72
+ items: {
73
+ type: "object",
74
+ properties: {
75
+ path: { type: "string", description: "Path to the file" },
76
+ oldText: { type: "string", description: "The exact text to find" },
77
+ newText: { type: "string", description: "The text to replace it with" },
78
+ allowMultiple: { type: "boolean", description: "Allow multiple replacements in this file." }
79
+ },
80
+ required: ["path", "oldText", "newText"]
81
+ }
82
+ }
83
+ },
84
+ required: ["edits"],
85
+ },
86
+ },
40
87
  {
41
88
  name: "patch_file",
42
89
  description: "Safely update a file by replacing a specific line range with new content.",
@@ -51,11 +98,82 @@ export const TOOLS = [
51
98
  required: ["path", "startLine", "endLine", "newContent"],
52
99
  },
53
100
  },
101
+ {
102
+ name: "get_project_map",
103
+ description: "Generate a tree-view map of the project structure to visualize the layout. Useful for onboarding and architectural analysis.",
104
+ inputSchema: {
105
+ type: "object",
106
+ properties: {
107
+ maxDepth: { type: "number", description: "Maximum directory depth to scan (default: 3)" },
108
+ includeFiles: { type: "boolean", description: "Whether to include files in the map (default: true)" }
109
+ }
110
+ }
111
+ },
112
+ {
113
+ name: "get_project_gaps",
114
+ description: "Scans the codebase for TODOs, FIXMEs, and empty function bodies. Helps identify what is left and where the agent might have skipped logic.",
115
+ inputSchema: {
116
+ type: "object",
117
+ properties: {
118
+ path: { type: "string", description: "Path to the source directory (default: 'src')" },
119
+ },
120
+ },
121
+ },
122
+ {
123
+ name: "audit_dependencies",
124
+ description: "Audits package.json for unused, redundant, or duplicate-like packages to ensure a clean dependency tree.",
125
+ inputSchema: { type: "object", properties: {} },
126
+ },
127
+ {
128
+ name: "run_tests",
129
+ description: "Execute project test suites (Vitest, Playwright, etc.) and capture detailed pass/fail reports for analysis.",
130
+ inputSchema: {
131
+ type: "object",
132
+ properties: {
133
+ command: { type: "string", description: "The test command to run (default: 'npm test')" }
134
+ }
135
+ }
136
+ },
137
+ {
138
+ name: "get_system_health",
139
+ description: "Retrieve real-time system metrics like CPU load, RAM usage, and uptime.",
140
+ inputSchema: { type: "object", properties: {} }
141
+ },
142
+ {
143
+ name: "check_active_ports",
144
+ description: "Identify which network ports are currently active and listening. Helps verify if the dev server or API is running.",
145
+ inputSchema: {
146
+ type: "object",
147
+ properties: {
148
+ filter: { type: "string", description: "Optional: Filter results by port number or service name (e.g., ':3000')" }
149
+ }
150
+ }
151
+ },
152
+ {
153
+ name: "start_dashboard",
154
+ description: "Start the Enderun Web Dashboard (Command Center) to visualize real-time agent status, logs, and system metrics in the browser.",
155
+ inputSchema: {
156
+ type: "object",
157
+ properties: {
158
+ port: { type: "number", description: "Optional: Port to run the dashboard on (default: 5858)" }
159
+ }
160
+ }
161
+ },
54
162
  {
55
163
  name: "get_framework_status",
56
164
  description: "Get the current project phase, active traces, and agent states.",
57
165
  inputSchema: { type: "object", properties: {} },
58
166
  },
167
+ {
168
+ name: "read_project_memory",
169
+ description: "Read the full project central memory (PROJECT_MEMORY.md). Use this at the start of a session to gain context.",
170
+ inputSchema: { type: "object", properties: {} },
171
+ },
172
+ {
173
+ name: "get_memory_insights",
174
+ description: "Retrieve a summarized version of the project memory (active phase, trace, and last 5 actions) to save tokens.",
175
+ inputSchema: { type: "object", properties: {} },
176
+ },
59
177
  {
60
178
  name: "update_project_memory",
61
179
  description: "Update a specific section in PROJECT_MEMORY.md.",
@@ -0,0 +1,50 @@
1
+ import fs from "fs";
2
+ import { safePath } from "../../utils/security.js";
3
+ import { Metrics } from "../../utils/metrics.js";
4
+ import { verifyCorporateCompliance } from "../../utils/compliance.js";
5
+ /**
6
+ * Performs multiple surgical text replacements across multiple files in a single batch.
7
+ */
8
+ export function handleBatchSurgicalEdit(projectRoot, args) {
9
+ const edits = args.edits;
10
+ if (!Array.isArray(edits) || edits.length === 0) {
11
+ throw new Error("No edits provided in the batch request.");
12
+ }
13
+ const results = [];
14
+ let totalTokens = 0;
15
+ for (const edit of edits) {
16
+ const filePath = safePath(projectRoot, edit.path);
17
+ if (!fs.existsSync(filePath)) {
18
+ throw new Error(`File not found: ${edit.path}`);
19
+ }
20
+ const content = fs.readFileSync(filePath, "utf8");
21
+ const { oldText, newText, allowMultiple = false } = edit;
22
+ if (!content.includes(oldText)) {
23
+ throw new Error(`Text not found in file ${edit.path}: "${oldText.slice(0, 50)}..."`);
24
+ }
25
+ // Surgical precision guard
26
+ if (!allowMultiple) {
27
+ const firstIndex = content.indexOf(oldText);
28
+ const lastIndex = content.lastIndexOf(oldText);
29
+ if (firstIndex !== lastIndex) {
30
+ throw new Error(`Ambiguous replacement in ${edit.path}: "${oldText.slice(0, 50)}..." found multiple times.`);
31
+ }
32
+ }
33
+ const newContent = allowMultiple
34
+ ? content.replace(new RegExp(oldText.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "g"), newText)
35
+ : content.replace(oldText, newText);
36
+ // ENFORCE CORPORATE COMPLIANCE
37
+ verifyCorporateCompliance(newContent, edit.path);
38
+ fs.writeFileSync(filePath, newContent);
39
+ const tokens = Metrics.estimateTokens(newText);
40
+ totalTokens += tokens;
41
+ results.push(`βœ… Edited ${edit.path}`);
42
+ }
43
+ Metrics.logUsage(projectRoot, "@mcp", `batch_surgical_edit: ${edits.length} files`, totalTokens);
44
+ return {
45
+ content: [{
46
+ type: "text",
47
+ text: `Successfully performed ${edits.length} edits:\n${results.join("\n")}`
48
+ }]
49
+ };
50
+ }
@@ -1,9 +1,10 @@
1
1
  import fs from "fs";
2
2
  import { safePath } from "../../utils/security.js";
3
3
  import { Metrics } from "../../utils/metrics.js";
4
+ import { verifyCorporateCompliance } from "../../utils/compliance.js";
4
5
  export function handleReplaceText(projectRoot, args) {
5
6
  const filePath = safePath(projectRoot, args.path);
6
- let content = fs.readFileSync(filePath, "utf8");
7
+ const content = fs.readFileSync(filePath, "utf8");
7
8
  const oldText = args.oldText;
8
9
  const newText = args.newText;
9
10
  const allowMultiple = args.allowMultiple || false; // Default to false
@@ -21,13 +22,16 @@ export function handleReplaceText(projectRoot, args) {
21
22
  }
22
23
  }
23
24
  // Perform replacement(s)
25
+ let newContent;
24
26
  if (allowMultiple) {
25
- content = content.replace(new RegExp(oldText.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "g"), newText);
27
+ newContent = content.replace(new RegExp(oldText.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "g"), newText);
26
28
  }
27
29
  else {
28
- content = content.replace(oldText, newText);
30
+ newContent = content.replace(oldText, newText);
29
31
  }
30
- fs.writeFileSync(filePath, content);
32
+ // ENFORCE CORPORATE COMPLIANCE
33
+ verifyCorporateCompliance(newContent, args.path);
34
+ fs.writeFileSync(filePath, newContent);
31
35
  const tokens = Metrics.estimateTokens(newText);
32
36
  Metrics.logUsage(projectRoot, "@mcp", `replace_text: ${args.path}`, tokens);
33
37
  return { content: [{ type: "text", text: `βœ… Surgical edit successful in ${args.path}` }] };
@@ -2,9 +2,12 @@ import fs from "fs";
2
2
  import path from "path";
3
3
  import { safePath, resolveFrameworkDir } from "../../utils/security.js";
4
4
  import { Metrics } from "../../utils/metrics.js";
5
+ import { verifyCorporateCompliance } from "../../utils/compliance.js";
5
6
  export function handleWriteFile(projectRoot, args) {
6
7
  const filePath = safePath(projectRoot, args.path);
7
8
  const content = args.content;
9
+ // ENFORCE CORPORATE COMPLIANCE
10
+ verifyCorporateCompliance(content, args.path);
8
11
  fs.mkdirSync(path.dirname(filePath), { recursive: true });
9
12
  fs.writeFileSync(filePath, content);
10
13
  // AUTO-LOGGING & METRICS
@@ -0,0 +1,41 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ /**
4
+ * Audits package.json for unused or duplicate-like packages.
5
+ * Focuses on project health and cleanup.
6
+ */
7
+ export function handleAuditDependencies(projectRoot, _args) {
8
+ const pkgPath = path.join(projectRoot, "package.json");
9
+ if (!fs.existsSync(pkgPath)) {
10
+ throw new Error("package.json not found.");
11
+ }
12
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
13
+ const deps = { ...pkg.dependencies, ...pkg.devDependencies };
14
+ const depNames = Object.keys(deps);
15
+ const results = [];
16
+ // 1. Look for similar packages (potential duplicates)
17
+ const similarityGroups = {
18
+ "CSS/Styling": ["tailwind", "panda", "styled-components", "emotion", "sass"],
19
+ "Testing": ["vitest", "jest", "mocha", "jasmine"],
20
+ "Fetching": ["axios", "ky", "fetch"]
21
+ };
22
+ for (const [group, patterns] of Object.entries(similarityGroups)) {
23
+ const found = depNames.filter(d => patterns.some(p => d.includes(p)));
24
+ if (found.length > 1) {
25
+ results.push(`⚠️ Potential redundancy in [${group}]: Found ${found.join(", ")}`);
26
+ }
27
+ }
28
+ // 2. Scan for "any" usage in package names (bad practice markers)
29
+ const legacyDeps = depNames.filter(d => d.includes("legacy") || d.includes("compat"));
30
+ if (legacyDeps.length > 0) {
31
+ results.push(`ℹ️ Legacy compatibility packages detected: ${legacyDeps.join(", ")}`);
32
+ }
33
+ return {
34
+ content: [{
35
+ type: "text",
36
+ text: results.length > 0
37
+ ? `Dependency Audit Results:\n\n${results.join("\n")}`
38
+ : "βœ… Dependencies look clean and consolidated."
39
+ }]
40
+ };
41
+ }
@@ -0,0 +1,25 @@
1
+ import { execSync } from "child_process";
2
+ /**
3
+ * Executes project tests and returns results for agent analysis.
4
+ */
5
+ export function handleRunTests(projectRoot, args) {
6
+ const testCommand = args.command || "npm test";
7
+ try {
8
+ const output = execSync(testCommand, { cwd: projectRoot, encoding: "utf8", stdio: "pipe" });
9
+ return {
10
+ content: [{ type: "text", text: `βœ… Tests passed successfully!\n\n${output}` }]
11
+ };
12
+ }
13
+ catch (error) {
14
+ const err = error;
15
+ const stderr = err.stderr?.toString() || "";
16
+ const stdout = err.stdout?.toString() || "";
17
+ return {
18
+ isError: true,
19
+ content: [{
20
+ type: "text",
21
+ text: `❌ Tests FAILED!\n\n--- STDOUT ---\n${stdout}\n\n--- STDERR ---\n${stderr}`
22
+ }]
23
+ };
24
+ }
25
+ }
@@ -2,11 +2,23 @@ import { TOOLS } from "./definitions.js";
2
2
  import { handleReadFile } from "./file_system/read_file.js";
3
3
  import { handleWriteFile } from "./file_system/write_file.js";
4
4
  import { handleReplaceText } from "./file_system/replace_text.js";
5
+ import { handleBatchSurgicalEdit } from "./file_system/batch_surgical_edit.js";
5
6
  import { handlePatchFile } from "./file_system/patch_file.js";
7
+ import { handleGrepSearch } from "./search/grep_search.js";
8
+ import { handleListDir } from "./search/list_dir.js";
9
+ import { handleGetProjectGaps } from "./search/get_gaps.js";
10
+ import { handleGetProjectMap } from "./search/get_map.js";
6
11
  import { handleGetFrameworkStatus } from "./framework/get_status.js";
7
12
  import { handleUpdateProjectMemory } from "./framework/update_memory.js";
13
+ import { handleAuditDependencies } from "./framework/audit_deps.js";
14
+ import { handleRunTests } from "./framework/run_tests.js";
15
+ import { handleGetSystemHealth } from "./observability/get_health.js";
16
+ import { handleCheckPorts } from "./observability/check_ports.js";
17
+ import { handleStartDashboard } from "./dashboard/start_dashboard.js";
8
18
  import { handleOrchestrateLoop } from "./framework/orchestrate.js";
9
19
  import { handleUpdateContractHash } from "./framework/update_contract_hash.js";
20
+ import { handleReadProjectMemory } from "./memory/read_memory.js";
21
+ import { handleGetMemoryInsights } from "./memory/get_insights.js";
10
22
  import { handleSendAgentMessage } from "./messaging/send_message.js";
11
23
  import { handleLogAgentAction } from "./messaging/log_action.js";
12
24
  import { handleAcquireLock, handleReleaseLock } from "./control_plane/locking.js";
@@ -14,11 +26,23 @@ import { handleRegisterAgent } from "./control_plane/registry.js";
14
26
  // Map of tool names to their handler functions
15
27
  export const toolHandlers = {
16
28
  read_file: handleReadFile,
29
+ list_dir: handleListDir,
30
+ grep_search: handleGrepSearch,
31
+ get_project_map: handleGetProjectMap,
32
+ get_project_gaps: handleGetProjectGaps,
17
33
  write_file: handleWriteFile,
18
34
  replace_text: handleReplaceText,
35
+ batch_surgical_edit: handleBatchSurgicalEdit,
19
36
  patch_file: handlePatchFile,
20
37
  get_framework_status: handleGetFrameworkStatus,
38
+ read_project_memory: handleReadProjectMemory,
39
+ get_memory_insights: handleGetMemoryInsights,
21
40
  update_project_memory: handleUpdateProjectMemory,
41
+ audit_dependencies: handleAuditDependencies,
42
+ run_tests: handleRunTests,
43
+ get_system_health: handleGetSystemHealth,
44
+ check_active_ports: handleCheckPorts,
45
+ start_dashboard: handleStartDashboard,
22
46
  orchestrate_loop: handleOrchestrateLoop,
23
47
  send_agent_message: handleSendAgentMessage,
24
48
  log_agent_action: handleLogAgentAction,
@@ -0,0 +1,34 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { resolveFrameworkDir } from "../../utils/security.js";
4
+ /**
5
+ * Extracts key insights from the project memory to minimize token usage.
6
+ * Returns only the active phase, trace, and the last 5 decisions/tasks.
7
+ */
8
+ export function handleGetMemoryInsights(projectRoot, _args) {
9
+ try {
10
+ const frameworkDir = resolveFrameworkDir(projectRoot);
11
+ const memoryPath = path.join(projectRoot, frameworkDir, "memory/PROJECT_MEMORY.md");
12
+ if (!fs.existsSync(memoryPath)) {
13
+ return { content: [{ type: "text", text: "New project: No history available." }] };
14
+ }
15
+ const content = fs.readFileSync(memoryPath, "utf8");
16
+ const lines = content.split("\n");
17
+ const activePhase = lines.find(l => l.includes("Active Phase:"))?.split(":")[1]?.trim() || "Unknown";
18
+ const activeTrace = lines.find(l => l.includes("Active Trace:"))?.split(":")[1]?.trim() || "None";
19
+ // Find the last 5 history items (heuristic)
20
+ const historyStartIndex = lines.findIndex(l => l.includes("## History"));
21
+ let recentHistory = "No history found.";
22
+ if (historyStartIndex !== -1) {
23
+ recentHistory = lines.slice(historyStartIndex + 1, historyStartIndex + 15)
24
+ .filter(l => l.trim().startsWith("-"))
25
+ .slice(-5)
26
+ .join("\n");
27
+ }
28
+ const insights = `🧠 **Memory Insights**\n- **Phase:** ${activePhase}\n- **Trace:** ${activeTrace}\n\n**Recent Actions:**\n${recentHistory}`;
29
+ return { content: [{ type: "text", text: insights }] };
30
+ }
31
+ catch (e) {
32
+ return { isError: true, content: [{ type: "text", text: `Failed to extract insights: ${String(e)}` }] };
33
+ }
34
+ }
@@ -0,0 +1,28 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { resolveFrameworkDir } from "../../utils/security.js";
4
+ /**
5
+ * Reads the project's central memory (PROJECT_MEMORY.md).
6
+ * This is the "brain" of the project.
7
+ */
8
+ export function handleReadProjectMemory(projectRoot, _args) {
9
+ try {
10
+ const frameworkDir = resolveFrameworkDir(projectRoot);
11
+ const memoryPath = path.join(projectRoot, frameworkDir, "memory/PROJECT_MEMORY.md");
12
+ if (!fs.existsSync(memoryPath)) {
13
+ return {
14
+ content: [{ type: "text", text: "ℹ️ Project memory file not found. It might be a new project." }]
15
+ };
16
+ }
17
+ const content = fs.readFileSync(memoryPath, "utf8");
18
+ return {
19
+ content: [{ type: "text", text: content }]
20
+ };
21
+ }
22
+ catch (e) {
23
+ return {
24
+ isError: true,
25
+ content: [{ type: "text", text: `Failed to read project memory: ${String(e)}` }]
26
+ };
27
+ }
28
+ }
@@ -8,7 +8,7 @@ export async function handleSendAgentMessage(projectRoot, args) {
8
8
  const messagesDir = path.join(projectRoot, frameworkDir, "messages");
9
9
  const agentName = to.replace("@", "");
10
10
  const messagePath = path.join(messagesDir, `${agentName}.json`);
11
- const lockPath = path.join(messagesDir, ".lock");
11
+ const lockPath = path.join(messagesDir, `${agentName}.lock`);
12
12
  // Hermes Lock Protocol: Retry 3 times with 500ms delay
13
13
  let retries = 3;
14
14
  let acquired = false;
@@ -0,0 +1,26 @@
1
+ import { execSync } from "child_process";
2
+ /**
3
+ * Checks for active network ports and their status.
4
+ */
5
+ export function handleCheckPorts(projectRoot, args) {
6
+ const filter = args.filter || ""; // Optional filter (e.g., ":3000")
7
+ try {
8
+ // Using 'lsof -i -P -n' to list open files and network connections
9
+ // Note: may require permissions or behave differently on non-Unix systems
10
+ const command = process.platform === "win32"
11
+ ? `netstat -ano | findstr LISTENING ${filter ? `| findstr ${filter}` : ""}`
12
+ : `lsof -i -P -n | grep LISTEN ${filter ? `| grep ${filter}` : ""}`;
13
+ const output = execSync(command, { encoding: "utf8" });
14
+ return {
15
+ content: [{
16
+ type: "text",
17
+ text: `πŸ“‘ **Active Listening Ports:**\n\n${output || "No active listening ports found matching filter."}`
18
+ }]
19
+ };
20
+ }
21
+ catch (_e) {
22
+ return {
23
+ content: [{ type: "text", text: "ℹ️ No active ports found or command failed (this is normal if nothing is listening)." }]
24
+ };
25
+ }
26
+ }
@@ -0,0 +1,19 @@
1
+ import os from "os";
2
+ /**
3
+ * Retrieves system health metrics including CPU load and memory usage.
4
+ */
5
+ export function handleGetSystemHealth(_projectRoot, _args) {
6
+ const totalMem = os.totalmem();
7
+ const freeMem = os.freemem();
8
+ const usedMem = totalMem - freeMem;
9
+ const memUsagePercent = ((usedMem / totalMem) * 100).toFixed(2);
10
+ const loadAvg = os.loadavg(); // [1, 5, 15] minute averages
11
+ const healthReport = `πŸ–₯️ **System Health Report**
12
+ - **Memory:** ${memUsagePercent}% used (${(usedMem / 1024 / 1024 / 1024).toFixed(2)} GB / ${(totalMem / 1024 / 1024 / 1024).toFixed(2)} GB)
13
+ - **CPU Load (1m, 5m, 15m):** ${loadAvg.map(l => l.toFixed(2)).join(", ")}
14
+ - **Platform:** ${os.platform()} (${os.release()})
15
+ - **Uptime:** ${(os.uptime() / 3600).toFixed(2)} hours`;
16
+ return {
17
+ content: [{ type: "text", text: healthReport }]
18
+ };
19
+ }
@@ -0,0 +1,48 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { safePath } from "../../utils/security.js";
4
+ /**
5
+ * Scans the codebase for TODOs, FIXMEs, and empty function bodies.
6
+ * Helps identify what's left and where the agent might have skipped logic.
7
+ */
8
+ export function handleGetProjectGaps(projectRoot, args) {
9
+ const srcDir = safePath(projectRoot, args.path || "src");
10
+ const results = [];
11
+ const walk = (dir) => {
12
+ if (!fs.existsSync(dir))
13
+ return;
14
+ const files = fs.readdirSync(dir);
15
+ for (const file of files) {
16
+ const fullPath = path.join(dir, file);
17
+ const relativePath = path.relative(projectRoot, fullPath);
18
+ if (fs.statSync(fullPath).isDirectory()) {
19
+ if (file !== "node_modules" && file !== "dist" && !file.startsWith(".")) {
20
+ walk(fullPath);
21
+ }
22
+ }
23
+ else if (file.endsWith(".ts") || file.endsWith(".tsx")) {
24
+ const content = fs.readFileSync(fullPath, "utf8");
25
+ const lines = content.split("\n");
26
+ lines.forEach((line, index) => {
27
+ // 1. Scan for markers
28
+ if (line.includes("TODO") || line.includes("FIXME") || line.includes("!!!")) {
29
+ results.push(`[${relativePath}:${index + 1}] Marker found: ${line.trim()}`);
30
+ }
31
+ // 2. Scan for empty function placeholders (heuristic)
32
+ if (line.includes("throw new Error(\"Not implemented") || line.includes("// ... rest of code")) {
33
+ results.push(`[${relativePath}:${index + 1}] Gap found: ${line.trim()}`);
34
+ }
35
+ });
36
+ }
37
+ }
38
+ };
39
+ walk(srcDir);
40
+ return {
41
+ content: [{
42
+ type: "text",
43
+ text: results.length > 0
44
+ ? `Found ${results.length} gaps/todos:\n\n${results.join("\n")}`
45
+ : "βœ… No major gaps or TODOs found in the scanned directory."
46
+ }]
47
+ };
48
+ }
@@ -0,0 +1,43 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ /**
4
+ * Generates a tree-view map of the project structure.
5
+ * Helps agents visualize the entire project layout quickly.
6
+ */
7
+ export function handleGetProjectMap(projectRoot, args) {
8
+ const maxDepth = Number(args.maxDepth) || 3;
9
+ const includeFiles = args.includeFiles !== false;
10
+ const buildTree = (dir, depth) => {
11
+ if (depth > maxDepth)
12
+ return [];
13
+ const results = [];
14
+ const files = fs.readdirSync(dir);
15
+ files.forEach(file => {
16
+ if (file === "node_modules" || file === ".git" || file === "dist" || file.startsWith("."))
17
+ return;
18
+ const fullPath = path.join(dir, file);
19
+ const stat = fs.statSync(fullPath);
20
+ const indent = " ".repeat(depth);
21
+ if (stat.isDirectory()) {
22
+ results.push(`${indent}πŸ“ ${file}/`);
23
+ results.push(...buildTree(fullPath, depth + 1));
24
+ }
25
+ else if (includeFiles) {
26
+ results.push(`${indent}πŸ“„ ${file}`);
27
+ }
28
+ });
29
+ return results;
30
+ };
31
+ try {
32
+ const tree = buildTree(projectRoot, 0);
33
+ return {
34
+ content: [{
35
+ type: "text",
36
+ text: `πŸ—ΊοΈ **Project Map (Depth: ${maxDepth})**\n\n${tree.join("\n")}`
37
+ }]
38
+ };
39
+ }
40
+ catch (e) {
41
+ return { isError: true, content: [{ type: "text", text: `Failed to map project: ${String(e)}` }] };
42
+ }
43
+ }
@@ -0,0 +1,59 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ /**
4
+ * Searches for a regex pattern within files in the project.
5
+ */
6
+ export function handleGrepSearch(projectRoot, args) {
7
+ const pattern = args.pattern;
8
+ const includePattern = args.includePattern || ""; // e.g., ".ts"
9
+ const excludePattern = args.excludePattern || "node_modules";
10
+ if (!pattern) {
11
+ throw new Error("Search pattern is required.");
12
+ }
13
+ const results = [];
14
+ const regex = new RegExp(pattern, "g");
15
+ const walk = (dir) => {
16
+ const files = fs.readdirSync(dir);
17
+ for (const file of files) {
18
+ const fullPath = path.join(dir, file);
19
+ const relativePath = path.relative(projectRoot, fullPath);
20
+ // Skip excluded directories/files
21
+ if (relativePath.includes(excludePattern))
22
+ continue;
23
+ try {
24
+ const stat = fs.statSync(fullPath);
25
+ if (stat.isDirectory()) {
26
+ walk(fullPath);
27
+ }
28
+ else if (stat.isFile()) {
29
+ // Check include pattern
30
+ if (includePattern && !file.endsWith(includePattern))
31
+ continue;
32
+ const content = fs.readFileSync(fullPath, "utf8");
33
+ const lines = content.split("\n");
34
+ lines.forEach((line, index) => {
35
+ if (regex.test(line)) {
36
+ results.push(`${relativePath}:${index + 1}: ${line.trim()}`);
37
+ // Reset regex lastIndex because of 'g' flag
38
+ regex.lastIndex = 0;
39
+ }
40
+ });
41
+ }
42
+ }
43
+ catch {
44
+ // Ignore read errors
45
+ }
46
+ if (results.length > 100)
47
+ break; // Limit results
48
+ }
49
+ };
50
+ walk(projectRoot);
51
+ return {
52
+ content: [{
53
+ type: "text",
54
+ text: results.length > 0
55
+ ? `Found ${results.length} matches:\n\n${results.join("\n")}`
56
+ : "No matches found."
57
+ }]
58
+ };
59
+ }
@@ -0,0 +1,28 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { safePath } from "../../utils/security.js";
4
+ /**
5
+ * Lists the contents of a directory.
6
+ */
7
+ export function handleListDir(projectRoot, args) {
8
+ const dirPath = safePath(projectRoot, args.path || ".");
9
+ if (!fs.existsSync(dirPath)) {
10
+ throw new Error(`Directory not found: ${args.path}`);
11
+ }
12
+ const stats = fs.statSync(dirPath);
13
+ if (!stats.isDirectory()) {
14
+ throw new Error(`Path is not a directory: ${args.path}`);
15
+ }
16
+ const files = fs.readdirSync(dirPath);
17
+ const results = files.map(file => {
18
+ const fullPath = path.join(dirPath, file);
19
+ const isDir = fs.statSync(fullPath).isDirectory();
20
+ return `${isDir ? "[DIR] " : " "}${file}`;
21
+ });
22
+ return {
23
+ content: [{
24
+ type: "text",
25
+ text: `Directory listing for ${args.path || "."}:\n\n${results.join("\n")}`
26
+ }]
27
+ };
28
+ }