@suifei/dsh-ai-team 0.3.52 → 0.3.53

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,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.53 — 2026-11-10
4
+
5
+ 修复全新环境安装三连问题(严重):
6
+
7
+ - **`{{model}}` 无值**:成员/宿主 session 只把 provider/model 挂在活体 Agent options 上;进程重启后恢复的 session 两者皆无,prompt 渲染失败。现在 activation/wake/boot 都会把 `model/selection` 写入 session 日志,路由跨重启持久有效;
8
+ - **插件开关破坏宿主**:卸载清理此前是 fire-and-forget,旧组合未清理完新组合已激活。现在 disposer 完全等待宿主/激活/账本清理收尾,且绝不抛错;
9
+ - **首次安装即坏**:`boot()` 同步异常或 skill provider/team tool 注册异常会让组合激活失败。现在全部降级为警告,插件激活永不失败。
10
+
3
11
  ## 0.3.52 — 2026-11-10
4
12
 
5
13
  - bootstrap 返回全部 Task 的 Thread 映射,修复卡片显示 6 条回复但右栏打开为空的错位;
package/index.js CHANGED
@@ -34,7 +34,7 @@ export const name = 'ai-team';
34
34
  /** The workbench only makes sense where the Web carrier exists. */
35
35
  export const inject = ['webServer', 'permissionPresets', 'sandboxPolicy'];
36
36
 
37
- const VERSION = '0.3.52';
37
+ const VERSION = '0.3.53';
38
38
  const PROJECT_ID = 'prj_main';
39
39
  const HUMAN_ID = 'mem_human';
40
40
 
@@ -166,12 +166,30 @@ export function apply(ctx) {
166
166
  console.warn('[ai-team] member session workspace attach failed:', error?.message ?? error);
167
167
  }
168
168
  };
169
+ // A restored member session has no live AgentOptions; without a recorded
170
+ // model/selection event its prompt renders with an unresolvable {{model}}.
171
+ const modelSelectionLogged = new Map();
172
+ const persistModelSelection = (sessionId, selection, label) => {
173
+ if (typeof sessionId !== 'string' || sessionId === '') return;
174
+ if (typeof selection?.provider !== 'string' || selection.provider === ''
175
+ || typeof selection?.model !== 'string' || selection.model === '') return;
176
+ const route = `${selection.provider}/${selection.model}`;
177
+ if (modelSelectionLogged.get(sessionId) === route) return;
178
+ try {
179
+ const session = ctx.get('sessions')?.get?.(sessionId);
180
+ if (session === undefined || session === null || typeof session.append !== 'function') return;
181
+ session.append('model/selection', { provider: selection.provider, model: selection.model });
182
+ modelSelectionLogged.set(sessionId, route);
183
+ } catch (error) {
184
+ console.warn('[ai-team] model selection persist failed:', label ?? sessionId, error?.message ?? error);
185
+ }
186
+ };
169
187
  const access = validatePermissionProfile({
170
188
  permissionPresets: ctx.get('permissionPresets'),
171
189
  sandboxPolicy: ctx.get('sandboxPolicy'),
172
190
  });
173
191
  const ready = access.ok
174
- ? boot()
192
+ ? Promise.resolve().then(boot)
175
193
  .then(async (value) => {
176
194
  booted = value;
177
195
  for (const runtime of value.runtimes.values()) {
@@ -179,6 +197,7 @@ export function apply(ctx) {
179
197
  if (member.kind === 'agent' && typeof member.sessionId === 'string') {
180
198
  await attachMemberWorkspace(runtime, member.sessionId);
181
199
  await titleMemberSession(runtime, member);
200
+ persistModelSelection(member.sessionId, member.config, member.name);
182
201
  }
183
202
  }
184
203
  void pmoTick(runtime).catch((error) => console.warn('[ai-team] PMO tick failed:', error?.message ?? error));
@@ -342,6 +361,7 @@ export function apply(ctx) {
342
361
  messageId = delivered.messageId ?? null;
343
362
  // A cold session cannot be renamed before wake; retry once it is live.
344
363
  await titleMemberSession(projectRuntime, member);
364
+ persistModelSelection(member.sessionId, member.config, member.name);
345
365
  }
346
366
  await projectRuntime.service.recordWake(plan.memberId, {
347
367
  ok: true, taskId: plan.taskId, reason: plan.reason, messageId,
@@ -505,11 +525,18 @@ export function apply(ctx) {
505
525
  };
506
526
 
507
527
  const skillsService = ctx.get('skills');
508
- const disposeSkillProvider = installFileSkillProvider(skillsService, {
509
- dshHome: dshHome(),
510
- projectCwd: process.cwd(),
511
- bundledDir: fileURLToPath(new URL('./', import.meta.url)),
512
- });
528
+ let disposeSkillProvider = () => {};
529
+ try {
530
+ // A vendor failure must never fail composition activation: that left
531
+ // fresh installs with a half-activated host until a process restart.
532
+ disposeSkillProvider = installFileSkillProvider(skillsService, {
533
+ dshHome: dshHome(),
534
+ projectCwd: process.cwd(),
535
+ bundledDir: fileURLToPath(new URL('./', import.meta.url)),
536
+ }) ?? (() => {});
537
+ } catch (error) {
538
+ console.warn('[ai-team] file skill provider failed:', error?.message ?? error);
539
+ }
513
540
  const tools = ctx.get('tools');
514
541
  let disposeSkillOpt = () => {};
515
542
  try {
@@ -528,20 +555,25 @@ export function apply(ctx) {
528
555
  } catch (error) {
529
556
  console.warn('[ai-team] bundled SkillOpt tools failed:', error?.message ?? error);
530
557
  }
531
- const disposeTool = tools?.register
532
- ? tools.register(createTeamTool({
533
- getState: (exec) => runtimeForAgent(exec?.agent?.id)?.service.state
534
- ?? booted?.service.state
535
- ?? { projects: {}, members: {}, tasks: {}, threads: {}, inbox: {} },
536
- dispatch: (command, exec) => {
537
- const runtime = runtimeForAgent(exec?.agent?.id) ?? projectRuntime(command?.projectId) ?? null;
538
- if (runtime === null) return Promise.reject(new Error('no Project runtime'));
539
- return runtime.service.dispatch(command);
540
- },
541
- }), {
542
- when: (activation) => runtimeForAgent(activation?.agent?.id) !== null,
543
- })
544
- : () => {};
558
+ let disposeTool = () => {};
559
+ try {
560
+ disposeTool = tools?.register
561
+ ? tools.register(createTeamTool({
562
+ getState: (exec) => runtimeForAgent(exec?.agent?.id)?.service.state
563
+ ?? booted?.service.state
564
+ ?? { projects: {}, members: {}, tasks: {}, threads: {}, inbox: {} },
565
+ dispatch: (command, exec) => {
566
+ const runtime = runtimeForAgent(exec?.agent?.id) ?? projectRuntime(command?.projectId) ?? null;
567
+ if (runtime === null) return Promise.reject(new Error('no Project runtime'));
568
+ return runtime.service.dispatch(command);
569
+ },
570
+ }), {
571
+ when: (activation) => runtimeForAgent(activation?.agent?.id) !== null,
572
+ })
573
+ : () => {};
574
+ } catch (error) {
575
+ console.warn('[ai-team] team tool registration failed:', error?.message ?? error);
576
+ }
545
577
 
546
578
  const ensureParent = async () => {
547
579
  if (host !== null) return host;
@@ -553,6 +585,7 @@ export function apply(ctx) {
553
585
  agents: ctx.get('agents'),
554
586
  agentDefaultModel: ctx.get('agentDefaultModel'),
555
587
  workspaceRegistry: ctx.get('workspaceRegistry'),
588
+ sessions: ctx.get('sessions'),
556
589
  cwd: booted?.dataDir ?? process.cwd(),
557
590
  resumeSessionId: existingHost,
558
591
  }).then(async (value) => {
@@ -632,6 +665,7 @@ export function apply(ctx) {
632
665
  }
633
666
  activations.set(result.childId, result.activation);
634
667
  await attachMemberWorkspace(projectRuntime, result.childId);
668
+ persistModelSelection(result.childId, activationMember.config, member.name);
635
669
  return {
636
670
  ok: true,
637
671
  member: bound.member,
@@ -1062,16 +1096,24 @@ export function apply(ctx) {
1062
1096
  });
1063
1097
 
1064
1098
  return () => {
1099
+ // Teardown must fully settle before the loader activates the next
1100
+ // composition: a racing parent-agent dispose left the previous
1101
+ // session-controller graph half-disposed and broke plugin toggles.
1102
+ const cleanup = [];
1065
1103
  for (const client of sseClients) {
1066
1104
  try { client.res.end(); } catch { /* socket already gone */ }
1067
1105
  }
1068
1106
  sseClients.clear();
1069
1107
  if (pmoTimer !== null) { clearInterval(pmoTimer); pmoTimer = null; }
1070
1108
  for (const activation of activations.values()) {
1071
- try { activation.dispose?.().catch?.(() => {}); } catch { /* already gone */ }
1109
+ cleanup.push(Promise.resolve().then(async () => {
1110
+ try { await activation.dispose?.(); } catch { /* already gone */ }
1111
+ }));
1072
1112
  }
1073
1113
  activations.clear();
1074
- if (host !== null) void host.dispose?.();
1114
+ if (host !== null) cleanup.push(Promise.resolve().then(async () => {
1115
+ try { await host.dispose?.(); } catch { /* already gone */ }
1116
+ }));
1075
1117
  try { disposePermissionGuard(); } catch { /* already disposed */ }
1076
1118
  try { offLlmFault(); } catch { /* already disposed */ }
1077
1119
  try { disposeSkillProvider(); } catch { /* already disposed */ }
@@ -1080,7 +1122,12 @@ export function apply(ctx) {
1080
1122
  offSessionEvent();
1081
1123
  disposeTool();
1082
1124
  dispose();
1083
- for (const runtime of booted?.runtimes?.values() ?? []) runtime.close();
1125
+ for (const runtime of booted?.runtimes?.values() ?? []) {
1126
+ cleanup.push(Promise.resolve().then(async () => {
1127
+ try { await runtime.close(); } catch { /* ledger already closed */ }
1128
+ }));
1129
+ }
1130
+ return Promise.allSettled(cleanup).then(() => undefined);
1084
1131
  };
1085
1132
  }, 'ai-team: workbench routes');
1086
1133
  }
@@ -25,6 +25,7 @@ export class HostAgentError extends Error {
25
25
  * agents: any,
26
26
  * agentDefaultModel: any,
27
27
  * workspaceRegistry?: any,
28
+ * sessions?: any,
28
29
  * cwd: string,
29
30
  * newSessionId?: () => string
30
31
  * }} options
@@ -34,14 +35,31 @@ export async function ensureHostAgent(options) {
34
35
  if (agents === undefined || typeof agents.create !== 'function') {
35
36
  throw new HostAgentError('E_RUNTIME_UNAVAILABLE', 'agents service is unavailable');
36
37
  }
38
+ // Persist the resolved route into the session log. Live AgentOptions die
39
+ // with the process; without a recorded selection a restored session renders
40
+ // prompts with an unresolvable {{model}} variable.
41
+ const persistSelection = (sessionId, selection) => {
42
+ try {
43
+ const session = options.sessions?.get?.(sessionId);
44
+ if (session === undefined || session === null || typeof session.append !== 'function') return;
45
+ if (typeof selection?.provider !== 'string' || typeof selection?.model !== 'string') return;
46
+ session.append('model/selection', { provider: selection.provider, model: selection.model });
47
+ } catch (error) {
48
+ console.warn('[ai-team] host model selection persist failed:', error?.message ?? error);
49
+ }
50
+ };
37
51
  if (typeof options.resumeSessionId === 'string' && options.resumeSessionId !== '') {
38
52
  const live = typeof agents.get === 'function' ? agents.get(options.resumeSessionId) : undefined;
39
53
  if (live !== undefined) {
54
+ const selection = typeof options.agentDefaultModel?.currentSelection === 'function' ? options.agentDefaultModel.currentSelection() : null;
55
+ persistSelection(options.resumeSessionId, selection);
40
56
  return { agent: live, created: false, resumed: true, sessionId: options.resumeSessionId, dispose: async () => {} };
41
57
  }
42
58
  try {
43
59
  const handle = await agents.resume({ resumeSessionId: options.resumeSessionId });
44
60
  try { await options.workspaceRegistry?.archiveSession?.(options.resumeSessionId); } catch { /* cosmetic */ }
61
+ const selection = typeof options.agentDefaultModel?.currentSelection === 'function' ? options.agentDefaultModel.currentSelection() : null;
62
+ persistSelection(options.resumeSessionId, selection);
45
63
  return {
46
64
  agent: handle.agent,
47
65
  created: false,
@@ -83,6 +101,7 @@ export async function ensureHostAgent(options) {
83
101
  cause: error?.code ?? null,
84
102
  });
85
103
  }
104
+ persistSelection(sessionId, selection);
86
105
  const host = handle.agent;
87
106
  try {
88
107
  await options.workspaceRegistry?.archiveSession?.(sessionId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suifei/dsh-ai-team",
3
- "version": "0.3.52",
3
+ "version": "0.3.53",
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",