@sanqianx/project-knowledge 5.3.2 → 5.4.0

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.0",
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,15 @@
1
1
  # Changelog
2
2
 
3
+ ## [5.4.0] - 2026-11-26
4
+
5
+ - AI 团队的维护仓库和工具改为在页面上登记(「自动维护」页:登记仓库 → 登记工具 → 新建维护计划),不再手工编辑 `maintenance.json`,也不需要重启。登记仓库时只选项目,仓库路径由知识库解析后随受信转发交给工作流模块。从 `0.2.3` 升级时,旧登记文件在首次启动时导入一次,已有的维护计划和运行记录继续有效。
6
+ - 页签改名:「任务」→「团队任务」,「仓库维护」→「自动维护」,里面的条目叫「维护计划」。工具可以编辑和删除;仓库的分支、远端和推送授权可以修改,立即生效。
7
+ - 成员的「模型」改为下拉,选项是知识库里已启用且凭据已配置的档案。保存时知识库核对档案,再把模型名交给工作流模块;模块只采信受信来源的模型引用。目前只保存引用,没有功能会按它启动模型。
8
+ - 安全:`/api/workflow/*` 的写请求要求回环 Host,浏览器请求的 `Sec-Fetch-Site` 须为同源;放行的 Origin 转发给工作流模块核对。
9
+ - 修复:模块代理的异步报错(例如受信转发拒绝了一个请求)没有被请求处理器接住,会成为未处理的拒绝并终止进程;现在统一返回错误响应。
10
+ - 测试:新增全新实例在页面上登记并运行的浏览器全流程;测试用的服务不再指向工作流模块的默认端口。运行清单列出工作流模块的全部文件。
11
+ - 固定 Workflow `0.3.0`。
12
+
3
13
  ## [5.3.2] - 2026-11-26
4
14
 
5
15
  - 仓库目录按约定重构,产品行为与 5.3.1 相同:产品源码归入 `src/` 并按领域分目录,网页资源归入 `resources/ui/`,回归测试归入 `tests/` 且不再打进发布包。npm 包内的路径随之变化(`_site/` → `src/`,`ui/` → `resources/ui/`)。已登记仓库的受管提交钩子会在启动时自动重新绑定到新的脚本路径。
@@ -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": "40429a508830b7b074d412b9407aa0c9b42936ab742f3583d07e66fc92532bf8",
15
+ "plugins/project-knowledge/.codex-plugin/plugin.json": "9fff44a93149679c47c379bf3a32fbbd9e55aa1fdb793b89d08188c1148074d1",
16
+ "plugins/project-knowledge/.mcp.json": "c74f2bdd8a1e9777a956ea763f4fa9d159be5744b7204d250062d8173c805c58",
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.0",
325
325
  "files": {
326
326
  "LICENSE": "c1b9df1275e769f3dbab000d1e457a2d4b0f28eb5da6c77e48dc37eeba202ed7",
327
- "README.md": "0ee483525831969a3855d942cbb2388d0c6a72e160bfa3c4fd33ee1bc729d1c7",
328
- "docs/contract.md": "2b750eae9998f2ee19953769c56fb046e31cfa105ad2eee351ec63764bb3572f",
329
- "package.json": "a2a86aabd55bc62c62d6c0953fd30cbedcac7ba9f33854298e843c47f29225c7",
327
+ "README.md": "35b7178c7647a837b752d9fbaadfd794f8b10a7ab73a652a4561dea8f7617fb1",
328
+ "docs/contract.md": "cc5fef48a687e754f8e3d4bc8af75b845534a7e829f887ba4e78514e4a1bd6ad",
329
+ "package.json": "e218363490845f95d9633a75d7352d4fffb4cfc6d914a8376333b8082a2f31e3",
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": "54e7a0022a1cd88f64e7557b323f8dc94e813abe80260c52ae8c93e372e128d0",
346
+ "ui/app.js": "9fae8c934fd9ebf67e3df9378d16f8e8fa5a7309a128e31a0d353bf364d96b46",
347
+ "ui/index.html": "2f41ba6969c7061e085f16c01b64c5aa35dbc3e7a234e31e0b542329a1bd2905",
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.0",
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": {
@@ -92,7 +92,7 @@
92
92
  "@modelcontextprotocol/sdk": "1.29.0",
93
93
  "@sanqianx/ai-coding-event-bridge-console": "0.7.5-rc.1",
94
94
  "@sanqianx/ai-coding-knowledge-engine": "0.4.1",
95
- "@sanqianx/ai-coding-workflow": "0.2.3",
95
+ "@sanqianx/ai-coding-workflow": "0.3.0",
96
96
  "@sanqianx/vector-hub": "1.0.8-rc.9",
97
97
  "buffer": "^6.0.3",
98
98
  "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.0",
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.0",
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.0"
12
12
  }
13
13
  }
14
14
  }
@@ -293,7 +293,96 @@ 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. The shell verifies the
303
+ // profile (enabled, credentials configured), injects its default model and
304
+ // attaches the token; the module 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
+ async _proxyWorkflowMemberTrusted(req, res, pathname, search) {
362
+ const body = await this._readForwardedBody(req, '成员请求必须是合法 JSON。');
363
+ // The browser names a profile; the model name and the driver are never its decision.
364
+ const forward = { ...body };
365
+ delete forward.model;
366
+ delete forward.driverId;
367
+ let trusted = false;
368
+ if (body.profileId === null || body.profileId === '') {
369
+ forward.profileId = null;
370
+ forward.model = null;
371
+ trusted = true;
372
+ } else if (body.profileId !== undefined) {
373
+ if (typeof body.profileId !== 'string') throw new DomainError('INVALID_ARGUMENT', '模型选择无效,请重新选择。', { status: 400 });
374
+ const { unavailable, profile } = await this._usableProfile(body.profileId);
375
+ if (unavailable) throw new DomainError('MODULE_UNREACHABLE', '暂时无法核对所选模型:工作台服务不可达,请恢复后重试。', { status: 503, retryable: true });
376
+ if (!profile) throw new DomainError('INVALID_ARGUMENT', '所选模型不可用:它已停用、凭据未配置或已被删除,请重新选择。', { status: 400 });
377
+ forward.profileId = profile.id;
378
+ forward.model = profile.models?.default || null;
379
+ trusted = true;
380
+ }
381
+ // A request that names no model is proxied as before, without the token.
382
+ return this.proxy(req, res, this._workflowApi(pathname) + (search || ''), {
383
+ bodyOverride: Buffer.from(JSON.stringify(forward), 'utf8'),
384
+ extraHeaders: trusted && this.runtimeToken ? { 'X-KB-Runtime-Token': this.runtimeToken } : {},
385
+ });
297
386
  }
298
387
 
299
388
  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,