@suifei/dsh-ai-team 0.4.31 → 0.4.33

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,25 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.33 - 2026-11-12
4
+
5
+ **中危批次 4:验收门禁、权限沿革、技能过滤、job 原子写**
6
+
7
+ - **Human 验收也要过 QA 门禁**:`accept` 的清单校验原本只在 `reviewer !== null`(Agent)时执行,而 Human 是 UI 上唯一的验收人 —— `qaRequired` 的卡可以零勾选通过,未校验的 `checks` 还会原样写进 `task.qaChecks`。现在对所有验收人生效;没有清单却提交勾选会被拒。
8
+ - **换 owner 会同时换权限**:`project/owner-changed` 只更新 `ownerMemberId`,`ownerId` 停在原主;`isLead` 对两者做 OR 判定,于是**前** owner 继续保留 lead 权限。现在两者一起改。
9
+ - **技能目录按 `invocation.modelInvocable` 过滤**:`SkillSummary` 把开关放在 `invocation` 下,之前读顶层字段(恒 undefined),`disable-model-invocation` 的技能照样写进成员 prompt。
10
+ - **job 文件原子写**:`writeJob` 从裸 `writeFileSync` 改为「写临时文件 + rename」,进程中断不再留下半截 JSON(半截文件会让下一轮 tick 把成功误判成 conflict failed)。
11
+ - **rubric 计数不再被捕获组放大**:`String.match` 带捕获组时返回数组含分组,命中一次会被算成多次,dim3 分数系统性虚高。改为 `matchAll` 只数完整匹配。
12
+ - 测试:`node --test` **221/221**(新增 `test/audit-medium-batch.test.js` 5 例)。
13
+
14
+ ## 0.4.32 - 2026-11-12
15
+
16
+ **中危批次 3:前端断流自愈、重复提交、同人绑定**
17
+
18
+ - **断流不再假装在重连**:`EventSource` 只在临时失败时自己重试;一旦被判死(`readyState === CLOSED`,例如服务端 4xx/5xx),浏览器不会再试,而界面还挂着「正在自动重连…」。现在由前端按 2s→30s 退避重建事件源,卸载时清掉定时器;收到帧后清掉断流提示并提示已恢复。
19
+ - **重复提交**:发送与回复共用同一个在途守卫——连按 Ctrl/⌘+Enter 或双击不会写出两条相同的消息/回复。
20
+ - **同人绑定真的会合并**:界面把「绑定到谁」的名字当 `personId` 提交,而聚合桶键是 `name:<名字>`,于是别名落到 `person:<名字>`,两行永远合不到一起、提示却是成功。现在服务端把别名的目标归一为 `person:<id>` / `name:<名字>`,聚合时裸名字也按 `name:` 处理,历史数据文件不回改也能生效。
21
+ - 测试:`node --test` **216/216**(新增 `client-contract` 结构契约 3 例、人员别名 2 例)。
22
+
3
23
  ## 0.4.31 - 2026-11-12
4
24
 
5
25
  **中危批次 2:Host 会话落账、报告路径判别、PMO 决策遵从建议**
package/client.js CHANGED
@@ -85,6 +85,7 @@ window.__ModuleLoader__.load({
85
85
  fromDiscussion: '由讨论升格',
86
86
  loading: '加载中…',
87
87
  streamDown: '实时更新已中断,界面可能滞后;正在自动重连…',
88
+ streamUp: '实时更新已恢复。',
88
89
  loadFailedTitle: '工作台不可达',
89
90
  loadFailedBody: 'bootstrap 接口(/ai-team)无法访问;请确认插件已启用后重试。',
90
91
  spike: 'AI Team',
@@ -497,6 +498,7 @@ window.__ModuleLoader__.load({
497
498
  loadFailedTitle: 'Workbench unreachable',
498
499
  loadFailedBody: 'The bootstrap endpoint (/ai-team) cannot be reached; confirm the plugin is enabled and retry.',
499
500
  streamDown: 'Live updates stopped; the view may lag while the stream reconnects…',
501
+ streamUp: 'Live updates are back.',
500
502
  spike: 'AI Team',
501
503
  spikeTitle: 'Wenyuan Pavilion AI Team workbench: compile, collate, edit; direction, acceptance and ledger.',
502
504
  navAria: 'Page navigation',
@@ -2637,6 +2639,8 @@ window.__ModuleLoader__.load({
2637
2639
  const scopeRef = React.useRef(scope);
2638
2640
  // SSE 断流一次性提示:只提示一次,恢复后重置。
2639
2641
  const streamDownRef = React.useRef(false);
2642
+ // 发送在途守卫:双击按钮或连按 Ctrl+Enter 会重复提交同一条消息/回复。
2643
+ const sendingRef = React.useRef(false);
2640
2644
  scopeRef.current = scope;
2641
2645
  const [nBusy, setNBusy] = React.useState(false);
2642
2646
  const [nError, setNError] = React.useState('');
@@ -2731,15 +2735,25 @@ window.__ModuleLoader__.load({
2731
2735
  }
2732
2736
  load();
2733
2737
  // Event-driven refresh only; the Host sends one frame per command and
2734
- // no heartbeat/timer. EventSource reconnects on its own; a project is
2735
- // required — no magic fallback id here.
2736
- const source = typeof EventSource === 'function' && projectId
2737
- ? new EventSource('/ai-team/api/projects/' + encodeURIComponent(projectId) + '/events')
2738
- : null;
2739
- if (source) {
2738
+ // no heartbeat/timer. A project is required — no magic fallback id here.
2739
+ // EventSource 只在**临时**失败时自动重连;一旦被判死(readyState
2740
+ // CLOSED,例如服务端返回 4xx/5xx),它不会再试,界面会永远停在
2741
+ // 「正在自动重连…」的假承诺上。这里自己接管重建,并在恢复后清掉提示。
2742
+ let source = null;
2743
+ let retryTimer = null;
2744
+ let retryDelay = 2000;
2745
+ const openStream = () => {
2746
+ if (!alive || typeof EventSource !== 'function' || !projectId) return;
2747
+ source = new EventSource('/ai-team/api/projects/' + encodeURIComponent(projectId) + '/events');
2740
2748
  source.addEventListener('change', (raw) => {
2741
2749
  if (!alive) return;
2742
- streamDownRef.current = false;
2750
+ retryDelay = 2000;
2751
+ if (streamDownRef.current) {
2752
+ streamDownRef.current = false;
2753
+ // 恢复后清掉断流提示;否则「正在自动重连」会一直挂着。
2754
+ say('');
2755
+ pushToast(t('streamUp'));
2756
+ }
2743
2757
  try {
2744
2758
  const frame = JSON.parse(raw.data);
2745
2759
  pushToast(notificationText(frame?.event));
@@ -2752,19 +2766,30 @@ window.__ModuleLoader__.load({
2752
2766
  load();
2753
2767
  });
2754
2768
  source.addEventListener('error', () => {
2755
- // EventSource 自己会重连,但**必须让用户看见**:旧实现只在首屏
2756
- // (dataRef===null)时打印,面板已有数据时断流完全静默。
2757
2769
  if (!alive) return;
2758
- console.error(PKG + ': event stream unavailable (retrying)');
2770
+ console.error(PKG + ': event stream unavailable');
2759
2771
  if (!streamDownRef.current) {
2760
2772
  streamDownRef.current = true;
2761
2773
  say(t('streamDown'));
2762
2774
  }
2775
+ // CONNECTING 时浏览器自己会重试,保持原样;CLOSED 表示已放弃,
2776
+ // 必须由我们按退避重建,否则永远不会恢复。
2777
+ if (source !== null && source.readyState === 2) {
2778
+ try { source.close(); } catch { /* already closed */ }
2779
+ source = null;
2780
+ if (retryTimer === null) {
2781
+ const delay = retryDelay;
2782
+ retryDelay = Math.min(retryDelay * 2, 30000);
2783
+ retryTimer = setTimeout(() => { retryTimer = null; openStream(); }, delay);
2784
+ }
2785
+ }
2763
2786
  });
2764
- }
2787
+ };
2788
+ openStream();
2765
2789
  return () => {
2766
2790
  alive = false;
2767
2791
  if (controller) controller.abort();
2792
+ if (retryTimer !== null) clearTimeout(retryTimer);
2768
2793
  if (source) source.close();
2769
2794
  };
2770
2795
  }, [projectId]);
@@ -3657,6 +3682,15 @@ window.__ModuleLoader__.load({
3657
3682
  async function send() {
3658
3683
  const text = draft.trim();
3659
3684
  if (!text) return;
3685
+ if (sendingRef.current) return;
3686
+ sendingRef.current = true;
3687
+ try {
3688
+ await sendOnce(text);
3689
+ } finally {
3690
+ sendingRef.current = false;
3691
+ }
3692
+ }
3693
+ async function sendOnce(text) {
3660
3694
  // 目录门槛只拦"要动手"的任务:讨论与建卡无需工作目录(11-管理视角
3661
3695
  // §3);激活/认领由 Host fail-closed,并把用户引导到目录设置。
3662
3696
  if (!project?.workspacePath && mode === 'task') {
@@ -3699,6 +3733,9 @@ window.__ModuleLoader__.load({
3699
3733
  async function sendReply() {
3700
3734
  const text = reply.trim();
3701
3735
  if (!text || !selectedTask) return;
3736
+ // 与发送共用同一个在途守卫:连按 Ctrl+Enter 会写出两条相同回复。
3737
+ if (sendingRef.current) return;
3738
+ sendingRef.current = true;
3702
3739
  try {
3703
3740
  const result = await runCommand('thread.post', {
3704
3741
  taskId: selectedTask.id,
@@ -3712,6 +3749,8 @@ window.__ModuleLoader__.load({
3712
3749
  await reloadData();
3713
3750
  } catch (error) {
3714
3751
  sayRight(tf(t, 'replyFailed', { message: error?.message ?? String(error) }));
3752
+ } finally {
3753
+ sendingRef.current = false;
3715
3754
  }
3716
3755
  }
3717
3756
  function openConvert() {
package/index.js CHANGED
@@ -1723,7 +1723,11 @@ export function apply(ctx, config = {}) {
1723
1723
  return send(res, { error: { code: 'E_INVALID_ARGUMENT', message: 'name and personId are required' } }, 400);
1724
1724
  }
1725
1725
  const aliases = readAliases() ?? {};
1726
- aliases[memberName] = personId;
1726
+ // 归一到视图层的桶键:接受 `person:<id>`、`name:<名字>` 或裸名字。
1727
+ // 归一后才能与 aggregatePeople 的桶键对齐(裸名字曾让两行永不合并,
1728
+ // 而界面还提示「已绑定」)。
1729
+ const normalized = personId.startsWith('person:') || personId.startsWith('name:') ? personId : `name:${personId}`;
1730
+ aliases[memberName] = normalized;
1727
1731
  writeFileSync(aliasesPath, JSON.stringify(aliases, null, 2) + '\n', 'utf8');
1728
1732
  diag?.append({ ev: 'people.alias', name: memberName, personId });
1729
1733
  return send(res, { ok: true, aliases });
@@ -22,8 +22,13 @@ export function aggregatePeople(registryEntries, runtimes, options = {}) {
22
22
  const aliases = options.aliases ?? null;
23
23
  const people = new Map();
24
24
  const bucketOf = (name) => {
25
- const personId = aliases !== null && Object.prototype.hasOwnProperty.call(aliases, name) ? aliases[name] : null;
26
- return personId !== null ? `person:${personId}` : `name:${name}`;
25
+ // 别名的目标可以是 `person:<id>`(真正的 personId)、`name:<名字>`,或
26
+ // 历史数据里的裸名字。裸名字必须归一到 `name:<名字>`——否则「X → 白砚」
27
+ // 会让 X 落到 `person:白砚`,而白砚本人是 `name:白砚`,两行永远合不到一起。
28
+ const alias = aliases !== null && Object.prototype.hasOwnProperty.call(aliases, name) ? aliases[name] : null;
29
+ if (alias === null) return `name:${name}`;
30
+ if (alias.startsWith('person:') || alias.startsWith('name:')) return alias;
31
+ return `name:${alias}`;
27
32
  };
28
33
  for (const runtime of runtimes) {
29
34
  const projectName = registryEntries.find((project) => project.id === runtime.id)?.name ?? runtime.id;
@@ -1132,7 +1132,10 @@ export class TeamService {
1132
1132
  }
1133
1133
  const checklist = Array.isArray(task.qaChecklist) ? task.qaChecklist : [];
1134
1134
  const checks = Array.isArray(command.payload?.checks) ? command.payload.checks : [];
1135
- if (reviewer !== null && checklist.length > 0) {
1135
+ // 门禁对**所有**验收人都生效:Human 是 UI 上唯一的验收人,之前把它
1136
+ // 排除在 `reviewer !== null` 之外,等于让 qaRequired 的卡零勾选通过,
1137
+ // 未校验的 checks 还会原样写进 task.qaChecks。
1138
+ if (checklist.length > 0) {
1136
1139
  // QA 门禁必须逐项对应 task.qaChecklist:只比较条数 + passed 会让
1137
1140
  // 任意 item 文本(含伪造/无关条目)通过门禁,与 tool schema 契约
1138
1141
  // "Exact qaChecklist item" 不一致。
@@ -1149,6 +1152,9 @@ export class TeamService {
1149
1152
  if (pending.length > 0) {
1150
1153
  fail(ERRORS.INVALID_STATE, `QA checklist item not verified: ${pending[0]}`);
1151
1154
  }
1155
+ } else if (checks.length > 0) {
1156
+ // 没有清单却提交了勾选:不接受未知证据,避免写进投影后无从核对。
1157
+ fail(ERRORS.INVALID_ARGUMENT, 'this task has no QA checklist; do not submit checks');
1152
1158
  }
1153
1159
  outcome = acceptTask(task, command.actor, {
1154
1160
  note: command.payload?.note,
@@ -733,10 +733,12 @@ export function applyEvent(state, event) {
733
733
  const ownerMemberId = textOr(payload.ownerMemberId, null);
734
734
  const project = state.projects?.[projectId];
735
735
  if (project === undefined || ownerMemberId === null) return advance(state, event);
736
+ // ownerId 与 ownerMemberId 必须一起改:`isLead` 对两者做 OR 判定,只改
737
+ // ownerMemberId 会让**前** owner 因旧的 ownerId 继续保留 lead 权限。
736
738
  return advance(state, event, {
737
739
  projects: {
738
740
  ...state.projects,
739
- [projectId]: { ...project, ownerMemberId },
741
+ [projectId]: { ...project, ownerId: ownerMemberId, ownerMemberId },
740
742
  },
741
743
  });
742
744
  }
@@ -20,8 +20,15 @@ export async function formatSkillCatalog(skills, options = {}) {
20
20
  if (!Array.isArray(summaries) || summaries.length === 0) return '';
21
21
  // 只注入「模型可以自己调用」的技能:`disable-model-invocation: true` 的技能
22
22
  // 是给 Human 显式用的,列进成员 prompt 会把成员引向一个它无权调用的入口。
23
- const available = summaries.filter((skill) =>
24
- !isSkillExcluded(skill?.name) && skill?.modelInvocable !== false && skill?.disableModelInvocation !== true);
23
+ // SkillSummary 把这两个开关放在 `invocation` 下;直接读顶层字段会让过滤永远
24
+ // 通过(字段恒为 undefined),被禁的技能照样写进 prompt。
25
+ const available = summaries.filter((skill) => {
26
+ if (isSkillExcluded(skill?.name)) return false;
27
+ const modelInvocable = skill?.invocation?.modelInvocable ?? skill?.modelInvocable;
28
+ const disabled = skill?.invocation?.disableModelInvocation ?? skill?.disableModelInvocation;
29
+ if (modelInvocable === false || disabled === true) return false;
30
+ return true;
31
+ });
25
32
  if (available.length === 0) return '';
26
33
  const limit = Number.isSafeInteger(options.limit) && options.limit > 0 ? options.limit : 12;
27
34
  const rows = available.slice(0, limit).map((skill) => {
@@ -12,7 +12,7 @@
12
12
  * job 状态:`generating` → `judging` → `done` | `failed`。
13
13
  * 全部为纯逻辑 + 注入式 I/O,便于在测试里用内存文件系统驱动任意 tick 序列。
14
14
  */
15
- import { existsSync, mkdirSync, readFileSync, readdirSync, unlinkSync, writeFileSync } from 'node:fs';
15
+ import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
16
16
  import { join } from 'node:path';
17
17
 
18
18
  export const JOB_STATES = Object.freeze(['generating', 'judging', 'done', 'failed']);
@@ -49,11 +49,14 @@ export function listJobs(projectDir) {
49
49
  return jobs.sort((a, b) => (a.createdAt ?? 0) - (b.createdAt ?? 0));
50
50
  }
51
51
 
52
- /** 写入 job(原子性靠单写者约定;插件 tick 单线程)。 */
52
+ /** 写入 job:先写临时文件再改名,避免进程中断留下半截 JSON。 */
53
53
  export function writeJob(projectDir, job) {
54
54
  const dir = jobsDir(projectDir);
55
55
  mkdirSync(dir, { recursive: true });
56
- writeFileSync(join(dir, `${job.id}.json`), JSON.stringify(job, null, 2), 'utf8');
56
+ const target = join(dir, `${job.id}.json`);
57
+ const temp = `${target}.tmp`;
58
+ writeFileSync(temp, JSON.stringify(job, null, 2), 'utf8');
59
+ renameSync(temp, target);
57
60
  return job;
58
61
  }
59
62
 
@@ -44,7 +44,15 @@ const CHECKPOINT_PATTERNS = [/🔴/, /🛑/, /CHECKPOINT/, /STOP/];
44
44
  const COUNTEREXAMPLE_PATTERNS = [/反例/, /黑名单/, /不要做/, /禁止/, /反模式/];
45
45
 
46
46
  const clampScore = (value) => Math.max(1, Math.min(10, value));
47
- const countMatches = (text, patterns) => patterns.reduce((total, pattern) => total + (String(text).match(pattern)?.length ?? 0), 0);
47
+ // 只数**完整匹配**:`String.match` 在带捕获组时会把分组也塞进返回数组,长度
48
+ // 因此虚高(`/(a)(b)/g` 命中一次返回 3 个元素),dim3 分数被系统性抬高。
49
+ const countMatches = (text, patterns) => patterns.reduce((total, pattern) => {
50
+ const flags = pattern.flags.includes('g') ? pattern.flags : `${pattern.flags}g`;
51
+ const global = new RegExp(pattern.source, flags);
52
+ let hits = 0;
53
+ for (const _ of String(text).matchAll(global)) hits += 1;
54
+ return total + hits;
55
+ }, 0);
48
56
 
49
57
  /**
50
58
  * 静态评分(dims 1-7、9)。dim8 由调用方注入(measured dim8 干跑/实测分)。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suifei/dsh-ai-team",
3
- "version": "0.4.31",
3
+ "version": "0.4.33",
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",