Commit c945123b by 黄南光

知识库引入mem0,权限系统改进优化

1 parent d96f279e
Showing 396 changed files with 382 additions and 61 deletions
...@@ -67,3 +67,93 @@ rg: docs: 系统找不到指定的文件。 (os error 2) ...@@ -67,3 +67,93 @@ rg: docs: 系统找不到指定的文件。 (os error 2)
- **Notes**: 后续调查不再假设 `docs` 已存在。 - **Notes**: 后续调查不再假设 `docs` 已存在。
--- ---
## [ERR-20260807-001] apply_patch
**Logged**: 2026-08-07T00:00:00+08:00
**Priority**: medium
**Status**: pending
**Area**: docs
### Summary
Windows workspace 中 apply_patch 可以新建文件,但随后更新同一文件时被沙箱 deny-read ACL 拒绝。
### Error
apply_patch verification failed: fs sandbox helper failed; windows sandbox helper_unknown_error; apply deny-read ACLs.
### Context
- 操作:更新刚由 apply_patch 新建的幻灯片 analysis.md。
- 环境:Codex Desktop,Windows,workspace-write。
- 文件位于允许写入的仓库目录,外部只读 PowerShell 可以读取。
### Suggested Fix
检查 Windows sandbox helper 对新建文件的 ACL 继承;修复前在 apply_patch 失败后使用经过批准、目标路径明确的 PowerShell 原子替换作为受限回退。
### Metadata
- Reproducible: yes
- Related Files: myDocs/wiki_knowledge版本迭代记录/slide-deck/wiki-version-evolution/analysis.md
---
## [ERR-20260811-001] codegraph-cli-unavailable
**Logged**: 2026-08-11T16:00:00+08:00
**Priority**: medium
**Status**: pending
**Area**: docs
### Summary
仓库存在 `.codegraph/` 索引目录,但当前 PowerShell 环境未注册 `codegraph` CLI,且可用工具列表中没有 CodeGraph MCP。
### Error
```text
codegraph : The term 'codegraph' is not recognized as the name of a cmdlet, function, script file, or operable program.
```
### Context
- 操作:按项目 AGENTS.md 要求运行 `codegraph status`。
- 环境:Codex Desktop、Windows、PowerShell,仓库根目录为 `D:\code\wiki_knowledge`。
- 已确认 `.codegraph/` 目录存在;当前会话既没有 CLI,也没有可延迟加载的 CodeGraph 工具。
### Suggested Fix
将 CodeGraph CLI 加入当前环境 PATH,或为 Codex Desktop 配置 `codegraph_explore` MCP;在恢复前使用 Git 历史、精确文件读取和测试进行降级分析,并在交付中标注证据来源。
### Metadata
- Reproducible: yes
- Related Files: .codegraph/, AGENTS.md
---
## [ERR-20260811-002] project-python-path-and-conda-run-encoding
**Logged**: 2026-08-11T16:20:00+08:00
**Priority**: medium
**Status**: resolved
**Area**: config
### Summary
AGENTS.md 标注的 Python 路径已失效;`conda run` 在包含中文路径/文件名的命令输出上还会触发 GBK 编码异常。
### Error
```text
D:\software_install\anaconda\envs\wiki_knowledge\python.exe not found
UnicodeEncodeError: 'gbk' codec can't encode character ...
```
### Context
- 项目实际环境位于 `D:\software_install\anaconda_env\envs\wiki_knowledge\python.exe`。
- `conda run -n wiki_knowledge python --version` 可运行,但复杂中文输出可能被 conda 的 GBK 包装层破坏。
- 当前仓库测试清单可由实际解释器直接收集,共 158 项。
### Suggested Fix
更新 AGENTS.md 的解释器路径;Windows 中文项目优先直接调用 env 下的 python.exe,避免经 `conda run` 转发标准输出。
### Metadata
- Reproducible: yes
- Related Files: AGENTS.md
### Resolution
- **Resolved**: 2026-08-11T16:22:00+08:00
- **Notes**: 已定位并验证实际解释器路径;后续基准脚本直接使用该解释器。
---
...@@ -5,3 +5,53 @@ Corrections, insights, and knowledge gaps captured during development. ...@@ -5,3 +5,53 @@ Corrections, insights, and knowledge gaps captured during development.
**Categories**: correction | insight | knowledge_gap | best_practice **Categories**: correction | insight | knowledge_gap | best_practice
--- ---
## [LRN-20260807-001] correction
**Logged**: 2026-08-07T17:20:00+08:00
**Priority**: high
**Status**: pending
**Area**: docs
### Summary
大型领导汇报不应机械追求页数和逐版本铺陈;视觉与内容必须先满足用户明确偏好。
### Details
用户否定蓝色 Corporate 96 页方案,要求改为橙黄明亮、现代简约、约 50 页,并删除无关页面。之前虽然内容事实正确,但叙事拆分过细、页面数量驱动了无关过渡页,视觉显得老气。
### Suggested Action
后续大型 PPT 先锁定视觉禁忌和管理层信息优先级;以“核心结论、关键架构、量化证据、治理价值、决策请求”为主干,版本只按演进阶段聚合,不为每个技术点单独占页。
### Metadata
- Source: user_feedback
- Related Files: myDocs/wiki_knowledge版本迭代记录/slide-deck/wiki-version-evolution
- Tags: slides, executive-report, visual-style, content-density
---
## [LRN-20260811-002] correction
**Logged**: 2026-08-11T16:35:00+08:00
**Priority**: high
**Status**: resolved
**Area**: config
### Summary
项目实际 Python 解释器位于 `D:\software_install\anaconda_env\envs\wiki_knowledge\python.exe`,不是 AGENTS.md 中旧的 anaconda 路径。
### Details
用户明确给出新路径;本轮已通过 `--version` 验证为 Python 3.12.13。直接调用该解释器可避免 `conda run` 对中文路径和输出的 GBK 编码包装问题。
### Suggested Action
后续测试、基准采样和报告生成统一直接调用该解释器;如需更新项目长期说明,应在用户允许时修正 AGENTS.md。
### Metadata
- Source: user_feedback
- Related Files: AGENTS.md
- Tags: python, conda, windows, encoding
### Resolution
- **Resolved**: 2026-08-11T16:36:00+08:00
- **Notes**: 已验证并采用用户提供的解释器路径。
---
<svg width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M9.85748 0.741031C9.74731 0.410542 9.27985 0.410541 9.16968 0.741031L9.04323 1.1204C8.90014 1.54964 8.56332 1.88647 8.13407 2.02955L7.7547 2.15601C7.42421 2.26617 7.42421 2.73364 7.7547 2.84381L8.13407 2.97026C8.56332 3.11334 8.90014 3.45017 9.04323 3.87942L9.16968 4.25878C9.27985 4.58927 9.74731 4.58927 9.85748 4.25878L9.98393 3.87942C10.127 3.45017 10.4638 3.11334 10.8931 2.97026L11.2725 2.84381C11.6029 2.73364 11.6029 2.26617 11.2725 2.15601L10.8931 2.02955C10.4638 1.88647 10.127 1.54964 9.98393 1.1204L9.85748 0.741031ZM5.70128 2.48215C5.48096 1.82117 4.54602 1.82118 4.32569 2.48215L3.94778 3.61589C3.66162 4.47438 2.98796 5.14804 2.12947 5.4342L0.995735 5.81211C0.334753 6.03244 0.334757 6.96738 0.995735 7.1877L2.12947 7.56562C2.98796 7.85178 3.66162 8.52543 3.94778 9.38392L4.32569 10.5177C4.54602 11.1786 5.48096 11.1786 5.70128 10.5177L6.0792 9.38392C6.36536 8.52543 7.03901 7.85178 7.8975 7.56562L9.03124 7.1877C9.69222 6.96738 9.69222 6.03244 9.03124 5.81211L7.8975 5.4342C7.03901 5.14804 6.36536 4.47438 6.0792 3.61589L5.70128 2.48215Z" fill="url(#paint0_linear_4063_21546)"/>
<defs>
<linearGradient id="paint0_linear_4063_21546" x1="-1.44911" y1="0.745343" x2="12.3604" y2="11.4423" gradientUnits="userSpaceOnUse">
<stop stop-color="#7B4DFF"/>
<stop offset="1" stop-color="#33ADFF"/>
</linearGradient>
</defs>
</svg>
<svg width="28" height="28" viewBox="0 0 28 28" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect width="28" height="28" rx="14" fill="#1A2029"/>
<path d="M18.3116 7.51889C19.5622 7.11018 20.7472 8.29519 20.3385 9.54577L16.5721 21.0703C16.1291 22.4257 14.2715 22.5758 13.6167 21.3089L11.2083 16.649L6.54843 14.2406C5.28162 13.5859 5.43162 11.7283 6.78708 11.2853L18.3116 7.51889Z" fill="#ffffff"/>
<path d="M11.2083 16.649L13.6167 21.3089C14.2715 22.5758 16.1291 22.4257 16.5721 21.0703L20.3385 9.54577C20.7472 8.29519 19.5622 7.11018 18.3116 7.51889L6.78708 11.2853C5.43162 11.7283 5.28162 13.5859 6.54843 14.2406L11.2083 16.649ZM11.2083 16.649L13.7673 14.09" stroke="#1A2029" stroke-width="1.78022" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
{
"app_description": {
"message": "Плащания в уеб магазина на Chrome"
},
"app_name": {
"message": "Плащания в уеб магазина на Chrome"
},
"craw_app_unavailable": {
"message": "Понастоящем няма достъп до приложението."
},
"craw_connect_to_network": {
"message": "Моля, свържете се с мрежа."
},
"iap_unavailable": {
"message": "Понастоящем няма достъп до вградената система за плащания."
},
"jwt_retrieve_failed": {
"message": "The transaction could not be completed."
},
"please_sign_in": {
"message": "Моля, влезте в Chrome."
}
}
{
"app_description": {
"message": "Mga Pagbabayad sa Chrome Web Store"
},
"app_name": {
"message": "Mga Pagbabayad sa Chrome Web Store"
},
"craw_app_unavailable": {
"message": "Kasalukuyang hindi available ang app."
},
"craw_connect_to_network": {
"message": "Mangyaring kumonekta sa isang network."
},
"iap_unavailable": {
"message": "Kasalukuyang hindi available ang Mga Pagbabayad na In-App."
},
"jwt_retrieve_failed": {
"message": "The transaction could not be completed."
},
"please_sign_in": {
"message": "Mangyaring mag-sign in sa Chrome."
}
}
{
"app_description": {
"message": "Plačila v spletni trgovini Chrome"
},
"app_name": {
"message": "Plačila v spletni trgovini Chrome"
},
"craw_app_unavailable": {
"message": "Aplikacija trenutno ni na voljo."
},
"craw_connect_to_network": {
"message": "Povežite se z omrežjem."
},
"iap_unavailable": {
"message": "Plačila v aplikacijah trenutno niso na voljo."
},
"jwt_retrieve_failed": {
"message": "The transaction could not be completed."
},
"please_sign_in": {
"message": "Prijavite se v Chrome."
}
}
No preview for this file type
2026/08/12-16:24:12.459 4a80 Creating DB D:\code\wiki_knowledge\.tmp\chrome_final_pdf_20260812\Default\Local Storage\leveldb since it was missing.
2026/08/12-16:24:12.581 4a80 Reusing MANIFEST D:\code\wiki_knowledge\.tmp\chrome_final_pdf_20260812\Default\Local Storage\leveldb/MANIFEST-000001
{"preferred_apps":[],"version":1}
\ No newline at end of file \ No newline at end of file
/*!
Copyright (c) 2018 Jed Watson.
Licensed under the MIT License (MIT), see
http://jedwatson.github.io/classnames
*/
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
/**
* @license
* Lodash <https://lodash.com/>
* Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
* Released under MIT license <https://lodash.com/license>
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
*/
/**
* @license React
* react-dom.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* @license React
* react-is.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* @license React
* react.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* @license React
* scheduler.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" fill="none" viewBox="0 0 24 24">
<path fill="currentColor" fill-rule="evenodd"
d="M9.035 15.956a1.29 1.29 0 0 0 1.821-.004l6.911-6.911a3.15 3.15 0 0 0 0-4.457l-.034-.034a3.15 3.15 0 0 0-4.456 0l-7.235 7.234a5.031 5.031 0 0 0 7.115 7.115l6.577-6.577a1.035 1.035 0 0 1 1.463 1.464l-6.576 6.577A7.1 7.1 0 0 1 4.579 10.32l7.235-7.234a5.22 5.22 0 0 1 7.382 0l.034.034a5.22 5.22 0 0 1 0 7.383l-6.91 6.91a3.36 3.36 0 0 1-4.741.012l-.006-.005-.012-.011a3.346 3.346 0 0 1 0-4.732L12.76 7.48a1.035 1.035 0 0 1 1.464 1.463l-5.198 5.198a1.277 1.277 0 0 0 0 1.805z"
clip-rule="evenodd"></path>
</svg>
\ No newline at end of file \ No newline at end of file
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M4.5 4.03749C4.5 3.99728 4.52792 3.96954 4.56007 3.96521C5.63969 3.81967 8.21907 3.5 10 3.5C11.7809 3.5 14.3603 3.81967 15.4399 3.96521C15.4721 3.96954 15.5 3.99728 15.5 4.03749C15.5 4.08051 15.4651 4.11538 15.4221 4.11538H15.25C14.5596 4.11538 14 4.67503 14 5.36538V6.21983C14 7.32424 13.3295 8.31807 12.3055 8.73163L12.0774 8.82372C10.9831 9.26567 10.8995 10.783 11.9386 11.3425L12.7145 11.7603C13.5063 12.1866 14 13.0132 14 13.9125V14.6346C14 15.325 14.5596 15.8846 15.25 15.8846H15.4221C15.4651 15.8846 15.5 15.9195 15.5 15.9625C15.5 16.0027 15.4721 16.0305 15.4399 16.0348C14.3603 16.1803 11.7809 16.5 10 16.5C8.21907 16.5 5.63969 16.1803 4.56007 16.0348C4.52792 16.0305 4.5 16.0027 4.5 15.9625C4.5 15.9195 4.53487 15.8846 4.57789 15.8846H4.75C5.44036 15.8846 6 15.325 6 14.6346V13.9125C6 13.0132 6.49373 12.1866 7.28546 11.7603L8.06138 11.3425C9.10055 10.783 9.01692 9.26567 7.92255 8.82372L7.73532 9.28734L7.92255 8.82372L7.69451 8.73163C6.67046 8.31807 6 7.32424 6 6.21983V5.36538C6 4.67503 5.44036 4.11538 4.75 4.11538H4.57789C4.53487 4.11538 4.5 4.08051 4.5 4.03749Z"
stroke="currentColor" />
</svg>
\ No newline at end of file \ No newline at end of file
Google Chrome settings and storage represent user-selected preferences and information and MUST not be extracted, overwritten or modified except through Google Chrome defined APIs.
\ No newline at end of file \ No newline at end of file
2026/08/12-16:23:03.759 1624 Creating DB D:\code\wiki_knowledge\.tmp\chrome_print_20260812_1614\Default\Storage\ext\nmmhkkegccagdldgiimedpiccmgmieda\def\Session Storage since it was missing.
2026/08/12-16:23:03.850 1624 Reusing MANIFEST D:\code\wiki_knowledge\.tmp\chrome_print_20260812_1614\Default\Storage\ext\nmmhkkegccagdldgiimedpiccmgmieda\def\Session Storage/MANIFEST-000001
{"user_experience_metrics.stability.exited_cleanly":true,"variations_crash_streak":0}
\ No newline at end of file \ No newline at end of file
...@@ -37,23 +37,32 @@ def _env_list(name: str, default: str) -> list[str]: ...@@ -37,23 +37,32 @@ def _env_list(name: str, default: str) -> list[str]:
# config.py 在项目根目录,故根目录即当前文件所在目录 # config.py 在项目根目录,故根目录即当前文件所在目录
BASE_DIR = os.path.abspath(os.path.dirname(__file__)) BASE_DIR = os.path.abspath(os.path.dirname(__file__))
RAW_DIR = os.path.join(BASE_DIR, "ware", "raw") # 原始文档(base 公共基础库) # 统一存储布局:知识库按类型分目录落 ware/kb/ 下——
WIKI_DIR = os.path.join(BASE_DIR, "ware", "wiki") # 生成的 Wiki 页面(base 公共基础库) # 基础库(base) → ware/kb/base/<kb_id>/{raw,wiki},其中内置公共基础库固定 ware/kb/base/main;
METADATA_DIR = os.path.join(WIKI_DIR, "metadata") # 文件处理元数据(耗时、Token 等) # 部门库(dept) → ware/kb/dept/<kb_id>/{raw,wiki}。
SKILLS_DIR = os.path.join(BASE_DIR, "skills") # 内置/随仓库分发的 Agent 技能 # 目录名一律用**库自身 UUID**(wiki_kb_info.id,不是绑定部门的 id):纯 ASCII、Linux 安全、
# 彼此隔离,且不随部门绑定关系变化而失效;显示名存 wiki_kb_info.kb_name。
# 物理路径只由 wiki_kb_info.root_dir 决定,见 kb_paths.py。
KB_ROOT_DIR = os.path.join(BASE_DIR, "ware", "kb") # 所有知识库的物理根
KB_BASE_ROOT = os.path.join(KB_ROOT_DIR, "base") # 基础库命名空间根
KB_DEPT_ROOT = os.path.join(KB_ROOT_DIR, "dept") # 部门库命名空间根
COMM_KB_ROOT = os.path.join(KB_BASE_ROOT, "main") # 内置公共基础库命名空间根
RAW_DIR = os.path.join(COMM_KB_ROOT, "raw") # 原始文档(内置公共基础库)
WIKI_DIR = os.path.join(COMM_KB_ROOT, "wiki") # 生成的 Wiki 页面(内置公共基础库)
METADATA_DIR = os.path.join(WIKI_DIR, "metadata") # 文件处理元数据(耗时、Token 等)
SKILLS_DIR = os.path.join(BASE_DIR, "skills") # 内置/随仓库分发的 Agent 技能
INTERMEDIATES_DIR = os.path.join(BASE_DIR, "ware", "intermediates") # 中间产物 INTERMEDIATES_DIR = os.path.join(BASE_DIR, "ware", "intermediates") # 中间产物
VLM_MD_INTERMEDIATES_DIR = os.path.join(INTERMEDIATES_DIR, "pdfVL2md") # VLM 解析 PDF/PPT 的中间 MD VLM_MD_INTERMEDIATES_DIR = os.path.join(INTERMEDIATES_DIR, "pdfVL2md") # VLM 解析 PDF/PPT 的中间 MD
# 多知识库命名空间:部门库落 ware/kb/dept/<dept_id>/{raw,wiki},以部门 UUID 作目录名, # 摄入轨迹与 Office 预览 PDF(集中到 config,消除散落硬编码)
# 纯 ASCII、Linux 安全、天然不撞名(不同中心下同名部门也不冲突),显示名存 wiki_kb_info.kb_name。 INGEST_TRACE_DIR = os.path.join(BASE_DIR, "ware", "ingest_trace") # 摄入 Agent 轨迹留痕
KB_ROOT_DIR = os.path.join(BASE_DIR, "ware", "kb") # 非 base 库的物理根 OFFICE_PREVIEW_PDF_DIR = os.path.join(BASE_DIR, "ware", "preview", "pdf") # PPT/PPTX 预览 PDF 缓存
KB_DEPT_ROOT_DIR = os.path.join(KB_ROOT_DIR, "dept") # 部门库根
# 管理员上传的技能落盘目录(与内置 SKILLS_DIR 分离,便于隔离/清理/日志) # 管理员上传的技能落盘目录(与内置 SKILLS_DIR 分离,便于隔离/清理/日志)
WARE_SKILLS_DIR = os.path.join(BASE_DIR, "ware", "skills") WARE_SKILLS_DIR = os.path.join(BASE_DIR, "ware", "skills")
# 确保必要目录存在 # 确保必要目录存在
for _d in (RAW_DIR, WIKI_DIR, METADATA_DIR, VLM_MD_INTERMEDIATES_DIR, KB_DEPT_ROOT_DIR, WARE_SKILLS_DIR): for _d in (RAW_DIR, WIKI_DIR, METADATA_DIR, VLM_MD_INTERMEDIATES_DIR, KB_ROOT_DIR, KB_BASE_ROOT, KB_DEPT_ROOT, WARE_SKILLS_DIR):
os.makedirs(_d, exist_ok=True) os.makedirs(_d, exist_ok=True)
...@@ -241,7 +250,7 @@ REFLECT_ON_DELETE_MIN_TURNS = int(os.environ.get("REFLECT_ON_DELETE_MIN_TURNS", ...@@ -241,7 +250,7 @@ REFLECT_ON_DELETE_MIN_TURNS = int(os.environ.get("REFLECT_ON_DELETE_MIN_TURNS",
# 沉淀使用的模型,留空则复用 QUERY_MODEL_NAME # 沉淀使用的模型,留空则复用 QUERY_MODEL_NAME
REFLECT_MODEL_NAME = os.environ.get("REFLECT_MODEL_NAME") or QUERY_MODEL_NAME REFLECT_MODEL_NAME = os.environ.get("REFLECT_MODEL_NAME") or QUERY_MODEL_NAME
# 长期记忆后端:db=存 wiki_user_profiles.agent_md(本轮);mem0=外部记忆组件(预留) # 长期记忆后端:db=存 wiki_user_profiles.long_mem_core_md(本轮);mem0=外部记忆组件(预留)
MEMORY_STORE_BACKEND = os.environ.get("MEMORY_STORE_BACKEND", "db").strip().lower() MEMORY_STORE_BACKEND = os.environ.get("MEMORY_STORE_BACKEND", "db").strip().lower()
# 是否给问答 Agent 挂「记忆工具」remember_user_memory:用户说「你记住…」时模型即时调用, # 是否给问答 Agent 挂「记忆工具」remember_user_memory:用户说「你记住…」时模型即时调用,
...@@ -297,9 +306,9 @@ MEM0_HISTORY_DB_PATH = os.environ.get( ...@@ -297,9 +306,9 @@ MEM0_HISTORY_DB_PATH = os.environ.get(
) )
# ---------------------------- 用户画像 ---------------------------- # ---------------------------- 用户画像 ----------------------------
# agent.md 长期记忆的长度上限(字符)。达上限时**不机械删条目**,而是调 LLM 融合汇总成高密度记忆 # 长期记忆核心摘要(long_mem_core.md)的长度上限(字符)。达上限时**不机械删条目**,而是调 LLM
# 压回上限内(见 remember._llm_compact);仅当 LLM 压缩失败/仍超限才回退机械裁剪 `_enforce_cap` 兜底。 # 融合汇总成高密度记忆压回上限内(见 remember._llm_compact);仅当 LLM 压缩失败/仍超限才回退机械裁剪兜底。
AGENT_MD_MAX_CHARS = int(os.environ.get("AGENT_MD_MAX_CHARS", "4000")) LONG_MEM_CORE_MD_MAX_CHARS = int(os.environ.get("LONG_MEM_CORE_MD_MAX_CHARS", "4000"))
# user.md 用户画像的长度上限(字符)。同上,超限走 LLM 融合汇总而非机械截断。 # user.md 用户画像的长度上限(字符)。同上,超限走 LLM 融合汇总而非机械截断。
PROFILE_MD_MAX_CHARS = int(os.environ.get("PROFILE_MD_MAX_CHARS", "4000")) PROFILE_MD_MAX_CHARS = int(os.environ.get("PROFILE_MD_MAX_CHARS", "4000"))
......
...@@ -43,7 +43,7 @@ services: ...@@ -43,7 +43,7 @@ services:
# 前端容器内 Next.js server 反代 /api 到后端的内网地址(运行时生效,改地址无需重新构建) # 前端容器内 Next.js server 反代 /api 到后端的内网地址(运行时生效,改地址无需重新构建)
- BACKEND_INTERNAL_URL=${BACKEND_INTERNAL_URL:-http://backend:8104} - BACKEND_INTERNAL_URL=${BACKEND_INTERNAL_URL:-http://backend:8104}
ports: ports:
- "3001:3000" - "53001:3000"
qdrant: qdrant:
image: qdrant/qdrant:latest image: qdrant/qdrant:latest
......
...@@ -56,14 +56,14 @@ export default function ProfilePage() { ...@@ -56,14 +56,14 @@ export default function ProfilePage() {
const startEdit = () => { const startEdit = () => {
if (!data) return; if (!data) return;
setDraft(tab === "profile" ? data.profileMdRaw : data.agentMdRaw); setDraft(tab === "profile" ? data.profileMdRaw : data.longMemCoreMdRaw);
setEditing(true); setEditing(true);
}; };
const handleSave = async () => { const handleSave = async () => {
setBusy(true); setBusy(true);
try { try {
await updateMyProfile(tab === "profile" ? { profileMd: draft } : { agentMd: draft }); await updateMyProfile(tab === "profile" ? { profileMd: draft } : { longMemCoreMd: draft });
setData(await fetchProfile()); setData(await fetchProfile());
setEditing(false); setEditing(false);
} finally { } finally {
...@@ -87,7 +87,7 @@ export default function ProfilePage() { ...@@ -87,7 +87,7 @@ export default function ProfilePage() {
} }
}; };
const content = tab === "profile" ? data?.profileMd : data?.agentMd; const content = tab === "profile" ? data?.profileMd : data?.longMemCoreMd;
return ( return (
<div className="flex-1 overflow-y-auto bg-slate-100"> <div className="flex-1 overflow-y-auto bg-slate-100">
...@@ -95,7 +95,7 @@ export default function ProfilePage() { ...@@ -95,7 +95,7 @@ export default function ProfilePage() {
<header className="mb-6"> <header className="mb-6">
<h1 className="text-lg font-bold text-slate-800">我的画像</h1> <h1 className="text-lg font-bold text-slate-800">我的画像</h1>
<p className="text-xs text-slate-500 mt-1"> <p className="text-xs text-slate-500 mt-1">
用户画像可手动编辑修正;长期记忆由系统自动沉淀(只读),如需重置可清空。 用户画像可手动编辑修正;长期记忆核心摘要由系统自动沉淀(只读),如需重置可清空。
</p> </p>
</header> </header>
...@@ -117,7 +117,7 @@ export default function ProfilePage() { ...@@ -117,7 +117,7 @@ export default function ProfilePage() {
{( {(
[ [
{ key: "profile", label: "用户画像", icon: UserRound }, { key: "profile", label: "用户画像", icon: UserRound },
{ key: "memory", label: "长期记忆", icon: Brain }, { key: "memory", label: "长期记忆核心摘要", icon: Brain },
] as const ] as const
).map(({ key, label, icon: Icon }) => ( ).map(({ key, label, icon: Icon }) => (
<button <button
...@@ -199,7 +199,7 @@ export default function ProfilePage() { ...@@ -199,7 +199,7 @@ export default function ProfilePage() {
value={draft} value={draft}
onChange={(e) => setDraft(e.target.value)} onChange={(e) => setDraft(e.target.value)}
spellCheck={false} spellCheck={false}
placeholder={tab === "profile" ? "用户画像(markdown)" : "长期记忆(markdown)"} placeholder={tab === "profile" ? "用户画像(markdown)" : "长期记忆核心摘要(markdown)"}
className="flex-1 min-h-[320px] w-full resize-none font-mono text-xs leading-relaxed text-slate-700 bg-slate-50 border border-slate-200 rounded-lg p-3 outline-none focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20 transition" className="flex-1 min-h-[320px] w-full resize-none font-mono text-xs leading-relaxed text-slate-700 bg-slate-50 border border-slate-200 rounded-lg p-3 outline-none focus:border-blue-500 focus:ring-2 focus:ring-blue-500/20 transition"
/> />
) : content ? ( ) : content ? (
...@@ -212,7 +212,7 @@ export default function ProfilePage() { ...@@ -212,7 +212,7 @@ export default function ProfilePage() {
<p className="text-xs text-slate-400 leading-relaxed"> <p className="text-xs text-slate-400 leading-relaxed">
{tab === "profile" {tab === "profile"
? "用户画像尚未生成,稍后刷新即可看到;也可点「编辑」自行填写" ? "用户画像尚未生成,稍后刷新即可看到;也可点「编辑」自行填写"
: "还没有沉淀出长期记忆,多使用几次问答后会自动生成"} : "还没有沉淀出长期记忆核心摘要,多使用几次问答后会自动生成"}
</p> </p>
</div> </div>
)} )}
...@@ -228,7 +228,7 @@ export default function ProfilePage() { ...@@ -228,7 +228,7 @@ export default function ProfilePage() {
<ConfirmDialog <ConfirmDialog
open={confirmClear} open={confirmClear}
title="清空长期记忆?" title="清空长期记忆核心摘要?"
description="将清除系统对你的所有理解(关注范围、表达偏好等),会话记录不受影响。此操作不可撤销。" description="将清除系统对你的所有理解(关注范围、表达偏好等),会话记录不受影响。此操作不可撤销。"
confirmText="清空" confirmText="清空"
loading={busy} loading={busy}
......
...@@ -45,14 +45,6 @@ function subtreeVisible(node: OaSource, types: Set<string>, q: string): boolean ...@@ -45,14 +45,6 @@ function subtreeVisible(node: OaSource, types: Set<string>, q: string): boolean
if (nodeMatch(node, types, q)) return true; if (nodeMatch(node, types, q)) return true;
return (node.children ?? []).some((c) => subtreeVisible(c, types, q)); return (node.children ?? []).some((c) => subtreeVisible(c, types, q));
} }
function allIds(nodes: OaSource[], out: string[] = []): string[] {
for (const n of nodes) {
out.push(n.id);
if (n.children?.length) allIds(n.children, out);
}
return out;
}
export default function SourcePage() { export default function SourcePage() {
const [tree, setTree] = useState<OaSource[]>([]); const [tree, setTree] = useState<OaSource[]>([]);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
...@@ -91,8 +83,21 @@ export default function SourcePage() { ...@@ -91,8 +83,21 @@ export default function SourcePage() {
} }
}; };
// 筛选生效时展开全部命中分支;否则用手动展开集合 // 筛选/搜索生效时把命中分支的容器节点补进展开集(默认展开),此后用户仍可手动折叠——
const forceOpen = filterActive ? new Set(allIds(tree)) : open; // 展开态统一以 open 为准,不再靠 filterActive 强制撑开,故折叠按钮永远可用。
useEffect(() => {
if (!filterActive) return;
const ids = new Set<string>();
const walk = (nodes: OaSource[]) => {
for (const n of nodes) {
const kids = n.children ?? [];
if (kids.length > 0 && subtreeVisible(n, types, q)) ids.add(n.id);
if (kids.length) walk(kids);
}
};
walk(tree);
setOpen((prev) => new Set([...prev, ...ids]));
}, [types, q, tree, filterActive]);
return ( return (
<SysPage <SysPage
...@@ -143,7 +148,7 @@ export default function SourcePage() { ...@@ -143,7 +148,7 @@ export default function SourcePage() {
{loading ? <Spinner /> : ( {loading ? <Spinner /> : (
<ul> <ul>
{tree.map((n) => ( {tree.map((n) => (
<SourceRow key={n.id} node={n} depth={0} open={forceOpen} onToggle={toggle} types={types} q={q} /> <SourceRow key={n.id} node={n} depth={0} open={open} onToggle={toggle} types={types} q={q} />
))} ))}
</ul> </ul>
)} )}
...@@ -179,11 +184,11 @@ function SourceRow({ ...@@ -179,11 +184,11 @@ function SourceRow({
return ( return (
<li> <li>
<div <div
onClick={() => hasChild && !active && onToggle(node.id)} onClick={() => hasChild && onToggle(node.id)}
className={cn( className={cn(
GRID, GRID,
"border-b border-slate-50 px-4 py-2 text-sm", "border-b border-slate-50 px-4 py-2 text-sm",
hasChild && !active && "cursor-pointer hover:bg-blue-50/40" hasChild && "cursor-pointer hover:bg-blue-50/40"
)} )}
> >
<span className="flex items-center gap-1" style={{ paddingLeft: depth * 16 }}> <span className="flex items-center gap-1" style={{ paddingLeft: depth * 16 }}>
......
"use client"; "use client";
import { useState, useEffect, useMemo, useCallback } from "react"; import { useState, useEffect, useMemo, useCallback } from "react";
import { ChevronRight, ChevronDown, Folder, FolderOpen, FileText, Search, BookOpen, Loader2, Download, Check, Database } from "lucide-react"; import { ChevronRight, ChevronDown, Folder, FolderOpen, FileText, Search, BookOpen, Loader2, Download, Check } from "lucide-react";
import ReactMarkdown from "react-markdown"; import ReactMarkdown from "react-markdown";
import remarkGfm from "remark-gfm"; import remarkGfm from "remark-gfm";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
import FrontmatterCard from "@/components/FrontmatterCard"; import FrontmatterCard from "@/components/FrontmatterCard";
import { parseFrontmatter } from "@/lib/frontmatter"; import { parseFrontmatter } from "@/lib/frontmatter";
import { KbTreePicker } from "@/components/system/OrgTree";
import { listReadableKbs, type KbInfo } from "@/lib/auth"; import { listReadableKbs, type KbInfo } from "@/lib/auth";
const API_BASE = process.env.NEXT_PUBLIC_API_URL || "/api"; const API_BASE = process.env.NEXT_PUBLIC_API_URL || "/api";
...@@ -63,9 +64,10 @@ export default function WikiRepoPage() { ...@@ -63,9 +64,10 @@ export default function WikiRepoPage() {
const [searchQuery, setSearchQuery] = useState(""); const [searchQuery, setSearchQuery] = useState("");
const [selectedForDownload, setSelectedForDownload] = useState<Set<string>>(new Set()); const [selectedForDownload, setSelectedForDownload] = useState<Set<string>>(new Set());
const [kbs, setKbs] = useState<KbInfo[]>([]); const [kbs, setKbs] = useState<KbInfo[]>([]);
const [kbId, setKbId] = useState(""); const [kbId, setKbId] = useState(""); // 选择 token:kbId=单库 / grp:xxx=某中心
const [kbIds, setKbIds] = useState<string[]>([]); // 该 token 覆盖的库 id(选中心=其下全部库)
const kbQuery = kbId ? `kbId=${encodeURIComponent(kbId)}` : ""; const kbQuery = kbIds.length ? `kbIds=${encodeURIComponent(kbIds.join(","))}` : "";
const fetchTree = useCallback(async () => { const fetchTree = useCallback(async () => {
setIsLoadingTree(true); setIsLoadingTree(true);
...@@ -86,7 +88,7 @@ export default function WikiRepoPage() { ...@@ -86,7 +88,7 @@ export default function WikiRepoPage() {
.then((d) => { .then((d) => {
setKbs(d.items); setKbs(d.items);
const base = d.items.find((k) => k.kbType === "base") || d.items[0]; const base = d.items.find((k) => k.kbType === "base") || d.items[0];
if (base) setKbId(base.id); if (base) { setKbId(base.id); setKbIds([base.id]); }
}) })
.catch(() => {}); .catch(() => {});
}, []); }, []);
...@@ -253,21 +255,17 @@ export default function WikiRepoPage() { ...@@ -253,21 +255,17 @@ export default function WikiRepoPage() {
</button> </button>
)} )}
</div> </div>
<div className="relative"> <KbTreePicker
<Database className="w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-slate-400 pointer-events-none" /> mode="single"
<select kbs={kbs}
value={kbId} value={kbId}
onChange={(e) => setKbId(e.target.value)} onChange={(token, ids) => { setKbId(token); setKbIds(ids); }}
className="w-full pl-9 pr-3 py-2 bg-slate-100 border border-transparent rounded-xl text-sm outline-none focus:bg-white focus:ring-2 focus:ring-blue-500/20 focus:border-blue-300 transition-all appearance-none" allowGroupSelect
> placeholder="选择知识库"
{kbs.length === 0 && <option value="">公共基础库</option>} showAccessBadge
{kbs.map((k) => ( panelWidthClass="w-[26rem]"
<option key={k.id} value={k.id}> buttonClassName="flex w-full items-center gap-1.5 pl-3 pr-3 py-2 bg-slate-100 border border-transparent rounded-xl text-sm text-slate-700 outline-none hover:bg-white transition-all"
{k.kbType === "base" ? k.kbName : (k.deptPath || k.kbName)} />
</option>
))}
</select>
</div>
<div className="relative group"> <div className="relative group">
<Search className="w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-slate-400 group-focus-within:text-blue-500 transition-colors" /> <Search className="w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-slate-400 group-focus-within:text-blue-500 transition-colors" />
<input <input
......
...@@ -33,7 +33,7 @@ export default function UserProfileDialog({ ...@@ -33,7 +33,7 @@ export default function UserProfileDialog({
const [tab, setTab] = useState<TabKey>("profile"); const [tab, setTab] = useState<TabKey>("profile");
const [data, setData] = useState<AdminUserProfile | null>(null); const [data, setData] = useState<AdminUserProfile | null>(null);
const [profileMd, setProfileMd] = useState(""); const [profileMd, setProfileMd] = useState("");
const [agentMd, setAgentMd] = useState(""); const [longMemCoreMd, setLongMemCoreMd] = useState("");
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [busy, setBusy] = useState(false); const [busy, setBusy] = useState(false);
const [error, setError] = useState(""); const [error, setError] = useState("");
...@@ -46,7 +46,7 @@ export default function UserProfileDialog({ ...@@ -46,7 +46,7 @@ export default function UserProfileDialog({
const payload = await fetchUserProfile(userId); const payload = await fetchUserProfile(userId);
setData(payload); setData(payload);
setProfileMd(payload.profileMd); setProfileMd(payload.profileMd);
setAgentMd(payload.agentMd); setLongMemCoreMd(payload.longMemCoreMd);
} catch (err) { } catch (err) {
setError(err instanceof Error ? err.message : "加载失败"); setError(err instanceof Error ? err.message : "加载失败");
} finally { } finally {
...@@ -88,8 +88,8 @@ export default function UserProfileDialog({ ...@@ -88,8 +88,8 @@ export default function UserProfileDialog({
} }
}; };
const value = tab === "profile" ? profileMd : agentMd; const value = tab === "profile" ? profileMd : longMemCoreMd;
const onChange = tab === "profile" ? setProfileMd : setAgentMd; const onChange = tab === "profile" ? setProfileMd : setLongMemCoreMd;
return ( return (
<div <div
...@@ -109,7 +109,7 @@ export default function UserProfileDialog({ ...@@ -109,7 +109,7 @@ export default function UserProfileDialog({
<h3 className="text-sm font-bold text-slate-800 truncate"> <h3 className="text-sm font-bold text-slate-800 truncate">
{displayName} · 画像编辑 {displayName} · 画像编辑
</h3> </h3>
<p className="text-[11px] text-slate-400">管理员可修改用户画像;长期记忆只读(权威源在 mem0)</p> <p className="text-[11px] text-slate-400">管理员可修改用户画像;长期记忆核心摘要只读(权威源在 mem0)</p>
</div> </div>
</div> </div>
...@@ -118,7 +118,7 @@ export default function UserProfileDialog({ ...@@ -118,7 +118,7 @@ export default function UserProfileDialog({
{( {(
[ [
{ key: "profile", label: "用户画像", icon: UserRound }, { key: "profile", label: "用户画像", icon: UserRound },
{ key: "memory", label: "长期记忆", icon: Brain }, { key: "memory", label: "长期记忆核心摘要", icon: Brain },
] as const ] as const
).map(({ key, label, icon: Icon }) => ( ).map(({ key, label, icon: Icon }) => (
<button <button
...@@ -167,7 +167,7 @@ export default function UserProfileDialog({ ...@@ -167,7 +167,7 @@ export default function UserProfileDialog({
placeholder={ placeholder={
tab === "profile" tab === "profile"
? "用户画像(markdown)" ? "用户画像(markdown)"
: "长期记忆(mem0 核心集,只读)" : "长期记忆核心摘要(mem0 核心集,只读)"
} }
className={cn( className={cn(
"flex-1 min-h-[320px] w-full resize-none font-mono text-xs leading-relaxed text-slate-700 border rounded-lg p-3 outline-none transition", "flex-1 min-h-[320px] w-full resize-none font-mono text-xs leading-relaxed text-slate-700 border rounded-lg p-3 outline-none transition",
......
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!