@suifei/dsh-ai-team 0.4.47 → 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 +23 -0
- package/client.js +4481 -4465
- package/index.js +67 -17
- package/lib/host/project-registry.js +6 -3
- package/lib/skillopt/review-runner.js +4 -1
- 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()) {
|
|
@@ -1172,14 +1215,7 @@ export function apply(ctx, config = {}) {
|
|
|
1172
1215
|
} catch (error) {
|
|
1173
1216
|
diag.append({ ev: 'skillopt.reviewer.refresh.fail', projectId: runtime.id, message: error?.message ?? String(error) });
|
|
1174
1217
|
}
|
|
1175
|
-
const
|
|
1176
|
-
service: runtime.service,
|
|
1177
|
-
projectRuntime: runtime,
|
|
1178
|
-
job: { id: jobId, skillPath, skillName: skillPath.split(/[\\/]/).slice(-2, -1)[0] ?? skillPath, before: text0, candidate },
|
|
1179
|
-
actor,
|
|
1180
|
-
votes: config.skilloptJudgeVotes ?? 3,
|
|
1181
|
-
});
|
|
1182
|
-
writeJob(runtime.dir, {
|
|
1218
|
+
const jobRecord = {
|
|
1183
1219
|
id: jobId,
|
|
1184
1220
|
state: 'judging',
|
|
1185
1221
|
project: runtime.dir,
|
|
@@ -1188,20 +1224,31 @@ export function apply(ctx, config = {}) {
|
|
|
1188
1224
|
dimension: `dim${dimension.id} ` + dimension.name,
|
|
1189
1225
|
before: text0,
|
|
1190
1226
|
candidate,
|
|
1227
|
+
createdAt: Date.now(),
|
|
1228
|
+
};
|
|
1229
|
+
const started = await startReview({
|
|
1230
|
+
service: runtime.service,
|
|
1231
|
+
projectRuntime: runtime,
|
|
1232
|
+
job: jobRecord,
|
|
1233
|
+
actor,
|
|
1234
|
+
votes: config.skilloptJudgeVotes ?? 3,
|
|
1235
|
+
// 卡片一创建就把 job 落盘:进程若在投递评审请求期间崩溃,下一轮仍能
|
|
1236
|
+
// 从 job 里读到卡 id,超时终态会把它收口,而不是留下孤儿卡。
|
|
1237
|
+
onCard: async (reviewTaskId) => {
|
|
1238
|
+
writeJob(runtime.dir, { ...jobRecord, reviewTaskId, reviewOrders: [], cardCreatedAt: Date.now() });
|
|
1239
|
+
},
|
|
1240
|
+
});
|
|
1241
|
+
writeJob(runtime.dir, {
|
|
1242
|
+
...jobRecord,
|
|
1191
1243
|
reviewTaskId: started.reviewTaskId,
|
|
1192
1244
|
reviewerId: started.reviewerId,
|
|
1193
1245
|
reviewOrders: started.orders,
|
|
1194
|
-
createdAt: Date.now(),
|
|
1195
1246
|
});
|
|
1196
1247
|
diag.append({ ev: 'skillopt.job.started', jobId, project: runtime.dir, skillPath, dimension: `dim${dimension.id}`, reviewTaskId: started.reviewTaskId, votes: started.orders.length });
|
|
1197
1248
|
return [
|
|
1198
1249
|
`[skillopt optimize] reviewing job=${jobId} target=dim${dimension.id} ${dimension.name} baseline=${rubric.total}`,
|
|
1199
1250
|
` reviewer=${REVIEWER_NAME} card=${started.reviewTaskId} votes=${started.orders.length} (blind A/B, odd majority)`,
|
|
1200
1251
|
' call skillopt_jobs to collect the verdict when the reviewer answers.',
|
|
1201
|
-
].join('\n'); return [
|
|
1202
|
-
`[skillopt optimize] started job=${jobId} target=dim${dimension.id} ${dimension.name} baseline=${rubric.total}` ,
|
|
1203
|
-
' two-phase async: the PMO tick harvests generator -> judges -> keep/revert and appends results.tsv',
|
|
1204
|
-
' poll with skillopt_jobs',
|
|
1205
1252
|
].join('\n');
|
|
1206
1253
|
},
|
|
1207
1254
|
});
|
|
@@ -1987,6 +2034,9 @@ export function apply(ctx, config = {}) {
|
|
|
1987
2034
|
inbox.sort((left, right) => (right.createdAt ?? 0) - (left.createdAt ?? 0));
|
|
1988
2035
|
return send(res, {
|
|
1989
2036
|
...bootstrap,
|
|
2037
|
+
// 新建项目对话框的默认「工作目录」:初装默认项目也用它,避免
|
|
2038
|
+
// 建出一个没有工作目录的项目(成员只能在插件数据目录里跑)。
|
|
2039
|
+
defaultWorkspace: booted.defaultWorkspace ?? '',
|
|
1990
2040
|
inbox,
|
|
1991
2041
|
inboxUnread: inbox.filter((item) => item.state === 'unread').length,
|
|
1992
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
|
|
@@ -30,7 +30,7 @@ export async function ensureReviewer({ service, projectRuntime, actor }) {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
/** 创建评审卡(task)并投递 N 条盲评请求给评审成员。 */
|
|
33
|
-
export async function startReview({ service, projectRuntime, job, actor, votes }) {
|
|
33
|
+
export async function startReview({ service, projectRuntime, job, actor, votes, onCard = null }) {
|
|
34
34
|
const reviewer = await ensureReviewer({ service, projectRuntime, actor });
|
|
35
35
|
if (reviewer === undefined || reviewer === null) throw new Error('reviewer member unavailable');
|
|
36
36
|
const count = reviewVoteCount(votes ?? 3);
|
|
@@ -50,6 +50,9 @@ export async function startReview({ service, projectRuntime, job, actor, votes }
|
|
|
50
50
|
});
|
|
51
51
|
const reviewTaskId = created?.task?.id ?? created?.id ?? null;
|
|
52
52
|
if (typeof reviewTaskId !== 'string') throw new Error('review card creation failed');
|
|
53
|
+
// 卡片一创建就把 id 交回调用方落盘:进程若在「投递评审请求」期间崩溃,
|
|
54
|
+
// 调用方手里已经有卡 id,随后的超时终态能把它收口,而不是留下孤儿卡。
|
|
55
|
+
if (typeof onCard === 'function') await onCard(reviewTaskId);
|
|
53
56
|
const orders = [];
|
|
54
57
|
for (let index = 0; index < count; index++) {
|
|
55
58
|
const order = Math.random() < 0.5 ? 'ab' : 'ba';
|
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",
|