lantern-harness 0.1.33 → 0.1.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +45 -0
- package/README.md +2 -2
- package/builtin/session/lh-nav-groups.mjs +9 -0
- package/builtin/session/mcp-client.mjs +291 -2
- package/cli/server.mjs +2 -0
- package/config/app.defaults.json +2 -1
- package/dist/500.html +72 -9
- package/dist/_astro/Base.DjXU-4S_.css +1 -0
- package/dist/_astro/{Base.astro_astro_type_script_index_0_lang.BQ1EoZdo.js → Base.astro_astro_type_script_index_0_lang.CiZNg228.js} +1 -1
- package/dist/_astro/{CaseExecBoard.CTVdi8MV.js → CaseExecBoard.DzNtPCwr.js} +1 -1
- package/dist/_astro/{CaseGenerateApp.CJK7V6iA.js → CaseGenerateApp.BvRwwxhs.js} +1 -1
- package/dist/_astro/{CasesLibrary.Don-Cnus.js → CasesLibrary.B9I31b7C.js} +1 -1
- package/dist/_astro/ChatApp.79JSgx7d.js +226 -0
- package/dist/_astro/ColumnResize.CkE59sGq.js +1 -0
- package/dist/_astro/{DashboardBoard.BaJyXPXA.js → DashboardBoard.BuyuI8WW.js} +1 -1
- package/dist/_astro/{DocsFileBrowser.D2Cff2LP.js → DocsFileBrowser.9WTBumS5.js} +1 -1
- package/dist/_astro/{DocsPager.CnXEnQqa.js → DocsPager.BS20yicJ.js} +1 -1
- package/dist/_astro/{DrawerField.C0MkN-LW.js → DrawerField.CiHAvXHQ.js} +1 -1
- package/dist/_astro/{KnowledgeLibrary.CWxIHa8I.js → KnowledgeLibrary.CQ8ULHI5.js} +1 -1
- package/dist/_astro/LifeKrTasksBoard.BWoB442i.js +1 -0
- package/dist/_astro/LifeKrTodosBoard.rDbG9XcJ.js +1 -0
- package/dist/_astro/LifeObjectivesBoard.DUDQg_RD.js +1 -0
- package/dist/_astro/LifePlanTypeSelect.BtXnXOkz.js +1 -0
- package/dist/_astro/LifeReviewsBoard.p-dp_NXl.js +5 -0
- package/dist/_astro/LifeShared.Di9sdb_T.js +3 -0
- package/dist/_astro/LifeStagesBoard.BSvhzmp_.js +1 -0
- package/dist/_astro/LifeYearCycleSelect.Q4VvLY8X.js +1 -0
- package/dist/_astro/LifeYearPlansBoard.CYN2gZKp.js +1 -0
- package/dist/_astro/MultiSelectDropdown.y8JMbCxO.js +1 -0
- package/dist/_astro/{NavLibraries.CZlA6Z1w.js → NavLibraries.D9EKoN80.js} +1 -1
- package/dist/_astro/PluginsPage.DE3qbeY5.js +17 -0
- package/dist/_astro/PluginsPage.r98lZChB.js +1 -0
- package/dist/_astro/{PmBugsBoard.ChL0RBVn.js → PmBugsBoard.Cu1uf0TC.js} +1 -1
- package/dist/_astro/{PmIterationsBoard.hTKVnMgh.js → PmIterationsBoard.RzRKkAH0.js} +1 -1
- package/dist/_astro/{PmProjectDetail.Saj76lNM.js → PmProjectDetail.DH8Z3nHb.js} +1 -1
- package/dist/_astro/{PmProjectsBoard.CCtClGM1.js → PmProjectsBoard.Dokaj4V1.js} +1 -1
- package/dist/_astro/{PmRequirementsBoard.DGXYC1Te.js → PmRequirementsBoard.DET5YIVX.js} +1 -1
- package/dist/_astro/PmRequirementsBoard.i203nmYC.js +1 -0
- package/dist/_astro/{PmShared.BuhrL7Gb.js → PmShared.BJpoEYvk.js} +1 -1
- package/dist/_astro/{PromptsLibrary.DJtTAFz_.js → PromptsLibrary.Dp1S_lHQ.js} +1 -1
- package/dist/_astro/{ReportsPage.BjD8w0zS.js → ReportsPage.C8uufWVb.js} +1 -1
- package/dist/_astro/{ReqAnalysisBoard.BsQ4A1Lt.js → ReqAnalysisBoard.B3bhMWmE.js} +1 -1
- package/dist/_astro/{RequirementsLibrary.WxAFCP3X.js → RequirementsLibrary.BnY7_YXU.js} +1 -1
- package/dist/_astro/{SearchableSelect.D3ODywC4.js → SearchableSelect.5SfNLwNW.js} +1 -1
- package/dist/_astro/SelectDropdown.TgxIOKMD.js +1 -0
- package/dist/_astro/{SettingsDialog.CR7rv0mg.js → SettingsDialog.BzGBZlo2.js} +1 -1
- package/dist/_astro/{SpaceSwitcher.BCZbiL7o.js → SpaceSwitcher.Cy4UrzbH.js} +1 -1
- package/dist/_astro/TasksBoard.CWkx5cD1.js +1 -0
- package/dist/_astro/{TemplatesLibrary.y_RtSjYC.js → TemplatesLibrary.phzK5kho.js} +1 -1
- package/dist/_astro/{TestStatsBoard.C3vkF9vc.js → TestStatsBoard.Dp1TWEf7.js} +1 -1
- package/dist/_astro/TodosBoard.Bkuw_LDW.js +1 -0
- package/dist/_astro/{UiAutoBoard._og5jRon.js → UiAutoBoard.Cpb_EF46.js} +1 -1
- package/dist/_astro/app-config.C4rpn1Ix.js +1 -0
- package/dist/_astro/app-version.CXqYg1a3.js +1 -0
- package/dist/_astro/{bash-tools.cciCC33C.js → bash-tools.RQcI4_42.js} +1 -1
- package/dist/_astro/{case-gen-run.DDhoxXlU.js → case-gen-run.CH0ldlsU.js} +1 -1
- package/dist/_astro/{case-types.CJ5PHz59.js → case-types.CprZTsyX.js} +1 -1
- package/dist/_astro/{hydrate-cache.B7--LFB_.js → hydrate-cache.DI6vqM0o.js} +1 -1
- package/dist/_astro/i18n.BJeTr39S.js +7 -0
- package/dist/_astro/{open-docs-in-session.DQ2_5fkC.js → open-docs-in-session.BdihMTEh.js} +1 -1
- package/dist/_astro/plugins.C0NrHGZv.js +1 -0
- package/dist/_astro/{req-analysis.D9EOpleR.js → req-analysis.CjhgP3jI.js} +1 -1
- package/dist/_astro/{settings.Cu00if4D.js → settings.NTeTjmxg.js} +2 -2
- package/dist/_astro/{spaces-client.Czm-VPh5.js → spaces-client.CMGNsQJ-.js} +1 -1
- package/dist/_astro/{story-review.COs6QaUe.js → story-review.BBfB1qYF.js} +1 -1
- package/dist/_astro/tasks.DefXqRfI.js +1 -0
- package/dist/_astro/{view-prefs.SdItxolG.js → view-prefs.8MPl3A7e.js} +1 -1
- package/dist/case-exec/index.html +141 -15
- package/dist/cases/generate/index.html +73 -10
- package/dist/cases/library/index.html +141 -15
- package/dist/dashboard/index.html +141 -15
- package/dist/docs/changelog/index.html +148 -44
- package/dist/docs/install/index.html +86 -12
- package/dist/docs/manual/index.html +150 -17
- package/dist/knowledge/index.html +141 -15
- package/dist/life/kr-tasks/index.html +921 -0
- package/dist/life/kr-todos/index.html +921 -0
- package/dist/life/objectives/index.html +921 -0
- package/dist/life/reviews/index.html +921 -0
- package/dist/life/stages/index.html +921 -0
- package/dist/life/year-plans/index.html +921 -0
- package/dist/plugins/index.html +73 -10
- package/dist/pm/bugs/index.html +141 -15
- package/dist/pm/iterations/index.html +141 -15
- package/dist/pm/projects/detail/index.html +141 -15
- package/dist/pm/projects/index.html +141 -15
- package/dist/pm/requirements/index.html +141 -15
- package/dist/prompts/index.html +141 -15
- package/dist/reports/index.html +141 -15
- package/dist/requirement-analysis/index.html +141 -15
- package/dist/requirements/index.html +141 -15
- package/dist/tasks/index.html +141 -15
- package/dist/templates/index.html +141 -15
- package/dist/test-automation/index.html +141 -15
- package/dist/test-stats/index.html +141 -15
- package/dist/todos/index.html +141 -15
- package/dist/workbench/index.html +73 -10
- package/docs//345/205/250/345/261/200/346/217/222/344/273/266.md +3 -3
- package/docs//345/256/211/350/243/205/346/211/213/345/206/214.md +10 -3
- package/docs//346/223/215/344/275/234/346/211/213/345/206/214.md +53 -14
- package/lh-plugins/lh-life.mjs +1130 -0
- package/lh-plugins/lh-mcp.mjs +67 -2
- package/package.json +1 -1
- package/dist/_astro/Base.Dlgbb4Ry.css +0 -1
- package/dist/_astro/ChatApp.BTcAJ7PK.js +0 -226
- package/dist/_astro/ColumnResize._Iq05ix_.js +0 -1
- package/dist/_astro/MultiSelectDropdown.BHxW9XLR.js +0 -1
- package/dist/_astro/PluginsPage.CyjR13X6.js +0 -7
- package/dist/_astro/PluginsPage.DMEvFLnP.js +0 -1
- package/dist/_astro/PmRequirementsBoard.BNNq671Z.js +0 -1
- package/dist/_astro/SelectDropdown.apWlFGbA.js +0 -1
- package/dist/_astro/TasksBoard.CdWQSwlg.js +0 -1
- package/dist/_astro/TodosBoard.CSupMlTp.js +0 -1
- package/dist/_astro/app-config.Bg6v8zQQ.js +0 -1
- package/dist/_astro/app-version.DpWEt8o3.js +0 -1
- package/dist/_astro/i18n.CH6ZNsHf.js +0 -7
- package/dist/_astro/plugins.CVnHeKyf.js +0 -1
- package/dist/_astro/tasks.jfnSAEmg.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,50 @@
|
|
|
1
1
|
# 版本日志
|
|
2
2
|
|
|
3
|
+
## [0.1.35] - 2026-11-01
|
|
4
|
+
|
|
5
|
+
人生管理插件上线:侧栏六张 OKR 表(KR 待办 / KR 任务 / Objective / OKR 复盘 / 年度计划 / 人生阶段),飞书多维表式行内编辑与分组;并统一空态文案、派生完成度命名与组内新增预设。
|
|
6
|
+
|
|
7
|
+
### 新增
|
|
8
|
+
|
|
9
|
+
- **人生管理插件**:开启后侧栏六个入口;数据落在空间对应目录(`KR待办/`、`KR任务/`、`Objective目标/`、`OKR复盘/`、`年度计划/`、`人生阶段/`),计划类型 / 年度周期 / 人生周期目录在 `.lantern/config/life/`
|
|
10
|
+
- **飞书式六表**:行内新增 / 行内改、右侧抽屉编辑、分组(含嵌套)、字段显隐、列宽拖拽、多选批量删除、后台轮询;Objective ↔ 年度计划双向关联(计划侧只读胶囊框)
|
|
11
|
+
- **OKR 复盘**:挂 Objective;年度 / 季度 / 完成度只读派生;经验收获三段提纲;标题为空选目标时建议「目标名 复盘」
|
|
12
|
+
|
|
13
|
+
### 修复
|
|
14
|
+
|
|
15
|
+
- **年度计划按「未完成」组新建**:状态预设漏掉 `incomplete`,会错成「进行中」
|
|
16
|
+
- **人生阶段新建行点空白收起**:`isPristine` 误用 `progress === 0`,改为对比 `base.progress`
|
|
17
|
+
- **Objective 改年度周期**:与已绑年度计划不一致时前后端清空计划关联
|
|
18
|
+
- **导航单测**:`NAV_ENTRIES` 增加人生管理六项后同步期望顺序
|
|
19
|
+
|
|
20
|
+
### 优化
|
|
21
|
+
|
|
22
|
+
- **空态统一**:目录 / 枚举「未选择」、外键「未关联」、分组桶「未设置年度」;空关联用整格空态触发器
|
|
23
|
+
- **派生列命名**:KR 任务 / Objective / OKR 复盘统一「完成度」;人生阶段可编辑仍为「进度」
|
|
24
|
+
- **KR 待办新建行可写备注**;表头「年度周期 / 季度周期 / 重要紧急程度」对齐
|
|
25
|
+
|
|
26
|
+
## [0.1.34] - 2026-10-31
|
|
27
|
+
|
|
28
|
+
「我的插件」支持管理当前空间的外接 MCP:列表查看连接状态与工具数、表单 / JSON 双方式添加(兼容 Trae `mcpServers`)、腾讯文档一键配置;并收紧大屏留白、修弹层蒙版与刷新闪屏、记住插件面板开闭与 Tab。
|
|
29
|
+
|
|
30
|
+
### 新增
|
|
31
|
+
|
|
32
|
+
- **我的插件 · MCP Tab**:表格列出当前空间 `.lantern/local/mcp.json` 服务器(名称 / 类型 / 地址 / 工具数 / 状态);支持添加、编辑、删除;点「连接 / 已连接」可单台重连,顶栏可全部刷新
|
|
33
|
+
- **腾讯文档默认行**:列表常驻「腾讯文档」;未配 Token 时显示「需配置」,粘贴空间 MCP Token 即可(预填官方 HTTP 地址)
|
|
34
|
+
- **表单 / JSON 双编辑**:弹窗默认表单,可切换 JSON;兼容 Trae / Claude Desktop 的 `mcpServers` 与灵光 `servers[]`;stdio 支持 `env`(`KEY=VALUE`)
|
|
35
|
+
- **MCP 管理 API**:`GET/PUT/DELETE /__tb_mcp/servers`;敏感 headers / env 脱敏回写;配置变更按内容差异强制重连
|
|
36
|
+
|
|
37
|
+
### 修复
|
|
38
|
+
|
|
39
|
+
- **插件弹层蒙版未盖住左侧菜单**:改用 Headless UI Dialog(`z-110` portal),进出场淡入淡出
|
|
40
|
+
- **保存 / 刷新 MCP 列表闪屏**:已有数据时静默刷新,不再整表切成「加载中」
|
|
41
|
+
- **刷新后插件页被关掉、Tab 丢失**:工作台插件面板开闭与「扩展插件 / MCP」Tab 按数据空间记本机
|
|
42
|
+
|
|
43
|
+
### 优化
|
|
44
|
+
|
|
45
|
+
- **插件页大屏布局**:内容区加宽、左右留白收紧;页头统计含 MCP 数量卡(不可点);页面 Tab 改下划线样式,与状态筛选胶囊分开;Tab 切换带淡入动画
|
|
46
|
+
- **MCP 操作按钮**:添加为主色;行内「编辑 / 删除」改为文字链
|
|
47
|
+
|
|
3
48
|
## [0.1.33] - 2026-10-31
|
|
4
49
|
|
|
5
50
|
需求分析补齐「原文结构」导出与审查衔接:拆解时一并整理原文、XMind / Markdown 按步骤与编号导出,生成用户故事后自动初审;测试点 XMind 与原文结构同一套逻辑图样式;并修掉文档库列宽拖拽误重置。
|
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ AI 工作台:对话与插件工具、需求 / 用例 / 知识 / 提示词内
|
|
|
12
12
|
| --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
13
13
|
| AI 工作台 | 多轮对话,流式输出,BYOK(自带密钥)直连模型;默认提示词按空间可改,可按插件挂载工具 |
|
|
14
14
|
| 会话记忆 | 五轨记忆(用户档案 / 全局事实 / 项目关键 / 项目日志 / 每日),待确认队列与工作台「记忆」Tab |
|
|
15
|
-
| 插件库 | 内置能力开关:内容库(需求 / 用例 / 提示词 / 知识库 / 模板)、生成能力、记忆与检索、任务 / 待办 / 工作汇报 /
|
|
15
|
+
| 插件库 | 内置能力开关:内容库(需求 / 用例 / 提示词 / 知识库 / 模板)、生成能力、记忆与检索、任务 / 待办 / 工作汇报 / 测试统计、人生管理(OKR 六表)、自动化测试(Playwright / pytest / Selenium)、项目管理(项目 / 迭代 / 需求 / 缺陷)、仪表盘、开发工具;开启后侧栏出现对应入口,也可让模型推荐能力建议 |
|
|
16
16
|
|
|
17
17
|
模型配置(BYOK)、内容目录约定、插件用法见 **[操作手册](https://lantern.yychuiyan.com/docs/manual/)**。
|
|
18
18
|
|
|
@@ -76,7 +76,7 @@ lantern acp # 以 ACP 子集供外部编排驱动无 UI Agent
|
|
|
76
76
|
|
|
77
77
|
4、 插件默认值:
|
|
78
78
|
|
|
79
|
-
新建空间默认开启「提示词管理」(每个空间都要有默认提示词,属于内置常开项),侧栏为「我的工作台」「提示词管理」「帮助中心」。其余扩展插件(其它内容库、生成能力、知识库检索、会话记忆、任务管理 / 待办事项 / 工作汇报 / 测试统计 / 用例执行统计 /
|
|
79
|
+
新建空间默认开启「提示词管理」(每个空间都要有默认提示词,属于内置常开项),侧栏为「我的工作台」「提示词管理」「帮助中心」。其余扩展插件(其它内容库、生成能力、知识库检索、会话记忆、任务管理 / 待办事项 / 工作汇报 / 测试统计 / 用例执行统计 / 自动化测试、人生管理、项目列表 / 迭代管理 / 需求管理 / 缺陷管理、仪表盘、插件开发)都要在「插件」页按分类手动开启;由「插件开发」新增的插件同样默认关闭。
|
|
80
80
|
|
|
81
81
|
### 方式二:源码启动
|
|
82
82
|
|
|
@@ -25,6 +25,7 @@ import { REPORT_ROOT_DIR } from '../../lh-plugins/lh-reports.mjs';
|
|
|
25
25
|
import { TASK_DIR_NAME, TODO_DIR_NAME } from '../../lh-plugins/lh-work-store.mjs';
|
|
26
26
|
import { CASE_EXEC_DIR_NAME, TEST_STATS_DIR_NAME } from '../../lh-plugins/lh-stats.mjs';
|
|
27
27
|
import { PM_DIR_NAMES, PM_ENTITY_META } from '../../lh-plugins/lh-pm.mjs';
|
|
28
|
+
import { LIFE_DIR_NAMES, LIFE_ENTITY_META } from '../../lh-plugins/lh-life.mjs';
|
|
28
29
|
import { REQ_ANALYSIS_DIR_NAME } from '../../lh-plugins/lh-req-analysis.mjs';
|
|
29
30
|
import { UIAUTO_DIR_NAME } from '../../lh-plugins/lh-uiauto.mjs';
|
|
30
31
|
import { CASE_REVIEW_DIR_NAME } from '../../lh-plugins/lh-case-review.mjs';
|
|
@@ -94,6 +95,13 @@ const WORK_ITEM_DIR_NAMES = new Map([
|
|
|
94
95
|
['iterations', PM_ENTITY_META.iterations.dir],
|
|
95
96
|
['pmRequirements', PM_ENTITY_META.requirements.dir],
|
|
96
97
|
['bugs', PM_ENTITY_META.bugs.dir],
|
|
98
|
+
// 人生管理六张表(共用 life 插件开关,侧栏各一条)
|
|
99
|
+
['lifeKrTodos', LIFE_ENTITY_META.krTodos.dir],
|
|
100
|
+
['lifeKrTasks', LIFE_ENTITY_META.krTasks.dir],
|
|
101
|
+
['lifeObjectives', LIFE_ENTITY_META.objectives.dir],
|
|
102
|
+
['lifeReviews', LIFE_ENTITY_META.reviews.dir],
|
|
103
|
+
['lifeYearPlans', LIFE_ENTITY_META.yearPlans.dir],
|
|
104
|
+
['lifeStages', LIFE_ENTITY_META.lifeStages.dir],
|
|
97
105
|
// 需求分析的分析结果、自动化测试的执行记录
|
|
98
106
|
['reqAnalysis', REQ_ANALYSIS_DIR_NAME],
|
|
99
107
|
['uiAuto', UIAUTO_DIR_NAME],
|
|
@@ -112,6 +120,7 @@ const SKIP_DIR_NAMES = new Set([
|
|
|
112
120
|
...CONTENT_DIR_NAMES,
|
|
113
121
|
// 项目管理四个插件的固定数据目录:与导航分组同名时靠改名避免冲突
|
|
114
122
|
...PM_DIR_NAMES,
|
|
123
|
+
...LIFE_DIR_NAMES,
|
|
115
124
|
// 需求分析 / 自动化测试的空间数据目录,同样是插件的而不是导航分组
|
|
116
125
|
REQ_ANALYSIS_DIR_NAME,
|
|
117
126
|
UIAUTO_DIR_NAME,
|
|
@@ -115,6 +115,265 @@ export function loadMcpConfig(root = getDataRoot()) {
|
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
+
const SENSITIVE_HEADER_RE = /^(authorization|x-api-key|api-key|token)$/i;
|
|
119
|
+
/** 列表脱敏占位前缀;客户端回写时以此识别「未改密钥」 */
|
|
120
|
+
export const MCP_HEADER_MASK_PREFIX = '••••';
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* @param {string} key
|
|
124
|
+
*/
|
|
125
|
+
export function isSensitiveMcpHeader(key) {
|
|
126
|
+
return SENSITIVE_HEADER_RE.test(String(key || ''));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* @param {string} value
|
|
131
|
+
*/
|
|
132
|
+
export function maskSecretValue(value) {
|
|
133
|
+
const v = String(value || '');
|
|
134
|
+
if (!v) return '';
|
|
135
|
+
if (v.length <= 4) return `${MCP_HEADER_MASK_PREFIX}${v}`;
|
|
136
|
+
return `${MCP_HEADER_MASK_PREFIX}${v.slice(-4)}`;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* @param {Record<string, string> | undefined} headers
|
|
141
|
+
* @returns {Record<string, string> | undefined}
|
|
142
|
+
*/
|
|
143
|
+
export function redactMcpHeaders(headers) {
|
|
144
|
+
if (!headers || typeof headers !== 'object') return undefined;
|
|
145
|
+
/** @type {Record<string, string>} */
|
|
146
|
+
const out = {};
|
|
147
|
+
for (const [k, v] of Object.entries(headers)) {
|
|
148
|
+
if (typeof v !== 'string') continue;
|
|
149
|
+
out[k] = isSensitiveMcpHeader(k) ? maskSecretValue(v) : v;
|
|
150
|
+
}
|
|
151
|
+
return Object.keys(out).length ? out : undefined;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* 合并 headers:新值若为空或仍是脱敏串,则保留旧值。
|
|
156
|
+
* @param {Record<string, string> | undefined} prev
|
|
157
|
+
* @param {Record<string, string> | undefined} next
|
|
158
|
+
*/
|
|
159
|
+
export function mergeMcpHeaders(prev, next) {
|
|
160
|
+
if (!next || typeof next !== 'object') return prev;
|
|
161
|
+
/** @type {Record<string, string>} */
|
|
162
|
+
const out = { ...(prev && typeof prev === 'object' ? prev : {}) };
|
|
163
|
+
for (const [k, v] of Object.entries(next)) {
|
|
164
|
+
if (typeof v !== 'string') continue;
|
|
165
|
+
const trimmed = v.trim();
|
|
166
|
+
if (!trimmed) {
|
|
167
|
+
delete out[k];
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
if (isSensitiveMcpHeader(k) && trimmed.startsWith(MCP_HEADER_MASK_PREFIX)) {
|
|
171
|
+
if (prev && typeof prev[k] === 'string' && prev[k]) out[k] = prev[k];
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
out[k] = trimmed;
|
|
175
|
+
}
|
|
176
|
+
return Object.keys(out).length ? out : undefined;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const SENSITIVE_ENV_RE = /(api[_-]?key|token|secret|password|authorization)/i;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* @param {string} key
|
|
183
|
+
*/
|
|
184
|
+
export function isSensitiveMcpEnvKey(key) {
|
|
185
|
+
return SENSITIVE_ENV_RE.test(String(key || ''));
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* @param {Record<string, string> | undefined} env
|
|
190
|
+
* @returns {Record<string, string> | undefined}
|
|
191
|
+
*/
|
|
192
|
+
export function redactMcpEnv(env) {
|
|
193
|
+
if (!env || typeof env !== 'object') return undefined;
|
|
194
|
+
/** @type {Record<string, string>} */
|
|
195
|
+
const out = {};
|
|
196
|
+
for (const [k, v] of Object.entries(env)) {
|
|
197
|
+
if (typeof v !== 'string') continue;
|
|
198
|
+
out[k] = isSensitiveMcpEnvKey(k) ? maskSecretValue(v) : v;
|
|
199
|
+
}
|
|
200
|
+
return Object.keys(out).length ? out : undefined;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* @param {Record<string, string> | undefined} prev
|
|
205
|
+
* @param {Record<string, string> | undefined} next
|
|
206
|
+
*/
|
|
207
|
+
export function mergeMcpEnv(prev, next) {
|
|
208
|
+
if (!next || typeof next !== 'object') return prev;
|
|
209
|
+
/** @type {Record<string, string>} */
|
|
210
|
+
const out = { ...(prev && typeof prev === 'object' ? prev : {}) };
|
|
211
|
+
for (const [k, v] of Object.entries(next)) {
|
|
212
|
+
if (typeof v !== 'string') continue;
|
|
213
|
+
const trimmed = v.trim();
|
|
214
|
+
if (!trimmed) {
|
|
215
|
+
delete out[k];
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
if (isSensitiveMcpEnvKey(k) && trimmed.startsWith(MCP_HEADER_MASK_PREFIX)) {
|
|
219
|
+
if (prev && typeof prev[k] === 'string' && prev[k]) out[k] = prev[k];
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
out[k] = trimmed;
|
|
223
|
+
}
|
|
224
|
+
return Object.keys(out).length ? out : undefined;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* 把 Claude Desktop / Trae 的 mcpServers、灵光 servers[]、单条对象统一成内部列表。
|
|
229
|
+
* @param {unknown} raw
|
|
230
|
+
*/
|
|
231
|
+
export function coerceMcpServersInput(raw) {
|
|
232
|
+
if (!raw || typeof raw !== 'object') return [];
|
|
233
|
+
const obj = /** @type {Record<string, unknown>} */ (raw);
|
|
234
|
+
if (obj.mcpServers && typeof obj.mcpServers === 'object' && !Array.isArray(obj.mcpServers)) {
|
|
235
|
+
const list = [];
|
|
236
|
+
for (const [name, conf] of Object.entries(
|
|
237
|
+
/** @type {Record<string, unknown>} */ (obj.mcpServers),
|
|
238
|
+
)) {
|
|
239
|
+
if (!conf || typeof conf !== 'object') continue;
|
|
240
|
+
list.push({ name, .../** @type {object} */ (conf) });
|
|
241
|
+
}
|
|
242
|
+
return normalizeMcpServers({ servers: list });
|
|
243
|
+
}
|
|
244
|
+
if (Array.isArray(obj.servers) || Array.isArray(raw)) {
|
|
245
|
+
return normalizeMcpServers(raw);
|
|
246
|
+
}
|
|
247
|
+
if ('command' in obj || 'url' in obj || 'transport' in obj) {
|
|
248
|
+
return normalizeMcpServers({
|
|
249
|
+
servers: [{ name: obj.name || 'mcp', ...obj }],
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
return [];
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* @param {string} root
|
|
257
|
+
* @param {ReturnType<typeof normalizeMcpServers>} servers
|
|
258
|
+
*/
|
|
259
|
+
export function saveMcpServers(root, servers) {
|
|
260
|
+
const p = mcpConfigPath(root);
|
|
261
|
+
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
262
|
+
const normalized = normalizeMcpServers({ servers });
|
|
263
|
+
const tmp = `${p}.${process.pid}.${Date.now()}.tmp`;
|
|
264
|
+
fs.writeFileSync(tmp, `${JSON.stringify({ servers: normalized }, null, 2)}\n`, 'utf8');
|
|
265
|
+
fs.renameSync(tmp, p);
|
|
266
|
+
return { path: p, servers: normalized };
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* @param {string} root
|
|
271
|
+
* @param {object} raw
|
|
272
|
+
* @param {{ previousName?: string }} [opts]
|
|
273
|
+
*/
|
|
274
|
+
export function upsertMcpServer(root, raw, opts = {}) {
|
|
275
|
+
const { servers, path: cfgPath, error } = loadMcpConfig(root);
|
|
276
|
+
if (error) throw new Error(error);
|
|
277
|
+
const previousName = opts.previousName ? sanitizeMcpSegment(opts.previousName) : '';
|
|
278
|
+
const existing =
|
|
279
|
+
(previousName && servers.find((s) => s.name === previousName)) ||
|
|
280
|
+
(raw?.name ? servers.find((s) => s.name === sanitizeMcpSegment(raw.name)) : undefined);
|
|
281
|
+
|
|
282
|
+
const transport = String(raw?.transport || (raw?.url ? 'http' : 'stdio'))
|
|
283
|
+
.trim()
|
|
284
|
+
.toLowerCase();
|
|
285
|
+
const name = sanitizeMcpSegment(raw?.name || existing?.name || '');
|
|
286
|
+
if (!NAME_RE.test(name)) throw new Error('invalid server name');
|
|
287
|
+
|
|
288
|
+
/** @type {object} */
|
|
289
|
+
let next;
|
|
290
|
+
if (transport === 'stdio') {
|
|
291
|
+
const command = String(raw?.command || existing?.command || '').trim();
|
|
292
|
+
if (!command) throw new Error('command is required for stdio');
|
|
293
|
+
next = {
|
|
294
|
+
name,
|
|
295
|
+
transport: 'stdio',
|
|
296
|
+
command,
|
|
297
|
+
args: Array.isArray(raw?.args)
|
|
298
|
+
? raw.args.map((a) => String(a))
|
|
299
|
+
: Array.isArray(existing?.args)
|
|
300
|
+
? existing.args
|
|
301
|
+
: [],
|
|
302
|
+
env:
|
|
303
|
+
raw?.env !== undefined
|
|
304
|
+
? mergeMcpEnv(
|
|
305
|
+
existing?.env,
|
|
306
|
+
raw.env && typeof raw.env === 'object'
|
|
307
|
+
? Object.fromEntries(
|
|
308
|
+
Object.entries(raw.env).filter(([, v]) => typeof v === 'string'),
|
|
309
|
+
)
|
|
310
|
+
: undefined,
|
|
311
|
+
)
|
|
312
|
+
: existing?.env,
|
|
313
|
+
};
|
|
314
|
+
} else if (transport === 'http' || transport === 'streamable-http' || transport === 'sse') {
|
|
315
|
+
const url = String(raw?.url || existing?.url || '').trim();
|
|
316
|
+
if (!url) throw new Error('url is required for http');
|
|
317
|
+
next = {
|
|
318
|
+
name,
|
|
319
|
+
transport: 'http',
|
|
320
|
+
url,
|
|
321
|
+
headers: mergeMcpHeaders(existing?.headers, raw?.headers),
|
|
322
|
+
};
|
|
323
|
+
} else {
|
|
324
|
+
throw new Error(`unsupported transport: ${transport}`);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const replaceNames = new Set([previousName, existing?.name].filter(Boolean));
|
|
328
|
+
if (servers.some((s) => s.name === name && !replaceNames.has(s.name))) {
|
|
329
|
+
throw new Error(`server already exists: ${name}`);
|
|
330
|
+
}
|
|
331
|
+
const list = servers.filter((s) => !replaceNames.has(s.name));
|
|
332
|
+
list.push(next);
|
|
333
|
+
return saveMcpServers(root, list);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* @param {string} root
|
|
338
|
+
* @param {string} name
|
|
339
|
+
*/
|
|
340
|
+
export function removeMcpServer(root, name) {
|
|
341
|
+
const target = sanitizeMcpSegment(name);
|
|
342
|
+
const { servers, error } = loadMcpConfig(root);
|
|
343
|
+
if (error) throw new Error(error);
|
|
344
|
+
if (!servers.some((s) => s.name === target)) throw new Error(`server not found: ${target}`);
|
|
345
|
+
return saveMcpServers(
|
|
346
|
+
root,
|
|
347
|
+
servers.filter((s) => s.name !== target),
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* 供 UI 列表:配置脱敏 + 连接状态字段由调用方补。
|
|
353
|
+
* @param {string} [root]
|
|
354
|
+
*/
|
|
355
|
+
export function listMcpServersForUi(root = getDataRoot()) {
|
|
356
|
+
const cfg = loadMcpConfig(root);
|
|
357
|
+
return {
|
|
358
|
+
path: cfg.path,
|
|
359
|
+
error: cfg.error,
|
|
360
|
+
servers: cfg.servers.map((s) => ({
|
|
361
|
+
name: s.name,
|
|
362
|
+
transport: s.transport,
|
|
363
|
+
command: s.command,
|
|
364
|
+
args: s.args,
|
|
365
|
+
env: redactMcpEnv(s.env),
|
|
366
|
+
url: s.url,
|
|
367
|
+
headers: redactMcpHeaders(s.headers),
|
|
368
|
+
hasSecrets: Boolean(
|
|
369
|
+
(s.headers &&
|
|
370
|
+
Object.keys(s.headers).some((k) => isSensitiveMcpHeader(k) && s.headers[k])) ||
|
|
371
|
+
(s.env && Object.keys(s.env).some((k) => isSensitiveMcpEnvKey(k) && s.env[k])),
|
|
372
|
+
),
|
|
373
|
+
})),
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
|
|
118
377
|
/** @type {Map<string, { client: import('@modelcontextprotocol/sdk/client/index.js').Client, conf: object, root: string }>} */
|
|
119
378
|
const pool = new Map();
|
|
120
379
|
/** @type {Map<string, { server: string, remoteName: string }>} */
|
|
@@ -164,12 +423,14 @@ async function connectServer(conf, root) {
|
|
|
164
423
|
|
|
165
424
|
/**
|
|
166
425
|
* @param {string} [root]
|
|
426
|
+
* @param {{ forceNames?: string[] }} [opts] 指定名称强制断开重连(配置未变也重连)
|
|
167
427
|
*/
|
|
168
|
-
export async function ensureMcpClients(root = getDataRoot()) {
|
|
428
|
+
export async function ensureMcpClients(root = getDataRoot(), opts = {}) {
|
|
169
429
|
if (poolRoot && poolRoot !== root) {
|
|
170
430
|
await closeAllMcpClients();
|
|
171
431
|
}
|
|
172
432
|
poolRoot = root;
|
|
433
|
+
const force = new Set((opts.forceNames || []).map((n) => sanitizeMcpSegment(n)));
|
|
173
434
|
const { servers, error } = loadMcpConfig(root);
|
|
174
435
|
const wanted = new Set(servers.map((s) => s.name));
|
|
175
436
|
for (const key of [...pool.keys()]) {
|
|
@@ -187,7 +448,17 @@ export async function ensureMcpClients(root = getDataRoot()) {
|
|
|
187
448
|
if (error) errors.push(error);
|
|
188
449
|
for (const conf of servers) {
|
|
189
450
|
const key = poolKey(root, conf.name);
|
|
190
|
-
|
|
451
|
+
const prev = pool.get(key);
|
|
452
|
+
const sameConf = prev && JSON.stringify(prev.conf) === JSON.stringify(conf);
|
|
453
|
+
if (sameConf && !force.has(conf.name)) continue;
|
|
454
|
+
if (prev) {
|
|
455
|
+
try {
|
|
456
|
+
await prev.client.close();
|
|
457
|
+
} catch {
|
|
458
|
+
// ignore
|
|
459
|
+
}
|
|
460
|
+
pool.delete(key);
|
|
461
|
+
}
|
|
191
462
|
try {
|
|
192
463
|
const client = await connectServer(conf, root);
|
|
193
464
|
pool.set(key, { client, conf, root });
|
|
@@ -198,6 +469,24 @@ export async function ensureMcpClients(root = getDataRoot()) {
|
|
|
198
469
|
return { servers, connected: [...pool.keys()].map((k) => k.slice(root.length + 2)), errors };
|
|
199
470
|
}
|
|
200
471
|
|
|
472
|
+
/**
|
|
473
|
+
* 强制重连一台(或全部)MCP 服务器。
|
|
474
|
+
* @param {string} [root]
|
|
475
|
+
* @param {string} [name] 缺省则强制重连配置里全部
|
|
476
|
+
*/
|
|
477
|
+
export async function reconnectMcpServer(root = getDataRoot(), name) {
|
|
478
|
+
const target = name ? sanitizeMcpSegment(name) : '';
|
|
479
|
+
if (target) {
|
|
480
|
+
const { servers } = loadMcpConfig(root);
|
|
481
|
+
if (!servers.some((s) => s.name === target)) {
|
|
482
|
+
throw new Error(`server not found: ${target}`);
|
|
483
|
+
}
|
|
484
|
+
return ensureMcpClients(root, { forceNames: [target] });
|
|
485
|
+
}
|
|
486
|
+
const { servers } = loadMcpConfig(root);
|
|
487
|
+
return ensureMcpClients(root, { forceNames: servers.map((s) => s.name) });
|
|
488
|
+
}
|
|
489
|
+
|
|
201
490
|
/**
|
|
202
491
|
* @param {string} [root]
|
|
203
492
|
*/
|
package/cli/server.mjs
CHANGED
|
@@ -20,6 +20,7 @@ import { lhMcpPlugin } from '../lh-plugins/lh-mcp.mjs';
|
|
|
20
20
|
import { lhTodosPlugin } from '../lh-plugins/lh-todos.mjs';
|
|
21
21
|
import { lhTasksPlugin } from '../lh-plugins/lh-tasks.mjs';
|
|
22
22
|
import { lhPmPlugin } from '../lh-plugins/lh-pm.mjs';
|
|
23
|
+
import { lhLifePlugin } from '../lh-plugins/lh-life.mjs';
|
|
23
24
|
import { lhReportsPlugin } from '../lh-plugins/lh-reports.mjs';
|
|
24
25
|
import { lhStatsPlugin } from '../lh-plugins/lh-stats.mjs';
|
|
25
26
|
import { lhUiautoPlugin } from '../lh-plugins/lh-uiauto.mjs';
|
|
@@ -63,6 +64,7 @@ function attachPlugins(app, dataRoot) {
|
|
|
63
64
|
lhTodosPlugin(),
|
|
64
65
|
lhTasksPlugin(),
|
|
65
66
|
lhPmPlugin(),
|
|
67
|
+
lhLifePlugin(),
|
|
66
68
|
lhReportsPlugin(),
|
|
67
69
|
lhStatsPlugin(),
|
|
68
70
|
lhUiautoPlugin(),
|