@suifei/dsh-ai-team 0.4.138 → 0.4.139

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.139 - 2026-11-20
4
+
5
+ **Grok 4.7 不再在第一条回复前报 HTTP 400;热重载时归档修复只跑一次**
6
+
7
+ - Grok 4.7(#88,感谢 @TardisBooo):11 个 SkillOpt 工具的 `parameters` 是裸属性表(`{ project: { type: 'string' } }`),不是对象 JSON Schema。这种写法只对宿主的 `defineTool()` 有效(它会先编译);插件直接 `tools.register()`,内置 SkillOpt 的 `defineTool` 又是原样透传,所以裸属性表原样发给了模型。Grok 4.7 严格校验,整个请求 400;Qwen、DeepSeek 一直容忍。现在都包成 `{ type: 'object', properties }`;参数里没有 `required` / `enum`,参数名与含义不变。实测:直连 Grok 4.7,修复前 11 个工具单发各 400,修复后 12 个工具一起发 200;DSH 宿主里成员路由到 Grok 4.7,修复前第一步 `400 invalid_request_error`,修复后回合正常结束。Qwen 修复前后都正常,调 `skillopt_rubric` 时 `dim8` 从字符串 `"7"` 变成数字 `7`(模型现在看得懂参数类型)。
8
+ - 回归测试 `test/tool-schemas.test.js`:走插件真实的 `apply()`,捕获插件注册的**每一个**工具(含 index.js 自己注册的 `skillopt_rubric` / `judge` / `optimize` / `jobs`,以及以后新加的),逐个断言是对象 schema;单独断言按 Agent 注册的 `team` 工具。退掉 #88 任一处修复,测试都会失败。
9
+ - 归档修复只跑一次(`repairOnce`,`lib/runtime/host-repair.js`):启动 tick、取 PMO 会话、回合被拦会并发调用修复,旧写法在 `await` 之前只查「修好没」,几路都通过,同一批会话被解档、PMO 被归入工作区好几遍(il2c 每次热重载 3 行 `host.repair.ok`)。现在修好之前同一时刻只跑一次,并发调用共享这一次;没修成(如工作区注册服务未就绪)下次照常重跑。实测:隔离宿主热重载两次,0.4.138 写 2 / 5 / 2 行,现在 1 / 1 / 1 行。
10
+ - 测试:`test/host-repair.test.js` 新增并发共享与重跑、index.js 接线。
11
+
3
12
  ## 0.4.138 - 2026-11-19
4
13
 
5
14
  **热重载后「旧树未散」的唤醒:暂存,等成员旧回合结束再补投**
package/README.md CHANGED
@@ -36,6 +36,7 @@
36
36
  - **头像**(0.4.135–0.4.136):人才市场、团队、成员卡片都有头像,由 [`@suifei/hash-avatar`](https://www.npmjs.com/package/@suifei/hash-avatar) 在本机按名字生成。这个库**不随插件打包**:插件运行时从 npm 取最新版并缓存在本机,库更新了插件不用重发,新增的种族、画风直接出现在挑选界面里。内置人才预置了参数(默认亚洲人),自定义成员和人才可以选性别、年龄、种族(人类 / 奇幻 / 动物 / 科幻共 88 种)和画风(扁平、像素、水墨等 10 种)。
37
37
  - **PMO 会话里的收工汇报**(0.4.137):成员收工后,「【项目】文渊阁·PMO」会话里直接显示它的收工汇报全文,开头带成员头像和名字,不经过模型。
38
38
  - **热重载后的唤醒**(0.4.138):插件关再开(含升级)时正在跑回合的成员,暂时收不到唤醒;插件把这些唤醒暂存起来,等那个回合结束后自动补投,不再记成失败。
39
+ - **Grok 4.7 可用**(0.4.139):插件注册的工具参数都是标准的对象 JSON Schema,Grok 4.7 等严格校验工具定义的模型不再在第一条回复前报 HTTP 400(感谢 [@TardisBooo](https://github.com/TardisBooo),#88)。
39
40
  - **弹窗与人员池**(0.4.132–0.4.133):
40
41
  - 弹窗占主页面的 90%,功能按钮固定在右上角。
41
42
  - 成员资料按「资料 / 模型 / 技能 / 协作」分页签。
package/index.js CHANGED
@@ -25,7 +25,7 @@ import { ids } from './lib/domain/ids.js';
25
25
  import { MemberRuntime, validatePermissionProfile } from './lib/runtime/member-runtime.js';
26
26
  import { ensureHostAgent } from './lib/runtime/host-agent.js';
27
27
  import { activationSpec } from './lib/runtime/activation-spec.js';
28
- import { repairArchivedHosts as repairHostSessions } from './lib/runtime/host-repair.js';
28
+ import { repairArchivedHosts as repairHostSessions, repairOnce } from './lib/runtime/host-repair.js';
29
29
  import { classifyLlmFailure, nextRequestAttempt, retryDecision } from './lib/runtime/failure-policy.js';
30
30
  import { memberIdentity } from './lib/domain/member-profile.js';
31
31
  import { findSkill, findSkillText, loadSkillContext } from './lib/runtime/skill-loader.js';
@@ -1623,10 +1623,13 @@ export function apply(ctx, config = {}) {
1623
1623
  name: 'skillopt_rubric',
1624
1624
  description: 'Score a SKILL.md against the 9-dimension Darwin rubric (triage only — absolute scores must not be used for keep/revert).',
1625
1625
  parameters: {
1626
- project: { type: 'string', description: 'Project directory (defaults to cwd)' },
1627
- skillPath: { type: 'string', description: 'Path to SKILL.md to score' },
1628
- dim8: { type: 'number', description: 'Measured effect score 1-10 (omit for dry-run)' },
1629
- measured: { type: 'boolean', description: 'Set when dim8 came from a real prompt run' },
1626
+ type: 'object',
1627
+ properties: {
1628
+ project: { type: 'string', description: 'Project directory (defaults to cwd)' },
1629
+ skillPath: { type: 'string', description: 'Path to SKILL.md to score' },
1630
+ dim8: { type: 'number', description: 'Measured effect score 1-10 (omit for dry-run)' },
1631
+ measured: { type: 'boolean', description: 'Set when dim8 came from a real prompt run' },
1632
+ },
1630
1633
  },
1631
1634
  // DSH 工具输出协议:render 必须返回 content 数组(与 vendored 一致)。
1632
1635
  output: { schema: { type: 'string' }, render: (_args, value) => [{ type: 'text', text: String(value) }] },
@@ -1648,9 +1651,12 @@ export function apply(ctx, config = {}) {
1648
1651
  name: 'skillopt_judge',
1649
1652
  description: 'Paired independent-judge verdict (N odd votes, majority) for before/after SKILL.md — the authoritative keep/revert signal.',
1650
1653
  parameters: {
1651
- project: { type: 'string', description: 'Project directory' },
1652
- beforePath: { type: 'string', description: 'Baseline file path (default: current live SKILL.md)' },
1653
- afterPath: { type: 'string', description: 'Candidate file path (default: latest staged proposal)' },
1654
+ type: 'object',
1655
+ properties: {
1656
+ project: { type: 'string', description: 'Project directory' },
1657
+ beforePath: { type: 'string', description: 'Baseline file path (default: current live SKILL.md)' },
1658
+ afterPath: { type: 'string', description: 'Candidate file path (default: latest staged proposal)' },
1659
+ },
1654
1660
  },
1655
1661
  // DSH 工具输出协议:render 必须返回 content 数组(与 vendored 一致)。
1656
1662
  output: { schema: { type: 'string' }, render: (_args, value) => [{ type: 'text', text: String(value) }] },
@@ -1681,9 +1687,12 @@ export function apply(ctx, config = {}) {
1681
1687
  name: 'skillopt_optimize',
1682
1688
  description: 'Start a Darwin hill-climbing job for one SKILL.md (diagnose, generate candidate, paired judge, keep/revert). The PMO tick harvests it; poll skillopt_jobs for the outcome.',
1683
1689
  parameters: {
1684
- project: { type: 'string', description: 'Project directory' },
1685
- skillPath: { type: 'string', description: 'Path to SKILL.md to optimize' },
1686
- candidate: { type: 'string', description: 'Full improved SKILL.md text. Omit to get the diagnosis + rewrite request first; pass it to start the reviewer round.' },
1690
+ type: 'object',
1691
+ properties: {
1692
+ project: { type: 'string', description: 'Project directory' },
1693
+ skillPath: { type: 'string', description: 'Path to SKILL.md to optimize' },
1694
+ candidate: { type: 'string', description: 'Full improved SKILL.md text. Omit to get the diagnosis + rewrite request first; pass it to start the reviewer round.' },
1695
+ },
1687
1696
  },
1688
1697
  output: { schema: { type: 'string' }, render: (_args, value) => [{ type: 'text', text: String(value) }] },
1689
1698
  async execute(args) {
@@ -1753,7 +1762,7 @@ export function apply(ctx, config = {}) {
1753
1762
  const jobsTool = guardedTools.register({
1754
1763
  name: 'skillopt_jobs',
1755
1764
  description: 'List optimize jobs (state, target dimension, verdict) for a project.',
1756
- parameters: { project: { type: 'string', description: 'Project directory' } },
1765
+ parameters: { type: 'object', properties: { project: { type: 'string', description: 'Project directory' } } },
1757
1766
  output: { schema: { type: 'string' }, render: (_args, value) => [{ type: 'text', text: String(value) }] },
1758
1767
  async execute(args) {
1759
1768
  // 主动收割:工具调用即驱动(不依赖 PMO 定时器——实测宿主热重载/
@@ -2006,8 +2015,8 @@ export function apply(ctx, config = {}) {
2006
2015
  // 模型请求(实测 453 blocked / 0 completed)。旧版本把 host 归档用于隐藏会话。
2007
2016
  let hostRepaired = false;
2008
2017
  let hostRepairWarned = false;
2009
- const repairArchivedHosts = async () => {
2010
- if (hostRepaired) return;
2018
+ // 启动 tick、ensureParent、blocked 回合会并发调用:repairOnce 保证同一时刻只跑一次。
2019
+ const repairArchivedHosts = repairOnce(async () => {
2011
2020
  try {
2012
2021
  const registry = serviceOf(ctx, 'workspaceRegistry');
2013
2022
  const repaired = await repairHostSessions({
@@ -2054,7 +2063,7 @@ export function apply(ctx, config = {}) {
2054
2063
  hostRepaired = true;
2055
2064
  diag.append({ ev: 'host.unarchive.sweep.fail', error: error?.message ?? String(error) });
2056
2065
  }
2057
- };
2066
+ }, () => hostRepaired);
2058
2067
  /**
2059
2068
  * 取项目的 PMO 会话(成员的父会话)。核心模型:一个项目一个 PMO,驻留在项目工作区;
2060
2069
  * 成员都是它的子会话,于是全部落在同一工作区。不传项目时取活动项目(skillopt 评审等
@@ -1,73 +1,92 @@
1
- /**
2
- * Repair Team Host sessions archived by earlier revisions.
3
- *
4
- * Members are subagent descendants of the Host Agent, and
5
- * `archived-session-gate` (dsh-api-session-controller) rejects every
6
- * `agent/pre-step` whose Session — or any Session above it in the subagent
7
- * lineage — is archived. The loop then ends the turn as `{kind:'blocked'}`
8
- * **without issuing a model request**, so an archived Host silently disables
9
- * the whole team (measured: 453 blocked turns, 0 completed, no `request/header`).
10
- *
11
- * Earlier revisions archived the Host on purpose to hide it from the session
12
- * list. This sweep lifts that damage by calling `unarchiveSession` for the
13
- * persisted host of each runtime and the `parentSession` of every member session.
14
- *
15
- * Two constraints learned the hard way:
16
- * 1. Use only the **documented** API. `archivedSessionIds` is not part of the
17
- * workspaceRegistry contract; gating on it silently skipped the whole
18
- * repair. `unarchiveSession` on a non-archived id resolves without writing,
19
- * so calling it unconditionally is safe and needs no read-back.
20
- * 2. Diagnostics ending without `.fail` are dropped at the default `errors`
21
- * diag level. Failure rows therefore carry `.fail`; success is proven by
22
- * the durable archive list, not by a log line.
23
- */
24
-
25
- /**
26
- * @param {{
27
- * runtimes: Iterable<any>,
28
- * sessions?: { get?: (id: string) => any },
29
- * workspaceRegistry?: { unarchiveSession?: (id: string) => Promise<void> },
30
- * diag?: { append?: (row: any) => any } | null,
31
- * knownHostSessionIds?: Iterable<string>
32
- * }} options
33
- * @returns {Promise<string[]|null>} session ids the sweep asked to unarchive;
34
- * `null` means the registry was not ready yet and the caller should retry.
35
- */
36
- export async function repairArchivedHosts(options = {}) {
37
- const registry = options.workspaceRegistry;
38
- // `workspaceRegistry` 要等 sessionPersistence 与历史 bootstrap 完成才 active,
39
- // 插件激活瞬间常常还取不到。此时返回 null(而不是空数组)让调用方保持
40
- // 「未修复」状态,等下一个 tick 重试——而不是一次失败就永久放弃。
41
- if (registry === undefined || registry === null || typeof registry.unarchiveSession !== 'function') return null;
42
-
43
- const victims = new Set();
44
- for (const known of options.knownHostSessionIds ?? []) {
45
- if (typeof known === 'string' && known !== '') victims.add(known);
46
- }
47
- for (const runtime of options.runtimes ?? []) {
48
- const hostId = runtime?.service?.state?.hostSessionId;
49
- if (typeof hostId === 'string' && hostId !== '') victims.add(hostId);
50
- for (const member of Object.values(runtime?.service?.state?.members ?? {})) {
51
- const sessionId = member?.sessionId;
52
- if (typeof sessionId !== 'string' || sessionId === '') continue;
53
- // 成员会话自己也可能被归档(例如用户手动归档了那条会话):gate 会直接
54
- // 拒绝它,只有 host 一代的解归档覆盖不到。
55
- victims.add(sessionId);
56
- try {
57
- const header = options.sessions?.get?.(sessionId)?.header;
58
- if (typeof header?.parentSession === 'string') victims.add(header.parentSession);
59
- } catch { /* member session is not live; skip */ }
60
- }
61
- }
62
-
63
- const repaired = [];
64
- for (const sessionId of victims) {
65
- try {
66
- await registry.unarchiveSession(sessionId);
67
- repaired.push(sessionId);
68
- } catch (error) {
69
- options.diag?.append?.({ ev: 'host.unarchive.fail', sessionId, message: error?.message ?? String(error) });
70
- }
71
- }
72
- return repaired;
73
- }
1
+ /**
2
+ * Repair Team Host sessions archived by earlier revisions.
3
+ *
4
+ * Members are subagent descendants of the Host Agent, and
5
+ * `archived-session-gate` (dsh-api-session-controller) rejects every
6
+ * `agent/pre-step` whose Session — or any Session above it in the subagent
7
+ * lineage — is archived. The loop then ends the turn as `{kind:'blocked'}`
8
+ * **without issuing a model request**, so an archived Host silently disables
9
+ * the whole team (measured: 453 blocked turns, 0 completed, no `request/header`).
10
+ *
11
+ * Earlier revisions archived the Host on purpose to hide it from the session
12
+ * list. This sweep lifts that damage by calling `unarchiveSession` for the
13
+ * persisted host of each runtime and the `parentSession` of every member session.
14
+ *
15
+ * Two constraints learned the hard way:
16
+ * 1. Use only the **documented** API. `archivedSessionIds` is not part of the
17
+ * workspaceRegistry contract; gating on it silently skipped the whole
18
+ * repair. `unarchiveSession` on a non-archived id resolves without writing,
19
+ * so calling it unconditionally is safe and needs no read-back.
20
+ * 2. Diagnostics ending without `.fail` are dropped at the default `errors`
21
+ * diag level. Failure rows therefore carry `.fail`; success is proven by
22
+ * the durable archive list, not by a log line.
23
+ */
24
+
25
+ /**
26
+ * @param {{
27
+ * runtimes: Iterable<any>,
28
+ * sessions?: { get?: (id: string) => any },
29
+ * workspaceRegistry?: { unarchiveSession?: (id: string) => Promise<void> },
30
+ * diag?: { append?: (row: any) => any } | null,
31
+ * knownHostSessionIds?: Iterable<string>
32
+ * }} options
33
+ * @returns {Promise<string[]|null>} session ids the sweep asked to unarchive;
34
+ * `null` means the registry was not ready yet and the caller should retry.
35
+ */
36
+ export async function repairArchivedHosts(options = {}) {
37
+ const registry = options.workspaceRegistry;
38
+ // `workspaceRegistry` 要等 sessionPersistence 与历史 bootstrap 完成才 active,
39
+ // 插件激活瞬间常常还取不到。此时返回 null(而不是空数组)让调用方保持
40
+ // 「未修复」状态,等下一个 tick 重试——而不是一次失败就永久放弃。
41
+ if (registry === undefined || registry === null || typeof registry.unarchiveSession !== 'function') return null;
42
+
43
+ const victims = new Set();
44
+ for (const known of options.knownHostSessionIds ?? []) {
45
+ if (typeof known === 'string' && known !== '') victims.add(known);
46
+ }
47
+ for (const runtime of options.runtimes ?? []) {
48
+ const hostId = runtime?.service?.state?.hostSessionId;
49
+ if (typeof hostId === 'string' && hostId !== '') victims.add(hostId);
50
+ for (const member of Object.values(runtime?.service?.state?.members ?? {})) {
51
+ const sessionId = member?.sessionId;
52
+ if (typeof sessionId !== 'string' || sessionId === '') continue;
53
+ // 成员会话自己也可能被归档(例如用户手动归档了那条会话):gate 会直接
54
+ // 拒绝它,只有 host 一代的解归档覆盖不到。
55
+ victims.add(sessionId);
56
+ try {
57
+ const header = options.sessions?.get?.(sessionId)?.header;
58
+ if (typeof header?.parentSession === 'string') victims.add(header.parentSession);
59
+ } catch { /* member session is not live; skip */ }
60
+ }
61
+ }
62
+
63
+ const repaired = [];
64
+ for (const sessionId of victims) {
65
+ try {
66
+ await registry.unarchiveSession(sessionId);
67
+ repaired.push(sessionId);
68
+ } catch (error) {
69
+ options.diag?.append?.({ ev: 'host.unarchive.fail', sessionId, message: error?.message ?? String(error) });
70
+ }
71
+ }
72
+ return repaired;
73
+ }
74
+
75
+ /**
76
+ * 归档修复的调用门:修好之前同一时刻只跑一次,并发调用共享同一个 Promise;修好后直接返回。
77
+ *
78
+ * 启动 tick、ensureParent、blocked 回合会并发调用修复;旧写法在 await 之前只查「修好没」,
79
+ * 几路都通过,同一批会话被解档、PMO 被归入工作区各三遍(il2c 11-19 04:47:11 与 09:17:32
80
+ * 热重载各三行 host.repair.ok,相隔 ≤11ms)。没修好(如 workspaceRegistry 未就绪)时,
81
+ * 下一次调用照常重跑。
82
+ * @param {() => Promise<void>} run 一次修复
83
+ * @param {() => boolean} isDone 是否已修好
84
+ */
85
+ export function repairOnce(run, isDone) {
86
+ let running = null;
87
+ return () => {
88
+ if (isDone()) return Promise.resolve();
89
+ running ??= Promise.resolve().then(run).finally(() => { running = null; });
90
+ return running;
91
+ };
92
+ }
@@ -374,7 +374,7 @@ export function apply(ctx, config = {}) {
374
374
  defineTool({
375
375
  name: t.name,
376
376
  description: t.description,
377
- parameters: t.parameters,
377
+ parameters: { type: 'object', properties: t.parameters },
378
378
  output: { schema: { type: 'string' }, render: renderOutput },
379
379
  async execute(args, exec) {
380
380
  const a = args || {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suifei/dsh-ai-team",
3
- "version": "0.4.138",
3
+ "version": "0.4.139",
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",