LeoYeAI/agent-master-skills / skills/agent-comm-hub
agent-comm-hub
Flagged多智能体协同通信基础设施——基于 MCP+SSE 的实时消息、任务调度、记忆共享与进化引擎。支持 WorkBuddy、Hermes、QClaw 及任意 MCP 兼容 Agent 接入。53 个 MCP 工具、4 级权限、零外部依赖 Python SDK。触发词:agent通信、智能体通信、hub通信、多智能体、跨agent通信、任务调度、assign_task、send_message、hermes通信、workbuddy通信、agent hub、通信hub、mcp通信、记忆共享、进化引擎、策略共享、经验分享、共享记忆,共同进化
src/utils.ts
View on GitHub/**
* utils.ts — MCP 工具共享工具函数
* 从 tools.ts 提取,供 src/tools/ 下所有模块共用
*/
import { type AuthContext } from "./security.js";
import { checkPermission, getRequiredPermission } from "./security.js";
import { logError } from "./logger.js";
import { getErrorMessage } from "./types.js";
import { HubError } from "./errors.js";
// ─── 通用工具:带指数退避的重试 ──────────────────────────
export async function withRetry<T>(
fn: () => T,
label: string,
maxRetries = 3,
): Promise<T> {
for (let attempt = 1; attempt <= maxRetries; attempt++) {
try {
return fn();
} catch (err: unknown) {
const isLast = attempt === maxRetries;
logError("withRetry_failed", err, { label, attempt, maxRetries });
if (isLast) throw err;
const delay = Math.pow(2, attempt - 1) * 100;
await new Promise(r => setTimeout(r, delay));
}
}
throw new Error(`unreachable`);
}
/**
* 创建带权限检查的工具包装器
*/
export function requireAuth(
authContext: AuthContext | undefined,
toolName: string
): AuthContext {
if (!authContext) {
throw new Error(`Authentication required for tool: ${toolName}`);
}
if (!checkPermission(toolName, authContext.role)) {
const required = getRequiredPermission(toolName) ?? "member";
throw new Error(
`Permission denied: ${toolName} requires '${required}' role, current role is '${authContext.role}'`
);
}
return authContext;
}
// ─── MCP 工具错误返回统一格式 ─────────────────────────────
/** MCP 工具 catch 块返回的统一格式(兼容 MCP SDK Tool callback 返回类型) */
export interface McpErrorContent {
content: [{ type: "text"; text: string }];
isError?: boolean;
[x: string]: unknown;
}
/**
* 构建统一 MCP 错误返回
* HubError → 结构化 JSON(含 code)
* 其他 Error → 简单 JSON(含 error + message)
* unknown → 简单 JSON(String(err))
*/
export function mcpError(err: unknown, toolName?: string): McpErrorContent {
if (HubError.isHubError(err)) {
return {
content: [{ type: "text", text: JSON.stringify(err.toJSON()) }],
isError: true,
};
}
const message = getErrorMessage(err);
const payload = { error: true, message };
if (toolName) (payload as Record<string, unknown>).tool = toolName;
return {
content: [{ type: "text", text: JSON.stringify(payload) }],
isError: true,
};
}
/**
* 构建统一 MCP 验证失败返回(非异常,用于 result.ok === false)
* 将 { success: false, error: string } 统一为 McpErrorContent
*/
export function mcpFail(error: string, toolName?: string): McpErrorContent {
const payload = { error: true, message: error };
if (toolName) (payload as Record<string, unknown>).tool = toolName;
return {
content: [{ type: "text", text: JSON.stringify(payload) }],
isError: true,
};
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |