@suifei/dsh-ai-team 0.4.156 → 0.4.158

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 CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.158 - 2026-12-04
4
+
5
+ - 编制巡检从支持 `capacityOf` 的 DSH 读取当前代理树的已占用与剩余槽位,加人建议会标明采样时的并发余量。旧宿主沿用容量回执或默认估计。感谢 @buger-gif 提供编制巡检和并发边界的案例(#116)。
6
+ - 工作台使用 DSH 0.2.3 Alpha 的 Web 路由会话认证,修复已登录时仍无法打开看板。感谢 @Estelle00 提供新版宿主的启动场景(#122)。
7
+
8
+ ## 0.4.157 - 2026-12-03
9
+
10
+ - DSH 会话可根据目标建议团队,显示匹配的交付物。有多个候选时请用户选择。`/ai-team 调整` 可用一句话准备增员、改岗位或离队交接草稿,沿用会话确认和原卡交接。感谢 @buger-gif 的会话建队与编制反馈(#121)。
11
+
3
12
  ## 0.4.156 - 2026-12-03
4
13
 
5
14
  - 在 DSH 会话查看当前工作区的项目编制,从人才库增员、修改岗位或指定接手人后离队。确认时重新核对成员、人才和未收口任务,交接成功后原成员进入人才池。感谢 @buger-gif 的会话调整与任务交接场景(#121、#116)。
package/README.md CHANGED
@@ -37,6 +37,9 @@
37
37
 
38
38
  ## 最近更新
39
39
 
40
+ - **实时代理树槽位**(0.4.158)。支持 `capacityOf` 的宿主会在编制巡检中报告已占用和剩余槽位,建议新增成员时可看出同时启动是否需要排队。感谢 [@buger-gif](https://github.com/buger-gif),[#116](https://github.com/suifei/dsh-ai-team/issues/116)。
41
+ - **DSH 0.2.3 Alpha 看板兼容**(0.4.158)。工作台沿用宿主 Web 路由的会话认证,修复已登录时看板仍加载失败的问题。感谢 [@Estelle00](https://github.com/Estelle00),[#122](https://github.com/suifei/dsh-ai-team/issues/122)。
42
+ - **会话建队建议与一句话调整编制**(0.4.157)。根据目标匹配团队预设并显示依据。可用一句话准备增员、改岗位或离队交接的草稿。感谢 [@buger-gif](https://github.com/buger-gif),[#121](https://github.com/suifei/dsh-ai-team/issues/121)。
40
43
  - **从会话调整编制**(0.4.156)。可查看同一工作区的团队,从人才库增员、修改岗位或把原任务交给接手人后离队。变更经草稿确认。感谢 [@buger-gif](https://github.com/buger-gif),[#121](https://github.com/suifei/dsh-ai-team/issues/121)、[#116](https://github.com/suifei/dsh-ai-team/issues/116)。
41
44
  - **从会话建队与分树容量**(0.4.155)。在 DSH 会话输入目标即可预览目录和岗位,确认后由现有流程创建项目。编制巡检和排队补投按项目代理树处理并发。感谢 [@buger-gif](https://github.com/buger-gif),[#121](https://github.com/suifei/dsh-ai-team/issues/121)、[#116](https://github.com/suifei/dsh-ai-team/issues/116)。
42
45
  - **目录浏览和验收补位**(0.4.154)。新建或编辑项目时可使用宿主的原生对话框或浏览式选择器。桌面安装说明补齐首次初始化和退出步骤。编制巡检标明缺少合格验收人的任务、观察到的成员回合和容量来源。感谢 [@ljyzww](https://github.com/ljyzww),[#100](https://github.com/suifei/dsh-ai-team/issues/100)。感谢 [@Arnoldnuo](https://github.com/Arnoldnuo),[#102](https://github.com/suifei/dsh-ai-team/issues/102)。感谢 [@buger-gif](https://github.com/buger-gif),[#116](https://github.com/suifei/dsh-ai-team/issues/116)。
@@ -138,7 +141,9 @@ const svg = HashAvatar.svg('墨渊', { gender: 'male', age: 'middle', race: 'asi
138
141
  /ai-team 建队 --team docs 整理接口文档
139
142
  ```
140
143
 
141
- 会话会显示工作目录、目标、团队预设与岗位。输入草稿末尾的 `/ai-team 确认 草稿ID` 创建项目,或用对应的取消命令丢弃草稿。省略 `--team` 时使用设置中的默认团队预设。草稿跟随当前会话,宿主重启后可以重新生成。
144
+ 可用 `/ai-team 建队 --recommend 整理接口文档` 根据目标匹配文档、内容、教育、视频或游戏预设。唯一候选会随匹配依据进入草稿。有多个候选或线索不足时,用 `--team` 指定预设。省略这两个选项时使用设置中的团队。
145
+
146
+ 会话会显示工作目录、目标、团队预设与岗位。输入草稿末尾的 `/ai-team 确认 草稿ID` 创建项目,或用对应的取消命令丢弃草稿。草稿跟随当前会话,宿主重启后可以重新生成。
142
147
 
143
148
  新项目会出现在文渊阁,PMO 自动初始关闭。团队准备好后,可以在项目页开启 PMO 自动。
144
149
 
@@ -146,6 +151,14 @@ const svg = HashAvatar.svg('墨渊', { gender: 'male', age: 'middle', race: 'asi
146
151
 
147
152
  `/ai-team 编制` 显示当前工作区的项目与成员编号。同一工作区有多个项目时,先选项目,使用 `/ai-team 编制 项目ID` 查看成员。用 `/ai-team 人才 [关键词]` 查看人才编号。
148
153
 
154
+ 也可以用 `/ai-team 调整` 说清一件事。同一工作区有多个项目时,在句子前加项目编号。同名成员或人才会列出编号供选择。
155
+
156
+ ```text
157
+ /ai-team 调整 给团队加一位文案
158
+ /ai-team 调整 把校书的岗位改为文档协调
159
+ /ai-team 调整 让墨痕把任务交给校书后离队
160
+ ```
161
+
149
162
  ```text
150
163
  /ai-team 增员 项目ID 人才ID
151
164
  /ai-team 改岗位 项目ID 成员ID 新岗位
@@ -168,7 +181,7 @@ const svg = HashAvatar.svg('墨渊', { gender: 'male', age: 'middle', race: 'asi
168
181
 
169
182
  在当前 DSH profile 的 `ai-team` 配置中设 `staffingReviewMinutes: 180` 和 `diagLevel: full` 后,启用 PMO 自动的运行中普通项目会随现有巡检周期采样,每个时间窗口记录一次。`staffingReviewMinutes: 0`(默认)关闭采样。诊断日志中的 `pmo.staffing.review` 包含岗位已分配队列、可认领与待验收队列、最长及平均等待,以及采样窗口内每位成员的提交、验收和退回。返工率按退回的本窗口提交除以本窗口提交数计算,零样本为空。
170
183
 
171
- 巡检还会记录没有合格验收人的任务 ID、插件观察到的在队成员运行回合数和容量来源。并发上限按当前项目的根代理树记录,来源为 `default` 时使用默认估计,为 `host` 时来自这棵树的宿主容量回执。宿主释放槽位后,插件优先补投本树排队最久的成员。PMO 会把长期无人可验收的任务带进现有补位建议。
184
+ 巡检还会记录没有合格验收人的任务 ID 和在队成员运行回合数。宿主提供 `capacityOf` 时,`host-live` 表示当前代理树的实时槽位快照,`occupiedSlots` 和 `remainingSlots` 分别记录占用和余量。`host` 表示这棵树的容量回执,`default` 表示默认估计。这两种来源的占用和余量字段为空。宿主释放槽位后,插件优先补投本树排队最久的成员。加人建议会提示采样时的槽位不足,长期无人可验收的任务也会进入现有补位建议。
172
185
 
173
186
  巡检复用现有派员建议和冷却规则,记录被暂缓的建议。人员动作仍由已有授权流程处理。试跑样本和调整建议可回到 [#116](https://github.com/suifei/dsh-ai-team/issues/116)。
174
187
 
@@ -417,8 +430,8 @@ round-19 DeepSeek + Zhipu 双 provider
417
430
  | 贡献者 | 贡献 | 带来的进展 |
418
431
  |---|---|---|
419
432
  | [@idontlikefruit](https://github.com/idontlikefruit) | 受阻状态的三组复现输入 [#115](https://github.com/suifei/dsh-ai-team/issues/115) | 统一看板徽标、读屏和分组统计的受阻判定,保留历史依赖 |
420
- | [@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 会话里确认建队、编制调整和原任务交接 |
421
- | [@Estelle00](https://github.com/Estelle00) | DSH 0.2.3 启动 503 的复现和桌面验证 [#122](https://github.com/suifei/dsh-ai-team/issues/122) | 接入新版会话鉴权接口,恢复工作台初始化 |
433
+ | [@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 会话按目标建议预设,并确认一句话编制草稿及原任务交接 |
434
+ | [@Estelle00](https://github.com/Estelle00) | DSH 0.2.3 启动 503 的复现和桌面验证 [#122](https://github.com/suifei/dsh-ai-team/issues/122) | 接入新版会话鉴权接口,恢复工作台初始化,并在 Alpha 宿主验证看板登录 |
422
435
  | [@phm101299-ui](https://github.com/phm101299-ui) | PMO 冷恢复的复现、根因和桌面验证 [#112](https://github.com/suifei/dsh-ai-team/issues/112) | 让原 PMO 在宿主重启后带着模型路由继续工作,保留成员关系和任务 |
423
436
  | [@godfay-g](https://github.com/godfay-g) | 技能目录和 ZIP 的导入建议 [#109](https://github.com/suifei/dsh-ai-team/issues/109) | 成员与自定义人才可在文渊阁选择已安装的技能或导入完整技能包。0.4.151 统一新建人才的导入入口,并由文渊阁直接安装整包 |
424
437
  | [@qq958691165](https://github.com/qq958691165) | 归档项目的成员反馈、团队管理建议 [#103](https://github.com/suifei/dsh-ai-team/issues/103) | 人员池排除归档项目,侧栏集中管理项目成员与团队预设 |
package/index.js CHANGED
@@ -82,7 +82,7 @@ import { readAttachment, uploadAttachment } from './lib/host/attachment-routes.j
82
82
  import { createDiagLogger, defaultDiagDir, installDiagSink } from './lib/diaglog.js';
83
83
  import { CATALOG_PACKAGE, clearOfficialCatalog, officialStatus, syncOfficialCatalog } from './lib/domain/catalog-sync.js';
84
84
  import { AVATAR_PACKAGE, avatarFile, avatarOptions, renderAvatarSvg, startAvatarLib } from './lib/domain/avatar.js';
85
- import { DEFAULT_TEAM, catalogRoots, deleteTalent, deleteTeam, forkTalent, installSkill, listInstallableSkills, listTalents, listTeams, loadCatalog, readSkillText, resolveTeam, talentFromMember, talentIdFrom, uniqueTalentId, uniqueTeamId, userCatalogDir, writeTalent, writeTeam } from './lib/domain/catalog.js';
85
+ import { DEFAULT_TEAM, catalogRoots, deleteTalent, deleteTeam, forkTalent, installSkill, listInstallableSkills, listTalents, listTeams, loadCatalog, matchTeamPresets, readSkillText, resolveTeam, talentFromMember, talentIdFrom, uniqueTalentId, uniqueTeamId, userCatalogDir, writeTalent, writeTeam } from './lib/domain/catalog.js';
86
86
 
87
87
  export const name = 'ai-team';
88
88
 
@@ -182,8 +182,7 @@ async function memberHostSkillReferences(names, ownedRoots, summaries) {
182
182
  }
183
183
 
184
184
  /** 新项目用哪个团队:新建时选的优先,其次插件设置 `teamPreset`,最后内置默认团队。 */
185
- function teamPresetFor(config, diag, chosen = '') {
186
- const catalog = talentCatalog(diag);
185
+ function teamPresetFor(config, diag, chosen = '', catalog = talentCatalog(diag)) {
187
186
  if (chosen !== '') {
188
187
  const entry = listTeams(catalog).find((team) => team.id === chosen);
189
188
  if (entry === undefined) fail(ERRORS.INVALID_ARGUMENT, `团队不存在:${chosen}`, { status: 400 });
@@ -1008,7 +1007,7 @@ export function apply(ctx, config = {}) {
1008
1007
  const pmoLastStaffing = new Map();
1009
1008
  const pmoStaffingReviewWindows = new Map();
1010
1009
  // DSH 的 ActivationPool 按根 Agent 分配,已观察的上限随当前项目树而变。
1011
- const treeCapacity = observeTreeCapacity();
1010
+ const treeCapacity = observeTreeCapacity({ diag });
1012
1011
  const pmoLastEscalate = new Map();
1013
1012
  const pmoLastReview = new Map();
1014
1013
  let pmoTimer = null;
@@ -1511,10 +1510,10 @@ export function apply(ctx, config = {}) {
1511
1510
  const reviewDue = reviewWindow !== null && pmoStaffingReviewWindows.get(projectRuntime.id) !== reviewWindow;
1512
1511
  const suppressed = [];
1513
1512
  const inTurn = (id) => turnsInFlight.has(id);
1514
- const observedHostCapacity = treeCapacity.get(hosts.get(projectRuntime.id)?.agent);
1515
- const capacity = observedHostCapacity ?? HOST_SUBAGENT_LIMIT;
1513
+ const hostCapacity = treeCapacity.read(hosts.get(projectRuntime.id)?.agent, serviceOf(ctx, 'subagents'));
1514
+ const capacity = hostCapacity.capacity ?? HOST_SUBAGENT_LIMIT;
1516
1515
  const adviceList = planStaffingAdvice(staffingState, {
1517
- now, inTurn, capacity,
1516
+ now, inTurn, capacity, remainingSlots: hostCapacity.remainingSlots,
1518
1517
  humanId: projectRuntime.service.humanId(), wait: (config.staffingAdviceMinutes ?? 30) * 60_000,
1519
1518
  onSuppressed: reviewDue ? (entry) => suppressed.push(entry) : undefined,
1520
1519
  });
@@ -1522,7 +1521,7 @@ export function apply(ctx, config = {}) {
1522
1521
  pmoStaffingReviewWindows.set(projectRuntime.id, reviewWindow);
1523
1522
  try {
1524
1523
  const review = staffingReview(staffingState, projectRuntime.ledger.events, {
1525
- now, intervalMs: reviewInterval, capacity, capacitySource: observedHostCapacity === null ? 'default' : 'host',
1524
+ ...hostCapacity, now, intervalMs: reviewInterval, capacity,
1526
1525
  inTurn, advice: adviceList, suppressed,
1527
1526
  });
1528
1527
  diag.append({ ev: 'pmo.staffing.review', projectId: projectRuntime.id, window: reviewWindow, ...review });
@@ -2590,7 +2589,20 @@ export function apply(ctx, config = {}) {
2590
2589
  }
2591
2590
 
2592
2591
  const nativeTeamCommand = sessionTeamCommand({
2593
- prepare: (input) => ({ ...projectInput(input), teamPreset: teamPresetFor(config, diag, input.team) }),
2592
+ prepare(input) {
2593
+ const project = projectInput(input);
2594
+ if (!input.recommend) return { ...project, teamPreset: teamPresetFor(config, diag, input.team) };
2595
+ const catalog = talentCatalog(diag);
2596
+ const candidates = matchTeamPresets(catalog, project.goal);
2597
+ diag.append({ ev: 'session.team.recommendation', candidates: candidates.map(({ id, terms }) => ({ id, terms })) });
2598
+ if (candidates.length !== 1) {
2599
+ const hint = '请用 /ai-team 建队 --team 预设ID 目标 指定团队。';
2600
+ const summary = candidates.map(({ name, id, terms }) => `- ${name}(${id}) · ${terms.join('、')}`).join('\n');
2601
+ fail(ERRORS.INVALID_ARGUMENT, summary ? `目标对应多个团队。${hint}\n${summary}` : `目标中缺少明确的团队线索。${hint}`);
2602
+ }
2603
+ const [match] = candidates;
2604
+ return { ...project, teamPreset: teamPresetFor(config, diag, match.id, catalog), matchedTerms: match.terms };
2605
+ },
2594
2606
  create: async (id, input) => (await activateProject(id, { ...input, pmoAuto: false })).service.state.projects[id],
2595
2607
  prepareRoster: createSessionRoster({
2596
2608
  async runtimes() {
@@ -2624,17 +2636,19 @@ export function apply(ctx, config = {}) {
2624
2636
  const dispose = webServer.register({
2625
2637
  kind: 'prefix',
2626
2638
  path: '/ai-team',
2627
- handler: async (req, res) => {
2639
+ auth: 'required',
2640
+ handler: async (req, res, peer) => {
2628
2641
  try {
2629
- // 0.2.2 使用 requestRejection;0.2.3 的 admit 同时验证来源与会话。
2630
- // isTrustedRequest 只检查来源,不能作为认证栅栏。
2631
- const connection = serviceOf(ctx, 'connection');
2642
+ // 0.2.3 的 WebServer 从宿主认证作用域传入 Peer;0.2.2 由 Connection 检查。
2632
2643
  let rejection = 503;
2633
- if (typeof connection?.requestRejection === 'function') {
2634
- rejection = connection.requestRejection(req);
2635
- } else if (typeof connection?.admit === 'function') {
2636
- const admission = await connection.admit(req);
2637
- rejection = admission?.rejection ?? (admission?.peer ? undefined : 503);
2644
+ if (peer) {
2645
+ const aborted = peer.signal?.aborted;
2646
+ if (typeof aborted === 'boolean') rejection = aborted ? 401 : undefined;
2647
+ } else {
2648
+ const connection = serviceOf(ctx, 'connection');
2649
+ if (typeof connection?.requestRejection === 'function') {
2650
+ rejection = connection.requestRejection(req);
2651
+ }
2638
2652
  }
2639
2653
  if (rejection !== undefined) {
2640
2654
  const status = rejection === 401 || rejection === 403 ? rejection : 503;
@@ -371,6 +371,33 @@ export function listTeams(catalog) {
371
371
  .sort((a, b) => (a.id === DEFAULT_TEAM ? -1 : b.id === DEFAULT_TEAM ? 1 : 0) || a.source.localeCompare(b.source) || a.name.localeCompare(b.name, 'zh'));
372
372
  }
373
373
 
374
+ const PRESET_GOAL_TERMS = {
375
+ docs: ['文档', '手册', '知识库', 'readme', 'api documentation'],
376
+ content: ['公众号', '博客', '社媒', '文案', 'blog'],
377
+ education: ['课件', '教材', '题库', '教案', '复习', '课程', 'quiz'],
378
+ video: ['视频', '分镜', '剪辑', '字幕', 'video'],
379
+ game: ['小游戏', '游戏开发', '游戏原型', '游戏玩法', 'game prototype'],
380
+ };
381
+
382
+ /** 只按现有预设的交付物找候选。命中多种方向时保留候选,交给用户选。 */
383
+ export function matchTeamPresets(catalog, goal) {
384
+ const clauses = goal.normalize('NFKC').toLowerCase().split(/[,。;、!?,;!?\r\n]+/u)
385
+ .filter((clause) => !/(?:不要|不用|无需|不需要|不做|别|排除|\b(?:not|no|without|exclude)\b)/u.test(clause));
386
+ const candidates = [];
387
+ for (const team of listTeams(catalog)) {
388
+ if (!Object.hasOwn(PRESET_GOAL_TERMS, team.id) || team.broken || team.source === 'user') continue;
389
+ const terms = PRESET_GOAL_TERMS[team.id].filter((term) => {
390
+ if (/^[a-z ]+$/u.test(term)) {
391
+ const word = new RegExp(`\\b${term}\\b`, 'u');
392
+ return clauses.some((clause) => word.test(clause));
393
+ }
394
+ return clauses.some((clause) => clause.includes(term));
395
+ });
396
+ if (terms.length > 0) candidates.push({ id: team.id, name: team.name, terms });
397
+ }
398
+ return candidates;
399
+ }
400
+
374
401
  /**
375
402
  * 组队:写一个用户团队 `<userRoot>/teams/<id>/team.yml`。
376
403
  * `members` 是 [{ talent, name? }](同一人才可招多位,成员 id 自动生成且不重复),`lead` 是成员下标或成员 id(缺省第一位)。
package/lib/host/pmo.js CHANGED
@@ -260,7 +260,7 @@ function tasksWithoutReviewer(state, tasks) {
260
260
  }
261
261
 
262
262
  /** A read-only rollup of the existing queues and observed submissions in this window. */
263
- export function staffingReview(state, events, { now, intervalMs, capacity, capacitySource = null, inTurn, advice = [], suppressed = [] }) {
263
+ export function staffingReview(state, events, { now, intervalMs, capacity, capacitySource = null, occupiedSlots = null, remainingSlots = null, inTurn, advice = [], suppressed = [] }) {
264
264
  const since = now - intervalMs;
265
265
  const people = new Map(Object.values(state.members ?? {})
266
266
  .filter((member) => member.kind === 'agent' && member.status !== 'retired')
@@ -299,7 +299,7 @@ export function staffingReview(state, events, { now, intervalMs, capacity, capac
299
299
  if (task.status === 'in_progress') group.inProgress += 1;
300
300
  }
301
301
  return {
302
- since, now, capacity, capacitySource, capacityScope: 'agent-tree', activeMemberTurns,
302
+ since, now, capacity, capacitySource, capacityScope: 'agent-tree', occupiedSlots, remainingSlots, activeMemberTurns,
303
303
  claimable: waitingSummary(claimableTasks(state, open), now),
304
304
  pendingAcceptance: waitingSummary(waitingReview, now),
305
305
  pendingAcceptanceWithoutReviewer: { ...waitingSummary(missingReviewers, now), taskIds: missingReviewers.map(({ id }) => id) },
@@ -320,10 +320,10 @@ export function staffingReview(state, events, { now, intervalMs, capacity, capac
320
320
  * 同一类建议 4 小时内只提一次;上一条还没处理(unread)时不再提。冷却读账本里的收件箱,重启不丢。
321
321
  *
322
322
  * @param {any} state 账本投影
323
- * @param {{ now: number, inTurn: (sessionId: string) => boolean, capacity?: number, humanId?: string | null, wait?: number, onSuppressed?: (entry: object) => void }} options 「慢」的门槛 wait 来自配置 staffingAdviceMinutes
323
+ * @param {{ now: number, inTurn: (sessionId: string) => boolean, capacity?: number, remainingSlots?: number | null, humanId?: string | null, wait?: number, onSuppressed?: (entry: object) => void }} options 「慢」的门槛 wait 来自配置 staffingAdviceMinutes
324
324
  * @returns {Array<{ role: 'developer' | 'qa', action: 'add' | 'recover', count: number, memberIds: string[], title: string, reasons: string[], taskIds: string[] }>}
325
325
  */
326
- export function planStaffingAdvice(state, { now, inTurn, capacity = HOST_SUBAGENT_LIMIT, humanId = null, wait = STAFFING_ADVICE_WAIT, onSuppressed }) {
326
+ export function planStaffingAdvice(state, { now, inTurn, capacity = HOST_SUBAGENT_LIMIT, remainingSlots = null, humanId = null, wait = STAFFING_ADVICE_WAIT, onSuppressed }) {
327
327
  const open = openTasks(state);
328
328
  if (open.length === 0) return [];
329
329
  const age = (task) => taskAge(task, now);
@@ -369,7 +369,11 @@ export function planStaffingAdvice(state, { now, inTurn, capacity = HOST_SUBAGEN
369
369
  const reasons = [...entry.reasons];
370
370
  const who = entry.role === 'developer' ? '开发' : '验收';
371
371
  if (entry.action === 'recover') return { ...entry, reasons, title: `建议恢复停摆的${who}:${reasons.join(';')}` };
372
- if (headcount + entry.count > capacity) reasons.push(`团队现有 ${headcount} 名 AI 成员,按这棵代理树的 ${capacity} 个并发位估算,同时跑满时会排队`);
372
+ if (remainingSlots !== null && remainingSlots < entry.count) {
373
+ reasons.push(`采样时这棵代理树剩余 ${remainingSlots} 个并发位,新增成员同时启动会排队`);
374
+ } else if (headcount + entry.count > capacity) {
375
+ reasons.push(`团队现有 ${headcount} 名 AI 成员,按这棵代理树的 ${capacity} 个并发位估算,同时跑满时会排队`);
376
+ }
373
377
  return { ...entry, reasons, title: `建议加 ${entry.count} 名${who}:${reasons.join(';')}` };
374
378
  });
375
379
  }
@@ -1,141 +1,180 @@
1
- import { realpathSync } from 'node:fs';
2
- import { isAbsolute } from 'node:path';
3
- import { listTalents } from '../domain/catalog.js';
4
- import { DomainError, ERRORS, fail } from '../domain/errors.js';
5
- import { unfinishedTasksFor } from '../domain/member-profile.js';
6
-
7
- const USAGE = {
8
- 编制: '/ai-team 编制 [项目ID]',
9
- 人才: '/ai-team 人才 [关键词]',
10
- 增员: '/ai-team 增员 项目ID 人才ID',
11
- 改岗位: '/ai-team 改岗位 项目ID 成员ID 新岗位',
12
- 离队: '/ai-team 离队 项目ID 成员ID [接手人ID]',
13
- };
14
-
15
- export const rosterHelp = Object.values(USAGE).join('\n');
16
- export const isRosterAction = (action) => Object.hasOwn(USAGE, action);
17
-
18
- function workspaceProject(runtime, workspacePath) {
19
- const project = runtime.service.state.projects?.[runtime.id];
20
- if (!project || project.status === 'archived' || typeof project.workspacePath !== 'string' || !isAbsolute(project.workspacePath)) return null;
21
- try {
22
- return realpathSync(project.workspacePath) === workspacePath ? project : null;
23
- } catch {
24
- return null;
25
- }
26
- }
27
-
28
- const memberLabel = (member) => `${member.name}(${member.id})`;
29
-
30
- function describeRoster(runtime, project) {
31
- const state = runtime.service.state;
32
- const members = Object.values(state.members ?? {}).filter((member) => member.kind === 'agent');
33
- return [
34
- `「${project.name}」的编制(${project.id})`,
35
- ...members.map((member) => {
36
- const unfinished = unfinishedTasksFor(state, member.id).length;
37
- const role = member.role ? ` · ${member.role}` : '';
38
- const departed = member.status === 'retired' ? ' · 已离队' : '';
39
- return `- ${memberLabel(member)}${role}${departed} · ${unfinished} 张未收口任务`;
40
- }),
41
- '使用 /ai-team 人才查看可选人才。',
42
- ].join('\n');
43
- }
44
-
45
- function planChange(runtime, action, target, value, catalog) {
46
- const reason = '会话编制草稿确认';
47
- if (action === '增员') {
48
- const talent = catalog().talents.get(target);
49
- if (!talent) fail(ERRORS.NOT_FOUND, '人才库中找不到该人才。使用 /ai-team 人才 查看可选人才。');
50
- return {
51
- type: 'member.add',
52
- payload: {
53
- name: talent.name, role: talent.role, duty: talent.duty,
54
- personality: talent.personality, skills: talent.skills, avatar: talent.avatar,
55
- talent: talent.id, talentVersion: talent.version,
56
- },
57
- lines: [`增员 ${talent.name} · ${talent.role}(${talent.id})`],
58
- };
59
- }
60
- if (action === '改岗位') {
61
- const member = runtime.service.state.members?.[target];
62
- if (member?.kind !== 'agent' || member.status === 'retired') fail(ERRORS.NOT_FOUND, '同一项目中找不到这位在队成员。');
63
- if (member.role === value) fail(ERRORS.INVALID_ARGUMENT, '该成员已经是这个岗位。');
64
- return {
65
- type: 'member.profile.update', payload: { memberId: target, role: value, reason },
66
- lines: [`岗位 ${memberLabel(member)} 从「${member.role || '未设置'}」改为「${value}」`],
67
- };
68
- }
69
- const payload = { memberId: target, ...(value ? { successorId: value } : {}), reason };
70
- const { member, successor, unfinished } = runtime.service.describeMemberDeparture(runtime.id, payload, { reviewed: true });
71
- return {
72
- type: 'member.leave', payload,
73
- lines: [
74
- `离队 ${memberLabel(member)}进入人才池`,
75
- ...(successor === null ? [] : [`接手人 ${memberLabel(successor)}`]),
76
- ...(unfinished.length === 0 ? ['该成员没有未收口任务。'] : unfinished.map((task) => `- #${task.number} ${task.title}(${task.status})`)),
77
- ],
78
- taskRevisions: unfinished.map(({ id, revision }) => [id, revision]),
79
- };
80
- }
81
-
82
- export function createSessionRoster({ runtimes, isAvailable, catalog, actor, disposeMemberActivation }) {
83
- return async function prepareRoster({ action, argument, workspacePath }) {
84
- if (action === '人才') {
85
- const query = argument.trim().toLowerCase();
86
- const talents = listTalents(catalog()).filter((talent) => [talent.id, talent.name, talent.role].some((value) => value.toLowerCase().includes(query)));
87
- return { text: talents.length === 0 ? '没有匹配的人才。' : talents.map((talent) => `- ${talent.id} · ${talent.name} · ${talent.role}`).join('\n') };
88
- }
89
- const [, projectId, target, value = ''] = /^(\S+)(?:\s+(\S+))?(?:\s+([\s\S]+))?$/.exec(argument.trim()) ?? [];
90
- const wrongTarget = action === '编制' ? target !== undefined : target === undefined;
91
- if (wrongTarget || (action === '增员' && value !== '') || (action === '改岗位' && value === '')
92
- || (action === '离队' && /\s/.test(value))) {
93
- fail(ERRORS.INVALID_ARGUMENT, `用 ${USAGE[action]}。`);
94
- }
95
- const options = [];
96
- for (const runtime of await runtimes()) {
97
- const project = isAvailable(runtime) ? workspaceProject(runtime, workspacePath) : null;
98
- if (project !== null) options.push({ runtime, project });
99
- }
100
- if (projectId === undefined && options.length > 1) {
101
- return { text: ['同一工作区有多个项目,请使用 /ai-team 编制 项目ID。', ...options.map(({ project }) => `- ${project.id} · ${project.name}`)].join('\n') };
102
- }
103
- const selection = projectId === undefined ? options[0] : options.find(({ project }) => project.id === projectId);
104
- if (!selection) fail(ERRORS.NOT_FOUND, '当前会话的工作区找不到该项目。使用 /ai-team 编制 查看同一工作区的项目。');
105
- const { runtime, project } = selection;
106
- if (action === '编制') return { text: describeRoster(runtime, project) };
107
-
108
- const change = planChange(runtime, action, target, value, catalog);
109
- const command = { type: change.type, payload: change.payload, actor, projectId };
110
- runtime.service.checkBlueprintCommand(command, change.payload);
111
- const approved = JSON.stringify(change);
112
- return {
113
- projectId, action,
114
- lines: [`编制草稿 ${project.name}(${projectId})`, ...change.lines],
115
- async apply(draftId) {
116
- const result = await runtime.service.dispatch({
117
- ...command, correlationId: draftId,
118
- verifyDraft() {
119
- const currentProject = isAvailable(runtime) ? workspaceProject(runtime, workspacePath) : null;
120
- if (!currentProject || currentProject.name !== project.name) {
121
- fail(ERRORS.REVISION, '项目或工作目录已变化,请重新生成草稿。');
122
- }
123
- let current;
124
- try {
125
- current = planChange(runtime, action, target, value, catalog);
126
- } catch (error) {
127
- if (error instanceof DomainError) fail(ERRORS.REVISION, `${error.message} 请核对编制后重新生成草稿。`);
128
- throw error;
129
- }
130
- if (JSON.stringify(current) !== approved) fail(ERRORS.REVISION, '成员、人才或任务已变化,请重新生成草稿。');
131
- },
132
- });
133
- if (action === '离队') {
134
- await disposeMemberActivation(runtime, target, command.type);
135
- return `已将${memberLabel(result.member)}移入人才池,交接了 ${result.transferredTasks?.length ?? 0} 张原任务。`;
136
- }
137
- return action === '增员' ? `已添加${memberLabel(result.member)}。` : `已将${memberLabel(result.member)}的岗位更新为「${result.member.role}」。`;
138
- },
139
- };
140
- };
141
- }
1
+ import { realpathSync } from 'node:fs';
2
+ import { isAbsolute } from 'node:path';
3
+ import { listTalents } from '../domain/catalog.js';
4
+ import { DomainError, ERRORS, fail } from '../domain/errors.js';
5
+ import { unfinishedTasksFor } from '../domain/member-profile.js';
6
+
7
+ const USAGE = {
8
+ 编制: '/ai-team 编制 [项目ID]',
9
+ 调整: '/ai-team 调整 [项目ID] 一句话',
10
+ 人才: '/ai-team 人才 [关键词]',
11
+ 增员: '/ai-team 增员 项目ID 人才ID',
12
+ 改岗位: '/ai-team 改岗位 项目ID 成员ID 新岗位',
13
+ 离队: '/ai-team 离队 项目ID 成员ID [接手人ID]',
14
+ };
15
+
16
+ export const rosterHelp = Object.values(USAGE).join('\n');
17
+ export const isRosterAction = (action) => Object.hasOwn(USAGE, action);
18
+
19
+ function workspaceProject(runtime, workspacePath) {
20
+ const project = runtime.service.state.projects?.[runtime.id];
21
+ if (!project || project.status === 'archived' || typeof project.workspacePath !== 'string' || !isAbsolute(project.workspacePath)) return null;
22
+ try {
23
+ return realpathSync(project.workspacePath) === workspacePath ? project : null;
24
+ } catch {
25
+ return null;
26
+ }
27
+ }
28
+
29
+ const memberLabel = (member) => `${member.name}(${member.id})`;
30
+
31
+ function resolveName(entries, value, label, aliases = (entry) => [entry.name]) {
32
+ const name = value.trim();
33
+ const direct = entries.find(({ id }) => id === name);
34
+ if (direct) return direct.id;
35
+ const matches = entries.filter((entry) => aliases(entry).includes(name));
36
+ if (matches.length === 1) return matches[0].id;
37
+ if (matches.length === 0) fail(ERRORS.NOT_FOUND, `找不到${label}「${name}」,请核对名字或编号。`);
38
+ fail(ERRORS.CONFLICT, `${label}「${name}」有多个候选,请使用编号。\n${matches.map(memberLabel).join('\n')}`);
39
+ }
40
+
41
+ function readRosterSentence(sentence, runtime, catalog) {
42
+ const statement = sentence.trim().replace(/[。!!.]$/u, '');
43
+ const hint = '一句话只能准备一项调整。示例:给团队加一位文案;把校书的岗位改为文档协调;让墨痕把任务交给校书后离队。';
44
+ if (/[。;;\r\n]|(?:并|同时|然后)\s*(?:给|把|让|再|加|离队|改)/u.test(statement)) fail(ERRORS.INVALID_ARGUMENT, hint);
45
+ const hire = /^给团队加(?:一位|一名)\s*(.+)$/u.exec(statement);
46
+ if (hire) {
47
+ const target = resolveName(listTalents(catalog()), hire[1], '人才', ({ name, role }) => [name, role]);
48
+ return { action: '增员', target, value: '' };
49
+ }
50
+ const members = Object.values(runtime.service.state.members ?? {}).filter(({ kind, status }) => kind === 'agent' && status !== 'retired');
51
+ const findMember = (name) => resolveName(members, name, '成员');
52
+ const edit = /^把(.+?)的岗位改为\s*(.+)$/u.exec(statement);
53
+ if (edit) return { action: '改岗位', target: findMember(edit[1]), value: edit[2].trim() };
54
+ const handoff = /^让(.+?)把任务交给(.+?)后离队$/u.exec(statement);
55
+ if (handoff) return { action: '离队', target: findMember(handoff[1]), value: findMember(handoff[2]) };
56
+ const leave = /^让(.+?)离队$/u.exec(statement);
57
+ if (leave) return { action: '离队', target: findMember(leave[1]), value: '' };
58
+ fail(ERRORS.INVALID_ARGUMENT, hint);
59
+ }
60
+
61
+ function describeRoster(runtime, project) {
62
+ const state = runtime.service.state;
63
+ const members = Object.values(state.members ?? {}).filter((member) => member.kind === 'agent');
64
+ return [
65
+ `「${project.name}」的编制(${project.id})`,
66
+ ...members.map((member) => {
67
+ const unfinished = unfinishedTasksFor(state, member.id).length;
68
+ const role = member.role ? ` · ${member.role}` : '';
69
+ const departed = member.status === 'retired' ? ' · 已离队' : '';
70
+ return `- ${memberLabel(member)}${role}${departed} · ${unfinished} 张未收口任务`;
71
+ }),
72
+ '使用 /ai-team 人才查看可选人才。',
73
+ ].join('\n');
74
+ }
75
+
76
+ function planChange(runtime, action, target, value, catalog) {
77
+ const reason = '会话编制草稿确认';
78
+ if (action === '增员') {
79
+ const talent = catalog().talents.get(target);
80
+ if (!talent) fail(ERRORS.NOT_FOUND, '人才库中找不到该人才。使用 /ai-team 人才 查看可选人才。');
81
+ return {
82
+ type: 'member.add',
83
+ payload: {
84
+ name: talent.name, role: talent.role, duty: talent.duty,
85
+ personality: talent.personality, skills: talent.skills, avatar: talent.avatar,
86
+ talent: talent.id, talentVersion: talent.version,
87
+ },
88
+ lines: [`增员 ${talent.name} · ${talent.role}(${talent.id})`],
89
+ };
90
+ }
91
+ if (action === '改岗位') {
92
+ const member = runtime.service.state.members?.[target];
93
+ if (member?.kind !== 'agent' || member.status === 'retired') fail(ERRORS.NOT_FOUND, '同一项目中找不到这位在队成员。');
94
+ if (member.role === value) fail(ERRORS.INVALID_ARGUMENT, '该成员已经是这个岗位。');
95
+ return {
96
+ type: 'member.profile.update', payload: { memberId: target, role: value, reason },
97
+ lines: [`岗位 ${memberLabel(member)} 从「${member.role || '未设置'}」改为「${value}」`],
98
+ };
99
+ }
100
+ const payload = { memberId: target, ...(value ? { successorId: value } : {}), reason };
101
+ const { member, successor, unfinished } = runtime.service.describeMemberDeparture(runtime.id, payload, { reviewed: true });
102
+ return {
103
+ type: 'member.leave', payload,
104
+ lines: [
105
+ `离队 ${memberLabel(member)}进入人才池`,
106
+ ...(successor === null ? [] : [`接手人 ${memberLabel(successor)}`]),
107
+ ...(unfinished.length === 0 ? ['该成员没有未收口任务。'] : unfinished.map((task) => `- #${task.number} ${task.title}(${task.status})`)),
108
+ ],
109
+ taskRevisions: unfinished.map(({ id, revision }) => [id, revision]),
110
+ };
111
+ }
112
+
113
+ export function createSessionRoster({ runtimes, isAvailable, catalog, actor, disposeMemberActivation }) {
114
+ return async function prepareRoster({ action: requested, argument, workspacePath }) {
115
+ if (requested === '人才') {
116
+ const query = argument.trim().toLowerCase();
117
+ const talents = listTalents(catalog()).filter((talent) => [talent.id, talent.name, talent.role].some((value) => value.toLowerCase().includes(query)));
118
+ return { text: talents.length === 0 ? '没有匹配的人才。' : talents.map((talent) => `- ${talent.id} · ${talent.name} · ${talent.role}`).join('\n') };
119
+ }
120
+ const input = argument.trim();
121
+ const [, first, supplied, rest = ''] = /^(\S+)(?:\s+(\S+))?(?:\s+([\s\S]+))?$/.exec(input) ?? [];
122
+ const requestedSentence = requested === '调整';
123
+ const requestedProject = requestedSentence && !first?.startsWith('prj_') ? undefined : first;
124
+ if (!requestedSentence) {
125
+ const wrongTarget = requested === '编制' ? supplied !== undefined : supplied === undefined;
126
+ if (wrongTarget || (requested === '增员' && rest !== '') || (requested === '改岗位' && rest === '')
127
+ || (requested === '离队' && /\s/.test(rest))) fail(ERRORS.INVALID_ARGUMENT, `用 ${USAGE[requested]}。`);
128
+ }
129
+ const options = [];
130
+ for (const runtime of await runtimes()) {
131
+ const project = isAvailable(runtime) ? workspaceProject(runtime, workspacePath) : null;
132
+ if (project !== null) options.push({ runtime, project });
133
+ }
134
+ if (requestedProject === undefined && options.length > 1) {
135
+ const usage = requestedSentence ? '/ai-team 调整 项目ID 一句话' : '/ai-team 编制 项目ID';
136
+ return { text: [`同一工作区有多个项目,请使用 ${usage}。`, ...options.map(({ project }) => `- ${project.id} · ${project.name}`)].join('\n') };
137
+ }
138
+ const selection = requestedProject === undefined ? options[0] : options.find(({ project }) => project.id === requestedProject);
139
+ if (!selection) fail(ERRORS.NOT_FOUND, '当前会话的工作区找不到该项目。使用 /ai-team 编制 查看同一工作区的项目。');
140
+ const { runtime, project } = selection;
141
+ if (requested === '编制') return { text: describeRoster(runtime, project) };
142
+ const { action, target, value } = requestedSentence
143
+ ? readRosterSentence(requestedProject ? input.slice(first.length) : input, runtime, catalog)
144
+ : { action: requested, target: supplied, value: rest };
145
+ const projectId = project.id;
146
+
147
+ const change = planChange(runtime, action, target, value, catalog);
148
+ const command = { type: change.type, payload: change.payload, actor, projectId };
149
+ runtime.service.checkBlueprintCommand(command, change.payload);
150
+ const approved = JSON.stringify(change);
151
+ return {
152
+ projectId, action,
153
+ lines: [`编制草稿 ${project.name}(${projectId})`, ...change.lines],
154
+ async apply(draftId) {
155
+ const result = await runtime.service.dispatch({
156
+ ...command, correlationId: draftId,
157
+ verifyDraft() {
158
+ const currentProject = isAvailable(runtime) ? workspaceProject(runtime, workspacePath) : null;
159
+ if (!currentProject || currentProject.name !== project.name) {
160
+ fail(ERRORS.REVISION, '项目或工作目录已变化,请重新生成草稿。');
161
+ }
162
+ let current;
163
+ try {
164
+ current = planChange(runtime, action, target, value, catalog);
165
+ } catch (error) {
166
+ if (error instanceof DomainError) fail(ERRORS.REVISION, `${error.message} 请核对编制后重新生成草稿。`);
167
+ throw error;
168
+ }
169
+ if (JSON.stringify(current) !== approved) fail(ERRORS.REVISION, '成员、人才或任务已变化,请重新生成草稿。');
170
+ },
171
+ });
172
+ if (action === '离队') {
173
+ await disposeMemberActivation(runtime, target, command.type);
174
+ return `已将${memberLabel(result.member)}移入人才池,交接了 ${result.transferredTasks?.length ?? 0} 张原任务。`;
175
+ }
176
+ return action === '增员' ? `已添加${memberLabel(result.member)}。` : `已将${memberLabel(result.member)}的岗位更新为「${result.member.role}」。`;
177
+ },
178
+ };
179
+ };
180
+ }
@@ -5,7 +5,7 @@ import { ids, newId } from '../domain/ids.js';
5
5
  import { isRosterAction, rosterHelp } from './session-roster.js';
6
6
  import { requireWorkspaceDirectory } from './workspace-path.js';
7
7
 
8
- const HELP = `用 /ai-team 建队 目标 生成草稿。可在目标前加 --team 预设ID。按草稿中的命令确认或取消。\n${rosterHelp}`;
8
+ const HELP = `用 /ai-team 建队 目标 生成草稿。可在目标前加 --team 预设ID 或 --recommend。按草稿中的命令确认或取消。\n${rosterHelp}`;
9
9
 
10
10
  function sessionWorkspace(session) {
11
11
  const path = session?.header?.cwd;
@@ -31,7 +31,7 @@ export function sessionTeamCommand({ prepare, create, prepareRoster, diag }) {
31
31
  return {
32
32
  name: 'ai-team',
33
33
  description: '在会话里建队和调整文渊阁编制',
34
- input: { hint: '建队 / 编制 / 人才 / 增员 / 改岗位 / 离队 / 确认 / 取消' },
34
+ input: { hint: '建队 / 编制 / 调整 / 人才 / 增员 / 改岗位 / 离队 / 确认 / 取消' },
35
35
  async handler({ agent, rawInput, signal }) {
36
36
  const session = agent?.session;
37
37
  const [, action, argument = ''] = /^(\S+)(?:\s+([\s\S]*))?$/.exec(rawInput.trim()) ?? [];
@@ -48,9 +48,10 @@ export function sessionTeamCommand({ prepare, create, prepareRoster, diag }) {
48
48
  }
49
49
  if (action === '建队') {
50
50
  const selected = /^--team\s+(\S+)\s+([\s\S]+)$/.exec(argument);
51
- const goal = (selected?.[2] ?? argument).trim();
51
+ const recommend = /^--recommend(?:\s|$)/.test(argument);
52
+ const goal = (recommend ? argument.slice('--recommend'.length) : selected?.[2] ?? argument).trim();
52
53
  if (goal === '' || (!selected && argument.startsWith('--team'))) return { kind: 'error', text: HELP };
53
- const input = { name: goal.split(/\r?\n/, 1)[0], goal, workspacePath, team: selected?.[1] ?? '' };
54
+ const input = { name: goal.split(/\r?\n/, 1)[0], goal, workspacePath, team: selected?.[1] ?? '', recommend };
54
55
  const proposed = prepare(input);
55
56
  const id = ids.project();
56
57
  const signature = presetSignature(proposed.teamPreset);
@@ -62,11 +63,18 @@ export function sessionTeamCommand({ prepare, create, prepareRoster, diag }) {
62
63
  `目标 ${goal}`,
63
64
  `工作目录 ${workspacePath}`,
64
65
  `预设 ${proposed.teamPreset.team.name}(${proposed.teamPreset.id})`,
66
+ ...(proposed.matchedTerms ? [`匹配依据 ${proposed.matchedTerms.join('、')}`] : []),
65
67
  ...proposed.teamPreset.team.members.map((member) => `- ${member.name} · ${member.role}`),
66
68
  '确认后创建项目,PMO 自动为关闭状态。',
67
69
  ],
68
70
  async apply() {
69
- const approved = prepare(input);
71
+ let approved;
72
+ try {
73
+ approved = prepare(input);
74
+ } catch (error) {
75
+ if (error instanceof DomainError) fail(ERRORS.REVISION, '团队预设已更新,请重新生成草稿后再确认。');
76
+ throw error;
77
+ }
70
78
  if (presetSignature(approved.teamPreset) !== signature) {
71
79
  fail(ERRORS.REVISION, '团队预设已更新,请重新生成草稿后再确认。');
72
80
  }
@@ -45,14 +45,29 @@ export function isCapacityError(error) {
45
45
  export function capacityLimit(error) {
46
46
  if (!isCapacityError(error)) return null;
47
47
  const match = /active child limit:\s*(\d+)/i.exec(String(error?.message ?? ''));
48
- return match === null ? null : Number(match[1]);
48
+ const limit = match === null ? null : Number(match[1]);
49
+ return Number.isSafeInteger(limit) && limit > 0 ? limit : null;
49
50
  }
50
51
 
51
- /** DSH reserves activation slots per root Agent. A replacement root starts with no observed limit. */
52
- export function observeTreeCapacity() {
52
+ /** Sample the exact live Agent tree. Older hosts only reveal a limit in their capacity errors. */
53
+ export function observeTreeCapacity({ diag } = {}) {
53
54
  const limits = new WeakMap();
54
55
  return {
55
- get: (root) => limits.get(root) ?? null,
56
+ read(root, subagents) {
57
+ if (root != null && typeof subagents?.capacityOf === 'function') {
58
+ try {
59
+ const { running, limit } = subagents.capacityOf(root) ?? {};
60
+ if (!Number.isSafeInteger(running) || running < 0 || !Number.isSafeInteger(limit) || limit < 1) {
61
+ throw new Error('capacityOf returned invalid slot counts');
62
+ }
63
+ return { capacity: limit, capacitySource: 'host-live', occupiedSlots: running, remainingSlots: Math.max(0, limit - running) };
64
+ } catch (error) {
65
+ diag?.append({ ev: 'pmo.staffing.capacity.fail', rootId: root.id ?? null, code: error?.code ?? null, message: error?.message ?? String(error) });
66
+ }
67
+ }
68
+ const capacity = limits.get(root) ?? null;
69
+ return { capacity, capacitySource: capacity === null ? 'default' : 'host', occupiedSlots: null, remainingSlots: null };
70
+ },
56
71
  record(root, error) {
57
72
  if (root == null || typeof root !== 'object') return;
58
73
  const limit = capacityLimit(error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suifei/dsh-ai-team",
3
- "version": "0.4.156",
3
+ "version": "0.4.158",
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",