@sanqianx/project-knowledge 5.3.2 → 5.4.1

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.
@@ -9,7 +9,7 @@
9
9
  "plugins": [
10
10
  {
11
11
  "name": "project-knowledge",
12
- "version": "5.3.2",
12
+ "version": "5.4.1",
13
13
  "source": "./plugins/project-knowledge",
14
14
  "description": "Search durable project decisions and implementation history through MCP."
15
15
  }
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## [5.4.1] - 2026-11-26
4
+
5
+ - 新增《AI 团队成员工具开发指南》(`docs/ai-team-member-tools-guide.md`,随包发布):自动维护是什么、为什么它是固定的、成员和工具的关系、模块给工具的输入、两种工具与退出码、必须遵守的规则、两个例子、登记与试运行、常见问题。
6
+ - AI 团队页「登记工具」旁边新增「怎么写工具?」,在页面内直接打开指南的精简版;工具列表为空时也有入口。
7
+ - 成员对话框里关于「模型」的说明更正:模型只是引用,没有功能会按它启动模型;项目指定了 Reviewer 成员时,它须与受信的审查配置一致,否则模型审查显示阻塞。
8
+ - 成员的「模型」下拉列出每一个模型(按档案分组),不再是一个档案只显示它的默认模型。保存时知识库核对所选模型确实属于这个档案,不在列表里的会被拒绝并说明原因。
9
+ - 固定 Workflow `0.3.2`。
10
+
11
+ ## [5.4.0] - 2026-11-26
12
+
13
+ - AI 团队的维护仓库和工具改为在页面上登记(「自动维护」页:登记仓库 → 登记工具 → 新建维护计划),不再手工编辑 `maintenance.json`,也不需要重启。登记仓库时只选项目,仓库路径由知识库解析后随受信转发交给工作流模块。从 `0.2.3` 升级时,旧登记文件在首次启动时导入一次,已有的维护计划和运行记录继续有效。
14
+ - 页签改名:「任务」→「团队任务」,「仓库维护」→「自动维护」,里面的条目叫「维护计划」。工具可以编辑和删除;仓库的分支、远端和推送授权可以修改,立即生效。
15
+ - 成员的「模型」改为下拉,选项是知识库里已启用且凭据已配置的档案。保存时知识库核对档案,再把模型名交给工作流模块;模块只采信受信来源的模型引用。目前只保存引用,没有功能会按它启动模型。
16
+ - 安全:`/api/workflow/*` 的写请求要求回环 Host,浏览器请求的 `Sec-Fetch-Site` 须为同源;放行的 Origin 转发给工作流模块核对。
17
+ - 修复:模块代理的异步报错(例如受信转发拒绝了一个请求)没有被请求处理器接住,会成为未处理的拒绝并终止进程;现在统一返回错误响应。
18
+ - 测试:新增全新实例在页面上登记并运行的浏览器全流程;测试用的服务不再指向工作流模块的默认端口。运行清单列出工作流模块的全部文件。
19
+ - 固定 Workflow `0.3.0`。
20
+
3
21
  ## [5.3.2] - 2026-11-26
4
22
 
5
23
  - 仓库目录按约定重构,产品行为与 5.3.1 相同:产品源码归入 `src/` 并按领域分目录,网页资源归入 `resources/ui/`,回归测试归入 `tests/` 且不再打进发布包。npm 包内的路径随之变化(`_site/` → `src/`,`ui/` → `resources/ui/`)。已登记仓库的受管提交钩子会在启动时自动重新绑定到新的脚本路径。
@@ -53,6 +53,12 @@ project-knowledge stop
53
53
  需要 Node.js 22+ 与 `PATH` 中的 Git。4.8.0 仅交付 npm 网页版本,不提供新版
54
54
  Windows 安装包或桌面自动更新。
55
55
 
56
+ ## AI 团队
57
+
58
+ 从主导航进入「AI 团队」。成员要用本机工具做事时,看
59
+ [成员工具开发指南](ai-team-member-tools-guide.md):自动维护是什么、工具怎么写、
60
+ 怎么登记和试运行。页面里「登记工具」旁边的「怎么写工具?」是它的精简版。
61
+
56
62
  ## 唯一分析流程
57
63
 
58
64
  知识引擎是唯一分析执行者:
@@ -0,0 +1,176 @@
1
+ # AI 团队成员工具开发指南
2
+
3
+ 适用范围:知识库 5.4.x,工作流模块 0.3.x。
4
+
5
+ 这份指南讲的是:AI 团队的成员要用一个工具去做事时,这个工具怎么写、怎么登记、怎么试。页面上「登记工具」旁边的「怎么写工具?」是它的精简版。
6
+
7
+ ## 自动维护是什么
8
+
9
+ 给一个仓库定几条「到了条件就执行」的例行保养:每次提交后检查一遍,每天整理一次格式或文档。每条保养是一份维护计划,挂在某个成员名下,用你登记的工具去做。
10
+
11
+ 为什么要有它:
12
+
13
+ - **有些事必须每次都做。** 每次提交后跑一遍检查,问题当天就能发现。靠人记得去做,迟早会漏。
14
+ - **不需要有人发起任务。** 团队成员平时在任务里干活:有人发起任务后,Leader 规划,开发成员在真实的开发会话里实现,审查成员做模型审查。自动维护走另一条线,到了条件就执行。
15
+ - **做得安全。** 工具在独立的维护工作目录里运行,不碰正在开发的目录。改动先留成候选提交,经你允许才会推送。
16
+
17
+ 它是固定的,这是有意的:
18
+
19
+ - 触发条件(提交后、每天、手动)、工具和负责成员都由你事先定好。到了条件就执行,每次一样。
20
+ - 成员不会自己判断今天该做什么。重复性的保养正需要每次一样,结果才可核对。
21
+ - 需要判断的部分放在工具里:工具可以调用模型,成员的职责提示词会传给它。规则要变,改工具,不用改知识库。
22
+
23
+ 它不是「成员自己领任务、自己挑工具」。那部分现在没有实现。
24
+
25
+ ## 成员和工具的关系
26
+
27
+ | 成员在哪条线上做事 | 用的是什么 |
28
+ | --- | --- |
29
+ | 任务:Leader 规划,开发成员实现,审查成员审查 | 知识库自带的检查器和模型,不是这里登记的工具 |
30
+ | 自动维护:一份维护计划挂在某个成员名下 | 你登记的工具 |
31
+
32
+ 登记的工具只在维护计划里被使用。计划运行时,模块把负责成员的信息随输入传给工具。
33
+
34
+ 成员的「模型」是从下拉里选的:知识库里已启用且凭据已配置的档案,以及这些档案下的各个模型,按档案分组。它只是引用,没有功能会按它启动模型。唯一用到它的地方是核对:项目指定了 Reviewer 成员时,这个成员的模型要和受信的审查配置一致,否则任务里的模型审查会显示阻塞并说明原因。不确定时选「不指定」,不会阻塞任何东西。
35
+
36
+ ## 工具是什么
37
+
38
+ 一个能在本机直接运行的程序。Node、Python、PowerShell 脚本或 exe 都可以。模块按你登记的「程序路径 + 参数」启动它,不经过 shell。
39
+
40
+ 工具不碰你正在开发的目录。模块先为仓库建一个独立的维护工作目录(一个 Git worktree),工具在里面运行,工作目录就是仓库根,以你的系统用户身份执行。
41
+
42
+ ## 模块给工具什么
43
+
44
+ 标准输入里一行 JSON,以换行结束:
45
+
46
+ ```json
47
+ {
48
+ "schema": "ai-team-maintenance/v1",
49
+ "projectId": "…", "jobId": "…", "runId": "…",
50
+ "workspace": "维护工作目录", "baseSha": "起始提交",
51
+ "trigger": { "kind": "commit", "commitSha": "…" },
52
+ "member": { "memberId": "…", "name": "维护 Agent",
53
+ "instructions": "成员的职责提示词", "memoryGroupIds": [] },
54
+ "phase": "check", "attempt": 0, "findings": null
55
+ }
56
+ ```
57
+
58
+ | 字段 | 含义 |
59
+ | --- | --- |
60
+ | `schema` | 固定是 `ai-team-maintenance/v1` |
61
+ | `projectId`、`jobId`、`runId` | 知识库项目、维护计划和这次运行 |
62
+ | `workspace` | 维护工作目录,也就是当前工作目录 |
63
+ | `baseSha` | 本轮的起始提交。提交触发时是那次提交,每日和手动触发时是目标分支的最新提交 |
64
+ | `trigger` | `manual`、`commit`(带 `commitSha`)或 `daily`(带日期、时间和时区) |
65
+ | `member` | 负责成员:`memberId`、`name`、`instructions`、`memoryGroupIds` |
66
+ | `phase` | `check`、`repair` 或 `apply` |
67
+ | `attempt` | 第几次。检查从 0 开始,修复和应用从 1 开始 |
68
+ | `findings` | 只在修复命令里有:上一轮检查的 `stdout` 和 `stderr`,各含 `text` 和 `truncated` |
69
+
70
+ ## 两种工具,靠退出码说话
71
+
72
+ | | 只检查 | 可修改文件 |
73
+ | --- | --- | --- |
74
+ | 做什么 | 读工作区,报告问题 | 改工作区里的文件 |
75
+ | 退出 0 | 通过 | 成功,模块生成一个候选提交 |
76
+ | 退出 1 | 有问题 | 失败 |
77
+ | 其他退出码 | 工具自身故障 | 失败 |
78
+ | 可选 | 再登记一条修复命令:检查不通过时运行,修完自动复查,最多 1 到 5 次 | 无 |
79
+
80
+ - 修复命令运行时,`findings` 里带着上一轮检查的 stdout 和 stderr。检查命令输出什么格式,由你的检查命令和修复命令自己约定,模块不解析它。
81
+ - 「可修改文件」的工具退出 0 后,模块把工作目录里的改动生成一个提交。没有改动时,这次运行记为「无改动」。
82
+
83
+ ## 必须遵守
84
+
85
+ - **程序路径**:绝对路径,并且已经存在。Windows 上不能填 `.cmd` 或 `.bat`,要填 `node.exe` 的路径,脚本写在参数里,一行一个。
86
+ - **同步跑完就退出**:默认 120 秒超时,最长可设 1800 秒。超时后这次运行会中断并进入保护状态。
87
+ - **不要动 Git**:不提交,不切换提交。每一步之后模块会核对当前提交没变,提交由模块来做。
88
+ - **只改工作目录里的文件**:每路输出最多保留 64 KB,页面只显示前 8 KB,结论要放在最前面。
89
+ - **环境变量只传白名单**(PATH、HOME、USERPROFILE、APPDATA、LOCALAPPDATA、TEMP 等):API 密钥之类的传不进去,工具要自己从文件读凭据。
90
+ - **工具不要放进被检查的仓库**:仓库有未提交改动时,维护会一直等。放在仓库外的任何目录都行。
91
+
92
+ ## 用上成员的信息
93
+
94
+ 成员不会自己启动模型来执行工具。成员给工具的只有输入里的 `member`:名字、职责提示词、记忆组合 ID。
95
+
96
+ 所以让工具按成员定制,就是工具自己使用 `member.instructions`,例如把职责提示词当作规则去调用模型。记忆正文目前工具取不到。
97
+
98
+ ## 例子一:检查并修复行尾空格
99
+
100
+ ```js
101
+ // trailing.js — 用法:node.exe trailing.js check | repair
102
+ 'use strict';
103
+ const fs = require('node:fs');
104
+ const input = JSON.parse(fs.readFileSync(0, 'utf8')); // 模块经标准输入传来的上下文
105
+ const files = () => fs.readdirSync('.').filter(name => name.endsWith('.md'));
106
+ if (process.argv[2] === 'check') {
107
+ const found = files().filter(name => /[ \t]+$/m.test(fs.readFileSync(name, 'utf8')));
108
+ if (found.length) { console.log(JSON.stringify({ files: found })); process.exit(1); } // 退出 1:有问题
109
+ } else if (process.argv[2] === 'repair') {
110
+ for (const name of files()) fs.writeFileSync(name, fs.readFileSync(name, 'utf8').replace(/[ \t]+$/gm, ''));
111
+ }
112
+ ```
113
+
114
+ 页面上登记成「只检查」:程序路径填 `node.exe` 的完整路径,参数一行是 `trailing.js` 的路径、一行是 `check`;修复程序路径相同,修复参数把 `check` 换成 `repair`。
115
+
116
+ ## 例子二:按成员的职责提示词调用模型
117
+
118
+ 这是一个适配器的骨架,省略了调用模型的部分。它说明三件事:凭据从文件读,职责提示词取自成员,调用失败要和「有问题」区分开。
119
+
120
+ ```js
121
+ // review.js — 用法:node.exe review.js check
122
+ 'use strict';
123
+ const fs = require('node:fs');
124
+ const path = require('node:path');
125
+ const input = JSON.parse(fs.readFileSync(0, 'utf8'));
126
+ if (process.argv[2] !== 'check') process.exit(2); // 这个工具只做检查
127
+
128
+ // 凭据从文件读:环境变量只传 PATH、HOME、APPDATA 等几项,API 密钥传不进来。
129
+ const key = fs.readFileSync(path.join(process.env.USERPROFILE, '.my-tool', 'key'), 'utf8').trim();
130
+ const request = [
131
+ input.member.instructions, // 成员的职责提示词,例如「只关注接口文档与实现是否一致」
132
+ '检查这个目录:' + input.workspace,
133
+ '发现问题时输出一行 JSON:{"path":"相对路径","expected":"应当怎样"};没有问题时什么都不输出。',
134
+ ].join('\n\n');
135
+
136
+ // 用 request 和 key 调用你选的模型,然后按结论退出:
137
+ // 有问题 console.log(JSON.stringify({ path, expected })); process.exit(1)
138
+ // 没有问题 process.exit(0)
139
+ // 调用失败 process.exit(2) 算工具自身故障,不会被当成「有问题」
140
+ ```
141
+
142
+ ## 登记与试运行
143
+
144
+ 1. 把工具放在仓库之外的任意目录。
145
+ 2. 先当普通命令行程序写好,手工喂一段 JSON 跑通。
146
+ 3. 打开「AI 团队 → 自动维护」。还没登记仓库的,先选项目登记仓库。
147
+ 4. 点「登记工具」,填名称、类型、程序路径和参数。保存时会检查程序路径存在。
148
+ 5. 点「新建计划」,选成员、工具和触发方式。先选手动。
149
+ 6. 对计划点「运行一次」,在运行详情里看每一轮的退出码和输出。
150
+ 7. 确认可靠后,再改成「目标分支提交后」或「每天」,或者再加修复命令。
151
+
152
+ ## 常见问题
153
+
154
+ **运行一直显示「原工作区有未提交改动或 Git 操作」。**
155
+ 你的开发目录里有没提交的文件,或者正在合并、变基。提交或贮藏(stash)之后,队列自动继续。也可以在开发期间先点「标记开发占用」:维护只接收触发不执行,释放后按顺序执行。
156
+
157
+ **运行「未通过」。**
158
+ 打开运行详情看原因。「仍有检查未通过项」是检查不通过而且修复次数用完;「检查命令执行失败」「修复命令执行失败」「维护命令执行失败」是工具自身出错,看那一轮的输出。
159
+
160
+ **改动在哪里?**
161
+ 在运行详情的「候选提交」里,是一个提交号。`git show <提交号>` 查看,`git cherry-pick <提交号>` 合入你的分支。只有仓库设置里开了「允许自动推送」、计划选择了推送,而且远端没有前进时,才会自动快进推送。
162
+
163
+ **工具能拿到 API 密钥吗?**
164
+ 不能从环境变量拿。模块只传 PATH、HOME、USERPROFILE、APPDATA、LOCALAPPDATA、TEMP 等几项。工具自己从文件读凭据,放在你的用户目录下。
165
+
166
+ **为什么不能填 .cmd 或 .bat?**
167
+ 模块不经 shell 启动程序,而 Windows 上这两种脚本必须经 shell。填 `node.exe` 的完整路径,把脚本路径写在参数里。
168
+
169
+ **能登记几个?**
170
+ 每个仓库最多 12 个工具、12 份维护计划。一个知识库维护一个仓库。
171
+
172
+ ## 现在没有的
173
+
174
+ - 成员自己挑工具、自己决定做什么。
175
+ - MCP 工具直接接入。已有的 MCP 工具可以由你写一个本地适配器来调用。
176
+ - 工具读取记忆正文。成员的记忆组合 ID 会传给工具,正文目前取不到。
@@ -11,9 +11,9 @@
11
11
  "plugins/project-knowledge/hooks/codex.json": "216e03c07295606ef6ebb2c4f669ad0d790b5e7c4f3f34600488033db75e4239",
12
12
  "plugins/project-knowledge/scripts/context-hook.cjs": "90d3fd7dcf965a17fdb1f6a88b80da25b943b06bd5030a8eb2fbc2ea39b174fa",
13
13
  "plugins/project-knowledge/scripts/mcp-launcher.cjs": "c9235eaf722ad011ce42d7a8416a77bef8e2a65e174f27b3d183f4b8f811f293",
14
- "plugins/project-knowledge/.claude-plugin/plugin.json": "8f3dc48aaa6803803c2c8bcd8eead9e4b431923e564bfc0038824997fdab0a63",
15
- "plugins/project-knowledge/.codex-plugin/plugin.json": "6dc3e0c81f202bc6417ffd289aa66c1857d07a65f82712fffa627d882e864fa7",
16
- "plugins/project-knowledge/.mcp.json": "2acba512fb6e5cccb10a8cb8264f4899d3887716efde4c177290ca8a11d8f6ce",
14
+ "plugins/project-knowledge/.claude-plugin/plugin.json": "9ce8ff166dcf87a8bb27f0ebfa4a09826609b20067dc960cb74a4111117a9f50",
15
+ "plugins/project-knowledge/.codex-plugin/plugin.json": "3bc9adfbf18b7d821b82d9b706c2bc28f7439c94e65143c0f8d3c3bae484aca7",
16
+ "plugins/project-knowledge/.mcp.json": "24c204677f374f96b4df87b36a7b8d44fa77cef957fa738b98596e4c251cd893",
17
17
  "resources/ui/version-info.js": "01a82217b031de54b80d6c7974da9c70888c4c90a046bd4248a808f7989ddce7",
18
18
  "resources/ui/version-info.css": "209fad8e42b661f72d2aba3280e1ca47768b5cefb776fe5459538d34fbad120f"
19
19
  },
@@ -321,30 +321,31 @@
321
321
  "workflow": {
322
322
  "name": "@sanqianx/ai-coding-workflow",
323
323
  "installName": "@sanqianx/ai-coding-workflow",
324
- "version": "0.2.3",
324
+ "version": "0.3.2",
325
325
  "files": {
326
326
  "LICENSE": "c1b9df1275e769f3dbab000d1e457a2d4b0f28eb5da6c77e48dc37eeba202ed7",
327
- "README.md": "0ee483525831969a3855d942cbb2388d0c6a72e160bfa3c4fd33ee1bc729d1c7",
328
- "docs/contract.md": "2b750eae9998f2ee19953769c56fb046e31cfa105ad2eee351ec63764bb3572f",
329
- "package.json": "a2a86aabd55bc62c62d6c0953fd30cbedcac7ba9f33854298e843c47f29225c7",
327
+ "README.md": "5d4729ed8d2087607e26eb378487f610bb1a2d26a6664a09eace7e815cdde1fd",
328
+ "docs/contract.md": "88f109d7039ab6d2a81bbaa0c0c606b011579f5299564b113bdb3d9c826d03b9",
329
+ "package.json": "31d0649f5aa0c01947ba7da930118b54d155e74bb85955d39dfc5111fa6ec430",
330
330
  "src/bin.js": "1feb264c5f2df3302846d604a3a58c51d991d3736ee46c31d658e50978946618",
331
331
  "src/checks.js": "adffca98f9717a23bc6a611ecc387b15626b187a2e37a65cb658ac917cf3b1bb",
332
332
  "src/consumer.js": "0f25dcda53d25f82a8c83e637cb3de64e9e5b5014a74531383c8244c094d5500",
333
333
  "src/digests.js": "dd90e639d21c3b59a604e3280f214d0b4ed178e3c659c18b90d31b5479913332",
334
334
  "src/domain.js": "2edd3170002a592fc17f09456074b3c3c7d48dcd608efb64e9e76b314cd9a361",
335
335
  "src/errors.js": "1868330aa021b3dba5e92061dbb41e15a94f4cb0746f870c49aac4bf6119d708",
336
- "src/identity.js": "89a3023b84c82f37aa2647033632463940da48ae9b60cf329e3c29259cc6367c",
337
- "src/maintenance-config.js": "4edb8f033894344b27cb7a57e5444259a90781e90009b54e34b939a4be7aa0b9",
336
+ "src/identity.js": "03a80672f56082539554a3d0794d64d303eb9ba8d22f7ebbcd26469829fc3da5",
337
+ "src/maintenance-config.js": "e3d8dc8a0061d4e45c1f7bacef62ec6fea36c5f4c6a513ceb5146461bd43c071",
338
338
  "src/maintenance-runner.js": "2e8a38b597a6396abdea8c2ff015f80fe2f3587f6ef7b6a92fbed6feb4154c69",
339
- "src/maintenance.js": "10e536c8bc534adbbe055e1fc94232d8b3c796891cc5c801c77f10909d118a2b",
339
+ "src/maintenance.js": "508369ec7298ad776c46dea3c1435042481742a35e80af494636c4e19622fb7c",
340
340
  "src/review-native.js": "47ca1ba2c424116bcdce66526d1bafb90f560b945f8b4fd58a6732e252aa7a7f",
341
- "src/server.js": "e5db984d61025a22fbd729d3dc1ebcf6bfcdfedc499c33e1bcb89637e039ac38",
341
+ "src/server.js": "402b94bae2384e4b73f8f5636ab0aa38ec77067d3ca7660ba98fbfbd4822e545",
342
342
  "src/snapshots.js": "e4d3dca2d9193a536f9c24fb9f572aff58eb1031f2caac71ba8531d4b47db7b0",
343
- "src/store.js": "5c7d5e1415c326fec192bc2e6824b93abda1236e23b1304afe11f52754d96500",
343
+ "src/store.js": "1d02fa856007b3e1ecb9d02e63fa4c8bd20be50d78ce1df29e42624a5d05e83c",
344
344
  "src/tasks.js": "95a043d7c9a25cb266a9ec7f21b8502dc96e13b441b0e4c884c4f91996f558ed",
345
- "ui/app.css": "c64fc049febb5a461bd902b08de491e030b53ffc0d2c6c8a5366ec0b88b27843",
346
- "ui/app.js": "de7601e903486498719e8be749cc0d457a281a6f73867a999d63eb7171c579b2",
347
- "ui/index.html": "23177779fefb0e0cc194c102df3a29a86559101944610c6f09587ef472ec5ae0"
345
+ "ui/app.css": "9a774194c2ed6783446f284f1789666b443b1bbe33f297ccfd0b4835ded12f4c",
346
+ "ui/app.js": "951285b24bab5238d00a456b9557f1b39e49541d55d3d30a1a6eb22cc7411d6f",
347
+ "ui/index.html": "0eefc46d87ab44a4d62ca970021b8c2e7b42b536ebc5e0c76948aa2ee173aaff",
348
+ "src/maintenance-registry.js": "3c2579c2de0c8e8c6006622491882cb5d07c05aa3585e20f155a023cbcc6d975"
348
349
  }
349
350
  }
350
351
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanqianx/project-knowledge",
3
- "version": "5.3.2",
3
+ "version": "5.4.1",
4
4
  "description": "Knowledge base manager with Git integration, AI-driven analysis, and bilingual (zh-CN/en-US) knowledge output",
5
5
  "main": "src/server.js",
6
6
  "scripts": {
@@ -60,6 +60,7 @@
60
60
  "docs/release-5.0.17-acceptance.md",
61
61
  "docs/release-5.0.19-acceptance.md",
62
62
  "docs/fresh-v5-start.md",
63
+ "docs/ai-team-member-tools-guide.md",
63
64
  "README.md",
64
65
  "NOTICE",
65
66
  "CHANGELOG.md"
@@ -92,7 +93,7 @@
92
93
  "@modelcontextprotocol/sdk": "1.29.0",
93
94
  "@sanqianx/ai-coding-event-bridge-console": "0.7.5-rc.1",
94
95
  "@sanqianx/ai-coding-knowledge-engine": "0.4.1",
95
- "@sanqianx/ai-coding-workflow": "0.2.3",
96
+ "@sanqianx/ai-coding-workflow": "0.3.2",
96
97
  "@sanqianx/vector-hub": "1.0.8-rc.9",
97
98
  "buffer": "^6.0.3",
98
99
  "cheerio": "^1.2.0",
@@ -2,7 +2,7 @@
2
2
  "$schema": "https://json.schemastore.org/claude-code-plugin-manifest.json",
3
3
  "name": "project-knowledge",
4
4
  "hooks": "./hooks/claude.json",
5
- "version": "5.3.2",
5
+ "version": "5.4.1",
6
6
  "description": "Read durable project decisions and implementation history from Project Knowledge.",
7
7
  "author": {
8
8
  "name": "SanQianX",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "project-knowledge",
3
- "version": "5.3.2",
3
+ "version": "5.4.1",
4
4
  "description": "Read durable project decisions and implementation history from Project Knowledge.",
5
5
  "author": {
6
6
  "name": "SanQianX",
@@ -8,7 +8,7 @@
8
8
  "const fs=require('fs'),path=require('path'),os=require('os');const PKG='@sanqianx/project-knowledge',SC='project-knowledge/integration-runtime/v1';let f='';const root=process.env.CLAUDE_PLUGIN_ROOT||process.env.PLUGIN_ROOT;if(root){f=path.join(root,'scripts','mcp-launcher.cjs');if(!fs.existsSync(f))f=''}if(!f){const dd=process.env.KB_DATA_DIR||path.join(os.homedir(),'.project-knowledge');try{const bp=path.join(dd,'integration-runtime.json');const st=fs.statSync(bp);if(st.isFile()&&st.size<=32768){const b=JSON.parse(fs.readFileSync(bp,'utf8'));if(b&&b.schema===SC&&b.packageName===PKG&&typeof b.packageRoot==='string'&&path.isAbsolute(b.packageRoot)){const c=path.join(b.packageRoot,'plugins','project-knowledge','scripts','mcp-launcher.cjs');const rr=fs.realpathSync(b.packageRoot),cr=fs.realpathSync(c);const rel=path.relative(rr,cr);if(rel&&rel!=='..'&&!rel.startsWith('..'+path.sep)&&!path.isAbsolute(rel)&&fs.statSync(cr).isFile())f=cr}}}catch(e){}}if(!f){console.error('[project-knowledge-mcp] 未能通过受信任插件根或已验证的安装绑定定位启动器,已停止;不访问网络,也不加载工作目录源码。');process.exit(127)}require(f);"
9
9
  ],
10
10
  "env": {
11
- "KB_PLUGIN_VERSION": "5.3.2"
11
+ "KB_PLUGIN_VERSION": "5.4.1"
12
12
  }
13
13
  }
14
14
  }
@@ -293,7 +293,112 @@ class ModuleBridge {
293
293
  if (req.method === 'POST' && /^\/api\/workflow\/workflow-tasks\/?$/.test(pathname)) {
294
294
  return this._proxyWorkflowTeamCreateTrusted(req, res, pathname, search);
295
295
  }
296
- return this.proxy(req, res, this._workflowApi(pathname) + (search || ''));
296
+ // Page-maintained maintenance registry: the repository path never comes
297
+ // from the browser. The shell resolves it from the registered project and
298
+ // attaches its runtime token; the module accepts a registration only with it.
299
+ if (req.method === 'POST' && /^\/api\/workflow\/maintenance\/repos(?:\/update)?\/?$/.test(pathname)) {
300
+ return this._proxyWorkflowMaintenanceRepoTrusted(req, res, pathname, search);
301
+ }
302
+ // A member's model names a Workbench profile and one of the models it lists. The shell verifies
303
+ // both (enabled, credentials configured, model listed), and attaches the token; the module
304
+ // trusts a model reference only with it.
305
+ if ((req.method === 'POST' && /^\/api\/workflow\/members\/?$/.test(pathname)) ||
306
+ (req.method === 'PATCH' && /^\/api\/workflow\/members\/[^/]+\/?$/.test(pathname))) {
307
+ return this._proxyWorkflowMemberTrusted(req, res, pathname, search);
308
+ }
309
+ // The shell has vetted the Origin before this point; the module's
310
+ // maintenance routes check it too, so it is forwarded rather than dropped.
311
+ const origin = String(req.headers.origin || '');
312
+ return this.proxy(req, res, this._workflowApi(pathname) + (search || ''), { extraHeaders: origin ? { Origin: origin } : {} });
313
+ }
314
+
315
+ // The JSON body of a request whose payload the shell rewrites before a trusted forward.
316
+ // Anything that is not an object (a bare null, a number) is treated as an empty body.
317
+ async _readForwardedBody(req, message) {
318
+ const chunks = [];
319
+ for await (const chunk of req) chunks.push(chunk);
320
+ let body = {};
321
+ try { body = chunks.length ? JSON.parse(Buffer.concat(chunks).toString('utf8')) : {}; }
322
+ catch { throw new DomainError('INVALID_ARGUMENT', message, { status: 400 }); }
323
+ return body && typeof body === 'object' && !Array.isArray(body) ? body : {};
324
+ }
325
+
326
+ async _proxyWorkflowMaintenanceRepoTrusted(req, res, pathname, search) {
327
+ const body = await this._readForwardedBody(req, '登记请求必须是合法 JSON。');
328
+ const forward = { ...body };
329
+ // Only the update of a registered repository needs no project: its path cannot change.
330
+ if (!/\/update\/?$/.test(pathname)) {
331
+ const projectId = typeof body.projectId === 'string' ? body.projectId : '';
332
+ let project = null;
333
+ try { project = projectId && this.workflowProjectResolver ? this.workflowProjectResolver({ projectId }) : null; }
334
+ catch (error) { if (!(error instanceof DomainError)) throw error; }
335
+ if (!project || typeof project.repoPath !== 'string' || !path.isAbsolute(project.repoPath)) {
336
+ throw new DomainError('PROJECT_NOT_FOUND', '找不到这个项目可用的仓库目录。请刷新页面后重新选择;项目的仓库路径在「项目」页面确认。', { status: 404 });
337
+ }
338
+ // The path is the shell's own resolution; whatever the page sent for it is replaced.
339
+ forward.projectId = project.projectId;
340
+ forward.repoPath = project.repoPath;
341
+ }
342
+ return this.proxy(req, res, this._workflowApi(pathname) + (search || ''), {
343
+ bodyOverride: Buffer.from(JSON.stringify(forward), 'utf8'),
344
+ extraHeaders: this.runtimeToken ? { 'X-KB-Runtime-Token': this.runtimeToken } : {},
345
+ });
346
+ }
347
+
348
+ // The Workbench profile a member selected, when it is enabled with configured credentials.
349
+ // `unavailable` means the Workbench could not be asked at all — a different failure from "not usable".
350
+ async _usableProfile(profileId) {
351
+ let response;
352
+ try { response = await this._fetch(`${this.terminalUrl}/api/claude-workbench/v1/profiles`); }
353
+ catch { return { unavailable: true }; }
354
+ if (!response.ok) return { unavailable: true };
355
+ const payload = await response.json().catch(() => null);
356
+ const list = Array.isArray(payload) ? payload : payload?.profiles;
357
+ const profile = Array.isArray(list) ? list.find(item => item && item.id === profileId) : null;
358
+ return { unavailable: false, profile: profile && profile.enabled && profile.credentialConfigured ? profile : null };
359
+ }
360
+
361
+ // The model a member may use under a profile: one the profile lists, or its default when nothing was
362
+ // chosen (a profile that lists no models offers only its default). Anything else is refused.
363
+ _profileModel(profile, requested) {
364
+ const listed = Array.isArray(profile.models?.list) ? profile.models.list.map(item => item && item.id).filter(id => typeof id === 'string' && id) : [];
365
+ const allowed = listed.length ? listed : [profile.models?.default].filter(id => typeof id === 'string' && id);
366
+ const chosen = requested === undefined || requested === null || requested === '' ? allowed[0] : requested;
367
+ if (typeof chosen !== 'string' || !allowed.includes(chosen)) {
368
+ throw new DomainError('INVALID_ARGUMENT', allowed.length
369
+ ? '所选模型不在这个档案的模型列表里,请重新选择。'
370
+ : '所选档案没有可用的模型,请先在系统面板的『模型供应商管理』里为它添加模型。', { status: 400 });
371
+ }
372
+ return chosen;
373
+ }
374
+
375
+ async _proxyWorkflowMemberTrusted(req, res, pathname, search) {
376
+ const body = await this._readForwardedBody(req, '成员请求必须是合法 JSON。');
377
+ // The browser names a profile; the model name and the driver are never its decision.
378
+ const forward = { ...body };
379
+ delete forward.model;
380
+ delete forward.driverId;
381
+ let trusted = false;
382
+ if (body.profileId === null || body.profileId === '') {
383
+ forward.profileId = null;
384
+ forward.model = null;
385
+ trusted = true;
386
+ } else if (body.profileId !== undefined) {
387
+ if (typeof body.profileId !== 'string') throw new DomainError('INVALID_ARGUMENT', '模型选择无效,请重新选择。', { status: 400 });
388
+ const { unavailable, profile } = await this._usableProfile(body.profileId);
389
+ if (unavailable) throw new DomainError('MODULE_UNREACHABLE', '暂时无法核对所选模型:工作台服务不可达,请恢复后重试。', { status: 503, retryable: true });
390
+ if (!profile) throw new DomainError('INVALID_ARGUMENT', '所选模型不可用:它已停用、凭据未配置或已被删除,请重新选择。', { status: 400 });
391
+ // 模型须是这个档案列出的一个;没有指定时用档案的默认模型。页面说了不算,档案说了算。
392
+ // The model must be one the profile lists; without a choice the profile's default is used. The profile decides, never the page.
393
+ forward.profileId = profile.id;
394
+ forward.model = this._profileModel(profile, body.model);
395
+ trusted = true;
396
+ }
397
+ // A request that names no model is proxied as before, without the token.
398
+ return this.proxy(req, res, this._workflowApi(pathname) + (search || ''), {
399
+ bodyOverride: Buffer.from(JSON.stringify(forward), 'utf8'),
400
+ extraHeaders: trusted && this.runtimeToken ? { 'X-KB-Runtime-Token': this.runtimeToken } : {},
401
+ });
297
402
  }
298
403
 
299
404
  async _proxyWorkflowTeamCreateTrusted(req, res, pathname, search) {
@@ -13,7 +13,9 @@ const definitions = {
13
13
  vectorHub: { option: '--vector-source', name: '@sanqianx/vector-hub', installName: '@sanqianx/vector-hub', required: ['dist/cjs/bin.js', 'dist/cjs/server/manager.js', 'ui/index.html'] },
14
14
  eventBridge: { option: '--bridge-source', name: '@sanqianx/ai-coding-event-bridge-console', installName: '@sanqianx/ai-coding-event-bridge-console', required: ['src/server.js', 'src/bridge/core/consumer-registry.js', 'console/index.html'] },
15
15
  engine: { option: '--engine-source', name: '@sanqianx/ai-coding-knowledge-engine', installName: '@sanqianx/ai-coding-knowledge-engine', required: ['src/bin.js', 'src/server.js', 'src/coordinator.js', 'src/analysis-worker.js', 'ui/index.html', 'ui/app.js', 'ui/app.css'] },
16
- workflow: { option: '--workflow-source', name: '@sanqianx/ai-coding-workflow', installName: '@sanqianx/ai-coding-workflow', required: ['src/bin.js', 'src/server.js', 'src/store.js', 'src/tasks.js', 'ui/index.html', 'ui/app.js'] },
16
+ // The workflow runtime ships its whole src tree too (0.3.0 added src/maintenance-registry.js):
17
+ // the refresh walker lists a newly shipped src file instead of letting it slip outside the gate.
18
+ workflow: { option: '--workflow-source', name: '@sanqianx/ai-coding-workflow', installName: '@sanqianx/ai-coding-workflow', required: ['src/bin.js', 'src/server.js', 'src/store.js', 'src/tasks.js', 'ui/index.html', 'ui/app.js'], files: ['src/'] },
17
19
  };
18
20
  function run(command, args, cwd) {
19
21
  const result = spawnSync(command, args, { cwd, windowsHide: true, encoding: 'utf8', maxBuffer: 16 * 1024 * 1024 });
@@ -146,6 +146,19 @@ function enforceSecurity(req, security) {
146
146
  }
147
147
  }
148
148
 
149
+ // "Origin equals Host" (above) lets a page that controls both names through.
150
+ // Writes under /api/workflow/* can now register local commands that run
151
+ // automatically, so they are held to a stricter rule: on a loopback bind the
152
+ // Host must name a loopback address, and a browser's Sec-Fetch-Site, when
153
+ // sent, must say same-origin or none. Non-browser clients send no
154
+ // Sec-Fetch-Site and are judged by Host alone.
155
+ function workflowWriteAllowed(req, security) {
156
+ const host = String(req.headers.host || '').toLowerCase();
157
+ if (security.loopbackBind && !/^(?:127\.0\.0\.1|localhost|\[::1\])(?::\d+)?$/.test(host)) return false;
158
+ const site = req.headers['sec-fetch-site'];
159
+ return site === undefined || site === 'same-origin' || site === 'none';
160
+ }
161
+
149
162
  function send(res, status, body, contentType = '') {
150
163
  if (res.writableEnded) return;
151
164
  const isBuffer = Buffer.isBuffer(body);
@@ -922,42 +935,50 @@ function createRequestHandler(runtime, options = {}) {
922
935
  const url = new URL(req.url, `http://${req.headers.host || `${host}:${port}`}`);
923
936
  const method = req.method || 'GET';
924
937
  const pathname = url.pathname;
938
+ if (!['GET', 'HEAD', 'OPTIONS'].includes(method) && pathname.startsWith('/api/workflow/') && !workflowWriteAllowed(req, security)) {
939
+ throw new DomainError('ORIGIN_FORBIDDEN', 'Workflow writes are allowed only for the same-origin page on a loopback host.', { status: 403 });
940
+ }
925
941
  if (method === 'GET' && pathname === '/api/registry/events') {
926
942
  return streamSse(res, write => runtime.registryEvents.subscribe(write));
927
943
  }
928
944
 
929
945
  const moduleUi = pathname.match(/^\/modules\/(terminal|vectorhub|eventbridge|engine)\/(.*)$/);
930
- if (moduleUi && method === 'GET') return runtime.moduleBridge.proxyModuleUi(req, res, moduleUi[1], moduleUi[2], url.search);
946
+ if (moduleUi && method === 'GET') return await runtime.moduleBridge.proxyModuleUi(req, res, moduleUi[1], moduleUi[2], url.search);
931
947
  if (pathname.startsWith('/api/engine/') || pathname === '/api/engine') {
932
948
  if (['/api/engine/runtime-config', '/api/engine/runtime-auth', '/api/engine/scopes', '/api/engine/control', '/api/engine/migrate'].includes(pathname)) throw new DomainError('FORBIDDEN', 'Runtime configuration is not exposed to browsers.', { status: 403 });
933
- return runtime.moduleBridge.proxyEngine(req, res, pathname, url.search);
949
+ return await runtime.moduleBridge.proxyEngine(req, res, pathname, url.search);
934
950
  }
935
951
 
936
952
  // ===== module bridge:壳 ↔ 模块(同源代理 + 聚合 + 登记/移除) =====
953
+ // 代理调用一律 `return await`:它们会异步抛错(例如受信转发拒绝了一个请求)。
954
+ // 不 await 时错误绕过下面的 catch,变成未处理的拒绝,进程会被终止。
955
+ // Every proxy call is `return await`ed: proxies reject asynchronously (a trusted
956
+ // forward refusing a request, for example). Without the await the rejection bypasses
957
+ // the catch below, becomes unhandled, and the process is terminated.
937
958
  if (pathname.startsWith('/api/terminal/') || pathname === '/api/terminal') {
938
959
  if (pathname.startsWith('/api/terminal/internal/')) throw new DomainError('FORBIDDEN', 'Internal module endpoints are not exposed to browsers.', { status: 403 });
939
- return runtime.moduleBridge.proxyTerminal(req, res, pathname, url.search);
960
+ return await runtime.moduleBridge.proxyTerminal(req, res, pathname, url.search);
940
961
  }
941
962
  if (pathname.startsWith('/api/vectorhub/') || pathname === '/api/vectorhub') {
942
963
  if (pathname.startsWith('/api/vectorhub/internal/')) throw new DomainError('FORBIDDEN', 'Internal module endpoints are not exposed to browsers.', { status: 403 });
943
- return runtime.moduleBridge.proxyVectorHub(req, res, pathname, url.search);
964
+ return await runtime.moduleBridge.proxyVectorHub(req, res, pathname, url.search);
944
965
  }
945
966
  if (pathname.startsWith('/api/eventbridge/') || pathname === '/api/eventbridge') {
946
967
  if (pathname.startsWith('/api/eventbridge/internal/')) throw new DomainError('FORBIDDEN', 'Internal module endpoints are not exposed to browsers.', { status: 403 });
947
- return runtime.moduleBridge.proxyEventBridge(req, res, pathname, url.search);
968
+ return await runtime.moduleBridge.proxyEventBridge(req, res, pathname, url.search);
948
969
  }
949
970
  // Fifth module (optional): team/workflow business API. The module's
950
971
  // own base is /api/workflow/v1; the shell rewrites /api/workflow/<rest>
951
972
  // to it. Internal (trusted-service) subroutes stay server-side only.
952
973
  if (pathname.startsWith('/api/workflow/') || pathname === '/api/workflow') {
953
974
  if (pathname.startsWith('/api/workflow/internal/')) throw new DomainError('FORBIDDEN', 'Internal module endpoints are not exposed to browsers.', { status: 403 });
954
- return runtime.moduleBridge.proxyWorkflow(req, res, pathname, url.search);
975
+ return await runtime.moduleBridge.proxyWorkflow(req, res, pathname, url.search);
955
976
  }
956
977
  // AI team page proxy: /workflow-ui/<asset> -> workflow module /<asset>.
957
978
  // GET-only, encoded-segment and api/internal segments rejected inside
958
979
  // proxyModuleUi; the module serves its own index.html at the root.
959
980
  const workflowUi = pathname.match(/^\/workflow-ui\/?(.*)$/);
960
- if (workflowUi && method === 'GET') return runtime.moduleBridge.proxyModuleUi(req, res, 'workflow', workflowUi[1], url.search);
981
+ if (workflowUi && method === 'GET') return await runtime.moduleBridge.proxyModuleUi(req, res, 'workflow', workflowUi[1], url.search);
961
982
  if (method === 'GET' && pathname === '/api/modules/health') {
962
983
  return send(res, 200, { ...await runtime.moduleBridge.modulesHealth(), ownership: runtime.ownership });
963
984
  }
@@ -1288,14 +1309,14 @@ function createRequestHandler(runtime, options = {}) {
1288
1309
  }
1289
1310
 
1290
1311
  if (method === 'POST' && (pathname === '/api/knowledge/search' || pathname === '/api/knowledge/ask')) {
1291
- if (runtime.analysisOwner !== 'legacy') return runtime.moduleBridge.proxyEngine(req, res, pathname.replace('/api/knowledge/', '/api/engine/'), url.search);
1312
+ if (runtime.analysisOwner !== 'legacy') return await runtime.moduleBridge.proxyEngine(req, res, pathname.replace('/api/knowledge/', '/api/engine/'), url.search);
1292
1313
  const body = await readJsonBody(req);
1293
1314
  const input = { projectId: body.projectId, projectSlug: body.projectSlug, repoPath: body.repoPath, query: body.query, limit: body.limit };
1294
1315
  const result = pathname.endsWith('/ask') ? await runtime.knowledgeRuntime.ask(input) : await runtime.knowledgeRuntime.search(input);
1295
1316
  return send(res, 200, result);
1296
1317
  }
1297
1318
  if (method === 'GET' && pathname === '/api/knowledge/entry') {
1298
- if (runtime.analysisOwner !== 'legacy') return runtime.moduleBridge.proxyEngine(req, res, '/api/engine/get', url.search);
1319
+ if (runtime.analysisOwner !== 'legacy') return await runtime.moduleBridge.proxyEngine(req, res, '/api/engine/get', url.search);
1299
1320
  const result = await runtime.knowledgeRuntime.get({
1300
1321
  projectId: url.searchParams.get('projectId') || '',
1301
1322
  projectSlug: url.searchParams.get('projectSlug') || '',
@@ -1305,7 +1326,7 @@ function createRequestHandler(runtime, options = {}) {
1305
1326
  return send(res, 200, result);
1306
1327
  }
1307
1328
  if (method === 'GET' && pathname === '/api/knowledge/history') {
1308
- if (runtime.analysisOwner !== 'legacy') return runtime.moduleBridge.proxyEngine(req, res, '/api/engine/history', url.search);
1329
+ if (runtime.analysisOwner !== 'legacy') return await runtime.moduleBridge.proxyEngine(req, res, '/api/engine/history', url.search);
1309
1330
  const result = await runtime.knowledgeRuntime.history({
1310
1331
  projectId: url.searchParams.get('projectId') || '',
1311
1332
  projectSlug: url.searchParams.get('projectSlug') || '',
@@ -1315,7 +1336,7 @@ function createRequestHandler(runtime, options = {}) {
1315
1336
  return send(res, 200, result);
1316
1337
  }
1317
1338
  if (method === 'GET' && pathname === '/api/knowledge/maintenance') {
1318
- if (runtime.analysisOwner !== 'legacy') return runtime.moduleBridge.proxyEngine(req, res, '/api/engine/health', url.search);
1339
+ if (runtime.analysisOwner !== 'legacy') return await runtime.moduleBridge.proxyEngine(req, res, '/api/engine/health', url.search);
1319
1340
  const projects = runtime.registryStore.listIds().map(projectId => ({ projectId, index: runtime.projectStore.readState(projectId).index }));
1320
1341
  return send(res, 200, { ok: true, schema: 'index-maintenance/v2', indexPath: runtime.layout.getIndexPath(), projects, active: runtime.indexService.pending.size > 0 });
1321
1342
  }
@@ -1372,7 +1393,7 @@ function createRequestHandler(runtime, options = {}) {
1372
1393
  // Bridge consumer wake-up (I-16): the notification body carries no
1373
1394
  // conversation truth — the durable journal is drained regardless.
1374
1395
  if (method === 'POST' && pathname === '/api/bridge/notify') {
1375
- if (runtime.analysisOwner !== 'legacy') return runtime.moduleBridge.proxyEngine(req, res, '/api/engine/bridge/notify', url.search);
1396
+ if (runtime.analysisOwner !== 'legacy') return await runtime.moduleBridge.proxyEngine(req, res, '/api/engine/bridge/notify', url.search);
1376
1397
  if (runtime.bridgeConsumerService) {
1377
1398
  runtime.bridgeConsumerService.handleNotification().catch(() => {
1378
1399
  // Drain failures are logged by the service; wake-up stays 204.
@@ -1741,6 +1762,7 @@ module.exports = {
1741
1762
  installProcessHandlers,
1742
1763
  mergeAiProfiles,
1743
1764
  requestOriginAllowed,
1765
+ workflowWriteAllowed,
1744
1766
  isLoopback,
1745
1767
  isProjectBusy,
1746
1768
  taskForProject,