@suifei/dsh-ai-team 0.4.49 → 0.4.50

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.
@@ -0,0 +1,38 @@
1
+ /**
2
+ * 初装默认项目 / 新建项目对话框的「默认工作目录」解析。
3
+ *
4
+ * 规则(用户裁定):
5
+ * 1. 只有**没有指定**项目工作目录时才用默认目录;
6
+ * 2. 项目一旦切换过工作目录,就按项目自己的目录执行(本模块只负责默认值);
7
+ * 3. 默认值不能是插件自己的数据目录,否则成员会退化成「在账本目录里干活」;
8
+ * 4. 系统目录(Windows / Program Files)不当作团队工作目录——桌面启动器的
9
+ * cwd 可能就是程序目录。
10
+ */
11
+
12
+ import { statSync } from 'node:fs';
13
+ import { sep } from 'node:path';
14
+
15
+ const SYSTEM_DIR = /^[a-z]:[\\/](windows|program files|program files \(x86\))([\\/]|$)/i;
16
+
17
+ const isDirectory = (value) => {
18
+ try { return statSync(value).isDirectory() === true; } catch { return false; }
19
+ };
20
+
21
+ /**
22
+ * @param {{ configured?: string, cwd?: string, home?: string, dataDir?: string }} input
23
+ * @returns {string} 绝对目录,找不到任何可用目录时返回空串
24
+ */
25
+ export function resolveDefaultWorkspace({ configured = '', cwd = '', home = '', dataDir = '' } = {}) {
26
+ const explicit = typeof configured === 'string' ? configured.trim() : '';
27
+ const candidates = [explicit, cwd, home];
28
+ for (const raw of candidates) {
29
+ if (typeof raw !== 'string' || raw === '') continue;
30
+ if (!isDirectory(raw)) continue;
31
+ // 插件数据目录永远不能当工作目录。
32
+ if (dataDir !== '' && (raw === dataDir || raw.startsWith(`${dataDir}${sep}`))) continue;
33
+ // 显式配置的目录由用户负责;自动探测到的系统目录一律跳过。
34
+ if (raw !== explicit && SYSTEM_DIR.test(raw)) continue;
35
+ return raw;
36
+ }
37
+ return '';
38
+ }
@@ -29,9 +29,9 @@ export class ProjectRegistry {
29
29
  }
30
30
  const projects = Array.isArray(parsed?.projects) && parsed.projects.length > 0
31
31
  ? parsed.projects.filter((project) => typeof project?.id === 'string' && project.id !== '')
32
- : [{ id: DEFAULT_PROJECT_ID, name: '我的项目', workspacePath: defaultWorkspacePath, createdAt: 0 }];
32
+ : [{ id: DEFAULT_PROJECT_ID, name: '我的项目', createdAt: 0 }];
33
33
  if (!projects.some((project) => project.id === DEFAULT_PROJECT_ID)) {
34
- projects.unshift({ id: DEFAULT_PROJECT_ID, name: '我的项目', workspacePath: defaultWorkspacePath, createdAt: 0 });
34
+ projects.unshift({ id: DEFAULT_PROJECT_ID, name: '我的项目', createdAt: 0 });
35
35
  }
36
36
  const active = projects.some((project) => project.id === parsed?.activeProjectId)
37
37
  ? parsed.activeProjectId
@@ -49,6 +49,16 @@ export class ProjectRegistry {
49
49
  return this.projects.map((project) => ({ ...project, active: project.id === this.activeProjectId }));
50
50
  }
51
51
 
52
+ /** 更新某个项目的工作目录(与账本的 project/workspace-changed 保持同步)。 */
53
+ setWorkspace(id, workspacePath) {
54
+ const project = this.projects.find((entry) => entry.id === id);
55
+ if (project === undefined) return false;
56
+ const next = typeof workspacePath === 'string' ? workspacePath : '';
57
+ if ((project.workspacePath ?? '') === next) return false;
58
+ project.workspacePath = next;
59
+ this.save();
60
+ return true;
61
+ }
52
62
  add({ id, name, createdAt, goal, workspacePath }) {
53
63
  if (typeof id !== 'string' || id === '') throw new Error('project id is required');
54
64
  if (!this.projects.some((project) => project.id === id)) {
@@ -1,4 +1,4 @@
1
- /**
1
+ /**
2
2
  * One Project runtime: its own ledger, TeamService and optional SSE/waker hooks.
3
3
  *
4
4
  * A Project is the isolation boundary required by the ledger writer: every
@@ -85,7 +85,9 @@ export class ProjectRuntime {
85
85
  type: 'project.create',
86
86
  actor: { kind: 'human', memberId: HUMAN_ID },
87
87
  projectId,
88
- payload: { id: projectId, name: projectName, goal: projectGoal, workspacePath },
88
+ // 播种是内部路径:允许先建一个「待设定目录」的默认项目,用户在首次使用
89
+ // 引导里选定目录后再 project.workspace.update。
90
+ payload: { id: projectId, name: projectName, goal: projectGoal, workspacePath, seed: true },
89
91
  });
90
92
  }
91
93
  await seedDefaultRoster(service, projectId, { humanId: HUMAN_ID });
@@ -498,9 +498,14 @@ export class TeamService {
498
498
  if (this.state.projects?.[id] !== undefined) {
499
499
  fail(ERRORS.CONFLICT, `project ${id} already exists`);
500
500
  }
501
- // 工作目录可空(稍后设置),但给了就必须存在——与 project.workspace.update
502
- // 的校验一致,否则成员激活会在一个不存在的 cwd 上失败。
501
+ // 工作目录**必需**(用户裁定:每个项目都必须指定目录):没有目录的项目里
502
+ // 成员无法激活、PMO 也无从派发,等于建了个用不了的项目。
503
+ // 例外只有内部播种(payload.seed):它先建出「待设定目录」的默认项目,
504
+ // 由首次使用引导补上目录,否则 boot 自己就会被这条校验挡住。
503
505
  const rawWorkspace = typeof payload.workspacePath === 'string' ? payload.workspacePath.trim() : '';
506
+ if (rawWorkspace === '' && payload.seed !== true) {
507
+ fail(ERRORS.INVALID_ARGUMENT, '工作目录是必填项:请选择一个已存在的目录作为项目工作区');
508
+ }
504
509
  if (rawWorkspace !== '') {
505
510
  let stat = null;
506
511
  try { stat = statSync(rawWorkspace); } catch { stat = null; }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suifei/dsh-ai-team",
3
- "version": "0.4.49",
3
+ "version": "0.4.50",
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",