@canonry/canonry 7.51.5 → 7.51.6
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/ads-ABAT3K4K.js +544 -0
- package/dist/agent-5G4DRLYX.js +70 -0
- package/dist/agent-ask-UDVCZRO7.js +139 -0
- package/dist/agent-conversations-5E4JP2QZ.js +52 -0
- package/dist/agent-memory-7IIJ4HGZ.js +92 -0
- package/dist/agent-providers-BOXPUXZ4.js +55 -0
- package/dist/agent-transcript-4O56G6PQ.js +77 -0
- package/dist/analytics-PKMWX5XL.js +240 -0
- package/dist/apply-OK4XEBDA.js +175 -0
- package/dist/backfill-2OT56CX2.js +41 -0
- package/dist/backlinks-547WCHND.js +303 -0
- package/dist/bing-ZVBV4ZD5.js +418 -0
- package/dist/bootstrap-HUB7XQ73.js +326 -0
- package/dist/cdp-KQKQ4PWJ.js +162 -0
- package/dist/chunk-2G6IP3MO.js +517 -0
- package/dist/chunk-42D2LE2B.js +1273 -0
- package/dist/chunk-4MJYGB56.js +124 -0
- package/dist/chunk-63ISSSGX.js +9150 -0
- package/dist/{chunk-PLYJX67A.js → chunk-6G6FTDWC.js} +8080 -13939
- package/dist/chunk-6GO5VVAC.js +15 -0
- package/dist/{chunk-4YCGZGA3.js → chunk-73P65KPW.js} +2 -2
- package/dist/chunk-7B2Q4NJE.js +133 -0
- package/dist/{chunk-JBZZEIM2.js → chunk-7WZ2FPB4.js} +2 -13
- package/dist/chunk-AOJU5LKX.js +8 -0
- package/dist/chunk-B2FR2ZQ4.js +420 -0
- package/dist/{chunk-HAHXPJQ5.js → chunk-B5J675KK.js} +16 -1684
- package/dist/{chunk-SFMWHPMX.js → chunk-D6COIM3U.js} +17128 -17143
- package/dist/{chunk-A3WSAAQS.js → chunk-DGVUTH7W.js} +9086 -34522
- package/dist/chunk-ELCLGWUT.js +83 -0
- package/dist/chunk-GO2J7SYT.js +1034 -0
- package/dist/chunk-HACZUMGM.js +145 -0
- package/dist/chunk-HM4NNKLG.js +94 -0
- package/dist/chunk-I3A56PFP.js +58 -0
- package/dist/chunk-I77PLCWG.js +961 -0
- package/dist/chunk-ISOQPVPY.js +232 -0
- package/dist/chunk-KFT5LOP2.js +610 -0
- package/dist/chunk-MLKGABMK.js +9 -0
- package/dist/chunk-MMEO22MF.js +38 -0
- package/dist/chunk-NHQ2U5I4.js +78 -0
- package/dist/chunk-PCXRFT3N.js +530 -0
- package/dist/chunk-PITHTCAX.js +15376 -0
- package/dist/chunk-QWKPSFGL.js +30 -0
- package/dist/chunk-RKIXES2B.js +609 -0
- package/dist/chunk-TSENU4GG.js +18 -0
- package/dist/{chunk-HLVEB5TB.js → chunk-TUTKNUMV.js} +7 -5
- package/dist/chunk-U3AHE2RT.js +1160 -0
- package/dist/chunk-UQ3MOZGC.js +644 -0
- package/dist/{chunk-AZFPA7JV.js → chunk-VBCE4CLX.js} +6 -4
- package/dist/chunk-VJWDBFSL.js +69 -0
- package/dist/chunk-VYMZ3QXG.js +8264 -0
- package/dist/chunk-WAULJDKO.js +2686 -0
- package/dist/chunk-WDFI5YMD.js +204 -0
- package/dist/chunk-XEBKF4N5.js +8 -0
- package/dist/chunk-Z7IUAJOF.js +13 -0
- package/dist/{chunk-KEATAHXH.js → chunk-ZWJRY5UI.js} +358 -581
- package/dist/chunk-ZXUAWVWM.js +15 -0
- package/dist/citations-UYB2RU5U.js +106 -0
- package/dist/{cli-catalog-MO6Z2CIZ.js → cli-catalog-F6FI7NB2.js} +5 -3
- package/dist/cli-commands-ZG5ILKDA.js +19 -0
- package/dist/cli.js +35 -29
- package/dist/competitor-EKP4R7YY.js +561 -0
- package/dist/content-DREE6JF3.js +257 -0
- package/dist/dashboard-ZALEOLLU.js +71 -0
- package/dist/demo-JG4Y22O4.js +75 -0
- package/dist/{demo-server-GIWDJGJX.js → demo-server-3A4J2C65.js} +22 -9
- package/dist/discover-W6GMD2HS.js +372 -0
- package/dist/discover-eval-CKFZHRBW.js +282 -0
- package/dist/doctor-TNGBSUMA.js +152 -0
- package/dist/evidence-3H2GFQBZ.js +57 -0
- package/dist/export-cmd-WUIKU5GK.js +49 -0
- package/dist/ga-JI6REFO4.js +911 -0
- package/dist/gbp-4ENDM5NS.js +370 -0
- package/dist/google-HKQSCLOC.js +946 -0
- package/dist/google-marketing-KQR5J2S4.js +403 -0
- package/dist/health-cmd-TS7EMMCS.js +64 -0
- package/dist/history-MSD5DK6K.js +90 -0
- package/dist/index.d.ts +47 -47
- package/dist/index.js +29 -6
- package/dist/init-L6WAEOWX.js +432 -0
- package/dist/insights-RTZ3IZTD.js +63 -0
- package/dist/intelligence-service-TH52PCNJ.js +15 -0
- package/dist/keys-625DZBRM.js +116 -0
- package/dist/keyword-CW46RNRR.js +164 -0
- package/dist/logs-V33SHBIW.js +30 -0
- package/dist/mcp-DFEDPSEG.js +14 -0
- package/dist/mcp.js +14 -5
- package/dist/measurement-plan-6W37RUOP.js +42 -0
- package/dist/notify-DSUOT7WO.js +125 -0
- package/dist/organic-evidence-BMN6L4OB.js +53 -0
- package/dist/overview-WRRMBZ6S.js +213 -0
- package/dist/project-2GJIU3FE.js +460 -0
- package/dist/query-3XPMGJUA.js +211 -0
- package/dist/research-V433CKJ4.js +200 -0
- package/dist/results-export-RGBU7QQQ.js +27 -0
- package/dist/run-NIAC6OJN.js +31 -0
- package/dist/schedule-KDWXRIE7.js +177 -0
- package/dist/search-626MPUJN.js +42 -0
- package/dist/serve-73SMMASI.js +557 -0
- package/dist/session-7WWOETZB.js +47 -0
- package/dist/settings-VKFQO6F2.js +107 -0
- package/dist/skills-5HC5H7TE.js +33 -0
- package/dist/snapshot-BSJUHFBC.js +538 -0
- package/dist/src-F6HM73TN.js +316 -0
- package/dist/status-V4OWP7LZ.js +126 -0
- package/dist/support-ARF4HER7.js +24 -0
- package/dist/technical-aeo-TG7CGU3F.js +625 -0
- package/dist/telemetry-O2IUNUBW.js +118 -0
- package/dist/tools-2GJIDKND.js +41 -0
- package/dist/traffic-XV4I3UPH.js +1295 -0
- package/dist/users-VGBLDL5K.js +170 -0
- package/dist/visibility-stats-UKJYJ6PP.js +241 -0
- package/dist/wordpress-JZA7CGC6.js +600 -0
- package/package.json +1 -1
- package/dist/chunk-4QQYYRHV.js +0 -23082
- package/dist/cli-commands-FOJR3HHU.js +0 -15
- package/dist/intelligence-service-XQCNWAPL.js +0 -9
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createApiClient
|
|
3
|
+
} from "./chunk-B5J675KK.js";
|
|
4
|
+
import "./chunk-UQ3MOZGC.js";
|
|
5
|
+
import {
|
|
6
|
+
emitJsonl
|
|
7
|
+
} from "./chunk-Z7IUAJOF.js";
|
|
8
|
+
import "./chunk-AOJU5LKX.js";
|
|
9
|
+
import {
|
|
10
|
+
CliError,
|
|
11
|
+
isMachineFormat
|
|
12
|
+
} from "./chunk-HGMYEDAQ.js";
|
|
13
|
+
import {
|
|
14
|
+
CitationStates,
|
|
15
|
+
DiscoveryPromoteCompetitorSkipReasons,
|
|
16
|
+
describeError
|
|
17
|
+
} from "./chunk-D6COIM3U.js";
|
|
18
|
+
import "./chunk-MLKGABMK.js";
|
|
19
|
+
|
|
20
|
+
// src/commands/discover.ts
|
|
21
|
+
var TERMINAL_DISCOVERY_STATUSES = /* @__PURE__ */ new Set([
|
|
22
|
+
"completed",
|
|
23
|
+
"failed"
|
|
24
|
+
]);
|
|
25
|
+
function getClient() {
|
|
26
|
+
return createApiClient();
|
|
27
|
+
}
|
|
28
|
+
function buildRunBody(opts, icpDescription) {
|
|
29
|
+
const body = {};
|
|
30
|
+
if (icpDescription) body.icpDescription = icpDescription;
|
|
31
|
+
if (opts.buyer !== void 0 && opts.buyer.trim() !== "") body.buyerDescription = opts.buyer;
|
|
32
|
+
if (opts.seedProviders && opts.seedProviders.length > 0) body.seedProviders = opts.seedProviders;
|
|
33
|
+
if (opts.dedupThreshold !== void 0) body.dedupThreshold = opts.dedupThreshold;
|
|
34
|
+
if (opts.maxProbes !== void 0) body.maxProbes = opts.maxProbes;
|
|
35
|
+
if (opts.probeConcurrency !== void 0) body.probeConcurrency = opts.probeConcurrency;
|
|
36
|
+
if (opts.locations && opts.locations.length > 0) body.locations = opts.locations;
|
|
37
|
+
return body;
|
|
38
|
+
}
|
|
39
|
+
function resolveIcpAngles(opts) {
|
|
40
|
+
const angles = (opts.icpAngles ?? []).map((a) => a.trim()).filter((a) => a.length > 0);
|
|
41
|
+
if (angles.length > 0) return { angles, multiAngle: true };
|
|
42
|
+
const icp = opts.icp?.trim();
|
|
43
|
+
if (icp) return { angles: [icp], multiAngle: false };
|
|
44
|
+
return { angles: [void 0], multiAngle: false };
|
|
45
|
+
}
|
|
46
|
+
function summarizeAngles(sessions) {
|
|
47
|
+
return {
|
|
48
|
+
angleCount: sessions.length,
|
|
49
|
+
totalProbes: sessions.reduce((sum, s) => sum + (s.probeCount ?? 0), 0),
|
|
50
|
+
totalCited: sessions.reduce((sum, s) => sum + (s.citedCount ?? 0), 0),
|
|
51
|
+
totalWasted: sessions.reduce((sum, s) => sum + (s.wastedCount ?? 0), 0),
|
|
52
|
+
totalAspirational: sessions.reduce((sum, s) => sum + (s.aspirationalCount ?? 0), 0)
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function errorMessage(err) {
|
|
56
|
+
return describeError(err);
|
|
57
|
+
}
|
|
58
|
+
async function discoverRun(project, opts) {
|
|
59
|
+
const client = getClient();
|
|
60
|
+
const { angles, multiAngle } = resolveIcpAngles(opts);
|
|
61
|
+
const runs = [];
|
|
62
|
+
for (const angle of angles) {
|
|
63
|
+
try {
|
|
64
|
+
const start = await client.triggerDiscoveryRun(project, buildRunBody(opts, angle));
|
|
65
|
+
runs.push({ angle, start });
|
|
66
|
+
} catch (err) {
|
|
67
|
+
if (runs.length > 0) {
|
|
68
|
+
process.stderr.write(
|
|
69
|
+
`
|
|
70
|
+
Failed to start ${angle ? `angle "${angle}"` : "discovery run"}: ${errorMessage(err)}
|
|
71
|
+
Sessions already started (recover with \`canonry discover show ${project} <id>\`):
|
|
72
|
+
` + runs.map((r) => ` ${r.start.sessionId}`).join("\n") + "\n"
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
throw err;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (!opts.wait) {
|
|
79
|
+
if (isMachineFormat(opts.format)) {
|
|
80
|
+
console.log(JSON.stringify(multiAngle ? runs.map((r) => r.start) : runs[0].start, null, 2));
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
for (const { angle, start } of runs) {
|
|
84
|
+
if (angle) console.log(`[${angle}]`);
|
|
85
|
+
if (start.consolidated) {
|
|
86
|
+
console.log(`Reusing in-flight discovery session: ${start.sessionId}`);
|
|
87
|
+
console.log(` Run: ${start.runId}`);
|
|
88
|
+
console.log(` Status: ${start.status}`);
|
|
89
|
+
console.log(` Tail: canonry discover show ${project} ${start.sessionId}`);
|
|
90
|
+
} else {
|
|
91
|
+
console.log(`Discovery run started: ${start.runId}`);
|
|
92
|
+
console.log(` Session: ${start.sessionId}`);
|
|
93
|
+
console.log(` Status: ${start.status}`);
|
|
94
|
+
console.log(` Tail: canonry discover show ${project} ${start.sessionId}`);
|
|
95
|
+
}
|
|
96
|
+
if (runs.length > 1) console.log();
|
|
97
|
+
}
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const parallel = runs.length > 1;
|
|
101
|
+
if (parallel) process.stderr.write(`Waiting for ${runs.length} discovery sessions...
|
|
102
|
+
`);
|
|
103
|
+
const settled = await Promise.allSettled(
|
|
104
|
+
runs.map((r) => pollSession(client, project, r.start.sessionId, parallel))
|
|
105
|
+
);
|
|
106
|
+
const results = [];
|
|
107
|
+
const failures = [];
|
|
108
|
+
settled.forEach((outcome, i) => {
|
|
109
|
+
const run = runs[i];
|
|
110
|
+
if (outcome.status === "fulfilled") {
|
|
111
|
+
results.push({ angle: run.angle, session: outcome.value });
|
|
112
|
+
} else {
|
|
113
|
+
failures.push({ angle: run.angle, sessionId: run.start.sessionId, reason: outcome.reason });
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
if (results.length > 0) {
|
|
117
|
+
if (isMachineFormat(opts.format)) {
|
|
118
|
+
console.log(JSON.stringify(multiAngle ? results.map((r) => r.session) : results[0].session, null, 2));
|
|
119
|
+
} else {
|
|
120
|
+
for (const { angle, session } of results) {
|
|
121
|
+
if (angle) console.log(`## ICP angle: ${angle}
|
|
122
|
+
`);
|
|
123
|
+
printSessionDetail(session);
|
|
124
|
+
if (results.length > 1) console.log();
|
|
125
|
+
}
|
|
126
|
+
if (results.length > 1) {
|
|
127
|
+
const summary = summarizeAngles(results.map((r) => r.session));
|
|
128
|
+
console.log(`\u2500\u2500 Summary across ${summary.angleCount} angle(s) \u2500\u2500`);
|
|
129
|
+
console.log(
|
|
130
|
+
` Probes: ${summary.totalProbes} Cited: ${summary.totalCited} Wasted: ${summary.totalWasted} Aspirational: ${summary.totalAspirational}`
|
|
131
|
+
);
|
|
132
|
+
console.log("\n Promote each session:");
|
|
133
|
+
for (const { session } of results) {
|
|
134
|
+
console.log(` canonry discover promote ${project} ${session.id}`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (failures.length > 0) {
|
|
140
|
+
if (!multiAngle) throw failures[0].reason;
|
|
141
|
+
for (const f of failures) {
|
|
142
|
+
process.stderr.write(
|
|
143
|
+
`Discovery session ${f.sessionId}${f.angle ? ` ("${f.angle}")` : ""} did not complete: ${errorMessage(f.reason)}
|
|
144
|
+
`
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
throw new CliError({
|
|
148
|
+
code: "DISCOVERY_INCOMPLETE",
|
|
149
|
+
message: `${failures.length} of ${runs.length} discovery session(s) did not complete`,
|
|
150
|
+
details: { failed: failures.map((f) => f.sessionId) }
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
async function discoverSeed(project, opts) {
|
|
155
|
+
await discoverRun(project, opts);
|
|
156
|
+
}
|
|
157
|
+
async function discoverProbe(project, sessionId, opts) {
|
|
158
|
+
const client = getClient();
|
|
159
|
+
const session = await client.getDiscoverySession(project, sessionId);
|
|
160
|
+
if (opts.format === "json") {
|
|
161
|
+
console.log(JSON.stringify(session, null, 2));
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (opts.format === "jsonl") {
|
|
165
|
+
const context = { project, sessionId };
|
|
166
|
+
emitJsonl(session.probes.map((probe) => ({ ...context, ...probe })));
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
printSessionDetail(session);
|
|
170
|
+
}
|
|
171
|
+
async function discoverList(project, opts) {
|
|
172
|
+
const client = getClient();
|
|
173
|
+
const sessions = await client.listDiscoverySessions(project, opts.limit !== void 0 ? { limit: opts.limit } : void 0);
|
|
174
|
+
if (opts.format === "json") {
|
|
175
|
+
console.log(JSON.stringify(sessions, null, 2));
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
if (opts.format === "jsonl") {
|
|
179
|
+
emitJsonl(sessions.map((s) => ({ project, ...s })));
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
if (sessions.length === 0) {
|
|
183
|
+
console.log(`No discovery sessions for "${project}".`);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
console.log(`Discovery sessions for "${project}" (${sessions.length}):
|
|
187
|
+
`);
|
|
188
|
+
console.log(" ID STATUS PROBES CITED WASTED ASPIR. CREATED");
|
|
189
|
+
console.log(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
190
|
+
for (const s of sessions) {
|
|
191
|
+
const id = s.id.padEnd(36);
|
|
192
|
+
const status = (s.status ?? "").padEnd(10);
|
|
193
|
+
const probes = String(s.probeCount ?? 0).padStart(6);
|
|
194
|
+
const cited = String(s.citedCount ?? 0).padStart(5);
|
|
195
|
+
const wasted = String(s.wastedCount ?? 0).padStart(6);
|
|
196
|
+
const asp = String(s.aspirationalCount ?? 0).padStart(6);
|
|
197
|
+
console.log(` ${id} ${status} ${probes} ${cited} ${wasted} ${asp} ${s.createdAt}`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
async function discoverShow(project, sessionId, opts) {
|
|
201
|
+
const client = getClient();
|
|
202
|
+
const session = await client.getDiscoverySession(project, sessionId);
|
|
203
|
+
if (opts.format === "json") {
|
|
204
|
+
console.log(JSON.stringify(session, null, 2));
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
if (opts.format === "jsonl") {
|
|
208
|
+
const context = { project, sessionId };
|
|
209
|
+
emitJsonl(session.probes.map((probe) => ({ ...context, ...probe })));
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
printSessionDetail(session);
|
|
213
|
+
}
|
|
214
|
+
async function discoverHarvest(project, sessionId, opts) {
|
|
215
|
+
const client = getClient();
|
|
216
|
+
const harvest = await client.getDiscoveryHarvest(project, sessionId, {
|
|
217
|
+
minProbeHits: opts.minProbeHits,
|
|
218
|
+
anchor: opts.anchor
|
|
219
|
+
});
|
|
220
|
+
if (opts.format === "json") {
|
|
221
|
+
console.log(JSON.stringify(harvest, null, 2));
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
if (opts.format === "jsonl") {
|
|
225
|
+
const context = { project, sessionId, provider: harvest.provider };
|
|
226
|
+
emitJsonl(harvest.candidates.map((c) => ({ ...context, ...c })));
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
const r = harvest.stats.rejected;
|
|
230
|
+
console.log(`Harvested issued search queries \u2014 session ${harvest.sessionId} (${harvest.provider})`);
|
|
231
|
+
console.log(
|
|
232
|
+
` ${harvest.stats.admitted} admitted of ${harvest.stats.rawCandidates} raw \xB7 floor=${harvest.minProbeHits} \xB7 anchor=${harvest.anchorApplied ? "on" : "off"} \xB7 novelty=${harvest.semanticNoveltyApplied ? "semantic" : "exact-only"}`
|
|
233
|
+
);
|
|
234
|
+
console.log(
|
|
235
|
+
` rejected: ${r.belowFloor} below-floor \xB7 ${r.length} length \xB7 ${r.navigational} navigational \xB7 ${r.duplicate} already-tracked \xB7 ${r.semanticDuplicate} synonym \xB7 ${r.offAnchor} off-subject`
|
|
236
|
+
);
|
|
237
|
+
if (harvest.candidates.length === 0) {
|
|
238
|
+
console.log(" (no candidates \u2014 nothing to track from this session)");
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
console.log("");
|
|
242
|
+
console.log(" HITS QUERY");
|
|
243
|
+
for (const candidate of harvest.candidates) {
|
|
244
|
+
console.log(` ${String(candidate.probeHits).padStart(4)} ${candidate.query}`);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
async function discoverPromotePreview(project, sessionId, opts) {
|
|
248
|
+
const client = getClient();
|
|
249
|
+
const preview = await client.previewDiscoveryPromote(project, sessionId);
|
|
250
|
+
if (isMachineFormat(opts.format)) {
|
|
251
|
+
console.log(JSON.stringify(preview, null, 2));
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
console.log(`Promote preview for session ${sessionId} (status: ${preview.status}):`);
|
|
255
|
+
console.log(` Cited (${preview.queriesByBucket.cited.length})`);
|
|
256
|
+
for (const q of preview.queriesByBucket.cited.slice(0, 10)) console.log(` + ${q}`);
|
|
257
|
+
console.log(` Wasted-surface (${preview.queriesByBucket["wasted-surface"].length})`);
|
|
258
|
+
for (const q of preview.queriesByBucket["wasted-surface"].slice(0, 10)) console.log(` + ${q}`);
|
|
259
|
+
console.log(` Aspirational (${preview.queriesByBucket.aspirational.length})`);
|
|
260
|
+
for (const q of preview.queriesByBucket.aspirational.slice(0, 10)) console.log(` + ${q}`);
|
|
261
|
+
if (preview.suggestedCompetitors.length > 0) {
|
|
262
|
+
console.log(` Suggested new competitors:`);
|
|
263
|
+
for (const c of preview.suggestedCompetitors) {
|
|
264
|
+
console.log(` - ${c.domain} (${c.hits} hits, ${c.competitorType})${mergedHostsNote(c)}`);
|
|
265
|
+
}
|
|
266
|
+
console.log(" Only direct-competitor is promoted by default \u2014 pass --competitor-types to include other types.");
|
|
267
|
+
}
|
|
268
|
+
const skippedCompetitors = preview.skippedCompetitors ?? [];
|
|
269
|
+
const held = skippedCompetitors.filter((c) => c.reason !== DiscoveryPromoteCompetitorSkipReasons["already-tracked"]);
|
|
270
|
+
if (held.length > 0) {
|
|
271
|
+
console.log(` Competitors a promote leaves out:`);
|
|
272
|
+
for (const c of held) console.log(` ! ${c.domain} (${c.reason}): ${c.message}`);
|
|
273
|
+
}
|
|
274
|
+
console.log(`
|
|
275
|
+
Run \`canonry discover promote ${project} ${sessionId}\` to merge cited + aspirational queries.`);
|
|
276
|
+
console.log(" Add `--bucket wasted-surface` only when off-ICP competitor gaps should be tracked.");
|
|
277
|
+
}
|
|
278
|
+
async function discoverPromote(project, sessionId, opts) {
|
|
279
|
+
const client = getClient();
|
|
280
|
+
const body = {};
|
|
281
|
+
if (opts.buckets && opts.buckets.length > 0) body.buckets = opts.buckets;
|
|
282
|
+
if (opts.competitorTypes && opts.competitorTypes.length > 0) body.competitorTypes = opts.competitorTypes;
|
|
283
|
+
if (opts.includeCompetitors === false) body.includeCompetitors = false;
|
|
284
|
+
const result = await client.promoteDiscovery(project, sessionId, body);
|
|
285
|
+
if (isMachineFormat(opts.format)) {
|
|
286
|
+
console.log(JSON.stringify(result, null, 2));
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
const { promoted, skipped } = result;
|
|
290
|
+
const competitorDetails = result.competitorDetails;
|
|
291
|
+
const promotedCompetitors = competitorDetails?.promoted ?? promoted.competitors.map((domain) => ({ domain }));
|
|
292
|
+
const held = (competitorDetails?.skipped ?? []).filter((c) => c.reason !== DiscoveryPromoteCompetitorSkipReasons["already-tracked"]);
|
|
293
|
+
console.log(`Promoted discovery session ${sessionId} into "${project}":`);
|
|
294
|
+
console.log(` Queries: ${promoted.queries.length} added, ${skipped.queries.length} already tracked`);
|
|
295
|
+
for (const q of promoted.queries) console.log(` + ${q}`);
|
|
296
|
+
console.log(` Competitors: ${promoted.competitors.length} added, ${skipped.competitors.length - held.length} already tracked, ${held.length} left out`);
|
|
297
|
+
for (const c of promotedCompetitors) console.log(` + ${c.domain}${mergedHostsNote(c)}`);
|
|
298
|
+
for (const c of held) console.log(` ! ${c.domain} (${c.reason}): ${c.message}`);
|
|
299
|
+
if (promoted.queries.length === 0 && promoted.competitors.length === 0) {
|
|
300
|
+
console.log(` Nothing new \u2014 the project's basket already covers this session.`);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
function mergedHostsNote(competitor) {
|
|
304
|
+
const sources = competitor.sources ?? [];
|
|
305
|
+
const hosts = sources.map((source) => source.domain).filter((host) => host !== competitor.domain);
|
|
306
|
+
return hosts.length > 0 ? ` (from ${sources.map((source) => source.domain).join(", ")})` : "";
|
|
307
|
+
}
|
|
308
|
+
function printSessionDetail(session) {
|
|
309
|
+
console.log(`Discovery session: ${session.id}`);
|
|
310
|
+
console.log(` Status: ${session.status}`);
|
|
311
|
+
if (session.icpDescription) console.log(` ICP: ${session.icpDescription}`);
|
|
312
|
+
if (session.seedProvider) console.log(` Seed provider: ${session.seedProvider}`);
|
|
313
|
+
if (session.dedupThreshold != null) console.log(` Dedup thresh: ${session.dedupThreshold}`);
|
|
314
|
+
if (session.seedCountRaw != null && session.seedCount != null) {
|
|
315
|
+
console.log(` Seed candidates: ${session.seedCount} (raw ${session.seedCountRaw})`);
|
|
316
|
+
}
|
|
317
|
+
if (session.probeCount != null) console.log(` Probes: ${session.probeCount}`);
|
|
318
|
+
console.log(` Buckets: cited=${session.citedCount ?? 0} wasted-surface=${session.wastedCount ?? 0} aspirational=${session.aspirationalCount ?? 0}`);
|
|
319
|
+
if (session.competitorMap.length > 0) {
|
|
320
|
+
console.log(` Top recurring competitor domains:`);
|
|
321
|
+
for (const c of session.competitorMap.slice(0, 10)) {
|
|
322
|
+
console.log(` - ${c.domain} (${c.hits} hits, ${c.competitorType})`);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
if (session.warning) console.log(` Warning: ${session.warning}`);
|
|
326
|
+
if (session.error) console.log(` Error: ${session.error}`);
|
|
327
|
+
if (session.startedAt) console.log(` Started: ${session.startedAt}`);
|
|
328
|
+
if (session.finishedAt) console.log(` Finished: ${session.finishedAt}`);
|
|
329
|
+
console.log(` Created: ${session.createdAt}`);
|
|
330
|
+
if (session.probes && session.probes.length > 0) {
|
|
331
|
+
const sorted = [...session.probes].sort((a, b) => (a.bucket ?? "").localeCompare(b.bucket ?? ""));
|
|
332
|
+
console.log(`
|
|
333
|
+
Probes (${session.probes.length}): (cell = [citation][mention]; C=cited c=not, M=mentioned m=not, \u2013=no data)`);
|
|
334
|
+
for (const p of sorted) {
|
|
335
|
+
const bucket = (p.bucket ?? "\u2013").padEnd(15);
|
|
336
|
+
const citationGlyph = p.citationState === CitationStates.cited ? "C" : "c";
|
|
337
|
+
const mentionGlyph = typeof p.answerMentioned === "boolean" ? p.answerMentioned ? "M" : "m" : "\u2013";
|
|
338
|
+
console.log(` [${citationGlyph}${mentionGlyph}] ${bucket} ${p.query}`);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
var POLL_INTERVAL_MS = 3e3;
|
|
343
|
+
var POLL_TIMEOUT_MS = 15 * 60 * 1e3;
|
|
344
|
+
async function pollSession(client, project, sessionId, quiet = false) {
|
|
345
|
+
if (!quiet) process.stderr.write(`Waiting for discovery session ${sessionId}`);
|
|
346
|
+
const deadline = Date.now() + POLL_TIMEOUT_MS;
|
|
347
|
+
for (; ; ) {
|
|
348
|
+
await new Promise((r) => setTimeout(r, POLL_INTERVAL_MS));
|
|
349
|
+
if (Date.now() > deadline) {
|
|
350
|
+
throw new CliError({
|
|
351
|
+
code: "DISCOVERY_TIMEOUT",
|
|
352
|
+
message: `Timed out waiting for discovery session ${sessionId} after ${POLL_TIMEOUT_MS / 1e3}s`
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
const session = await client.getDiscoverySession(project, sessionId);
|
|
356
|
+
if (!quiet) process.stderr.write(".");
|
|
357
|
+
if (TERMINAL_DISCOVERY_STATUSES.has(session.status)) {
|
|
358
|
+
if (!quiet) process.stderr.write("\n");
|
|
359
|
+
return session;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
export {
|
|
364
|
+
discoverHarvest,
|
|
365
|
+
discoverList,
|
|
366
|
+
discoverProbe,
|
|
367
|
+
discoverPromote,
|
|
368
|
+
discoverPromotePreview,
|
|
369
|
+
discoverRun,
|
|
370
|
+
discoverSeed,
|
|
371
|
+
discoverShow
|
|
372
|
+
};
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createApiClient
|
|
3
|
+
} from "./chunk-B5J675KK.js";
|
|
4
|
+
import "./chunk-UQ3MOZGC.js";
|
|
5
|
+
import "./chunk-AOJU5LKX.js";
|
|
6
|
+
import {
|
|
7
|
+
CliError,
|
|
8
|
+
EXIT_USER_ERROR
|
|
9
|
+
} from "./chunk-HGMYEDAQ.js";
|
|
10
|
+
import "./chunk-D6COIM3U.js";
|
|
11
|
+
import "./chunk-MLKGABMK.js";
|
|
12
|
+
|
|
13
|
+
// src/commands/discover-eval.ts
|
|
14
|
+
import fs from "fs";
|
|
15
|
+
import path from "path";
|
|
16
|
+
|
|
17
|
+
// src/discovery-eval.ts
|
|
18
|
+
var DISCOVERY_EVAL_PANEL = [
|
|
19
|
+
{
|
|
20
|
+
slug: "eval-local-single-intent",
|
|
21
|
+
displayName: "Summit Roof Coatings",
|
|
22
|
+
domain: "summitroofcoatings.com",
|
|
23
|
+
icp: "commercial roof coating contractor in Phoenix, Arizona",
|
|
24
|
+
buyer: "commercial property managers responsible for flat-roof maintenance budgets",
|
|
25
|
+
locations: [{ label: "phoenix", city: "Phoenix", region: "Arizona", country: "US" }]
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
slug: "eval-local-multi-intent",
|
|
29
|
+
displayName: "Peak Comfort HVAC",
|
|
30
|
+
domain: "peakcomforthvac.com",
|
|
31
|
+
icp: "residential HVAC installation, repair, and maintenance company in Denver, Colorado",
|
|
32
|
+
buyer: "homeowners with aging furnaces or AC units comparing replacement and repair options",
|
|
33
|
+
locations: [{ label: "denver", city: "Denver", region: "Colorado", country: "US" }]
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
slug: "eval-b2b-saas",
|
|
37
|
+
displayName: "QuoteBeam",
|
|
38
|
+
domain: "quotebeam.io",
|
|
39
|
+
icp: "quoting and proposal software for residential solar installers",
|
|
40
|
+
buyer: "solar sales managers evaluating quoting tools for a 10-50 rep team",
|
|
41
|
+
locations: []
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
slug: "eval-national-ecommerce",
|
|
45
|
+
displayName: "Willow and Sprout",
|
|
46
|
+
domain: "willowandsprout.com",
|
|
47
|
+
icp: "organic cotton baby clothing brand sold online across the US",
|
|
48
|
+
buyer: "expecting parents researching non-toxic baby essentials",
|
|
49
|
+
locations: []
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
slug: "eval-problem-heavy-consumer",
|
|
53
|
+
displayName: "SwiftRemit",
|
|
54
|
+
domain: "swiftremit.app",
|
|
55
|
+
icp: "mobile app for sending money internationally with low fees",
|
|
56
|
+
buyer: "immigrants who send money home to family every month",
|
|
57
|
+
locations: []
|
|
58
|
+
}
|
|
59
|
+
];
|
|
60
|
+
var EVAL_CANONICAL_FLOOR = 8;
|
|
61
|
+
var EVAL_BANDS = {
|
|
62
|
+
/** canonicalCount must be >= baseline * this factor (and >= the floor). */
|
|
63
|
+
canonicalCountFactor: 0.6,
|
|
64
|
+
/** retention may drop at most this many absolute points below baseline. */
|
|
65
|
+
retentionDrop: 0.2,
|
|
66
|
+
/** brandShare may exceed baseline by at most this (and never exceed 0.1). */
|
|
67
|
+
brandShareSlack: 0.05,
|
|
68
|
+
brandShareCeiling: 0.1,
|
|
69
|
+
/** duration must be <= baseline * factor + slack seconds. */
|
|
70
|
+
durationFactor: 2,
|
|
71
|
+
durationSlackSeconds: 30
|
|
72
|
+
};
|
|
73
|
+
function scoreSession(shape, session) {
|
|
74
|
+
const raw = session.seedCountRaw ?? 0;
|
|
75
|
+
const brandFiltered = session.seedBrandFilteredCount ?? 0;
|
|
76
|
+
const preFilterTotal = raw + brandFiltered;
|
|
77
|
+
const truncated = session.canonicalCount == null;
|
|
78
|
+
const canonicalCount = session.canonicalCount ?? session.seedCount ?? 0;
|
|
79
|
+
const started = session.startedAt ? Date.parse(session.startedAt) : NaN;
|
|
80
|
+
const finished = session.finishedAt ? Date.parse(session.finishedAt) : NaN;
|
|
81
|
+
return {
|
|
82
|
+
shape,
|
|
83
|
+
seedCountRaw: raw,
|
|
84
|
+
canonicalCount,
|
|
85
|
+
canonicalCountTruncated: truncated,
|
|
86
|
+
retention: raw > 0 ? canonicalCount / raw : 0,
|
|
87
|
+
brandShare: preFilterTotal > 0 ? brandFiltered / preFilterTotal : 0,
|
|
88
|
+
groundingShare: raw > 0 ? (session.seedFromGroundingCount ?? 0) / raw : 0,
|
|
89
|
+
bandPairFraction: session.dedupBandPairFraction ?? null,
|
|
90
|
+
probeCount: session.probeCount ?? 0,
|
|
91
|
+
warning: session.warning ?? null,
|
|
92
|
+
durationSeconds: Number.isFinite(started) && Number.isFinite(finished) ? Math.round((finished - started) / 1e3) : null
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function compareToBaseline(scorecards, baseline) {
|
|
96
|
+
const regressions = [];
|
|
97
|
+
const notes = [];
|
|
98
|
+
const bySlug = new Map(scorecards.map((c) => [c.shape, c]));
|
|
99
|
+
for (const base of baseline.scorecards) {
|
|
100
|
+
const current = bySlug.get(base.shape);
|
|
101
|
+
if (!current) {
|
|
102
|
+
regressions.push(`${base.shape}: missing from this run (baseline shape not evaluated)`);
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
bySlug.delete(base.shape);
|
|
106
|
+
if (current.canonicalCount < EVAL_CANONICAL_FLOOR) {
|
|
107
|
+
regressions.push(
|
|
108
|
+
`${base.shape}: canonicalCount ${current.canonicalCount} is below the absolute platform floor (${EVAL_CANONICAL_FLOOR})`
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
if (current.canonicalCount < base.canonicalCount * EVAL_BANDS.canonicalCountFactor) {
|
|
112
|
+
regressions.push(
|
|
113
|
+
`${base.shape}: canonicalCount ${current.canonicalCount} vs baseline ${base.canonicalCount} (band: >= ${EVAL_BANDS.canonicalCountFactor}x)`
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
if (current.canonicalCount < base.canonicalCount && current.retention < base.retention - EVAL_BANDS.retentionDrop) {
|
|
117
|
+
regressions.push(
|
|
118
|
+
`${base.shape}: retention ${current.retention.toFixed(2)} vs baseline ${base.retention.toFixed(2)} (band: -${EVAL_BANDS.retentionDrop}), with canonicals also down (${current.canonicalCount} < ${base.canonicalCount})`
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
const brandCeiling = Math.min(base.brandShare + EVAL_BANDS.brandShareSlack, EVAL_BANDS.brandShareCeiling);
|
|
122
|
+
if (current.brandShare > brandCeiling) {
|
|
123
|
+
regressions.push(
|
|
124
|
+
`${base.shape}: brandShare ${current.brandShare.toFixed(2)} exceeds ${brandCeiling.toFixed(2)} (no-brand rule regressed)`
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
if (current.warning) {
|
|
128
|
+
regressions.push(`${base.shape}: collapse warning fired: ${current.warning.slice(0, 80)}`);
|
|
129
|
+
}
|
|
130
|
+
if (current.durationSeconds != null && base.durationSeconds != null && current.durationSeconds > base.durationSeconds * EVAL_BANDS.durationFactor + EVAL_BANDS.durationSlackSeconds) {
|
|
131
|
+
regressions.push(
|
|
132
|
+
`${base.shape}: duration ${current.durationSeconds}s vs baseline ${base.durationSeconds}s (band: ${EVAL_BANDS.durationFactor}x + ${EVAL_BANDS.durationSlackSeconds}s)`
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
if (current.canonicalCountTruncated) {
|
|
136
|
+
notes.push(`${base.shape}: engine predates canonical_count; using truncated seedCount (understates quality)`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
for (const [slug] of bySlug) {
|
|
140
|
+
notes.push(`${slug}: new shape with no baseline entry (add it via --update-baseline)`);
|
|
141
|
+
}
|
|
142
|
+
return { pass: regressions.length === 0, regressions, notes };
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// src/commands/discover-eval.ts
|
|
146
|
+
var DEFAULT_BASELINE_PATH = "canonry-discovery-eval-baseline.json";
|
|
147
|
+
var POLL_INTERVAL_MS = 5e3;
|
|
148
|
+
var SHAPE_TIMEOUT_MS = 10 * 6e4;
|
|
149
|
+
async function runDiscoveryEvalPanel(client, shapes, opts) {
|
|
150
|
+
const scorecards = [];
|
|
151
|
+
const pollInterval = opts.pollIntervalMs ?? POLL_INTERVAL_MS;
|
|
152
|
+
const timeout = opts.shapeTimeoutMs ?? SHAPE_TIMEOUT_MS;
|
|
153
|
+
const now = opts.now ?? Date.now;
|
|
154
|
+
for (const shape of shapes) {
|
|
155
|
+
await client.putProject(shape.slug, {
|
|
156
|
+
displayName: shape.displayName,
|
|
157
|
+
canonicalDomain: shape.domain,
|
|
158
|
+
country: "US",
|
|
159
|
+
language: "en",
|
|
160
|
+
...shape.locations.length > 0 ? { locations: shape.locations, defaultLocation: shape.locations[0].label } : {}
|
|
161
|
+
});
|
|
162
|
+
const started = await client.triggerDiscoveryRun(shape.slug, {
|
|
163
|
+
icpDescription: shape.icp,
|
|
164
|
+
buyerDescription: shape.buyer,
|
|
165
|
+
maxProbes: opts.maxProbes ?? 2,
|
|
166
|
+
probeConcurrency: opts.probeConcurrency ?? 2,
|
|
167
|
+
...opts.seedProviders && opts.seedProviders.length > 0 ? { seedProviders: opts.seedProviders } : {}
|
|
168
|
+
});
|
|
169
|
+
const sessionId = typeof started.sessionId === "string" ? started.sessionId : "";
|
|
170
|
+
if (!sessionId) {
|
|
171
|
+
throw new CliError({
|
|
172
|
+
code: "EVAL_SESSION_START_FAILED",
|
|
173
|
+
message: `${shape.slug}: discover run returned no sessionId`,
|
|
174
|
+
exitCode: EXIT_USER_ERROR
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
const deadline = now() + timeout;
|
|
178
|
+
let session;
|
|
179
|
+
for (; ; ) {
|
|
180
|
+
const rows = await client.listDiscoverySessions(shape.slug, { limit: 10 });
|
|
181
|
+
session = rows.find((r) => r.id === sessionId);
|
|
182
|
+
if (session?.status === "completed") break;
|
|
183
|
+
if (session?.status === "failed") {
|
|
184
|
+
throw new CliError({
|
|
185
|
+
code: "EVAL_SESSION_FAILED",
|
|
186
|
+
message: `${shape.slug}: discovery session failed`,
|
|
187
|
+
exitCode: EXIT_USER_ERROR,
|
|
188
|
+
details: { sessionId }
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
if (now() > deadline) {
|
|
192
|
+
throw new CliError({
|
|
193
|
+
code: "EVAL_SESSION_TIMEOUT",
|
|
194
|
+
message: `${shape.slug}: session did not complete within ${Math.round(timeout / 6e4)} minutes`,
|
|
195
|
+
exitCode: EXIT_USER_ERROR,
|
|
196
|
+
details: { sessionId }
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
await new Promise((r) => setTimeout(r, pollInterval));
|
|
200
|
+
}
|
|
201
|
+
scorecards.push(scoreSession(shape.slug, session));
|
|
202
|
+
}
|
|
203
|
+
return scorecards;
|
|
204
|
+
}
|
|
205
|
+
function renderHuman(scorecards, verdict) {
|
|
206
|
+
console.log("SHAPE RAW CANON RETENTION BRAND GROUND BAND TIME");
|
|
207
|
+
for (const c of scorecards) {
|
|
208
|
+
console.log(
|
|
209
|
+
[
|
|
210
|
+
c.shape.padEnd(30),
|
|
211
|
+
String(c.seedCountRaw).padStart(4),
|
|
212
|
+
String(c.canonicalCount).padStart(6) + (c.canonicalCountTruncated ? "*" : " "),
|
|
213
|
+
c.retention.toFixed(2).padStart(9),
|
|
214
|
+
c.brandShare.toFixed(2).padStart(6),
|
|
215
|
+
c.groundingShare.toFixed(2).padStart(7),
|
|
216
|
+
(c.bandPairFraction ?? 0).toFixed(2).padStart(5),
|
|
217
|
+
c.durationSeconds == null ? " ?" : `${String(c.durationSeconds).padStart(4)}s`
|
|
218
|
+
].join(" ")
|
|
219
|
+
);
|
|
220
|
+
if (c.warning) console.log(` warning: ${c.warning}`);
|
|
221
|
+
}
|
|
222
|
+
if (verdict) {
|
|
223
|
+
for (const note of verdict.notes) console.log(`note: ${note}`);
|
|
224
|
+
for (const regression of verdict.regressions) console.log(`REGRESSION: ${regression}`);
|
|
225
|
+
console.log(verdict.pass ? "PASS: no regressions against the baseline." : "FAIL: regressions detected.");
|
|
226
|
+
} else {
|
|
227
|
+
console.log("No baseline compared (wrote or missing baseline).");
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
async function discoverEvalWithClient(client, opts) {
|
|
231
|
+
const selected = opts.shapes && opts.shapes.length > 0 ? DISCOVERY_EVAL_PANEL.filter((s) => opts.shapes.includes(s.slug)) : DISCOVERY_EVAL_PANEL;
|
|
232
|
+
if (selected.length === 0) {
|
|
233
|
+
throw new CliError({
|
|
234
|
+
code: "EVAL_NO_SHAPES",
|
|
235
|
+
message: `no matching shapes; known: ${DISCOVERY_EVAL_PANEL.map((s) => s.slug).join(", ")}`,
|
|
236
|
+
exitCode: EXIT_USER_ERROR
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
const scorecards = await runDiscoveryEvalPanel(client, selected, opts);
|
|
240
|
+
const baselinePath = path.resolve(opts.baseline ?? DEFAULT_BASELINE_PATH);
|
|
241
|
+
if (opts.updateBaseline) {
|
|
242
|
+
const baseline2 = { capturedAt: (/* @__PURE__ */ new Date()).toISOString(), scorecards };
|
|
243
|
+
fs.writeFileSync(baselinePath, JSON.stringify(baseline2, null, 2) + "\n");
|
|
244
|
+
if (opts.format === "json" || opts.format === "jsonl") {
|
|
245
|
+
console.log(JSON.stringify({ scorecards, baselineWritten: baselinePath }, null, 2));
|
|
246
|
+
} else {
|
|
247
|
+
renderHuman(scorecards, null);
|
|
248
|
+
console.log(`Baseline written: ${baselinePath}`);
|
|
249
|
+
}
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
if (!fs.existsSync(baselinePath)) {
|
|
253
|
+
throw new CliError({
|
|
254
|
+
code: "EVAL_NO_BASELINE",
|
|
255
|
+
message: `no baseline at ${baselinePath}; run with --update-baseline to capture one`,
|
|
256
|
+
exitCode: EXIT_USER_ERROR
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
const baseline = JSON.parse(fs.readFileSync(baselinePath, "utf8"));
|
|
260
|
+
const verdict = compareToBaseline(scorecards, baseline);
|
|
261
|
+
if (opts.format === "json" || opts.format === "jsonl") {
|
|
262
|
+
console.log(JSON.stringify({ scorecards, verdict, baseline: { capturedAt: baseline.capturedAt } }, null, 2));
|
|
263
|
+
} else {
|
|
264
|
+
renderHuman(scorecards, verdict);
|
|
265
|
+
}
|
|
266
|
+
if (!verdict.pass) {
|
|
267
|
+
throw new CliError({
|
|
268
|
+
code: "EVAL_REGRESSION",
|
|
269
|
+
message: `${verdict.regressions.length} regression${verdict.regressions.length === 1 ? "" : "s"} against the baseline`,
|
|
270
|
+
exitCode: EXIT_USER_ERROR,
|
|
271
|
+
details: { regressions: verdict.regressions }
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
async function discoverEval(opts) {
|
|
276
|
+
await discoverEvalWithClient(createApiClient(), opts);
|
|
277
|
+
}
|
|
278
|
+
export {
|
|
279
|
+
discoverEval,
|
|
280
|
+
discoverEvalWithClient,
|
|
281
|
+
runDiscoveryEvalPanel
|
|
282
|
+
};
|