@miphamai/cli 0.85.40 → 0.85.41
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/README.md +1 -1
- package/package.json +1 -1
- package/src/core/capture-measure.ts +142 -0
- package/src/core/capture-rate.ts +149 -0
- package/src/core/crsi-modify.ts +50 -2
- package/src/core/crsi-sandbox.ts +9 -3
- package/src/core/improvement-track.ts +7 -2
- package/src/core/instructions.ts +22 -10
- package/src/core/probation.ts +171 -0
- package/src/core/reward-fn.ts +9 -1
- package/src/core/task-performance-tasks.json +100 -7
- package/src/core/task-performance.ts +78 -8
- package/src/shared/package-info.ts +2 -2
- package/src/ui/commands.ts +171 -4
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Mipham Code v0.85.
|
|
1
|
+
# Mipham Code v0.85.41
|
|
2
2
|
|
|
3
3
|
**Multi-model open-core intelligent coding terminal** — 12 AI providers, 139 commands, 31 tools, 28 skills + marketplace, self-update. AI-assisted code generation, security auditing, MCP protocol, and extensible skills — in a single CLI.
|
|
4
4
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 捕获率的编排层(有 LLM 调用、有子进程判定),算术全在 `capture-rate.ts`。
|
|
3
|
+
*
|
|
4
|
+
* 三臂:`off`(不注入)· `on`(注入被测 skill 文本)· `oracle`(手写参考解,
|
|
5
|
+
* **零 LLM 调用**,本地跑该题的冻结测试)。sealed 只作为**旁证读数**给出,
|
|
6
|
+
* 永不进入任何裁定。
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { Llm } from '../providers/llm'
|
|
10
|
+
import {
|
|
11
|
+
judgeGeneratedCode,
|
|
12
|
+
loadPerformanceTasks,
|
|
13
|
+
runTaskPerformance,
|
|
14
|
+
type PerformanceTask,
|
|
15
|
+
type TaskPerformanceReport,
|
|
16
|
+
} from './task-performance'
|
|
17
|
+
import { computeCapture, perTaskValue, type CaptureResult } from './capture-rate'
|
|
18
|
+
|
|
19
|
+
export interface CaptureMeasurement {
|
|
20
|
+
/** k 次 off 运行(不注入)。 */
|
|
21
|
+
off: TaskPerformanceReport[]
|
|
22
|
+
/** k 次 on 运行(注入 skillText)。 */
|
|
23
|
+
on: TaskPerformanceReport[]
|
|
24
|
+
capture: CaptureResult
|
|
25
|
+
/** 参考解是否全部通过自己的冻结测试。false ⇒ 上界不可信,整轮作废。 */
|
|
26
|
+
oraclePassed: boolean
|
|
27
|
+
/**
|
|
28
|
+
* 正对照:把**同一臂**的读数喂给两侧,捕获率必须恰好为 0。
|
|
29
|
+
* 不为 0 ⇒ 分子/分母/臂映射至少有一处接错了,整轮的其它读数都不可信。
|
|
30
|
+
*/
|
|
31
|
+
controlRate: number | null
|
|
32
|
+
/** sealed 池的同一套测量。每组只有 1 题,故它只是过拟合旁证,不是第二读数。 */
|
|
33
|
+
sealed: { capture: CaptureResult; oraclePassed: boolean }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface Arms {
|
|
37
|
+
off: TaskPerformanceReport[]
|
|
38
|
+
on: TaskPerformanceReport[]
|
|
39
|
+
capture: CaptureResult
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function runArms(
|
|
43
|
+
llm: Llm,
|
|
44
|
+
tasks: PerformanceTask[],
|
|
45
|
+
skillText: string,
|
|
46
|
+
k: number,
|
|
47
|
+
timeoutMs?: number,
|
|
48
|
+
): Promise<Arms> {
|
|
49
|
+
const off: TaskPerformanceReport[] = []
|
|
50
|
+
const on: TaskPerformanceReport[] = []
|
|
51
|
+
const timeout = timeoutMs ? { timeoutMs } : {}
|
|
52
|
+
for (let i = 0; i < k; i++) off.push(await runTaskPerformance(llm, { tasks, ...timeout }))
|
|
53
|
+
for (let i = 0; i < k; i++) {
|
|
54
|
+
on.push(await runTaskPerformance(llm, { tasks, skillText, ...timeout }))
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const toArm = (values: Map<string, number | null>) =>
|
|
58
|
+
[...values].map(([taskId, value]) => ({ taskId, value }))
|
|
59
|
+
|
|
60
|
+
const capture = computeCapture({
|
|
61
|
+
off: toArm(
|
|
62
|
+
perTaskValue(
|
|
63
|
+
off.flatMap((r) => r.results),
|
|
64
|
+
k,
|
|
65
|
+
),
|
|
66
|
+
),
|
|
67
|
+
on: toArm(
|
|
68
|
+
perTaskValue(
|
|
69
|
+
on.flatMap((r) => r.results),
|
|
70
|
+
k,
|
|
71
|
+
),
|
|
72
|
+
),
|
|
73
|
+
total: tasks.length,
|
|
74
|
+
})
|
|
75
|
+
return { off, on, capture }
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export async function measureCapture(
|
|
79
|
+
llm: Llm,
|
|
80
|
+
opts: { skillName: string; skillText: string; k?: number; timeoutMs?: number },
|
|
81
|
+
): Promise<CaptureMeasurement> {
|
|
82
|
+
const k = opts.k ?? 3
|
|
83
|
+
const all = loadPerformanceTasks({ pool: 'all' })
|
|
84
|
+
const gateTasks = all.filter((t) => t.skill === opts.skillName && t.split === 'gate')
|
|
85
|
+
const sealedTasks = all.filter((t) => t.skill === opts.skillName && t.split === 'sealed')
|
|
86
|
+
|
|
87
|
+
const gate = await runArms(llm, gateTasks, opts.skillText, k, opts.timeoutMs)
|
|
88
|
+
const sealed = await runArms(llm, sealedTasks, opts.skillText, k, opts.timeoutMs)
|
|
89
|
+
|
|
90
|
+
// 正对照:同一臂两侧相等 ⇒ 率必须为 0。零成本,且能抓到臂接反/池映射错。
|
|
91
|
+
// 取 **off 臂**:它的 headroom 正是真实率的分母,故真实率非 null 时这里必然也可算
|
|
92
|
+
// (off 全满分的轮次本来就没有率,不需要另立一条「对照失效」的判据)。
|
|
93
|
+
const offArm = [
|
|
94
|
+
...perTaskValue(
|
|
95
|
+
gate.off.flatMap((r) => r.results),
|
|
96
|
+
k,
|
|
97
|
+
),
|
|
98
|
+
].map(([taskId, value]) => ({
|
|
99
|
+
taskId,
|
|
100
|
+
value,
|
|
101
|
+
}))
|
|
102
|
+
const control = computeCapture({ off: offArm, on: offArm, total: gateTasks.length })
|
|
103
|
+
|
|
104
|
+
const oraclePassed = gateTasks.every((t) => judgeGeneratedCode(t.testCode, t.oracleCode).passed)
|
|
105
|
+
const sealedOraclePassed = sealedTasks.every(
|
|
106
|
+
(t) => judgeGeneratedCode(t.testCode, t.oracleCode).passed,
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
return {
|
|
110
|
+
off: gate.off,
|
|
111
|
+
on: gate.on,
|
|
112
|
+
capture: gate.capture,
|
|
113
|
+
oraclePassed,
|
|
114
|
+
controlRate: control.rate,
|
|
115
|
+
sealed: { capture: sealed.capture, oraclePassed: sealedOraclePassed },
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface SealedMeasurement {
|
|
120
|
+
off: TaskPerformanceReport[]
|
|
121
|
+
on: TaskPerformanceReport[]
|
|
122
|
+
capture: CaptureResult
|
|
123
|
+
/** 参考解是否全过自己的冻结测试。false ⇒ 读数不可信。 */
|
|
124
|
+
oraclePassed: boolean
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* 只跑 sealed 池的独立读面(`/crsi bench --sealed`,设计 §4.3)。
|
|
129
|
+
*
|
|
130
|
+
* 它比 `--capture` 便宜(不跑 gate 臂),答的是同一个问题的一半:这份 skill 在
|
|
131
|
+
* **没参与调参**的题上还吃得到多少。缺省 k=1 —— 它出的不是裁定数,是旁证数。
|
|
132
|
+
*/
|
|
133
|
+
export async function measureSealed(
|
|
134
|
+
llm: Llm,
|
|
135
|
+
opts: { skillName: string; skillText: string; k?: number; timeoutMs?: number },
|
|
136
|
+
): Promise<SealedMeasurement> {
|
|
137
|
+
const k = opts.k ?? 1
|
|
138
|
+
const tasks = loadPerformanceTasks({ pool: 'sealed' }).filter((t) => t.skill === opts.skillName)
|
|
139
|
+
const arms = await runArms(llm, tasks, opts.skillText, k, opts.timeoutMs)
|
|
140
|
+
const oraclePassed = tasks.every((t) => judgeGeneratedCode(t.testCode, t.oracleCode).passed)
|
|
141
|
+
return { off: arms.off, on: arms.on, capture: arms.capture, oraclePassed }
|
|
142
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 捕获率:`(on − off) / (100 − off)` —— 自动改进捕获了「满分上界」的百分之几。
|
|
3
|
+
*
|
|
4
|
+
* 纯算术,无 LLM、无 I/O:题与样本由调用方给。设计约束见
|
|
5
|
+
* `docs/superpowers/specs/2026-11-20-crsi-eval-governance-design.md` §4.2:
|
|
6
|
+
* - headroom `100 − off` 不为正的题 **剔除**(分母不许注水);
|
|
7
|
+
* - 任一侧无合格样本的题 **配对剔除**(不拿半份样本凑数);
|
|
8
|
+
* - 题全被剔除 ⇒ **没有率**(`null`),不是 0,也不是 1。
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export interface ArmValue {
|
|
12
|
+
taskId: string
|
|
13
|
+
/** 该题在该臂上的 0–100 读数;`null` = 没有合格样本。 */
|
|
14
|
+
value: number | null
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface CaptureInput {
|
|
18
|
+
off: ArmValue[]
|
|
19
|
+
on: ArmValue[]
|
|
20
|
+
/** 组内题数 M(含被剔除的),用于报告 "over N of M tasks"。 */
|
|
21
|
+
total: number
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface CaptureResult {
|
|
25
|
+
numerator: number
|
|
26
|
+
denominator: number
|
|
27
|
+
rate: number | null
|
|
28
|
+
tasksUsed: number
|
|
29
|
+
tasksTotal: number
|
|
30
|
+
noHeadroom: string[]
|
|
31
|
+
dropped: string[]
|
|
32
|
+
ci: { lo: number; hi: number } | null
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** 每题每臂的 0–100 读数。合格样本不足 k 次 ⇒ `null`(配对剔除的一半)。 */
|
|
36
|
+
export function perTaskValue(
|
|
37
|
+
results: { id: string; passed: boolean; truncated?: boolean; uncertain?: boolean }[],
|
|
38
|
+
k: number,
|
|
39
|
+
): Map<string, number | null> {
|
|
40
|
+
const acc = new Map<string, { pass: number; usable: number }>()
|
|
41
|
+
for (const r of results) {
|
|
42
|
+
const entry = acc.get(r.id) ?? { pass: 0, usable: 0 }
|
|
43
|
+
if (!r.truncated && !r.uncertain) {
|
|
44
|
+
entry.usable++
|
|
45
|
+
if (r.passed) entry.pass++
|
|
46
|
+
}
|
|
47
|
+
acc.set(r.id, entry)
|
|
48
|
+
}
|
|
49
|
+
const out = new Map<string, number | null>()
|
|
50
|
+
for (const [id, entry] of acc) {
|
|
51
|
+
out.set(id, entry.usable === k ? (entry.pass / entry.usable) * 100 : null)
|
|
52
|
+
}
|
|
53
|
+
return out
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function mulberry32(seed: number): () => number {
|
|
57
|
+
let a = seed
|
|
58
|
+
return () => {
|
|
59
|
+
a += 0x6d2b79f5
|
|
60
|
+
let t = a
|
|
61
|
+
t = Math.imul(t ^ (t >>> 15), t | 1)
|
|
62
|
+
t ^= t + Math.imul(t ^ (t >>> 7), t | 61)
|
|
63
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function quantile(sorted: number[], q: number): number {
|
|
68
|
+
const pos = (sorted.length - 1) * q
|
|
69
|
+
const lo = Math.floor(pos)
|
|
70
|
+
const hi = Math.ceil(pos)
|
|
71
|
+
if (lo === hi) return sorted[lo]!
|
|
72
|
+
return sorted[lo]! + (sorted[hi]! - sorted[lo]!) * (pos - lo)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function computeCapture(
|
|
76
|
+
input: CaptureInput,
|
|
77
|
+
opts?: { resamples?: number; seed?: number },
|
|
78
|
+
): CaptureResult {
|
|
79
|
+
const onById = new Map(input.on.map((v) => [v.taskId, v.value]))
|
|
80
|
+
const noHeadroom: string[] = []
|
|
81
|
+
const dropped: string[] = []
|
|
82
|
+
const pairs: { off: number; on: number }[] = []
|
|
83
|
+
|
|
84
|
+
for (const o of input.off) {
|
|
85
|
+
const onValue = onById.get(o.taskId) ?? null
|
|
86
|
+
if (o.value === null || onValue === null) {
|
|
87
|
+
dropped.push(o.taskId)
|
|
88
|
+
continue
|
|
89
|
+
}
|
|
90
|
+
if (100 - o.value <= 0) {
|
|
91
|
+
noHeadroom.push(o.taskId)
|
|
92
|
+
continue
|
|
93
|
+
}
|
|
94
|
+
pairs.push({ off: o.value, on: onValue })
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
let numerator = 0
|
|
98
|
+
let denominator = 0
|
|
99
|
+
for (const p of pairs) {
|
|
100
|
+
numerator += p.on - p.off
|
|
101
|
+
denominator += 100 - p.off
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (denominator === 0) {
|
|
105
|
+
return {
|
|
106
|
+
numerator,
|
|
107
|
+
denominator,
|
|
108
|
+
rate: null,
|
|
109
|
+
tasksUsed: 0,
|
|
110
|
+
tasksTotal: input.total,
|
|
111
|
+
noHeadroom,
|
|
112
|
+
dropped,
|
|
113
|
+
ci: null,
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const rate = numerator / denominator
|
|
118
|
+
const resamples = opts?.resamples ?? 1000
|
|
119
|
+
const random = mulberry32(opts?.seed ?? 42)
|
|
120
|
+
const rates: number[] = []
|
|
121
|
+
for (let i = 0; i < resamples; i++) {
|
|
122
|
+
let num = 0
|
|
123
|
+
let den = 0
|
|
124
|
+
for (let j = 0; j < pairs.length; j++) {
|
|
125
|
+
// `pairs` 在进入重采样前已剔掉 no-headroom / 缺样本的题,抽到的每一题都可计。
|
|
126
|
+
const pick = pairs[Math.floor(random() * pairs.length)]!
|
|
127
|
+
num += pick.on - pick.off
|
|
128
|
+
den += 100 - pick.off
|
|
129
|
+
}
|
|
130
|
+
if (den > 0) rates.push(num / den)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
let ci: { lo: number; hi: number } | null = null
|
|
134
|
+
if (rates.length >= 2) {
|
|
135
|
+
rates.sort((a, b) => a - b)
|
|
136
|
+
ci = { lo: quantile(rates, 0.025), hi: quantile(rates, 0.975) }
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
numerator,
|
|
141
|
+
denominator,
|
|
142
|
+
rate,
|
|
143
|
+
tasksUsed: pairs.length,
|
|
144
|
+
tasksTotal: input.total,
|
|
145
|
+
noHeadroom,
|
|
146
|
+
dropped,
|
|
147
|
+
ci,
|
|
148
|
+
}
|
|
149
|
+
}
|
package/src/core/crsi-modify.ts
CHANGED
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
regressedAnchors,
|
|
27
27
|
} from './eval-harness'
|
|
28
28
|
import { mechanismSentinel, type RewardFn, type ScoreReport } from './reward-fn'
|
|
29
|
+
import { openProbation, recordNoInstrument } from './probation'
|
|
29
30
|
|
|
30
31
|
export interface CrsiProposal {
|
|
31
32
|
/** 人类可读的改动说明 */
|
|
@@ -64,6 +65,30 @@ export interface CrsiProposal {
|
|
|
64
65
|
// 模块级单例:成功跑完测试的修改停在这里,等待人类 approve / reject。
|
|
65
66
|
let pendingSandbox: CrsiSandbox | null = null
|
|
66
67
|
|
|
68
|
+
/**
|
|
69
|
+
* 与 `pendingSandbox` 同生命周期的试用期基线。
|
|
70
|
+
*
|
|
71
|
+
* **为什么由调用方事后设置**:真实调用顺序是 `runCrsiModification` → `measureModification`
|
|
72
|
+
* (测量排在沙箱之后,避免 failed proposal 白跑 LLM)。所以基线不可能作为
|
|
73
|
+
* `runCrsiModification` 的入参 —— 它在那一刻还不存在。
|
|
74
|
+
*/
|
|
75
|
+
export interface PendingProbation {
|
|
76
|
+
filePath: string
|
|
77
|
+
skillName: string
|
|
78
|
+
baselineScores: number[]
|
|
79
|
+
poolSize: number
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
let pendingProbation: PendingProbation | null = null
|
|
83
|
+
|
|
84
|
+
/** 待合并改动的目标文件 —— `approvePending` 用它登记「没有随机仪器」的那句话。 */
|
|
85
|
+
let pendingFilePath: string | null = null
|
|
86
|
+
|
|
87
|
+
/** 设置/清空待合并的试用期基线(清空用 `null`)。 */
|
|
88
|
+
export function setPendingProbation(probation: PendingProbation | null): void {
|
|
89
|
+
pendingProbation = probation
|
|
90
|
+
}
|
|
91
|
+
|
|
67
92
|
/**
|
|
68
93
|
* 编排完整 5 阶段:createWorktree → applyModification → runTests →(失败自动
|
|
69
94
|
* rollback)→ getDiff。测试通过后暂存为 pending,返回 diff 供人类审阅。
|
|
@@ -112,6 +137,9 @@ export async function runCrsiModification(
|
|
|
112
137
|
}
|
|
113
138
|
}
|
|
114
139
|
|
|
140
|
+
// 新的修改使上一次的测量失效 —— 不让旧基线挂到新合并上。
|
|
141
|
+
pendingProbation = null
|
|
142
|
+
pendingFilePath = proposal.filePath
|
|
115
143
|
sandbox.createWorktree()
|
|
116
144
|
|
|
117
145
|
const applied = sandbox.applyModification({
|
|
@@ -236,15 +264,33 @@ export function hasPending(): boolean {
|
|
|
236
264
|
return pendingSandbox !== null
|
|
237
265
|
}
|
|
238
266
|
|
|
239
|
-
/** 人类批准:merge 进仓库并清理 worktree
|
|
240
|
-
export function approvePending(): {
|
|
267
|
+
/** 人类批准:merge 进仓库并清理 worktree;成功且有测量时开试用期。 */
|
|
268
|
+
export function approvePending(): {
|
|
269
|
+
success: boolean
|
|
270
|
+
message: string
|
|
271
|
+
probationOpened?: boolean
|
|
272
|
+
} {
|
|
241
273
|
if (!pendingSandbox) {
|
|
242
274
|
return { success: false, message: '没有待批准的修改。先运行 /crsi modify。' }
|
|
243
275
|
}
|
|
244
276
|
const sandbox = pendingSandbox
|
|
277
|
+
const probation = pendingProbation
|
|
278
|
+
const filePath = pendingFilePath
|
|
245
279
|
pendingSandbox = null
|
|
280
|
+
pendingProbation = null
|
|
281
|
+
pendingFilePath = null
|
|
246
282
|
const merged = sandbox.merge()
|
|
247
283
|
sandbox.finalize()
|
|
284
|
+
if (merged.success && merged.commitHash) {
|
|
285
|
+
if (probation) {
|
|
286
|
+
openProbation({ ...probation, commitHash: merged.commitHash })
|
|
287
|
+
return { ...merged, probationOpened: true }
|
|
288
|
+
}
|
|
289
|
+
// 没有随机仪器也要**说出来**:静默跳过会让这次合并在 stats 里完全消失。
|
|
290
|
+
if (filePath) {
|
|
291
|
+
recordNoInstrument({ filePath, commitHash: merged.commitHash })
|
|
292
|
+
}
|
|
293
|
+
}
|
|
248
294
|
return merged
|
|
249
295
|
}
|
|
250
296
|
|
|
@@ -255,5 +301,7 @@ export function rejectPending(): { success: boolean; message: string } {
|
|
|
255
301
|
}
|
|
256
302
|
const sandbox = pendingSandbox
|
|
257
303
|
pendingSandbox = null
|
|
304
|
+
pendingProbation = null
|
|
305
|
+
pendingFilePath = null
|
|
258
306
|
return sandbox.rollback()
|
|
259
307
|
}
|
package/src/core/crsi-sandbox.ts
CHANGED
|
@@ -592,7 +592,7 @@ export class CrsiSandbox {
|
|
|
592
592
|
* ONLY call this after human approval and successful test run.
|
|
593
593
|
* Cherry-picks the changes from the worktree branch to the current branch.
|
|
594
594
|
*/
|
|
595
|
-
merge(): { success: boolean; message: string } {
|
|
595
|
+
merge(): { success: boolean; message: string; commitHash?: string } {
|
|
596
596
|
if (!this.worktreePath || !this.worktreeBranch) {
|
|
597
597
|
return { success: false, message: 'No worktree to merge from.' }
|
|
598
598
|
}
|
|
@@ -618,9 +618,14 @@ export class CrsiSandbox {
|
|
|
618
618
|
)
|
|
619
619
|
|
|
620
620
|
// Cherry-pick to main repo
|
|
621
|
-
const
|
|
621
|
+
const worktreeCommit = runIn(this.worktreePath, 'git rev-parse HEAD').trim()
|
|
622
622
|
|
|
623
|
-
runIn(this.repoRoot, `git cherry-pick "${
|
|
623
|
+
runIn(this.repoRoot, `git cherry-pick "${worktreeCommit}"`, { timeoutMs: 30_000 })
|
|
624
|
+
|
|
625
|
+
// 回退目标必须是**主分支上那个新提交**:cherry-pick 造的是另一个 SHA,
|
|
626
|
+
// 而工作树随后会被 finalize() 删掉、其分支被 -D —— 工作树那个提交可能变成
|
|
627
|
+
// 不可达对象。`git revert <worktree> ` 会解析不到。
|
|
628
|
+
const commitHash = runIn(this.repoRoot, 'git rev-parse HEAD').trim()
|
|
624
629
|
|
|
625
630
|
// Mark as merged
|
|
626
631
|
for (const modResult of this.sessionReport.modifications) {
|
|
@@ -635,6 +640,7 @@ export class CrsiSandbox {
|
|
|
635
640
|
return {
|
|
636
641
|
success: true,
|
|
637
642
|
message: `Successfully merged ${this.sessionReport.summary.merged} modification(s).`,
|
|
643
|
+
commitHash,
|
|
638
644
|
}
|
|
639
645
|
} catch (err) {
|
|
640
646
|
return { success: false, message: `Merge failed: ${String(err)}` }
|
|
@@ -63,8 +63,13 @@ export interface ImprovementRecord extends ImprovementReport {
|
|
|
63
63
|
|
|
64
64
|
// ── 纯函数 ──
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
/**
|
|
67
|
+
* 噪声自适应最小效应量。`floor` 缺省为 `MIN_EFFECT_FLOOR` —— 既有调用点不变。
|
|
68
|
+
* 试用期传自己的地板(两题步长),因为 4 题池上单题翻转只有 25 分,按 20 分地板判
|
|
69
|
+
* 退化会让「一次恰好翻转」触发回退提示。
|
|
70
|
+
*/
|
|
71
|
+
export function computeMinEffect(noise: number, floor: number = MIN_EFFECT_FLOOR): number {
|
|
72
|
+
return Math.max(floor, NOISE_K * noise)
|
|
68
73
|
}
|
|
69
74
|
|
|
70
75
|
export function classifyDelta(deltaMean: number, minEffect: number): ImprovementVerdict {
|
package/src/core/instructions.ts
CHANGED
|
@@ -343,7 +343,6 @@ export function formatInstructionSizeNotice(
|
|
|
343
343
|
|
|
344
344
|
export class InstructionsLoader {
|
|
345
345
|
private instructions: InstructionFile[] = []
|
|
346
|
-
private crsiLessonSummaries: CrsiLessonSummary[] = []
|
|
347
346
|
private lessonsPath: string | null = null
|
|
348
347
|
/** Checkout root resolved at `loadAll`, reused by `loadForPaths`. */
|
|
349
348
|
private root: string | null = null
|
|
@@ -371,8 +370,8 @@ export class InstructionsLoader {
|
|
|
371
370
|
// Tier 3: 用户层 ~/.mipham/USER.md
|
|
372
371
|
this.tryLoad(miphamHome('USER.md'), 'user')
|
|
373
372
|
|
|
374
|
-
// CRSI
|
|
375
|
-
this.
|
|
373
|
+
// CRSI 教训召回:在这里只**确定来源路径**;内容每次投影时重读(见 currentLessonSummaries)。
|
|
374
|
+
this.loadCrsiLessons(root)
|
|
376
375
|
}
|
|
377
376
|
|
|
378
377
|
/**
|
|
@@ -561,6 +560,9 @@ Never omit it or present the work as purely human-authored.`)
|
|
|
561
560
|
this.lessonsPath = path
|
|
562
561
|
return extractCrsiLessonSummaries(content)
|
|
563
562
|
} catch {
|
|
563
|
+
// 文件被删:指针必须同时清空。否则「删了教训」与「从来没有过」在 sizeReport
|
|
564
|
+
// 里同形 —— 报告会继续点名一个不存在来源。
|
|
565
|
+
this.lessonsPath = null
|
|
564
566
|
return []
|
|
565
567
|
}
|
|
566
568
|
}
|
|
@@ -579,9 +581,21 @@ Never omit it or present the work as purely human-authored.`)
|
|
|
579
581
|
* 落进指针(并在指针里被点名)—— 择点走 `selectResidentLessons`,与
|
|
580
582
|
* `loadAlwaysOnLessonsBlock` 是同一个。
|
|
581
583
|
*/
|
|
584
|
+
/**
|
|
585
|
+
* 教训摘要的**唯一读取点**:每次都从盘上重读。
|
|
586
|
+
*
|
|
587
|
+
* 从前只在 `loadAll` 读一次并缓存 ⇒ 会话中途删掉一条教训,系统提示里那条会一直留着
|
|
588
|
+
* (与 Agnes Harness 报告 Limitations 第 3 条同型的「删了没有墓碑」)。一个文件的
|
|
589
|
+
* 读取成本远低于「给模型看到已经不存在的规则」。
|
|
590
|
+
*/
|
|
591
|
+
private currentLessonSummaries(): CrsiLessonSummary[] {
|
|
592
|
+
return this.root ? this.loadCrsiLessons(this.root) : []
|
|
593
|
+
}
|
|
594
|
+
|
|
582
595
|
private crsiLessonsText(): string {
|
|
583
|
-
|
|
584
|
-
|
|
596
|
+
const summaries = this.currentLessonSummaries()
|
|
597
|
+
if (!this.lessonsPath || summaries.length === 0) return ''
|
|
598
|
+
const selection = selectResidentLessons(summaries)
|
|
585
599
|
return [
|
|
586
600
|
buildCrsiLessonsBlock(selection.resident),
|
|
587
601
|
buildCrsiLessonsPointer(selection, this.lessonsPath),
|
|
@@ -600,11 +614,9 @@ Never omit it or present the work as purely human-authored.`)
|
|
|
600
614
|
* 与指针同一条件,故不会出现「扳机响了但没有指针」。
|
|
601
615
|
*/
|
|
602
616
|
crsiLessonNudgeText(): string {
|
|
603
|
-
|
|
604
|
-
return
|
|
605
|
-
|
|
606
|
-
this.lessonsPath,
|
|
607
|
-
)
|
|
617
|
+
const summaries = this.currentLessonSummaries()
|
|
618
|
+
if (!this.lessonsPath || summaries.length === 0) return ''
|
|
619
|
+
return buildLessonRevisitNudge(selectResidentLessons(summaries), this.lessonsPath)
|
|
608
620
|
}
|
|
609
621
|
|
|
610
622
|
/**
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 试用期(probation):合并之后、裁定之前。
|
|
3
|
+
*
|
|
4
|
+
* `/crsi modify --approve` 是终态 —— 合并后变坏只能靠人事后发现。本模块给
|
|
5
|
+
* **有一次任务表现测量**的合并开一个观察窗:后续同口径重测满 N 次时出裁定;
|
|
6
|
+
* 判为退化**只打印** `git revert <sha>`,**不执行**(破坏性 git 由人敲)。
|
|
7
|
+
*
|
|
8
|
+
* 边界(刻意):没有随机信号就没有观察窗 —— `core/*.ts` 的合并不开窗,
|
|
9
|
+
* 由 `/crsi stats` 明说「没有可用仪器」,而不是静默跳过。
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { randomUUID } from 'node:crypto'
|
|
13
|
+
import { existsSync, mkdirSync, readFileSync } from 'node:fs'
|
|
14
|
+
import { atomicWriteFileSync } from '../shared/atomic-write'
|
|
15
|
+
import { miphamHome } from './paths.ts'
|
|
16
|
+
import { classifyDelta, computeMinEffect, type ImprovementVerdict } from './improvement-track'
|
|
17
|
+
|
|
18
|
+
/** 观察窗长度:同一 skill、同一 gate 池、k≥3 的重测次数。 */
|
|
19
|
+
export const PROBATION_WINDOW = 3
|
|
20
|
+
|
|
21
|
+
export interface ProbationRecord {
|
|
22
|
+
id: string
|
|
23
|
+
filePath: string
|
|
24
|
+
skillName: string
|
|
25
|
+
commitHash: string
|
|
26
|
+
/** 合并时的 k 个 post 臂采样(不是标量:噪声要用它估)。 */
|
|
27
|
+
baselineScores: number[]
|
|
28
|
+
/** 观察窗内每次同口径重测。 */
|
|
29
|
+
checks: number[]
|
|
30
|
+
/** 组内 gate 题数 —— 地板 = 两题步长 = `2 × (100 / poolSize)`。 */
|
|
31
|
+
poolSize: number
|
|
32
|
+
/** 窗口未满时**缺席**(与 `inconclusive` 不同形)。 */
|
|
33
|
+
verdict?: ImprovementVerdict
|
|
34
|
+
/**
|
|
35
|
+
* 这次合并没有任何随机仪器可用(例如改了 `core/*.ts`)。
|
|
36
|
+
* 登记它是为了**说出来** —— 静默跳过会让「没有仪器」和「没有合并」同形。
|
|
37
|
+
*/
|
|
38
|
+
noInstrument?: true
|
|
39
|
+
timestamp: string
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function probationPath(): string {
|
|
43
|
+
return miphamHome('crsi', 'probation.jsonl')
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function readProbations(): ProbationRecord[] {
|
|
47
|
+
const file = probationPath()
|
|
48
|
+
if (!existsSync(file)) return []
|
|
49
|
+
return readFileSync(file, 'utf-8')
|
|
50
|
+
.split('\n')
|
|
51
|
+
.filter((line) => line.trim() !== '')
|
|
52
|
+
.flatMap((line) => {
|
|
53
|
+
try {
|
|
54
|
+
return [JSON.parse(line) as ProbationRecord]
|
|
55
|
+
} catch {
|
|
56
|
+
return [] // 残留坏行跳过,不抛(与引入台账同口径)
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function writeProbations(records: ProbationRecord[]): void {
|
|
62
|
+
mkdirSync(miphamHome('crsi'), { recursive: true })
|
|
63
|
+
atomicWriteFileSync(
|
|
64
|
+
probationPath(),
|
|
65
|
+
records.map((r) => JSON.stringify(r)).join('\n') + (records.length > 0 ? '\n' : ''),
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function mean(xs: number[]): number {
|
|
70
|
+
return xs.length === 0 ? 0 : xs.reduce((a, b) => a + b, 0) / xs.length
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function stdDev(xs: number[]): number {
|
|
74
|
+
if (xs.length < 2) return 0
|
|
75
|
+
const m = mean(xs)
|
|
76
|
+
const variance = xs.reduce((a, b) => a + (b - m) ** 2, 0) / (xs.length - 1)
|
|
77
|
+
return Math.sqrt(variance)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** 地板 = 两题步长(4 题池即 50):单题翻转不判退化。 */
|
|
81
|
+
export function probationMinEffect(baseline: number[], checks: number[], poolSize: number): number {
|
|
82
|
+
const noise = Math.max(stdDev(baseline), stdDev(checks))
|
|
83
|
+
return computeMinEffect(noise, 2 * (100 / Math.max(1, poolSize)))
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function openProbation(
|
|
87
|
+
rec: Omit<ProbationRecord, 'id' | 'checks' | 'verdict' | 'timestamp'>,
|
|
88
|
+
): void {
|
|
89
|
+
const records = readProbations()
|
|
90
|
+
records.push({
|
|
91
|
+
...rec,
|
|
92
|
+
id: randomUUID(),
|
|
93
|
+
checks: [],
|
|
94
|
+
timestamp: new Date().toISOString(),
|
|
95
|
+
})
|
|
96
|
+
writeProbations(records)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* 登记一次「没有随机仪器」的合并。它没有基线、永远不会结算 —— 存在的唯一目的
|
|
101
|
+
* 是让 `/crsi stats` 说得出这句话,而不是让这次合并从台账里消失。
|
|
102
|
+
*/
|
|
103
|
+
export function recordNoInstrument(rec: { filePath: string; commitHash: string }): void {
|
|
104
|
+
const records = readProbations()
|
|
105
|
+
records.push({
|
|
106
|
+
id: randomUUID(),
|
|
107
|
+
filePath: rec.filePath,
|
|
108
|
+
skillName: rec.filePath,
|
|
109
|
+
commitHash: rec.commitHash,
|
|
110
|
+
baselineScores: [],
|
|
111
|
+
checks: [],
|
|
112
|
+
poolSize: 0,
|
|
113
|
+
noInstrument: true,
|
|
114
|
+
timestamp: new Date().toISOString(),
|
|
115
|
+
})
|
|
116
|
+
writeProbations(records)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* 给最近一条未结的该 skill 记录追加一次读数。窗口满 N 次时写 verdict。
|
|
121
|
+
* 没有未结窗口 ⇒ `null`(不是抛错:调用方可能对任何 bench 结果都调一次)。
|
|
122
|
+
*/
|
|
123
|
+
export function settleProbation(skillName: string, score: number): ProbationRecord | null {
|
|
124
|
+
const records = readProbations()
|
|
125
|
+
let idx = -1
|
|
126
|
+
for (let i = records.length - 1; i >= 0; i--) {
|
|
127
|
+
const r = records[i]!
|
|
128
|
+
if (!r.noInstrument && r.skillName === skillName && r.verdict === undefined) {
|
|
129
|
+
idx = i
|
|
130
|
+
break
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (idx < 0) return null
|
|
134
|
+
|
|
135
|
+
const rec = records[idx]!
|
|
136
|
+
const checks = [...rec.checks, score]
|
|
137
|
+
const updated: ProbationRecord = { ...rec, checks }
|
|
138
|
+
if (checks.length >= PROBATION_WINDOW) {
|
|
139
|
+
const minEffect = probationMinEffect(rec.baselineScores, checks, rec.poolSize)
|
|
140
|
+
updated.verdict = classifyDelta(mean(checks) - mean(rec.baselineScores), minEffect)
|
|
141
|
+
}
|
|
142
|
+
records[idx] = updated
|
|
143
|
+
writeProbations(records)
|
|
144
|
+
return updated
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** `/crsi stats` 的试用期段。空数组 = 没有试用期记录,不打任何行。 */
|
|
148
|
+
export function formatProbationLines(): string[] {
|
|
149
|
+
const records = readProbations()
|
|
150
|
+
if (records.length === 0) return []
|
|
151
|
+
const lines = ['', '### 试用期(probation)', '']
|
|
152
|
+
for (const r of records) {
|
|
153
|
+
if (r.noInstrument) {
|
|
154
|
+
lines.push(`- ${r.filePath}: no stochastic instrument for this merge`)
|
|
155
|
+
continue
|
|
156
|
+
}
|
|
157
|
+
const base = mean(r.baselineScores).toFixed(1)
|
|
158
|
+
if (r.verdict === undefined) {
|
|
159
|
+
lines.push(
|
|
160
|
+
`- ${r.skillName}: ${r.checks.length}/${PROBATION_WINDOW}(基线 ${base})—— 观察中`,
|
|
161
|
+
)
|
|
162
|
+
continue
|
|
163
|
+
}
|
|
164
|
+
lines.push(`- ${r.skillName}: ${r.verdict}(基线 ${base},${r.checks.length} 次重测)`)
|
|
165
|
+
if (r.verdict === 'regressed') {
|
|
166
|
+
// 只打印。破坏性 git 操作由人执行 —— 本模块不调用任何 git 命令。
|
|
167
|
+
lines.push(` - 建议回退:\`git revert ${r.commitHash}\``)
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return lines
|
|
171
|
+
}
|
package/src/core/reward-fn.ts
CHANGED
|
@@ -45,7 +45,15 @@ export function taskPerformanceRewardFn(llm: Llm): RewardFn {
|
|
|
45
45
|
return {
|
|
46
46
|
name: 'task-performance',
|
|
47
47
|
description: 'LLM 生成 + 冻结测试评 skill/通用任务',
|
|
48
|
-
|
|
48
|
+
// 没测到 ⇒ 抛错,让 `runCrsiModification` 走它已有的「量具不可用」分支。
|
|
49
|
+
// 返回 score=100 会让奖励闸把一次上游故障读成满分。
|
|
50
|
+
evaluate: async () => {
|
|
51
|
+
const report = await runTaskPerformance(llm)
|
|
52
|
+
if (!report.measurable) {
|
|
53
|
+
throw new Error('task-performance 未测到任何可评分样本(仪器/上游故障)')
|
|
54
|
+
}
|
|
55
|
+
return report
|
|
56
|
+
},
|
|
49
57
|
}
|
|
50
58
|
}
|
|
51
59
|
|
|
@@ -5,38 +5,131 @@
|
|
|
5
5
|
"id": "perf-impl-quicksort",
|
|
6
6
|
"category": "test-driven",
|
|
7
7
|
"prompt": "实现并导出 quicksort 函数:export function quicksort(arr: number[]): number[]。只输出 TypeScript 代码,不要解释、不要 markdown 代码块。",
|
|
8
|
-
"testCode": "import { test, expect } from 'bun:test'\nimport { quicksort } from './solution'\n\ntest('sorts numbers', () => {\n expect(quicksort([3, 1, 4, 1, 5, 9, 2, 6])).toEqual([1, 1, 2, 3, 4, 5, 6, 9])\n expect(quicksort([])).toEqual([])\n expect(quicksort([7])).toEqual([7])\n})\n"
|
|
8
|
+
"testCode": "import { test, expect } from 'bun:test'\nimport { quicksort } from './solution'\n\ntest('sorts numbers', () => {\n expect(quicksort([3, 1, 4, 1, 5, 9, 2, 6])).toEqual([1, 1, 2, 3, 4, 5, 6, 9])\n expect(quicksort([])).toEqual([])\n expect(quicksort([7])).toEqual([7])\n})\n",
|
|
9
|
+
"oracleCode": "export function quicksort(arr: number[]): number[] {\n return [...arr].sort((a, b) => a - b)\n}\n",
|
|
10
|
+
"split": "gate"
|
|
9
11
|
},
|
|
10
12
|
{
|
|
11
13
|
"id": "perf-impl-fibonacci",
|
|
12
14
|
"category": "test-driven",
|
|
13
15
|
"prompt": "实现并导出 fibonacci 函数:export function fibonacci(n: number): number。返回第 n 项(fibonacci(0)=0, fibonacci(1)=1)。只输出 TypeScript 代码,不要解释、不要 markdown 代码块。",
|
|
14
|
-
"testCode": "import { test, expect } from 'bun:test'\nimport { fibonacci } from './solution'\n\ntest('computes fibonacci', () => {\n expect(fibonacci(0)).toBe(0)\n expect(fibonacci(1)).toBe(1)\n expect(fibonacci(10)).toBe(55)\n expect(fibonacci(20)).toBe(6765)\n})\n"
|
|
16
|
+
"testCode": "import { test, expect } from 'bun:test'\nimport { fibonacci } from './solution'\n\ntest('computes fibonacci', () => {\n expect(fibonacci(0)).toBe(0)\n expect(fibonacci(1)).toBe(1)\n expect(fibonacci(10)).toBe(55)\n expect(fibonacci(20)).toBe(6765)\n})\n",
|
|
17
|
+
"oracleCode": "export function fibonacci(n: number): number {\n if (n < 2) return n\n let a = 0, b = 1\n for (let i = 2; i <= n; i++) {\n const next = a + b\n a = b\n b = next\n }\n return b\n}\n",
|
|
18
|
+
"split": "gate"
|
|
15
19
|
},
|
|
16
20
|
{
|
|
17
21
|
"id": "perf-impl-binary-search",
|
|
18
22
|
"category": "test-driven",
|
|
19
23
|
"prompt": "实现并导出 binarySearch 函数:export function binarySearch(arr: number[], target: number): number。返回 target 的下标,不存在返回 -1。假设 arr 已升序。只输出 TypeScript 代码,不要解释、不要 markdown 代码块。",
|
|
20
|
-
"testCode": "import { test, expect } from 'bun:test'\nimport { binarySearch } from './solution'\n\ntest('finds target', () => {\n expect(binarySearch([1, 2, 3, 4, 5], 3)).toBe(2)\n expect(binarySearch([1, 2, 3, 4, 5], 1)).toBe(0)\n expect(binarySearch([1, 2, 3, 4, 5], 99)).toBe(-1)\n})\n"
|
|
24
|
+
"testCode": "import { test, expect } from 'bun:test'\nimport { binarySearch } from './solution'\n\ntest('finds target', () => {\n expect(binarySearch([1, 2, 3, 4, 5], 3)).toBe(2)\n expect(binarySearch([1, 2, 3, 4, 5], 1)).toBe(0)\n expect(binarySearch([1, 2, 3, 4, 5], 99)).toBe(-1)\n})\n",
|
|
25
|
+
"oracleCode": "export function binarySearch(arr: number[], target: number): number {\n let lo = 0, hi = arr.length - 1\n while (lo <= hi) {\n const mid = (lo + hi) >> 1\n if (arr[mid] === target) return mid\n if (arr[mid] < target) lo = mid + 1\n else hi = mid - 1\n }\n return -1\n}\n",
|
|
26
|
+
"split": "gate"
|
|
21
27
|
},
|
|
22
28
|
{
|
|
23
29
|
"id": "perf-impl-reverse-string",
|
|
24
30
|
"category": "test-driven",
|
|
25
31
|
"prompt": "实现并导出 reverseString 函数:export function reverseString(s: string): string。只输出 TypeScript 代码,不要解释、不要 markdown 代码块。",
|
|
26
|
-
"testCode": "import { test, expect } from 'bun:test'\nimport { reverseString } from './solution'\n\ntest('reverses', () => {\n expect(reverseString('hello')).toBe('olleh')\n expect(reverseString('')).toBe('')\n expect(reverseString('a')).toBe('a')\n})\n"
|
|
32
|
+
"testCode": "import { test, expect } from 'bun:test'\nimport { reverseString } from './solution'\n\ntest('reverses', () => {\n expect(reverseString('hello')).toBe('olleh')\n expect(reverseString('')).toBe('')\n expect(reverseString('a')).toBe('a')\n})\n",
|
|
33
|
+
"oracleCode": "export function reverseString(s: string): string {\n return s.split('').reverse().join('')\n}\n",
|
|
34
|
+
"split": "gate"
|
|
27
35
|
},
|
|
28
36
|
{
|
|
29
37
|
"id": "perf-impl-max",
|
|
30
38
|
"category": "test-driven",
|
|
31
39
|
"prompt": "实现并导出 maxOf 函数:export function maxOf(arr: number[]): number。返回数组最大值,空数组返回 -Infinity。只输出 TypeScript 代码,不要解释、不要 markdown 代码块。",
|
|
32
|
-
"testCode": "import { test, expect } from 'bun:test'\nimport { maxOf } from './solution'\n\ntest('finds max', () => {\n expect(maxOf([1, 5, 3, 9, 2])).toBe(9)\n expect(maxOf([-1, -5, -3])).toBe(-1)\n expect(maxOf([])).toBe(-Infinity)\n})\n"
|
|
40
|
+
"testCode": "import { test, expect } from 'bun:test'\nimport { maxOf } from './solution'\n\ntest('finds max', () => {\n expect(maxOf([1, 5, 3, 9, 2])).toBe(9)\n expect(maxOf([-1, -5, -3])).toBe(-1)\n expect(maxOf([])).toBe(-Infinity)\n})\n",
|
|
41
|
+
"oracleCode": "export function maxOf(arr: number[]): number {\n return arr.reduce((m, x) => (x > m ? x : m), -Infinity)\n}\n",
|
|
42
|
+
"split": "sealed"
|
|
33
43
|
},
|
|
34
44
|
{
|
|
35
45
|
"id": "perf-safe-parse-positive",
|
|
36
46
|
"category": "test-driven",
|
|
47
|
+
"prompt": "实现并导出 parsePositiveNumber 函数:export function parsePositiveNumber(input: string): number。非法输入(null、空串、非数字、非正数)必须抛 RangeError。只输出 TypeScript 代码,不要解释、不要 markdown 代码块。",
|
|
48
|
+
"testCode": "import { test, expect } from 'bun:test'\nimport { parsePositiveNumber } from './solution'\n\ntest('rejects invalid input', () => {\n expect(() => parsePositiveNumber(null as any)).toThrow(RangeError)\n expect(() => parsePositiveNumber('')).toThrow(RangeError)\n expect(() => parsePositiveNumber('abc')).toThrow(RangeError)\n})\ntest('parses valid', () => {\n expect(parsePositiveNumber('42')).toBe(42)\n})\n",
|
|
49
|
+
"oracleCode": "export function parsePositiveNumber(input: string): number {\n const text = String(input).trim()\n if (!/^\\d+(\\.\\d+)?$/.test(text)) throw new RangeError('not a positive number')\n const n = Number(text)\n if (!Number.isFinite(n) || n <= 0) throw new RangeError('not a positive number')\n return n\n}\n",
|
|
37
50
|
"skill": "safe-coding",
|
|
38
|
-
"
|
|
39
|
-
|
|
51
|
+
"split": "gate"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"id": "perf-safe-parse-int",
|
|
55
|
+
"category": "test-driven",
|
|
56
|
+
"prompt": "实现并导出 parseStrictInt 函数:export function parseStrictInt(s: string): number | null。只接受十进制整数字面量(允许首尾空白与负号),其余一律返回 null。只输出 TypeScript 代码,不要解释、不要 markdown 代码块。",
|
|
57
|
+
"testCode": "import { test, expect } from 'bun:test'\nimport { parseStrictInt } from './solution'\n\ntest('parses integers', () => {\n expect(parseStrictInt('42')).toBe(42)\n expect(parseStrictInt(' -7 ')).toBe(-7)\n})\ntest('rejects non-integers', () => {\n expect(parseStrictInt('4.2')).toBe(null)\n expect(parseStrictInt('')).toBe(null)\n expect(parseStrictInt('1e3')).toBe(null)\n})\n",
|
|
58
|
+
"oracleCode": "export function parseStrictInt(s: string): number | null {\n const text = String(s).trim()\n if (!/^-?\\d+$/.test(text)) return null\n const n = Number(text)\n return Number.isSafeInteger(n) ? n : null\n}\n",
|
|
59
|
+
"skill": "safe-coding",
|
|
60
|
+
"split": "gate"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"id": "perf-safe-clamp",
|
|
64
|
+
"category": "test-driven",
|
|
65
|
+
"prompt": "实现并导出 clamp 函数:export function clamp(n: number, min: number, max: number): number。把 n 限制在 [min, max];若 min > max 必须抛 RangeError。只输出 TypeScript 代码,不要解释、不要 markdown 代码块。",
|
|
66
|
+
"testCode": "import { test, expect } from 'bun:test'\nimport { clamp } from './solution'\n\ntest('clamps into range', () => {\n expect(clamp(5, 0, 10)).toBe(5)\n expect(clamp(-3, 0, 10)).toBe(0)\n expect(clamp(99, 0, 10)).toBe(10)\n})\ntest('rejects inverted bounds', () => {\n expect(() => clamp(1, 10, 0)).toThrow(RangeError)\n})\n",
|
|
67
|
+
"oracleCode": "export function clamp(n: number, min: number, max: number): number {\n if (min > max) throw new RangeError('min > max')\n return Math.min(Math.max(n, min), max)\n}\n",
|
|
68
|
+
"skill": "safe-coding",
|
|
69
|
+
"split": "gate"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"id": "perf-safe-divide",
|
|
73
|
+
"category": "test-driven",
|
|
74
|
+
"prompt": "实现并导出 safeDivide 函数:export function safeDivide(a: number, b: number): number | null。除数为 0 或结果非有限时返回 null。只输出 TypeScript 代码,不要解释、不要 markdown 代码块。",
|
|
75
|
+
"testCode": "import { test, expect } from 'bun:test'\nimport { safeDivide } from './solution'\n\ntest('divides', () => {\n expect(safeDivide(6, 3)).toBe(2)\n expect(safeDivide(-9, 3)).toBe(-3)\n})\ntest('returns null instead of Infinity/NaN', () => {\n expect(safeDivide(1, 0)).toBe(null)\n expect(safeDivide(-1, 0)).toBe(null)\n expect(safeDivide(0, 0)).toBe(null)\n})\n",
|
|
76
|
+
"oracleCode": "export function safeDivide(a: number, b: number): number | null {\n if (!Number.isFinite(a) || !Number.isFinite(b) || b === 0) return null\n const r = a / b\n return Number.isFinite(r) ? r : null\n}\n",
|
|
77
|
+
"skill": "safe-coding",
|
|
78
|
+
"split": "sealed"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"id": "perf-safe-parse-bool",
|
|
82
|
+
"category": "test-driven",
|
|
83
|
+
"prompt": "实现并导出 parseBool 函数:export function parseBool(s: string): boolean | null。接受 true/1/yes/on 与 false/0/no/off(大小写不敏感、允许首尾空白),其余返回 null。只输出 TypeScript 代码,不要解释、不要 markdown 代码块。",
|
|
84
|
+
"testCode": "import { test, expect } from 'bun:test'\nimport { parseBool } from './solution'\n\ntest('parses truthy spellings', () => {\n expect(parseBool('true')).toBe(true)\n expect(parseBool(' YES ')).toBe(true)\n expect(parseBool('on')).toBe(true)\n expect(parseBool('1')).toBe(true)\n})\ntest('parses falsy spellings', () => {\n expect(parseBool('false')).toBe(false)\n expect(parseBool('Off')).toBe(false)\n expect(parseBool('0')).toBe(false)\n})\ntest('rejects unknown', () => {\n expect(parseBool('maybe')).toBe(null)\n expect(parseBool('')).toBe(null)\n})\n",
|
|
85
|
+
"oracleCode": "export function parseBool(s: string): boolean | null {\n const text = String(s).trim().toLowerCase()\n if (['true', '1', 'yes', 'on'].includes(text)) return true\n if (['false', '0', 'no', 'off'].includes(text)) return false\n return null\n}\n",
|
|
86
|
+
"skill": "safe-coding",
|
|
87
|
+
"split": "gate"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"id": "perf-tdd-stack",
|
|
91
|
+
"category": "test-driven",
|
|
92
|
+
"prompt": "实现并导出 createStack 函数:export function createStack<T>()。返回对象需提供 push(v)、pop()、peek()、size();空栈 pop/peek 返回 null。只输出 TypeScript 代码,不要解释、不要 markdown 代码块。",
|
|
93
|
+
"testCode": "import { test, expect } from 'bun:test'\nimport { createStack } from './solution'\n\ntest('behaves LIFO', () => {\n const s = createStack<number>()\n s.push(1)\n s.push(2)\n expect(s.size()).toBe(2)\n expect(s.peek()).toBe(2)\n expect(s.pop()).toBe(2)\n expect(s.pop()).toBe(1)\n expect(s.pop()).toBe(null)\n})\n",
|
|
94
|
+
"oracleCode": "export function createStack<T>() {\n const items: T[] = []\n return {\n push(v: T): void {\n items.push(v)\n },\n pop(): T | null {\n return items.length > 0 ? items.pop()! : null\n },\n peek(): T | null {\n return items.length > 0 ? items[items.length - 1]! : null\n },\n size(): number {\n return items.length\n },\n }\n}\n",
|
|
95
|
+
"skill": "tdd",
|
|
96
|
+
"split": "gate"
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"id": "perf-tdd-queue",
|
|
100
|
+
"category": "test-driven",
|
|
101
|
+
"prompt": "实现并导出 createQueue 函数:export function createQueue<T>()。返回对象需提供 enqueue(v)、dequeue()、size();空队列 dequeue 返回 null。只输出 TypeScript 代码,不要解释、不要 markdown 代码块。",
|
|
102
|
+
"testCode": "import { test, expect } from 'bun:test'\nimport { createQueue } from './solution'\n\ntest('behaves FIFO', () => {\n const q = createQueue<string>()\n q.enqueue('a')\n q.enqueue('b')\n expect(q.size()).toBe(2)\n expect(q.dequeue()).toBe('a')\n expect(q.dequeue()).toBe('b')\n expect(q.dequeue()).toBe(null)\n expect(q.size()).toBe(0)\n})\n",
|
|
103
|
+
"oracleCode": "export function createQueue<T>() {\n const items: T[] = []\n return {\n enqueue(v: T): void {\n items.push(v)\n },\n dequeue(): T | null {\n return items.length > 0 ? items.shift()! : null\n },\n size(): number {\n return items.length\n },\n }\n}\n",
|
|
104
|
+
"skill": "tdd",
|
|
105
|
+
"split": "gate"
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"id": "perf-tdd-lru",
|
|
109
|
+
"category": "test-driven",
|
|
110
|
+
"prompt": "实现并导出 createLRU 函数:export function createLRU(capacity: number)。返回对象需提供 get(key)、set(key, value)、size();容量满时淘汰最久未使用的键,get 命中也算一次使用。只输出 TypeScript 代码,不要解释、不要 markdown 代码块。",
|
|
111
|
+
"testCode": "import { test, expect } from 'bun:test'\nimport { createLRU } from './solution'\n\ntest('evicts least recently used', () => {\n const lru = createLRU(2)\n lru.set('a', 1)\n lru.set('b', 2)\n expect(lru.get('a')).toBe(1)\n lru.set('c', 3)\n expect(lru.get('b')).toBe(null)\n expect(lru.get('a')).toBe(1)\n expect(lru.get('c')).toBe(3)\n expect(lru.size()).toBe(2)\n})\n",
|
|
112
|
+
"oracleCode": "export function createLRU(capacity: number) {\n const map = new Map<string, number>()\n return {\n get(key: string): number | null {\n if (!map.has(key)) return null\n const value = map.get(key)!\n map.delete(key)\n map.set(key, value)\n return value\n },\n set(key: string, value: number): void {\n if (map.has(key)) {\n map.delete(key)\n } else if (map.size >= capacity) {\n const oldest = map.keys().next().value\n if (oldest !== undefined) map.delete(oldest)\n }\n map.set(key, value)\n },\n size(): number {\n return map.size\n },\n }\n}\n",
|
|
113
|
+
"skill": "tdd",
|
|
114
|
+
"split": "sealed"
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"id": "perf-tdd-range",
|
|
118
|
+
"category": "test-driven",
|
|
119
|
+
"prompt": "实现并导出 range 函数:export function range(start: number, end: number, step?: number): number[]。step 缺省为 1,step 为 0 必须抛 RangeError。只输出 TypeScript 代码,不要解释、不要 markdown 代码块。",
|
|
120
|
+
"testCode": "import { test, expect } from 'bun:test'\nimport { range } from './solution'\n\ntest('builds ranges', () => {\n expect(range(0, 5)).toEqual([0, 1, 2, 3, 4])\n expect(range(5, 0, -1)).toEqual([5, 4, 3, 2, 1])\n expect(range(0, 5, 2)).toEqual([0, 2, 4])\n expect(range(0, 0)).toEqual([])\n})\ntest('rejects zero step', () => {\n expect(() => range(0, 5, 0)).toThrow(RangeError)\n})\n",
|
|
121
|
+
"oracleCode": "export function range(start: number, end: number, step = 1): number[] {\n if (step === 0) throw new RangeError('step must not be 0')\n const out: number[] = []\n if (step > 0) {\n for (let i = start; i < end; i += step) out.push(i)\n } else {\n for (let i = start; i > end; i += step) out.push(i)\n }\n return out\n}\n",
|
|
122
|
+
"skill": "tdd",
|
|
123
|
+
"split": "gate"
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"id": "perf-tdd-chunk",
|
|
127
|
+
"category": "test-driven",
|
|
128
|
+
"prompt": "实现并导出 chunk 函数:export function chunk<T>(arr: T[], size: number): T[][]。size 必须是正整数,否则抛 RangeError;最后一块可以不足 size。只输出 TypeScript 代码,不要解释、不要 markdown 代码块。",
|
|
129
|
+
"testCode": "import { test, expect } from 'bun:test'\nimport { chunk } from './solution'\n\ntest('splits into chunks', () => {\n expect(chunk([1, 2, 3, 4, 5], 2)).toEqual([[1, 2], [3, 4], [5]])\n expect(chunk([], 2)).toEqual([])\n expect(chunk([1], 5)).toEqual([[1]])\n})\ntest('rejects bad size', () => {\n expect(() => chunk([1], 0)).toThrow(RangeError)\n expect(() => chunk([1], 1.5)).toThrow(RangeError)\n})\n",
|
|
130
|
+
"oracleCode": "export function chunk<T>(arr: T[], size: number): T[][] {\n if (!Number.isInteger(size) || size <= 0) throw new RangeError('size must be a positive integer')\n const out: T[][] = []\n for (let i = 0; i < arr.length; i += size) out.push(arr.slice(i, i + size))\n return out\n}\n",
|
|
131
|
+
"skill": "tdd",
|
|
132
|
+
"split": "gate"
|
|
40
133
|
}
|
|
41
134
|
]
|
|
42
135
|
}
|
|
@@ -10,16 +10,39 @@ import { parseFrontmatter } from '../skills/loader'
|
|
|
10
10
|
|
|
11
11
|
export type PerformanceTaskCategory = 'test-driven' | 'bug-fix'
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* 任务分池。`gate` = 参与候选选择与改进判定;`sealed` = **只在读数值时出现**,
|
|
15
|
+
* 永不进入任何裁定(见设计文档 §4.3)。
|
|
16
|
+
*/
|
|
17
|
+
export type TaskPool = 'gate' | 'sealed'
|
|
18
|
+
|
|
13
19
|
export interface PerformanceTask {
|
|
14
20
|
id: string
|
|
15
21
|
category: PerformanceTaskCategory
|
|
16
22
|
prompt: string
|
|
17
23
|
testCode: string
|
|
18
24
|
skill?: string // 绑定被测 skill 的名字(= skill frontmatter name)
|
|
25
|
+
/**
|
|
26
|
+
* 手写参考解。**必须**能通过本任务自己的 `testCode` —— 由
|
|
27
|
+
* `test/integrity/task-battery.test.ts` 逐题机械验证。
|
|
28
|
+
*
|
|
29
|
+
* 它是捕获率的上界(分母 `100 − off`):参考解若不满分,说明是题或答案坏了,
|
|
30
|
+
* 而不是被测 skill 不好。
|
|
31
|
+
*/
|
|
32
|
+
oracleCode: string
|
|
33
|
+
/** 分池,缺省 `'gate'`。 */
|
|
34
|
+
split?: TaskPool
|
|
19
35
|
}
|
|
20
36
|
|
|
21
|
-
|
|
22
|
-
|
|
37
|
+
/**
|
|
38
|
+
* 取任务集。**缺省 `'gate'`** —— 所有选择/改进路径因此天然看不到 sealed,
|
|
39
|
+
* 不需要逐处修改调用点;`'all'` 只给守卫与测试用。
|
|
40
|
+
*/
|
|
41
|
+
export function loadPerformanceTasks(opts?: { pool?: TaskPool | 'all' }): PerformanceTask[] {
|
|
42
|
+
const all = tasksFile.tasks as PerformanceTask[]
|
|
43
|
+
const pool = opts?.pool ?? 'gate'
|
|
44
|
+
if (pool === 'all') return all
|
|
45
|
+
return all.filter((t) => (t.split ?? 'gate') === pool)
|
|
23
46
|
}
|
|
24
47
|
|
|
25
48
|
export interface JudgeResult {
|
|
@@ -66,6 +89,14 @@ export interface TaskPerformanceResult {
|
|
|
66
89
|
* the result and excluded from `score` — mixing the two biases the readout low.
|
|
67
90
|
*/
|
|
68
91
|
truncated?: boolean
|
|
92
|
+
/**
|
|
93
|
+
* 没测到,而不是没答对:零文本且 provider 连 usage 都没报。
|
|
94
|
+
*
|
|
95
|
+
* 与 `truncated` 同族但**不同名** —— 前者是「仪器/上游故障」,后者是「输出被截断」。
|
|
96
|
+
* 两者都不进 `score`,但必须分开计数:合成一个数字会让「上游挂了」与「上限太短」
|
|
97
|
+
* 在读数上同形(见 docs/superpowers/specs/2026-11-20-crsi-eval-governance-design.md §4.6)。
|
|
98
|
+
*/
|
|
99
|
+
uncertain?: boolean
|
|
69
100
|
}
|
|
70
101
|
|
|
71
102
|
/** 空模型闸的读数:`passed` = 空程序也能通过的题数。 */
|
|
@@ -109,6 +140,16 @@ export interface TaskPerformanceReport {
|
|
|
109
140
|
failures: string[]
|
|
110
141
|
/** Tasks whose generation was cut off at the output cap; counted, not scored. */
|
|
111
142
|
truncated: number
|
|
143
|
+
/** 仪器/上游故障(零文本且零 usage);只计数,不进分数。 */
|
|
144
|
+
uncertain: number
|
|
145
|
+
/**
|
|
146
|
+
* 这一轮**到底测到没有**:至少有一道题进了分母。
|
|
147
|
+
*
|
|
148
|
+
* `false` 时 `score` 的 100 是「无题可评分」的占位,**不是满分**。任何把它当分数
|
|
149
|
+
* 用的地方(展示、改进判定、奖励闸)都必须先看这个字段 —— 否则一次 provider
|
|
150
|
+
* 抽风会读成「满分」,进而产出假的 improved / 假的 regressed。
|
|
151
|
+
*/
|
|
152
|
+
measurable: boolean
|
|
112
153
|
/** B2 代价维:整轮(LLM 生成 + 冻结测试判定)的墙钟耗时。只记录,不参与任何判定。 */
|
|
113
154
|
durationMs: number
|
|
114
155
|
/**
|
|
@@ -155,12 +196,27 @@ async function collectGeneratedCode(
|
|
|
155
196
|
return { code: stripCodeFences(text), truncated, tokens, usageReported }
|
|
156
197
|
}
|
|
157
198
|
|
|
199
|
+
export interface TaskPerformanceOptions {
|
|
200
|
+
/**
|
|
201
|
+
* 跑哪些题。**选择**与**注入**是两件事:捕获率需要「同一批题、注入 / 不注入」,
|
|
202
|
+
* 而旧签名用同一个 `skill` 参数同时决定两者,`off` 臂因此表达不出来。
|
|
203
|
+
*/
|
|
204
|
+
tasks?: PerformanceTask[]
|
|
205
|
+
/** 注入的 systemPrompt。缺席 = 不注入(`off` 臂)。 */
|
|
206
|
+
skillText?: string
|
|
207
|
+
/** 旧参数:既选题又注入。保留为薄包装,既有调用点零改动。 */
|
|
208
|
+
skill?: { name: string; text: string }
|
|
209
|
+
timeoutMs?: number
|
|
210
|
+
}
|
|
211
|
+
|
|
158
212
|
export async function runTaskPerformance(
|
|
159
213
|
llm: Llm,
|
|
160
|
-
opts?:
|
|
214
|
+
opts?: TaskPerformanceOptions,
|
|
161
215
|
): Promise<TaskPerformanceReport> {
|
|
162
216
|
const wanted = opts?.skill?.name
|
|
163
|
-
const tasks =
|
|
217
|
+
const tasks =
|
|
218
|
+
opts?.tasks ?? loadPerformanceTasks().filter((t) => (t.skill ?? undefined) === wanted)
|
|
219
|
+
const systemPrompt = opts?.skillText ?? opts?.skill?.text
|
|
164
220
|
const results: TaskPerformanceResult[] = []
|
|
165
221
|
const startedAt = Date.now()
|
|
166
222
|
let tokensUsed = 0
|
|
@@ -169,17 +225,20 @@ export async function runTaskPerformance(
|
|
|
169
225
|
const { code, truncated, tokens, usageReported } = await collectGeneratedCode(
|
|
170
226
|
llm,
|
|
171
227
|
task.prompt,
|
|
172
|
-
|
|
228
|
+
systemPrompt,
|
|
173
229
|
)
|
|
174
230
|
tokensUsed += tokens
|
|
175
231
|
anyUsageReported = anyUsageReported || usageReported
|
|
176
232
|
if (!code) {
|
|
233
|
+
// 仪器故障与答错必须不同形:provider 连 usage 都没报 ⇒ 这次**没测到**,
|
|
234
|
+
// 不能记成「模型答错」(一次上游抽风会让基线凭空掉分)。
|
|
177
235
|
results.push({
|
|
178
236
|
id: task.id,
|
|
179
237
|
description: task.prompt,
|
|
180
238
|
passed: false,
|
|
181
|
-
detail: 'LLM 未生成代码',
|
|
239
|
+
detail: usageReported ? 'LLM 未生成代码' : '未测得结果:无文本且无 usage(仪器/上游故障)',
|
|
182
240
|
...(truncated ? { truncated: true } : {}),
|
|
241
|
+
...(usageReported ? {} : { uncertain: true }),
|
|
183
242
|
})
|
|
184
243
|
continue
|
|
185
244
|
}
|
|
@@ -197,8 +256,10 @@ export async function runTaskPerformance(
|
|
|
197
256
|
// generation is incomplete by construction; folding those failures into the mean
|
|
198
257
|
// makes the readout (and any improved/regressed verdict derived from it) depend on
|
|
199
258
|
// the output cap rather than on the work.
|
|
200
|
-
const scored = results.filter((r) => !r.truncated)
|
|
201
|
-
const truncated = results.
|
|
259
|
+
const scored = results.filter((r) => !r.truncated && !r.uncertain)
|
|
260
|
+
const truncated = results.filter((r) => r.truncated).length
|
|
261
|
+
// 与 truncated 互斥计数:一条结果可以同时带两个标记,原始计数相加会超过 total。
|
|
262
|
+
const uncertain = results.filter((r) => r.uncertain && !r.truncated).length
|
|
202
263
|
return {
|
|
203
264
|
total: results.length,
|
|
204
265
|
passed,
|
|
@@ -209,6 +270,8 @@ export async function runTaskPerformance(
|
|
|
209
270
|
results,
|
|
210
271
|
failures: results.filter((r) => !r.passed).map((r) => r.id),
|
|
211
272
|
truncated,
|
|
273
|
+
uncertain,
|
|
274
|
+
measurable: scored.length > 0,
|
|
212
275
|
durationMs: Date.now() - startedAt,
|
|
213
276
|
...(anyUsageReported ? { tokensUsed } : {}),
|
|
214
277
|
}
|
|
@@ -282,6 +345,9 @@ export async function measureSkillDelta(
|
|
|
282
345
|
skill: { name: resolved.skillName, text: resolved.postText },
|
|
283
346
|
})
|
|
284
347
|
|
|
348
|
+
// 任一侧没测到 ⇒ 没有可比的 delta(不是 0,也不是「持平」)。
|
|
349
|
+
if (!baseline.measurable || !post.measurable) return null
|
|
350
|
+
|
|
285
351
|
return {
|
|
286
352
|
skillName: resolved.skillName,
|
|
287
353
|
baseline,
|
|
@@ -340,6 +406,9 @@ export async function measureSkillDeltaRepeated(
|
|
|
340
406
|
const r = await runTaskPerformance(llm, {
|
|
341
407
|
skill: { name: resolved.skillName, text: resolved.baselineText },
|
|
342
408
|
})
|
|
409
|
+
// 没测到的一轮不许折成 100 塞进样本:那会把「上游挂了」变成「基线满分」,
|
|
410
|
+
// 进而产出假的 regressed(拦掉一次合法合并)或假的 improved。
|
|
411
|
+
if (!r.measurable) return null
|
|
343
412
|
baselineScores.push(r.score)
|
|
344
413
|
baselineDurations.push(r.durationMs)
|
|
345
414
|
if (r.tokensUsed !== undefined) baselineTokens.push(r.tokensUsed)
|
|
@@ -348,6 +417,7 @@ export async function measureSkillDeltaRepeated(
|
|
|
348
417
|
const r = await runTaskPerformance(llm, {
|
|
349
418
|
skill: { name: resolved.skillName, text: resolved.postText },
|
|
350
419
|
})
|
|
420
|
+
if (!r.measurable) return null
|
|
351
421
|
postScores.push(r.score)
|
|
352
422
|
postDurations.push(r.durationMs)
|
|
353
423
|
if (r.tokensUsed !== undefined) postTokens.push(r.tokensUsed)
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
export const PACKAGE_NAME = '@miphamai/cli' as const
|
|
10
10
|
|
|
11
11
|
/** 当前发布版本 */
|
|
12
|
-
export const PACKAGE_VERSION = '0.85.
|
|
12
|
+
export const PACKAGE_VERSION = '0.85.41' as const
|
|
13
13
|
|
|
14
14
|
/** npm install 全局安装命令 */
|
|
15
15
|
export const NPM_INSTALL_COMMAND = `npm install -g ${PACKAGE_NAME}` as const
|
|
@@ -90,4 +90,4 @@ export const TOOL_COUNT = 31 as const
|
|
|
90
90
|
* —— `test/e2e/full-pipeline.test.ts` 在 Linux 上整文件 skip、在 macOS 上跑 ——
|
|
91
91
|
* 但**总数相同**(两边都把被 skip 的算进去)。
|
|
92
92
|
*/
|
|
93
|
-
export const TEST_COUNT =
|
|
93
|
+
export const TEST_COUNT = 5064 as const
|
package/src/ui/commands.ts
CHANGED
|
@@ -25,7 +25,14 @@ import { miphamHome, workflowScriptDir, workflowScriptDirs, worktreeRoot } from
|
|
|
25
25
|
import { fixDoctor, fixConfig, fixCache, selectRepoClaudeFiles } from '../core/fix'
|
|
26
26
|
import { fixCodeTarget } from '../core/fix-code'
|
|
27
27
|
import { homedir } from 'node:os'
|
|
28
|
-
import {
|
|
28
|
+
import {
|
|
29
|
+
runCrsiModification,
|
|
30
|
+
approvePending,
|
|
31
|
+
rejectPending,
|
|
32
|
+
hasPending,
|
|
33
|
+
setPendingProbation,
|
|
34
|
+
} from '../core/crsi-modify'
|
|
35
|
+
import { settleProbation, formatProbationLines, PROBATION_WINDOW } from '../core/probation'
|
|
29
36
|
import {
|
|
30
37
|
produceCrsiProposal,
|
|
31
38
|
produceRuleProposal,
|
|
@@ -61,7 +68,9 @@ import {
|
|
|
61
68
|
runTaskPerformance,
|
|
62
69
|
measureSkillDeltaRepeated,
|
|
63
70
|
stripCodeFences,
|
|
71
|
+
loadPerformanceTasks,
|
|
64
72
|
} from '../core/task-performance'
|
|
73
|
+
import { measureCapture, measureSealed } from '../core/capture-measure'
|
|
65
74
|
import { randomUUID } from 'node:crypto'
|
|
66
75
|
import {
|
|
67
76
|
buildImprovementReport,
|
|
@@ -1075,6 +1084,9 @@ const crsiStatsCmd: CommandHandler = async (ctx) => {
|
|
|
1075
1084
|
}
|
|
1076
1085
|
}
|
|
1077
1086
|
|
|
1087
|
+
// ── 试用期:未结窗口也打出来(「开了没读数」与「从未开窗」不同形) ──
|
|
1088
|
+
lines.push(...formatProbationLines())
|
|
1089
|
+
|
|
1078
1090
|
return { content: lines.join('\n') }
|
|
1079
1091
|
}
|
|
1080
1092
|
|
|
@@ -1111,9 +1123,19 @@ async function measureModification(
|
|
|
1111
1123
|
): Promise<string> {
|
|
1112
1124
|
const llm = ctx.engine.getLlm() ?? ctx.engine.getRegistry()
|
|
1113
1125
|
let improvementLine = ''
|
|
1126
|
+
// 先清空:非 skill 文件 / 没量到样本 / 抛错,都不该留下上一轮的基线。
|
|
1127
|
+
setPendingProbation(null)
|
|
1114
1128
|
try {
|
|
1115
1129
|
const sample = await measureSkillDeltaRepeated(llm, params)
|
|
1116
1130
|
if (sample) {
|
|
1131
|
+
// 试用期基线 = 合并后的那一臂(postScores)。窗口问的是「合并后会不会回落」,
|
|
1132
|
+
// 不是「这次改动涨了多少」。没有测量就不开窗(不让旧基线挂到新合并上)。
|
|
1133
|
+
setPendingProbation({
|
|
1134
|
+
filePath: params.filePath,
|
|
1135
|
+
skillName: sample.skillName,
|
|
1136
|
+
baselineScores: sample.postScores,
|
|
1137
|
+
poolSize: loadPerformanceTasks().filter((t) => t.skill === sample.skillName).length,
|
|
1138
|
+
})
|
|
1117
1139
|
const report = buildImprovementReport(sample, [params.filePath], undefined, {
|
|
1118
1140
|
// 手工路径没有失败信号,问题键就取「这次想修什么」的规范化描述:
|
|
1119
1141
|
// 同一句话被反复修时,它们才聚得起来。
|
|
@@ -1145,6 +1167,7 @@ async function measureModification(
|
|
|
1145
1167
|
}
|
|
1146
1168
|
} catch {
|
|
1147
1169
|
// 测量失败(LLM 不可用等)不阻断 modify 流程——改进信号是可选的。
|
|
1170
|
+
setPendingProbation(null)
|
|
1148
1171
|
}
|
|
1149
1172
|
return improvementLine
|
|
1150
1173
|
}
|
|
@@ -1156,7 +1179,11 @@ const crsiModifyCmd: CommandHandler = async (ctx, args) => {
|
|
|
1156
1179
|
}
|
|
1157
1180
|
const r = approvePending()
|
|
1158
1181
|
setPendingVerdict(null)
|
|
1159
|
-
|
|
1182
|
+
if (!r.success) return { content: `⚠️ ${r.message}` }
|
|
1183
|
+
const probationNote = r.probationOpened
|
|
1184
|
+
? `\n🧪 已开启试用期:后续 ${PROBATION_WINDOW} 次同口径重测(同 skill、gate 池、k≥3)后出裁定;退化只提示回退,不自动执行。`
|
|
1185
|
+
: ''
|
|
1186
|
+
return { content: `✅ ${r.message}${probationNote}` }
|
|
1160
1187
|
}
|
|
1161
1188
|
if (args[0] === '--reject') {
|
|
1162
1189
|
const r = rejectPending()
|
|
@@ -1653,13 +1680,152 @@ const crsiBenchCmd: CommandHandler = async (ctx, args) => {
|
|
|
1653
1680
|
skill = { name: skillName, text: body }
|
|
1654
1681
|
}
|
|
1655
1682
|
|
|
1683
|
+
if (args.includes('--sealed')) {
|
|
1684
|
+
if (!skill) {
|
|
1685
|
+
return {
|
|
1686
|
+
content: '❌ `--sealed` 需要 `--skill <name>`:sealed 是「某份 skill」的留出集。',
|
|
1687
|
+
}
|
|
1688
|
+
}
|
|
1689
|
+
const kIdx = args.indexOf('--k')
|
|
1690
|
+
// 缺省 1:sealed 出的是旁证数,不是裁定数,没必要一上手就烧 k 轮。
|
|
1691
|
+
const k = kIdx >= 0 ? Math.max(1, Number(args[kIdx + 1]) || 1) : 1
|
|
1692
|
+
const s = await measureSealed(llm, { skillName: skill.name, skillText: skill.text, k })
|
|
1693
|
+
const avg = s.off.length > 0 ? s.off.reduce((a, r) => a + r.score, 0) / s.off.length : 0
|
|
1694
|
+
const avgOn = s.on.length > 0 ? s.on.reduce((a, r) => a + r.score, 0) / s.on.length : 0
|
|
1695
|
+
const lines = [
|
|
1696
|
+
`## 🧪 sealed 留出集(skill: ${skill.name}, k=${k})`,
|
|
1697
|
+
'',
|
|
1698
|
+
`off 均分: **${avg.toFixed(1)}/100** · on 均分: **${avgOn.toFixed(1)}/100**`,
|
|
1699
|
+
]
|
|
1700
|
+
if (!s.oraclePassed) {
|
|
1701
|
+
lines.push('', '❌ 参考解未过自己的冻结测试 ⇒ 该读数不可信(先修题或参考解)。')
|
|
1702
|
+
} else if (s.capture.rate === null) {
|
|
1703
|
+
lines.push(
|
|
1704
|
+
'',
|
|
1705
|
+
`没有率:${s.capture.tasksTotal} 题里没有一道有 headroom(off 已满分)—— 这不是 0。`,
|
|
1706
|
+
)
|
|
1707
|
+
} else {
|
|
1708
|
+
lines.push(
|
|
1709
|
+
'',
|
|
1710
|
+
`rate = ${s.capture.numerator.toFixed(1)}/${s.capture.denominator.toFixed(1)} over ${s.capture.tasksUsed} of ${s.capture.tasksTotal} tasks ⇒ **${(s.capture.rate * 100).toFixed(1)}%**`,
|
|
1711
|
+
)
|
|
1712
|
+
}
|
|
1713
|
+
lines.push(
|
|
1714
|
+
'',
|
|
1715
|
+
'sealed 不进裁定:不加分、不开试用期 —— 它只答「gate 上的捕获率是不是过拟合」(进裁定 = 把留出集当考场)。',
|
|
1716
|
+
)
|
|
1717
|
+
return { content: lines.join('\n') }
|
|
1718
|
+
}
|
|
1719
|
+
|
|
1720
|
+
if (args.includes('--capture')) {
|
|
1721
|
+
if (!skill) {
|
|
1722
|
+
return {
|
|
1723
|
+
content:
|
|
1724
|
+
'❌ `--capture` 需要 `--skill <name>`:捕获率是「某份 skill 文本吃到了多少上界」。',
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
const kIdx = args.indexOf('--k')
|
|
1728
|
+
const k = kIdx >= 0 ? Math.max(1, Number(args[kIdx + 1]) || 3) : 3
|
|
1729
|
+
const m = await measureCapture(llm, { skillName: skill.name, skillText: skill.text, k })
|
|
1730
|
+
const c = m.capture
|
|
1731
|
+
const average = (runs: typeof m.off) =>
|
|
1732
|
+
runs.length > 0 ? runs.reduce((a, r) => a + r.score, 0) / runs.length : 0
|
|
1733
|
+
const all = [...m.off, ...m.on]
|
|
1734
|
+
const tokens = all.every((r) => r.tokensUsed !== undefined)
|
|
1735
|
+
? all.reduce((a, r) => a + (r.tokensUsed ?? 0), 0)
|
|
1736
|
+
: undefined
|
|
1737
|
+
const lines = [
|
|
1738
|
+
`## 🎯 捕获率(skill: ${skill.name}, k=${k})`,
|
|
1739
|
+
'',
|
|
1740
|
+
`off 均分: **${average(m.off).toFixed(1)}/100** · on 均分: **${average(m.on).toFixed(1)}/100**`,
|
|
1741
|
+
]
|
|
1742
|
+
if (!m.oraclePassed) {
|
|
1743
|
+
lines.push('', '❌ 参考解未全过自己的冻结测试 ⇒ 上界不可信,**本轮作废**。先修题或参考解。')
|
|
1744
|
+
} else if (c.rate === null) {
|
|
1745
|
+
lines.push(
|
|
1746
|
+
'',
|
|
1747
|
+
`没有率:${c.tasksTotal} 题里没有一道有 headroom(off 已满分)—— 这不是 0,也不是通过。`,
|
|
1748
|
+
)
|
|
1749
|
+
} else {
|
|
1750
|
+
const ci = c.ci
|
|
1751
|
+
? `; 95% CI ${(c.ci.lo * 100).toFixed(1)}%–${(c.ci.hi * 100).toFixed(1)}%`
|
|
1752
|
+
: '; 区间不可得'
|
|
1753
|
+
lines.push(
|
|
1754
|
+
'',
|
|
1755
|
+
`rate = ${c.numerator.toFixed(1)}/${c.denominator.toFixed(1)} over ${c.tasksUsed} of ${c.tasksTotal} tasks${ci} ⇒ **${(c.rate * 100).toFixed(1)}%**`,
|
|
1756
|
+
)
|
|
1757
|
+
}
|
|
1758
|
+
if (c.noHeadroom.length > 0) lines.push('', `无 headroom: ${c.noHeadroom.join(', ')}`)
|
|
1759
|
+
if (c.dropped.length > 0) lines.push('', `配对剔除: ${c.dropped.join(', ')}`)
|
|
1760
|
+
|
|
1761
|
+
// 正对照(零成本):同一臂喂两侧必须**恰好**得 0。不为 0 ⇒ 臂接反 / 池映射错,
|
|
1762
|
+
// 分子分母再漂亮也是另一个对象的读数。为 null ⇒ on 臂全程无 headroom,本轮没验证到。
|
|
1763
|
+
const controlBroken = m.controlRate !== null && m.controlRate !== 0
|
|
1764
|
+
if (m.controlRate === null) {
|
|
1765
|
+
lines.push('', '正对照: 不可得(off 臂全程无 headroom,本轮本来也没有率)')
|
|
1766
|
+
} else if (controlBroken) {
|
|
1767
|
+
lines.push(
|
|
1768
|
+
'',
|
|
1769
|
+
`❌ 正对照 = **${(m.controlRate * 100).toFixed(1)}%**(应恰为 0)⇒ 分子/分母/臂映射至少有一处接错了,**本轮读数不可信**。`,
|
|
1770
|
+
)
|
|
1771
|
+
}
|
|
1772
|
+
|
|
1773
|
+
// sealed 旁证:只说过拟合,不进任何裁定(设计 §4.3)。
|
|
1774
|
+
const sc = m.sealed.capture
|
|
1775
|
+
if (!m.sealed.oraclePassed) {
|
|
1776
|
+
lines.push('', 'sealed 旁证: 参考解未过自己的冻结测试 ⇒ 不可读')
|
|
1777
|
+
} else if (sc.rate === null) {
|
|
1778
|
+
lines.push('', `sealed 旁证: 无率(${sc.tasksTotal} 题里没有一道有 headroom)`)
|
|
1779
|
+
} else {
|
|
1780
|
+
lines.push(
|
|
1781
|
+
'',
|
|
1782
|
+
`sealed 旁证: **${(sc.rate * 100).toFixed(1)}%**(${sc.tasksUsed}/${sc.tasksTotal} 题;只作过拟合旁证,不进裁定)`,
|
|
1783
|
+
)
|
|
1784
|
+
}
|
|
1785
|
+
|
|
1786
|
+
const unmeasurable = all.filter((r) => !r.measurable).length
|
|
1787
|
+
if (unmeasurable > 0) {
|
|
1788
|
+
lines.push('', `⚠️ ${unmeasurable} 次运行不可测(仪器故障或截断)⇒ 本轮不是一次合格重测`)
|
|
1789
|
+
}
|
|
1790
|
+
lines.push(
|
|
1791
|
+
'',
|
|
1792
|
+
tokens === undefined ? 'RSI Tax: 未测(有运行没报 usage)' : `RSI Tax: ${tokens} tokens`,
|
|
1793
|
+
)
|
|
1794
|
+
|
|
1795
|
+
// 只有 k≥3 才算一次合格重测;k=1 的冒烟永不进观察窗(设计 §4.4)。
|
|
1796
|
+
// 且必须**三项前提同时成立**:参考解可信 · 正对照为 0 · 每轮都可测。否则这一轮
|
|
1797
|
+
// 读数是真的、但描述的不是被测 skill —— 拿它推进观察窗,等于往窗口里掺沙子。
|
|
1798
|
+
const canSettle =
|
|
1799
|
+
k >= 3 && m.oraclePassed && !controlBroken && unmeasurable === 0 && c.rate !== null
|
|
1800
|
+
if (canSettle) {
|
|
1801
|
+
const rec = settleProbation(skill.name, average(m.on))
|
|
1802
|
+
if (rec) {
|
|
1803
|
+
lines.push(
|
|
1804
|
+
'',
|
|
1805
|
+
rec.verdict
|
|
1806
|
+
? `试用期: ${rec.checks.length}/${PROBATION_WINDOW} → ${rec.verdict}`
|
|
1807
|
+
: `试用期: ${rec.checks.length}/${PROBATION_WINDOW} —— 观察中`,
|
|
1808
|
+
)
|
|
1809
|
+
}
|
|
1810
|
+
} else if (k >= 3) {
|
|
1811
|
+
lines.push('', '试用期: 本轮未推进(观察窗只收前提成立的整轮)')
|
|
1812
|
+
}
|
|
1813
|
+
return { content: lines.join('\n') }
|
|
1814
|
+
}
|
|
1815
|
+
|
|
1656
1816
|
const report = await runTaskPerformance(llm, skill ? { skill } : undefined)
|
|
1657
1817
|
|
|
1658
1818
|
const lines: string[] = [
|
|
1659
1819
|
'## 🎯 CRSI 任务表现基准' + (skill ? `(skill: ${skill.name})` : ''),
|
|
1660
1820
|
'',
|
|
1661
1821
|
]
|
|
1662
|
-
|
|
1822
|
+
// `measurable === false` 时 score 的 100 是「无题可评分」的占位,不是满分。
|
|
1823
|
+
lines.push(
|
|
1824
|
+
report.measurable
|
|
1825
|
+
? `得分: **${report.score}/100** (${report.passed}/${report.total})`
|
|
1826
|
+
: `得分: **未测得**(0 道题可评分;${report.total} 题全是仪器故障或截断)`,
|
|
1827
|
+
'',
|
|
1828
|
+
)
|
|
1663
1829
|
lines.push('| 任务 | 结果 |')
|
|
1664
1830
|
lines.push('|------|------|')
|
|
1665
1831
|
for (const r of report.results) {
|
|
@@ -7133,7 +7299,8 @@ const COMMAND_DESCRIPTIONS: Record<string, string> = {
|
|
|
7133
7299
|
'固化 CRSI 失败信号(默认教训 / --rule 受管理规则 / --prose 改 skill 散文),沙箱 + 人批准门控',
|
|
7134
7300
|
'/crsi prose-clear': '清空散文提议去重 ledger(~/.mipham/crsi/prose-proposals.jsonl)',
|
|
7135
7301
|
'/crsi eval': 'Run the ground-truth CRSI eval harness and record the score',
|
|
7136
|
-
'/crsi bench':
|
|
7302
|
+
'/crsi bench':
|
|
7303
|
+
'Run the LLM task-performance benchmark(--capture 出捕获率,--sealed 出留出集旁证,均需 --skill)',
|
|
7137
7304
|
'/crsi meta': 'RSI Level 3 meta-rule analysis — rules that improve the rules',
|
|
7138
7305
|
'/crsi interpret': 'Tool-call behavior dashboard — error patterns, usage, health',
|
|
7139
7306
|
'/crsi critique': 'Enable/disable RLAIF self-critique on tool calls',
|