@suifei/dsh-ai-team 0.4.48 → 0.4.49
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/CHANGELOG.md +15 -0
- package/client.js +4481 -4465
- package/index.js +50 -4
- package/lib/host/project-registry.js +6 -3
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* ledger/domain service is the only writer and the Host never fakes work.
|
|
10
10
|
*/
|
|
11
11
|
import { homedir } from 'node:os';
|
|
12
|
-
import { join } from 'node:path';
|
|
12
|
+
import { join, sep } from 'node:path';
|
|
13
13
|
import { fileURLToPath } from 'node:url';
|
|
14
14
|
import { existsSync, readFileSync, renameSync, statSync, writeFileSync } from 'node:fs';
|
|
15
15
|
import z from '@deepseek-ai/schemastery';
|
|
@@ -92,6 +92,8 @@ export const Config = z.object({
|
|
|
92
92
|
skilloptTimeoutMs: z.number().step(1).min(10_000).max(600_000).default(120_000),
|
|
93
93
|
// Darwin paired judge:独立子代理票数,奇数 ≥3(接近平局可升 5)。
|
|
94
94
|
skilloptJudgeVotes: z.number().step(1).min(3).max(9).default(3),
|
|
95
|
+
// 初装默认项目与「新建项目」对话框的默认工作目录;留空则取宿主 cwd(见 boot)。
|
|
96
|
+
defaultWorkspace: z.string().default(''),
|
|
95
97
|
});
|
|
96
98
|
|
|
97
99
|
/**
|
|
@@ -170,7 +172,7 @@ function profileName() {
|
|
|
170
172
|
* A torn tail is repaired by the writer; the repair is recorded as a system
|
|
171
173
|
* event so the append-only history explains the gap.
|
|
172
174
|
*/
|
|
173
|
-
async function boot(diag) {
|
|
175
|
+
async function boot(diag, config = {}) {
|
|
174
176
|
const dataDir = join(dshHome(), 'ai-team', profileName());
|
|
175
177
|
// 旧版本把 desktop profile 的数据写进了 `ai-team/default/`(profile 名只认
|
|
176
178
|
// `--profile`,而桌面启动器按位置参数传)。这里做一次性、数据驱动、可回退的
|
|
@@ -181,7 +183,24 @@ async function boot(diag) {
|
|
|
181
183
|
if (dataDir !== legacyDir && resolvedProfile().source === 'argv-path') {
|
|
182
184
|
migrateLegacyNamespace({ fromDir: legacyDir, toDir: dataDir, diag });
|
|
183
185
|
}
|
|
184
|
-
|
|
186
|
+
// 默认工作目录:配置项 → 宿主 cwd → 用户主目录。cwd 不能是插件数据目录
|
|
187
|
+
// (否则又退化成「成员在账本目录里干活」),系统目录也不当作团队工作目录。
|
|
188
|
+
const resolveDefaultWorkspace = () => {
|
|
189
|
+
const configured = typeof config?.defaultWorkspace === 'string' ? config.defaultWorkspace.trim() : '';
|
|
190
|
+
const systemish = (value) => /^[a-z]:[\\/](windows|program files|program files \(x86\))([\\/]|$)/i.test(value);
|
|
191
|
+
for (const candidate of [configured, process.cwd(), homedir()]) {
|
|
192
|
+
if (typeof candidate !== 'string' || candidate === '') continue;
|
|
193
|
+
try {
|
|
194
|
+
if (statSync(candidate).isDirectory() !== true) continue;
|
|
195
|
+
} catch { continue }
|
|
196
|
+
if (candidate === dataDir || candidate.startsWith(dataDir + sep)) continue;
|
|
197
|
+
if (candidate !== configured && systemish(candidate)) continue;
|
|
198
|
+
return candidate;
|
|
199
|
+
}
|
|
200
|
+
return '';
|
|
201
|
+
};
|
|
202
|
+
const defaultWorkspace = resolveDefaultWorkspace();
|
|
203
|
+
const registry = ProjectRegistry.load(dataDir, { defaultWorkspacePath: defaultWorkspace });
|
|
185
204
|
const runtimes = new Map();
|
|
186
205
|
for (const project of registry.list()) {
|
|
187
206
|
const runtime = await ProjectRuntime.open({
|
|
@@ -194,6 +213,29 @@ async function boot(diag) {
|
|
|
194
213
|
});
|
|
195
214
|
runtimes.set(project.id, runtime);
|
|
196
215
|
}
|
|
216
|
+
// 升级路径:旧版本初装时给过一个**没有工作目录**的默认项目。对仍然空白的项目
|
|
217
|
+
// 补上默认目录(有任务/有对话的项目不动——那可能是用户特意留空的)。
|
|
218
|
+
if (defaultWorkspace !== '') {
|
|
219
|
+
for (const runtime of runtimes.values()) {
|
|
220
|
+
const project = runtime.service.state.projects?.[runtime.id];
|
|
221
|
+
if (project === undefined) continue;
|
|
222
|
+
if (typeof project.workspacePath === 'string' && project.workspacePath.trim() !== '') continue;
|
|
223
|
+
const tasks = Object.values(runtime.service.state.tasks ?? {}).filter((task) => task.tombstone !== true);
|
|
224
|
+
const threads = Object.keys(runtime.service.state.threads ?? {});
|
|
225
|
+
if (tasks.length > 0 || threads.length > 0) continue;
|
|
226
|
+
try {
|
|
227
|
+
await runtime.service.dispatch({
|
|
228
|
+
type: 'project.workspace.update',
|
|
229
|
+
payload: { workspacePath: defaultWorkspace },
|
|
230
|
+
actor: { kind: 'human', memberId: runtime.service.humanId() ?? 'mem_human' },
|
|
231
|
+
projectId: runtime.id,
|
|
232
|
+
});
|
|
233
|
+
diag?.append({ ev: 'project.workspace.backfilled', projectId: runtime.id, workspacePath: defaultWorkspace });
|
|
234
|
+
} catch (error) {
|
|
235
|
+
diag?.append({ ev: 'project.workspace.backfill.fail', projectId: runtime.id, message: error?.message ?? String(error) });
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
197
239
|
const activeProjectId = registry.activeProjectId;
|
|
198
240
|
const runtime = runtimes.get(activeProjectId) ?? runtimes.values().next().value;
|
|
199
241
|
diag?.append({
|
|
@@ -212,6 +254,7 @@ async function boot(diag) {
|
|
|
212
254
|
ledger: runtime.ledger,
|
|
213
255
|
service: runtime.service,
|
|
214
256
|
dataDir,
|
|
257
|
+
defaultWorkspace,
|
|
215
258
|
};
|
|
216
259
|
}
|
|
217
260
|
|
|
@@ -323,7 +366,7 @@ export function apply(ctx, config = {}) {
|
|
|
323
366
|
sandboxPolicy: serviceOf(ctx, 'sandboxPolicy'),
|
|
324
367
|
});
|
|
325
368
|
const ready = access.ok
|
|
326
|
-
? Promise.resolve().then(() => boot(diag))
|
|
369
|
+
? Promise.resolve().then(() => boot(diag, config))
|
|
327
370
|
.then(async (value) => {
|
|
328
371
|
booted = value;
|
|
329
372
|
for (const runtime of value.runtimes.values()) {
|
|
@@ -1991,6 +2034,9 @@ export function apply(ctx, config = {}) {
|
|
|
1991
2034
|
inbox.sort((left, right) => (right.createdAt ?? 0) - (left.createdAt ?? 0));
|
|
1992
2035
|
return send(res, {
|
|
1993
2036
|
...bootstrap,
|
|
2037
|
+
// 新建项目对话框的默认「工作目录」:初装默认项目也用它,避免
|
|
2038
|
+
// 建出一个没有工作目录的项目(成员只能在插件数据目录里跑)。
|
|
2039
|
+
defaultWorkspace: booted.defaultWorkspace ?? '',
|
|
1994
2040
|
inbox,
|
|
1995
2041
|
inboxUnread: inbox.filter((item) => item.state === 'unread').length,
|
|
1996
2042
|
projects: booted.registry.list()
|
|
@@ -10,7 +10,10 @@ export class ProjectRegistry {
|
|
|
10
10
|
this.activeProjectId = activeProjectId ?? DEFAULT_PROJECT_ID;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
static load(rootDir) {
|
|
13
|
+
static load(rootDir, options = {}) {
|
|
14
|
+
// 初装时会给一个默认项目;它必须有工作目录,否则成员会话的 cwd 只能落到
|
|
15
|
+
// 插件数据目录(workspace attach 会被拒,成员也在错误目录里干活)。
|
|
16
|
+
const defaultWorkspacePath = typeof options.defaultWorkspacePath === 'string' ? options.defaultWorkspacePath : '';
|
|
14
17
|
mkdirSync(rootDir, { recursive: true });
|
|
15
18
|
const file = join(rootDir, 'projects.json');
|
|
16
19
|
let parsed;
|
|
@@ -26,9 +29,9 @@ export class ProjectRegistry {
|
|
|
26
29
|
}
|
|
27
30
|
const projects = Array.isArray(parsed?.projects) && parsed.projects.length > 0
|
|
28
31
|
? parsed.projects.filter((project) => typeof project?.id === 'string' && project.id !== '')
|
|
29
|
-
: [{ id: DEFAULT_PROJECT_ID, name: '我的项目', createdAt: 0 }];
|
|
32
|
+
: [{ id: DEFAULT_PROJECT_ID, name: '我的项目', workspacePath: defaultWorkspacePath, createdAt: 0 }];
|
|
30
33
|
if (!projects.some((project) => project.id === DEFAULT_PROJECT_ID)) {
|
|
31
|
-
projects.unshift({ id: DEFAULT_PROJECT_ID, name: '我的项目', createdAt: 0 });
|
|
34
|
+
projects.unshift({ id: DEFAULT_PROJECT_ID, name: '我的项目', workspacePath: defaultWorkspacePath, createdAt: 0 });
|
|
32
35
|
}
|
|
33
36
|
const active = projects.some((project) => project.id === parsed?.activeProjectId)
|
|
34
37
|
? parsed.activeProjectId
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@suifei/dsh-ai-team",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.49",
|
|
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",
|