@suifei/dsh-ai-team 0.4.96 → 0.4.97

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,22 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.97 - 2026-11-15
4
+
5
+ **换新团队会话:`project.team.renew`(Human,项目停止时)**
6
+
7
+ 官方契约:父会话的子智能体目录在创建时记下成员关系、永久保留,宿主没有删除 API。il2c 的旧 PMO 因 0.4.88 之前的
8
+ 自愈重建挂着 330 个子智能体,0.4.95 起不再增加,但存量只能靠换一个新的 PMO 会话清掉。
9
+
10
+ - 新命令 `project.team.renew`:仅项目停止时可用(运行中 409)。新建 PMO 会话(不续接旧会话)并落账
11
+ `team/host-bound`;全部在册成员在新 PMO 下各重建一次(Human 发起),提示里带上该成员手上那张卡与最近讨论;
12
+ 旧 PMO 从工作区摘下并归档(`stopActivity`),名下旧子智能体随血缘一起归档;
13
+ - `ensureParent(runtime, { fresh: true })`:丢弃缓存的 PMO 句柄、跳过续接直接新建(复用既有新建路径);
14
+ - 诊断 `team.renewed`(`errors` 级,列出新旧 PMO 与每个成员的新旧会话)/ `team.renew.fail`;
15
+ - 测试:`node --test` **335 通过 / 1 跳过**;`host.test` 新增「运行中拒绝;停止后新 PMO、成员全部换新、旧 PMO 归档并
16
+ 摘出工作区、新 PMO 入工作区」(旧代码即失败);
17
+ - E2E(隔离 DSH_HOME,rc.1 / rc.3):旧 PMO 下 12 个子智能体 → 换新后新 PMO 下 6 个;工作区 7 个会话(新 PMO + 6
18
+ 成员)、旧 PMO 已归档;随后启动项目派卡,唤醒全部投递到换新后的会话、卡片走完一轮。
19
+
3
20
  ## 0.4.96 - 2026-11-15
4
21
 
5
22
  **停止即停:停止期间 PMO 与成员不能再用宿主内置工具互相唤醒**
package/index.js CHANGED
@@ -1844,11 +1844,18 @@ export function apply(ctx, config = {}) {
1844
1844
  * 成员都是它的子会话,于是全部落在同一工作区。不传项目时取活动项目(skillopt 评审等
1845
1845
  * 与具体项目无关的子代理)。没有工作区的项目没有 PMO——必须指定工作区才能工作。
1846
1846
  */
1847
- const ensureParent = async (projectRuntime = booted?.runtime) => {
1847
+ const ensureParent = async (projectRuntime = booted?.runtime, options = {}) => {
1848
1848
  if (projectRuntime === null || projectRuntime === undefined) {
1849
1849
  throw Object.assign(new Error('no project runtime for the PMO session'), { code: 'E_RUNTIME_UNAVAILABLE' });
1850
1850
  }
1851
1851
  const projectId = projectRuntime.id;
1852
+ // fresh:Human 的「换新团队会话」——丢掉当前 PMO 句柄,不续接旧会话、直接新建。
1853
+ if (options.fresh === true) {
1854
+ const previous = hosts.get(projectId);
1855
+ hosts.delete(projectId);
1856
+ hostPromises.delete(projectId);
1857
+ try { await previous?.dispose?.(); } catch { /* already gone */ }
1858
+ }
1852
1859
  const ready = hosts.get(projectId);
1853
1860
  if (ready !== undefined) return ready;
1854
1861
  await repairArchivedHosts();
@@ -1865,7 +1872,7 @@ export function apply(ctx, config = {}) {
1865
1872
  workspaceRegistry: serviceOf(ctx, 'workspaceRegistry'),
1866
1873
  sessions: serviceOf(ctx, 'sessions'),
1867
1874
  cwd,
1868
- resumeSessionId: projectRuntime.service.state.hostSessionId,
1875
+ resumeSessionId: options.fresh === true ? null : projectRuntime.service.state.hostSessionId,
1869
1876
  }).then(async (value) => {
1870
1877
  // 卸载后才完成的父代理:句柄不能留在进程里,也不能写账本。
1871
1878
  if (disposed) {
@@ -2665,6 +2672,67 @@ export function apply(ctx, config = {}) {
2665
2672
  }
2666
2673
  // 成员恢复巡检(不依赖 boot/tick):subagent provider 不提供
2667
2674
  // continuable 会话,唤醒失败后必须重建会话——单成员或全量。
2675
+ // 换新团队会话(Human):新建 PMO 会话、7 个成员在新 PMO 下各重建一次、归档旧 PMO。
2676
+ // 用途:旧 PMO 的子智能体目录在创建时记下全部成员关系且永久保留(官方契约,无删除
2677
+ // API)——il2c 的旧 PMO 因历史自愈重建挂着 330 个子智能体。只能在项目停止时做。
2678
+ if (body.type === 'project.team.renew') {
2679
+ const state = runtime.service.state;
2680
+ if (state.projects?.[runtime.id]?.runState !== 'stopped') {
2681
+ return send(res, { error: { code: 'E_INVALID_STATE', message: 'stop the project before renewing its team sessions' } }, 409);
2682
+ }
2683
+ const previousHostSessionId = typeof state.hostSessionId === 'string' ? state.hostSessionId : null;
2684
+ let host;
2685
+ try {
2686
+ host = await ensureParent(runtime, { fresh: true });
2687
+ } catch (error) {
2688
+ diag.append({ ev: 'team.renew.fail', projectId: runtime.id, stage: 'host', message: error?.message ?? String(error) });
2689
+ return send(res, { error: { code: error?.code ?? 'E_RUNTIME', message: error?.message ?? String(error) } }, 409);
2690
+ }
2691
+ const results = [];
2692
+ for (const member of Object.values(runtime.service.state.members ?? {}).filter((entry) => entry.kind === 'agent' && entry.status !== 'retired')) {
2693
+ const before = member.sessionId ?? null;
2694
+ // 把成员手上那张卡(及最近讨论)直接递过去:重建 = 上下文清零。
2695
+ const activeTaskOf = (target) => Object.values(runtime.service.state.tasks ?? {}).find((task) => task.tombstone !== true
2696
+ && ['in_progress', 'pending_acceptance', 'pending'].includes(task.status)
2697
+ && (task.assigneeId === target.id || task.ownerId === target.id))?.id ?? null;
2698
+ try {
2699
+ const activated = await activateMember({
2700
+ payload: {
2701
+ memberId: member.id,
2702
+ force: true,
2703
+ prompt: `团队会话已换新(Human 操作,你的上一段对话不在本会话里)。先读 tasks 与 thread 的当前状态,再继续你名下未完成的工作;项目当前已停止,等 Human 重新启动后再动手。${describeTaskContext(runtime.service.state, activeTaskOf(member), { includeThread: true })}`,
2704
+ },
2705
+ }, runtime);
2706
+ results.push({ memberId: member.id, ok: activated.error === undefined, oldSessionId: before, newSessionId: activated.sessionId ?? null, error: activated.error ?? null });
2707
+ } catch (error) {
2708
+ results.push({ memberId: member.id, ok: false, oldSessionId: before, newSessionId: null, error: { code: 'E_RUNTIME', message: error?.message ?? String(error) } });
2709
+ }
2710
+ }
2711
+ // 旧 PMO:从工作区摘下并归档,侧栏不再出现;它名下的旧子智能体随血缘一起归档。
2712
+ let archived = false;
2713
+ if (previousHostSessionId !== null && previousHostSessionId !== host.sessionId) {
2714
+ await detachMemberWorkspace(runtime, previousHostSessionId);
2715
+ const registry = serviceOf(ctx, 'workspaceRegistry');
2716
+ try {
2717
+ if (typeof registry?.archiveSession === 'function') {
2718
+ await registry.archiveSession(previousHostSessionId, { stopActivity: true });
2719
+ archived = true;
2720
+ }
2721
+ } catch (error) {
2722
+ diag.append({ ev: 'team.renew.fail', projectId: runtime.id, stage: 'archive', sessionId: previousHostSessionId, message: error?.message ?? String(error) });
2723
+ }
2724
+ }
2725
+ diag.append({
2726
+ ev: 'team.renewed',
2727
+ projectId: runtime.id,
2728
+ previousHostSessionId,
2729
+ hostSessionId: host.sessionId,
2730
+ archived,
2731
+ members: results.map((row) => ({ memberId: row.memberId, ok: row.ok, oldSessionId: row.oldSessionId, newSessionId: row.newSessionId })),
2732
+ });
2733
+ broadcast(undefined);
2734
+ return send(res, { ok: results.every((row) => row.ok), hostSessionId: host.sessionId, previousHostSessionId, archived, results });
2735
+ }
2668
2736
  if (body.type === 'member.reseat') {
2669
2737
  const payload = body.payload ?? {};
2670
2738
  const state = runtime.service.state;
package/lib/diaglog.js CHANGED
@@ -39,6 +39,8 @@ export function isErrorEvent(ev) {
39
39
  || ev === 'team.interrupt'
40
40
  // 停止期间团队会话想唤醒/派生智能体被拦下:停止是否真的停住的直接证据。
41
41
  || ev === 'team.stopped.blocked'
42
+ // 换新团队会话(Human):新旧 PMO 与每个成员的新旧会话。
43
+ || ev === 'team.renewed'
42
44
  // 重建后旧会话有没有从工作区摘掉:决定工作区列表是否随自愈累积死会话。
43
45
  || ev === 'workspace.detach');
44
46
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suifei/dsh-ai-team",
3
- "version": "0.4.96",
3
+ "version": "0.4.97",
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",