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/tokenizer.ts
View on GitHub/**
* tokenizer.ts — 中文 N-gram 分词器 (Phase 2 Day 3)
*
* 解决 FTS5 默认 tokenizer 不支持中文分词的问题。
* 方案:在写入时对中文内容预分词(bigram + trigram),
* 搜索时对查询词也做相同处理,配合精确短语匹配。
*
* 无外部依赖,纯算法实现。
*/
/**
* 生成 N-gram 分词结果
* @param text 输入文本(中文/英文混合)
* @param n gram 长度(2=bigram, 3=trigram)
* @returns N-gram tokens 数组
*/
export function ngram(text: string, n: number): string[] {
const tokens: string[] = [];
for (let i = 0; i <= text.length - n; i++) {
tokens.push(text.slice(i, i + n));
}
return tokens;
}
/**
* 对混合文本分词:英文按单词拆分并小写化,中文按 bigram+trigram 拆分
* @param text 输入文本
* @returns 去重后的 tokens 数组
*/
function segment(text: string): string[] {
const parts: string[] = [];
// 按英文/数字块和中文块分割
const segments = text.split(/([a-zA-Z0-9_]+)/);
for (const seg of segments) {
if (/^[a-zA-Z0-9_]+$/.test(seg)) {
// 英文/数字:整词 + 小写化
parts.push(seg.toLowerCase());
} else if (seg.trim()) {
// 中文:bigram + trigram
for (let n = 2; n <= 3; n++) {
parts.push(...ngram(seg, n));
}
}
}
return [...new Set(parts)];
}
/**
* 为记忆内容构建 FTS tokens(写入时调用)
* 将 title + content 分词后的 tokens 拼接为空格分隔的字符串,
* 存入 memories.fts_tokens 列供 FTS5 索引。
*
* @param title 记忆标题
* @param content 记忆内容
* @returns 空格分隔的 tokens 字符串
*/
export function buildFtsTokens(title: string | null, content: string): string {
const text = (title || "") + " " + content;
return segment(text).join(" ");
}
/**
* 将搜索 query 转换为 FTS5 MATCH 表达式(搜索时调用)
*
* 策略:精确短语匹配 + bigram OR 搜索
* 例如 "机器学习" → '"机器学习" OR 机机 OR 机器 OR 器学 OR 学习'
*
* @param query 用户搜索关键词
* @returns FTS5 MATCH 表达式
*/
export function buildSearchQuery(query: string): string {
if (!query.trim()) return "";
// 清理 FTS5 特殊字符(保留双引号、字母数字、中文、空格)
const cleaned = query.replace(/[!*()&|:{}^~\\]/g, " ").trim();
const segments = cleaned.split(/([a-zA-Z0-9_]+)/);
const parts: string[] = [];
for (const seg of segments) {
if (/^[a-zA-Z0-9_]+$/.test(seg)) {
// 英文/数字:精确匹配 + 前缀通配
parts.push(seg.toLowerCase());
parts.push(seg.toLowerCase() + "*");
} else if (seg.trim()) {
// 中文:精确短语(带引号)+ bigram OR
// 过滤掉纯符号 token
const stripped = seg.replace(/[\s#]+/g, "").trim();
if (stripped.length >= 2) {
parts.push('"' + stripped.replace(/"/g, '""') + '"');
}
// 仅对包含中文的 segment 生成 bigram
if (/[\u4e00-\u9fff]/.test(seg)) {
const chineseOnly = seg.replace(/[^\u4e00-\u9fff]/g, "");
if (chineseOnly.length >= 2) {
parts.push(...ngram(chineseOnly, 2));
}
}
}
}
const result = [...new Set(parts)].join(" OR ");
return result;
}
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 |