@suifei/dsh-ai-team 0.4.0 → 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 +15 -8
- package/lib/skillopt/job-runner.js +22 -7
- package/lib/skillopt/jobs.js +12 -3
- package/package.json +1 -1
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.
|
|
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'];
|
|
@@ -565,18 +565,22 @@ export function apply(ctx, config = {}) {
|
|
|
565
565
|
if (projectRuntime === null || projectRuntime === undefined) return;
|
|
566
566
|
const state = projectRuntime.service.state;
|
|
567
567
|
const project = state.projects?.[projectRuntime.id];
|
|
568
|
-
|
|
568
|
+
// job 收割先于 pmoAuto 门:Human 启动的优化 job 与 PMO 派发无关,
|
|
569
|
+
// PMO 自动关闭时也必须收敛(否则 job 永远停在 generating)。
|
|
569
570
|
// 两阶段异步优化 job 收割:与任务派发无关,放在停止门之前——
|
|
570
571
|
// Human 启动的 job 必须在任意运行态下收敛(生成/评审/落盘)。
|
|
571
572
|
try {
|
|
572
|
-
const parentInfo = await ensureParent();
|
|
573
573
|
await reconcileJobs({
|
|
574
574
|
ctx,
|
|
575
|
-
|
|
575
|
+
// job 归属项目数据目录(与 skillopt_optimize 写入处一致):
|
|
576
|
+
// 与工作区/激活项目无关,保证任意 tick 都能找到待收割 job。
|
|
577
|
+
projectDir: projectRuntime.dir,
|
|
576
578
|
deps: {
|
|
577
579
|
now: () => Date.now(),
|
|
578
580
|
provider: (ctx.get('subagents')?.list?.() ?? [])[0],
|
|
579
|
-
parent
|
|
581
|
+
// parent 惰性解析:仅启动 judge 子代理时需要;generating 阶段
|
|
582
|
+
// 不依赖 agents 服务,避免 tick 阶段服务不可用时整块失败。
|
|
583
|
+
ensureParent: () => ensureParent(),
|
|
580
584
|
votes: config.skilloptJudgeVotes ?? 3,
|
|
581
585
|
startChild: async (label, spec) => {
|
|
582
586
|
const child = await subagents.startActivation({ ...spec, label });
|
|
@@ -585,14 +589,15 @@ export function apply(ctx, config = {}) {
|
|
|
585
589
|
readText: (file) => readFileSync(file, 'utf8'),
|
|
586
590
|
writeText: (file, next) => writeFileSync(file, next, 'utf8'),
|
|
587
591
|
score: (value) => scoreSkillRubric(value, { measured: false }),
|
|
588
|
-
appendResult: makeResultAppender({ projectDir:
|
|
589
|
-
vcs: await makeVcs({ shell: lazyShellService(ctx), projectDir:
|
|
592
|
+
appendResult: makeResultAppender({ projectDir: projectRuntime.dir }),
|
|
593
|
+
vcs: await makeVcs({ shell: lazyShellService(ctx), projectDir: projectRuntime.dir }),
|
|
590
594
|
diag: (row) => diag.append(row),
|
|
591
595
|
},
|
|
592
596
|
});
|
|
593
597
|
} catch (error) {
|
|
594
598
|
diag.append({ ev: 'skillopt.job.tick.fail', message: error?.message ?? String(error) });
|
|
595
599
|
}
|
|
600
|
+
if (project === undefined || project.pmoAuto === false || project.status === 'archived') return;
|
|
596
601
|
// P6 停止门:stopped 项目停止一切派发(补派/心跳/升级/continue 全停),
|
|
597
602
|
// 正在执行的回合自然完成;唤醒事件 hook 同样检查(见 wakeFromResult)。
|
|
598
603
|
if (project.runState === 'stopped') return;
|
|
@@ -931,13 +936,15 @@ export function apply(ctx, config = {}) {
|
|
|
931
936
|
diag,
|
|
932
937
|
});
|
|
933
938
|
const jobId = 'job_' + Date.now().toString(36) + Math.random().toString(36).slice(2, 8);
|
|
939
|
+
// job 归属项目数据目录(tick 收割处相同),与调用者的路径参数解耦。
|
|
940
|
+
const jobRoot = currentRuntime()?.dir ?? project;
|
|
934
941
|
const child = await generator.start({
|
|
935
942
|
skillPath,
|
|
936
943
|
before: text0,
|
|
937
944
|
dimension,
|
|
938
945
|
round: 1,
|
|
939
946
|
});
|
|
940
|
-
writeJob(
|
|
947
|
+
writeJob(jobRoot, {
|
|
941
948
|
id: jobId,
|
|
942
949
|
state: 'generating',
|
|
943
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
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
|
100
|
+
parent,
|
|
86
101
|
},
|
|
87
102
|
delivery: 'parent',
|
|
88
103
|
signal: new AbortController().signal,
|
package/lib/skillopt/jobs.js
CHANGED
|
@@ -61,14 +61,23 @@ export function removeJob(projectDir, jobId) {
|
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
63
|
* 判定在飞子代理是否已完成。
|
|
64
|
-
*
|
|
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
|
-
|
|
71
|
-
|
|
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.
|
|
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",
|