@suifei/dsh-ai-team 0.4.163 → 0.4.165
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 +8 -0
- package/README.md +6 -2
- package/index.js +48 -29
- package/lib/host/pmo.js +10 -5
- package/lib/host/project-registry.js +109 -109
- package/lib/host/service.js +2 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.165 - 2026-12-04
|
|
4
|
+
|
|
5
|
+
- 编制巡检的连续窗口按新入账的序号统计提交、验收和退回。宿主重启、跳过窗口或账本水位失效时,在诊断记录中标出新起点。感谢 @buger-gif 提供验收流量与编制巡检的对照场景(#116)。
|
|
6
|
+
|
|
7
|
+
## 0.4.164 - 2026-12-04
|
|
8
|
+
|
|
9
|
+
- 运行中的常规项目可以在关闭 PMO 自动时开启只读编制巡检。诊断日志同时记录 PMO 状态、验收流量、积压、槽位和建议。关闭 PMO 后建议仅用于诊断采样。感谢 @buger-gif 提供编制巡检和真实验收队列场景(#116)。
|
|
10
|
+
|
|
3
11
|
## 0.4.163 - 2026-12-04
|
|
4
12
|
|
|
5
13
|
- `/ai-team 开工` 根据目标建议团队和一张可独立验收的首发样稿。项目、编制和首发任务在同一次确认中落地,任务走文渊阁现有派发与验收流程。项目登记失败后重试可沿用已落盘的原卡。感谢 @buger-gif 提供从一句目标到建队派活的场景(#121)。
|
package/README.md
CHANGED
|
@@ -37,6 +37,8 @@
|
|
|
37
37
|
|
|
38
38
|
## 最近更新
|
|
39
39
|
|
|
40
|
+
- **巡检连续窗口精确对账**(0.4.165)。连续采样按两次账本水位之间的新增记录统计提交、验收和退回。巡检在首次启动及采样中断后标出新的起点。感谢 [@buger-gif](https://github.com/buger-gif),[#116](https://github.com/suifei/dsh-ai-team/issues/116)。
|
|
41
|
+
- **手动调度项目也能巡检编制**(0.4.164)。打开巡检设置后,即使关闭 PMO 自动,也可按窗口观察待验收任务、验收流量和代理树槽位。采样建议留在诊断日志。感谢 [@buger-gif](https://github.com/buger-gif),[#116](https://github.com/suifei/dsh-ai-team/issues/116)。
|
|
40
42
|
- **一句目标开工**(0.4.163)。在 DSH 会话输入 `/ai-team 开工 目标`,可一起核对预设、编制、首发样稿、执行人和验收条件。确认后创建项目并派发首发任务。感谢 [@buger-gif](https://github.com/buger-gif),[#121](https://github.com/suifei/dsh-ai-team/issues/121)。
|
|
41
43
|
- **会话里建卡和分派**(0.4.162)。可核对整批任务的执行人、交付标准和独立验收项,再一次确认到文渊阁。待领取的原卡也能在会话里分派。感谢 [@buger-gif](https://github.com/buger-gif),[#121](https://github.com/suifei/dsh-ai-team/issues/121)。
|
|
42
44
|
- **会话一次确认多项编制调整**(0.4.161)。增员、改岗位和原任务交接可进入同一份草稿,核对整组后一次写入。感谢 [@buger-gif](https://github.com/buger-gif),[#121](https://github.com/suifei/dsh-ai-team/issues/121)。
|
|
@@ -202,7 +204,9 @@ const svg = HashAvatar.svg('墨渊', { gender: 'male', age: 'middle', race: 'asi
|
|
|
202
204
|
|
|
203
205
|
### 只读编制巡检试跑
|
|
204
206
|
|
|
205
|
-
在当前 DSH profile 的 `ai-team` 配置中设 `staffingReviewMinutes: 180` 和 `diagLevel: full`
|
|
207
|
+
在当前 DSH profile 的 `ai-team` 配置中设 `staffingReviewMinutes: 180` 和 `diagLevel: full` 后,运行中的普通项目会随现有巡检周期采样,每个时间窗口记录一次。关闭 PMO 自动时,采样建议只写入诊断日志。暂停项目会暂停巡检,`staffingReviewMinutes: 0`(默认)关闭采样。诊断日志中的 `pmo.staffing.review` 记录采样时的 `pmoAuto`、岗位已分配队列、可认领与待验收队列、最长及平均等待,以及采样窗口内每位成员的提交、验收和退回。返工率按退回的本窗口提交除以本窗口提交数计算,零样本为空。
|
|
208
|
+
|
|
209
|
+
连续窗口按 `afterSeq` 到 `headSeq` 之间新入账的记录统计提交、验收和退回。`afterSeq` 是上一条采样的账本水位。首次采样、重启或窗口中断时,`afterSeq` 为 `null`,按 `(since, now]` 的时间范围开启一段新记录。项目级 `acceptanceActivity` 包含已离队成员和人工处理的结果。通过次数包含人工自验,日志另外列出自验次数。
|
|
206
210
|
|
|
207
211
|
巡检还会记录没有合格验收人的任务 ID 和在队成员运行回合数。宿主提供 `capacityOf` 时,`host-live` 表示当前代理树的实时槽位快照,`occupiedSlots` 和 `remainingSlots` 分别记录占用和余量。`host` 表示这棵树的容量回执,`default` 表示默认估计。这两种来源的占用和余量字段为空。宿主释放槽位后,插件优先补投本树排队最久的成员。加人建议会提示采样时的槽位不足,长期无人可验收的任务也会进入现有补位建议。
|
|
208
212
|
|
|
@@ -453,7 +457,7 @@ round-19 DeepSeek + Zhipu 双 provider
|
|
|
453
457
|
| 贡献者 | 贡献 | 带来的进展 |
|
|
454
458
|
|---|---|---|
|
|
455
459
|
| [@idontlikefruit](https://github.com/idontlikefruit) | 受阻状态的三组复现输入 [#115](https://github.com/suifei/dsh-ai-team/issues/115) | 统一看板徽标、读屏和分组统计的受阻判定,保留历史依赖 |
|
|
456
|
-
| [@buger-gif](https://github.com/buger-gif) | 编制巡检、离队交接案例 [#116](https://github.com/suifei/dsh-ai-team/issues/116)、[#117](https://github.com/suifei/dsh-ai-team/issues/117),派发空转记录 [#120](https://github.com/suifei/dsh-ai-team/issues/120),会话按目标建队开工、指定人数、按目标补位、调整编制与任务分派场景 [#121](https://github.com/suifei/dsh-ai-team/issues/121) |
|
|
460
|
+
| [@buger-gif](https://github.com/buger-gif) | 编制巡检、离队交接案例 [#116](https://github.com/suifei/dsh-ai-team/issues/116)、[#117](https://github.com/suifei/dsh-ai-team/issues/117),派发空转记录 [#120](https://github.com/suifei/dsh-ai-team/issues/120),会话按目标建队开工、指定人数、按目标补位、调整编制与任务分派场景 [#121](https://github.com/suifei/dsh-ai-team/issues/121) | 统一认领与离队顺序,减少派发空转。手动调度的项目可按相连的账本水位对照验收流量与代理树槽位。在 DSH 会话按目标核对团队和首发样稿后一次确认开工,也可调整编制、交接原任务或分派已有卡片 |
|
|
457
461
|
| [@Estelle00](https://github.com/Estelle00) | DSH 0.2.3 启动 503 的复现和桌面验证 [#122](https://github.com/suifei/dsh-ai-team/issues/122) | 接入新版会话鉴权接口,恢复工作台初始化,并在 Alpha 宿主验证看板登录 |
|
|
458
462
|
| [@phm101299-ui](https://github.com/phm101299-ui) | PMO 冷恢复的复现、根因和桌面验证 [#112](https://github.com/suifei/dsh-ai-team/issues/112) | 让原 PMO 在宿主重启后带着模型路由继续工作,保留成员关系和任务 |
|
|
459
463
|
| [@godfay-g](https://github.com/godfay-g) | 技能目录和 ZIP 的导入建议 [#109](https://github.com/suifei/dsh-ai-team/issues/109) | 成员与自定义人才可在文渊阁选择已安装的技能或导入完整技能包。0.4.151 统一新建人才的导入入口,并由文渊阁直接安装整包 |
|
package/index.js
CHANGED
|
@@ -1395,6 +1395,47 @@ export function apply(ctx, config = {}) {
|
|
|
1395
1395
|
diag.append({ ev: 'blueprint.advance.fail', projectId: runtime.id, message: error?.message ?? String(error) });
|
|
1396
1396
|
}
|
|
1397
1397
|
};
|
|
1398
|
+
const inspectStaffing = (projectRuntime) => {
|
|
1399
|
+
const staffingState = projectRuntime.service.state;
|
|
1400
|
+
const project = staffingState.projects?.[projectRuntime.id];
|
|
1401
|
+
if (disposed || !project || project.status === 'archived' || project.runState === 'stopped') return [];
|
|
1402
|
+
const pmoAuto = project.pmoAuto !== false;
|
|
1403
|
+
const now = Date.now();
|
|
1404
|
+
const reviewInterval = (config.staffingReviewMinutes ?? 0) * 60_000;
|
|
1405
|
+
const reviewWindow = diag.level === 'full' && reviewInterval > 0 ? Math.floor(now / reviewInterval) : null;
|
|
1406
|
+
const previous = pmoStaffingReviewWindows.get(projectRuntime.id);
|
|
1407
|
+
const reviewDue = reviewWindow !== null && (previous === undefined || reviewWindow > previous.window);
|
|
1408
|
+
if (!pmoAuto && (!reviewDue || project.blueprint)) return [];
|
|
1409
|
+
const suppressed = [];
|
|
1410
|
+
const inTurn = (id) => turnsInFlight.has(id);
|
|
1411
|
+
const hostCapacity = treeCapacity.read(hosts.get(projectRuntime.id)?.agent, serviceOf(ctx, 'subagents'));
|
|
1412
|
+
const capacity = hostCapacity.capacity ?? HOST_SUBAGENT_LIMIT;
|
|
1413
|
+
const adviceList = planStaffingAdvice(staffingState, {
|
|
1414
|
+
now, inTurn, capacity, remainingSlots: hostCapacity.remainingSlots,
|
|
1415
|
+
humanId: projectRuntime.service.humanId(), wait: (config.staffingAdviceMinutes ?? 30) * 60_000,
|
|
1416
|
+
onSuppressed: reviewDue ? (entry) => suppressed.push(entry) : undefined,
|
|
1417
|
+
});
|
|
1418
|
+
if (reviewDue) {
|
|
1419
|
+
const sample = { window: reviewWindow };
|
|
1420
|
+
try {
|
|
1421
|
+
// 修复账本可能重用序号,只有原水位仍在这条哈希链上才能接续。
|
|
1422
|
+
const validPrior = previous?.window === reviewWindow - 1 && previous.headSeq <= staffingState.lastSeq
|
|
1423
|
+
&& projectRuntime.ledger.writer.hashAt(previous.headSeq) === previous.lastHash;
|
|
1424
|
+
const prior = validPrior ? previous : null;
|
|
1425
|
+
const review = staffingReview(staffingState, projectRuntime.ledger.events, {
|
|
1426
|
+
...hostCapacity, now, intervalMs: reviewInterval, since: prior?.now, afterSeq: prior?.headSeq, capacity,
|
|
1427
|
+
inTurn, advice: adviceList, suppressed,
|
|
1428
|
+
});
|
|
1429
|
+
diag.append({ ev: 'pmo.staffing.review', projectId: projectRuntime.id, window: reviewWindow, pmoAuto, ...review });
|
|
1430
|
+
Object.assign(sample, { now, headSeq: review.headSeq, lastHash: staffingState.lastHash });
|
|
1431
|
+
} catch (error) {
|
|
1432
|
+
diag.append({ ev: 'pmo.staffing.review.fail', projectId: projectRuntime.id, message: error?.message ?? String(error) });
|
|
1433
|
+
} finally {
|
|
1434
|
+
pmoStaffingReviewWindows.set(projectRuntime.id, sample);
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
return pmoAuto ? adviceList : [];
|
|
1438
|
+
};
|
|
1398
1439
|
const pmoTick = async (projectRuntime) => {
|
|
1399
1440
|
if (projectRuntime === null || projectRuntime === undefined) return;
|
|
1400
1441
|
// 归档修复重试点:boot 时 workspaceRegistry 往往还没 active,等 tick
|
|
@@ -1441,10 +1482,13 @@ export function apply(ctx, config = {}) {
|
|
|
1441
1482
|
// 门禁必须在 await 之后重新取:reconcileJobs 可能耗时数秒,期间 Human
|
|
1442
1483
|
// 可能已经停用 PMO / 归档 / 停止项目,用 await 之前的快照会继续写账本。
|
|
1443
1484
|
const project = projectRuntime.service.state.projects?.[projectRuntime.id];
|
|
1444
|
-
if (project === undefined || project.pmoAuto === false || project.status === 'archived') return;
|
|
1445
1485
|
// P6 停止门:stopped 项目停止一切派发(补派/心跳/升级/continue 全停),
|
|
1446
1486
|
// 正在执行的回合自然完成;唤醒事件 hook 同样检查(见 wakeFromResult)。
|
|
1447
|
-
if (project.runState === 'stopped') return;
|
|
1487
|
+
if (!project || project.status === 'archived' || project.runState === 'stopped') return;
|
|
1488
|
+
if (project.pmoAuto === false) {
|
|
1489
|
+
inspectStaffing(projectRuntime);
|
|
1490
|
+
return;
|
|
1491
|
+
}
|
|
1448
1492
|
for (const member of Object.values(state.members ?? {})) {
|
|
1449
1493
|
if (member.kind === 'agent' && typeof member.sessionId === 'string') {
|
|
1450
1494
|
await titleMemberSession(projectRuntime, member);
|
|
@@ -1505,34 +1549,9 @@ export function apply(ctx, config = {}) {
|
|
|
1505
1549
|
}, {});
|
|
1506
1550
|
}
|
|
1507
1551
|
// 加人建议:推进过慢(待办没人接 / 待验收排长队)时给 Human 收件箱一条建议,由 Human 决定(planStaffingAdvice)。
|
|
1508
|
-
const
|
|
1509
|
-
const reviewInterval = (config.staffingReviewMinutes ?? 0) * 60_000;
|
|
1510
|
-
const reviewWindow = diag.level === 'full' && reviewInterval > 0 ? Math.floor(now / reviewInterval) : null;
|
|
1511
|
-
const reviewDue = reviewWindow !== null && pmoStaffingReviewWindows.get(projectRuntime.id) !== reviewWindow;
|
|
1512
|
-
const suppressed = [];
|
|
1513
|
-
const inTurn = (id) => turnsInFlight.has(id);
|
|
1514
|
-
const hostCapacity = treeCapacity.read(hosts.get(projectRuntime.id)?.agent, serviceOf(ctx, 'subagents'));
|
|
1515
|
-
const capacity = hostCapacity.capacity ?? HOST_SUBAGENT_LIMIT;
|
|
1516
|
-
const adviceList = planStaffingAdvice(staffingState, {
|
|
1517
|
-
now, inTurn, capacity, remainingSlots: hostCapacity.remainingSlots,
|
|
1518
|
-
humanId: projectRuntime.service.humanId(), wait: (config.staffingAdviceMinutes ?? 30) * 60_000,
|
|
1519
|
-
onSuppressed: reviewDue ? (entry) => suppressed.push(entry) : undefined,
|
|
1520
|
-
});
|
|
1521
|
-
if (reviewDue) {
|
|
1522
|
-
pmoStaffingReviewWindows.set(projectRuntime.id, reviewWindow);
|
|
1523
|
-
try {
|
|
1524
|
-
const review = staffingReview(staffingState, projectRuntime.ledger.events, {
|
|
1525
|
-
...hostCapacity, now, intervalMs: reviewInterval, capacity,
|
|
1526
|
-
inTurn, advice: adviceList, suppressed,
|
|
1527
|
-
});
|
|
1528
|
-
diag.append({ ev: 'pmo.staffing.review', projectId: projectRuntime.id, window: reviewWindow, ...review });
|
|
1529
|
-
} catch (error) {
|
|
1530
|
-
diag.append({ ev: 'pmo.staffing.review.fail', projectId: projectRuntime.id, message: error?.message ?? String(error) });
|
|
1531
|
-
}
|
|
1532
|
-
}
|
|
1533
|
-
for (const advice of adviceList) {
|
|
1552
|
+
for (const advice of inspectStaffing(projectRuntime)) {
|
|
1534
1553
|
const item = await projectRuntime.service.recordStaffingAdvice(projectRuntime.id, advice);
|
|
1535
|
-
diag.append({ ev: 'pmo.advice', projectId: projectRuntime.id, role: advice.role, count: advice.count, title: advice.title, itemId: item
|
|
1554
|
+
if (item) diag.append({ ev: 'pmo.advice', projectId: projectRuntime.id, role: advice.role, count: advice.count, title: advice.title, itemId: item.id });
|
|
1536
1555
|
}
|
|
1537
1556
|
if (active.length > 0) {
|
|
1538
1557
|
// Prune per-task clock entries whose task left the active set, so
|
package/lib/host/pmo.js
CHANGED
|
@@ -268,16 +268,21 @@ const ACCEPTANCE_ACTIVITY = new Map([
|
|
|
268
268
|
['review/changes-requested', 'returned'],
|
|
269
269
|
]);
|
|
270
270
|
|
|
271
|
-
/**
|
|
272
|
-
export function staffingReview(state, events, {
|
|
273
|
-
|
|
271
|
+
/** An unlinked sample uses wall time. Consecutive samples count newly appended records. */
|
|
272
|
+
export function staffingReview(state, events, {
|
|
273
|
+
now, intervalMs, since = now - intervalMs, afterSeq = null, capacity, capacitySource = null,
|
|
274
|
+
occupiedSlots = null, remainingSlots = null, inTurn, advice = [], suppressed = [],
|
|
275
|
+
}) {
|
|
276
|
+
const headSeq = state.lastSeq ?? null;
|
|
274
277
|
const people = new Map(Object.values(state.members ?? {})
|
|
275
278
|
.filter((member) => member.kind === 'agent' && member.status !== 'retired')
|
|
276
279
|
.map(({ id, role, status }) => [id, { id, role: role || '未设置岗位', status, submitted: 0, accepted: 0, returned: 0 }]));
|
|
277
280
|
const submissions = new Map();
|
|
278
281
|
const acceptanceActivity = { submitted: 0, accepted: 0, returned: 0, humanSelfAccepted: 0 };
|
|
279
282
|
for (const event of events) {
|
|
280
|
-
if (
|
|
283
|
+
if (afterSeq === null) {
|
|
284
|
+
if (!Number.isFinite(event.at) || event.at <= since || event.at > now) continue;
|
|
285
|
+
} else if (!Number.isSafeInteger(event.seq) || event.seq <= afterSeq || event.seq > headSeq) continue;
|
|
281
286
|
const activity = ACCEPTANCE_ACTIVITY.get(event.type);
|
|
282
287
|
const taskId = event.payload?.taskId ?? event.payload?.id;
|
|
283
288
|
if (activity === undefined || typeof taskId !== 'string' || taskId === '') continue;
|
|
@@ -313,7 +318,7 @@ export function staffingReview(state, events, { now, intervalMs, capacity, capac
|
|
|
313
318
|
if (task.status === 'in_progress') group.inProgress += 1;
|
|
314
319
|
}
|
|
315
320
|
return {
|
|
316
|
-
since, now, capacity, capacitySource, capacityScope: 'agent-tree', occupiedSlots, remainingSlots, activeMemberTurns,
|
|
321
|
+
since, now, afterSeq, headSeq, capacity, capacitySource, capacityScope: 'agent-tree', occupiedSlots, remainingSlots, activeMemberTurns,
|
|
317
322
|
claimable: waitingSummary(claimableTasks(state, open), now),
|
|
318
323
|
pendingAcceptance: waitingSummary(waitingReview, now),
|
|
319
324
|
acceptanceActivity,
|
|
@@ -1,109 +1,109 @@
|
|
|
1
|
-
/** Lightweight Project index. The ledger remains the source of truth for Project state. */
|
|
2
|
-
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
import { DEFAULT_PROJECT_ID } from './project-runtime.js';
|
|
5
|
-
import { reportFail } from '../diaglog.js';
|
|
6
|
-
|
|
7
|
-
export class ProjectRegistry {
|
|
8
|
-
constructor({ rootDir, projects, activeProjectId }) {
|
|
9
|
-
this.rootDir = rootDir;
|
|
10
|
-
this.projects = Array.isArray(projects) ? projects : [];
|
|
11
|
-
this.activeProjectId = activeProjectId ?? DEFAULT_PROJECT_ID;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
static load(rootDir, options = {}) {
|
|
15
|
-
// 初装时会给一个默认项目;它必须有工作目录,否则成员会话的 cwd 只能落到
|
|
16
|
-
// 插件数据目录(workspace attach 会被拒,成员也在错误目录里干活)。
|
|
17
|
-
const defaultWorkspacePath = typeof options.defaultWorkspacePath === 'string' ? options.defaultWorkspacePath : '';
|
|
18
|
-
mkdirSync(rootDir, { recursive: true });
|
|
19
|
-
const file = join(rootDir, 'projects.json');
|
|
20
|
-
let parsed;
|
|
21
|
-
try {
|
|
22
|
-
parsed = existsSync(file) ? JSON.parse(readFileSync(file, 'utf8')) : null;
|
|
23
|
-
} catch (error) {
|
|
24
|
-
// A corrupt index must not silently vanish the user's project list:
|
|
25
|
-
// keep the broken file for forensics, then fall back to the default.
|
|
26
|
-
const kept = `${file}.corrupt-${Date.now()}`;
|
|
27
|
-
try { renameSync(file, kept); } catch { /* rename is best-effort */ }
|
|
28
|
-
reportFail('registry.corrupt.fail', { kept }, `[ai-team] projects.json was unreadable (${error?.message ?? error}); kept as ${kept}`);
|
|
29
|
-
parsed = null;
|
|
30
|
-
}
|
|
31
|
-
// 默认项目只在**一个项目都没有**时播种(初装的第一入口)。此前只要列表里
|
|
32
|
-
// 缺少 `prj_main` 就补一条:用户把它删掉后会被静默复活,等于删不掉。
|
|
33
|
-
const projects = Array.isArray(parsed?.projects) && parsed.projects.length > 0
|
|
34
|
-
? parsed.projects.filter((project) => typeof project?.id === 'string' && project.id !== '')
|
|
35
|
-
: [];
|
|
36
|
-
if (projects.length === 0) projects.push({ id: DEFAULT_PROJECT_ID, name: '我的项目', createdAt: 0 });
|
|
37
|
-
const active = projects.some((project) => project.id === parsed?.activeProjectId)
|
|
38
|
-
? parsed.activeProjectId
|
|
39
|
-
: projects[0].id;
|
|
40
|
-
const registry = new ProjectRegistry({ rootDir, projects, activeProjectId: active });
|
|
41
|
-
if (!existsSync(file)) registry.save();
|
|
42
|
-
return registry;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
get activeProject() {
|
|
46
|
-
return this.projects.find((project) => project.id === this.activeProjectId) ?? this.projects[0];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
list() {
|
|
50
|
-
return this.projects.map((project) => ({ ...project, active: project.id === this.activeProjectId }));
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/** 更新某个项目的工作目录(与账本的 project/workspace-changed 保持同步)。 */
|
|
54
|
-
setWorkspace(id, workspacePath) {
|
|
55
|
-
const project = this.projects.find((entry) => entry.id === id);
|
|
56
|
-
if (project === undefined) return false;
|
|
57
|
-
const next = typeof workspacePath === 'string' ? workspacePath : '';
|
|
58
|
-
if ((project.workspacePath ?? '') === next) return false;
|
|
59
|
-
project.workspacePath = next;
|
|
60
|
-
this.save();
|
|
61
|
-
return true;
|
|
62
|
-
}
|
|
63
|
-
add({ id, name, createdAt, goal, workspacePath }) {
|
|
64
|
-
if (typeof id !== 'string' || id === '') throw new Error('project id is required');
|
|
65
|
-
if (!this.projects.some((project) => project.id === id)) {
|
|
66
|
-
this.projects.push({ id, name: name ?? id, goal: goal ?? '', workspacePath: workspacePath ?? '', createdAt: createdAt ?? Date.now() });
|
|
67
|
-
try {
|
|
68
|
-
this.save();
|
|
69
|
-
} catch (error) {
|
|
70
|
-
this.projects.pop();
|
|
71
|
-
throw error;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return this.projects.find((project) => project.id === id);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
setActive(id) {
|
|
78
|
-
const project = this.projects.find((entry) => entry.id === id);
|
|
79
|
-
if (project === undefined) throw new Error(`unknown project: ${id}`);
|
|
80
|
-
// 归档项目不能成为 active:registry 的 active 会被 bootstrap 当作「默认项目」,
|
|
81
|
-
// 指向一个已归档/无账本的项目会让工作台直接不可达。
|
|
82
|
-
if (project.archived === true) throw new Error(`project ${id} is archived`);
|
|
83
|
-
this.activeProjectId = id;
|
|
84
|
-
this.save();
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/** Mirror a Project's archive flag into the global index (ledger stays the source of truth). */
|
|
88
|
-
setArchived(id, archived) {
|
|
89
|
-
const project = this.projects.find((entry) => entry.id === id);
|
|
90
|
-
if (project === undefined) throw new Error(`unknown project: ${id}`);
|
|
91
|
-
project.archived = archived === true;
|
|
92
|
-
if (archived === true && this.activeProjectId === id) {
|
|
93
|
-
const fallback = this.projects.find((entry) => entry.id !== id && entry.archived !== true);
|
|
94
|
-
if (fallback !== undefined) this.activeProjectId = fallback.id;
|
|
95
|
-
}
|
|
96
|
-
this.save();
|
|
97
|
-
return project;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
save() {
|
|
101
|
-
const file = join(this.rootDir, 'projects.json');
|
|
102
|
-
const temp = `${file}.tmp`;
|
|
103
|
-
writeFileSync(temp, JSON.stringify({
|
|
104
|
-
activeProjectId: this.activeProjectId,
|
|
105
|
-
projects: this.projects,
|
|
106
|
-
}, null, 2), 'utf8');
|
|
107
|
-
renameSync(temp, file);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
1
|
+
/** Lightweight Project index. The ledger remains the source of truth for Project state. */
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { DEFAULT_PROJECT_ID } from './project-runtime.js';
|
|
5
|
+
import { reportFail } from '../diaglog.js';
|
|
6
|
+
|
|
7
|
+
export class ProjectRegistry {
|
|
8
|
+
constructor({ rootDir, projects, activeProjectId }) {
|
|
9
|
+
this.rootDir = rootDir;
|
|
10
|
+
this.projects = Array.isArray(projects) ? projects : [];
|
|
11
|
+
this.activeProjectId = activeProjectId ?? DEFAULT_PROJECT_ID;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
static load(rootDir, options = {}) {
|
|
15
|
+
// 初装时会给一个默认项目;它必须有工作目录,否则成员会话的 cwd 只能落到
|
|
16
|
+
// 插件数据目录(workspace attach 会被拒,成员也在错误目录里干活)。
|
|
17
|
+
const defaultWorkspacePath = typeof options.defaultWorkspacePath === 'string' ? options.defaultWorkspacePath : '';
|
|
18
|
+
mkdirSync(rootDir, { recursive: true });
|
|
19
|
+
const file = join(rootDir, 'projects.json');
|
|
20
|
+
let parsed;
|
|
21
|
+
try {
|
|
22
|
+
parsed = existsSync(file) ? JSON.parse(readFileSync(file, 'utf8')) : null;
|
|
23
|
+
} catch (error) {
|
|
24
|
+
// A corrupt index must not silently vanish the user's project list:
|
|
25
|
+
// keep the broken file for forensics, then fall back to the default.
|
|
26
|
+
const kept = `${file}.corrupt-${Date.now()}`;
|
|
27
|
+
try { renameSync(file, kept); } catch { /* rename is best-effort */ }
|
|
28
|
+
reportFail('registry.corrupt.fail', { kept }, `[ai-team] projects.json was unreadable (${error?.message ?? error}); kept as ${kept}`);
|
|
29
|
+
parsed = null;
|
|
30
|
+
}
|
|
31
|
+
// 默认项目只在**一个项目都没有**时播种(初装的第一入口)。此前只要列表里
|
|
32
|
+
// 缺少 `prj_main` 就补一条:用户把它删掉后会被静默复活,等于删不掉。
|
|
33
|
+
const projects = Array.isArray(parsed?.projects) && parsed.projects.length > 0
|
|
34
|
+
? parsed.projects.filter((project) => typeof project?.id === 'string' && project.id !== '')
|
|
35
|
+
: [];
|
|
36
|
+
if (projects.length === 0) projects.push({ id: DEFAULT_PROJECT_ID, name: '我的项目', createdAt: 0 });
|
|
37
|
+
const active = projects.some((project) => project.id === parsed?.activeProjectId)
|
|
38
|
+
? parsed.activeProjectId
|
|
39
|
+
: projects[0].id;
|
|
40
|
+
const registry = new ProjectRegistry({ rootDir, projects, activeProjectId: active });
|
|
41
|
+
if (!existsSync(file)) registry.save();
|
|
42
|
+
return registry;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
get activeProject() {
|
|
46
|
+
return this.projects.find((project) => project.id === this.activeProjectId) ?? this.projects[0];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
list() {
|
|
50
|
+
return this.projects.map((project) => ({ ...project, active: project.id === this.activeProjectId }));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** 更新某个项目的工作目录(与账本的 project/workspace-changed 保持同步)。 */
|
|
54
|
+
setWorkspace(id, workspacePath) {
|
|
55
|
+
const project = this.projects.find((entry) => entry.id === id);
|
|
56
|
+
if (project === undefined) return false;
|
|
57
|
+
const next = typeof workspacePath === 'string' ? workspacePath : '';
|
|
58
|
+
if ((project.workspacePath ?? '') === next) return false;
|
|
59
|
+
project.workspacePath = next;
|
|
60
|
+
this.save();
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
add({ id, name, createdAt, goal, workspacePath }) {
|
|
64
|
+
if (typeof id !== 'string' || id === '') throw new Error('project id is required');
|
|
65
|
+
if (!this.projects.some((project) => project.id === id)) {
|
|
66
|
+
this.projects.push({ id, name: name ?? id, goal: goal ?? '', workspacePath: workspacePath ?? '', createdAt: createdAt ?? Date.now() });
|
|
67
|
+
try {
|
|
68
|
+
this.save();
|
|
69
|
+
} catch (error) {
|
|
70
|
+
this.projects.pop();
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return this.projects.find((project) => project.id === id);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
setActive(id) {
|
|
78
|
+
const project = this.projects.find((entry) => entry.id === id);
|
|
79
|
+
if (project === undefined) throw new Error(`unknown project: ${id}`);
|
|
80
|
+
// 归档项目不能成为 active:registry 的 active 会被 bootstrap 当作「默认项目」,
|
|
81
|
+
// 指向一个已归档/无账本的项目会让工作台直接不可达。
|
|
82
|
+
if (project.archived === true) throw new Error(`project ${id} is archived`);
|
|
83
|
+
this.activeProjectId = id;
|
|
84
|
+
this.save();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Mirror a Project's archive flag into the global index (ledger stays the source of truth). */
|
|
88
|
+
setArchived(id, archived) {
|
|
89
|
+
const project = this.projects.find((entry) => entry.id === id);
|
|
90
|
+
if (project === undefined) throw new Error(`unknown project: ${id}`);
|
|
91
|
+
project.archived = archived === true;
|
|
92
|
+
if (archived === true && this.activeProjectId === id) {
|
|
93
|
+
const fallback = this.projects.find((entry) => entry.id !== id && entry.archived !== true);
|
|
94
|
+
if (fallback !== undefined) this.activeProjectId = fallback.id;
|
|
95
|
+
}
|
|
96
|
+
this.save();
|
|
97
|
+
return project;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
save() {
|
|
101
|
+
const file = join(this.rootDir, 'projects.json');
|
|
102
|
+
const temp = `${file}.tmp`;
|
|
103
|
+
writeFileSync(temp, JSON.stringify({
|
|
104
|
+
activeProjectId: this.activeProjectId,
|
|
105
|
+
projects: this.projects,
|
|
106
|
+
}, null, 2), 'utf8');
|
|
107
|
+
renameSync(temp, file);
|
|
108
|
+
}
|
|
109
|
+
}
|
package/lib/host/service.js
CHANGED
|
@@ -1805,6 +1805,8 @@ export class TeamService {
|
|
|
1805
1805
|
*/
|
|
1806
1806
|
async recordStaffingAdvice(projectId, advice) {
|
|
1807
1807
|
return this.runExclusive(async () => {
|
|
1808
|
+
const project = this.state.projects?.[projectId];
|
|
1809
|
+
if (!project || project.pmoAuto === false || project.status === 'archived' || project.runState === 'stopped') return null;
|
|
1808
1810
|
const humanId = this.humanId();
|
|
1809
1811
|
if (humanId === null) return null;
|
|
1810
1812
|
const item = createInboxItem({
|
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.165",
|
|
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",
|