@wyattjoh/rfc 0.1.0
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 +136 -0
- package/package.json +54 -0
- package/src/bin.ts +5 -0
- package/src/config.ts +114 -0
- package/src/credentials.ts +372 -0
- package/src/index.ts +10 -0
- package/src/live-evaluation-bin.ts +15 -0
- package/src/live-evaluation.ts +215 -0
- package/src/main.ts +783 -0
- package/src/mcp.ts +476 -0
- package/src/operations.ts +429 -0
- package/src/usage-store.ts +245 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { command, makeDefaultCliDependencies, run, toCliErrorEnvelope } from "./main";
|
|
2
|
+
export {
|
|
3
|
+
createRfcMcpServer,
|
|
4
|
+
rfcMcpAgentReference,
|
|
5
|
+
rfcMcpAgentReferenceUri,
|
|
6
|
+
rfcMcpInstructions,
|
|
7
|
+
runRfcMcpServer,
|
|
8
|
+
} from "./mcp";
|
|
9
|
+
export * from "./credentials";
|
|
10
|
+
export { defaultCliConfig, readCliConfig } from "./config";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
import { runLiveEvaluation } from "./live-evaluation";
|
|
4
|
+
import { toCliErrorEnvelope } from "./main";
|
|
5
|
+
|
|
6
|
+
try {
|
|
7
|
+
// Invoking this dedicated binary is the explicit live-evaluation opt-in.
|
|
8
|
+
process.exitCode = await runLiveEvaluation({
|
|
9
|
+
credentialStore: undefined,
|
|
10
|
+
enable: true,
|
|
11
|
+
});
|
|
12
|
+
} catch (error) {
|
|
13
|
+
process.stderr.write(`${JSON.stringify(toCliErrorEnvelope(error))}\n`);
|
|
14
|
+
process.exitCode = 1;
|
|
15
|
+
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
2
|
+
import { dirname } from "node:path";
|
|
3
|
+
import {
|
|
4
|
+
ConfigurationError,
|
|
5
|
+
evaluationCorpus,
|
|
6
|
+
evaluationCorpusDigest,
|
|
7
|
+
evaluationModelAlias,
|
|
8
|
+
evaluationPolicy,
|
|
9
|
+
evaluationReleaseAttestation,
|
|
10
|
+
failedEvaluationObservation,
|
|
11
|
+
observationFromCitationResult,
|
|
12
|
+
observationFromEvidenceBundle,
|
|
13
|
+
pinnedJevModel,
|
|
14
|
+
runEvaluation,
|
|
15
|
+
type EvaluationCase,
|
|
16
|
+
type EvaluationReportOptions,
|
|
17
|
+
} from "@wyattjoh/rfc-core";
|
|
18
|
+
import { readCliConfig } from "./config";
|
|
19
|
+
import {
|
|
20
|
+
makeDefaultCredentialStore,
|
|
21
|
+
resolveStoredCredential,
|
|
22
|
+
type CredentialStore,
|
|
23
|
+
} from "./credentials";
|
|
24
|
+
import {
|
|
25
|
+
createRfcCalibrationClient,
|
|
26
|
+
evaluateDeterministicRetrievalCase,
|
|
27
|
+
} from "../../rfc-core/src/internal-calibration";
|
|
28
|
+
|
|
29
|
+
const liveCorpus = {
|
|
30
|
+
...evaluationCorpus,
|
|
31
|
+
cases: evaluationCorpus.cases.filter((evaluationCase) => evaluationCase.live),
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const liveEvaluationIterations = 3;
|
|
35
|
+
|
|
36
|
+
const timedCorpus = {
|
|
37
|
+
...liveCorpus,
|
|
38
|
+
cases: liveCorpus.cases.flatMap((evaluationCase) =>
|
|
39
|
+
Array.from({ length: liveEvaluationIterations }, (_, iteration) => ({
|
|
40
|
+
...evaluationCase,
|
|
41
|
+
id: `${evaluationCase.id}:iteration-${iteration + 1}`,
|
|
42
|
+
})),
|
|
43
|
+
),
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const researchRequestFor = (evaluationCase: EvaluationCase) => {
|
|
47
|
+
if (evaluationCase.question === null) {
|
|
48
|
+
throw new Error(`Research case ${evaluationCase.id} is missing a question`);
|
|
49
|
+
}
|
|
50
|
+
return evaluationCase.rfc === null
|
|
51
|
+
? {
|
|
52
|
+
schemaVersion: 2 as const,
|
|
53
|
+
question: evaluationCase.question,
|
|
54
|
+
rfc: null,
|
|
55
|
+
searchTerms: evaluationCase.searchTerms ?? ["HTTP client request message"],
|
|
56
|
+
}
|
|
57
|
+
: {
|
|
58
|
+
schemaVersion: 2 as const,
|
|
59
|
+
question: evaluationCase.question,
|
|
60
|
+
rfc: evaluationCase.rfc,
|
|
61
|
+
searchTerms: undefined,
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const citationRequestFor = (evaluationCase: EvaluationCase) => {
|
|
66
|
+
if (
|
|
67
|
+
evaluationCase.rfc === null ||
|
|
68
|
+
evaluationCase.claim === null ||
|
|
69
|
+
evaluationCase.quote === null
|
|
70
|
+
) {
|
|
71
|
+
throw new Error(`Citation case ${evaluationCase.id} is incomplete`);
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
schemaVersion: 2 as const,
|
|
75
|
+
rfc: evaluationCase.rfc,
|
|
76
|
+
claim: evaluationCase.claim,
|
|
77
|
+
quote: evaluationCase.quote,
|
|
78
|
+
offset: evaluationCase.offset,
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const errorKind = (error: unknown): string => {
|
|
83
|
+
if (typeof error === "object" && error !== null && "_tag" in error) {
|
|
84
|
+
const tag = (error as { readonly _tag: unknown | undefined })._tag;
|
|
85
|
+
if (typeof tag === "string" && tag.length > 0) return tag;
|
|
86
|
+
}
|
|
87
|
+
return "EvaluationOperationError";
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Injectable dependencies for the opt-in live evaluator.
|
|
92
|
+
*/
|
|
93
|
+
export interface LiveEvaluationOptions {
|
|
94
|
+
/**
|
|
95
|
+
* Credential boundary shared with ordinary research and citation commands.
|
|
96
|
+
*/
|
|
97
|
+
readonly credentialStore: CredentialStore | undefined;
|
|
98
|
+
/**
|
|
99
|
+
* Explicit command-level opt-in for a live provider run.
|
|
100
|
+
*/
|
|
101
|
+
readonly enable: boolean | undefined;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const defaultLiveEvaluationOptions: LiveEvaluationOptions = {
|
|
105
|
+
credentialStore: undefined,
|
|
106
|
+
enable: true,
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Run the opt-in live TypeSafe calibration against authoritative RFC Editor sources.
|
|
111
|
+
*
|
|
112
|
+
* An untimed pass over every live case warms request-local source entries before
|
|
113
|
+
* three sequential timed iterations. This preserves a bounded provider call
|
|
114
|
+
* order while excluding cache warming from both p95 gates. The provider key is
|
|
115
|
+
* resolved from the same injectable Bun.secrets boundary used by the CLI.
|
|
116
|
+
*
|
|
117
|
+
* @param options Explicit live-run opt-in and credential boundary.
|
|
118
|
+
* @returns Zero when every precision, safety, latency, and model gate passes;
|
|
119
|
+
* otherwise two.
|
|
120
|
+
*/
|
|
121
|
+
export const runLiveEvaluation = async (
|
|
122
|
+
runtimeOptions: LiveEvaluationOptions = defaultLiveEvaluationOptions,
|
|
123
|
+
): Promise<number> => {
|
|
124
|
+
let config: ReturnType<typeof readCliConfig>;
|
|
125
|
+
try {
|
|
126
|
+
config = readCliConfig({
|
|
127
|
+
liveEvaluation: runtimeOptions.enable,
|
|
128
|
+
automaticAnswerEnabled: undefined,
|
|
129
|
+
evaluationCacheDirectory: undefined,
|
|
130
|
+
evaluationOutput: undefined,
|
|
131
|
+
});
|
|
132
|
+
} catch (error) {
|
|
133
|
+
throw new ConfigurationError({
|
|
134
|
+
reason:
|
|
135
|
+
error instanceof Error ? error.message : "Unable to validate live evaluation configuration",
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
if (!config.liveEvaluation) {
|
|
139
|
+
throw new ConfigurationError({
|
|
140
|
+
reason: "Live evaluation is disabled; pass the explicit live-evaluation opt-in",
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
if (
|
|
144
|
+
config.policyPreset !== evaluationPolicy.policyVersion ||
|
|
145
|
+
config.evaluationModel !== evaluationModelAlias ||
|
|
146
|
+
config.pinnedModel !== pinnedJevModel ||
|
|
147
|
+
config.modelAlias !== pinnedJevModel
|
|
148
|
+
) {
|
|
149
|
+
throw new ConfigurationError({
|
|
150
|
+
reason: "Live calibration must use the committed precision policy and exact Jev pin",
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const reportOptions: EvaluationReportOptions = {
|
|
155
|
+
origin: "live",
|
|
156
|
+
releaseBuildId: evaluationReleaseAttestation.buildId,
|
|
157
|
+
corpusDigest: evaluationCorpusDigest,
|
|
158
|
+
createdAt: new Date().toISOString(),
|
|
159
|
+
expiresAt: new Date(Date.now() + 30 * 24 * 60 * 60 * 1_000).toISOString(),
|
|
160
|
+
authoritativeSourceHashes: undefined,
|
|
161
|
+
policyVersion: evaluationPolicy.policyVersion,
|
|
162
|
+
requestedModel: evaluationModelAlias,
|
|
163
|
+
pinnedModel: pinnedJevModel,
|
|
164
|
+
minimumSupportedClaimPrecision: undefined,
|
|
165
|
+
maxKnownRfcP95LatencyMilliseconds: undefined,
|
|
166
|
+
maxTopicP95LatencyMilliseconds: undefined,
|
|
167
|
+
};
|
|
168
|
+
const apiKey = await resolveStoredCredential(
|
|
169
|
+
runtimeOptions.credentialStore ?? makeDefaultCredentialStore(),
|
|
170
|
+
);
|
|
171
|
+
const client = await createRfcCalibrationClient({
|
|
172
|
+
cacheDirectory: config.evaluationCacheDirectory,
|
|
173
|
+
modelAlias: config.evaluationModel,
|
|
174
|
+
policyPreset: config.policyPreset,
|
|
175
|
+
typeSafeApiKey: apiKey,
|
|
176
|
+
typeSafeApiUrl: undefined,
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
try {
|
|
180
|
+
const evaluateCase = async (evaluationCase: EvaluationCase) => {
|
|
181
|
+
try {
|
|
182
|
+
if (evaluationCase.kind === "research") {
|
|
183
|
+
const result = await client.research(researchRequestFor(evaluationCase));
|
|
184
|
+
return observationFromEvidenceBundle(evaluationCase, result);
|
|
185
|
+
}
|
|
186
|
+
const result = await client.verifyCitation(citationRequestFor(evaluationCase));
|
|
187
|
+
return observationFromCitationResult(evaluationCase, result);
|
|
188
|
+
} catch (error) {
|
|
189
|
+
return failedEvaluationObservation(evaluationCase, reportOptions, errorKind(error));
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
const warmupObservations = [];
|
|
193
|
+
for (const evaluationCase of liveCorpus.cases) {
|
|
194
|
+
warmupObservations.push(await evaluateCase(evaluationCase));
|
|
195
|
+
}
|
|
196
|
+
if (warmupObservations.some((observation) => observation.errorKind !== null)) {
|
|
197
|
+
throw new ConfigurationError({
|
|
198
|
+
reason: "Live evaluation warm-up did not complete every corpus case",
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
const report = await runEvaluation(
|
|
202
|
+
timedCorpus,
|
|
203
|
+
evaluateCase,
|
|
204
|
+
evaluateDeterministicRetrievalCase,
|
|
205
|
+
reportOptions,
|
|
206
|
+
);
|
|
207
|
+
const output = `${JSON.stringify(report, null, 2)}\n`;
|
|
208
|
+
await mkdir(dirname(config.evaluationOutput), { recursive: true });
|
|
209
|
+
await writeFile(config.evaluationOutput, output, "utf8");
|
|
210
|
+
process.stdout.write(output);
|
|
211
|
+
return report.gate.passed ? 0 : 2;
|
|
212
|
+
} finally {
|
|
213
|
+
await client.close();
|
|
214
|
+
}
|
|
215
|
+
};
|