@suifei/dsh-ai-team 0.4.24 → 0.4.28
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 +51 -0
- package/client.js +30 -10
- package/index.js +300 -42
- package/lib/domain/task.js +6 -0
- package/lib/host/decision-report.js +16 -2
- package/lib/host/member-tools.js +7 -5
- package/lib/host/project-registry.js +19 -2
- package/lib/host/service.js +172 -35
- package/lib/host/views.js +23 -1
- package/lib/host/waker.js +7 -3
- package/lib/host/weekly-view.js +3 -0
- package/lib/ledger/checkpoint.js +11 -0
- package/lib/ledger/writer.js +164 -23
- package/lib/runtime/failure-policy.js +15 -4
- package/lib/runtime/host-agent.js +38 -10
- package/lib/runtime/host-repair.js +70 -0
- package/lib/runtime/member-runtime.js +19 -12
- package/lib/runtime/skill-catalog.js +4 -1
- package/lib/runtime/skill-provider.js +29 -5
- package/lib/skillopt/adopt-gate.js +1 -1
- package/lib/skillopt/gate-wiring.js +24 -4
- package/lib/skillopt/job-runner.js +5 -0
- package/lib/skillopt/jobs.js +4 -1
- package/lib/skillopt/judge.js +46 -12
- package/lib/skillopt/optimize-wiring.js +12 -6
- package/lib/skillopt/proposal-store.js +33 -0
- package/lib/skillopt/review-runner.js +17 -3
- package/lib/skillopt/reviewer.js +4 -4
- package/lib/skillopt/rubric.js +20 -6
- package/lib/skillopt/tool-access.js +56 -0
- package/package.json +3 -3
- package/lib/vendor/skillopt/skillopt_sleep/__pycache__/__init__.cpython-311.pyc +0 -0
- package/lib/vendor/skillopt/skillopt_sleep/__pycache__/__main__.cpython-311.pyc +0 -0
- package/lib/vendor/skillopt/skillopt_sleep/__pycache__/backend.cpython-311.pyc +0 -0
- package/lib/vendor/skillopt/skillopt_sleep/__pycache__/budget.cpython-311.pyc +0 -0
- package/lib/vendor/skillopt/skillopt_sleep/__pycache__/config.cpython-311.pyc +0 -0
- package/lib/vendor/skillopt/skillopt_sleep/__pycache__/consolidate.cpython-311.pyc +0 -0
- package/lib/vendor/skillopt/skillopt_sleep/__pycache__/cycle.cpython-311.pyc +0 -0
- package/lib/vendor/skillopt/skillopt_sleep/__pycache__/dream.cpython-311.pyc +0 -0
- package/lib/vendor/skillopt/skillopt_sleep/__pycache__/evidence.cpython-311.pyc +0 -0
- package/lib/vendor/skillopt/skillopt_sleep/__pycache__/gate.cpython-311.pyc +0 -0
- package/lib/vendor/skillopt/skillopt_sleep/__pycache__/handoff_backend.cpython-311.pyc +0 -0
- package/lib/vendor/skillopt/skillopt_sleep/__pycache__/harvest.cpython-311.pyc +0 -0
- package/lib/vendor/skillopt/skillopt_sleep/__pycache__/harvest_codex.cpython-311.pyc +0 -0
- package/lib/vendor/skillopt/skillopt_sleep/__pycache__/harvest_copilot.cpython-311.pyc +0 -0
- package/lib/vendor/skillopt/skillopt_sleep/__pycache__/harvest_copilot_cli.cpython-311.pyc +0 -0
- package/lib/vendor/skillopt/skillopt_sleep/__pycache__/harvest_cursor.cpython-311.pyc +0 -0
- package/lib/vendor/skillopt/skillopt_sleep/__pycache__/harvest_opencode.cpython-311.pyc +0 -0
- package/lib/vendor/skillopt/skillopt_sleep/__pycache__/harvest_pi.cpython-311.pyc +0 -0
- package/lib/vendor/skillopt/skillopt_sleep/__pycache__/harvest_sources.cpython-311.pyc +0 -0
- package/lib/vendor/skillopt/skillopt_sleep/__pycache__/judges.cpython-311.pyc +0 -0
- package/lib/vendor/skillopt/skillopt_sleep/__pycache__/memory.cpython-311.pyc +0 -0
- package/lib/vendor/skillopt/skillopt_sleep/__pycache__/mine.cpython-311.pyc +0 -0
- package/lib/vendor/skillopt/skillopt_sleep/__pycache__/multi_skill.cpython-311.pyc +0 -0
- package/lib/vendor/skillopt/skillopt_sleep/__pycache__/replay.cpython-311.pyc +0 -0
- package/lib/vendor/skillopt/skillopt_sleep/__pycache__/skill_resolver.cpython-311.pyc +0 -0
- package/lib/vendor/skillopt/skillopt_sleep/__pycache__/staging.cpython-311.pyc +0 -0
- package/lib/vendor/skillopt/skillopt_sleep/__pycache__/state.cpython-311.pyc +0 -0
- package/lib/vendor/skillopt/skillopt_sleep/__pycache__/tasks_file.cpython-311.pyc +0 -0
- package/lib/vendor/skillopt/skillopt_sleep/__pycache__/types.cpython-311.pyc +0 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
2
|
* SkillOpt adopt gate 的宿主接线:把「读候选/基线」和「独立 judge」落到
|
|
3
3
|
* DSH 服务上。与 adopt-gate.js(纯协议)分离,便于单测协议、集成测接线。
|
|
4
4
|
*
|
|
5
5
|
* baseline 取 live SKILL.md 当前内容:adopt 之前 live 文件就是改前版本
|
|
6
6
|
* (staging 只写候选项),因此不需要 git 历史即可对比。
|
|
7
7
|
*/
|
|
8
|
-
import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
|
9
|
-
import { join } from 'node:path';
|
|
8
|
+
import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs';
|
|
9
|
+
import { isAbsolute, join } from 'node:path';
|
|
10
10
|
import { judgePair } from './judge-runner.js';
|
|
11
11
|
|
|
12
12
|
/** 引号一个 argv 元素(Windows cmd 与 POSIX sh 通用单引号形式)。 */
|
|
@@ -19,6 +19,25 @@ export function quoteArgv(argv) {
|
|
|
19
19
|
return argv.map(quote).join(' ');
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* 模型可控的 project 会被拼进 shell 命令,因此必须在进 shell 前校验。
|
|
24
|
+
* `quoteArgv` 只是引号包裹:`$(...)`、反引号在双引号内仍会被 shell 展开,
|
|
25
|
+
* 而 pwsh 下 `\"` 也不是转义——只靠引号挡不住注入。这里要求它是一个
|
|
26
|
+
* 真实存在的绝对目录,且不含任何 shell 元字符。
|
|
27
|
+
*/
|
|
28
|
+
export function assertSafeProjectDir(dir) {
|
|
29
|
+
if (typeof dir !== 'string' || dir.trim() === '') throw new Error('project directory is required');
|
|
30
|
+
const text = dir.trim();
|
|
31
|
+
if (!isAbsolute(text)) throw new Error('project directory must be an absolute path');
|
|
32
|
+
if (/[\u0000-\u001f`$;|&<>(){}[\]*?"'!^%\r\n]/.test(text)) {
|
|
33
|
+
throw new Error('project directory must not contain shell metacharacters');
|
|
34
|
+
}
|
|
35
|
+
if (!existsSync(text) || statSync(text).isDirectory() !== true) {
|
|
36
|
+
throw new Error('project directory does not exist');
|
|
37
|
+
}
|
|
38
|
+
return text;
|
|
39
|
+
}
|
|
40
|
+
|
|
22
41
|
/** 跑引擎 CLI(status 等只读命令);返回 {exitCode, stdout, stderr}。 */
|
|
23
42
|
export async function runEngineCli(shell, args, options = {}) {
|
|
24
43
|
const request = {
|
|
@@ -48,7 +67,8 @@ export async function runEngineCli(shell, args, options = {}) {
|
|
|
48
67
|
export function makeReadPair(deps) {
|
|
49
68
|
const { shell, engineScript, python = 'python', diag } = deps;
|
|
50
69
|
return async (projectDir) => {
|
|
51
|
-
const
|
|
70
|
+
const safeDir = assertSafeProjectDir(projectDir);
|
|
71
|
+
const status = await runEngineCli(shell, [python, engineScript, 'status', '--json', '--project', safeDir]);
|
|
52
72
|
if (status.timedOut) throw new Error('engine status timed out');
|
|
53
73
|
const raw = status.stdout.slice(status.stdout.indexOf('{'));
|
|
54
74
|
let payload;
|
|
@@ -9,6 +9,7 @@ import { extractAssistantText } from './subagent-text.js';
|
|
|
9
9
|
import { isChildSettled, planJobStep, readJob, writeJob, listJobs } from './jobs.js';
|
|
10
10
|
import { decideByMajority, normalizeVoteCount, parseJudgeOutput, buildPairPrompt, voteFromParsed } from './judge.js';
|
|
11
11
|
import { validateCandidate } from './optimizer.js';
|
|
12
|
+
import { sha12 } from './proposal-store.js';
|
|
12
13
|
|
|
13
14
|
/** 观测一个在飞子代理:状态 + 会话事件(同步,供状态机使用)。 */
|
|
14
15
|
export function observeChild(ctx, childId, outputStart) {
|
|
@@ -82,6 +83,9 @@ export async function stepJob(input) {
|
|
|
82
83
|
break;
|
|
83
84
|
}
|
|
84
85
|
job = { ...job, before, candidate: action.payload.text, backup: await deps.vcs.backup(job.skillPath, before) };
|
|
86
|
+
// 先落盘再改 live:中途崩溃时 job 里已有 before/backup,可据此回滚;
|
|
87
|
+
// 反过来(先改 live)会让磁盘上的技能停在未审候选且无任何记录。
|
|
88
|
+
writeJob(projectDir, job);
|
|
85
89
|
deps.writeText(job.skillPath, action.payload.text);
|
|
86
90
|
} else if (action.type === 'start-judges') {
|
|
87
91
|
const votes = normalizeVoteCount(deps.votes ?? 3);
|
|
@@ -131,6 +135,7 @@ export async function stepJob(input) {
|
|
|
131
135
|
job.dimension ?? '-',
|
|
132
136
|
`${decision.better}-${decision.worse} ${decision.verdict}`,
|
|
133
137
|
'paired',
|
|
138
|
+
sha12(job.candidate),
|
|
134
139
|
].join('\t'));
|
|
135
140
|
deps.diag?.({ ev: 'skillopt.job.done', jobId: job.id, verdict: decision.verdict, better: decision.better, worse: decision.worse, kept });
|
|
136
141
|
}
|
package/lib/skillopt/jobs.js
CHANGED
|
@@ -41,7 +41,10 @@ export function listJobs(projectDir) {
|
|
|
41
41
|
if (!name.endsWith('.json')) continue;
|
|
42
42
|
try {
|
|
43
43
|
jobs.push(JSON.parse(readFileSync(join(dir, name), 'utf8')));
|
|
44
|
-
} catch {
|
|
44
|
+
} catch (error) {
|
|
45
|
+
// 静默跳过会让「job 幽灵消失」无从排查:坏文件保留在盘上并留一行警告。
|
|
46
|
+
console.warn(`[skillopt] skipping unreadable job file ${name}: ${error?.message ?? error}`);
|
|
47
|
+
}
|
|
45
48
|
}
|
|
46
49
|
return jobs.sort((a, b) => (a.createdAt ?? 0) - (b.createdAt ?? 0));
|
|
47
50
|
}
|
package/lib/skillopt/judge.js
CHANGED
|
@@ -53,19 +53,44 @@ export function buildPairPrompt({ before, after, order }) {
|
|
|
53
53
|
*/
|
|
54
54
|
export function parseJudgeOutput(output) {
|
|
55
55
|
const text = typeof output === 'string' ? output : '';
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
// 逐个尝试文本里的 JSON 对象:模板回显/前置示例会让第一个 `{...}` 不是结论,
|
|
57
|
+
// 只解析第一处会在合规输出上直接判 null(等于丢掉这一票)。
|
|
58
|
+
const readObjectAt = (start) => {
|
|
59
|
+
let depth = 0;
|
|
60
|
+
let inString = false;
|
|
61
|
+
let escaped = false;
|
|
62
|
+
for (let index = start; index < text.length; index += 1) {
|
|
63
|
+
const char = text[index];
|
|
64
|
+
if (inString) {
|
|
65
|
+
if (escaped) escaped = false;
|
|
66
|
+
else if (char === '\\') escaped = true;
|
|
67
|
+
else if (char === '"') inString = false;
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (char === '"') { inString = true; continue; }
|
|
71
|
+
if (char === '{') depth += 1;
|
|
72
|
+
else if (char === '}') {
|
|
73
|
+
depth -= 1;
|
|
74
|
+
if (depth === 0) return text.slice(start, index + 1);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return null;
|
|
78
|
+
};
|
|
79
|
+
let found = null;
|
|
80
|
+
for (let at = text.indexOf('{'), attempts = 0; at !== -1 && attempts < 20; at = text.indexOf('{', at + 1), attempts += 1) {
|
|
81
|
+
const candidate = readObjectAt(at);
|
|
82
|
+
if (candidate === null) continue;
|
|
83
|
+
let row;
|
|
84
|
+
try { row = JSON.parse(candidate); } catch { continue; }
|
|
85
|
+
if (row?.better !== 'A' && row?.better !== 'B' && row?.better !== 'tie') continue;
|
|
86
|
+
// 取**最后**一个合法结论:模型常先回显模板或示例,真正的判决写在末尾。
|
|
87
|
+
found = {
|
|
62
88
|
better: row.better,
|
|
63
89
|
margin: row.margin === 'clear' ? 'clear' : 'slight',
|
|
64
90
|
reason: typeof row.reason === 'string' ? row.reason.slice(0, 300) : '',
|
|
65
91
|
};
|
|
66
|
-
} catch {
|
|
67
|
-
return null;
|
|
68
92
|
}
|
|
93
|
+
return found;
|
|
69
94
|
}
|
|
70
95
|
|
|
71
96
|
/**
|
|
@@ -84,16 +109,25 @@ export function voteFromParsed(parsed) {
|
|
|
84
109
|
/**
|
|
85
110
|
* 多数决:keep 当且仅当 better ≥ worse(含 tie)——与 darwin Phase 2 Step 5 一致。
|
|
86
111
|
* 无效投票(null)不计数;全部无效时判 'inconclusive'(不得据此 adopt)。
|
|
112
|
+
*
|
|
113
|
+
* 有效票**必须过半**:3 票里只剩 1 票 better、另 2 票超时/不可解析时,1-0
|
|
114
|
+
* 也是「better ≥ worse」,会把一次几乎没验成的改动判成 keep。
|
|
87
115
|
* @param {Array<'better'|'worse'|'tie'|null>} votes
|
|
88
|
-
* @
|
|
116
|
+
* @param {{minValid?: number}} [options]
|
|
117
|
+
* @returns {{verdict: 'keep'|'revert'|'inconclusive', better:number, worse:number, ties:number, valid:number, required:number}}
|
|
89
118
|
*/
|
|
90
|
-
export function decideByMajority(votes) {
|
|
119
|
+
export function decideByMajority(votes, options = {}) {
|
|
91
120
|
const valid = votes.filter((vote) => vote === 'better' || vote === 'worse' || vote === 'tie');
|
|
92
121
|
const better = valid.filter((vote) => vote === 'better').length;
|
|
93
122
|
const worse = valid.filter((vote) => vote === 'worse').length;
|
|
94
123
|
const ties = valid.filter((vote) => vote === 'tie').length;
|
|
95
|
-
|
|
96
|
-
|
|
124
|
+
// 默认要求 ceil(n/2):3 票至少 2 票有效、5 票至少 3 票有效。
|
|
125
|
+
const required = Number.isSafeInteger(options.minValid)
|
|
126
|
+
? Math.max(1, options.minValid)
|
|
127
|
+
: Math.max(1, Math.ceil(Array.isArray(votes) ? votes.length / 2 : 1));
|
|
128
|
+
if (valid.length === 0) return { verdict: 'inconclusive', better, worse, ties, valid: 0, required };
|
|
129
|
+
if (valid.length < required) return { verdict: 'inconclusive', better, worse, ties, valid: valid.length, required };
|
|
130
|
+
return { verdict: better >= worse ? 'keep' : 'revert', better, worse, ties, valid: valid.length, required };
|
|
97
131
|
}
|
|
98
132
|
|
|
99
133
|
/** 校验投票数:奇数且 ≥3(close call 可升 5)。 */
|
|
@@ -6,6 +6,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync, copyFileSync } from
|
|
|
6
6
|
import { dirname, join } from 'node:path';
|
|
7
7
|
import { runEngineCli, quoteArgv } from './gate-wiring.js';
|
|
8
8
|
import { awaitActivationText } from './subagent-text.js';
|
|
9
|
+
import { sha12 } from './proposal-store.js';
|
|
9
10
|
|
|
10
11
|
/** 项目是否为干净 git 仓库(决定 git 棘轮还是文件备份)。 */
|
|
11
12
|
async function isCleanGitRepo(shell, cwd) {
|
|
@@ -91,10 +92,13 @@ export function makeGenerator({ subagents, ensureParent, providerName, cwd }) {
|
|
|
91
92
|
}
|
|
92
93
|
|
|
93
94
|
/**
|
|
94
|
-
* 同步判据:results.tsv 中该 skill 的**最后一条**记录是否为 paired keep
|
|
95
|
-
*
|
|
95
|
+
* 同步判据:results.tsv 中该 skill 的**最后一条**记录是否为 paired keep,
|
|
96
|
+
* 且该记录的内容指纹必须等于当前 staging 候选。
|
|
97
|
+
*
|
|
98
|
+
* 只查「最后一条是 keep」会让任意一次旧 keep 解锁任意新提案(adopt 门形同虚设),
|
|
99
|
+
* 因此第 10 列记录候选的 sha12,比对不上就按「未验证」拒绝。
|
|
96
100
|
*/
|
|
97
|
-
export function hasPairedKeepRecord(projectDir, skillPath) {
|
|
101
|
+
export function hasPairedKeepRecord(projectDir, skillPath, candidateText) {
|
|
98
102
|
const name = typeof skillPath === 'string' && skillPath !== ''
|
|
99
103
|
? skillPath.split(/[\\/]/).slice(-2, -1)[0]
|
|
100
104
|
: null;
|
|
@@ -104,7 +108,9 @@ export function hasPairedKeepRecord(projectDir, skillPath) {
|
|
|
104
108
|
const rows = lines.map((line) => line.split('\t')).filter((cells) => name === null || cells[2] === name);
|
|
105
109
|
const last = rows.at(-1);
|
|
106
110
|
if (last === undefined) return false;
|
|
107
|
-
|
|
111
|
+
if (last[5] !== 'keep' || last[8] !== 'paired') return false;
|
|
112
|
+
if (typeof candidateText !== 'string') return false;
|
|
113
|
+
return last[9] === sha12(candidateText);
|
|
108
114
|
}
|
|
109
115
|
|
|
110
116
|
/** results.tsv 追加(表头自动补)。 */
|
|
@@ -113,8 +119,8 @@ export function makeResultAppender({ projectDir }) {
|
|
|
113
119
|
const path = join(dir, 'results.tsv');
|
|
114
120
|
return async (line) => {
|
|
115
121
|
mkdirSync(dir, { recursive: true });
|
|
116
|
-
const header = ['timestamp', 'commit', 'skill', 'old_score', 'new_score', 'status', 'dimension', 'note', 'eval_mode'].join('\t');
|
|
117
|
-
const prefix = existsSync(path) && readFileSync(path, 'utf8').includes('
|
|
122
|
+
const header = ['timestamp', 'commit', 'skill', 'old_score', 'new_score', 'status', 'dimension', 'note', 'eval_mode', 'proposal_sha'].join('\t');
|
|
123
|
+
const prefix = existsSync(path) && readFileSync(path, 'utf8').includes('proposal_sha') ? '' : header + '\n';
|
|
118
124
|
writeFileSync(path, prefix + line + '\n', { encoding: 'utf8', flag: 'a' });
|
|
119
125
|
};
|
|
120
126
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 提案落盘的共用原语:内容指纹、live 文件备份、原子替换。
|
|
3
|
+
*
|
|
4
|
+
* 三者必须一起用:先按 sha 判断 live 是否仍是评审时的基线(并发冲突),再备份,
|
|
5
|
+
* 最后用 tmp + rename 原子替换。缺任一步都会出现「评审期间的人工修改被静默覆盖」
|
|
6
|
+
* 或「写到一半崩溃留下半截 SKILL.md」。
|
|
7
|
+
*/
|
|
8
|
+
import { createHash } from 'node:crypto';
|
|
9
|
+
import { mkdirSync, renameSync, writeFileSync } from 'node:fs';
|
|
10
|
+
import { join } from 'node:path';
|
|
11
|
+
|
|
12
|
+
/** 12 位内容指纹:足够区分提案版本,又能塞进 results.tsv 的一列。 */
|
|
13
|
+
export function sha12(text) {
|
|
14
|
+
return createHash('sha256').update(String(text ?? ''), 'utf8').digest('hex').slice(0, 12);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** 备份 live 文本到 `.skillopt-sleep/backups/`,返回备份路径。 */
|
|
18
|
+
export function backupLive({ projectDir, skillPath, text, now = Date.now() }) {
|
|
19
|
+
const dir = join(projectDir, '.skillopt-sleep', 'backups');
|
|
20
|
+
mkdirSync(dir, { recursive: true });
|
|
21
|
+
const stamp = new Date(now).toISOString().replace(/[:.]/g, '-');
|
|
22
|
+
const name = String(skillPath).split(/[\\/]/).pop() ?? 'SKILL.md';
|
|
23
|
+
const target = join(dir, `${name}.${stamp}.bak`);
|
|
24
|
+
writeFileSync(target, String(text ?? ''), 'utf8');
|
|
25
|
+
return target;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** 同目录 tmp + rename,避免半截写入。 */
|
|
29
|
+
export function applyLiveAtomically(path, text) {
|
|
30
|
+
const tmp = `${path}.tmp-${process.pid.toString(36)}-${Date.now().toString(36)}`;
|
|
31
|
+
writeFileSync(tmp, String(text ?? ''), 'utf8');
|
|
32
|
+
renameSync(tmp, path);
|
|
33
|
+
}
|
|
@@ -52,14 +52,17 @@ export async function startReview({ service, projectRuntime, job, actor, votes }
|
|
|
52
52
|
const orders = [];
|
|
53
53
|
for (let index = 0; index < count; index++) {
|
|
54
54
|
const order = Math.random() < 0.5 ? 'ab' : 'ba';
|
|
55
|
-
|
|
55
|
+
// 每一票带独立 orderId:投递顺序与回帖顺序无关,靠 id 才能把票对应回
|
|
56
|
+
// 该票的 A/B 顺序;否则一次乱序/重复回帖就会整票移位甚至反转 keep/revert。
|
|
57
|
+
const orderId = `v${index + 1}`;
|
|
58
|
+
const body = buildReviewRequest({ before: job.before, after: job.candidate, order, jobId: job.id, taskId: reviewTaskId, baseSeq: 0, orderId });
|
|
56
59
|
await service.dispatch({
|
|
57
60
|
type: 'member.message',
|
|
58
61
|
payload: { memberId: reviewer.id, body },
|
|
59
62
|
actor,
|
|
60
63
|
projectId: projectRuntime.id,
|
|
61
64
|
});
|
|
62
|
-
orders.push({ order, aIsAfter: order === 'ba' });
|
|
65
|
+
orders.push({ orderId, order, aIsAfter: order === 'ba' });
|
|
63
66
|
}
|
|
64
67
|
return { reviewTaskId, reviewerId: reviewer.id, orders };
|
|
65
68
|
}
|
|
@@ -70,8 +73,11 @@ export function collectReview({ service, job }) {
|
|
|
70
73
|
const entries = Array.isArray(thread?.entries) ? thread.entries : [];
|
|
71
74
|
const reviewerId = job.reviewerId;
|
|
72
75
|
const orders = Array.isArray(job.reviewOrders) ? job.reviewOrders : [];
|
|
76
|
+
const byOrderId = new Map(orders.filter((order) => typeof order?.orderId === 'string').map((order) => [order.orderId, order]));
|
|
77
|
+
const used = new Set();
|
|
73
78
|
const votes = [];
|
|
74
79
|
for (const entry of entries) {
|
|
80
|
+
if (votes.length >= orders.length) break;
|
|
75
81
|
if (entry?.authorId !== reviewerId) continue;
|
|
76
82
|
const parsed = (() => {
|
|
77
83
|
try {
|
|
@@ -82,7 +88,15 @@ export function collectReview({ service, job }) {
|
|
|
82
88
|
}
|
|
83
89
|
})();
|
|
84
90
|
if (parsed === null || (parsed.better !== 'A' && parsed.better !== 'B' && parsed.better !== 'tie')) continue;
|
|
85
|
-
|
|
91
|
+
let order = typeof parsed.orderId === 'string' ? byOrderId.get(parsed.orderId) : undefined;
|
|
92
|
+
// 旧 job 的 orders 没有 orderId:保留按序对齐的兼容路径,但仍受票数上限约束。
|
|
93
|
+
if (order === undefined && typeof parsed.orderId !== 'string' && byOrderId.size === 0) {
|
|
94
|
+
order = orders[votes.length];
|
|
95
|
+
}
|
|
96
|
+
if (order === undefined) continue;
|
|
97
|
+
const key = order.orderId ?? `#${votes.length}`;
|
|
98
|
+
if (used.has(key)) continue; // 同一票重复回帖只计一次
|
|
99
|
+
used.add(key);
|
|
86
100
|
votes.push({
|
|
87
101
|
better: parsed.better,
|
|
88
102
|
margin: parsed.margin === 'clear' ? 'clear' : 'slight',
|
package/lib/skillopt/reviewer.js
CHANGED
|
@@ -13,12 +13,12 @@ export const REVIEWER_ROLE = '评审';
|
|
|
13
13
|
export const REVIEWER_NAME = '评审官';
|
|
14
14
|
|
|
15
15
|
/** 评审 prompt(盲评两版,输出一行 JSON)。 */
|
|
16
|
-
export function buildReviewRequest({ before, after, order, jobId, taskId, baseSeq = 0 }) {
|
|
16
|
+
export function buildReviewRequest({ before, after, order, jobId, taskId, baseSeq = 0, orderId = 'v1' }) {
|
|
17
17
|
const aIsAfter = order === 'ba';
|
|
18
18
|
const versionA = aIsAfter ? after : before;
|
|
19
19
|
const versionB = aIsAfter ? before : after;
|
|
20
20
|
const card = typeof taskId === 'string' && taskId !== '' ? taskId : '<taskId>';
|
|
21
|
-
const verdict =
|
|
21
|
+
const verdict = `{"orderId":"${orderId}","better":"A","margin":"clear","reason":"一句话理由"}`;
|
|
22
22
|
return [
|
|
23
23
|
`【技能盲评 ${jobId}】你是独立评审。只做比较,不要修改任何文件。`,
|
|
24
24
|
'',
|
|
@@ -35,9 +35,9 @@ export function buildReviewRequest({ before, after, order, jobId, taskId, baseSe
|
|
|
35
35
|
'## 如何提交结论(必须用 team 工具,两步)',
|
|
36
36
|
'1) 读取评审卡当前 headSeq:调用 team 工具',
|
|
37
37
|
` {"action":"thread","taskId":"${card}"}`,
|
|
38
|
-
'2) 用拿到的 headSeq 回帖(body 里只放一行 JSON
|
|
38
|
+
'2) 用拿到的 headSeq 回帖(body 里只放一行 JSON,**必须原样带上 orderId**):',
|
|
39
39
|
` {"action":"reply","taskId":"${card}","baseSeq":${baseSeq},"body":"${verdict.replace(/"/g, '\\"')}"}`,
|
|
40
|
-
`注意:action 必须是 "reply"(不是 thread.post),参数名是 taskId / baseSeq / body
|
|
40
|
+
`注意:action 必须是 "reply"(不是 thread.post),参数名是 taskId / baseSeq / body;body 里的 orderId 必须是 "${orderId}",插件靠它把这一票对应到 A/B 顺序,缺了就无法计票。初始 baseSeq 通常为 ${baseSeq},若第 1 步返回的 headSeq 不同,用返回的 headSeq。`,
|
|
41
41
|
'除这次 team 回帖外不要做其它动作。',
|
|
42
42
|
].join('\n');
|
|
43
43
|
}
|
package/lib/skillopt/rubric.js
CHANGED
|
@@ -55,7 +55,8 @@ const countMatches = (text, patterns) => patterns.reduce((total, pattern) => tot
|
|
|
55
55
|
*/
|
|
56
56
|
export function scoreSkillRubric(text, options = {}) {
|
|
57
57
|
const source = typeof text === 'string' ? text : '';
|
|
58
|
-
|
|
58
|
+
// NaN/Infinity 会穿透 clampScore(Math.min/max 对 NaN 返回 NaN)→ 总分变 NaN。
|
|
59
|
+
const dim8 = Number.isFinite(options.dim8) ? clampScore(options.dim8) : 5;
|
|
59
60
|
const evidence = [];
|
|
60
61
|
const scores = new Map();
|
|
61
62
|
|
|
@@ -110,13 +111,21 @@ export function scoreSkillRubric(text, options = {}) {
|
|
|
110
111
|
evidence.push(`dim5 softWords=${soft} concreteHints=${concrete}`);
|
|
111
112
|
}
|
|
112
113
|
|
|
113
|
-
// dim6 资源整合度:references/scripts/assets
|
|
114
|
+
// dim6 资源整合度:references/scripts/assets 引用是否真的可达
|
|
114
115
|
{
|
|
115
116
|
const refs = (source.match(/(references|scripts|assets)\/[^\s)`"']+/g) ?? []).length;
|
|
116
|
-
|
|
117
|
-
|
|
117
|
+
// 没给 resourcePaths 时**不能**把「引用数」当成「可达数」:那会让任何
|
|
118
|
+
// 含 references/ 的文本恒得 9 分(自证可达)。没有可达清单时按「未验证」
|
|
119
|
+
// 走中性分,并在证据里标注。
|
|
120
|
+
const hasKnown = Array.isArray(options.resourcePaths);
|
|
121
|
+
const known = hasKnown ? options.resourcePaths.length : 0;
|
|
122
|
+
const score = refs === 0
|
|
123
|
+
? (hasKnown ? 6 : 5)
|
|
124
|
+
: hasKnown
|
|
125
|
+
? (known >= refs ? 9 : 6)
|
|
126
|
+
: 6;
|
|
118
127
|
scores.set(6, clampScore(score));
|
|
119
|
-
evidence.push(`dim6 resource refs=${refs} reachable=${known}`);
|
|
128
|
+
evidence.push(`dim6 resource refs=${refs} reachable=${hasKnown ? known : 'unverified'}`);
|
|
120
129
|
}
|
|
121
130
|
|
|
122
131
|
// dim7 整体架构:层级 + 冗余扣分
|
|
@@ -158,10 +167,15 @@ export function scoreSkillRubric(text, options = {}) {
|
|
|
158
167
|
/** 输出可读的 triage 摘要(工具返回值用纯文本时)。 */
|
|
159
168
|
export function formatRubric(result) {
|
|
160
169
|
const rows = result.dimensions.map((dimension) => ` dim${dimension.id} ${dimension.name.padEnd(12)} ${String(dimension.score).padStart(2)}/10 ×${String(dimension.weight).padStart(2)} ${dimension.evidence}`);
|
|
170
|
+
// weakest 必须与 weakestDimension 同口径:dim8 是实测表现,不能靠静态改写
|
|
171
|
+
// 提升,混进来会把优化目标指向一个改不动的维度。
|
|
172
|
+
const editable = result.dimensions.filter((dimension) => dimension.id !== 8);
|
|
173
|
+
const weakest = (editable.length > 0 ? editable : result.dimensions)
|
|
174
|
+
.reduce((worst, dimension) => (dimension.weight * (10 - dimension.score) > worst.weight * (10 - worst.score) ? dimension : worst));
|
|
161
175
|
return [
|
|
162
176
|
`[skillopt rubric] total=${result.total}/100${result.evaluated ? '' : ' (dim8 dry-run: NOT a measured effect score)'}`,
|
|
163
177
|
' ⚠️ absolute totals are TRIAGE-ONLY; keep/revert must use paired judge majority',
|
|
164
178
|
...rows,
|
|
165
|
-
` weakest dim: ${
|
|
179
|
+
` weakest dim: ${weakest.name}`,
|
|
166
180
|
].join('\n');
|
|
167
181
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SkillOpt 工具的调用者授权。
|
|
3
|
+
*
|
|
4
|
+
* 这批工具由插件在**全局**工具表注册(`tools.register` 无 scope),因此进程内任何
|
|
5
|
+
* agent 都能看到并调用:`skillopt_adopt` 会写 live `SKILL.md`,`skillopt_schedule`
|
|
6
|
+
* 会装系统 cron。一次性 worker 子代理(judge/generator 等)不该拥有这种权力,否则
|
|
7
|
+
* 一个被喂进恶意工单的子代理就能静默改技能。
|
|
8
|
+
*
|
|
9
|
+
* 允许的两类调用者:
|
|
10
|
+
* 1. Team 成员(`runtimeForAgent(id) !== null`)——它们在团队运行时有明确职责;
|
|
11
|
+
* 2. Human 面对根会话(`session.header.origin !== 'subagent'`)。
|
|
12
|
+
* 其余(delegated subagent)一律拒绝,并把拒绝写成工具结果而不是异常。
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** 会改动 live 文件 / 系统状态 / 消耗评审预算的工具。 */
|
|
16
|
+
export const GUARDED_SKILLOPT_TOOLS = Object.freeze(new Set([
|
|
17
|
+
'skillopt_run',
|
|
18
|
+
'skillopt_adopt',
|
|
19
|
+
'skillopt_schedule',
|
|
20
|
+
'skillopt_unschedule',
|
|
21
|
+
'skillopt_optimize',
|
|
22
|
+
'skillopt_jobs',
|
|
23
|
+
'skillopt_judge',
|
|
24
|
+
]));
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param {object} tools ctx.get('tools')
|
|
28
|
+
* @param {(exec: object|undefined) => boolean} isAllowed
|
|
29
|
+
* @returns {object} 供 applySkillOpt 使用的 tools 代理
|
|
30
|
+
*/
|
|
31
|
+
export function wrapToolsWithSkilloptAccess(tools, isAllowed) {
|
|
32
|
+
if (tools === null || tools === undefined || typeof tools.register !== 'function') return tools;
|
|
33
|
+
return {
|
|
34
|
+
...tools,
|
|
35
|
+
register(definition, options) {
|
|
36
|
+
if (!GUARDED_SKILLOPT_TOOLS.has(definition?.name)) return tools.register(definition, options);
|
|
37
|
+
const originalExecute = definition.execute;
|
|
38
|
+
const guarded = {
|
|
39
|
+
...definition,
|
|
40
|
+
async execute(args, exec) {
|
|
41
|
+
let allowed = false;
|
|
42
|
+
try {
|
|
43
|
+
allowed = isAllowed(exec) === true;
|
|
44
|
+
} catch {
|
|
45
|
+
allowed = false;
|
|
46
|
+
}
|
|
47
|
+
if (!allowed) {
|
|
48
|
+
return `[skillopt ${String(definition.name).replace(/^skillopt_/, '')}] refusing: this tool mutates live files or the host schedule and is limited to Team members and Human-facing sessions`;
|
|
49
|
+
}
|
|
50
|
+
return originalExecute.call(definition, args, exec);
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
return tools.register(guarded, options);
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
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.28",
|
|
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",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"icon.svg",
|
|
45
45
|
"locale/*.json",
|
|
46
46
|
"lib/**/*.js",
|
|
47
|
-
"lib/vendor/skillopt/scripts
|
|
48
|
-
"lib/vendor/skillopt/skillopt_sleep
|
|
47
|
+
"lib/vendor/skillopt/scripts/*.py",
|
|
48
|
+
"lib/vendor/skillopt/skillopt_sleep/**/*.py",
|
|
49
49
|
"lib/vendor/skillopt/requirements.txt",
|
|
50
50
|
"lib/vendor/skillopt/LICENSE",
|
|
51
51
|
"skills/**/*",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|