atabey 0.0.7 → 0.0.9

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 (181) hide show
  1. package/README.md +1 -1
  2. package/dist/framework-mcp/src/resources/index.js +2 -2
  3. package/dist/framework-mcp/src/resources/index.js.map +1 -1
  4. package/dist/framework-mcp/src/utils/errors.d.ts +46 -0
  5. package/dist/framework-mcp/src/utils/errors.js +69 -0
  6. package/dist/framework-mcp/src/utils/errors.js.map +1 -0
  7. package/dist/framework-mcp/src/utils/memory.d.ts +3 -0
  8. package/dist/framework-mcp/src/utils/memory.js +75 -0
  9. package/dist/framework-mcp/src/utils/memory.js.map +1 -0
  10. package/dist/framework-mcp/src/utils/storage.d.ts +60 -0
  11. package/dist/framework-mcp/src/utils/storage.js +208 -0
  12. package/dist/framework-mcp/src/utils/storage.js.map +1 -0
  13. package/dist/framework-mcp/src/utils/types.d.ts +19 -0
  14. package/dist/framework-mcp/src/utils/types.js +13 -0
  15. package/dist/framework-mcp/src/utils/types.js.map +1 -0
  16. package/dist/src/cli/adapters/core.js +12 -19
  17. package/dist/src/cli/adapters/core.js.map +1 -1
  18. package/dist/src/shared/constants.d.ts +1 -0
  19. package/dist/src/shared/constants.js +1 -0
  20. package/dist/src/shared/constants.js.map +1 -1
  21. package/dist/tests/adapter.test.js +3 -2
  22. package/dist/tests/adapter.test.js.map +1 -1
  23. package/framework-mcp/dist/constants.js +64 -0
  24. package/framework-mcp/dist/framework-mcp/src/constants.js +64 -0
  25. package/framework-mcp/dist/framework-mcp/src/index.js +144 -0
  26. package/framework-mcp/dist/framework-mcp/src/resources/index.js +58 -0
  27. package/framework-mcp/dist/framework-mcp/src/tools/control_plane/locking.js +82 -0
  28. package/framework-mcp/dist/framework-mcp/src/tools/control_plane/registry.js +35 -0
  29. package/framework-mcp/dist/framework-mcp/src/tools/definitions.js +322 -0
  30. package/framework-mcp/dist/framework-mcp/src/tools/file_system/batch_surgical_edit.js +64 -0
  31. package/framework-mcp/dist/framework-mcp/src/tools/file_system/patch_file.js +34 -0
  32. package/framework-mcp/dist/framework-mcp/src/tools/file_system/read_file.js +51 -0
  33. package/framework-mcp/dist/framework-mcp/src/tools/file_system/replace_text.js +50 -0
  34. package/framework-mcp/dist/framework-mcp/src/tools/file_system/write_file.js +43 -0
  35. package/framework-mcp/dist/framework-mcp/src/tools/framework/audit_deps.js +41 -0
  36. package/framework-mcp/dist/framework-mcp/src/tools/framework/get_status.js +5 -0
  37. package/framework-mcp/dist/framework-mcp/src/tools/framework/orchestrate.js +5 -0
  38. package/framework-mcp/dist/framework-mcp/src/tools/framework/run_tests.js +27 -0
  39. package/framework-mcp/dist/framework-mcp/src/tools/framework/submit_plan.js +13 -0
  40. package/framework-mcp/dist/framework-mcp/src/tools/framework/update_contract_hash.js +5 -0
  41. package/framework-mcp/dist/framework-mcp/src/tools/framework/update_memory.js +8 -0
  42. package/framework-mcp/dist/framework-mcp/src/tools/index.js +62 -0
  43. package/framework-mcp/dist/framework-mcp/src/tools/memory/get_insights.js +34 -0
  44. package/framework-mcp/dist/framework-mcp/src/tools/memory/read_memory.js +28 -0
  45. package/framework-mcp/dist/framework-mcp/src/tools/messaging/log_action.js +22 -0
  46. package/framework-mcp/dist/framework-mcp/src/tools/messaging/send_message.js +94 -0
  47. package/framework-mcp/dist/framework-mcp/src/tools/observability/check_ports.js +26 -0
  48. package/framework-mcp/dist/framework-mcp/src/tools/observability/get_health.js +19 -0
  49. package/framework-mcp/dist/framework-mcp/src/tools/quality/check_lint.js +30 -0
  50. package/framework-mcp/dist/framework-mcp/src/tools/search/get_gaps.js +48 -0
  51. package/framework-mcp/dist/framework-mcp/src/tools/search/get_map.js +43 -0
  52. package/framework-mcp/dist/framework-mcp/src/tools/search/grep_search.js +75 -0
  53. package/framework-mcp/dist/framework-mcp/src/tools/search/list_dir.js +28 -0
  54. package/framework-mcp/dist/framework-mcp/src/tools/shell/run_command.js +56 -0
  55. package/framework-mcp/dist/framework-mcp/src/tools/types.js +1 -0
  56. package/framework-mcp/dist/framework-mcp/src/utils/cli.js +59 -0
  57. package/framework-mcp/dist/framework-mcp/src/utils/compliance.js +231 -0
  58. package/framework-mcp/dist/framework-mcp/src/utils/errors.js +68 -0
  59. package/framework-mcp/dist/framework-mcp/src/utils/fs.js +44 -0
  60. package/framework-mcp/dist/framework-mcp/src/utils/memory.js +74 -0
  61. package/framework-mcp/dist/framework-mcp/src/utils/metrics.js +56 -0
  62. package/framework-mcp/dist/framework-mcp/src/utils/permissions.js +71 -0
  63. package/framework-mcp/dist/framework-mcp/src/utils/security.js +60 -0
  64. package/framework-mcp/dist/framework-mcp/src/utils/storage.js +207 -0
  65. package/framework-mcp/dist/framework-mcp/src/utils/types.js +12 -0
  66. package/framework-mcp/dist/index.js +144 -0
  67. package/framework-mcp/dist/resources/index.js +58 -0
  68. package/framework-mcp/dist/src/cli/adapters/core.js +71 -0
  69. package/framework-mcp/dist/src/cli/adapters/index.js +5 -0
  70. package/framework-mcp/dist/src/cli/adapters/paths.js +101 -0
  71. package/framework-mcp/dist/src/cli/adapters/scaffold.js +71 -0
  72. package/framework-mcp/dist/src/cli/adapters/utils.js +75 -0
  73. package/framework-mcp/dist/src/cli/commands/approve.js +63 -0
  74. package/framework-mcp/dist/src/cli/commands/check.js +181 -0
  75. package/framework-mcp/dist/src/cli/commands/compliance.js +50 -0
  76. package/framework-mcp/dist/src/cli/commands/contract.js +50 -0
  77. package/framework-mcp/dist/src/cli/commands/dashboard.js +123 -0
  78. package/framework-mcp/dist/src/cli/commands/explorer.js +42 -0
  79. package/framework-mcp/dist/src/cli/commands/git.js +40 -0
  80. package/framework-mcp/dist/src/cli/commands/init/create-agent.js +58 -0
  81. package/framework-mcp/dist/src/cli/commands/init/scaffold-core.js +112 -0
  82. package/framework-mcp/dist/src/cli/commands/init/scaffold-docs.js +34 -0
  83. package/framework-mcp/dist/src/cli/commands/init/scaffold-ops.js +80 -0
  84. package/framework-mcp/dist/src/cli/commands/init/scaffold-standards.js +67 -0
  85. package/framework-mcp/dist/src/cli/commands/init.js +167 -0
  86. package/framework-mcp/dist/src/cli/commands/knowledge.js +42 -0
  87. package/framework-mcp/dist/src/cli/commands/lint.js +22 -0
  88. package/framework-mcp/dist/src/cli/commands/log.js +10 -0
  89. package/framework-mcp/dist/src/cli/commands/memory.js +4 -0
  90. package/framework-mcp/dist/src/cli/commands/orchestrate.js +159 -0
  91. package/framework-mcp/dist/src/cli/commands/plan.js +117 -0
  92. package/framework-mcp/dist/src/cli/commands/script.js +19 -0
  93. package/framework-mcp/dist/src/cli/commands/security.js +36 -0
  94. package/framework-mcp/dist/src/cli/commands/status.js +97 -0
  95. package/framework-mcp/dist/src/cli/commands/trace.js +109 -0
  96. package/framework-mcp/dist/src/cli/index.js +338 -0
  97. package/framework-mcp/dist/src/cli/shims.js +66 -0
  98. package/framework-mcp/dist/src/cli/utils/claude.js +56 -0
  99. package/framework-mcp/dist/src/cli/utils/compliance.js +173 -0
  100. package/framework-mcp/dist/src/cli/utils/config-schema.js +42 -0
  101. package/framework-mcp/dist/src/cli/utils/fs.js +137 -0
  102. package/framework-mcp/dist/src/cli/utils/i18n.js +30 -0
  103. package/framework-mcp/dist/src/cli/utils/memory.js +276 -0
  104. package/framework-mcp/dist/src/cli/utils/pkg.js +282 -0
  105. package/framework-mcp/dist/src/cli/utils/schemas.js +19 -0
  106. package/framework-mcp/dist/src/cli/utils/string.js +49 -0
  107. package/framework-mcp/dist/src/cli/utils/time.js +27 -0
  108. package/framework-mcp/dist/src/cli/utils/ui.js +58 -0
  109. package/framework-mcp/dist/src/contracts/index.js +1 -0
  110. package/framework-mcp/dist/src/contracts/tasks.js +20 -0
  111. package/framework-mcp/dist/src/dashboard/vite.config.js +15 -0
  112. package/framework-mcp/dist/src/modules/adapters/definitions.js +140 -0
  113. package/framework-mcp/dist/src/modules/adapters/registry.js +18 -0
  114. package/framework-mcp/dist/src/modules/adapters/shared.js +104 -0
  115. package/framework-mcp/dist/src/modules/adapters/types.js +1 -0
  116. package/framework-mcp/dist/src/modules/agents/definitions.js +457 -0
  117. package/framework-mcp/dist/src/modules/agents/registry/analyst.js +39 -0
  118. package/framework-mcp/dist/src/modules/agents/registry/architect.js +42 -0
  119. package/framework-mcp/dist/src/modules/agents/registry/backend.js +49 -0
  120. package/framework-mcp/dist/src/modules/agents/registry/database.js +45 -0
  121. package/framework-mcp/dist/src/modules/agents/registry/devops.js +45 -0
  122. package/framework-mcp/dist/src/modules/agents/registry/explorer.js +36 -0
  123. package/framework-mcp/dist/src/modules/agents/registry/frontend.js +51 -0
  124. package/framework-mcp/dist/src/modules/agents/registry/git.js +36 -0
  125. package/framework-mcp/dist/src/modules/agents/registry/manager.js +53 -0
  126. package/framework-mcp/dist/src/modules/agents/registry/mobile.js +39 -0
  127. package/framework-mcp/dist/src/modules/agents/registry/native.js +39 -0
  128. package/framework-mcp/dist/src/modules/agents/registry/quality.js +41 -0
  129. package/framework-mcp/dist/src/modules/agents/registry/security.js +43 -0
  130. package/framework-mcp/dist/src/modules/agents/types.js +1 -0
  131. package/framework-mcp/dist/src/modules/engines/evaluation-engine.js +102 -0
  132. package/framework-mcp/dist/src/modules/engines/health-engine.js +49 -0
  133. package/framework-mcp/dist/src/modules/engines/planning-engine.js +78 -0
  134. package/framework-mcp/dist/src/modules/engines/risk-engine.js +105 -0
  135. package/framework-mcp/dist/src/modules/engines/routing-engine.js +73 -0
  136. package/framework-mcp/dist/src/modules/engines/types.js +1 -0
  137. package/framework-mcp/dist/src/modules/skills/definitions.js +70 -0
  138. package/framework-mcp/dist/src/shared/constants.js +187 -0
  139. package/framework-mcp/dist/src/shared/errors.js +68 -0
  140. package/framework-mcp/dist/src/shared/fs.js +51 -0
  141. package/framework-mcp/dist/src/shared/logger.js +116 -0
  142. package/framework-mcp/dist/src/shared/storage.js +207 -0
  143. package/framework-mcp/dist/src/shared/types.js +12 -0
  144. package/framework-mcp/dist/tools/control_plane/locking.js +82 -0
  145. package/framework-mcp/dist/tools/control_plane/registry.js +35 -0
  146. package/framework-mcp/dist/tools/definitions.js +322 -0
  147. package/framework-mcp/dist/tools/file_system/batch_surgical_edit.js +64 -0
  148. package/framework-mcp/dist/tools/file_system/patch_file.js +34 -0
  149. package/framework-mcp/dist/tools/file_system/read_file.js +51 -0
  150. package/framework-mcp/dist/tools/file_system/replace_text.js +50 -0
  151. package/framework-mcp/dist/tools/file_system/write_file.js +43 -0
  152. package/framework-mcp/dist/tools/framework/audit_deps.js +41 -0
  153. package/framework-mcp/dist/tools/framework/get_status.js +5 -0
  154. package/framework-mcp/dist/tools/framework/orchestrate.js +5 -0
  155. package/framework-mcp/dist/tools/framework/run_tests.js +27 -0
  156. package/framework-mcp/dist/tools/framework/submit_plan.js +13 -0
  157. package/framework-mcp/dist/tools/framework/update_contract_hash.js +5 -0
  158. package/framework-mcp/dist/tools/framework/update_memory.js +8 -0
  159. package/framework-mcp/dist/tools/index.js +62 -0
  160. package/framework-mcp/dist/tools/memory/get_insights.js +34 -0
  161. package/framework-mcp/dist/tools/memory/read_memory.js +28 -0
  162. package/framework-mcp/dist/tools/messaging/log_action.js +22 -0
  163. package/framework-mcp/dist/tools/messaging/send_message.js +94 -0
  164. package/framework-mcp/dist/tools/observability/check_ports.js +26 -0
  165. package/framework-mcp/dist/tools/observability/get_health.js +19 -0
  166. package/framework-mcp/dist/tools/quality/check_lint.js +30 -0
  167. package/framework-mcp/dist/tools/search/get_gaps.js +48 -0
  168. package/framework-mcp/dist/tools/search/get_map.js +43 -0
  169. package/framework-mcp/dist/tools/search/grep_search.js +75 -0
  170. package/framework-mcp/dist/tools/search/list_dir.js +28 -0
  171. package/framework-mcp/dist/tools/shell/run_command.js +56 -0
  172. package/framework-mcp/dist/tools/types.js +1 -0
  173. package/framework-mcp/dist/utils/cli.js +59 -0
  174. package/framework-mcp/dist/utils/compliance.js +231 -0
  175. package/framework-mcp/dist/utils/fs.js +44 -0
  176. package/framework-mcp/dist/utils/metrics.js +56 -0
  177. package/framework-mcp/dist/utils/permissions.js +71 -0
  178. package/framework-mcp/dist/utils/security.js +60 -0
  179. package/framework-mcp/package.json +37 -0
  180. package/mcp.json +1 -1
  181. package/package.json +10 -5
@@ -0,0 +1,13 @@
1
+ import { safeExec } from "../../utils/cli.js";
2
+ export function handleSubmitPlan(projectRoot, args) {
3
+ if (!args.tasks || !Array.isArray(args.tasks)) {
4
+ return {
5
+ isError: true,
6
+ content: [{ type: "text", text: "[ERROR] Error: 'tasks' array is required for submit_plan." }]
7
+ };
8
+ }
9
+ const planJson = JSON.stringify(args.tasks);
10
+ // Escape for shell if necessary, but safeExec handles arguments as an array
11
+ const output = safeExec("npx", ["atabey", "plan:submit", planJson], projectRoot);
12
+ return { content: [{ type: "text", text: output }] };
13
+ }
@@ -0,0 +1,5 @@
1
+ import { safeExec } from "../../utils/cli.js";
2
+ export function handleUpdateContractHash(projectRoot, args) {
3
+ const output = safeExec("npx", ["atabey", "update-contract"], projectRoot, args.timeout);
4
+ return { content: [{ type: "text", text: output }] };
5
+ }
@@ -0,0 +1,8 @@
1
+ import { safeExec } from "../../utils/cli.js";
2
+ export function handleUpdateProjectMemory(projectRoot, args) {
3
+ const section = args.section;
4
+ const content = args.content;
5
+ // Using execFileSync with array args prevents command injection
6
+ safeExec("npx", ["atabey", "update_project_memory", section, content], projectRoot);
7
+ return { content: [{ type: "text", text: `[OK] Section ${section} updated.` }] };
8
+ }
@@ -0,0 +1,62 @@
1
+ import { TOOLS } from "./definitions.js";
2
+ import { handleReadFile } from "./file_system/read_file.js";
3
+ import { handleWriteFile } from "./file_system/write_file.js";
4
+ import { handleReplaceText } from "./file_system/replace_text.js";
5
+ import { handleBatchSurgicalEdit } from "./file_system/batch_surgical_edit.js";
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";
11
+ import { handleGetFrameworkStatus } from "./framework/get_status.js";
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 { handleOrchestrateLoop } from "./framework/orchestrate.js";
18
+ import { handleSubmitPlan } from "./framework/submit_plan.js";
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";
22
+ import { handleSendAgentMessage } from "./messaging/send_message.js";
23
+ import { handleLogAgentAction } from "./messaging/log_action.js";
24
+ import { handleAcquireLock, handleReleaseLock } from "./control_plane/locking.js";
25
+ import { handleRegisterAgent } from "./control_plane/registry.js";
26
+ import { handleRunCommand } from "./shell/run_command.js";
27
+ import { handleCheckLint } from "./quality/check_lint.js";
28
+ // Map of tool names to their handler functions
29
+ const bind = (fn) => {
30
+ return (root, args) => fn(root, args);
31
+ };
32
+ export const toolHandlers = {
33
+ read_file: bind(handleReadFile),
34
+ view_file: bind(handleReadFile), // Alias
35
+ list_dir: bind(handleListDir),
36
+ grep_search: bind(handleGrepSearch),
37
+ get_project_map: bind(handleGetProjectMap),
38
+ get_project_gaps: bind(handleGetProjectGaps),
39
+ write_file: bind(handleWriteFile),
40
+ replace_text: bind(handleReplaceText),
41
+ batch_surgical_edit: bind(handleBatchSurgicalEdit),
42
+ patch_file: bind(handlePatchFile),
43
+ get_framework_status: bind(handleGetFrameworkStatus),
44
+ read_project_memory: bind(handleReadProjectMemory),
45
+ get_memory_insights: bind(handleGetMemoryInsights),
46
+ update_project_memory: bind(handleUpdateProjectMemory),
47
+ audit_dependencies: bind(handleAuditDependencies),
48
+ run_tests: bind(handleRunTests),
49
+ get_system_health: bind(handleGetSystemHealth),
50
+ check_active_ports: bind(handleCheckPorts),
51
+ orchestrate_loop: bind(handleOrchestrateLoop),
52
+ submit_plan: bind(handleSubmitPlan),
53
+ send_agent_message: bind(handleSendAgentMessage),
54
+ log_agent_action: bind(handleLogAgentAction),
55
+ update_contract_hash: bind(handleUpdateContractHash),
56
+ acquire_lock: bind(handleAcquireLock),
57
+ release_lock: bind(handleReleaseLock),
58
+ register_agent: bind(handleRegisterAgent),
59
+ run_shell_command: bind(handleRunCommand),
60
+ check_lint: bind(handleCheckLint),
61
+ };
62
+ export { TOOLS };
@@ -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("**Phase:**"))?.split("**Phase:**")[1]?.trim() || "Unknown";
18
+ const activeTrace = lines.find(l => l.includes("**Trace ID:**"))?.split("**Trace ID:**")[1]?.trim() || "None";
19
+ // Find the last 5 history items (heuristic)
20
+ const historyStartIndex = lines.findIndex(l => l.toUpperCase().includes("HISTORY"));
21
+ let recentHistory = "No history found.";
22
+ if (historyStartIndex !== -1) {
23
+ recentHistory = lines.slice(historyStartIndex + 1)
24
+ .filter(l => l.trim().startsWith("-"))
25
+ .slice(-5)
26
+ .join("\n");
27
+ }
28
+ const insights = `[MEMORY] **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
+ }
@@ -0,0 +1,22 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { resolveFrameworkDir } from "../../utils/security.js";
4
+ export function handleLogAgentAction(projectRoot, args) {
5
+ const { agent, action, traceId, status, summary } = args;
6
+ const findings = args.findings ? args.findings.split(",").map(f => f.trim()) : [];
7
+ const frameworkDir = resolveFrameworkDir(projectRoot);
8
+ const agentName = agent.replace("@", "");
9
+ const logPath = path.join(projectRoot, frameworkDir, "logs", `${agentName}.json`);
10
+ const logEntry = {
11
+ timestamp: new Date().toISOString(),
12
+ agent,
13
+ action,
14
+ requestId: traceId,
15
+ status,
16
+ summary,
17
+ findings
18
+ };
19
+ fs.mkdirSync(path.dirname(logPath), { recursive: true });
20
+ fs.appendFileSync(logPath, JSON.stringify(logEntry) + "\n");
21
+ return { content: [{ type: "text", text: `[OK] Action logged for ${agent} to ${path.join(frameworkDir, "logs", `${agentName}.json`)}` }] };
22
+ }
@@ -0,0 +1,94 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { resolveFrameworkDir } from "../../utils/security.js";
4
+ import { Metrics } from "../../utils/metrics.js";
5
+ export async function handleSendAgentMessage(projectRoot, args) {
6
+ const { to, category, content, traceId, parentId, requiresApproval } = args;
7
+ const from = args.from || "@mcp";
8
+ if (!to || !category || !content || !traceId) {
9
+ const err = "Missing required messaging arguments (to, category, content, or traceId).";
10
+ Metrics.logError(projectRoot, from, "send_agent_message", err);
11
+ return { isError: true, content: [{ type: "text", text: `[ERROR] ${err}` }] };
12
+ }
13
+ const frameworkDir = resolveFrameworkDir(projectRoot);
14
+ const messagesDir = path.join(projectRoot, frameworkDir, "messages");
15
+ const agentName = to.replace("@", "");
16
+ const messagePath = path.join(messagesDir, `${agentName}.json`);
17
+ const lockPath = path.join(messagesDir, `${agentName}.lock`);
18
+ // Hermes Lock Protocol: Retry 20 times with 500ms delay
19
+ let retries = 20;
20
+ let acquired = false;
21
+ while (retries > 0) {
22
+ try {
23
+ if (fs.existsSync(lockPath)) {
24
+ try {
25
+ const stats = fs.statSync(lockPath);
26
+ if (Date.now() - stats.mtimeMs > 10000) {
27
+ const tempLockPath = `${lockPath}.${Math.random().toString(36).substring(2)}.old`;
28
+ fs.renameSync(lockPath, tempLockPath);
29
+ fs.unlinkSync(tempLockPath);
30
+ }
31
+ }
32
+ catch {
33
+ // ignore if concurrently unlinked or renamed
34
+ }
35
+ }
36
+ fs.mkdirSync(messagesDir, { recursive: true });
37
+ fs.writeFileSync(lockPath, `Locked by ${from} at ${new Date().toISOString()}`, { flag: "wx" });
38
+ acquired = true;
39
+ break;
40
+ }
41
+ catch (err) {
42
+ const error = err;
43
+ if (error.code === "EEXIST") {
44
+ retries--;
45
+ if (retries > 0) {
46
+ await new Promise((resolve) => setTimeout(resolve, 500));
47
+ }
48
+ }
49
+ else {
50
+ return { content: [{ type: "text", text: `[ERROR] Unexpected lock acquisition error: ${error.message || String(err)}` }], isError: true };
51
+ }
52
+ }
53
+ }
54
+ if (!acquired) {
55
+ const err = `Could not send message to ${to}: Hermes lock is busy.`;
56
+ Metrics.logError(projectRoot, from, "send_agent_message", err);
57
+ return { content: [{ type: "text", text: `[ERROR] ${err}` }], isError: true };
58
+ }
59
+ try {
60
+ const defaultPriority = (category === "ALERT" || category === "ACTION") ? "HIGH" : "NORMAL";
61
+ const finalRequiresApproval = requiresApproval !== undefined
62
+ ? requiresApproval
63
+ : category === "ALERT";
64
+ const message = {
65
+ timestamp: new Date().toISOString(),
66
+ from,
67
+ to,
68
+ category,
69
+ traceId,
70
+ parentId,
71
+ content,
72
+ priority: args.priority || defaultPriority,
73
+ status: "PENDING",
74
+ requiresApproval: finalRequiresApproval
75
+ };
76
+ fs.appendFileSync(messagePath, JSON.stringify(message) + "\n");
77
+ return { content: [{ type: "text", text: `[OK] Message sent to ${to} (from: ${from})` }] };
78
+ }
79
+ catch (e) {
80
+ const err = `Failed to write message: ${String(e)}`;
81
+ Metrics.logError(projectRoot, from, "send_agent_message", err);
82
+ return { isError: true, content: [{ type: "text", text: `[ERROR] ${err}` }] };
83
+ }
84
+ finally {
85
+ if (acquired && fs.existsSync(lockPath)) {
86
+ try {
87
+ fs.unlinkSync(lockPath);
88
+ }
89
+ catch {
90
+ // ignore
91
+ }
92
+ }
93
+ }
94
+ }
@@ -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: `[SIGNAL] **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,30 @@
1
+ import { exec } from "child_process";
2
+ import { Metrics } from "../../utils/metrics.js";
3
+ import { getBackendLanguage, getDefaultLintCommand } from "../../utils/cli.js";
4
+ const TIMEOUT = 60000; // 60 seconds
5
+ /**
6
+ * Handles running the project's linter.
7
+ */
8
+ export function handleCheckLint(projectRoot, _args) {
9
+ const language = getBackendLanguage(projectRoot);
10
+ const lintCommand = getDefaultLintCommand(language);
11
+ return new Promise((resolve) => {
12
+ exec(lintCommand, { cwd: projectRoot, timeout: TIMEOUT }, (error, stdout, stderr) => {
13
+ const output = stdout + stderr;
14
+ const tokens = Metrics.estimateTokens(output);
15
+ if (error) {
16
+ const err = `Linting failed for ${language} with command: ${lintCommand}. ${error.message}`;
17
+ Metrics.logError(projectRoot, "@mcp", "check_lint", err);
18
+ resolve({
19
+ isError: true,
20
+ content: [{ type: "text", text: `[ERROR] Lint Errors Found (${language}):\n\n${output}` }]
21
+ });
22
+ return;
23
+ }
24
+ Metrics.logUsage(projectRoot, "@mcp", "check_lint", tokens);
25
+ resolve({
26
+ content: [{ type: "text", text: `[OK] Lint check passed successfully for ${language}:\n\n${output}` }]
27
+ });
28
+ });
29
+ });
30
+ }
@@ -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
+ : "[OK] 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 = 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,75 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { Metrics } from "../../utils/metrics.js";
4
+ /**
5
+ * Searches for a regex pattern within files in the project.
6
+ */
7
+ export function handleGrepSearch(projectRoot, args) {
8
+ const pattern = args.pattern;
9
+ const includePattern = args.includePattern || ""; // e.g., ".ts"
10
+ const excludePattern = args.excludePattern || "node_modules";
11
+ if (!pattern) {
12
+ const err = "Search pattern is required.";
13
+ Metrics.logError(projectRoot, "@mcp", "grep_search", err);
14
+ return { isError: true, content: [{ type: "text", text: `[ERROR] ${err}` }] };
15
+ }
16
+ const results = [];
17
+ try {
18
+ new RegExp(pattern);
19
+ }
20
+ catch (e) {
21
+ const err = `Invalid regex pattern: ${String(e)}`;
22
+ Metrics.logError(projectRoot, "@mcp", "grep_search", err);
23
+ return { isError: true, content: [{ type: "text", text: `[ERROR] ${err}` }] };
24
+ }
25
+ const walk = (dir) => {
26
+ if (results.length > 100)
27
+ return;
28
+ try {
29
+ const files = fs.readdirSync(dir);
30
+ for (const file of files) {
31
+ if (results.length > 100)
32
+ return;
33
+ const filePath = path.join(dir, file);
34
+ if (excludePattern && filePath.includes(excludePattern)) {
35
+ continue;
36
+ }
37
+ const stat = fs.statSync(filePath);
38
+ if (stat.isDirectory()) {
39
+ walk(filePath);
40
+ }
41
+ else if (stat.isFile()) {
42
+ if (includePattern && !filePath.endsWith(includePattern)) {
43
+ continue;
44
+ }
45
+ const content = fs.readFileSync(filePath, "utf8");
46
+ // Create a new regex object for each line to avoid state issues with /g
47
+ if (new RegExp(pattern).test(content)) {
48
+ if (results.length < 100) {
49
+ results.push(filePath);
50
+ }
51
+ }
52
+ }
53
+ }
54
+ }
55
+ catch {
56
+ // Ignore directories that cannot be read
57
+ }
58
+ };
59
+ try {
60
+ walk(projectRoot);
61
+ }
62
+ catch (e) {
63
+ const err = `Search failed: ${String(e)}`;
64
+ Metrics.logError(projectRoot, "@mcp", "grep_search", err);
65
+ return { isError: true, content: [{ type: "text", text: `[ERROR] ${err}` }] };
66
+ }
67
+ return {
68
+ content: [{
69
+ type: "text",
70
+ text: results.length > 0
71
+ ? `Found ${results.length} matches:\n\n${results.join("\n")}`
72
+ : "No matches found."
73
+ }]
74
+ };
75
+ }
@@ -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
+ }
@@ -0,0 +1,56 @@
1
+ import { exec } from "child_process";
2
+ import { Metrics } from "../../utils/metrics.js";
3
+ const COMMAND_ALLOW_LIST = [
4
+ "npm test",
5
+ "npm run lint",
6
+ "npm run build",
7
+ "git status",
8
+ "git diff",
9
+ "npx vitest run",
10
+ "go test",
11
+ "go fmt",
12
+ "go build",
13
+ "pytest",
14
+ "ruff check",
15
+ "dotnet test",
16
+ "dotnet format",
17
+ "dotnet build",
18
+ "./gradlew",
19
+ "mvn",
20
+ ];
21
+ const TIMEOUT = 30000; // 30 seconds
22
+ export function handleRunCommand(projectRoot, args) {
23
+ const command = args.command;
24
+ const isAllowed = COMMAND_ALLOW_LIST.some(allowedCmd => command.startsWith(allowedCmd));
25
+ if (!isAllowed) {
26
+ const errorMsg = `Command not allowed: "${command}". Only commands starting with the following are allowed: ${COMMAND_ALLOW_LIST.join(", ")}`;
27
+ Metrics.logError(projectRoot, "@mcp", `run_shell_command: ${command} (denied)`, errorMsg);
28
+ return Promise.resolve({
29
+ content: [{ type: "text", text: `ERROR: ${errorMsg}` }],
30
+ isError: true,
31
+ });
32
+ }
33
+ return new Promise((resolve) => {
34
+ exec(command, { cwd: projectRoot, timeout: TIMEOUT }, (error, stdout, stderr) => {
35
+ const output = stdout + stderr;
36
+ const tokens = Metrics.estimateTokens(output);
37
+ Metrics.logUsage(projectRoot, "@mcp", `run_shell_command: ${command}`, tokens);
38
+ if (error) {
39
+ const errorMsg = `Command failed with exit code ${error.code}: ${error.message}.`;
40
+ Metrics.logError(projectRoot, "@mcp", `run_shell_command: ${command}`, errorMsg);
41
+ resolve({
42
+ content: [{ type: "text", text: `ERROR: ${errorMsg}. Output: ${output}` }],
43
+ isError: true,
44
+ });
45
+ return;
46
+ }
47
+ // Truncate long outputs
48
+ const MAX_OUTPUT_LENGTH = 5000;
49
+ let truncatedOutput = output;
50
+ if (output.length > MAX_OUTPUT_LENGTH) {
51
+ truncatedOutput = output.substring(0, MAX_OUTPUT_LENGTH) + "... [TRUNCATED] ..."; // Simplified
52
+ }
53
+ resolve({ content: [{ type: "text", text: truncatedOutput }] });
54
+ });
55
+ });
56
+ }
@@ -0,0 +1 @@
1
+ export {};