@suifei/dsh-ai-team 0.4.53 → 0.4.54

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,21 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.54 - 2026-11-12
4
+
5
+ **批 18:库模块的失败也进诊断日志**
6
+
7
+ 0.4.53 的事故说明了一个结构性问题:库模块(`ledger` / `project-registry` / `host-agent` / `skill-provider` / `skillopt/jobs`)拿不到 `diag` 实例,失败只能 `console.warn`——**线上不可检索**,而断言也看不见。
8
+
9
+ - 新增共享失败汇:`installDiagSink()` + `reportFail(event, payload, consoleText)`(`lib/diaglog.js`)。插件 boot 时把真正的 diag 接进来,teardown 时卸载(热重载不会写旧实例)。
10
+ - 9 处库模块的 `console.warn` 全部改走 `reportFail`,事件名一律以 `.fail` 结尾——发布默认的 `errors` 级别只保留 `.fail` 行,所以这些失败**从此会落盘**:
11
+ - `registry.corrupt.fail`(projects.json 损坏被改名保留)
12
+ - `ledger.takeover.marker.fail`、`checkpoint.save.fail`
13
+ - `host.unarchive.fail`、`host.model.persist.fail`
14
+ - `skill.dropped.fail`(frontmatter / 调用策略非法)
15
+ - `job.file.unreadable.fail`、`job.overwrite.refused.fail`
16
+ - 索引层 `console.warn/error` 保持原样(19 处,每一处旁边本来就有 diag 行)。
17
+ - 测试:`node --test` **254 通过 / 1 跳过**(新增 1 例:共享汇写入、`.fail` 命名与卸载后不再写)。
18
+
3
19
  ## 0.4.53 - 2026-11-12
4
20
 
5
21
  **修 0.4.52 引入的回归:PMO tick 每轮抛 ReferenceError**
package/index.js CHANGED
@@ -51,7 +51,7 @@ import { aggregatePeople } from './lib/host/people-view.js';
51
51
  import { riskView } from './lib/host/risk-view.js';
52
52
  import { weeklyView } from './lib/host/weekly-view.js';
53
53
  import { isInformationalThreadMention } from './lib/domain/inbox.js';
54
- import { createDiagLogger, defaultDiagDir } from './lib/diaglog.js';
54
+ import { createDiagLogger, defaultDiagDir, installDiagSink } from './lib/diaglog.js';
55
55
 
56
56
  export const name = 'ai-team';
57
57
 
@@ -245,6 +245,9 @@ export function apply(ctx, config = {}) {
245
245
  maxBytes: config.diagLogMaxBytes ?? 1048576,
246
246
  level: config.diagLevel ?? 'errors',
247
247
  });
248
+ // 库模块(ledger / registry / host-agent / skill-provider / jobs)拿不到 diag,
249
+ // 之前只能 console.warn——线上不可检索。这里把共享失败汇接到真正的 diag。
250
+ const removeDiagSink = installDiagSink((row) => diag.append(row));
248
251
  // HTTP 层失败/拒绝的统一落点(route.reject 在 errors 白名单内)。
249
252
  const errorResponse = (res, error) => {
250
253
  diag.append({
@@ -2388,6 +2391,7 @@ export function apply(ctx, config = {}) {
2388
2391
  // composition: a racing parent-agent dispose left the previous
2389
2392
  // session-controller graph half-disposed and broke plugin toggles.
2390
2393
  disposed = true;
2394
+ try { removeDiagSink(); } catch { /* sink already replaced */ }
2391
2395
  const cleanup = [];
2392
2396
  for (const client of sseClients) {
2393
2397
  try { client.res.end(); } catch { /* socket already gone */ }
package/lib/diaglog.js CHANGED
@@ -1,4 +1,4 @@
1
- /**
1
+ /**
2
2
  * Plugin-owned diagnostic log: one JSONL file per day, appended serially,
3
3
  * rotated at a byte cap, and readable back through tail(). Both the Host
4
4
  * (boot, dispatch, wake, PMO, member failure/recovery) and the Client half
@@ -30,6 +30,32 @@ export function isErrorEvent(ev) {
30
30
  * `level`: 'off' drops every row (published default footprint), 'errors' keeps
31
31
  * only crash/fail rows, 'full' writes everything (development).
32
32
  */
33
+ /**
34
+ * 共享失败汇(进程级):库模块(ledger / registry / host-agent / skill-provider /
35
+ * jobs)拿不到 `diag` 实例,此前只能 `console.warn`——线上这些信息不可检索。
36
+ * 插件在 boot 时用 `installDiagSink()` 把真正的 diag 接进来;所有 `reportFail`
37
+ * 事件名以 `.fail` 结尾,因此在发布默认的 `errors` 级别下也会落盘。
38
+ */
39
+ let sharedSink = null;
40
+
41
+ /** @returns {() => void} 卸载函数(teardown 时调用,避免热重载后写旧实例)。 */
42
+ export function installDiagSink(sink) {
43
+ sharedSink = typeof sink === 'function' ? sink : null;
44
+ return () => { if (sharedSink === sink) sharedSink = null; };
45
+ }
46
+
47
+ /**
48
+ * 记录一条失败:既进 diag(可检索),也保留原有 console 输出(开发期可见)。
49
+ * diag 写入永不抛出——诊断通道不能反过来把调用方弄挂。
50
+ */
51
+ export function reportFail(event, payload = {}, consoleText = '') {
52
+ try {
53
+ if (sharedSink !== null) sharedSink({ ev: event, ...payload });
54
+ } catch { /* diagnostics must never break the caller */ }
55
+ if (consoleText !== '') {
56
+ try { console.warn(consoleText); } catch { /* console may be gone */ }
57
+ }
58
+ }
33
59
  export function createDiagLogger(options = {}) {
34
60
  const dir = options.dir ?? defaultDiagDir();
35
61
  const maxBytes = options.maxBytes ?? 1048576;
@@ -2,6 +2,7 @@
2
2
  import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
3
3
  import { join } from 'node:path';
4
4
  import { DEFAULT_PROJECT_ID } from './project-runtime.js';
5
+ import { reportFail } from '../diaglog.js';
5
6
 
6
7
  export class ProjectRegistry {
7
8
  constructor({ rootDir, projects, activeProjectId }) {
@@ -24,7 +25,7 @@ export class ProjectRegistry {
24
25
  // keep the broken file for forensics, then fall back to the default.
25
26
  const kept = `${file}.corrupt-${Date.now()}`;
26
27
  try { renameSync(file, kept); } catch { /* rename is best-effort */ }
27
- console.error(`[ai-team] projects.json was unreadable (${error?.message ?? error}); kept as ${kept}`);
28
+ reportFail('registry.corrupt.fail', { kept }, `[ai-team] projects.json was unreadable (${error?.message ?? error}); kept as ${kept}`);
28
29
  parsed = null;
29
30
  }
30
31
  const projects = Array.isArray(parsed?.projects) && parsed.projects.length > 0
@@ -1,4 +1,4 @@
1
- /**
1
+ /**
2
2
  * 单项目账本写入器:append-only JSONL、分段、fsync、单写者锁、尾撕裂修复。
3
3
  *
4
4
  * 对应 03-架构设计报告 §6.5 / §6.6 / §8.1、附录 B §B.3.6:
@@ -30,6 +30,7 @@ import {
30
30
  verifyEvent,
31
31
  } from './events.js';
32
32
  import { applyEvent, FOLD_STATE_VERSION, fold, initialState } from './fold.js';
33
+ import { reportFail } from '../diaglog.js';
33
34
  import { loadCheckpoint, saveCheckpoint } from './checkpoint.js';
34
35
 
35
36
  export { LedgerError };
@@ -959,7 +960,7 @@ export class LedgerWriter {
959
960
  } catch (markerCleanupError) {
960
961
  // 不静默:残留标记会被陈旧回收逻辑接管,但要在日志里留痕。
961
962
  if (markerCleanupError.code !== 'ENOENT') {
962
- console.warn(`[ai-team] ledger takeover marker could not be removed (${takeoverPath}): ${markerCleanupError.message}`);
963
+ reportFail('ledger.takeover.marker.fail', { projectId: this.projectId, takeoverPath }, `[ai-team] ledger takeover marker could not be removed (${takeoverPath}): ${markerCleanupError.message}`);
963
964
  }
964
965
  }
965
966
  }
@@ -1108,7 +1109,7 @@ export function openLedger(options = {}) {
1108
1109
  } catch (error) {
1109
1110
  // 检查点保存失败绝不影响追加,但必须可见:静默失败会让检查点
1110
1111
  // 名存实亡(boot 退化为全量重放而无人知晓)。
1111
- console.warn(`[ai-team] ledger ${writer.projectId} checkpoint save failed:`, error?.message ?? error);
1112
+ reportFail('checkpoint.save.fail', { projectId: writer.projectId }, `[ai-team] ledger ${writer.projectId} checkpoint save failed: ${error?.message ?? error}`);
1112
1113
  return { error: error.message ?? String(error) };
1113
1114
  }
1114
1115
  };
@@ -1,4 +1,4 @@
1
- /**
1
+ /**
2
2
  * Resolve the parent Agent that owns member activations.
3
3
  *
4
4
  * Preference order:
@@ -56,7 +56,7 @@ export async function ensureHostAgent(options) {
56
56
  try {
57
57
  await registry.unarchiveSession(sessionId);
58
58
  } catch (error) {
59
- console.warn('[ai-team] could not unarchive Team Host session:', error?.message ?? error);
59
+ reportFail('host.unarchive.fail', { sessionId: sessionId ?? null }, '[ai-team] could not unarchive Team Host session: ' + (error?.message ?? error));
60
60
  }
61
61
  };
62
62
  // Persist the resolved route into the session log. Live AgentOptions die
@@ -69,7 +69,7 @@ export async function ensureHostAgent(options) {
69
69
  if (typeof selection?.provider !== 'string' || typeof selection?.model !== 'string') return;
70
70
  session.append('model/selection', { provider: selection.provider, model: selection.model });
71
71
  } catch (error) {
72
- console.warn('[ai-team] host model selection persist failed:', error?.message ?? error);
72
+ reportFail('host.model.persist.fail', {}, '[ai-team] host model selection persist failed: ' + (error?.message ?? error));
73
73
  }
74
74
  };
75
75
  if (typeof options.resumeSessionId === 'string' && options.resumeSessionId !== '') {
@@ -14,6 +14,7 @@
14
14
  import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs';
15
15
  import { join } from 'node:path';
16
16
  import { isSkillExcluded } from './skill-policy.js';
17
+ import { reportFail } from '../diaglog.js';
17
18
 
18
19
  const MAX_BODY_BYTES = 512 * 1024;
19
20
 
@@ -99,13 +100,13 @@ function scanCandidate(file, fallbackName, source) {
99
100
  // Official semantics: `description` is required; a skill without one is
100
101
  // dropped with a warning rather than synthesized into the catalog.
101
102
  if (description === '') {
102
- console.warn(`[ai-team] skill "${name}" dropped: frontmatter description is required`);
103
+ reportFail('skill.dropped.fail', { skill: name, file, reason: 'description-required' }, `[ai-team] skill "${name}" dropped: frontmatter description is required`);
103
104
  return null;
104
105
  }
105
106
  const modelInvocable = invocationFlag(fields, 'disable-model-invocation', true);
106
107
  const userInvocable = invocationFlag(fields, 'user-invocable', false);
107
108
  if (modelInvocable === null || userInvocable === null) {
108
- console.warn(`[ai-team] skill "${name}" dropped: "${modelInvocable === null ? 'disable-model-invocation' : 'user-invocable'}" is not a recognized boolean`);
109
+ reportFail('skill.dropped.fail', { skill: name, file, reason: 'invocation-not-boolean' }, `[ai-team] skill "${name}" dropped: invocation flag is not a boolean`);
109
110
  return null;
110
111
  }
111
112
  return {
@@ -12,6 +12,7 @@
12
12
  * job 状态:`generating` → `judging` → `done` | `failed`。
13
13
  * 全部为纯逻辑 + 注入式 I/O,便于在测试里用内存文件系统驱动任意 tick 序列。
14
14
  */
15
+ import { reportFail } from '../diaglog.js';
15
16
  import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
16
17
  import { join } from 'node:path';
17
18
 
@@ -43,7 +44,7 @@ export function listJobs(projectDir) {
43
44
  jobs.push(JSON.parse(readFileSync(join(dir, name), 'utf8')));
44
45
  } catch (error) {
45
46
  // 静默跳过会让「job 幽灵消失」无从排查:坏文件保留在盘上并留一行警告。
46
- console.warn(`[skillopt] skipping unreadable job file ${name}: ${error?.message ?? error}`);
47
+ reportFail('job.file.unreadable.fail', { file: name }, `[skillopt] skipping unreadable job file ${name}: ${error?.message ?? error}`);
47
48
  }
48
49
  }
49
50
  return jobs.sort((a, b) => (a.createdAt ?? 0) - (b.createdAt ?? 0));
@@ -58,7 +59,7 @@ export function writeJob(projectDir, job) {
58
59
  // 覆写成 failed,之后 TTL 与统计都会按错误状态走。
59
60
  const existing = readJob(projectDir, job.id);
60
61
  if (existing !== null && existing.state === 'done' && job.state !== 'done') {
61
- console.warn(`[skillopt] refusing to overwrite a done job ${job.id} with ${String(job.state)}`);
62
+ reportFail('job.overwrite.refused.fail', { jobId: job.id, next: job.state }, `[skillopt] refusing to overwrite a done job ${job.id} with ${String(job.state)}`);
62
63
  return existing;
63
64
  }
64
65
  const temp = `${target}.tmp`;
@@ -132,4 +133,4 @@ export function planJobStep(job, observation) {
132
133
  return { next: 'done', actions: [{ type: 'finish', payload: { votes } }], reason: 'judges settled' };
133
134
  }
134
135
  return { next: 'failed', actions: [{ type: 'fail', payload: { reason: `unknown state ${String(state)}` } }], reason: 'unknown state' };
135
- }
136
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suifei/dsh-ai-team",
3
- "version": "0.4.53",
3
+ "version": "0.4.54",
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",