@hmharness/evaluation 0.23.26 → 0.23.27

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/dist/index.d.ts CHANGED
@@ -6,3 +6,4 @@ export * from './score.js';
6
6
  export * from './sdk.js';
7
7
  export * from './marketplace.js';
8
8
  export * from './self-benchmark.js';
9
+ export * from './metrics.js';
package/dist/index.js CHANGED
@@ -6,3 +6,4 @@ export * from "./score.js";
6
6
  export * from "./sdk.js";
7
7
  export * from "./marketplace.js";
8
8
  export * from "./self-benchmark.js";
9
+ export * from "./metrics.js";
@@ -0,0 +1,69 @@
1
+ /**
2
+ * @hmharness/evaluation - unified metric protocol (upgrade pack 04, core metrics)
3
+ *
4
+ * The pack's twelve core metrics as ONE report shape with ONE honesty
5
+ * rule: a metric whose input was not provided is undefined - never zero,
6
+ * never fabricated ("no safety violations recorded" and "we did not
7
+ * measure safety violations" are different claims; conflating them is how
8
+ * benchmark reports start lying).
9
+ *
10
+ * 1 successRate success count / tasks
11
+ * 2 taskCompletionTime mean completion ms
12
+ * 3 actionEfficiency effective actions / total actions
13
+ * 4 recoveryRate recovered failures / failures
14
+ * 5 predictionCalibration brier (lower better; ece reported alongside when given)
15
+ * 6 worldModelDeltaAccuracy given directly (WM 2.0 deltaAccuracy.accuracy)
16
+ * 7 cost total cost in USD
17
+ * 8 latency p50/p95/max of per-action latency ms
18
+ * 9 humanInterventionRate interventions / tasks
19
+ * 10 regressionRate (baseline - current) / baseline when baseline > 0
20
+ * 11 transferGain withTransfer - baseline (target env ONLY -
21
+ * the pack forbids reporting source-env numbers as transfer)
22
+ * 12 safetyViolationRate violations / tasks
23
+ */
24
+ export interface RunMetricInput {
25
+ tasks?: number;
26
+ successes?: number;
27
+ completionsMs?: number[];
28
+ actions?: number;
29
+ effectiveActions?: number;
30
+ failures?: number;
31
+ recoveredFailures?: number;
32
+ brier?: number;
33
+ ece?: number;
34
+ deltaAccuracy?: number;
35
+ costUsd?: number;
36
+ actionLatenciesMs?: number[];
37
+ humanInterventions?: number;
38
+ /** baseline = the pre-change success count on the SAME task set */
39
+ regressionBaselineSuccesses?: number;
40
+ currentSuccesses?: number;
41
+ /** BOTH fields are target-environment numbers (never source-env) */
42
+ transferWithKnowledge?: number;
43
+ transferBaseline?: number;
44
+ safetyViolations?: number;
45
+ }
46
+ export interface MetricReport {
47
+ successRate?: number;
48
+ taskCompletionTimeMs?: number;
49
+ actionEfficiency?: number;
50
+ recoveryRate?: number;
51
+ predictionCalibration?: {
52
+ brier: number;
53
+ ece?: number;
54
+ };
55
+ worldModelDeltaAccuracy?: number;
56
+ costUsd?: number;
57
+ latency?: {
58
+ p50Ms: number;
59
+ p95Ms: number;
60
+ maxMs: number;
61
+ };
62
+ humanInterventionRate?: number;
63
+ regressionRate?: number;
64
+ transferGain?: number;
65
+ safetyViolationRate?: number;
66
+ /** which metrics were absent (undefined by honesty, not by accident) */
67
+ unmeasured: string[];
68
+ }
69
+ export declare function computeMetrics(input: RunMetricInput): MetricReport;
@@ -0,0 +1,69 @@
1
+ const pct = (num, den) => den > 0 ? Number((num / den).toFixed(3)) : undefined;
2
+ function quantile(sorted, q) {
3
+ const idx = Math.min(sorted.length - 1, Math.max(0, Math.round(q * (sorted.length - 1))));
4
+ return sorted[idx];
5
+ }
6
+ export function computeMetrics(input) {
7
+ const report = { unmeasured: [] };
8
+ if (input.tasks !== undefined && input.tasks > 0) {
9
+ if (input.successes !== undefined)
10
+ report.successRate = pct(input.successes, input.tasks);
11
+ if (input.humanInterventions !== undefined)
12
+ report.humanInterventionRate = pct(input.humanInterventions, input.tasks);
13
+ if (input.safetyViolations !== undefined)
14
+ report.safetyViolationRate = pct(input.safetyViolations, input.tasks);
15
+ }
16
+ if (input.completionsMs?.length) {
17
+ report.taskCompletionTimeMs = Number((input.completionsMs.reduce((s, x) => s + x, 0) / input.completionsMs.length).toFixed(0));
18
+ }
19
+ if (input.actions !== undefined && input.actions > 0 && input.effectiveActions !== undefined) {
20
+ report.actionEfficiency = pct(input.effectiveActions, input.actions);
21
+ }
22
+ if (input.failures !== undefined && input.failures > 0 && input.recoveredFailures !== undefined) {
23
+ report.recoveryRate = pct(input.recoveredFailures, input.failures);
24
+ }
25
+ if (input.brier !== undefined) {
26
+ report.predictionCalibration = { brier: input.brier, ...(input.ece !== undefined ? { ece: input.ece } : {}) };
27
+ }
28
+ if (input.deltaAccuracy !== undefined)
29
+ report.worldModelDeltaAccuracy = input.deltaAccuracy;
30
+ if (input.costUsd !== undefined)
31
+ report.costUsd = Number(input.costUsd.toFixed(4));
32
+ if (input.actionLatenciesMs?.length) {
33
+ const sorted = [...input.actionLatenciesMs].sort((a, b) => a - b);
34
+ report.latency = {
35
+ p50Ms: quantile(sorted, 0.5),
36
+ p95Ms: quantile(sorted, 0.95),
37
+ maxMs: sorted[sorted.length - 1],
38
+ };
39
+ }
40
+ if (input.regressionBaselineSuccesses !== undefined && input.currentSuccesses !== undefined) {
41
+ const base = input.regressionBaselineSuccesses;
42
+ // regression = the share of previously-passing outcomes lost; a baseline
43
+ // of 0 leaves it honestly undefined (division would fabricate infinity)
44
+ if (base > 0)
45
+ report.regressionRate = Number(((base - input.currentSuccesses) / base).toFixed(3));
46
+ }
47
+ if (input.transferWithKnowledge !== undefined && input.transferBaseline !== undefined) {
48
+ report.transferGain = Number((input.transferWithKnowledge - input.transferBaseline).toFixed(3));
49
+ }
50
+ const provided = new Set(Object.keys(report));
51
+ const all = [
52
+ ['successRate', 'successRate'],
53
+ ['taskCompletionTimeMs', 'taskCompletionTime'],
54
+ ['actionEfficiency', 'actionEfficiency'],
55
+ ['recoveryRate', 'recoveryRate'],
56
+ ['predictionCalibration', 'predictionCalibration'],
57
+ ['worldModelDeltaAccuracy', 'worldModelDeltaAccuracy'],
58
+ ['costUsd', 'cost'],
59
+ ['latency', 'latency'],
60
+ ['humanInterventionRate', 'humanInterventionRate'],
61
+ ['regressionRate', 'regressionRate'],
62
+ ['transferGain', 'transferGain'],
63
+ ['safetyViolationRate', 'safetyViolationRate'],
64
+ ];
65
+ for (const [field, label] of all)
66
+ if (!provided.has(field))
67
+ report.unmeasured.push(label);
68
+ return report;
69
+ }
package/package.json CHANGED
@@ -1,32 +1,32 @@
1
- {
2
- "name": "@hmharness/evaluation",
3
- "version": "0.23.26",
4
- "description": "hmharness evaluation: the Evaluator/Judge contract (V2 blueprint M2). Hard evidence outranks LLM judgment - build results, exit codes, exact/regex assertions first; the LLM judge is a last resort and is labeled as such. Evaluations attach to trajectories (judge.completed events).",
5
- "type": "module",
6
- "main": "dist/index.js",
7
- "exports": {
8
- ".": {
9
- "types": "./dist/index.d.ts",
10
- "default": "./dist/index.js"
11
- }
12
- },
13
- "types": "dist/index.d.ts",
14
- "scripts": {
15
- "build": "tsc -p tsconfig.build.json"
16
- },
17
- "dependencies": {
18
- "@hmharness/kernel": "0.23.26",
19
- "@hmharness/observability": "0.23.26"
20
- },
21
- "files": [
22
- "dist"
23
- ],
24
- "license": "MIT",
25
- "repository": {
26
- "type": "git",
27
- "url": "git+https://github.com/swsgbl/hmharness.git"
28
- },
29
- "engines": {
30
- "node": ">=22"
31
- }
32
- }
1
+ {
2
+ "name": "@hmharness/evaluation",
3
+ "version": "0.23.27",
4
+ "description": "hmharness evaluation: the Evaluator/Judge contract (V2 blueprint M2). Hard evidence outranks LLM judgment - build results, exit codes, exact/regex assertions first; the LLM judge is a last resort and is labeled as such. Evaluations attach to trajectories (judge.completed events).",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ }
12
+ },
13
+ "types": "dist/index.d.ts",
14
+ "scripts": {
15
+ "build": "tsc -p tsconfig.build.json"
16
+ },
17
+ "dependencies": {
18
+ "@hmharness/kernel": "0.23.27",
19
+ "@hmharness/observability": "0.23.27"
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "license": "MIT",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/swsgbl/hmharness.git"
28
+ },
29
+ "engines": {
30
+ "node": ">=22"
31
+ }
32
+ }