@suifei/dsh-ai-team 0.4.110 → 0.4.111
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 +12 -0
- package/index.js +1 -1
- package/lib/skillopt/job-runner.js +208 -208
- package/lib/skillopt/judge-runner.js +1 -1
- package/lib/skillopt/optimize-wiring.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.111 - 2026-11-16
|
|
4
|
+
|
|
5
|
+
**SkillOpt 一次性子代理不再逐个唤醒 PMO**
|
|
6
|
+
|
|
7
|
+
- 作答、判官、生成子代理用 `delivery: 'parent'` 启动;官方语义是 parent 投递「通知父会话的模型」,caller
|
|
8
|
+
投递「只把结果交回调用方」。il2c 实机:PMO 宿主会话 16:30 起收到 104 条「子智能体已完成任务」,开了 51 个
|
|
9
|
+
回合(单回合用量 404K tok),主对话被逐条点评夜间环的内容淹没,会话头显示「112 个子智能体」;
|
|
10
|
+
- 4 处 SkillOpt 一次性子代理改为 `delivery: 'caller'`(结果仍经 `activation.result` / 会话事件取回);
|
|
11
|
+
成员激活保留 `parent`——成员结果本就要交给 PMO;
|
|
12
|
+
- 宿主文档:本地子代理总会进入父会话目录,`dispose` 后仍在目录里,子智能体计数不会因此下降;
|
|
13
|
+
- 测试:`test/stop-guard.test.js` 新增投递契约 1 例(换回旧实现即失败),`darwin-alignment` 判官断言改为 caller;
|
|
14
|
+
|
|
3
15
|
## 0.4.110 - 2026-11-16
|
|
4
16
|
|
|
5
17
|
**SkillOpt 一次性子代理只凭题面作答,不在真实工作区动手**
|
package/index.js
CHANGED
|
@@ -1168,7 +1168,7 @@ export function apply(ctx, config = {}) {
|
|
|
1168
1168
|
provider: resolveSubagentProviderName(serviceOf(ctx, 'subagents'), config?.subagentProviderName),
|
|
1169
1169
|
label,
|
|
1170
1170
|
request: { cwd: answerCwd, prompt: [{ type: 'text', text: request.prompt }], parent: parentInfo?.agent },
|
|
1171
|
-
delivery: '
|
|
1171
|
+
delivery: 'caller',
|
|
1172
1172
|
signal: new AbortController().signal,
|
|
1173
1173
|
}));
|
|
1174
1174
|
const childId = activation.childId;
|
|
@@ -1,208 +1,208 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 优化 job 的宿主侧收割:每个 PMO tick 调用一次,把状态机的一步动作落到
|
|
3
|
-
* 真实文件/子代理/结果记录上。
|
|
4
|
-
*
|
|
5
|
-
* 与 jobs.js(纯逻辑)分离;本模块只做注入式 I/O,因此测试可用内存实现。
|
|
6
|
-
*/
|
|
7
|
-
import { readFileSync, writeFileSync } from 'node:fs';
|
|
8
|
-
import { extractAssistantText } from './subagent-text.js';
|
|
9
|
-
import { isChildSettled, planJobStep, readJob, writeJob, listJobs } from './jobs.js';
|
|
10
|
-
import { decideByMajority, normalizeVoteCount, parseJudgeOutput, buildPairPrompt, voteFromParsed } from './judge.js';
|
|
11
|
-
import { validateCandidate } from './optimizer.js';
|
|
12
|
-
import { sha12 } from './proposal-store.js';
|
|
13
|
-
|
|
14
|
-
/** 观测一个在飞子代理:状态 + 会话事件(同步,供状态机使用)。 */
|
|
15
|
-
export function observeChild(ctx, childId, outputStart) {
|
|
16
|
-
// 三条路径兜底:agents(活 agent)→ subagents activation → sessions。
|
|
17
|
-
const agent = ctx.get('agents')?.get?.(childId);
|
|
18
|
-
if (agent !== undefined && agent !== null) {
|
|
19
|
-
let events = [];
|
|
20
|
-
try {
|
|
21
|
-
events = agent.session?.snapshotEvents?.(outputStart) ?? [];
|
|
22
|
-
} catch { /* session may be gone */ }
|
|
23
|
-
return { status: agent.status ?? null, events, text: extractAssistantText(events) };
|
|
24
|
-
}
|
|
25
|
-
// 刚启动的子代理可能不在 agents registry:用 sessions 服务读会话事件。
|
|
26
|
-
const session = ctx.get('sessions')?.get?.(childId);
|
|
27
|
-
if (session !== undefined && session !== null) {
|
|
28
|
-
let events = [];
|
|
29
|
-
try {
|
|
30
|
-
events = session.snapshotEvents?.(outputStart) ?? [];
|
|
31
|
-
} catch { /* session may be gone */ }
|
|
32
|
-
return { status: null, events, text: extractAssistantText(events) };
|
|
33
|
-
}
|
|
34
|
-
// 完全查不到:不得视为已完成(由 TTL 兜底),调用方会继续等待。
|
|
35
|
-
return { status: 'running', events: [] };
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* 推进一个 job 一步。
|
|
40
|
-
*
|
|
41
|
-
* @param {object} input
|
|
42
|
-
* @param {object} input.ctx DSH context
|
|
43
|
-
* @param {string} input.projectDir
|
|
44
|
-
* @param {object} input.job job 记录
|
|
45
|
-
* @param {object} input.deps
|
|
46
|
-
* @param {(name:string, spec:object)=>Promise<object>} input.deps.startChild 启动子代理(返回 {childId})
|
|
47
|
-
* @param {(path:string, text:string)=>void} input.deps.writeText
|
|
48
|
-
* @param {(path:string)=>string} input.deps.readText
|
|
49
|
-
* @param {object} input.deps.vcs makeVcs 结果
|
|
50
|
-
* @param {(line:string)=>Promise<void>} input.deps.appendResult
|
|
51
|
-
* @param {(text:string)=>object} input.deps.score
|
|
52
|
-
* @param {() => number} input.deps.now
|
|
53
|
-
* @param {string} input.deps.provider
|
|
54
|
-
* @param {object} input.deps.parent
|
|
55
|
-
* @param {number} [input.deps.votes]
|
|
56
|
-
* @param {(row:object)=>void} [input.deps.diag]
|
|
57
|
-
* @returns {Promise<{job:object, changed:boolean}>}
|
|
58
|
-
*/
|
|
59
|
-
export async function stepJob(input) {
|
|
60
|
-
const { ctx, projectDir, deps } = input;
|
|
61
|
-
let job = input.job;
|
|
62
|
-
const children = {};
|
|
63
|
-
for (const childId of [job.generatorChildId, ...(job.judgeChildIds ?? [])].filter(Boolean)) {
|
|
64
|
-
children[childId] = observeChild(ctx, childId, job.outputStart);
|
|
65
|
-
}
|
|
66
|
-
const plan = planJobStep(job, { children, now: deps.now() });
|
|
67
|
-
if (plan.next === job.state && plan.actions.every((action) => action.type === 'await')) {
|
|
68
|
-
return { job, changed: false };
|
|
69
|
-
}
|
|
70
|
-
for (const action of plan.actions) {
|
|
71
|
-
if (action.type === 'fail') {
|
|
72
|
-
await rollback({ deps, job, projectDir });
|
|
73
|
-
job = { ...job, state: 'failed', error: action.payload?.reason ?? 'failed', updatedAt: deps.now() };
|
|
74
|
-
await recordFail({ deps, job });
|
|
75
|
-
deps.diag?.({ ev: 'skillopt.job.fail', jobId: job.id, reason: job.error });
|
|
76
|
-
break;
|
|
77
|
-
} else if (action.type === 'apply-candidate') {
|
|
78
|
-
// 备份基线 → 写入候选 → 校验(超限时回滚)。
|
|
79
|
-
const before = deps.readText(job.skillPath);
|
|
80
|
-
const validation = validateCandidate({ before, after: action.payload?.text ?? '' });
|
|
81
|
-
if (!validation.ok) {
|
|
82
|
-
await rollback({ deps, job, projectDir });
|
|
83
|
-
job = { ...job, state: 'failed', error: validation.reason, updatedAt: deps.now() };
|
|
84
|
-
await recordFail({ deps, job });
|
|
85
|
-
deps.diag?.({ ev: 'skillopt.job.fail', jobId: job.id, reason: validation.reason });
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
// 不是每个 vcs 适配器都有 backup(git 适配器就没有):无脑调用会 TypeError,
|
|
89
|
-
// job 卡到 TTL 才失败。
|
|
90
|
-
const backup = typeof deps.vcs?.backup === 'function' ? await deps.vcs.backup(job.skillPath, before) : null;
|
|
91
|
-
job = { ...job, before, candidate: action.payload.text, backup };
|
|
92
|
-
// 先落盘再改 live:中途崩溃时 job 里已有 before/backup,可据此回滚;
|
|
93
|
-
// 反过来(先改 live)会让磁盘上的技能停在未审候选且无任何记录。
|
|
94
|
-
writeJob(projectDir, job);
|
|
95
|
-
deps.writeText(job.skillPath, action.payload.text);
|
|
96
|
-
} else if (action.type === 'start-judges') {
|
|
97
|
-
const votes = normalizeVoteCount(deps.votes ?? 3);
|
|
98
|
-
const parentInfo = typeof deps.ensureParent === 'function' ? await deps.ensureParent() : null;
|
|
99
|
-
const parent = parentInfo?.agent ?? deps.parent;
|
|
100
|
-
const judgeChildIds = [];
|
|
101
|
-
const judgeOrders = [];
|
|
102
|
-
for (let index = 0; index < votes; index++) {
|
|
103
|
-
const order = Math.random() < 0.5 ? 'ab' : 'ba';
|
|
104
|
-
const { prompt } = buildPairPrompt({ before: job.before, after: job.candidate, order });
|
|
105
|
-
const child = await deps.startChild(`skillopt-judge-${job.id}-${index + 1}`, {
|
|
106
|
-
provider: deps.provider,
|
|
107
|
-
request: {
|
|
108
|
-
cwd: projectDir,
|
|
109
|
-
prompt: [{ type: 'text', text: prompt }],
|
|
110
|
-
parent,
|
|
111
|
-
},
|
|
112
|
-
delivery: '
|
|
113
|
-
signal: new AbortController().signal,
|
|
114
|
-
});
|
|
115
|
-
judgeChildIds.push(child.childId);
|
|
116
|
-
judgeOrders.push({ childId: child.childId, order });
|
|
117
|
-
}
|
|
118
|
-
job = { ...job, state: 'judging', judgeChildIds, judgeOrders, updatedAt: deps.now() };
|
|
119
|
-
} else if (action.type === 'finish') {
|
|
120
|
-
const votes = [];
|
|
121
|
-
for (const row of action.payload?.votes ?? []) {
|
|
122
|
-
const mapping = (job.judgeOrders ?? []).find((entry) => entry.childId === row.childId);
|
|
123
|
-
const parsed = parseJudgeOutput(row.text);
|
|
124
|
-
const vote = voteFromParsed(parsed === null ? null : { ...parsed, aIsAfter: mapping?.order === 'ba' });
|
|
125
|
-
votes.push({ childId: row.childId, vote, margin: parsed?.margin ?? null, reason: parsed?.reason ?? '' });
|
|
126
|
-
}
|
|
127
|
-
const decision = decideByMajority(votes.map((entry) => entry.vote));
|
|
128
|
-
const kept = decision.verdict === 'keep';
|
|
129
|
-
if (!kept) await rollback({ deps, job, projectDir });
|
|
130
|
-
job = { ...job, state: 'done', decision: { ...decision, votes, kept }, updatedAt: deps.now() };
|
|
131
|
-
const afterText = kept ? job.candidate : job.before;
|
|
132
|
-
const beforeScore = deps.score(job.before)?.total ?? null;
|
|
133
|
-
const afterScore = deps.score(afterText)?.total ?? null;
|
|
134
|
-
await deps.appendResult([
|
|
135
|
-
new Date(deps.now()).toISOString().slice(0, 19),
|
|
136
|
-
deps.vcs.kind === 'git' ? (job.commit ?? '-') : '-',
|
|
137
|
-
job.skillName,
|
|
138
|
-
String(beforeScore ?? '-'),
|
|
139
|
-
String(afterScore ?? '-'),
|
|
140
|
-
kept ? 'keep' : 'revert',
|
|
141
|
-
job.dimension ?? '-',
|
|
142
|
-
`${decision.better}-${decision.worse} ${decision.verdict}`,
|
|
143
|
-
'paired',
|
|
144
|
-
sha12(job.candidate),
|
|
145
|
-
].join('\t'));
|
|
146
|
-
deps.diag?.({ ev: 'skillopt.job.done', jobId: job.id, verdict: decision.verdict, better: decision.better, worse: decision.worse, kept });
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
// 失败/完成是终态:plan 是在 switch 之前算的,若拿它回写就会把刚判死的 job
|
|
150
|
-
// 复活成 judging,下一轮再拿一个未应用的候选写假记录。
|
|
151
|
-
const terminal = job.state === 'failed' || job.state === 'done';
|
|
152
|
-
if (!terminal && plan.next !== job.state && plan.next !== 'failed') job = { ...job, state: plan.next, updatedAt: deps.now() };
|
|
153
|
-
writeJob(projectDir, job);
|
|
154
|
-
return { job, changed: true };
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/** failed 终态也必须成行(results.tsv ≡ jobs 盘件机判行;257-#60②)。 */
|
|
158
|
-
async function recordFail({ deps, job }) {
|
|
159
|
-
await deps.appendResult([
|
|
160
|
-
new Date(deps.now()).toISOString().slice(0, 19),
|
|
161
|
-
'-',
|
|
162
|
-
job.skillName ?? '-',
|
|
163
|
-
'-',
|
|
164
|
-
'-',
|
|
165
|
-
'failed',
|
|
166
|
-
job.dimension ?? '-',
|
|
167
|
-
String(job.error ?? 'failed').replace(/[\t\r\n]+/g, ' '),
|
|
168
|
-
'paired',
|
|
169
|
-
typeof job.candidate === 'string' ? sha12(job.candidate) : '-',
|
|
170
|
-
].join('\t'));
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
async function rollback({ deps, job, projectDir }) {
|
|
174
|
-
if (job?.candidate === undefined || job?.before === undefined) return;
|
|
175
|
-
// 回滚前必须确认 live 仍是**我们写下的那个候选**:评审期间可能有人手改,
|
|
176
|
-
// 无条件把陈旧的 before 写回去会覆盖掉那次人工修改(且原子性无从谈起)。
|
|
177
|
-
let current = null;
|
|
178
|
-
try {
|
|
179
|
-
current = deps.readText ? deps.readText(job.skillPath) : null;
|
|
180
|
-
} catch {
|
|
181
|
-
current = null;
|
|
182
|
-
}
|
|
183
|
-
if (typeof current === 'string' && sha12(current) !== sha12(job.candidate)) {
|
|
184
|
-
deps.diag?.({ ev: 'skillopt.rollback.skipped', jobId: job.id, reason: 'live file changed since the candidate was applied' });
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
try {
|
|
188
|
-
if (deps.vcs.kind === 'file' && typeof job.backup === 'string') {
|
|
189
|
-
await deps.vcs.restore(job.skillPath, job.backup);
|
|
190
|
-
} else {
|
|
191
|
-
deps.writeText(job.skillPath, job.before);
|
|
192
|
-
}
|
|
193
|
-
} catch { /* best effort */ }
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/** 收割全部 pending job(tick 入口)。 */
|
|
197
|
-
export async function reconcileJobs(input) {
|
|
198
|
-
// 评审通道的 job(带 reviewTaskId)由 skillopt_jobs 收集,不走子代理 reconcile:
|
|
199
|
-
// 否则 reconcile 会在评审官回帖前把它判成 inconclusive done。
|
|
200
|
-
const jobs = listJobs(input.projectDir).filter((job) => (job.state === 'generating' || job.state === 'judging') && typeof job.reviewTaskId !== 'string');
|
|
201
|
-
const results = [];
|
|
202
|
-
for (const job of jobs) {
|
|
203
|
-
results.push(await stepJob({ ...input, job }));
|
|
204
|
-
}
|
|
205
|
-
return results;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
export { isChildSettled, readJob, writeJob };
|
|
1
|
+
/**
|
|
2
|
+
* 优化 job 的宿主侧收割:每个 PMO tick 调用一次,把状态机的一步动作落到
|
|
3
|
+
* 真实文件/子代理/结果记录上。
|
|
4
|
+
*
|
|
5
|
+
* 与 jobs.js(纯逻辑)分离;本模块只做注入式 I/O,因此测试可用内存实现。
|
|
6
|
+
*/
|
|
7
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
8
|
+
import { extractAssistantText } from './subagent-text.js';
|
|
9
|
+
import { isChildSettled, planJobStep, readJob, writeJob, listJobs } from './jobs.js';
|
|
10
|
+
import { decideByMajority, normalizeVoteCount, parseJudgeOutput, buildPairPrompt, voteFromParsed } from './judge.js';
|
|
11
|
+
import { validateCandidate } from './optimizer.js';
|
|
12
|
+
import { sha12 } from './proposal-store.js';
|
|
13
|
+
|
|
14
|
+
/** 观测一个在飞子代理:状态 + 会话事件(同步,供状态机使用)。 */
|
|
15
|
+
export function observeChild(ctx, childId, outputStart) {
|
|
16
|
+
// 三条路径兜底:agents(活 agent)→ subagents activation → sessions。
|
|
17
|
+
const agent = ctx.get('agents')?.get?.(childId);
|
|
18
|
+
if (agent !== undefined && agent !== null) {
|
|
19
|
+
let events = [];
|
|
20
|
+
try {
|
|
21
|
+
events = agent.session?.snapshotEvents?.(outputStart) ?? [];
|
|
22
|
+
} catch { /* session may be gone */ }
|
|
23
|
+
return { status: agent.status ?? null, events, text: extractAssistantText(events) };
|
|
24
|
+
}
|
|
25
|
+
// 刚启动的子代理可能不在 agents registry:用 sessions 服务读会话事件。
|
|
26
|
+
const session = ctx.get('sessions')?.get?.(childId);
|
|
27
|
+
if (session !== undefined && session !== null) {
|
|
28
|
+
let events = [];
|
|
29
|
+
try {
|
|
30
|
+
events = session.snapshotEvents?.(outputStart) ?? [];
|
|
31
|
+
} catch { /* session may be gone */ }
|
|
32
|
+
return { status: null, events, text: extractAssistantText(events) };
|
|
33
|
+
}
|
|
34
|
+
// 完全查不到:不得视为已完成(由 TTL 兜底),调用方会继续等待。
|
|
35
|
+
return { status: 'running', events: [] };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 推进一个 job 一步。
|
|
40
|
+
*
|
|
41
|
+
* @param {object} input
|
|
42
|
+
* @param {object} input.ctx DSH context
|
|
43
|
+
* @param {string} input.projectDir
|
|
44
|
+
* @param {object} input.job job 记录
|
|
45
|
+
* @param {object} input.deps
|
|
46
|
+
* @param {(name:string, spec:object)=>Promise<object>} input.deps.startChild 启动子代理(返回 {childId})
|
|
47
|
+
* @param {(path:string, text:string)=>void} input.deps.writeText
|
|
48
|
+
* @param {(path:string)=>string} input.deps.readText
|
|
49
|
+
* @param {object} input.deps.vcs makeVcs 结果
|
|
50
|
+
* @param {(line:string)=>Promise<void>} input.deps.appendResult
|
|
51
|
+
* @param {(text:string)=>object} input.deps.score
|
|
52
|
+
* @param {() => number} input.deps.now
|
|
53
|
+
* @param {string} input.deps.provider
|
|
54
|
+
* @param {object} input.deps.parent
|
|
55
|
+
* @param {number} [input.deps.votes]
|
|
56
|
+
* @param {(row:object)=>void} [input.deps.diag]
|
|
57
|
+
* @returns {Promise<{job:object, changed:boolean}>}
|
|
58
|
+
*/
|
|
59
|
+
export async function stepJob(input) {
|
|
60
|
+
const { ctx, projectDir, deps } = input;
|
|
61
|
+
let job = input.job;
|
|
62
|
+
const children = {};
|
|
63
|
+
for (const childId of [job.generatorChildId, ...(job.judgeChildIds ?? [])].filter(Boolean)) {
|
|
64
|
+
children[childId] = observeChild(ctx, childId, job.outputStart);
|
|
65
|
+
}
|
|
66
|
+
const plan = planJobStep(job, { children, now: deps.now() });
|
|
67
|
+
if (plan.next === job.state && plan.actions.every((action) => action.type === 'await')) {
|
|
68
|
+
return { job, changed: false };
|
|
69
|
+
}
|
|
70
|
+
for (const action of plan.actions) {
|
|
71
|
+
if (action.type === 'fail') {
|
|
72
|
+
await rollback({ deps, job, projectDir });
|
|
73
|
+
job = { ...job, state: 'failed', error: action.payload?.reason ?? 'failed', updatedAt: deps.now() };
|
|
74
|
+
await recordFail({ deps, job });
|
|
75
|
+
deps.diag?.({ ev: 'skillopt.job.fail', jobId: job.id, reason: job.error });
|
|
76
|
+
break;
|
|
77
|
+
} else if (action.type === 'apply-candidate') {
|
|
78
|
+
// 备份基线 → 写入候选 → 校验(超限时回滚)。
|
|
79
|
+
const before = deps.readText(job.skillPath);
|
|
80
|
+
const validation = validateCandidate({ before, after: action.payload?.text ?? '' });
|
|
81
|
+
if (!validation.ok) {
|
|
82
|
+
await rollback({ deps, job, projectDir });
|
|
83
|
+
job = { ...job, state: 'failed', error: validation.reason, updatedAt: deps.now() };
|
|
84
|
+
await recordFail({ deps, job });
|
|
85
|
+
deps.diag?.({ ev: 'skillopt.job.fail', jobId: job.id, reason: validation.reason });
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
// 不是每个 vcs 适配器都有 backup(git 适配器就没有):无脑调用会 TypeError,
|
|
89
|
+
// job 卡到 TTL 才失败。
|
|
90
|
+
const backup = typeof deps.vcs?.backup === 'function' ? await deps.vcs.backup(job.skillPath, before) : null;
|
|
91
|
+
job = { ...job, before, candidate: action.payload.text, backup };
|
|
92
|
+
// 先落盘再改 live:中途崩溃时 job 里已有 before/backup,可据此回滚;
|
|
93
|
+
// 反过来(先改 live)会让磁盘上的技能停在未审候选且无任何记录。
|
|
94
|
+
writeJob(projectDir, job);
|
|
95
|
+
deps.writeText(job.skillPath, action.payload.text);
|
|
96
|
+
} else if (action.type === 'start-judges') {
|
|
97
|
+
const votes = normalizeVoteCount(deps.votes ?? 3);
|
|
98
|
+
const parentInfo = typeof deps.ensureParent === 'function' ? await deps.ensureParent() : null;
|
|
99
|
+
const parent = parentInfo?.agent ?? deps.parent;
|
|
100
|
+
const judgeChildIds = [];
|
|
101
|
+
const judgeOrders = [];
|
|
102
|
+
for (let index = 0; index < votes; index++) {
|
|
103
|
+
const order = Math.random() < 0.5 ? 'ab' : 'ba';
|
|
104
|
+
const { prompt } = buildPairPrompt({ before: job.before, after: job.candidate, order });
|
|
105
|
+
const child = await deps.startChild(`skillopt-judge-${job.id}-${index + 1}`, {
|
|
106
|
+
provider: deps.provider,
|
|
107
|
+
request: {
|
|
108
|
+
cwd: projectDir,
|
|
109
|
+
prompt: [{ type: 'text', text: prompt }],
|
|
110
|
+
parent,
|
|
111
|
+
},
|
|
112
|
+
delivery: 'caller',
|
|
113
|
+
signal: new AbortController().signal,
|
|
114
|
+
});
|
|
115
|
+
judgeChildIds.push(child.childId);
|
|
116
|
+
judgeOrders.push({ childId: child.childId, order });
|
|
117
|
+
}
|
|
118
|
+
job = { ...job, state: 'judging', judgeChildIds, judgeOrders, updatedAt: deps.now() };
|
|
119
|
+
} else if (action.type === 'finish') {
|
|
120
|
+
const votes = [];
|
|
121
|
+
for (const row of action.payload?.votes ?? []) {
|
|
122
|
+
const mapping = (job.judgeOrders ?? []).find((entry) => entry.childId === row.childId);
|
|
123
|
+
const parsed = parseJudgeOutput(row.text);
|
|
124
|
+
const vote = voteFromParsed(parsed === null ? null : { ...parsed, aIsAfter: mapping?.order === 'ba' });
|
|
125
|
+
votes.push({ childId: row.childId, vote, margin: parsed?.margin ?? null, reason: parsed?.reason ?? '' });
|
|
126
|
+
}
|
|
127
|
+
const decision = decideByMajority(votes.map((entry) => entry.vote));
|
|
128
|
+
const kept = decision.verdict === 'keep';
|
|
129
|
+
if (!kept) await rollback({ deps, job, projectDir });
|
|
130
|
+
job = { ...job, state: 'done', decision: { ...decision, votes, kept }, updatedAt: deps.now() };
|
|
131
|
+
const afterText = kept ? job.candidate : job.before;
|
|
132
|
+
const beforeScore = deps.score(job.before)?.total ?? null;
|
|
133
|
+
const afterScore = deps.score(afterText)?.total ?? null;
|
|
134
|
+
await deps.appendResult([
|
|
135
|
+
new Date(deps.now()).toISOString().slice(0, 19),
|
|
136
|
+
deps.vcs.kind === 'git' ? (job.commit ?? '-') : '-',
|
|
137
|
+
job.skillName,
|
|
138
|
+
String(beforeScore ?? '-'),
|
|
139
|
+
String(afterScore ?? '-'),
|
|
140
|
+
kept ? 'keep' : 'revert',
|
|
141
|
+
job.dimension ?? '-',
|
|
142
|
+
`${decision.better}-${decision.worse} ${decision.verdict}`,
|
|
143
|
+
'paired',
|
|
144
|
+
sha12(job.candidate),
|
|
145
|
+
].join('\t'));
|
|
146
|
+
deps.diag?.({ ev: 'skillopt.job.done', jobId: job.id, verdict: decision.verdict, better: decision.better, worse: decision.worse, kept });
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
// 失败/完成是终态:plan 是在 switch 之前算的,若拿它回写就会把刚判死的 job
|
|
150
|
+
// 复活成 judging,下一轮再拿一个未应用的候选写假记录。
|
|
151
|
+
const terminal = job.state === 'failed' || job.state === 'done';
|
|
152
|
+
if (!terminal && plan.next !== job.state && plan.next !== 'failed') job = { ...job, state: plan.next, updatedAt: deps.now() };
|
|
153
|
+
writeJob(projectDir, job);
|
|
154
|
+
return { job, changed: true };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** failed 终态也必须成行(results.tsv ≡ jobs 盘件机判行;257-#60②)。 */
|
|
158
|
+
async function recordFail({ deps, job }) {
|
|
159
|
+
await deps.appendResult([
|
|
160
|
+
new Date(deps.now()).toISOString().slice(0, 19),
|
|
161
|
+
'-',
|
|
162
|
+
job.skillName ?? '-',
|
|
163
|
+
'-',
|
|
164
|
+
'-',
|
|
165
|
+
'failed',
|
|
166
|
+
job.dimension ?? '-',
|
|
167
|
+
String(job.error ?? 'failed').replace(/[\t\r\n]+/g, ' '),
|
|
168
|
+
'paired',
|
|
169
|
+
typeof job.candidate === 'string' ? sha12(job.candidate) : '-',
|
|
170
|
+
].join('\t'));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async function rollback({ deps, job, projectDir }) {
|
|
174
|
+
if (job?.candidate === undefined || job?.before === undefined) return;
|
|
175
|
+
// 回滚前必须确认 live 仍是**我们写下的那个候选**:评审期间可能有人手改,
|
|
176
|
+
// 无条件把陈旧的 before 写回去会覆盖掉那次人工修改(且原子性无从谈起)。
|
|
177
|
+
let current = null;
|
|
178
|
+
try {
|
|
179
|
+
current = deps.readText ? deps.readText(job.skillPath) : null;
|
|
180
|
+
} catch {
|
|
181
|
+
current = null;
|
|
182
|
+
}
|
|
183
|
+
if (typeof current === 'string' && sha12(current) !== sha12(job.candidate)) {
|
|
184
|
+
deps.diag?.({ ev: 'skillopt.rollback.skipped', jobId: job.id, reason: 'live file changed since the candidate was applied' });
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
try {
|
|
188
|
+
if (deps.vcs.kind === 'file' && typeof job.backup === 'string') {
|
|
189
|
+
await deps.vcs.restore(job.skillPath, job.backup);
|
|
190
|
+
} else {
|
|
191
|
+
deps.writeText(job.skillPath, job.before);
|
|
192
|
+
}
|
|
193
|
+
} catch { /* best effort */ }
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** 收割全部 pending job(tick 入口)。 */
|
|
197
|
+
export async function reconcileJobs(input) {
|
|
198
|
+
// 评审通道的 job(带 reviewTaskId)由 skillopt_jobs 收集,不走子代理 reconcile:
|
|
199
|
+
// 否则 reconcile 会在评审官回帖前把它判成 inconclusive done。
|
|
200
|
+
const jobs = listJobs(input.projectDir).filter((job) => (job.state === 'generating' || job.state === 'judging') && typeof job.reviewTaskId !== 'string');
|
|
201
|
+
const results = [];
|
|
202
|
+
for (const job of jobs) {
|
|
203
|
+
results.push(await stepJob({ ...input, job }));
|
|
204
|
+
}
|
|
205
|
+
return results;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export { isChildSettled, readJob, writeJob };
|
|
@@ -49,7 +49,7 @@ export async function judgePair(input) {
|
|
|
49
49
|
provider,
|
|
50
50
|
label: `skillopt-judge-${index + 1}`,
|
|
51
51
|
request: { cwd, prompt: [{ type: 'text', text: prompt }], parent },
|
|
52
|
-
delivery: '
|
|
52
|
+
delivery: 'caller',
|
|
53
53
|
signal: new AbortController().signal,
|
|
54
54
|
}));
|
|
55
55
|
const text = await awaitActivationText(activation, { timeoutMs: JUDGE_TIMEOUT_MS });
|
|
@@ -84,7 +84,7 @@ export function makeGenerator({ subagents, ensureParent, providerName, cwd }) {
|
|
|
84
84
|
provider,
|
|
85
85
|
label: `skillopt-optimize-${round}`,
|
|
86
86
|
request: { cwd, prompt: [{ type: 'text', text: prompt }], parent: parentInfo?.agent },
|
|
87
|
-
delivery: '
|
|
87
|
+
delivery: 'caller',
|
|
88
88
|
signal: new AbortController().signal,
|
|
89
89
|
}));
|
|
90
90
|
return { childId: activation.childId, outputStart: activation.outputStart ?? null };
|
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.111",
|
|
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",
|