@suifei/dsh-ai-team 0.4.72 → 0.4.74

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/index.js CHANGED
@@ -183,7 +183,7 @@ async function boot(diag, config = {}) {
183
183
  const legacyDir = join(dshHome(), 'ai-team', 'default');
184
184
  // 只在**桌面启动器**(profile 以位置参数传入)时搬迁:那个坑正是它造成的。
185
185
  // 从 --profile ai-team 起一个 CLI 不该把 GUI 的团队偷走。
186
- if (dataDir !== legacyDir && resolvedProfile().source === 'argv-path') {
186
+ if (dataDir !== legacyDir && ['argv-path', 'profiles-single'].includes(resolvedProfile().source)) {
187
187
  migrateLegacyNamespace({ fromDir: legacyDir, toDir: dataDir, diag });
188
188
  }
189
189
  // 默认工作目录:规则与优先级见 lib/host/default-workspace.js(有独立测试)。
@@ -730,7 +730,15 @@ export function apply(ctx, config = {}) {
730
730
  // activate them first; otherwise the first Human message is
731
731
  // silently dropped in a fresh Project.
732
732
  let messageId = null;
733
- if (member.sessionId === undefined || member.sessionId === null) {
733
+ // 路由过期(成员 provider/model 改过):已存活会话的 provider 是创建时
734
+ // 固定的,直接唤醒只会继续用旧路由——实机表现就是「模型换成 Qwen,
735
+ // provider 还是 deepseek-official,一直报缺 DEEPSEEK_API_KEY」。
736
+ // 重建一次会话,让新配置真正生效;上下文由 wakePrompt 带上。
737
+ const routeStale = member.routeStale === true;
738
+ if (routeStale) {
739
+ diag?.append({ ev: 'wake.route-stale', projectId: projectRuntime.id, memberId: plan.memberId, reason: plan.reason });
740
+ }
741
+ if (member.sessionId === undefined || member.sessionId === null || routeStale) {
734
742
  const activationKey = `${projectRuntime.id}:${member.id}`;
735
743
  let activation = activationTasks.get(activationKey);
736
744
  if (activation === undefined) {
@@ -738,7 +746,11 @@ export function apply(ctx, config = {}) {
738
746
  // 调用里,await 先让出执行权、单飞表还没登记,并发的两个计划会各自
739
747
  // 启动一次激活(两个子会话)。
740
748
  activation = (async () => activateMember({
741
- payload: { memberId: member.id, prompt: await wakePrompt(plan, member, { includeThread: true }) },
749
+ payload: {
750
+ memberId: member.id,
751
+ ...(routeStale ? { force: true } : {}),
752
+ prompt: await wakePrompt(plan, member, { includeThread: true }),
753
+ },
742
754
  }, projectRuntime))();
743
755
  activationTasks.set(activationKey, activation);
744
756
  activation.finally(() => activationTasks.delete(activationKey)).catch(() => {});
@@ -1362,8 +1374,9 @@ export function apply(ctx, config = {}) {
1362
1374
  const jobRoots = [...new Set([...runtimeRoots, ...(explicit !== null ? [explicit] : [])])];
1363
1375
  for (const jobRoot of jobRoots) {
1364
1376
  if (typeof jobRoot !== 'string' || jobRoot === '') continue;
1377
+ let reconciledHere = true;
1365
1378
  try {
1366
- const reconciledHere = await reconcileWithLock(jobRoot, {
1379
+ reconciledHere = await reconcileWithLock(jobRoot, {
1367
1380
  ctx,
1368
1381
  projectDir: jobRoot,
1369
1382
  deps: {
@@ -1410,6 +1423,21 @@ export function apply(ctx, config = {}) {
1410
1423
  diag.append({ ev: 'skillopt.review.card.close.fail', taskId, message: error?.message ?? String(error) });
1411
1424
  }
1412
1425
  };
1426
+ // failed 终态成行(与 job-runner.recordFail 同 10 列制式;257-#60②)。
1427
+ const appendFailResult = async (jobDir, job, reason) => {
1428
+ await makeResultAppender({ projectDir: jobDir })([
1429
+ new Date().toISOString().slice(0, 19),
1430
+ '-',
1431
+ job.skillName ?? '-',
1432
+ '-',
1433
+ '-',
1434
+ 'failed',
1435
+ job.dimension ?? '-',
1436
+ String(reason).replace(/[\t\r\n]+/g, ' '),
1437
+ 'paired',
1438
+ typeof job.candidate === 'string' ? sha12(job.candidate) : '-',
1439
+ ].join('\t'));
1440
+ };
1413
1441
  for (const job of jobs) {
1414
1442
  if (job.state !== 'judging' || typeof job.reviewTaskId !== 'string') continue;
1415
1443
  // job.project 是绝对路径;命名空间迁移后它会指向旧目录,精确比较会让
@@ -1429,12 +1457,14 @@ export function apply(ctx, config = {}) {
1429
1457
  // 评审通道被 reconcileJobs 明确排除,没有 TTL 兜底:评审官不回帖
1430
1458
  // 时 job 会永久停在 judging、评审卡永久 active。这里补超时终态。
1431
1459
  if (isJobExpired(job, Date.now(), REVIEW_JOB_TTL_MS)) {
1460
+ const timeoutReason = `review timed out after ${Math.round(REVIEW_JOB_TTL_MS / 60000)}min (${collected.votes.length}/${expected} votes)`;
1432
1461
  writeJob(job.project, {
1433
1462
  ...job,
1434
1463
  state: 'failed',
1435
- error: `review timed out after ${Math.round(REVIEW_JOB_TTL_MS / 60000)}min (${collected.votes.length}/${expected} votes)`,
1464
+ error: timeoutReason,
1436
1465
  updatedAt: Date.now(),
1437
1466
  });
1467
+ await appendFailResult(job.project, job, timeoutReason);
1438
1468
  // 超时也要收口:否则这张卡永久 pending,PMO 会一直唤醒评审官。
1439
1469
  await closeReviewCard(runtime, job.reviewTaskId, 'blind review timed out');
1440
1470
  diag.append({ ev: 'skillopt.job.timeout', jobId: job.id, got: collected.votes.length, expected });
@@ -1456,7 +1486,9 @@ export function apply(ctx, config = {}) {
1456
1486
  const candidateSha = typeof job.candidate === 'string' ? sha12(job.candidate) : null;
1457
1487
  const alreadyApplied = liveSha !== null && candidateSha !== null && liveSha === candidateSha;
1458
1488
  if (!alreadyApplied && liveText !== null && typeof job.before === 'string' && liveSha !== sha12(job.before)) {
1459
- writeJob(jobDir, { ...job, state: 'failed', error: 'live SKILL.md changed during review (conflict)', updatedAt: Date.now() });
1489
+ const conflictReason = 'live SKILL.md changed during review (conflict)';
1490
+ writeJob(jobDir, { ...job, state: 'failed', error: conflictReason, updatedAt: Date.now() });
1491
+ await appendFailResult(jobDir, job, conflictReason);
1460
1492
  await closeReviewCard(runtime, job.reviewTaskId, 'blind review aborted: live file changed');
1461
1493
  diag.append({ ev: 'skillopt.job.conflict', jobId: job.id, skillPath: job.skillPath });
1462
1494
  continue;
@@ -1,4 +1,4 @@
1
- import { existsSync, mkdirSync, readFileSync, realpathSync, statSync, writeFileSync } from 'node:fs';
1
+ import { existsSync, mkdirSync, readFileSync, realpathSync, statSync, writeFileSync } from 'node:fs';
2
2
  import pathDefault from 'node:path';
3
3
  import { ERRORS, fail } from '../domain/errors.js';
4
4
  import { findReportPath, parseDecisionQuestions } from './decision-report.js';
@@ -969,14 +969,25 @@ export class TeamService {
969
969
  updatedAt: this.now(),
970
970
  reason: typeof payload.reason === 'string' ? payload.reason : '',
971
971
  };
972
+ // 路由字段(provider/model)变化必须单独标记:已存活会话的 provider 在创建时
973
+ // 就固定了,只追加 model/selection 改不了路由(实机:模型换成 Qwen,provider
974
+ // 仍是 deepseek-official,于是报缺 DEEPSEEK_API_KEY 且一直不恢复)。
975
+ const routeChanged = (current.provider ?? '') !== (nextConfig.provider ?? '')
976
+ || (current.model ?? '') !== (nextConfig.model ?? '');
972
977
  await this.append(command, 'member/config-updated', {
973
978
  memberId: member.id,
974
979
  config: nextConfig,
975
980
  configVersion: nextConfig.configVersion,
976
981
  before: result.before,
977
982
  reason: nextConfig.reason,
983
+ routeChanged,
978
984
  });
979
- return { member: { ...member, config: nextConfig, configVersion: nextConfig.configVersion }, config: nextConfig, changed: true };
985
+ return {
986
+ member: { ...member, config: nextConfig, configVersion: nextConfig.configVersion, routeStale: routeChanged ? true : member.routeStale === true },
987
+ config: nextConfig,
988
+ changed: true,
989
+ routeChanged,
990
+ };
980
991
  }
981
992
 
982
993
  async retryMember(command, payload) {
package/lib/host/waker.js CHANGED
@@ -121,8 +121,25 @@ export function planWakes(state, result, actor = {}, options = {}) {
121
121
  });
122
122
  };
123
123
 
124
- if (event?.type === 'team/startup') {
125
- const unfinished = Object.values(state.tasks ?? {})
124
+ // 路由变更(成员 provider/model 改过)必须立即唤醒并重建会话:
125
+ // * 已存活会话的 provider 在创建时固定,追加 model/selection 只改模型名,
126
+ // 实机会表现成「模型换成 Qwen、provider 仍是 deepseek-official → 缺 key」;
127
+ // * 失败成员被 agentMember() 排除在自动唤醒之外(避免烧预算),但 Human 改
128
+ // 模型就是明确的修复动作,必须放行,否则改完仍然卡死。
129
+ if (event?.type === 'member/config-updated' && event.payload?.routeChanged === true) {
130
+ const memberId = event.payload.memberId;
131
+ const member = typeof memberId === 'string' ? state.members?.[memberId] : undefined;
132
+ if (member !== undefined && member.kind === 'agent' && member.status !== 'retired') {
133
+ targets.set(`${memberId}:route_changed`, {
134
+ memberId,
135
+ taskId: null,
136
+ reason: 'route_changed',
137
+ prompt: '模型/提供方已切换。按新配置继续:先读 tasks 与 thread 的当前状态,不要重复已完成的工作。',
138
+ key: `route_changed:${event.seq ?? memberId}:${memberId}:${options.projectId ?? ''}`,
139
+ });
140
+ }
141
+ }
142
+ if (event?.type === 'team/startup') { const unfinished = Object.values(state.tasks ?? {})
126
143
  .filter((entry) => entry.tombstone !== true && ['pending', 'in_progress', 'pending_acceptance'].includes(entry.status))
127
144
  .slice(0, 5);
128
145
  for (const entry of unfinished) {
@@ -783,6 +783,8 @@ export function applyEvent(state, event) {
783
783
  sessionId,
784
784
  status: MEMBER_STATUS.RUNNING,
785
785
  activatedAt: event.at,
786
+ // 新会话按当前配置创建,路由过期标记随之清除。
787
+ routeStale: false,
786
788
  },
787
789
  },
788
790
  });
@@ -843,6 +845,11 @@ export function applyEvent(state, event) {
843
845
  configUpdatedBy: event.actor?.memberId ?? event.actor?.kind ?? null,
844
846
  configUpdatedAt: event.at,
845
847
  configReason: stringOrNull(payload.reason),
848
+ // 路由(provider/model)改变:已存活会话的 provider 在创建时就固定在
849
+ // agentOptions 里,追加 model/selection 只改模型名、改不了路由,于是
850
+ // 表现成「模型换成了 Qwen,provider 还是 deepseek-official → 缺 key」。
851
+ // 标记过期,下一次唤醒直接重建会话让新路由生效。
852
+ routeStale: payload.routeChanged === true ? true : member.routeStale === true,
846
853
  },
847
854
  },
848
855
  });
@@ -1,4 +1,4 @@
1
- /**
1
+ /**
2
2
  * Profile 命名空间解析与一次性的旧命名空间迁移。
3
3
  *
4
4
  * 背景:桌面启动器不导出 `DSH_PROFILE`,而是把 profile 目录作为**位置参数**传给
@@ -12,6 +12,7 @@
12
12
  */
13
13
 
14
14
  import { existsSync, readdirSync, renameSync, statSync } from 'node:fs';
15
+ import { homedir } from 'node:os';
15
16
  import { join } from 'node:path';
16
17
 
17
18
  /** 从启动参数/env 解析 profile 名。 */
@@ -46,9 +47,29 @@ export function resolveProfile(argv = process.argv, env = process.env) {
46
47
  if (match !== null) return { name: match[1], source: 'argv-path' };
47
48
  }
48
49
  if (env?.DSH_PROFILE) return { name: env.DSH_PROFILE, source: 'env' };
50
+ // 兜底:某些启动器只传 dsh-root 而不传 profile 目录,于是上面两条都落空,
51
+ // 账本被写进 `ai-team/default/`(实机复现)。此时若 `~/.dsh/profiles` 下
52
+ // **只有一个** profile,它必然就是当前 profile。
53
+ const only = singleProfileName(env);
54
+ if (only !== null) return { name: only, source: 'profiles-single' };
49
55
  return { name: 'default', source: 'default' };
50
56
  }
51
57
 
58
+ /** `~/.dsh/profiles` 下唯一的 profile 名;不存在或有多个时返回 null(不猜)。 */
59
+ export function singleProfileName(env = process.env) {
60
+ try {
61
+ const home = typeof env?.DSH_HOME === 'string' && env.DSH_HOME.trim() !== ''
62
+ ? env.DSH_HOME
63
+ : join(homedir(), '.dsh');
64
+ const entries = readdirSync(join(home, 'profiles'), { withFileTypes: true })
65
+ .filter((entry) => entry.isDirectory())
66
+ .map((entry) => entry.name);
67
+ return entries.length === 1 ? entries[0] : null;
68
+ } catch {
69
+ return null;
70
+ }
71
+ }
72
+
52
73
  /** 目录下所有文件的总字节数;目录不存在按 0 计。 */
53
74
  export function dirBytes(dir) {
54
75
  if (!existsSync(dir)) return 0;
@@ -1,4 +1,4 @@
1
- /**
1
+ /**
2
2
  * 优化 job 的宿主侧收割:每个 PMO tick 调用一次,把状态机的一步动作落到
3
3
  * 真实文件/子代理/结果记录上。
4
4
  *
@@ -71,7 +71,9 @@ export async function stepJob(input) {
71
71
  if (action.type === 'fail') {
72
72
  await rollback({ deps, job, projectDir });
73
73
  job = { ...job, state: 'failed', error: action.payload?.reason ?? 'failed', updatedAt: deps.now() };
74
+ await recordFail({ deps, job });
74
75
  deps.diag?.({ ev: 'skillopt.job.fail', jobId: job.id, reason: job.error });
76
+ break;
75
77
  } else if (action.type === 'apply-candidate') {
76
78
  // 备份基线 → 写入候选 → 校验(超限时回滚)。
77
79
  const before = deps.readText(job.skillPath);
@@ -79,6 +81,7 @@ export async function stepJob(input) {
79
81
  if (!validation.ok) {
80
82
  await rollback({ deps, job, projectDir });
81
83
  job = { ...job, state: 'failed', error: validation.reason, updatedAt: deps.now() };
84
+ await recordFail({ deps, job });
82
85
  deps.diag?.({ ev: 'skillopt.job.fail', jobId: job.id, reason: validation.reason });
83
86
  break;
84
87
  }
@@ -151,6 +154,22 @@ export async function stepJob(input) {
151
154
  return { job, changed: true };
152
155
  }
153
156
 
157
+ /** failed 终态也必须成行(results.tsv ≡ jobs 盘件机判行;257-#60②)。 */
158
+ async function recordFail({ deps, job }) {
159
+ await deps.appendResult([
160
+ new Date(deps.now()).toISOString().slice(0, 19),
161
+ '-',
162
+ job.skillName ?? '-',
163
+ '-',
164
+ '-',
165
+ 'failed',
166
+ job.dimension ?? '-',
167
+ String(job.error ?? 'failed').replace(/[\t\r\n]+/g, ' '),
168
+ 'paired',
169
+ typeof job.candidate === 'string' ? sha12(job.candidate) : '-',
170
+ ].join('\t'));
171
+ }
172
+
154
173
  async function rollback({ deps, job, projectDir }) {
155
174
  if (job?.candidate === undefined || job?.before === undefined) return;
156
175
  // 回滚前必须确认 live 仍是**我们写下的那个候选**:评审期间可能有人手改,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suifei/dsh-ai-team",
3
- "version": "0.4.72",
3
+ "version": "0.4.74",
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",