myaiforone 1.0.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 (315) hide show
  1. package/README.md +113 -0
  2. package/agents/_template/CLAUDE.md +18 -0
  3. package/agents/_template/agent.json +7 -0
  4. package/agents/platform/agentcreator/CLAUDE.md +300 -0
  5. package/agents/platform/appcreator/CLAUDE.md +158 -0
  6. package/agents/platform/gym/CLAUDE.md +486 -0
  7. package/agents/platform/gym/agent.json +40 -0
  8. package/agents/platform/gym/programs/agent-building/program.json +160 -0
  9. package/agents/platform/gym/programs/automations-mastery/program.json +129 -0
  10. package/agents/platform/gym/programs/getting-started/program.json +124 -0
  11. package/agents/platform/gym/programs/mcp-integrations/program.json +116 -0
  12. package/agents/platform/gym/programs/multi-model-strategy/program.json +115 -0
  13. package/agents/platform/gym/programs/prompt-engineering/program.json +136 -0
  14. package/agents/platform/gym/souls/alex.md +12 -0
  15. package/agents/platform/gym/souls/jordan.md +12 -0
  16. package/agents/platform/gym/souls/morgan.md +12 -0
  17. package/agents/platform/gym/souls/riley.md +12 -0
  18. package/agents/platform/gym/souls/sam.md +12 -0
  19. package/agents/platform/hub/CLAUDE.md +372 -0
  20. package/agents/platform/promptcreator/CLAUDE.md +130 -0
  21. package/agents/platform/skillcreator/CLAUDE.md +163 -0
  22. package/bin/cli.js +566 -0
  23. package/config.example.json +310 -0
  24. package/dist/agent-registry.d.ts +32 -0
  25. package/dist/agent-registry.d.ts.map +1 -0
  26. package/dist/agent-registry.js +144 -0
  27. package/dist/agent-registry.js.map +1 -0
  28. package/dist/channels/discord.d.ts +17 -0
  29. package/dist/channels/discord.d.ts.map +1 -0
  30. package/dist/channels/discord.js +114 -0
  31. package/dist/channels/discord.js.map +1 -0
  32. package/dist/channels/imessage.d.ts +23 -0
  33. package/dist/channels/imessage.d.ts.map +1 -0
  34. package/dist/channels/imessage.js +214 -0
  35. package/dist/channels/imessage.js.map +1 -0
  36. package/dist/channels/slack.d.ts +19 -0
  37. package/dist/channels/slack.d.ts.map +1 -0
  38. package/dist/channels/slack.js +167 -0
  39. package/dist/channels/slack.js.map +1 -0
  40. package/dist/channels/telegram.d.ts +19 -0
  41. package/dist/channels/telegram.d.ts.map +1 -0
  42. package/dist/channels/telegram.js +274 -0
  43. package/dist/channels/telegram.js.map +1 -0
  44. package/dist/channels/types.d.ts +44 -0
  45. package/dist/channels/types.d.ts.map +1 -0
  46. package/dist/channels/types.js +18 -0
  47. package/dist/channels/types.js.map +1 -0
  48. package/dist/channels/whatsapp.d.ts +23 -0
  49. package/dist/channels/whatsapp.d.ts.map +1 -0
  50. package/dist/channels/whatsapp.js +189 -0
  51. package/dist/channels/whatsapp.js.map +1 -0
  52. package/dist/config.d.ts +134 -0
  53. package/dist/config.d.ts.map +1 -0
  54. package/dist/config.js +127 -0
  55. package/dist/config.js.map +1 -0
  56. package/dist/cron.d.ts +8 -0
  57. package/dist/cron.d.ts.map +1 -0
  58. package/dist/cron.js +35 -0
  59. package/dist/cron.js.map +1 -0
  60. package/dist/decrypt-keys.d.ts +7 -0
  61. package/dist/decrypt-keys.d.ts.map +1 -0
  62. package/dist/decrypt-keys.js +53 -0
  63. package/dist/decrypt-keys.js.map +1 -0
  64. package/dist/encrypt-keys.d.ts +8 -0
  65. package/dist/encrypt-keys.d.ts.map +1 -0
  66. package/dist/encrypt-keys.js +62 -0
  67. package/dist/encrypt-keys.js.map +1 -0
  68. package/dist/executor.d.ts +31 -0
  69. package/dist/executor.d.ts.map +1 -0
  70. package/dist/executor.js +2009 -0
  71. package/dist/executor.js.map +1 -0
  72. package/dist/gemini-executor.d.ts +27 -0
  73. package/dist/gemini-executor.d.ts.map +1 -0
  74. package/dist/gemini-executor.js +160 -0
  75. package/dist/gemini-executor.js.map +1 -0
  76. package/dist/goals.d.ts +24 -0
  77. package/dist/goals.d.ts.map +1 -0
  78. package/dist/goals.js +189 -0
  79. package/dist/goals.js.map +1 -0
  80. package/dist/gym/activity-digest.d.ts +30 -0
  81. package/dist/gym/activity-digest.d.ts.map +1 -0
  82. package/dist/gym/activity-digest.js +506 -0
  83. package/dist/gym/activity-digest.js.map +1 -0
  84. package/dist/gym/dimension-scorer.d.ts +76 -0
  85. package/dist/gym/dimension-scorer.d.ts.map +1 -0
  86. package/dist/gym/dimension-scorer.js +236 -0
  87. package/dist/gym/dimension-scorer.js.map +1 -0
  88. package/dist/gym/gym-router.d.ts +7 -0
  89. package/dist/gym/gym-router.d.ts.map +1 -0
  90. package/dist/gym/gym-router.js +718 -0
  91. package/dist/gym/gym-router.js.map +1 -0
  92. package/dist/gym/index.d.ts +11 -0
  93. package/dist/gym/index.d.ts.map +1 -0
  94. package/dist/gym/index.js +11 -0
  95. package/dist/gym/index.js.map +1 -0
  96. package/dist/heartbeat.d.ts +21 -0
  97. package/dist/heartbeat.d.ts.map +1 -0
  98. package/dist/heartbeat.js +163 -0
  99. package/dist/heartbeat.js.map +1 -0
  100. package/dist/index.d.ts +2 -0
  101. package/dist/index.d.ts.map +1 -0
  102. package/dist/index.js +254 -0
  103. package/dist/index.js.map +1 -0
  104. package/dist/keystore.d.ts +22 -0
  105. package/dist/keystore.d.ts.map +1 -0
  106. package/dist/keystore.js +178 -0
  107. package/dist/keystore.js.map +1 -0
  108. package/dist/logger.d.ts +9 -0
  109. package/dist/logger.d.ts.map +1 -0
  110. package/dist/logger.js +45 -0
  111. package/dist/logger.js.map +1 -0
  112. package/dist/memory/daily.d.ts +22 -0
  113. package/dist/memory/daily.d.ts.map +1 -0
  114. package/dist/memory/daily.js +82 -0
  115. package/dist/memory/daily.js.map +1 -0
  116. package/dist/memory/embeddings.d.ts +15 -0
  117. package/dist/memory/embeddings.d.ts.map +1 -0
  118. package/dist/memory/embeddings.js +154 -0
  119. package/dist/memory/embeddings.js.map +1 -0
  120. package/dist/memory/index.d.ts +32 -0
  121. package/dist/memory/index.d.ts.map +1 -0
  122. package/dist/memory/index.js +159 -0
  123. package/dist/memory/index.js.map +1 -0
  124. package/dist/memory/search.d.ts +21 -0
  125. package/dist/memory/search.d.ts.map +1 -0
  126. package/dist/memory/search.js +77 -0
  127. package/dist/memory/search.js.map +1 -0
  128. package/dist/memory/store.d.ts +23 -0
  129. package/dist/memory/store.d.ts.map +1 -0
  130. package/dist/memory/store.js +144 -0
  131. package/dist/memory/store.js.map +1 -0
  132. package/dist/ollama-executor.d.ts +17 -0
  133. package/dist/ollama-executor.d.ts.map +1 -0
  134. package/dist/ollama-executor.js +112 -0
  135. package/dist/ollama-executor.js.map +1 -0
  136. package/dist/openai-executor.d.ts +38 -0
  137. package/dist/openai-executor.d.ts.map +1 -0
  138. package/dist/openai-executor.js +197 -0
  139. package/dist/openai-executor.js.map +1 -0
  140. package/dist/router.d.ts +11 -0
  141. package/dist/router.d.ts.map +1 -0
  142. package/dist/router.js +185 -0
  143. package/dist/router.js.map +1 -0
  144. package/dist/test-message.d.ts +2 -0
  145. package/dist/test-message.d.ts.map +1 -0
  146. package/dist/test-message.js +60 -0
  147. package/dist/test-message.js.map +1 -0
  148. package/dist/utils/imsg-db-reader.d.ts +24 -0
  149. package/dist/utils/imsg-db-reader.d.ts.map +1 -0
  150. package/dist/utils/imsg-db-reader.js +92 -0
  151. package/dist/utils/imsg-db-reader.js.map +1 -0
  152. package/dist/utils/imsg-rpc.d.ts +25 -0
  153. package/dist/utils/imsg-rpc.d.ts.map +1 -0
  154. package/dist/utils/imsg-rpc.js +149 -0
  155. package/dist/utils/imsg-rpc.js.map +1 -0
  156. package/dist/utils/message-formatter.d.ts +3 -0
  157. package/dist/utils/message-formatter.d.ts.map +1 -0
  158. package/dist/utils/message-formatter.js +69 -0
  159. package/dist/utils/message-formatter.js.map +1 -0
  160. package/dist/web-ui.d.ts +12 -0
  161. package/dist/web-ui.d.ts.map +1 -0
  162. package/dist/web-ui.js +5784 -0
  163. package/dist/web-ui.js.map +1 -0
  164. package/dist/whatsapp-chats.d.ts +2 -0
  165. package/dist/whatsapp-chats.d.ts.map +1 -0
  166. package/dist/whatsapp-chats.js +76 -0
  167. package/dist/whatsapp-chats.js.map +1 -0
  168. package/dist/whatsapp-login.d.ts +2 -0
  169. package/dist/whatsapp-login.d.ts.map +1 -0
  170. package/dist/whatsapp-login.js +90 -0
  171. package/dist/whatsapp-login.js.map +1 -0
  172. package/dist/wiki-sync.d.ts +21 -0
  173. package/dist/wiki-sync.d.ts.map +1 -0
  174. package/dist/wiki-sync.js +147 -0
  175. package/dist/wiki-sync.js.map +1 -0
  176. package/docs/AddNewAgentGuide.md +100 -0
  177. package/docs/AddNewMcpGuide.md +72 -0
  178. package/docs/Architecture.md +795 -0
  179. package/docs/CLAUDE-AI-SETUP.md +166 -0
  180. package/docs/Setup.md +297 -0
  181. package/docs/ai-gym-architecture.md +1040 -0
  182. package/docs/ai-gym-build-plan.md +343 -0
  183. package/docs/ai-gym-onboarding.md +122 -0
  184. package/docs/appcreator_plan.md +348 -0
  185. package/docs/platform-mcp-audit.md +320 -0
  186. package/docs/server-deployment-plan.md +503 -0
  187. package/docs/superpowers/plans/2026-03-25-marketplace.md +1281 -0
  188. package/docs/superpowers/specs/2026-03-25-marketplace-design.md +287 -0
  189. package/docs/user-guide.md +2016 -0
  190. package/mcp-catalog.json +628 -0
  191. package/package.json +63 -0
  192. package/public/MyAIforOne-logomark-512.svg +16 -0
  193. package/public/MyAIforOne-logomark-transparent.svg +15 -0
  194. package/public/activity.html +314 -0
  195. package/public/admin.html +1674 -0
  196. package/public/agent-dashboard.html +670 -0
  197. package/public/api-docs.html +1106 -0
  198. package/public/automations.html +722 -0
  199. package/public/canvas.css +223 -0
  200. package/public/canvas.js +588 -0
  201. package/public/changelog.html +231 -0
  202. package/public/gym.html +2766 -0
  203. package/public/home.html +1930 -0
  204. package/public/index.html +2809 -0
  205. package/public/lab.html +1643 -0
  206. package/public/library.html +1442 -0
  207. package/public/marketplace.html +1101 -0
  208. package/public/mcp-docs.html +441 -0
  209. package/public/mini.html +390 -0
  210. package/public/monitor.html +584 -0
  211. package/public/org.html +4304 -0
  212. package/public/projects.html +734 -0
  213. package/public/settings.html +645 -0
  214. package/public/tasks.html +932 -0
  215. package/public/trainers/alex.svg +12 -0
  216. package/public/trainers/jordan.svg +12 -0
  217. package/public/trainers/morgan.svg +12 -0
  218. package/public/trainers/riley.svg +12 -0
  219. package/public/trainers/sam.svg +12 -0
  220. package/public/user-guide.html +218 -0
  221. package/registry/agents.json +3 -0
  222. package/registry/apps.json +20 -0
  223. package/registry/installed-drafts.json +3 -0
  224. package/registry/mcps.json +1084 -0
  225. package/registry/prompts/personal/mcp-test-prompt.md +6 -0
  226. package/registry/prompts/personal/memory-recall.md +6 -0
  227. package/registry/prompts/platform/brainstorm.md +15 -0
  228. package/registry/prompts/platform/code-review.md +16 -0
  229. package/registry/prompts/platform/explain.md +16 -0
  230. package/registry/prompts.json +58 -0
  231. package/registry/skills/external/brainstorming.md +5 -0
  232. package/registry/skills/external/code-review.md +40 -0
  233. package/registry/skills/external/frontend-patterns.md +642 -0
  234. package/registry/skills/external/frontend-slides.md +184 -0
  235. package/registry/skills/external/systematic-debugging.md +5 -0
  236. package/registry/skills/external/tdd.md +328 -0
  237. package/registry/skills/external/verification-before-completion.md +5 -0
  238. package/registry/skills/external/writing-plans.md +5 -0
  239. package/registry/skills/platform/ai41_app_build.md +930 -0
  240. package/registry/skills/platform/ai41_app_deploy.md +168 -0
  241. package/registry/skills/platform/ai41_app_orchestrator.md +239 -0
  242. package/registry/skills/platform/ai41_app_patterns.md +359 -0
  243. package/registry/skills/platform/ai41_app_register.md +85 -0
  244. package/registry/skills/platform/ai41_app_scaffold.md +421 -0
  245. package/registry/skills/platform/ai41_app_verify.md +107 -0
  246. package/registry/skills/platform/opProjectCreate.md +239 -0
  247. package/registry/skills/platform/op_devbrowser.md +136 -0
  248. package/registry/skills/platform/sop_brandguidelines.md +103 -0
  249. package/registry/skills/platform/sop_docx.md +117 -0
  250. package/registry/skills/platform/sop_frontenddesign.md +44 -0
  251. package/registry/skills/platform/sop_frontenddesign_v2.md +659 -0
  252. package/registry/skills/platform/sop_mcpbuilder.md +133 -0
  253. package/registry/skills/platform/sop_pdf.md +172 -0
  254. package/registry/skills/platform/sop_pptx.md +133 -0
  255. package/registry/skills/platform/sop_skillcreator.md +104 -0
  256. package/registry/skills/platform/sop_themefactory.md +128 -0
  257. package/registry/skills/platform/sop_webapptesting.md +75 -0
  258. package/registry/skills/platform/sop_webartifactsbuilder.md +97 -0
  259. package/registry/skills/platform/sop_xlsx.md +134 -0
  260. package/registry/skills.json +1055 -0
  261. package/scripts/discover-chats.sh +11 -0
  262. package/scripts/install-service-windows.ps1 +87 -0
  263. package/scripts/install-service.sh +52 -0
  264. package/scripts/seed-registry.ts +195 -0
  265. package/scripts/test-send.sh +5 -0
  266. package/scripts/tray-indicator.ps1 +35 -0
  267. package/scripts/uninstall-service-windows.ps1 +23 -0
  268. package/scripts/uninstall-service.sh +15 -0
  269. package/scripts/xbar-myagent.5s.sh +32 -0
  270. package/server/mcp-server/dist/index.d.ts +11 -0
  271. package/server/mcp-server/dist/index.js +1332 -0
  272. package/server/mcp-server/dist/lib/api-client.d.ts +165 -0
  273. package/server/mcp-server/dist/lib/api-client.js +241 -0
  274. package/server/mcp-server/index.ts +1545 -0
  275. package/server/mcp-server/lib/api-client.ts +366 -0
  276. package/server/mcp-server/tsconfig.json +14 -0
  277. package/src/agent-registry.ts +180 -0
  278. package/src/channels/discord.ts +129 -0
  279. package/src/channels/imessage.ts +261 -0
  280. package/src/channels/slack.ts +208 -0
  281. package/src/channels/telegram.ts +307 -0
  282. package/src/channels/types.ts +62 -0
  283. package/src/channels/whatsapp.ts +227 -0
  284. package/src/config.ts +281 -0
  285. package/src/cron.ts +43 -0
  286. package/src/decrypt-keys.ts +60 -0
  287. package/src/encrypt-keys.ts +70 -0
  288. package/src/executor.ts +2190 -0
  289. package/src/gemini-executor.ts +212 -0
  290. package/src/goals.ts +240 -0
  291. package/src/gym/activity-digest.ts +546 -0
  292. package/src/gym/dimension-scorer.ts +297 -0
  293. package/src/gym/gym-router.ts +801 -0
  294. package/src/gym/index.ts +19 -0
  295. package/src/heartbeat.ts +220 -0
  296. package/src/index.ts +275 -0
  297. package/src/keystore.ts +190 -0
  298. package/src/logger.ts +51 -0
  299. package/src/memory/daily.ts +101 -0
  300. package/src/memory/embeddings.ts +185 -0
  301. package/src/memory/index.ts +218 -0
  302. package/src/memory/search.ts +124 -0
  303. package/src/memory/store.ts +189 -0
  304. package/src/ollama-executor.ts +126 -0
  305. package/src/openai-executor.ts +259 -0
  306. package/src/router.ts +230 -0
  307. package/src/test-message.ts +72 -0
  308. package/src/utils/imsg-db-reader.ts +109 -0
  309. package/src/utils/imsg-rpc.ts +178 -0
  310. package/src/utils/message-formatter.ts +90 -0
  311. package/src/web-ui.ts +5778 -0
  312. package/src/whatsapp-chats.ts +91 -0
  313. package/src/whatsapp-login.ts +110 -0
  314. package/src/wiki-sync.ts +199 -0
  315. package/tsconfig.json +19 -0
@@ -0,0 +1,366 @@
1
+ /**
2
+ * MyAIforOne API Client
3
+ * Wraps all REST API endpoints for use by MCP tools.
4
+ */
5
+
6
+ const BASE_URL = process.env.MYAGENT_API_URL || "http://localhost:4888";
7
+
8
+ interface RequestOptions {
9
+ method?: string;
10
+ body?: any;
11
+ query?: Record<string, string | number | undefined>;
12
+ }
13
+
14
+ async function api(path: string, opts: RequestOptions = {}): Promise<any> {
15
+ let url = `${BASE_URL}${path}`;
16
+ if (opts.query) {
17
+ const params = new URLSearchParams();
18
+ for (const [k, v] of Object.entries(opts.query)) {
19
+ if (v !== undefined && v !== "") params.set(k, String(v));
20
+ }
21
+ const qs = params.toString();
22
+ if (qs) url += `?${qs}`;
23
+ }
24
+
25
+ const headers: Record<string, string> = {};
26
+ if (opts.body) headers["Content-Type"] = "application/json";
27
+
28
+ const res = await fetch(url, {
29
+ method: opts.method || "GET",
30
+ headers,
31
+ body: opts.body ? JSON.stringify(opts.body) : undefined,
32
+ });
33
+
34
+ const text = await res.text();
35
+ try { return JSON.parse(text); } catch { return text; }
36
+ }
37
+
38
+ // ─── Dashboard & Health ───────────────────────────────────────────
39
+ export const health = () => api("/health");
40
+ export const dashboard = () => api("/api/dashboard");
41
+ export const agentRegistry = () => api("/api/agent-registry");
42
+
43
+ // ─── Agents ───────────────────────────────────────────────────────
44
+ export const listAgents = (org?: string) => api("/api/agents", { query: { org } });
45
+ export const getAgent = (id: string) => api(`/api/agents/${id}`);
46
+ export const getAgentInstructions = (id: string) => api(`/api/agents/${id}/instructions`);
47
+ export const createAgent = (body: any) => api("/api/agents", { method: "POST", body });
48
+ export const updateAgent = (id: string, body: any) => api(`/api/agents/${id}`, { method: "PUT", body });
49
+ export const deleteAgent = (id: string, confirmAlias: string) =>
50
+ api(`/api/agents/${id}`, { method: "DELETE", body: { confirmAlias } });
51
+ export const recoverAgent = (id: string, userText?: string, response?: string) =>
52
+ api(`/api/agents/${id}/recover`, { method: "POST", body: { userText: userText || "Session recovery triggered via MCP tool", response } });
53
+
54
+ // ─── Chat ─────────────────────────────────────────────────────────
55
+ export const sendMessage = (agentId: string, text: string, accountOverride?: string) =>
56
+ api(`/api/chat/${agentId}`, { method: "POST", body: { text, accountOverride } });
57
+ export const startStream = (agentId: string, text: string, accountOverride?: string) =>
58
+ api(`/api/chat/${agentId}/stream`, { method: "POST", body: { text, accountOverride } });
59
+ export const stopJob = (jobId: string) => api(`/api/chat/jobs/${jobId}/stop`, { method: "POST" });
60
+ export const delegate = (agentId: string, text: string) =>
61
+ api("/api/delegate", { method: "POST", body: { agentId, text } });
62
+
63
+ // ─── Sessions ─────────────────────────────────────────────────────
64
+ export const listSessions = (agentId: string) => api(`/api/agents/${agentId}/sessions`);
65
+ export const resetSession = (agentId: string, senderId?: string) =>
66
+ api(`/api/agents/${agentId}/sessions/reset`, { method: "POST", body: { senderId } });
67
+ export const deleteSession = (agentId: string, senderId: string) =>
68
+ api(`/api/agents/${agentId}/sessions/${senderId}`, { method: "DELETE" });
69
+
70
+ // ─── Named Session Tabs ────────────────────────────────────────────
71
+ export const createSessionTab = (agentId: string, tabId: string, label: string, targetAgentId?: string) =>
72
+ api(`/api/agents/${agentId}/session-tabs`, { method: "POST", body: { tabId, label, ...(targetAgentId ? { targetAgentId } : {}) } });
73
+ export const listSessionTabs = (agentId: string) => api(`/api/agents/${agentId}/session-tabs`);
74
+ export const getSessionTabHistory = (agentId: string, tabId: string) =>
75
+ api(`/api/agents/${agentId}/session-tabs/${tabId}/history`);
76
+ export const renameSessionTab = (agentId: string, tabId: string, label: string) =>
77
+ api(`/api/agents/${agentId}/session-tabs/${tabId}`, { method: "PUT", body: { label } });
78
+ export const deleteSessionTab = (agentId: string, tabId: string) =>
79
+ api(`/api/agents/${agentId}/session-tabs/${tabId}`, { method: "DELETE" });
80
+
81
+ // ─── Model ────────────────────────────────────────────────────────
82
+ export const getModel = (agentId: string) => api(`/api/agents/${agentId}/model`);
83
+ export const setModel = (agentId: string, model: string) =>
84
+ api(`/api/agents/${agentId}/model`, { method: "PUT", body: { model } });
85
+ export const clearModel = (agentId: string) =>
86
+ api(`/api/agents/${agentId}/model`, { method: "DELETE" });
87
+
88
+ // ─── Cost ─────────────────────────────────────────────────────────
89
+ export const getAgentCost = (agentId: string) => api(`/api/agents/${agentId}/cost`);
90
+ export const getAllCosts = () => api("/api/cost/all");
91
+
92
+ // ─── Skills ───────────────────────────────────────────────────────
93
+ export const getAgentSkills = (agentId: string) => api(`/api/agents/${agentId}/skills`);
94
+ export const getOrgSkills = (orgName: string) => api(`/api/skills/org/${orgName}`);
95
+
96
+ // ─── Tasks ────────────────────────────────────────────────────────
97
+ export const listTasks = (agentId: string) => api(`/api/agents/${agentId}/tasks`);
98
+ export const taskStats = (agentId: string) => api(`/api/agents/${agentId}/tasks/stats`);
99
+ export const createTask = (agentId: string, body: any) =>
100
+ api(`/api/agents/${agentId}/tasks`, { method: "POST", body });
101
+ export const updateTask = (agentId: string, taskId: string, body: any) =>
102
+ api(`/api/agents/${agentId}/tasks/${taskId}`, { method: "PUT", body });
103
+ export const deleteTask = (agentId: string, taskId: string) =>
104
+ api(`/api/agents/${agentId}/tasks/${taskId}`, { method: "DELETE" });
105
+ export const allTasks = () => api("/api/tasks/all");
106
+
107
+ // ─── Automations ──────────────────────────────────────────────────
108
+ export const listAutomations = () => api("/api/automations");
109
+ export const createGoal = (agentId: string, body: any) =>
110
+ api(`/api/agents/${agentId}/goals`, { method: "POST", body });
111
+ export const toggleGoal = (agentId: string, goalId: string) =>
112
+ api(`/api/agents/${agentId}/goals/${goalId}/toggle`, { method: "POST" });
113
+ export const triggerGoal = (agentId: string, goalId: string) =>
114
+ api(`/api/agents/${agentId}/goals/${goalId}/trigger`, { method: "POST" });
115
+ export const goalHistory = (agentId: string, goalId: string) =>
116
+ api(`/api/agents/${agentId}/goals/${goalId}/history`);
117
+ export const deleteGoal = (agentId: string, goalId: string) =>
118
+ api(`/api/agents/${agentId}/goals/${goalId}`, { method: "DELETE" });
119
+ export const createCron = (agentId: string, body: any) =>
120
+ api(`/api/agents/${agentId}/cron`, { method: "POST", body });
121
+ export const toggleCron = (agentId: string, index: number) =>
122
+ api(`/api/agents/${agentId}/cron/${index}/toggle`, { method: "POST" });
123
+ export const triggerCron = (agentId: string, index: number) =>
124
+ api(`/api/agents/${agentId}/cron/${index}/trigger`, { method: "POST" });
125
+ export const cronHistory = (agentId: string, index: number) =>
126
+ api(`/api/agents/${agentId}/cron/${index}/history`);
127
+ export const deleteCron = (agentId: string, index: number) =>
128
+ api(`/api/agents/${agentId}/cron/${index}`, { method: "DELETE" });
129
+
130
+ // ─── MCPs ─────────────────────────────────────────────────────────
131
+ export const listMcps = () => api("/api/mcps");
132
+ export const mcpCatalog = () => api("/api/mcp-catalog");
133
+ export const listMcpKeys = (agentId: string) => api(`/api/agents/${agentId}/mcp-keys`);
134
+ export const saveMcpKey = (agentId: string, mcpName: string, envVar: string, value: string) =>
135
+ api(`/api/agents/${agentId}/mcp-keys`, { method: "POST", body: { mcpName, envVar, value } });
136
+ export const deleteMcpKey = (agentId: string, mcpName: string) =>
137
+ api(`/api/agents/${agentId}/mcp-keys/${mcpName}`, { method: "DELETE" });
138
+ export const listMcpConnections = (agentId: string) => api(`/api/agents/${agentId}/mcp-connections`);
139
+ export const createMcpConnection = (agentId: string, body: any) =>
140
+ api(`/api/agents/${agentId}/mcp-connections`, { method: "POST", body });
141
+ export const deleteMcpConnection = (agentId: string, instanceName: string) =>
142
+ api(`/api/agents/${agentId}/mcp-connections/${instanceName}`, { method: "DELETE" });
143
+
144
+ // ─── Channels ─────────────────────────────────────────────────────
145
+ export const listChannels = () => api("/api/channels");
146
+ export const updateChannel = (name: string, body: any) =>
147
+ api(`/api/channels/${name}`, { method: "PUT", body });
148
+ export const addAgentRoute = (channelName: string, body: any) =>
149
+ api(`/api/channels/${channelName}/agents`, { method: "POST", body });
150
+ export const removeAgentRoute = (channelName: string, agentId: string) =>
151
+ api(`/api/channels/${channelName}/agents/${agentId}`, { method: "DELETE" });
152
+ export const stickyRouting = () => api("/api/sticky-routing");
153
+
154
+ // ─── Registry / Marketplace ───────────────────────────────────────
155
+ export const marketplace = (type: string) => api(`/api/marketplace/${type}`);
156
+ export const installMarketplace = (id: string, type: string) =>
157
+ api("/api/marketplace/install", { method: "POST", body: { id, type } });
158
+ export const assignToAgent = (agentId: string, itemId: string, type: string) =>
159
+ api("/api/marketplace/assign", { method: "POST", body: { agentIds: [agentId], id: itemId, type } });
160
+
161
+ // ─── Apps ─────────────────────────────────────────────────────────
162
+ export const listApps = () => api("/api/apps");
163
+ export const createApp = (body: any) => api("/api/apps", { method: "POST", body });
164
+ export const updateApp = (id: string, body: any) => api(`/api/apps/${id}`, { method: "PUT", body });
165
+ export const deleteApp = (id: string) => api(`/api/apps/${id}`, { method: "DELETE" });
166
+
167
+ // ─── Activity & Logs ──────────────────────────────────────────────
168
+ export const activity = (limit?: number) => api("/api/activity", { query: { limit } });
169
+ export const agentLogs = (agentId: string, limit?: number, offset?: number, search?: string) =>
170
+ api(`/api/agents/${agentId}/logs`, { query: { limit, offset, search } });
171
+
172
+ // ─── Memory ───────────────────────────────────────────────────────
173
+ export const agentMemory = (agentId: string, limit?: number) =>
174
+ api(`/api/agents/${agentId}/memory`, { query: { limit } });
175
+ export const searchMemory = (agentId: string, query: string) =>
176
+ api(`/api/agents/${agentId}/memory/search`, { method: "POST", body: { query } });
177
+ export const clearMemoryContext = (agentId: string) =>
178
+ api(`/api/agents/${agentId}/memory/context`, { method: "DELETE" });
179
+
180
+ // ─── Pairing ──────────────────────────────────────────────────────
181
+ export const listPairing = () => api("/api/pairing");
182
+ export const pairSender = (senderKey: string) =>
183
+ api("/api/pairing", { method: "POST", body: { senderKey } });
184
+ export const unpairSender = (senderKey: string) =>
185
+ api(`/api/pairing/${encodeURIComponent(senderKey)}`, { method: "DELETE" });
186
+
187
+ // ─── Config ───────────────────────────────────────────────────────
188
+ export const listAccounts = () => api("/api/config/accounts");
189
+ export const addAccount = (name: string, path: string) =>
190
+ api("/api/config/accounts", { method: "POST", body: { name, path } });
191
+ export const deleteAccount = (name: string) =>
192
+ api(`/api/config/accounts/${encodeURIComponent(name)}`, { method: "DELETE" });
193
+ export const accountStatus = (name: string) =>
194
+ api(`/api/config/accounts/${encodeURIComponent(name)}/status`);
195
+ export const getServiceConfig = () => api("/api/config/service");
196
+ export const updateServiceConfig = (body: any) =>
197
+ api("/api/config/service", { method: "PUT", body });
198
+ export const testProvider = (provider: string) =>
199
+ api("/api/config/provider-test", { method: "POST", body: { provider } });
200
+
201
+ // ─── Profile ────────────────────────────────────────────────────────
202
+ export const getProfile = () => api("/api/profile");
203
+ export const updateProfile = (body: any) => api("/api/profile", { method: "PUT", body });
204
+
205
+ // ─── Files ────────────────────────────────────────────────────────
206
+ export const listFiles = (agentId: string) => api(`/api/agents/${agentId}/files`);
207
+ export const downloadFile = (agentId: string, path: string) =>
208
+ api(`/api/agents/${agentId}/download`, { query: { path } });
209
+
210
+ // ─── Additional ──────────────────────────────────────────────────
211
+ export const createProject = (agentId: string, name: string) =>
212
+ api(`/api/agents/${agentId}/projects`, { method: "POST", body: { id: name.toLowerCase().replace(/[^a-z0-9]+/g, "-"), name } });
213
+
214
+ // ─── Projects (cross-agent initiatives) ─────────────────────────
215
+ export const listProjects = () => api("/api/projects");
216
+ export const getProject = (id: string) => api(`/api/projects/${id}`);
217
+ export const createInitiative = (body: any) =>
218
+ api("/api/projects", { method: "POST", body });
219
+ export const updateProject = (id: string, body: any) =>
220
+ api(`/api/projects/${id}`, { method: "PUT", body });
221
+ export const deleteProject = (id: string) =>
222
+ api(`/api/projects/${id}`, { method: "DELETE" });
223
+ export const linkToProject = (id: string, type: string, value: any) =>
224
+ api(`/api/projects/${id}/link`, { method: "POST", body: { type, value } });
225
+ export const unlinkFromProject = (id: string, type: string, value: any) =>
226
+ api(`/api/projects/${id}/unlink`, { method: "POST", body: { type, value } });
227
+ export const getProjectStatus = (id: string) => api(`/api/projects/${id}/status`);
228
+ export const executeProject = (id: string, body?: any) =>
229
+ api(`/api/projects/${id}/execute`, { method: "POST", body: body || {} });
230
+ export const pauseProject = (id: string) =>
231
+ api(`/api/projects/${id}/pause`, { method: "POST" });
232
+ export const addMonitoredChat = (channelName: string, chatId: string) =>
233
+ api(`/api/channels/${channelName}/monitored`, { method: "POST", body: { chatId: Number(chatId) } });
234
+ export const removeMonitoredChat = (channelName: string, chatId: string) =>
235
+ api(`/api/channels/${channelName}/monitored`, { method: "DELETE", body: { chatId: Number(chatId) } });
236
+ export const scanSkills = (dir?: string) =>
237
+ api("/api/marketplace/scan-skills", { query: { dir } });
238
+ export const createPrompt = (id: string, name: string, content: string) =>
239
+ api("/api/marketplace/create-prompt", { method: "POST", body: { id, name, content } });
240
+ export const createSkill = (id: string, name: string, description: string, content: string, scope: string, orgName?: string, agentId?: string) =>
241
+ api("/api/skills/create", { method: "POST", body: { id, name, description, content, scope, orgName, agentId } });
242
+ export const addMcpToRegistry = (body: any) =>
243
+ api("/api/marketplace/add-mcp", { method: "POST", body });
244
+ export const checkAppHealth = (id: string) =>
245
+ api(`/api/apps/${id}/check-health`, { method: "POST" });
246
+ export const startLogin = (name: string, path: string) =>
247
+ api("/api/config/accounts/login", { method: "POST", body: { name, path } });
248
+
249
+ // ─── Login ───────────────────────────────────────────────────────
250
+ export const submitLoginCode = (accountName: string, code: string) =>
251
+ api("/api/config/accounts/login/code", { method: "POST", body: { accountName, code } });
252
+
253
+ // ─── Marketplace Extras ─────────────────────────────────────────
254
+ export const setPlatformDefault = (type: string, id: string) =>
255
+ api("/api/marketplace/platform-default", { method: "POST", body: { type, id } });
256
+ export const importSkills = (agentId: string, skills: string[]) =>
257
+ api("/api/marketplace/import-skills", { method: "POST", body: { agentId, skills } });
258
+ export const getPromptTrigger = () => api("/api/marketplace/prompt-trigger");
259
+ export const setPromptTrigger = (trigger: string) =>
260
+ api("/api/marketplace/prompt-trigger", { method: "POST", body: { trigger } });
261
+
262
+ // ─── Chat Streaming ─────────────────────────────────────────────
263
+ export const getChatJobRaw = (jobId: string, after?: number) =>
264
+ api(`/api/chat/jobs/${jobId}/raw`, { query: { after } });
265
+
266
+ // ─── Heartbeat ──────────────────────────────────────────────────
267
+ export const triggerHeartbeat = (agentId: string, triggeredBy?: string) =>
268
+ api(`/api/agents/${agentId}/heartbeat`, { method: "POST", body: { triggeredBy } });
269
+ export const heartbeatHistory = (agentId: string, limit?: number) =>
270
+ api(`/api/agents/${agentId}/heartbeat-history`, { query: { limit } });
271
+
272
+ // ─── Wiki Sync ──────────────────────────────────────────────────
273
+ export const triggerWikiSync = (agentId: string, triggeredBy?: string) =>
274
+ api(`/api/agents/${agentId}/wiki-sync`, { method: "POST", body: { triggeredBy } });
275
+ export const wikiSyncHistory = (agentId: string, limit?: number) =>
276
+ api(`/api/agents/${agentId}/wiki-sync-history`, { query: { limit } });
277
+
278
+ // ─── Whoami ─────────────────────────────────────────────────────
279
+ export const whoami = (agentId: string) => api(`/api/whoami/${agentId}`);
280
+
281
+ // ─── Changelog ──────────────────────────────────────────────────
282
+ export const changelog = () => api("/api/changelog");
283
+
284
+ // ─── Webhook ────────────────────────────────────────────────────
285
+ export const sendWebhook = (agentId: string, text: string, secret?: string, channel?: string, chatId?: string) => {
286
+ const headers: Record<string, string> = { "Content-Type": "application/json" };
287
+ if (secret) headers["x-webhook-secret"] = secret;
288
+ return api(`/webhook/${agentId}`, { method: "POST", body: { text, channel, chatId } });
289
+ };
290
+
291
+ // ─── Install xbar ───────────────────────────────────────────────
292
+ export const installXbar = () => api("/api/install-xbar", { method: "POST" });
293
+
294
+ // ─── Lab / Platform Agents ───────────────────────────────────────
295
+ export const getPlatformAgents = () => api("/api/platform-agents");
296
+ export const browseDirs = (path?: string) => api("/api/browse-dirs", { query: { path } });
297
+
298
+ // ─── SaaS Integration ───────────────────────────────────────────
299
+ export const getSaasConfig = () => api("/api/saas/config");
300
+ export const updateSaasConfig = (baseUrl?: string, apiKey?: string) =>
301
+ api("/api/saas/config", { method: "PUT", body: { baseUrl, apiKey } });
302
+ export const testSaasConnection = (baseUrl?: string, apiKey?: string) =>
303
+ api("/api/saas/test", { method: "POST", body: { baseUrl, apiKey } });
304
+ export const publishToSaas = (type: string, id: string, destination?: string) =>
305
+ api("/api/saas/publish", { method: "POST", body: { type, id, destination } });
306
+
307
+ // ─── File Upload ────────────────────────────────────────────────
308
+ export const uploadFile = (agentId: string, fileName: string, base64Content: string, mode?: string) =>
309
+ api(`/api/upload/${agentId}/json`, { method: "POST", body: { fileName, base64Content, mode } });
310
+
311
+ // ─── User Guide ─────────────────────────────────────────────────
312
+ export const getUserGuide = () => api("/api/user-guide");
313
+
314
+ // ─── Memory Write ───────────────────────────────────────────────
315
+ export const writeMemory = (agentId: string, content: string, target?: string) =>
316
+ api(`/api/agents/${agentId}/memory/write`, { method: "POST", body: { content, target } });
317
+
318
+ // ─── Skill Content ──────────────────────────────────────────────
319
+ export const getSkillContent = (path: string) =>
320
+ api("/api/skills/content", { query: { path } });
321
+
322
+ // ─── Goal/Cron Update ───────────────────────────────────────────
323
+ export const updateGoal = (agentId: string, goalId: string, body: any) =>
324
+ api(`/api/agents/${agentId}/goals/${goalId}`, { method: "PUT", body });
325
+ export const updateCron = (agentId: string, index: number, body: any) =>
326
+ api(`/api/agents/${agentId}/cron/${index}`, { method: "PUT", body });
327
+
328
+ // ─── Service Restart ────────────────────────────────────────────
329
+ export const restart = () => api("/api/restart", { method: "POST" });
330
+
331
+ // ─── Discovery ──────────────────────────────────────────────────
332
+ export const listCapabilities = () => api("/api/capabilities");
333
+
334
+ // ─── Drive ──────────────────────────────────────────────────────
335
+ export const browseDrive = (path?: string) => api("/api/drive/browse", { query: { path } });
336
+ export const readDriveFile = (path: string) => api("/api/drive/read", { query: { path } });
337
+ export const searchDrive = (q: string, path?: string, limit?: number, types?: string) =>
338
+ api("/api/drive/search", { query: { q, path, limit, types } });
339
+
340
+ // ─── Gym ─────────────────────────────────────────────────────────
341
+ export const getGymLearnerProfile = () => api("/api/gym/learner-profile");
342
+ export const updateGymLearnerProfile = (body: any) => api("/api/gym/learner-profile", { method: "PUT", body });
343
+ export const getGymPlan = () => api("/api/gym/plan");
344
+ export const updateGymPlan = (body: any) => api("/api/gym/plan", { method: "PUT", body });
345
+ export const getGymProgress = () => api("/api/gym/progress");
346
+ export const updateGymProgress = (body: any) => api("/api/gym/progress", { method: "PUT", body });
347
+ export const listGymCards = () => api("/api/gym/cards");
348
+ export const createGymCard = (body: any) => api("/api/gym/cards", { method: "POST", body });
349
+ export const dismissGymCard = (id: string) => api(`/api/gym/cards/${id}`, { method: "DELETE" });
350
+ export const snapshotDimensions = (body: any) => api("/api/gym/dimensions/snapshot", { method: "POST", body });
351
+ export const listGymPrograms = () => api("/api/gym/programs");
352
+ export const getGymProgram = (slug: string) => api(`/api/gym/programs/${slug}`);
353
+ export const createGymProgram = (body: any) => api("/api/gym/programs", { method: "POST", body });
354
+ export const importGymProgram = (body: any) => api("/api/gym/programs/import-markdown", { method: "POST", body });
355
+ export const updateGymProgram = (slug: string, body: any) => api(`/api/gym/programs/${slug}`, { method: "PATCH", body });
356
+ export const deleteGymProgram = (slug: string) => api(`/api/gym/programs/${slug}`, { method: "DELETE" });
357
+ export const getGymDimensionHistory = () => api("/api/gym/dimensions/history");
358
+ export const runGymDigest = () => api("/api/gym/digest/run", { method: "POST" });
359
+ export const getAgentActivitySummary = (id: string) => api(`/api/agents/${id}/activity-summary`);
360
+ export const searchAgentLogs = (q: string, agentIds?: string) => api("/api/agents/logs/search", { query: { q, agentIds } });
361
+ export const getGymFeed = () => api("/api/gym/feed");
362
+ export const getGymConfig = () => api("/api/gym/config");
363
+ export const listGymGuides = () => api("/api/gym/guides");
364
+ export const createGymGuide = (data: Record<string, unknown>) => api("/api/gym/guides", { method: "POST", body: data });
365
+ export const getGymInsights = () => api("/api/gym/insights");
366
+ export const saveGymInsights = (data: Record<string, unknown>) => api("/api/gym/insights", { method: "POST", body: data });
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "outDir": "dist",
7
+ "rootDir": ".",
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "declaration": true
12
+ },
13
+ "include": ["./**/*.ts"]
14
+ }
@@ -0,0 +1,180 @@
1
+ /**
2
+ * Agent Registry — indexes agent descriptions for RAG-based delegation.
3
+ * Used by group agents to find the right sub-agent for a user query.
4
+ */
5
+
6
+ import { readFileSync, writeFileSync, existsSync, mkdirSync } from "node:fs";
7
+ import { join, resolve } from "node:path";
8
+ import type { AppConfig } from "./config.js";
9
+ import { log } from "./logger.js";
10
+
11
+ interface AgentRegistryEntry {
12
+ id: string;
13
+ name: string;
14
+ description: string;
15
+ aliases: string[];
16
+ mcps: string[];
17
+ org: string;
18
+ function: string;
19
+ capabilities: string;
20
+ }
21
+
22
+ interface RegistryIndex {
23
+ entries: AgentRegistryEntry[];
24
+ updatedAt: string;
25
+ }
26
+
27
+ /**
28
+ * Build a searchable text block for an agent (used for keyword/embedding matching).
29
+ */
30
+ function buildAgentSearchText(id: string, agent: AppConfig["agents"][string]): string {
31
+ const parts = [
32
+ `Agent: ${agent.name} (${id})`,
33
+ `Description: ${agent.description}`,
34
+ `Aliases: ${(agent.mentionAliases || []).join(", ")}`,
35
+ ];
36
+ if (agent.mcps?.length) parts.push(`MCPs/Integrations: ${agent.mcps.join(", ")}`);
37
+ if (agent.org?.length) {
38
+ parts.push(`Organization: ${agent.org.map(o => `${o.organization} / ${o.function} / ${o.title}`).join("; ")}`);
39
+ }
40
+ if (agent.allowedTools?.length) parts.push(`Tools: ${agent.allowedTools.join(", ")}`);
41
+ if (agent.goals?.length) {
42
+ parts.push(`Goals: ${agent.goals.map(g => g.description).join("; ")}`);
43
+ }
44
+
45
+ // Try to read the CLAUDE.md for richer description
46
+ try {
47
+ const home = process.env.HOME || process.env.USERPROFILE || "";
48
+ const claudeMdPath = agent.claudeMd.startsWith("~") ? agent.claudeMd.replace("~", home) : agent.claudeMd;
49
+ if (existsSync(claudeMdPath)) {
50
+ const claudeMd = readFileSync(claudeMdPath, "utf-8");
51
+ // Extract just the first section (usually the main description)
52
+ const firstSection = claudeMd.split("##")[0].trim();
53
+ if (firstSection.length > 50 && firstSection.length < 2000) {
54
+ parts.push(`Details: ${firstSection}`);
55
+ }
56
+ }
57
+ } catch { /* ignore */ }
58
+
59
+ return parts.join("\n");
60
+ }
61
+
62
+ /**
63
+ * Build the registry for a group agent's sub-agents.
64
+ */
65
+ export function buildAgentRegistry(
66
+ config: AppConfig,
67
+ subAgents: string[] | "*",
68
+ ): AgentRegistryEntry[] {
69
+ const agentIds = subAgents === "*"
70
+ ? Object.keys(config.agents)
71
+ : subAgents;
72
+
73
+ return agentIds
74
+ .filter(id => config.agents[id] && !config.agents[id].subAgents) // exclude other group agents
75
+ .map(id => {
76
+ const agent = config.agents[id];
77
+ return {
78
+ id,
79
+ name: agent.name,
80
+ description: agent.description,
81
+ aliases: agent.mentionAliases || [],
82
+ mcps: agent.mcps || [],
83
+ org: agent.org?.[0]?.organization || "",
84
+ function: agent.org?.[0]?.function || "",
85
+ capabilities: buildAgentSearchText(id, agent),
86
+ };
87
+ });
88
+ }
89
+
90
+ /**
91
+ * Simple keyword-based search against agent registry.
92
+ * Returns top N matches ranked by keyword overlap.
93
+ * Falls back to this when vector search isn't available.
94
+ */
95
+ export function searchAgentRegistry(
96
+ registry: AgentRegistryEntry[],
97
+ query: string,
98
+ topN: number = 5,
99
+ ): AgentRegistryEntry[] {
100
+ const queryWords = query.toLowerCase().split(/\s+/).filter(w => w.length > 2);
101
+
102
+ const scored = registry.map(entry => {
103
+ const text = entry.capabilities.toLowerCase();
104
+ let score = 0;
105
+ for (const word of queryWords) {
106
+ if (text.includes(word)) score++;
107
+ // Bonus for name/description match
108
+ if (entry.name.toLowerCase().includes(word)) score += 2;
109
+ if (entry.description.toLowerCase().includes(word)) score += 2;
110
+ // Bonus for MCP match
111
+ if (entry.mcps.some(m => m.toLowerCase().includes(word))) score += 3;
112
+ }
113
+ return { entry, score };
114
+ });
115
+
116
+ return scored
117
+ .filter(s => s.score > 0)
118
+ .sort((a, b) => b.score - a.score)
119
+ .slice(0, topN)
120
+ .map(s => s.entry);
121
+ }
122
+
123
+ /**
124
+ * Build the system prompt section for a group agent.
125
+ * Includes the full registry table and delegation instructions.
126
+ */
127
+ export function buildGroupAgentPrompt(
128
+ registry: AgentRegistryEntry[],
129
+ query: string,
130
+ port: number = 4888,
131
+ ): string {
132
+ // Search for relevant agents
133
+ const relevant = searchAgentRegistry(registry, query, 5);
134
+ const allAgents = registry;
135
+
136
+ const lines: string[] = [
137
+ "\n\n## Sub-Agent Delegation",
138
+ "You are a **group agent**. Your job is to understand the user's request and delegate to the right specialist agent. You can delegate to multiple agents in one conversation.",
139
+ "",
140
+ "### How to Delegate",
141
+ "Use Bash to call the delegation API:",
142
+ "```bash",
143
+ `curl -s -X POST http://localhost:${port}/api/delegate \\`,
144
+ ` -H "Content-Type: application/json" \\`,
145
+ ` -d '{"agentId":"<agent-id>","text":"<the user\\'s question or task>"}'`,
146
+ "```",
147
+ "The response JSON has `{ ok: true, agentId, response }`. Present the `response` to the user.",
148
+ "",
149
+ "### Guidelines",
150
+ "- Pick the best agent based on their description, MCPs, and capabilities",
151
+ "- You can delegate to multiple agents in sequence if the request spans multiple domains",
152
+ "- If you're unsure which agent to use, pick the closest match — don't ask the user to choose",
153
+ "- If no agent matches, answer the question yourself using your own knowledge",
154
+ "- After getting a delegate's response, you can add context or synthesize across multiple responses",
155
+ "- NEVER reveal the delegation mechanism to the user — present responses naturally",
156
+ "",
157
+ ];
158
+
159
+ // Show relevant agents first (RAG results)
160
+ if (relevant.length > 0) {
161
+ lines.push("### Most Relevant Agents for This Query");
162
+ lines.push("| Agent | Alias | Description | MCPs |");
163
+ lines.push("|-------|-------|-------------|------|");
164
+ for (const a of relevant) {
165
+ lines.push(`| **${a.name}** | ${a.aliases[0] || a.id} | ${a.description.slice(0, 100)} | ${a.mcps.slice(0, 5).join(", ")} |`);
166
+ }
167
+ lines.push("");
168
+ }
169
+
170
+ // Full registry
171
+ lines.push("### Full Agent Registry");
172
+ lines.push("| ID | Name | Description | Org |");
173
+ lines.push("|----|------|-------------|-----|");
174
+ for (const a of allAgents) {
175
+ lines.push(`| ${a.id} | ${a.name} | ${a.description.slice(0, 80)} | ${a.org} |`);
176
+ }
177
+ lines.push("");
178
+
179
+ return lines.join("\n");
180
+ }