Skip to content

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通信、记忆共享、进化引擎、策略共享、经验分享、共享记忆,共同进化

FileKindSize
.clawhub/origin.jsonconfig146 B
API_REFERENCE.mdmarkdown18.4 KB
HERMES-SETUP.mdmarkdown5.5 KB
README.mdmarkdown8.8 KB
SKILL.mdskill md16.4 KB
_meta.jsonconfig133 B
client-sdk/agent-client.d.tsscript11.6 KB
client-sdk/agent-client.jsscript28.6 KB
client-sdk/agent-client.tsscript29.8 KB
client-sdk/hermes-integration.d.tsscript785 B
client-sdk/hermes-integration.jsscript6.3 KB
client-sdk/hermes-integration.tsscript6.1 KB
client-sdk/hub_client.pyscript50.8 KB
client-sdk/workbuddy-integration.d.tsscript11 B
client-sdk/workbuddy-integration.jsscript4.3 KB
client-sdk/workbuddy-integration.tsscript4.2 KB
deploy/docker-compose.ymlconfig2.0 KB
deploy/grafana/dashboard.jsonconfig16.4 KB
deploy/grafana/provisioning/dashboards/dashboards.ymlconfig258 B
deploy/grafana/provisioning/datasources/prometheus.ymlconfig186 B
deploy/prometheus.ymlconfig408 B
docs/advanced-orchestration-guide.mdmarkdown11.8 KB
docs/evolution-engine-guide.mdmarkdown16.6 KB
docs/hermes-integration-guide.mdmarkdown22.3 KB
package-lock.jsonmanifest139.0 KB
package.jsonmanifest861 B
scripts/hub_task_runner.pyscript6.0 KB
scripts/hub_watcher.pyscript13.9 KB
scripts/install.shscript549 B
scripts/migrate_evolution_db.pyscript6.5 KB
scripts/migrate_from_agent.jsscript2.5 KB
scripts/wb_task_trigger.pyscript2.2 KB
src/db.d.tsscript3.7 KB
src/db.jsscript34.0 KB
src/db.tsscript37.4 KB
src/dedup.d.tsscript2.4 KB
src/dedup.jsscript8.5 KB
src/dedup.tsscript8.7 KB
src/errors.tsscript3.4 KB
src/evolution.d.tsscript6.6 KB
src/evolution.jsscript26.4 KB
src/evolution.tsscript31.0 KB
src/identity.d.tsscript3.4 KB
src/identity.jsscript15.9 KB
src/identity.tsscript17.1 KB
src/logger.d.tsscript1.1 KB
src/logger.jsscript2.8 KB
src/logger.tsscript3.5 KB
src/memory.d.tsscript2.1 KB
src/memory.jsscript13.0 KB
src/memory.tsscript14.3 KB
src/metrics.d.tsscript1.8 KB
src/metrics.jsscript8.4 KB
src/metrics.tsscript9.1 KB
src/orchestrator.d.tsscript6.1 KB
src/orchestrator.jsscript30.4 KB
src/orchestrator.tsscript33.4 KB
src/repo/interfaces.d.tsscript3.6 KB
src/repo/interfaces.jsscript49 B
src/repo/interfaces.tsscript4.2 KB
src/repo/sqlite-impl.d.tsscript225 B
src/repo/sqlite-impl.jsscript7.7 KB
src/repo/sqlite-impl.tsscript8.8 KB
src/repo/types.d.tsscript1021 B
src/repo/types.jsscript116 B
src/repo/types.tsscript1.6 KB
src/security.d.tsscript3.7 KB
src/security.jsscript15.0 KB
src/security.tsscript16.4 KB
src/server.d.tsscript11 B
src/server.jsscript24.7 KB
src/server.tsscript24.7 KB
src/sse.d.tsscript1.6 KB
src/sse.jsscript3.3 KB
src/sse.tsscript3.6 KB
src/stdio.d.tsscript11 B
src/stdio.jsscript1.7 KB
src/stdio.tsscript1.6 KB
src/tokenizer.d.tsscript1.3 KB
src/tokenizer.jsscript3.4 KB
src/tokenizer.tsscript3.2 KB
src/tools.d.tsscript474 B
src/tools.jsscript1.1 KB
src/tools.tsscript1.3 KB
src/tools/consumed.d.tsscript361 B
src/tools/consumed.jsscript5.5 KB
src/tools/consumed.tsscript5.3 KB
src/tools/evolution.d.tsscript660 B
src/tools/evolution.jsscript19.3 KB
src/tools/evolution.tsscript17.6 KB
src/tools/file.d.tsscript348 B
src/tools/file.jsscript7.1 KB
src/tools/file.tsscript6.5 KB
src/tools/identity.d.tsscript438 B
src/tools/identity.jsscript9.8 KB
src/tools/identity.tsscript9.3 KB
src/tools/memory.d.tsscript410 B
src/tools/memory.jsscript11.9 KB
src/tools/memory.tsscript10.8 KB
src/tools/message.d.tsscript467 B
src/tools/message.jsscript17.2 KB
src/tools/message.tsscript15.8 KB
src/tools/orchestrator.d.tsscript746 B
src/tools/orchestrator.jsscript27.8 KB
src/tools/orchestrator.tsscript24.3 KB
src/tools/security.d.tsscript386 B
src/tools/security.jsscript9.0 KB
src/tools/security.tsscript7.8 KB
src/types.tsscript5.9 KB
src/utils.d.tsscript421 B
src/utils.jsscript1.3 KB
src/utils.tsscript3.0 KB
tsconfig.jsonconfig337 B
vitest.config.tsscript1.2 KB

src/repo/sqlite-impl.ts

View on GitHub
/**
 * repo/sqlite-impl.ts — IMessageRepo / ITaskRepo / IConsumedLogRepo 的 SQLite 实现
 * Phase 2 Day 2 基础 + Phase 4b 依赖链 + 质量门扩展
 */
import {
  db,
  msgStmt,
  taskStmt,
  consumedStmt,
  type Message,
  type Task,
  type ConsumedEntry,
} from "../db.js";
import type { IMessageRepo, ITaskRepo, IConsumedLogRepo } from "./interfaces.js";
import type { TaskDependency, QualityGate, DepType, DepStatus, GateStatus } from "./types.js";

// ─── MessageRepo ──────────────────────────────────────────────

class SqliteMessageRepo implements IMessageRepo {
  insert(msg: Message): void {
    msgStmt.insert.run(msg);
  }

  markDelivered(id: string): void {
    msgStmt.markDelivered.run(id);
  }

  markRead(id: string): void {
    msgStmt.markRead.run(id);
  }

  markAcknowledged(id: string): void {
    msgStmt.markAcknowledged.run(id);
  }

  markAllDelivered(toAgent: string): void {
    msgStmt.markAllDelivered.run(toAgent);
  }

  pendingFor(toAgent: string): Message[] {
    return msgStmt.pendingFor.all(toAgent) as Message[];
  }

  getById(id: string): Message | undefined {
    return msgStmt.getById.get(id) as Message | undefined;
  }

  listByStatus(toAgent: string, status: string): Message[] {
    const stmt = db.prepare(
      `SELECT * FROM messages WHERE to_agent=? AND status=? ORDER BY created_at ASC`
    );
    return stmt.all(toAgent, status) as Message[];
  }

  updateStatus(id: string, status: string): void {
    const stmt = db.prepare(`UPDATE messages SET status=? WHERE id=?`);
    stmt.run(status, id);
  }

  listSince(toAgent: string, since: number): Message[] {
    const stmt = db.prepare(
      `SELECT * FROM messages WHERE to_agent=? AND created_at > ? ORDER BY created_at ASC`
    );
    return stmt.all(toAgent, since) as Message[];
  }
}

// ─── TaskRepo ─────────────────────────────────────────────────

class SqliteTaskRepo implements ITaskRepo {
  insert(task: Task): void {
    taskStmt.insert.run(task);
  }

  getById(id: string): Task | undefined {
    return taskStmt.getById.get(id) as Task | undefined;
  }

  update(id: string, status: string, result: string | null, progress: number): void {
    taskStmt.update.run(status, result, progress, Date.now(), id);
  }

  assignTo(id: string, assignedTo: string): void {
    taskStmt.updateAssignee.run(assignedTo, Date.now(), Date.now(), id);
  }

  listFor(assignedTo: string, status: string): Task[] {
    return taskStmt.listFor.all(assignedTo, status) as Task[];
  }

  listByPipeline(pipelineId: string): Task[] {
    return taskStmt.listByPipeline.all(pipelineId) as Task[];
  }

  // ─── Phase 4b: 依赖链实现 ────────────────────────────────

  addDependency(upstreamId: string, downstreamId: string, depType: DepType = "finish_to_start"): TaskDependency {
    if (upstreamId === downstreamId) {
      throw new Error("Cannot create self-dependency");
    }

    // 检查是否已存在
    const existing = db.prepare(
      `SELECT * FROM task_dependencies WHERE upstream_id=? AND downstream_id=?`
    ).get(upstreamId, downstreamId);
    if (existing) {
      throw new Error(`Dependency already exists: ${upstreamId} → ${downstreamId}`);
    }

    const id = `dep_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
    const now = Date.now();

    const dep: TaskDependency = {
      id, upstream_id: upstreamId, downstream_id: downstreamId,
      dep_type: depType, status: "pending", created_at: now,
    };

    db.prepare(
      `INSERT INTO task_dependencies (id, upstream_id, downstream_id, dep_type, status, created_at)
       VALUES (@id, @upstream_id, @downstream_id, @dep_type, @status, @created_at)`
    ).run(dep);

    return dep;
  }

  removeDependency(upstreamId: string, downstreamId: string): void {
    const result = db.prepare(
      `DELETE FROM task_dependencies WHERE upstream_id=? AND downstream_id=?`
    ).run(upstreamId, downstreamId);
    if (result.changes === 0) {
      throw new Error(`Dependency not found: ${upstreamId} → ${downstreamId}`);
    }
  }

  getDependencies(taskId: string): { upstreams: TaskDependency[]; downstreams: TaskDependency[] } {
    const upstreams = db.prepare(
      `SELECT * FROM task_dependencies WHERE downstream_id=? ORDER BY created_at ASC`
    ).all(taskId) as TaskDependency[];

    const downstreams = db.prepare(
      `SELECT * FROM task_dependencies WHERE upstream_id=? ORDER BY created_at ASC`
    ).all(taskId) as TaskDependency[];

    return { upstreams, downstreams };
  }

  checkDependenciesSatisfied(taskId: string): boolean {
    // 查找所有 pending 状态的上游依赖
    const pending = db.prepare(
      `SELECT COUNT(*) as cnt FROM task_dependencies
       WHERE downstream_id=? AND status='pending'`
    ).get(taskId) as { cnt: number };
    return pending.cnt === 0;
  }

  setTaskWaiting(taskId: string): void {
    db.prepare(
      `UPDATE tasks SET status='waiting', updated_at=? WHERE id=?`
    ).run(Date.now(), taskId);
  }

  setTaskReady(taskId: string): void {
    const task = db.prepare(`SELECT * FROM tasks WHERE id=?`).get(taskId) as Task | undefined;
    if (!task) throw new Error(`Task not found: ${taskId}`);
    if (task.status !== "waiting") {
      throw new Error(`Task is not in waiting state: ${task.status}`);
    }
    db.prepare(
      `UPDATE tasks SET status='assigned', updated_at=? WHERE id=?`
    ).run(Date.now(), taskId);
  }

  wouldCreateCycle(upstreamId: string, downstreamId: string): boolean {
    // DFS: 从 downstreamId 出发,沿现有依赖的 downstream 方向搜索,
    // 看是否能到达 upstreamId。
    // 如果能到达,说明添加 upstreamId→downstreamId 后会形成环。
    const visited = new Set<string>();
    const stack = [downstreamId];

    while (stack.length > 0) {
      const current = stack.pop()!;
      if (current === upstreamId) return true;
      if (visited.has(current)) continue;
      visited.add(current);

      const deps = db.prepare(
        `SELECT downstream_id FROM task_dependencies WHERE upstream_id=?`
      ).all(current) as Array<{ downstream_id: string }>;

      for (const d of deps) {
        stack.push(d.downstream_id);
      }
    }
    return false;
  }

  satisfyDownstream(upstreamId: string): number {
    const result = db.prepare(
      `UPDATE task_dependencies SET status='satisfied'
       WHERE upstream_id=? AND status='pending' AND dep_type='finish_to_start'`
    ).run(upstreamId);
    return result.changes;
  }

  // ─── Phase 4b: 质量门实现 ────────────────────────────────

  addQualityGate(gate: Omit<QualityGate, "id"> & { id?: string }): QualityGate {
    const id = gate.id ?? `qg_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
    const fullGate: QualityGate = { ...gate, id };

    db.prepare(
      `INSERT INTO quality_gates (id, pipeline_id, gate_name, criteria, after_order, status, evaluator_id, result, evaluated_at, created_at)
       VALUES (@id, @pipeline_id, @gate_name, @criteria, @after_order, @status, @evaluator_id, @result, @evaluated_at, @created_at)`
    ).run(fullGate);

    return fullGate;
  }

  updateQualityGateStatus(gateId: string, status: GateStatus, evaluatorId: string, result?: string): void {
    const now = Date.now();
    db.prepare(
      `UPDATE quality_gates SET status=?, evaluator_id=?, result=?, evaluated_at=? WHERE id=?`
    ).run(status, evaluatorId, result ?? null, now, gateId);
  }

  listGatesByPipeline(pipelineId: string): QualityGate[] {
    return db.prepare(
      `SELECT * FROM quality_gates WHERE pipeline_id=? ORDER BY after_order ASC`
    ).all(pipelineId) as QualityGate[];
  }
}

// ─── ConsumedLogRepo ──────────────────────────────────────────

class SqliteConsumedLogRepo implements IConsumedLogRepo {
  insert(entry: ConsumedEntry): void {
    consumedStmt.insert.run(entry);
  }

  check(agentId: string, resource: string): ConsumedEntry | undefined {
    return consumedStmt.check.get(agentId, resource) as ConsumedEntry | undefined;
  }

  listByAgent(agentId: string, limit = 50): ConsumedEntry[] {
    return consumedStmt.listByAgent.all(agentId, limit) as ConsumedEntry[];
  }
}

// ─── 单例导出 ──────────────────────────────────────────────────

export const messageRepo: IMessageRepo     = new SqliteMessageRepo();
export const taskRepo:    ITaskRepo        = new SqliteTaskRepo();
export const consumedRepo: IConsumedLogRepo = new SqliteConsumedLogRepo();
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: 472kUpdated Claude CodeCodexVerifiedInstall
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: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
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 availableStars: 322kUpdated Claude CodeCodexVerifiedInstall