@miphamai/cli 0.85.37 → 0.85.39
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/skills/standard/code-review.SKILL.md +17 -0
- package/skills/standard/research.SKILL.md +13 -3
- package/src/core/crsi-modify.ts +41 -6
- package/src/core/crsi-sandbox.ts +5 -0
- package/src/core/engine.ts +6 -0
- package/src/core/eval-harness.ts +106 -0
- package/src/core/improvement-track.ts +91 -0
- package/src/core/proposal-integration.ts +149 -0
- package/src/core/task-performance.ts +41 -3
- package/src/mcp/registry.ts +32 -0
- package/src/shared/package-info.ts +2 -2
- package/src/skills/bundled-skills.ts +112 -28
- package/src/ui/commands.ts +216 -34
package/src/ui/commands.ts
CHANGED
|
@@ -47,10 +47,12 @@ import {
|
|
|
47
47
|
MANAGED_RULES_FILE,
|
|
48
48
|
} from '../core/crsi-producer'
|
|
49
49
|
import { prefilterProposal } from '../core/proposal-guard'
|
|
50
|
+
import { integrateProposals, formatIntegrationSummary } from '../core/proposal-integration'
|
|
50
51
|
import {
|
|
51
52
|
runEval,
|
|
52
53
|
appendEvalScore,
|
|
53
54
|
getContractHistory,
|
|
55
|
+
getLastEvalScore,
|
|
54
56
|
diffContractHistory,
|
|
55
57
|
renderContractDiff,
|
|
56
58
|
} from '../core/eval-harness'
|
|
@@ -65,6 +67,10 @@ import {
|
|
|
65
67
|
buildImprovementReport,
|
|
66
68
|
formatCostLine,
|
|
67
69
|
formatNullModelLine,
|
|
70
|
+
formatRsiTaxLine,
|
|
71
|
+
normalizeProblemKey,
|
|
72
|
+
groupImprovementsByProblem,
|
|
73
|
+
measurementTaxSummary,
|
|
68
74
|
appendImprovement,
|
|
69
75
|
readImprovements,
|
|
70
76
|
improvementRate,
|
|
@@ -1033,6 +1039,42 @@ const crsiStatsCmd: CommandHandler = async (ctx) => {
|
|
|
1033
1039
|
)
|
|
1034
1040
|
}
|
|
1035
1041
|
|
|
1042
|
+
// ── SIM:按问题分组(只读视图;分组不是过滤器,无键的旧记录仍在总台账里) ──
|
|
1043
|
+
const groups = groupImprovementsByProblem(records)
|
|
1044
|
+
lines.push('')
|
|
1045
|
+
lines.push('### 改进台账按问题分组(SIM)')
|
|
1046
|
+
if (groups.length === 0) {
|
|
1047
|
+
lines.push('暂无带问题键的记录(旧记录没有 problemKey —— 读作「未分组」,不是「没有问题」)。')
|
|
1048
|
+
} else {
|
|
1049
|
+
for (const g of groups.slice(0, 10)) {
|
|
1050
|
+
const sign = g.meanDelta >= 0 ? '+' : ''
|
|
1051
|
+
lines.push(
|
|
1052
|
+
`- ${g.key}: ${g.improved}/${g.total} improved(均值 delta ${sign}${g.meanDelta.toFixed(1)})`,
|
|
1053
|
+
)
|
|
1054
|
+
}
|
|
1055
|
+
if (groups.length > 10) lines.push(`… 另有 ${groups.length - 10} 组未列出`)
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
// ── RSI Tax:验证成本(只记录、只展示,不进任何判定) ──
|
|
1059
|
+
const tax = measurementTaxSummary(records)
|
|
1060
|
+
lines.push('')
|
|
1061
|
+
lines.push('### 验证成本(RSI Tax)')
|
|
1062
|
+
if (tax.records === 0) {
|
|
1063
|
+
lines.push('暂无带 token 量的记录(provider 未报 usage,或旧记录早于本维)。')
|
|
1064
|
+
} else {
|
|
1065
|
+
lines.push(
|
|
1066
|
+
`${tax.records} 条记录 · 合计 ${tax.totalTokens.toLocaleString()} tokens · 均值 ${tax.meanTokens.toLocaleString()}/条`,
|
|
1067
|
+
)
|
|
1068
|
+
// 0-token 基线:确定性 eval 不调 LLM,是同一批机制契约的免费读数。
|
|
1069
|
+
// 两个数回答的不是同一问题,故只做成本对照,不合并成一个「值不值」。
|
|
1070
|
+
const evalScore = getLastEvalScore('mechanism-sentinel')
|
|
1071
|
+
if (evalScore !== null) {
|
|
1072
|
+
lines.push(
|
|
1073
|
+
`0-token 基线: 确定性 eval 最近一次 ${evalScore}/100(不消耗 token;与上面的测量不是同一问题,仅作成本对照)`,
|
|
1074
|
+
)
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1036
1078
|
return { content: lines.join('\n') }
|
|
1037
1079
|
}
|
|
1038
1080
|
|
|
@@ -1049,8 +1091,62 @@ const crsiInventoryCmd: CommandHandler = async (ctx) => {
|
|
|
1049
1091
|
*
|
|
1050
1092
|
* 无附注时返回空串,且**调用点保持逐字不变**(附注前不补空行,附注后自带一个)。
|
|
1051
1093
|
*/
|
|
1052
|
-
function renderGateNote(result: { rewardNote?: string }): string {
|
|
1053
|
-
|
|
1094
|
+
function renderGateNote(result: { rewardNote?: string; regretNote?: string }): string {
|
|
1095
|
+
const lines: string[] = []
|
|
1096
|
+
if (result.rewardNote) lines.push(`⚠️ 奖励闸附注:${result.rewardNote}`)
|
|
1097
|
+
if (result.regretNote) lines.push(`🪞 方向性 regret:${result.regretNote}`)
|
|
1098
|
+
return lines.length > 0 ? lines.join('\n') + '\n' : ''
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
/**
|
|
1102
|
+
* 单提案与整合提案共用的「过闸后测量」段。
|
|
1103
|
+
*
|
|
1104
|
+
* 抽出来**只**为了不复制这段(它与闸本身无关):手工路径与 ELITE 整合路径
|
|
1105
|
+
* 对同一个 `filePath/newContent` 做完全相同的测量与渲染。prose 路径**不**并进来 ——
|
|
1106
|
+
* 它有 ε 预测与自己的渲染形状,合并只会让两条语义不同的路互相污染。
|
|
1107
|
+
*/
|
|
1108
|
+
async function measureModification(
|
|
1109
|
+
ctx: Parameters<CommandHandler>[0],
|
|
1110
|
+
params: { description: string; filePath: string; originalContent: string; newContent: string },
|
|
1111
|
+
): Promise<string> {
|
|
1112
|
+
const llm = ctx.engine.getLlm() ?? ctx.engine.getRegistry()
|
|
1113
|
+
let improvementLine = ''
|
|
1114
|
+
try {
|
|
1115
|
+
const sample = await measureSkillDeltaRepeated(llm, params)
|
|
1116
|
+
if (sample) {
|
|
1117
|
+
const report = buildImprovementReport(sample, [params.filePath], undefined, {
|
|
1118
|
+
// 手工路径没有失败信号,问题键就取「这次想修什么」的规范化描述:
|
|
1119
|
+
// 同一句话被反复修时,它们才聚得起来。
|
|
1120
|
+
problemKey: normalizeProblemKey(params.description),
|
|
1121
|
+
rationale: params.description,
|
|
1122
|
+
})
|
|
1123
|
+
setPendingVerdict(report.verdict)
|
|
1124
|
+
appendImprovement({ ...report, id: randomUUID(), timestamp: new Date().toISOString() })
|
|
1125
|
+
const rate = improvementRate(readImprovements())
|
|
1126
|
+
const label =
|
|
1127
|
+
report.verdict === 'improved'
|
|
1128
|
+
? 'improved ✅'
|
|
1129
|
+
: report.verdict === 'regressed'
|
|
1130
|
+
? 'regressed ⚠️'
|
|
1131
|
+
: 'inconclusive'
|
|
1132
|
+
const sign = report.deltaMean >= 0 ? '+' : ''
|
|
1133
|
+
// B2 代价维:只展示、不进判定(`formatCostLine` 缺席时返回 null ⇒ 整行不打)。
|
|
1134
|
+
const costLine = formatCostLine(report)
|
|
1135
|
+
// 空模型闸:只在闸失败时出声;它解释了 verdict 为什么被降级。
|
|
1136
|
+
const nullLine = formatNullModelLine(report)
|
|
1137
|
+
const taxLine = formatRsiTaxLine(report)
|
|
1138
|
+
improvementLine =
|
|
1139
|
+
`\n📊 改进判定: ${label} (delta ${sign}${report.deltaMean.toFixed(1)}, 噪声 ${report.noise.toFixed(1)}, 阈值 ${report.minEffect.toFixed(1)})` +
|
|
1140
|
+
`\n 改进率: ${rate.improved}/${rate.total} (${(rate.rate * 100).toFixed(0)}%, Wilson 95% [${(rate.lo * 100).toFixed(0)}%, ${(rate.hi * 100).toFixed(0)}%])` +
|
|
1141
|
+
(costLine ? `\n${costLine}` : '') +
|
|
1142
|
+
(taxLine ? `\n${taxLine}` : '') +
|
|
1143
|
+
(nullLine ? `\n${nullLine}` : '') +
|
|
1144
|
+
(report.verdict === 'regressed' ? '\n ⚠️ 任务表现倒退:--approve 将被拒绝。' : '')
|
|
1145
|
+
}
|
|
1146
|
+
} catch {
|
|
1147
|
+
// 测量失败(LLM 不可用等)不阻断 modify 流程——改进信号是可选的。
|
|
1148
|
+
}
|
|
1149
|
+
return improvementLine
|
|
1054
1150
|
}
|
|
1055
1151
|
|
|
1056
1152
|
const crsiModifyCmd: CommandHandler = async (ctx, args) => {
|
|
@@ -1067,10 +1163,97 @@ const crsiModifyCmd: CommandHandler = async (ctx, args) => {
|
|
|
1067
1163
|
setPendingVerdict(null)
|
|
1068
1164
|
return { content: r.success ? `✅ ${r.message}` : `⚠️ ${r.message}` }
|
|
1069
1165
|
}
|
|
1166
|
+
if (args[0] === '--integrate') {
|
|
1167
|
+
// ELITE(2611.21056):多提案 → 兼容子集 → 一个后代。
|
|
1168
|
+
// 每个提案是一个文件,内容是该提案下的**完整目标文件**;以当前目标为共同父本做 3-way merge。
|
|
1169
|
+
const dropConflicts = args[1] === '--drop-conflicts'
|
|
1170
|
+
const rest = args.slice(dropConflicts ? 2 : 1)
|
|
1171
|
+
if (rest.length < 4) {
|
|
1172
|
+
return {
|
|
1173
|
+
content:
|
|
1174
|
+
'Usage: /crsi modify --integrate [--drop-conflicts] <description> <filePath> <proposal1> <proposal2> [...]\n' +
|
|
1175
|
+
'- 每个 proposalN 是一个文件,内容为该提案下的完整目标文件\n' +
|
|
1176
|
+
'- 冲突默认拒绝;--drop-conflicts 只整合兼容子集(不静默丢弃机制)',
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
if (hasPending()) {
|
|
1180
|
+
return { content: '⚠️ 已有待批准的修改。先 /crsi modify --approve 或 --reject。' }
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
const description = rest[0]!
|
|
1184
|
+
const filePath = rest[1]!
|
|
1185
|
+
const { readFileSync } = await import('node:fs')
|
|
1186
|
+
const { join } = await import('node:path')
|
|
1187
|
+
const resolvePath = (p: string) => (p.startsWith('/') ? p : join(process.cwd(), p))
|
|
1188
|
+
|
|
1189
|
+
let originalContent: string
|
|
1190
|
+
try {
|
|
1191
|
+
originalContent = readFileSync(resolvePath(filePath), 'utf-8')
|
|
1192
|
+
} catch {
|
|
1193
|
+
return { content: `❌ 整合需要可读的父本:${filePath}` }
|
|
1194
|
+
}
|
|
1195
|
+
const proposals: Array<{ name: string; content: string }> = []
|
|
1196
|
+
for (const p of rest.slice(2)) {
|
|
1197
|
+
try {
|
|
1198
|
+
proposals.push({ name: p, content: readFileSync(resolvePath(p), 'utf-8') })
|
|
1199
|
+
} catch {
|
|
1200
|
+
return { content: `❌ 读不到提案文件:${p}` }
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
const integration = integrateProposals(originalContent, proposals)
|
|
1205
|
+
if (integration.error) {
|
|
1206
|
+
return { content: `❌ 整合失败:${integration.error}` }
|
|
1207
|
+
}
|
|
1208
|
+
const summary = formatIntegrationSummary(integration)
|
|
1209
|
+
const conflictList = integration.conflicts.map((c) => c.name).join(', ')
|
|
1210
|
+
if (integration.conflicts.length > 0 && !dropConflicts) {
|
|
1211
|
+
return {
|
|
1212
|
+
content:
|
|
1213
|
+
`⚠️ 整合冲突:${conflictList}\n${summary}\n` +
|
|
1214
|
+
'冲突意味着两个提案改了同一段。默认不丢弃任何机制——\n' +
|
|
1215
|
+
'用 --drop-conflicts 只整合兼容子集,或先把提案收敛成一个。',
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
if (!integration.content || integration.content === originalContent) {
|
|
1219
|
+
return { content: `⚠️ 没有可整合的改动。\n${summary}` }
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
const result = await runCrsiModification({
|
|
1223
|
+
description,
|
|
1224
|
+
filePath,
|
|
1225
|
+
newContent: integration.content,
|
|
1226
|
+
originalContent,
|
|
1227
|
+
blastRadius: [filePath],
|
|
1228
|
+
})
|
|
1229
|
+
if (!result.applied || result.phase === 'failed') {
|
|
1230
|
+
return {
|
|
1231
|
+
content: `❌ 整合未通过(phase: ${result.phase})。\n${result.error ?? ''}`,
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
const improvementLine = await measureModification(ctx, {
|
|
1236
|
+
description,
|
|
1237
|
+
filePath,
|
|
1238
|
+
originalContent,
|
|
1239
|
+
newContent: integration.content,
|
|
1240
|
+
})
|
|
1241
|
+
const conflictNote = integration.conflicts.length > 0 ? ` · 丢弃冲突 ${conflictList}` : ''
|
|
1242
|
+
return {
|
|
1243
|
+
content:
|
|
1244
|
+
`✅ 测试通过。🧩 整合:${summary}${conflictNote}\n` +
|
|
1245
|
+
renderGateNote(result) +
|
|
1246
|
+
`\n${result.diff}\n` +
|
|
1247
|
+
improvementLine +
|
|
1248
|
+
'\n/crsi modify --approve 合并\n/crsi modify --reject 丢弃',
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1070
1252
|
if (args.length < 3) {
|
|
1071
1253
|
return {
|
|
1072
1254
|
content:
|
|
1073
1255
|
'Usage: /crsi modify <description> <filePath> <newContent>\n' +
|
|
1256
|
+
' /crsi modify --integrate [--drop-conflicts] <description> <filePath> <proposal1> <proposal2> [...]\n' +
|
|
1074
1257
|
'- description 单 token(不含空格)\n' +
|
|
1075
1258
|
'- newContent 用 \\n 表示换行\n' +
|
|
1076
1259
|
'测试通过后:/crsi modify --approve 合并,/crsi modify --reject 丢弃',
|
|
@@ -1107,36 +1290,12 @@ const crsiModifyCmd: CommandHandler = async (ctx, args) => {
|
|
|
1107
1290
|
}
|
|
1108
1291
|
|
|
1109
1292
|
// 测量在 runCrsiModification 成功后进行(避免 failed proposal 白跑 6 次 LLM 调用)。
|
|
1110
|
-
const
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
setPendingVerdict(report.verdict)
|
|
1117
|
-
appendImprovement({ ...report, id: randomUUID(), timestamp: new Date().toISOString() })
|
|
1118
|
-
const rate = improvementRate(readImprovements())
|
|
1119
|
-
const label =
|
|
1120
|
-
report.verdict === 'improved'
|
|
1121
|
-
? 'improved ✅'
|
|
1122
|
-
: report.verdict === 'regressed'
|
|
1123
|
-
? 'regressed ⚠️'
|
|
1124
|
-
: 'inconclusive'
|
|
1125
|
-
const sign = report.deltaMean >= 0 ? '+' : ''
|
|
1126
|
-
// B2 代价维:只展示、不进判定(`formatCostLine` 缺席时返回 null ⇒ 整行不打)。
|
|
1127
|
-
const costLine = formatCostLine(report)
|
|
1128
|
-
// 空模型闸:只在闸失败时出声;它解释了 verdict 为什么被降级。
|
|
1129
|
-
const nullLine = formatNullModelLine(report)
|
|
1130
|
-
improvementLine =
|
|
1131
|
-
`\n📊 改进判定: ${label} (delta ${sign}${report.deltaMean.toFixed(1)}, 噪声 ${report.noise.toFixed(1)}, 阈值 ${report.minEffect.toFixed(1)})` +
|
|
1132
|
-
`\n 改进率: ${rate.improved}/${rate.total} (${(rate.rate * 100).toFixed(0)}%, Wilson 95% [${(rate.lo * 100).toFixed(0)}%, ${(rate.hi * 100).toFixed(0)}%])` +
|
|
1133
|
-
(costLine ? `\n${costLine}` : '') +
|
|
1134
|
-
(nullLine ? `\n${nullLine}` : '') +
|
|
1135
|
-
(report.verdict === 'regressed' ? '\n ⚠️ 任务表现倒退:--approve 将被拒绝。' : '')
|
|
1136
|
-
}
|
|
1137
|
-
} catch {
|
|
1138
|
-
// 测量失败(LLM 不可用等)不阻断 modify 流程——改进信号是可选的。
|
|
1139
|
-
}
|
|
1293
|
+
const improvementLine = await measureModification(ctx, {
|
|
1294
|
+
description,
|
|
1295
|
+
filePath,
|
|
1296
|
+
originalContent,
|
|
1297
|
+
newContent,
|
|
1298
|
+
})
|
|
1140
1299
|
|
|
1141
1300
|
return {
|
|
1142
1301
|
content:
|
|
@@ -1237,7 +1396,17 @@ const crsiProposeCmd: CommandHandler = async (ctx, args) => {
|
|
|
1237
1396
|
newContent: proposal.newContent,
|
|
1238
1397
|
})
|
|
1239
1398
|
if (sample) {
|
|
1240
|
-
const report = buildImprovementReport(
|
|
1399
|
+
const report = buildImprovementReport(
|
|
1400
|
+
sample,
|
|
1401
|
+
[proposal.filePath],
|
|
1402
|
+
proposal.expectedEffect,
|
|
1403
|
+
{
|
|
1404
|
+
// prose 路径有失败信号:分组键取「类别 + 标题」,同一类失败
|
|
1405
|
+
// 反复出现时才能看出这个环到底在修同一件事还是到处救火。
|
|
1406
|
+
problemKey: normalizeProblemKey(`${signal.category}: ${signal.title}`),
|
|
1407
|
+
rationale: proposal.description,
|
|
1408
|
+
},
|
|
1409
|
+
)
|
|
1241
1410
|
setPendingVerdict(report.verdict)
|
|
1242
1411
|
appendImprovement({ ...report, id: randomUUID(), timestamp: new Date().toISOString() })
|
|
1243
1412
|
if (report.predictionHit !== undefined) {
|
|
@@ -1249,6 +1418,9 @@ const crsiProposeCmd: CommandHandler = async (ctx, args) => {
|
|
|
1249
1418
|
// 「局部正确全局遗漏」)。ε 行可以有、代价行可以没有,故各自独立追加。
|
|
1250
1419
|
const costLine = formatCostLine(report)
|
|
1251
1420
|
if (costLine) predictionLine += `\n${costLine}`
|
|
1421
|
+
// RSI Tax 同理:两条渲染路径都接(只接一条 = 局部正确全局遗漏)。
|
|
1422
|
+
const taxLine = formatRsiTaxLine(report)
|
|
1423
|
+
if (taxLine) predictionLine += `\n${taxLine}`
|
|
1252
1424
|
// 空模型闸同理:两条渲染路径都接。
|
|
1253
1425
|
const nullLine = formatNullModelLine(report)
|
|
1254
1426
|
if (nullLine) predictionLine += `\n${nullLine}`
|
|
@@ -4148,7 +4320,17 @@ const codeReviewCmd = gitDiffBridgeCmd({
|
|
|
4148
4320
|
// 写成句末时模型容易先按默认深度铺开、再拿档位去追认。`max` 另有一句上限:
|
|
4149
4321
|
// 仓里存的可能是上一轮自己挑的,而不是用户这一轮要的 —— 只有**用户点名**才用。
|
|
4150
4322
|
const effort = getPreference('lastCodeReviewEffort', 'high')
|
|
4151
|
-
|
|
4323
|
+
// 范围与 `/simplify` 分开:整理(复用/简化/效率)有自己的命令,混进评审会让
|
|
4324
|
+
// 「这次改动有没有 bug」这个唯一的问题被风格建议稀释。严重度三档是**归属**,
|
|
4325
|
+
// 不是风险等级 —— 读的人先要判断的是「这是我这次弄坏的,还是本来就有的」。
|
|
4326
|
+
return (
|
|
4327
|
+
`Use effort level: ${effort} — settle this before you start; never pick max on your own, only when the user asked for it. ` +
|
|
4328
|
+
`Then use the code-review skill to review all uncommitted changes for bugs and CLAUDE.md violations only. ` +
|
|
4329
|
+
`Do not report reuse, simplification, efficiency, architecture or test-coverage cleanups — /simplify owns those. ` +
|
|
4330
|
+
`Mark each finding with exactly one severity: important (this change introduced or worsened it), ` +
|
|
4331
|
+
`pre_existing (it was already there before this change), or nit (minor). ` +
|
|
4332
|
+
`End the summary with one suggested fix. If there is nothing to report, write exactly: "Code review found no issues."${cap}`
|
|
4333
|
+
)
|
|
4152
4334
|
},
|
|
4153
4335
|
})
|
|
4154
4336
|
|