@suifei/dsh-ai-team 0.4.1 → 0.4.4

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
@@ -48,7 +48,7 @@ export const name = 'ai-team';
48
48
  /** The workbench only makes sense where the Web carrier exists. */
49
49
  export const inject = ['webServer', 'permissionPresets', 'sandboxPolicy', 'tools', 'shell'];
50
50
 
51
- const VERSION = '0.4.1';
51
+ const VERSION = '0.4.4';
52
52
  const HUMAN_ID = 'mem_human';
53
53
 
54
54
  const SKILLOPT_BACKENDS = ['mock', 'claude', 'codex', 'copilot', 'cursor', 'pi', 'opencode', 'handoff', 'azure_openai'];
@@ -570,14 +570,17 @@ export function apply(ctx, config = {}) {
570
570
  // 两阶段异步优化 job 收割:与任务派发无关,放在停止门之前——
571
571
  // Human 启动的 job 必须在任意运行态下收敛(生成/评审/落盘)。
572
572
  try {
573
- const parentInfo = await ensureParent();
574
573
  await reconcileJobs({
575
574
  ctx,
576
- projectDir: project.workspacePath || projectRuntime.dir,
575
+ // job 归属项目数据目录(与 skillopt_optimize 写入处一致):
576
+ // 与工作区/激活项目无关,保证任意 tick 都能找到待收割 job。
577
+ projectDir: projectRuntime.dir,
577
578
  deps: {
578
579
  now: () => Date.now(),
579
580
  provider: (ctx.get('subagents')?.list?.() ?? [])[0],
580
- parent: parentInfo?.agent,
581
+ // parent 惰性解析:仅启动 judge 子代理时需要;generating 阶段
582
+ // 不依赖 agents 服务,避免 tick 阶段服务不可用时整块失败。
583
+ ensureParent: () => ensureParent(),
581
584
  votes: config.skilloptJudgeVotes ?? 3,
582
585
  startChild: async (label, spec) => {
583
586
  const child = await subagents.startActivation({ ...spec, label });
@@ -586,8 +589,8 @@ export function apply(ctx, config = {}) {
586
589
  readText: (file) => readFileSync(file, 'utf8'),
587
590
  writeText: (file, next) => writeFileSync(file, next, 'utf8'),
588
591
  score: (value) => scoreSkillRubric(value, { measured: false }),
589
- appendResult: makeResultAppender({ projectDir: project.workspacePath || projectRuntime.dir }),
590
- vcs: await makeVcs({ shell: lazyShellService(ctx), projectDir: project.workspacePath || projectRuntime.dir }),
592
+ appendResult: makeResultAppender({ projectDir: projectRuntime.dir }),
593
+ vcs: await makeVcs({ shell: lazyShellService(ctx), projectDir: projectRuntime.dir }),
591
594
  diag: (row) => diag.append(row),
592
595
  },
593
596
  });
@@ -933,13 +936,15 @@ export function apply(ctx, config = {}) {
933
936
  diag,
934
937
  });
935
938
  const jobId = 'job_' + Date.now().toString(36) + Math.random().toString(36).slice(2, 8);
939
+ // job 归属项目数据目录(tick 收割处相同),与调用者的路径参数解耦。
940
+ const jobRoot = currentRuntime()?.dir ?? project;
936
941
  const child = await generator.start({
937
942
  skillPath,
938
943
  before: text0,
939
944
  dimension,
940
945
  round: 1,
941
946
  });
942
- writeJob(project, {
947
+ writeJob(jobRoot, {
943
948
  id: jobId,
944
949
  state: 'generating',
945
950
  project,
@@ -12,13 +12,26 @@ import { validateCandidate } from './optimizer.js';
12
12
 
13
13
  /** 观测一个在飞子代理:状态 + 会话事件(同步,供状态机使用)。 */
14
14
  export function observeChild(ctx, childId, outputStart) {
15
+ // 三条路径兜底:agents(活 agent)→ subagents activation → sessions。
15
16
  const agent = ctx.get('agents')?.get?.(childId);
16
- if (agent === undefined || agent === null) return { status: null, events: [] };
17
- let events = [];
18
- try {
19
- events = agent.session?.snapshotEvents?.(outputStart) ?? [];
20
- } catch { /* session may be gone */ }
21
- return { status: agent.status ?? null, events, text: extractAssistantText(events) };
17
+ if (agent !== undefined && agent !== null) {
18
+ let events = [];
19
+ try {
20
+ events = agent.session?.snapshotEvents?.(outputStart) ?? [];
21
+ } catch { /* session may be gone */ }
22
+ return { status: agent.status ?? null, events, text: extractAssistantText(events) };
23
+ }
24
+ // 刚启动的子代理可能不在 agents registry:用 sessions 服务读会话事件。
25
+ const session = ctx.get('sessions')?.get?.(childId);
26
+ if (session !== undefined && session !== null) {
27
+ let events = [];
28
+ try {
29
+ events = session.snapshotEvents?.(outputStart) ?? [];
30
+ } catch { /* session may be gone */ }
31
+ return { status: null, events, text: extractAssistantText(events) };
32
+ }
33
+ // 完全查不到:不得视为已完成(由 TTL 兜底),调用方会继续等待。
34
+ return { status: 'running', events: [] };
22
35
  }
23
36
 
24
37
  /**
@@ -72,6 +85,8 @@ export async function stepJob(input) {
72
85
  deps.writeText(job.skillPath, action.payload.text);
73
86
  } else if (action.type === 'start-judges') {
74
87
  const votes = normalizeVoteCount(deps.votes ?? 3);
88
+ const parentInfo = typeof deps.ensureParent === 'function' ? await deps.ensureParent() : null;
89
+ const parent = parentInfo?.agent ?? deps.parent;
75
90
  const judgeChildIds = [];
76
91
  const judgeOrders = [];
77
92
  for (let index = 0; index < votes; index++) {
@@ -82,7 +97,7 @@ export async function stepJob(input) {
82
97
  request: {
83
98
  cwd: projectDir,
84
99
  prompt: [{ type: 'text', text: prompt }],
85
- parent: deps.parent,
100
+ parent,
86
101
  },
87
102
  delivery: 'parent',
88
103
  signal: new AbortController().signal,
@@ -61,14 +61,23 @@ export function removeJob(projectDir, jobId) {
61
61
 
62
62
  /**
63
63
  * 判定在飞子代理是否已完成。
64
- * @param {{status?: string, events?: Array}} observation 宿主观测(agent.status + 会话事件)
64
+ *
65
+ * 关键:**查不到状态不等于已完成**。刚启动的子代理可能在宿主 registry 里
66
+ * 暂不可见(agents.get 返回 undefined),此时必须继续等(有 TTL 兜底),
67
+ * 否则会在子代理尚未产出时报「空候选」。只有明确 idle / 结束事件 /
68
+ * 有事件且无状态时才算结束。
69
+ *
70
+ * @param {{status?: string|null, events?: Array}} observation
65
71
  * @returns {boolean}
66
72
  */
67
73
  export function isChildSettled(observation) {
68
74
  const events = Array.isArray(observation?.events) ? observation.events : [];
69
75
  if (events.some((event) => event?.type === 'subagent/end' || event?.type === 'session/end')) return true;
70
- // 一次性子代理完成后 agent 回到 idle;无 agent(已释放)同样视为结束。
71
- return observation?.status === 'idle' || observation?.status === null || observation?.status === undefined && events.length > 0;
76
+ const status = observation?.status;
77
+ if (status === 'idle') return true;
78
+ if (status === 'running') return false;
79
+ // 状态未知:有事件说明会话存在且可能已产出(无结束事件时由 TTL 兜底)。
80
+ return events.length > 0;
72
81
  }
73
82
 
74
83
  /** job 是否超时(TTL)。 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@suifei/dsh-ai-team",
3
- "version": "0.4.1",
3
+ "version": "0.4.4",
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",