feat(rag): replace LiteParse flows with LightRAG provider

This commit is contained in:
lix-2026
2026-06-07 01:10:31 +08:00
parent f46c2fb5d0
commit 1f25364374
40 changed files with 7232 additions and 2350 deletions
+57 -112
View File
@@ -44,11 +44,9 @@ function isWriteMnoteTool(toolName) {
'mnote.context.snapshot',
'mnote.context.resolve_target',
'mnote.context.read_current_page',
'mnote.evidence.search',
'mnote.evidence.read',
'mnote.evidence.open',
'mnote.index.status',
'mnote.index.refresh',
'mnote.knowledge_rag.status',
'mnote.knowledge_rag.query',
'mnote.knowledge_rag.open_reference',
'mnote.doc.fetch',
'mnote.page.get',
'mnote.block.fetch',
@@ -248,8 +246,11 @@ if (process.env.MNOTE_REASONIX_ACP_SELFTEST === '1') {
if (!promptWithEnvelope.includes('native file tools')) {
throw new Error('selftest expected prompt to instruct native file tools');
}
if (!promptWithEnvelope.includes('Do not use MNote doc/page write tools for ordinary local Markdown edits.')) {
throw new Error('selftest expected prompt to forbid MNote doc/page write tools for ordinary local Markdown edits');
}
const evidencePayload = buildMnoteToolPayload(
'mnote.evidence.search',
'mnote.knowledge_rag.query',
{ query: 'ResourceBodyToken' },
{
workspaceId: 'ws_local',
@@ -266,8 +267,8 @@ if (process.env.MNOTE_REASONIX_ACP_SELFTEST === '1') {
if (evidencePayload.rootUri !== 'file:///tmp/mnote-local') {
throw new Error('selftest expected evidence payload to inherit local root context');
}
if (isWriteMnoteTool('mnote.evidence.search')) {
throw new Error('selftest expected evidence search to be read-only');
if (isWriteMnoteTool('mnote.knowledge_rag.query')) {
throw new Error('selftest expected knowledge RAG query to be read-only');
}
const successfulEvidenceToolResult = JSON.stringify({ ok: true, error: null, result: { ok: true } });
if (toolResultStatusFromContent(successfulEvidenceToolResult) !== 'completed') {
@@ -502,12 +503,9 @@ const MNOTE_TOOL_NAMES = [
'mnote.context.snapshot',
'mnote.context.resolve_target',
'mnote.context.read_current_page',
'mnote.evidence.search',
'mnote.evidence.read',
'mnote.evidence.open',
'mnote.index.status',
'mnote.index.refresh',
'mnote.index.update_settings',
'mnote.knowledge_rag.status',
'mnote.knowledge_rag.query',
'mnote.knowledge_rag.open_reference',
];
const REASONIX_TOOL_TO_MNOTE_TOOL = {
@@ -515,12 +513,9 @@ const REASONIX_TOOL_TO_MNOTE_TOOL = {
mnote_context_snapshot: 'mnote.context.snapshot',
mnote_context_resolve_target: 'mnote.context.resolve_target',
mnote_context_read_current_page: 'mnote.context.read_current_page',
mnote_evidence_search: 'mnote.evidence.search',
mnote_evidence_read: 'mnote.evidence.read',
mnote_evidence_open: 'mnote.evidence.open',
mnote_index_status: 'mnote.index.status',
mnote_index_refresh: 'mnote.index.refresh',
mnote_index_update_settings: 'mnote.index.update_settings',
mnote_knowledge_rag_status: 'mnote.knowledge_rag.status',
mnote_knowledge_rag_query: 'mnote.knowledge_rag.query',
mnote_knowledge_rag_open_reference: 'mnote.knowledge_rag.open_reference',
};
async function callMnoteTool(toolName, args) {
@@ -602,117 +597,65 @@ tools.register({
});
tools.register({
name: 'mnote_evidence_search',
description: '搜索 MNote 本地文档和资源证据,返回 quote、locator 与 openAction。查询语言与资料语言可能不一致时,先在提示层做轻量多语关键词扩展,再用简短关键词检索。',
name: 'mnote_knowledge_rag_status',
description: '查看 LightRAG 资料库 provider 状态、dashboard 地址和 MNote source registry。',
parameters: {
type: 'object',
properties: {
query: { type: 'string', description: '要搜索的问题或关键词' },
workspaceId: { type: 'string', description: 'MNote workspace ID,可省略并使用当前上下文' },
rootUri: { type: 'string', description: 'local folder rootUri,可省略并使用当前上下文' },
targetDocumentId: { type: 'string', description: '可选,限制到当前文档' },
includeResources: { type: 'boolean', description: '是否包含附件/资源标题' },
includeOcr: { type: 'boolean', description: '是否包含 OCR/source-map 证据' },
mode: { type: 'string', enum: ['hybrid', 'tree', 'graph'], description: '检索模式' },
topK: { type: 'integer', description: '最多返回结果数' },
scope: { type: 'object', description: '完整 EvidenceSearchScope,提供时优先使用' },
},
},
readOnly: true,
fn: async (args) => callMnoteTool(REASONIX_TOOL_TO_MNOTE_TOOL.mnote_knowledge_rag_status, args),
parallelSafe: true,
});
tools.register({
name: 'mnote_knowledge_rag_query',
description: '向 LightRAG 资料库提问,返回 answer、provider 原始结果和经 MNote registry 映射后的 references。回答必须引用返回来源。',
parameters: {
type: 'object',
properties: {
query: { type: 'string', description: '资料库问题' },
question: { type: 'string', description: '资料库问题,等价于 query' },
workspaceId: { type: 'string', description: 'MNote workspace ID,可省略并使用当前上下文' },
rootUri: { type: 'string', description: 'local folder rootUri,可省略并使用当前上下文' },
mode: { type: 'string', enum: ['mix', 'local', 'global', 'naive', 'bypass'], description: 'LightRAG query mode; use mix by default for knowledge-library questions' },
topK: { type: 'integer', description: 'LightRAG top_k' },
chunkTopK: { type: 'integer', description: 'LightRAG chunk_top_k' },
includeChunkContent: { type: 'boolean', description: '是否在 reference 中包含 chunk 内容' },
sourcePaths: {
type: 'array',
items: { type: 'string' },
description: '可选 MNote workspace 相对路径范围;可传文件或目录,返回 references 会限制在这些来源内。',
},
},
required: ['query'],
},
readOnly: true,
fn: async (args) => callMnoteTool(REASONIX_TOOL_TO_MNOTE_TOOL.mnote_evidence_search, args),
parallelSafe: true,
});
tools.register({
name: 'mnote_evidence_read',
description: '按 EvidenceLocator 读取原文证据及周边上下文。',
parameters: {
type: 'object',
properties: {
locator: { type: 'object', description: 'mnote_evidence_search 返回的 source/locator' },
context: {
type: 'object',
properties: {
beforeBlocks: { type: 'integer' },
afterBlocks: { type: 'integer' },
includeSectionSummary: { type: 'boolean' },
},
},
},
required: ['locator'],
},
readOnly: true,
fn: async (args) => callMnoteTool(REASONIX_TOOL_TO_MNOTE_TOOL.mnote_evidence_read, args),
parallelSafe: true,
});
tools.register({
name: 'mnote_evidence_open',
description: '把 EvidenceLocator 归一化为 MNote 可执行的打开/定位动作。',
parameters: {
type: 'object',
properties: {
locator: { type: 'object', description: 'mnote_evidence_search 返回的 source/locator' },
},
required: ['locator'],
},
readOnly: true,
fn: async (args) => callMnoteTool(REASONIX_TOOL_TO_MNOTE_TOOL.mnote_evidence_open, args),
parallelSafe: true,
});
tools.register({
name: 'mnote_index_status',
description: '查看 MNote 本地索引范围、缓存文件状态、文档数和 evidence block 数。',
parameters: {
type: 'object',
properties: {
workspaceId: { type: 'string', description: 'MNote workspace ID,可省略并使用当前上下文' },
rootUri: { type: 'string', description: 'local folder rootUri,可省略并使用当前上下文' },
},
},
readOnly: true,
fn: async (args) => callMnoteTool(REASONIX_TOOL_TO_MNOTE_TOOL.mnote_index_status, args),
parallelSafe: true,
});
tools.register({
name: 'mnote_index_refresh',
description: '按当前有效范围重建 MNote 本地搜索/evidence 缓存,不修改 Markdown 正文。',
parameters: {
type: 'object',
properties: {
workspaceId: { type: 'string', description: 'MNote workspace ID,可省略并使用当前上下文' },
rootUri: { type: 'string', description: 'local folder rootUri,可省略并使用当前上下文' },
},
},
readOnly: true,
fn: async (args) => callMnoteTool(REASONIX_TOOL_TO_MNOTE_TOOL.mnote_index_refresh, args),
fn: async (args) => callMnoteTool(REASONIX_TOOL_TO_MNOTE_TOOL.mnote_knowledge_rag_query, args),
parallelSafe: false,
});
tools.register({
name: 'mnote_index_update_settings',
description: '新增或删除 MNote 本地索引范围;includePaths 为空表示删除当前用户范围。',
name: 'mnote_knowledge_rag_open_reference',
description: '把 LightRAG reference 映射为 MNote 可打开的本地 resource action;没有 registry 命中时返回定位降级。',
parameters: {
type: 'object',
properties: {
reference: { type: 'object', description: 'mnote_knowledge_rag_query 返回的 reference' },
referenceId: { type: 'string' },
filePath: { type: 'string', description: 'LightRAG reference file_path' },
chunkId: { type: 'string' },
workspaceId: { type: 'string', description: 'MNote workspace ID,可省略并使用当前上下文' },
rootUri: { type: 'string', description: 'local folder rootUri,可省略并使用当前上下文' },
includePaths: { type: 'array', items: { type: 'string' }, description: 'root 内相对路径列表,空数组表示删除范围' },
scheduleMode: { type: 'string', enum: ['manual', 'daily', 'weekly', 'monthly'], description: '刷新计划' },
scheduleTime: { type: 'string', description: 'HH:mm' },
scheduleDate: { type: 'string', description: '可选日期' },
runOnChange: { type: 'boolean', description: '文件变化时是否自动刷新' },
dryRun: { type: 'boolean', description: 'true 只返回计划;false 写入设置并刷新索引' },
idempotencyKey: { type: 'string', description: '写入幂等键' },
},
required: ['includePaths', 'dryRun', 'idempotencyKey'],
required: ['filePath'],
},
readOnly: false,
fn: async (args) => callMnoteTool(REASONIX_TOOL_TO_MNOTE_TOOL.mnote_index_update_settings, args),
parallelSafe: false,
readOnly: true,
fn: async (args) => callMnoteTool(REASONIX_TOOL_TO_MNOTE_TOOL.mnote_knowledge_rag_open_reference, args),
parallelSafe: true,
});
// ── Session Store ────────────────────────────────────
@@ -751,10 +694,12 @@ onRequest('session/new', async (params) => {
'You are a helpful AI assistant inside MNote.',
'MNote capabilities are optional tools. Use them only when the user task requires MNote page, file, folder, attachment, or workspace context.',
'Use your native agent file tools for local file reads and edits inside allowed roots; MNote tools only provide target and context metadata.',
'Do not use MNote doc/page write tools for ordinary local Markdown edits.',
'Final answers must be direct user-facing answers. Do not narrate tool use, search steps, plans, or internal process; do not say phrases like "let me search", "I found", "I will check", or "让我".',
'<available-skills>',
'Use mnote_skill_read to load the full content of any skill listed by the current prompt capabilities.',
'- mnote-current-page — Read the current MNote Markdown page when the task needs page content.',
'- mnote-local-index — Search local documents with clickable evidence locators and manage local index scopes. When the query language may differ from the corpus language, infer likely corpus terms from filenames/titles/domain context, expand 2-6 concise multilingual keywords, and call mnote_evidence_search with the best short keyword queries. Do not assume the answer language from the corpus; answer in the user language and cite only retrieved evidence.',
'- mnote-knowledge-rag — Ask the LightRAG-backed knowledge library across books, papers, PDFs, Office files, images, and attachments. Use mnote_knowledge_rag_query for knowledge-library questions and cite only returned references; if locatorDegraded is true, say the source location is degraded rather than inventing page/bbox.',
'- mnote-local-file — Resolve MNote targets and then use native file tools inside allowed roots.',
'- mnote-chat-only — Reply conversationally without MNote file/page tools.',
'</available-skills>',