@suifei/dsh-ai-team 0.4.98 → 0.4.99

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.
Files changed (3) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/index.js +26 -2
  3. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.99 - 2026-11-15
4
+
5
+ **宿主边界:两处代码审视发现的缺陷**
6
+
7
+ - **插件路由过 Connection 信任栅栏**:webServer 承载层不做认证与 Host/Origin 校验(官方文档:「载体不拥有认证或
8
+ Origin 策略」),宿主自带插件(open-in-app、inspector)都在路由入口调用 `ctx.connection.requestRejection(req)`,
9
+ 本插件漏了——未认证、来源不可信的请求能读看板、以 Human 身份执行命令。实测 rc.3 上的 0.4.98:跨站 `text/plain`
10
+ POST 返回 200,账本 9 → 10 事件。现在所有 `/ai-team` 路由(含 SSE)先过栅栏,被拒按 401/403 返回、不进处理器;
11
+ 栅栏服务缺失则 503,不静默放行。`inject` 声明 `connection`;诊断 `http.rejected.fail`;
12
+ - **boot 落定前卸载不再残留账本锁**:teardown 只按 `booted` 关账本,而 `booted` 要等 boot 落定才赋值——在途 boot
13
+ 打开的账本没人关,落定后还会照常对账、激活成员、起 PMO tick。同进程下一次组合读到 pid=本进程的锁,永久
14
+ `E_LOCKED`(project ledger is locked by another writer),只能重启宿主。现在 teardown 等待在途 boot;boot
15
+ 落定时若已卸载,关掉它打开的账本、不再接线(诊断 `boot.after-dispose`);探针期间卸载同样止步;
16
+ - 测试:`node --test` **343 通过 / 1 跳过**;新增 `test/host-boundary.test.js`(2 例,去掉修复即失败:栅栏例 401/403
17
+ 均不进账本、缺栅栏 503;卸载例 3/3 复现 `E_LOCKED`);
18
+ - E2E(dsh CLI 建独立 profile `aiteam-boundary`,隔离 DSH_HOME,装 `npm pack` 出的包):
19
+ - rc.1:无凭据 401、冒充 Host 403、跨站 POST 403 且账本 9 → 9、带会话 cookie 的命令 200;
20
+ - rc.3:无凭据 401、冒充 Host 403、跨站 POST 403(rc.3 宿主在该环境不打印 token 地址,带凭据路径未测);
21
+ - 卸载竞态未能实机触发:这两个宿主不监听 profile 配置文件,运行时开关只有 agent 的 `plugin_manager`,
22
+ 时间窗(约 100 ms)无法从外部卡住;以单测的确定性复现为准。
23
+
3
24
  ## 0.4.98 - 2026-11-15
4
25
 
5
26
  **#18 审计复核:确认属实的五处修复**
package/index.js CHANGED
@@ -69,7 +69,7 @@ export const name = 'ai-team';
69
69
  /** The workbench only makes sense where the Web carrier exists. */
70
70
  // cordis 按 inject 保证属性注入;未声明的属性访问会抛错,因此这里列全插件
71
71
  // 实际使用的服务(含可选服务:缺失时 serviceOf 回退 ctx.get 并返回 undefined)。
72
- export const inject = ['webServer', 'permissionPresets', 'sandboxPolicy', 'tools', 'shell', 'agents', 'subagents', 'sessions'];
72
+ export const inject = ['webServer', 'connection', 'permissionPresets', 'sandboxPolicy', 'tools', 'shell', 'agents', 'subagents', 'sessions'];
73
73
 
74
74
  // 版本号只有一处真源:package.json。硬编码字面量曾让 /health 在升版后仍报旧版本,
75
75
  // 误导「运行实例是否加载了新代码」的判断。
@@ -463,12 +463,21 @@ export function apply(ctx, config = {}) {
463
463
  const ready = access.ok
464
464
  ? Promise.resolve().then(() => boot(diag, config))
465
465
  .then(async (value) => {
466
+ // 卸载先于 boot 落定:teardown 当时看不到 booted,账本没人关;同进程下一次
467
+ // 组合会读到 pid=本进程的锁而永久 E_LOCKED。这里补关,且不再接线。
468
+ if (disposed) {
469
+ await Promise.allSettled([...value.runtimes.values()].map((runtime) => runtime.close()));
470
+ diag.append({ ev: 'boot.after-dispose', projects: value.runtimes.size });
471
+ return null;
472
+ }
466
473
  booted = value;
467
474
  // 决定性探针:真实读一次已知会话。冷恢复失败的两种表现
468
475
  // (`agents.resume` 报 persistence 未配置、`coldResume` 报 notFound)
469
476
  // 都会在这里露出原始错误码——不再靠日志里那句
470
477
  // 「subagent X is unavailable」猜。
471
478
  await probePersistence(value.sessionIds);
479
+ // 探针期间被卸载:teardown 已按 booted 关了账本,后面的对账/唤醒/巡检不得再跑。
480
+ if (disposed) return null;
472
481
  // 路由过期对账:账本重新折叠时,凡是「上次失败的路由 ≠ 当前配置」的成员
473
482
  // 都会带上 routeStale(老数据无需迁移脚本),但那条标记只有**新配置事件**
474
483
  // 才会触发唤醒计划,失败成员又被排除在自动唤醒之外。所以 boot 后补一次
@@ -2162,6 +2171,19 @@ export function apply(ctx, config = {}) {
2162
2171
  path: '/ai-team',
2163
2172
  handler: async (req, res) => {
2164
2173
  try {
2174
+ // 信任栅栏:webServer 承载层不做认证与 Host/Origin 校验,路由各自过 Connection 的
2175
+ // 栅栏(宿主 open-in-app / inspector 同一做法)。缺了它,任何网页都能以 Human 身份
2176
+ // 跨站 POST 命令(实测桌面版:Origin: https://evil.example 的 text/plain POST 直达处理器)。
2177
+ // 栅栏缺失即拒绝,不静默放行。
2178
+ const connection = serviceOf(ctx, 'connection');
2179
+ if (typeof connection?.requestRejection !== 'function') {
2180
+ return send(res, { error: { code: 'E_TRUST_FENCE_UNAVAILABLE', message: 'connection service is unavailable' } }, 503);
2181
+ }
2182
+ const rejection = connection.requestRejection(req);
2183
+ if (rejection !== undefined) {
2184
+ diag.append({ ev: 'http.rejected.fail', status: rejection, method: req.method, path: String(req.url ?? '').split('?')[0], origin: req.headers?.origin ?? null });
2185
+ return send(res, { error: { code: rejection === 401 ? 'E_UNAUTHENTICATED' : 'E_FORBIDDEN', message: 'request rejected by the connection trust fence' } }, rejection);
2186
+ }
2165
2187
  const url = new URL(req.url, 'http://local');
2166
2188
  await ready;
2167
2189
  if (booted === null) {
@@ -2856,7 +2878,9 @@ export function apply(ctx, config = {}) {
2856
2878
  try { removeDiagSink(); } catch { /* sink already replaced */ }
2857
2879
  try { disposeShellGuard(); } catch { /* already disposed */ }
2858
2880
  try { disposeStopGuard(); } catch { /* already disposed */ }
2859
- const cleanup = [];
2881
+ // 在途的 boot 也算本组合的资源:等它落定(落定时见 disposed 会自行关账本),
2882
+ // 否则下一组合抢在关锁之前打开同一账本。
2883
+ const cleanup = [ready.then(() => undefined, () => undefined)];
2860
2884
  for (const client of sseClients) {
2861
2885
  try { client.res.end(); } catch { /* socket already gone */ }
2862
2886
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suifei/dsh-ai-team",
3
- "version": "0.4.98",
3
+ "version": "0.4.99",
4
4
  "type": "module",
5
5
  "description": "文渊阁 (Wenyuan Pavilion) — AI Team mode for DeepSeek Harness: concurrent projects, owned tasks, threads, inbox and an append-only team ledger",
6
6
  "license": "MIT",