@suifei/dsh-ai-team 0.4.74 → 0.4.76

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/client.js CHANGED
@@ -4402,7 +4402,7 @@ window.__ModuleLoader__.load({
4402
4402
  h('p', { className: 'at-modalmeta' }, t('workspaceDialogHint')),
4403
4403
  h('label', { className: 'at-field' }, h('span', null, t('workspace')),
4404
4404
  h('div', { className: 'at-inlineadd' },
4405
- h('input', { value: workspaceDraft, onChange: (event) => setWorkspaceDraft(event.target.value), placeholder: t('workspacePathPlaceholder'), autoFocus: true }),
4405
+ h('input', { value: workspaceDraft, onChange: (event) => setWorkspaceDraft(event.target.value), placeholder: data?.workspaceExample ?? t('workspacePathPlaceholder'), autoFocus: true }),
4406
4406
  h('button', { className: 'at-btn at-btn-small', type: 'button', onClick: pickProjectWorkspace }, t('workspaceChoose')))),
4407
4407
  workspaceError ? h('div', { className: 'at-modalerror', role: 'alert' }, workspaceError) : null,
4408
4408
  h('div', { className: 'at-modalactions' },
@@ -4423,7 +4423,7 @@ window.__ModuleLoader__.load({
4423
4423
  h('textarea', { value: nGoal, onChange: (event) => setNGoal(event.target.value) })),
4424
4424
  h('label', { className: 'at-field' }, h('span', null, t('workspace')),
4425
4425
  h('div', { className: 'at-inlineadd' },
4426
- h('input', { value: nWorkspace, onChange: (event) => setNWorkspace(event.target.value), placeholder: t('workspacePathPlaceholder') }),
4426
+ h('input', { value: nWorkspace, onChange: (event) => setNWorkspace(event.target.value), placeholder: data?.workspaceExample ?? t('workspacePathPlaceholder') }),
4427
4427
  h('button', { className: 'at-btn at-btn-small', type: 'button', onClick: pickNewWorkspace }, t('workspaceChoose')))),
4428
4428
  nError ? h('div', { className: 'at-modalerror', role: 'alert' }, nError) : null,
4429
4429
  h('div', { className: 'at-modalactions' },
package/index.js CHANGED
@@ -16,6 +16,7 @@ import z from '@deepseek-ai/schemastery';
16
16
  import { ProjectRuntime } from './lib/host/project-runtime.js';
17
17
  import { ProjectRegistry } from './lib/host/project-registry.js';
18
18
  import { resolveDefaultWorkspace } from './lib/host/default-workspace.js';
19
+ import { hostPlatform, workspaceExample } from './lib/host/workspace-path.js';
19
20
  import { migrateLegacyNamespace, resolveProfile } from './lib/ledger/namespace.js';
20
21
  import { ids } from './lib/domain/ids.js';
21
22
  import { MemberRuntime, validatePermissionProfile } from './lib/runtime/member-runtime.js';
@@ -49,6 +50,7 @@ import { createTeamTool } from './lib/host/member-tools.js';
49
50
  import { describeTaskContext, describeWake, planWakes } from './lib/host/waker.js';
50
51
  import { describeCauseChain } from './lib/runtime/error-chain.js';
51
52
  import { classifyWakeFailure } from './lib/runtime/wake-failure.js';
53
+ import { registerShellGuard } from './lib/runtime/shell-guard.js';
52
54
  import { aggregatePeople } from './lib/host/people-view.js';
53
55
  import { riskView } from './lib/host/risk-view.js';
54
56
  import { weeklyView } from './lib/host/weekly-view.js';
@@ -97,6 +99,9 @@ export const Config = z.object({
97
99
  skilloptJudgeVotes: z.number().step(1).min(3).max(9).default(3),
98
100
  // 初装默认项目与「新建项目」对话框的默认工作目录;留空则取宿主 cwd(见 boot)。
99
101
  defaultWorkspace: z.string().default(''),
102
+ // 成员 shell 风险守卫:'warn' 只记诊断(默认),'block' 直接拒绝,'off' 不介入。
103
+ // 实机事故:成员写 serve.ps1 并用隐藏窗口拉起常驻进程,触发杀软报毒。
104
+ shellGuard: z.union(['off', 'warn', 'block']).default('warn'),
100
105
  });
101
106
 
102
107
  /**
@@ -424,6 +429,33 @@ export function apply(ctx, config = {}) {
424
429
  // 都会在这里露出原始错误码——不再靠日志里那句
425
430
  // 「subagent X is unavailable」猜。
426
431
  await probePersistence(value.sessionIds);
432
+ // 路由过期对账:账本重新折叠时,凡是「上次失败的路由 ≠ 当前配置」的成员
433
+ // 都会带上 routeStale(老数据无需迁移脚本),但那条标记只有**新配置事件**
434
+ // 才会触发唤醒计划,失败成员又被排除在自动唤醒之外。所以 boot 后补一次
435
+ // 强制重建,让升级本身就把卡住的成员救回来。
436
+ for (const runtime of value.runtimes.values()) {
437
+ for (const member of Object.values(runtime.service.state.members ?? {})) {
438
+ if (member.kind !== 'agent' || member.routeStale !== true) continue;
439
+ if (member.status === 'retired') continue;
440
+ void activateMember({
441
+ payload: {
442
+ memberId: member.id,
443
+ force: true,
444
+ prompt: '模型/提供方已切换,会话按新路由重建。先读 tasks 与 thread 的当前状态,继续未完成的工作,不要重复已完成的事。',
445
+ },
446
+ }, runtime).then((result) => {
447
+ diag.append({
448
+ ev: result?.error === undefined ? 'member.route-reconciled' : 'member.route-reconcile.fail',
449
+ projectId: runtime.id,
450
+ memberId: member.id,
451
+ sessionId: result?.member?.sessionId ?? null,
452
+ error: result?.error ?? null,
453
+ });
454
+ }).catch((error) => {
455
+ diag.append({ ev: 'member.route-reconcile.fail', projectId: runtime.id, memberId: member.id, message: error?.message ?? String(error) });
456
+ });
457
+ }
458
+ }
427
459
  for (const runtime of value.runtimes.values()) {
428
460
  for (const member of Object.values(runtime.service.state.members ?? {})) {
429
461
  if (member.kind === 'agent' && typeof member.sessionId === 'string') {
@@ -1577,6 +1609,29 @@ export function apply(ctx, config = {}) {
1577
1609
  diag.append({ ev: 'team.tool.fail', message: error?.message ?? String(error) });
1578
1610
  console.warn('[ai-team] team tool registration failed:', error?.message ?? error);
1579
1611
  }
1612
+ // 成员 shell 风险守卫:实机事故是「成员写 serve.ps1 + Start-Process -WindowStyle
1613
+ // Hidden」被杀软报毒。默认只记录(warn),配置 shellGuard='block' 才拒绝。
1614
+ let disposeShellGuard = () => {};
1615
+ try {
1616
+ const memberSessions = () => {
1617
+ const ids = new Set();
1618
+ for (const runtime of booted?.runtimes?.values() ?? []) {
1619
+ for (const member of Object.values(runtime.service.state.members ?? {})) {
1620
+ if (typeof member?.sessionId === 'string' && member.sessionId !== '') ids.add(member.sessionId);
1621
+ }
1622
+ }
1623
+ return ids;
1624
+ };
1625
+ disposeShellGuard = registerShellGuard({
1626
+ tools: tools ?? serviceOf(ctx, 'tools'),
1627
+ memberSessions,
1628
+ diag,
1629
+ mode: config.shellGuard ?? 'warn',
1630
+ });
1631
+ diag.append({ ev: 'shell.guard', mode: config.shellGuard ?? 'warn' });
1632
+ } catch (error) {
1633
+ diag.append({ ev: 'shell.guard.fail', message: error?.message ?? String(error) });
1634
+ }
1580
1635
 
1581
1636
  // 历史归档修复:成员是 host 的子会话,`archived-session-gate` 会沿 subagent
1582
1637
  // 血缘上溯,父会话被归档即拒绝整条血缘 —— 回合以 {kind:'blocked'} 结束且不发
@@ -2192,6 +2247,10 @@ export function apply(ctx, config = {}) {
2192
2247
  // 新建项目对话框的默认「工作目录」:初装默认项目也用它,避免
2193
2248
  // 建出一个没有工作目录的项目(成员只能在插件数据目录里跑)。
2194
2249
  defaultWorkspace: booted.defaultWorkspace ?? '',
2250
+ // 目录输入框的示例必须跟宿主平台一致:WSL/Linux 要 /mnt/... 形式,
2251
+ // 给 Windows 的 D:/... 在 POSIX 上只是带反斜杠的文件名。
2252
+ platform: hostPlatform(),
2253
+ workspaceExample: workspaceExample(),
2195
2254
  // 首次使用:当前项目还没有工作目录时,界面必须先让用户设定目录。
2196
2255
  setupRequired: (bootstrap.project?.workspacePath ?? '') === '',
2197
2256
  inbox,
@@ -2530,6 +2589,7 @@ export function apply(ctx, config = {}) {
2530
2589
  // session-controller graph half-disposed and broke plugin toggles.
2531
2590
  disposed = true;
2532
2591
  try { removeDiagSink(); } catch { /* sink already replaced */ }
2592
+ try { disposeShellGuard(); } catch { /* already disposed */ }
2533
2593
  const cleanup = [];
2534
2594
  for (const client of sseClients) {
2535
2595
  try { client.res.end(); } catch { /* socket already gone */ }
@@ -30,7 +30,8 @@ const isDirectory = (value) => {
30
30
  * @returns {string} 绝对目录;找不到任何可用目录时返回空串。
31
31
  * 注意:返回的路径**可能尚不存在**——那是 `~/works` 建议值,调用方负责创建。
32
32
  */
33
- export function resolveDefaultWorkspace({ configured = '', cwd = '', home = '', dataDir = '', excludeRoots = [] } = {}) {
33
+ export function resolveDefaultWorkspace({ configured = '', cwd = '', home = '', dataDir = '', excludeRoots = [], exists = undefined } = {}) {
34
+ const isDir = typeof exists === 'function' ? exists : isDirectory;
34
35
  const explicit = typeof configured === 'string' ? configured.trim() : '';
35
36
  const under = (value, root) => {
36
37
  if (typeof root !== 'string' || root === '') return false;
@@ -45,12 +46,17 @@ export function resolveDefaultWorkspace({ configured = '', cwd = '', home = '',
45
46
  for (const root of excludeRoots) if (under(value, root)) return true;
46
47
  return false;
47
48
  };
49
+ // UNC 路径(`\\wsl.localhost\…`、`\\server\share`)不作自动建议:它通常来自启动器
50
+ // 的 cwd(从 WSL 目录里启动桌面端时就是这样),并不是用户的项目目录,而且成员
51
+ // 工具在 UNC 上读写既慢又容易出权限问题。显式配置不受此限。
52
+ const isUnc = (value) => /^\\\\[^\\]/.test(value);
48
53
  for (const raw of [explicit, cwd]) {
49
54
  if (typeof raw !== 'string' || raw === '') continue;
50
- if (!isDirectory(raw)) continue;
55
+ if (!isDir(raw)) continue;
51
56
  if (excluded(raw)) continue;
52
- // 显式配置的目录由用户负责;自动探测到的系统目录一律跳过。
57
+ // 显式配置的目录由用户负责;自动探测到的系统目录/UNC 一律跳过。
53
58
  if (raw !== explicit && SYSTEM_DIR.test(raw)) continue;
59
+ if (raw !== explicit && isUnc(raw)) continue;
54
60
  return raw;
55
61
  }
56
62
  // 兜底:用户主目录下的 `works` 子目录(跨平台由调用方传入 homedir)。
@@ -1,3 +1,4 @@
1
+ import { checkWorkspacePath } from './workspace-path.js';
1
2
  import { existsSync, mkdirSync, readFileSync, realpathSync, statSync, writeFileSync } from 'node:fs';
2
3
  import pathDefault from 'node:path';
3
4
  import { ERRORS, fail } from '../domain/errors.js';
@@ -503,6 +504,10 @@ export class TeamService {
503
504
  // 例外只有内部播种(payload.seed):它先建出「待设定目录」的默认项目,
504
505
  // 由首次使用引导补上目录,否则 boot 自己就会被这条校验挡住。
505
506
  const rawWorkspace = typeof payload.workspacePath === 'string' ? payload.workspacePath.trim() : '';
507
+ if (rawWorkspace !== '') {
508
+ const shape = checkWorkspacePath(rawWorkspace);
509
+ if (shape.ok !== true) fail(ERRORS.INVALID_ARGUMENT, shape.message, { suggestion: shape.suggestion ?? null });
510
+ }
506
511
  if (rawWorkspace === '' && payload.seed !== true) {
507
512
  fail(ERRORS.INVALID_ARGUMENT, '工作目录是必填项:请选择一个已存在的目录作为项目工作区');
508
513
  }
@@ -568,6 +573,10 @@ export class TeamService {
568
573
  fail(ERRORS.INVALID_ARGUMENT, 'workspacePath is required');
569
574
  }
570
575
  const workspacePath = payload.workspacePath.trim();
576
+ // 平台形态先判:WSL/Linux 宿主上 `D:\works\x` 只是带反斜杠的相对文件名,
577
+ // 直接做 statSync 只会得到「不存在」,完全指不出该怎么改。
578
+ const shape = checkWorkspacePath(workspacePath);
579
+ if (shape.ok !== true) fail(ERRORS.INVALID_ARGUMENT, shape.message, { suggestion: shape.suggestion ?? null });
571
580
  // P5b:目录必须真实存在且是目录——配置不存在的目录会让成员会话 cwd
572
581
  // 无效、回合直接失败(用户实证:working-directory: directory does not exist)。
573
582
  let stat = null;
@@ -0,0 +1,94 @@
1
+ /**
2
+ * 工作目录的**平台形态**校验。
3
+ *
4
+ * 实机事故:DSH web 在 WSL(Linux)里启动,用户在目录框里填了 `D:\works\localservice`
5
+ * ——Windows 形态。POSIX 上这只是一串**带反斜杠的文件名**(相对路径),既不是那个盘,
6
+ * 也不会给出有用的报错;成员会话随后在错误目录里干活。
7
+ *
8
+ * 这里只判断「路径形态与宿主平台是否匹配」,存在性仍由调用方的 statSync 负责。
9
+ */
10
+
11
+ import { readFileSync } from 'node:fs';
12
+
13
+ const WINDOWS_DRIVE = /^[A-Za-z]:[\\/]/;
14
+ const WINDOWS_DRIVE_BARE = /^[A-Za-z]:$/;
15
+ const UNC = /^\\\\[^\\]/;
16
+ const BACKSLASH = /\\/;
17
+
18
+ /** 把 `D:\works\a` 这类 Windows 路径转换成 WSL 的 `/mnt/d/works/a`。 */
19
+ export function windowsToWsl(raw) {
20
+ const match = /^([A-Za-z]):[\\/]*(.*)$/.exec(String(raw ?? ''));
21
+ if (match === null) return null;
22
+ const drive = match[1].toLowerCase();
23
+ const rest = match[2].replace(/\\/g, '/').replace(/\/+/g, '/').replace(/\/$/, '');
24
+ return rest === '' ? `/mnt/${drive}` : `/mnt/${drive}/${rest}`;
25
+ }
26
+
27
+ /** 宿主是否运行在 WSL 里(`/proc/version` 含 microsoft)。读不到就按普通 Linux 处理。 */
28
+ export function isWsl() {
29
+ if (process.platform !== 'linux') return false;
30
+ try {
31
+ return /microsoft/i.test(readFileSync('/proc/version', 'utf8'));
32
+ } catch {
33
+ return false;
34
+ }
35
+ }
36
+
37
+ /** 'win32' | 'wsl' | 'posix' */
38
+ export function hostPlatform(platform = process.platform, wsl = undefined) {
39
+ if (platform === 'win32') return 'win32';
40
+ if (platform === 'linux' && (wsl ?? isWsl()) === true) return 'wsl';
41
+ return 'posix';
42
+ }
43
+
44
+ /**
45
+ * 校验路径形态是否与宿主平台兼容。
46
+ * @returns {{ ok: true } | { ok: false, code: string, message: string, suggestion?: string }}
47
+ */
48
+ export function checkWorkspacePath(raw, options = {}) {
49
+ const value = typeof raw === 'string' ? raw.trim() : '';
50
+ if (value === '') return { ok: false, code: 'E_EMPTY', message: '工作目录不能为空' };
51
+ const platform = options.platform ?? process.platform;
52
+ const host = hostPlatform(platform, options.wsl);
53
+ if (host === 'win32') {
54
+ // Windows 上 POSIX 绝对路径(`/mnt/d/x`)不是有效盘符路径;Node 会把它解释成
55
+ // 当前盘根目录,容易落进意料之外的位置。直接给出明确提示。
56
+ if (value.startsWith('/') && !WINDOWS_DRIVE.test(value)) {
57
+ return {
58
+ ok: false,
59
+ code: 'E_PLATFORM_PATH',
60
+ message: `工作目录「${value}」是 POSIX 路径,而当前宿主是 Windows;请改用盘符路径,例如 D:/works/my-project`,
61
+ };
62
+ }
63
+ return { ok: true };
64
+ }
65
+ // POSIX(含 WSL):Windows 形态一律拒绝,并给出可用的替代写法。
66
+ if (UNC.test(value)) {
67
+ return {
68
+ ok: false,
69
+ code: 'E_PLATFORM_PATH',
70
+ message: `工作目录「${value}」是 Windows UNC 路径(\\\\wsl.localhost\\…),Linux 宿主无法使用;请改用挂载点路径,例如 /home/<user>/works`,
71
+ };
72
+ }
73
+ if (WINDOWS_DRIVE.test(value) || WINDOWS_DRIVE_BARE.test(value) || (BACKSLASH.test(value) && !value.startsWith('/'))) {
74
+ const suggestion = windowsToWsl(value);
75
+ const hint = host === 'wsl' && suggestion !== null
76
+ ? `请改用 WSL 内的挂载路径:${suggestion}`
77
+ : '请改用 POSIX 路径,例如 /home/<user>/works/my-project';
78
+ return {
79
+ ok: false,
80
+ code: 'E_PLATFORM_PATH',
81
+ message: `工作目录「${value}」是 Windows 路径,而当前宿主是 Linux;${hint}`,
82
+ ...(suggestion === null ? {} : { suggestion }),
83
+ };
84
+ }
85
+ return { ok: true };
86
+ }
87
+
88
+ /** 目录输入框的示例路径(与宿主平台一致)。 */
89
+ export function workspaceExample(platform = process.platform, options = {}) {
90
+ const host = hostPlatform(platform, options.wsl);
91
+ if (host === 'win32') return 'D:/works/my-project';
92
+ if (host === 'wsl') return '/mnt/d/works/my-project';
93
+ return '/home/user/works/my-project';
94
+ }
@@ -835,6 +835,17 @@ export function applyEvent(state, event) {
835
835
  const nextConfig = isPlainObject(payload.config) ? payload.config : (isPlainObject(payload.after) ? payload.after : null);
836
836
  if (nextConfig === null) return advance(state, event);
837
837
  const version = Number.isSafeInteger(payload.configVersion) ? payload.configVersion : member.configVersion ?? 0;
838
+ // 会话停在旧路由的两种证据:
839
+ // 1) 本次配置事件明确标了 routeChanged;
840
+ // 2) 上次失败记录里的 provider/model 与**新配置**不一致——说明会话仍在用
841
+ // 旧路由(实机:失败记录 provider=deepseek-official,配置已改 qwen)。
842
+ // 第 2 条只依赖账本自身,因此**重新折叠历史**就能把已切换过的成员标出来,
843
+ // 不需要额外的迁移脚本。
844
+ const lastFailure = member.lastFailure;
845
+ const routeDiffersFromFailure = lastFailure !== undefined && lastFailure !== null
846
+ && typeof lastFailure.provider === 'string' && lastFailure.provider !== ''
847
+ && (lastFailure.provider !== (nextConfig.provider ?? '')
848
+ || (lastFailure.model ?? null) !== (nextConfig.model ?? null));
838
849
  return advance(state, event, {
839
850
  members: {
840
851
  ...state.members,
@@ -849,7 +860,7 @@ export function applyEvent(state, event) {
849
860
  // agentOptions 里,追加 model/selection 只改模型名、改不了路由,于是
850
861
  // 表现成「模型换成了 Qwen,provider 还是 deepseek-official → 缺 key」。
851
862
  // 标记过期,下一次唤醒直接重建会话让新路由生效。
852
- routeStale: payload.routeChanged === true ? true : member.routeStale === true,
863
+ routeStale: payload.routeChanged === true || routeDiffersFromFailure ? true : member.routeStale === true,
853
864
  },
854
865
  },
855
866
  });
@@ -0,0 +1,102 @@
1
+ /**
2
+ * 成员 shell 风险守卫。
3
+ *
4
+ * 实机事故:成员把项目名 `localservice` 误读成「Windows 常驻服务」,在工作目录里写了
5
+ * `tools/serve.ps1`,再用 `Start-Process -WindowStyle Hidden -ExecutionPolicy Bypass`
6
+ * 拉起一个隐藏窗口的常驻进程——这正是杀软启发式最敏感的组合(隐藏 PowerShell + 自启
7
+ * 脚本 + 本地监听),用户那台机器因此报毒。
8
+ *
9
+ * 插件本身给成员的是 full-access(产品前提),但「悄悄起隐藏常驻进程」不该是默认行为。
10
+ * 这里在 `tools.guard` 上挂一道守卫:
11
+ * - `warn`(默认):记录一条可见的 `.fail` 诊断行,放行;
12
+ * - `block`:直接拒绝该次工具调用,理由回给成员;
13
+ * - `off`:完全不介入。
14
+ *
15
+ * 只对**团队成员会话**生效:Human 自己的会话、host 会话不受影响。
16
+ */
17
+
18
+ /** 高风险命令特征:隐藏窗口常驻进程、绕过执行策略、计划任务/服务注册、管道执行下载内容。 */
19
+ const PATTERNS = [
20
+ { id: 'hidden-window', re: /-windowstyle\s+hidden|-w\s+hidden/i, reason: '以隐藏窗口启动进程(杀软高危特征)' },
21
+ { id: 'bypass-policy', re: /-executionpolicy\s+bypass/i, reason: '绕过 PowerShell 执行策略' },
22
+ { id: 'encoded-command', re: /-(encodedcommand|enc)\s+[A-Za-z0-9+/=]{40,}/i, reason: '以 Base64 编码执行命令' },
23
+ { id: 'persist-service', re: /\b(sc\s+create|new-service|schtasks\s+\/create|reg\s+add\s+[^\n]*\\run)\b/i, reason: '注册系统服务/计划任务/开机自启' },
24
+ { id: 'pipe-to-shell', re: /\b(curl|wget|invoke-webrequest|iwr)\b[^\n|]*\|\s*(sh|bash|powershell|pwsh)\b/i, reason: '把下载内容直接管道给 shell 执行' },
25
+ { id: 'script-host', re: /\b(wscript|cscript|mshta)\b/i, reason: '用脚本宿主执行(wscript/cscript/mshta)' },
26
+ ];
27
+
28
+ /**
29
+ * 检查一段 shell 命令是否命中高风险特征。
30
+ * @returns {{ id: string, reason: string, excerpt: string } | null}
31
+ */
32
+ export function inspectShellCommand(command) {
33
+ if (typeof command !== 'string' || command.trim() === '') return null;
34
+ const text = command.replace(/\s+/g, ' ');
35
+ for (const pattern of PATTERNS) {
36
+ if (!pattern.re.test(text)) continue;
37
+ const at = text.search(pattern.re);
38
+ const excerpt = text.slice(Math.max(0, at - 40), Math.min(text.length, at + 120));
39
+ return { id: pattern.id, reason: pattern.reason, excerpt };
40
+ }
41
+ return null;
42
+ }
43
+
44
+ /** 从工具入参里取出可能承载命令的字符串。 */
45
+ export function commandOfToolCall(name, args) {
46
+ if (typeof name !== 'string') return '';
47
+ const fields = Array.isArray(args) ? [] : Object.entries(args ?? {});
48
+ const keys = ['command', 'cmd', 'script', 'code', 'input', 'args'];
49
+ for (const [key, value] of fields) {
50
+ if (typeof value !== 'string' || value === '') continue;
51
+ if (keys.includes(key)) return value;
52
+ }
53
+ // 有些 shell 工具把命令放在数组参数里。
54
+ for (const [, value] of fields) {
55
+ if (Array.isArray(value) && value.every((item) => typeof item === 'string')) return value.join(' ');
56
+ }
57
+ return '';
58
+ }
59
+
60
+ const SHELL_TOOLS = new Set(['pwsh', 'shell', 'bash', 'terminal', 'run_code', 'powershell']);
61
+
62
+ /**
63
+ * 注册守卫。只对成员会话生效,返回 disposer。
64
+ *
65
+ * @param {object} options
66
+ * @param {object} options.tools `ctx.tools`
67
+ * @param {() => Set<string>} options.memberSessions 当前团队成员会话 id 集合
68
+ * @param {(row: object) => void} options.diag
69
+ * @param {'off'|'warn'|'block'} options.mode
70
+ */
71
+ export function registerShellGuard({ tools, memberSessions, diag, mode = 'warn' }) {
72
+ if (mode === 'off') return () => {};
73
+ if (tools === undefined || typeof tools.guard !== 'function') return () => {};
74
+ return tools.guard((execution) => {
75
+ try {
76
+ const name = execution?.name;
77
+ if (!SHELL_TOOLS.has(String(name))) return undefined;
78
+ const sessionId = execution?.agent?.id;
79
+ const members = memberSessions();
80
+ if (typeof sessionId !== 'string' || !members.has(sessionId)) return undefined;
81
+ const command = commandOfToolCall(name, execution?.arguments);
82
+ const hit = inspectShellCommand(command);
83
+ if (hit === null) return undefined;
84
+ diag?.append?.({
85
+ ev: 'member.shell-risk.fail',
86
+ memberId: null,
87
+ sessionId,
88
+ tool: String(name),
89
+ pattern: hit.id,
90
+ action: mode,
91
+ excerpt: hit.excerpt,
92
+ });
93
+ if (mode === 'block') {
94
+ return `已阻止:${hit.reason}。若要启动常驻进程,请让 Human 明确授权后手动执行,或改用可见窗口。`;
95
+ }
96
+ return undefined;
97
+ } catch {
98
+ // 守卫自身出错绝不能阻断工具调用。
99
+ return undefined;
100
+ }
101
+ });
102
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suifei/dsh-ai-team",
3
- "version": "0.4.74",
3
+ "version": "0.4.76",
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",