@haystackeditor/cli 0.25.1 → 0.27.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 +39 -463
- package/dist/capture/app-config.js +30 -6
- package/dist/commands/capture-brief.js +45 -35
- package/dist/commands/capture-contract.js +4 -4
- package/dist/commands/crawl-report.js +196 -0
- package/dist/commands/db-profile-upload.js +3 -3
- package/dist/commands/feedback.js +66 -0
- package/dist/commands/init-telemetry.js +55 -9
- package/dist/commands/init.js +8 -3
- package/dist/commands/lockfile-pin.js +307 -0
- package/dist/commands/telemetry-token.js +3 -3
- package/dist/commands/tokens.js +4 -4
- package/dist/commands/verify-explore.js +3 -3
- package/dist/commands/verify-history.js +2 -2
- package/dist/commands/verify-onboarding.js +13 -16
- package/dist/commands/verify-precompute.js +3 -4
- package/dist/commands/verify.js +31 -118
- package/dist/index.js +55 -968
- package/dist/schema.js +4 -10
- package/dist/utils/haystack-api.js +8 -36
- package/package.json +1 -5
- package/schemas/feedback.v1.json +13 -0
- package/schemas/pre-verify.v2.json +240 -0
- package/schemas/verify-raw.v1.json +1132 -0
- package/schemas/verify.v2.json +655 -0
- package/dist/assets/hooks/agent-context/detect.ts +0 -316
- package/dist/assets/hooks/agent-context/format.ts +0 -100
- package/dist/assets/hooks/agent-context/index.ts +0 -41
- package/dist/assets/hooks/agent-context/parsers/claude.ts +0 -262
- package/dist/assets/hooks/agent-context/parsers/codex.ts +0 -416
- package/dist/assets/hooks/agent-context/parsers/gemini.ts +0 -155
- package/dist/assets/hooks/agent-context/parsers/opencode.ts +0 -174
- package/dist/assets/hooks/agent-context/tsconfig.json +0 -14
- package/dist/assets/hooks/agent-context/types.ts +0 -58
- package/dist/assets/hooks/llm-rules-template.md +0 -59
- package/dist/assets/hooks/package-lock.json +0 -598
- package/dist/assets/hooks/package.json +0 -12
- package/dist/assets/hooks/scripts/commit-msg.sh +0 -5
- package/dist/assets/hooks/scripts/post-commit.sh +0 -5
- package/dist/assets/hooks/scripts/pre-commit.sh +0 -175
- package/dist/assets/hooks/scripts/pre-push.sh +0 -25
- package/dist/assets/hooks/scripts/prepare-commit-msg.sh +0 -5
- package/dist/assets/hooks/truncation-checker/ast-analyzer.ts +0 -528
- package/dist/assets/hooks/truncation-checker/index.ts +0 -595
- package/dist/assets/hooks/truncation-checker/tsconfig.json +0 -13
- package/dist/assets/skills/map-cloud-verifier-universe/SKILL.md +0 -2051
- package/dist/assets/skills/map-cloud-verifier-universe/agents/openai.yaml +0 -4
- package/dist/assets/skills/map-cloud-verifier-universe/references/output-contract.md +0 -3411
- package/dist/assets/skills/map-your-system.md +0 -143
- package/dist/assets/skills/submit.md +0 -200
- package/dist/commands/ask.js +0 -20
- package/dist/commands/cloud-verifier-behaviors.js +0 -218
- package/dist/commands/cloud-verifier-data-store-census.js +0 -539
- package/dist/commands/cloud-verifier-data-store-drift.js +0 -158
- package/dist/commands/cloud-verifier-identity-census.js +0 -4060
- package/dist/commands/cloud-verifier-materialization.js +0 -704
- package/dist/commands/cloud-verifier-pascal-selector-census.js +0 -1382
- package/dist/commands/cloud-verifier-python-manifest-selector-census.js +0 -2015
- package/dist/commands/cloud-verifier-specialized-operational-census.js +0 -11432
- package/dist/commands/cloud-verifier-universe.js +0 -10178
- package/dist/commands/config.js +0 -549
- package/dist/commands/design-verify.js +0 -311
- package/dist/commands/dismiss.js +0 -159
- package/dist/commands/hooks.js +0 -226
- package/dist/commands/inbox.js +0 -137
- package/dist/commands/mcp.js +0 -201
- package/dist/commands/policy.js +0 -371
- package/dist/commands/pr-status.js +0 -207
- package/dist/commands/pr.js +0 -105
- package/dist/commands/prepare-universe-review.js +0 -1092
- package/dist/commands/production-source-deny-policy.js +0 -100
- package/dist/commands/request-review.js +0 -74
- package/dist/commands/review.js +0 -191
- package/dist/commands/rules.js +0 -98
- package/dist/commands/scaffold-provisional-universe.js +0 -806
- package/dist/commands/setup.js +0 -1170
- package/dist/commands/skills.js +0 -447
- package/dist/commands/status.js +0 -35
- package/dist/commands/submit.js +0 -745
- package/dist/commands/system-map.js +0 -228
- package/dist/commands/triage.js +0 -598
- package/dist/commands/webhooks.js +0 -241
- package/dist/states.js +0 -46
- package/dist/tools/detect.js +0 -832
- package/dist/triage/astra.js +0 -202
- package/dist/triage/prompts.js +0 -188
- package/dist/triage/runner.js +0 -200
- package/dist/triage/types.js +0 -7
- package/dist/types.js +0 -326
- package/dist/utils/action-output.js +0 -26
- package/dist/utils/analysis-api.js +0 -416
- package/dist/utils/config.js +0 -54
- package/dist/utils/design-verifier-api.js +0 -294
- package/dist/utils/design-verifier-history.js +0 -79
- package/dist/utils/design-verifier-result.js +0 -424
- package/dist/utils/github-api.js +0 -324
- package/dist/utils/pending-state.js +0 -86
- package/dist/utils/pr-ref.js +0 -56
- package/dist/utils/prompter.js +0 -328
- package/schemas/action.v1.json +0 -22
- package/schemas/ask.v1.json +0 -40
- package/schemas/inbox.v1.json +0 -27
- package/schemas/pr-status.v1.json +0 -61
- package/schemas/pr.v1.json +0 -97
- package/schemas/pr.v3.json +0 -45
- package/schemas/setup.v1.json +0 -75
- package/schemas/submit.v1.json +0 -90
- package/schemas/triage.v1.json +0 -103
- package/schemas/triage.v2.json +0 -64
|
@@ -1,294 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Client for the design-verifier trigger route on the auth worker.
|
|
3
|
-
*
|
|
4
|
-
* The worker owns everything sensitive: it authenticates the CLI token,
|
|
5
|
-
* enforces hsk_live repo scope, resolves the PR's base/head SHAs via the
|
|
6
|
-
* GitHub App install token, and forwards to the AWS design-verifier API with
|
|
7
|
-
* the server-side shared secret. This client just POSTs and interprets the
|
|
8
|
-
* response.
|
|
9
|
-
*/
|
|
10
|
-
import { haystackApiUrl } from './haystack-api.js';
|
|
11
|
-
import { isDesignVerifierHistoryReport } from './design-verifier-history.js';
|
|
12
|
-
function isDuration(value) {
|
|
13
|
-
return value === null || (typeof value === 'number' && Number.isFinite(value) && value >= 0);
|
|
14
|
-
}
|
|
15
|
-
function isTimestamp(value) {
|
|
16
|
-
return value === null || (typeof value === 'string' && Number.isFinite(Date.parse(value)));
|
|
17
|
-
}
|
|
18
|
-
function isTimingSummary(value) {
|
|
19
|
-
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
20
|
-
return false;
|
|
21
|
-
const timing = value;
|
|
22
|
-
if (!isDuration(timing.admissionMs) || !isDuration(timing.pipelineDurationMs) ||
|
|
23
|
-
typeof timing.recordedStageMs !== 'number' || !isDuration(timing.recordedStageMs) ||
|
|
24
|
-
!isDuration(timing.unattributedMs) ||
|
|
25
|
-
!Array.isArray(timing.stages))
|
|
26
|
-
return false;
|
|
27
|
-
const expectedStages = ['prepare', 'bake', 'blast-radius', 'prefetch', 'case-design', 'verdict'];
|
|
28
|
-
return timing.stages.length === expectedStages.length && timing.stages.every((stage, index) => stage && typeof stage === 'object' && stage.stage === expectedStages[index] &&
|
|
29
|
-
typeof stage.status === 'string' && isDuration(stage.durationMs) && isTimestamp(stage.completedAt) &&
|
|
30
|
-
['phase-artifact', 'phase-artifact-clock', 'cache-hit', 'missing'].includes(stage.source) &&
|
|
31
|
-
stage.breakdownMs && typeof stage.breakdownMs === 'object' && !Array.isArray(stage.breakdownMs) &&
|
|
32
|
-
Object.values(stage.breakdownMs).every((duration) => typeof duration === 'number' && isDuration(duration)));
|
|
33
|
-
}
|
|
34
|
-
function isDesignVerifierStatusResult(value, expected) {
|
|
35
|
-
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
36
|
-
return false;
|
|
37
|
-
const run = value;
|
|
38
|
-
if (run.version !== 'dv-cli-status-v1' || run.runId !== expected.runId ||
|
|
39
|
-
run.owner !== expected.owner || run.repo !== expected.repo || run.pr !== expected.pr ||
|
|
40
|
-
typeof run.status !== 'string')
|
|
41
|
-
return false;
|
|
42
|
-
if (run.status !== 'succeeded')
|
|
43
|
-
return true;
|
|
44
|
-
return !!run.result && typeof run.result === 'object' &&
|
|
45
|
-
run.result.verdict && typeof run.result.verdict === 'object' &&
|
|
46
|
-
Array.isArray(run.result.cases) && Array.isArray(run.result.scenarios) &&
|
|
47
|
-
Array.isArray(run.result.changedFiles) && Array.isArray(run.result.probes) &&
|
|
48
|
-
(run.result.timings === undefined || isTimingSummary(run.result.timings)) &&
|
|
49
|
-
run.result.replay && typeof run.result.replay === 'object';
|
|
50
|
-
}
|
|
51
|
-
function apiHeaders(token) {
|
|
52
|
-
return {
|
|
53
|
-
'Cache-Control': 'no-cache',
|
|
54
|
-
'User-Agent': 'Haystack-CLI',
|
|
55
|
-
Authorization: `Bearer ${token}`,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
function isUniverseAction(value, expected) {
|
|
59
|
-
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
60
|
-
return false;
|
|
61
|
-
const action = value;
|
|
62
|
-
return action.version === 'dv-universe-action-v1' && action.runId === expected.runId &&
|
|
63
|
-
(expected.actionId === undefined || action.actionId === expected.actionId) &&
|
|
64
|
-
(expected.caseId === undefined || action.caseId === expected.caseId) &&
|
|
65
|
-
(expected.universe === undefined || action.universe === expected.universe) &&
|
|
66
|
-
/^action-[0-9a-f-]{36}$/.test(action.actionId || '') &&
|
|
67
|
-
/^universe-[0-9a-f]{24}$/.test(action.universeId || '') &&
|
|
68
|
-
['control-before', 'before', 'after'].includes(action.universe) &&
|
|
69
|
-
['replay', 'exec'].includes(action.action) &&
|
|
70
|
-
['queued', 'running', 'completed', 'failed'].includes(action.status) &&
|
|
71
|
-
action.command && Array.isArray(action.command.argv) && typeof action.command.cwd === 'string';
|
|
72
|
-
}
|
|
73
|
-
function universeActionPath(owner, repo, prNumber, runId) {
|
|
74
|
-
return `/api/design-verifier/universe/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/${prNumber}/${encodeURIComponent(runId)}`;
|
|
75
|
-
}
|
|
76
|
-
async function parseUniverseActionResponse(response, expected) {
|
|
77
|
-
let data = {};
|
|
78
|
-
try {
|
|
79
|
-
data = await response.json();
|
|
80
|
-
}
|
|
81
|
-
catch {
|
|
82
|
-
return { status: 'error', message: `Universe endpoint returned invalid JSON (HTTP ${response.status})` };
|
|
83
|
-
}
|
|
84
|
-
if (response.ok) {
|
|
85
|
-
if (!isUniverseAction(data, expected)) {
|
|
86
|
-
return { status: 'error', message: `Universe endpoint returned an invalid or mismatched result (HTTP ${response.status})` };
|
|
87
|
-
}
|
|
88
|
-
return { status: 'ok', action: data };
|
|
89
|
-
}
|
|
90
|
-
const message = data.message || data.error || `HTTP ${response.status}`;
|
|
91
|
-
if (response.status === 401 || response.status === 403)
|
|
92
|
-
return { status: 'denied', message };
|
|
93
|
-
if (response.status === 404 || response.status === 410)
|
|
94
|
-
return { status: 'not_found', message };
|
|
95
|
-
if (response.status === 502 || response.status === 503)
|
|
96
|
-
return { status: 'unavailable', message };
|
|
97
|
-
return { status: 'error', message };
|
|
98
|
-
}
|
|
99
|
-
export async function startDesignVerifierUniverseAction(owner, repo, prNumber, runId, token, request) {
|
|
100
|
-
let response;
|
|
101
|
-
try {
|
|
102
|
-
response = await fetch(haystackApiUrl(universeActionPath(owner, repo, prNumber, runId)), {
|
|
103
|
-
method: 'POST',
|
|
104
|
-
headers: { ...apiHeaders(token), 'Content-Type': 'application/json' },
|
|
105
|
-
body: JSON.stringify(request),
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
catch (err) {
|
|
109
|
-
return { status: 'error', message: err.message };
|
|
110
|
-
}
|
|
111
|
-
return parseUniverseActionResponse(response, {
|
|
112
|
-
runId,
|
|
113
|
-
caseId: request.caseId,
|
|
114
|
-
universe: request.universe,
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
export async function getDesignVerifierUniverseAction(owner, repo, prNumber, runId, actionId, token) {
|
|
118
|
-
const path = universeActionPath(owner, repo, prNumber, runId);
|
|
119
|
-
let response;
|
|
120
|
-
try {
|
|
121
|
-
response = await fetch(haystackApiUrl(`${path}?actionId=${encodeURIComponent(actionId)}`), {
|
|
122
|
-
method: 'GET',
|
|
123
|
-
headers: apiHeaders(token),
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
catch (err) {
|
|
127
|
-
return { status: 'error', message: err.message };
|
|
128
|
-
}
|
|
129
|
-
return parseUniverseActionResponse(response, { runId, actionId });
|
|
130
|
-
}
|
|
131
|
-
export async function waitForDesignVerifierUniverseAction(owner, repo, prNumber, runId, actionId, token, options = {}) {
|
|
132
|
-
const intervalMs = options.intervalMs ?? 1_000;
|
|
133
|
-
const deadline = Date.now() + (options.timeoutMs ?? 10 * 60_000);
|
|
134
|
-
let consecutiveErrors = 0;
|
|
135
|
-
for (;;) {
|
|
136
|
-
const loaded = await getDesignVerifierUniverseAction(owner, repo, prNumber, runId, actionId, token);
|
|
137
|
-
if (loaded.status === 'ok') {
|
|
138
|
-
consecutiveErrors = 0;
|
|
139
|
-
if (['completed', 'failed'].includes(loaded.action.status)) {
|
|
140
|
-
return { status: 'terminal', action: loaded.action };
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
consecutiveErrors += 1;
|
|
145
|
-
if (loaded.status === 'denied' || loaded.status === 'not_found' || consecutiveErrors >= 3) {
|
|
146
|
-
return { status: 'error', message: loaded.message };
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
if (Date.now() >= deadline)
|
|
150
|
-
return { status: 'timeout' };
|
|
151
|
-
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
export async function triggerDesignVerifier(owner, repo, prNumber, token) {
|
|
155
|
-
const url = haystackApiUrl(`/api/design-verifier/trigger/${owner}/${repo}/${prNumber}`);
|
|
156
|
-
let response;
|
|
157
|
-
try {
|
|
158
|
-
response = await fetch(url, {
|
|
159
|
-
method: 'POST',
|
|
160
|
-
headers: { ...apiHeaders(token), 'Content-Type': 'application/json' },
|
|
161
|
-
body: '{}',
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
catch (err) {
|
|
165
|
-
return { status: 'error', message: err.message };
|
|
166
|
-
}
|
|
167
|
-
let data = {};
|
|
168
|
-
let parseFailed = false;
|
|
169
|
-
try {
|
|
170
|
-
data = await response.json();
|
|
171
|
-
}
|
|
172
|
-
catch {
|
|
173
|
-
// Recorded, not swallowed: non-OK statuses are classified below; a 2xx
|
|
174
|
-
// with an unparseable body becomes an explicit error rather than a
|
|
175
|
-
// silently-empty success.
|
|
176
|
-
parseFailed = true;
|
|
177
|
-
}
|
|
178
|
-
if (parseFailed && response.ok) {
|
|
179
|
-
return { status: 'error', message: `Trigger endpoint returned invalid JSON (HTTP ${response.status})` };
|
|
180
|
-
}
|
|
181
|
-
if (response.ok) {
|
|
182
|
-
const outcome = data.outcome === 'queued' || data.outcome === 'duplicate' ? data.outcome : 'started';
|
|
183
|
-
if (!data.runId) {
|
|
184
|
-
return { status: 'error', message: `Trigger succeeded but no runId was returned (HTTP ${response.status})` };
|
|
185
|
-
}
|
|
186
|
-
return { status: outcome, runId: data.runId };
|
|
187
|
-
}
|
|
188
|
-
const message = data.message || data.error || `HTTP ${response.status}`;
|
|
189
|
-
// API Gateway answers 403 "Missing Authentication Token" for routes that
|
|
190
|
-
// do not exist — which is exactly what the flag-gated backend looks like
|
|
191
|
-
// before enable_design_verifier is on. The worker's own denials carry
|
|
192
|
-
// specific error codes/messages, so this signature is unambiguous.
|
|
193
|
-
if (response.status === 403 && data.message === 'Missing Authentication Token') {
|
|
194
|
-
return { status: 'unavailable', message: 'Design verifier is not enabled in this environment yet.' };
|
|
195
|
-
}
|
|
196
|
-
if (response.status === 401 || response.status === 403)
|
|
197
|
-
return { status: 'denied', message };
|
|
198
|
-
if (response.status === 429)
|
|
199
|
-
return { status: 'rate_limited', message };
|
|
200
|
-
if (response.status === 404) {
|
|
201
|
-
// Two distinct 404s share this status: the worker's own pr_not_found
|
|
202
|
-
// (carries an error code and a specific message) versus the AWS gateway
|
|
203
|
-
// 404 for the flag-gated /v3/design-verifier route not being enabled
|
|
204
|
-
// yet. Only the latter means "feature unavailable".
|
|
205
|
-
if (data.error === 'pr_not_found') {
|
|
206
|
-
return { status: 'error', message };
|
|
207
|
-
}
|
|
208
|
-
return { status: 'unavailable', message: 'Design verifier is not enabled in this environment yet.' };
|
|
209
|
-
}
|
|
210
|
-
return { status: 'error', message };
|
|
211
|
-
}
|
|
212
|
-
export async function getDesignVerifierStatus(owner, repo, prNumber, runId, token) {
|
|
213
|
-
const url = haystackApiUrl(`/api/design-verifier/status/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/${prNumber}/${encodeURIComponent(runId)}`);
|
|
214
|
-
let response;
|
|
215
|
-
try {
|
|
216
|
-
response = await fetch(url, { method: 'GET', headers: apiHeaders(token) });
|
|
217
|
-
}
|
|
218
|
-
catch (err) {
|
|
219
|
-
return { status: 'error', message: err.message };
|
|
220
|
-
}
|
|
221
|
-
let data = {};
|
|
222
|
-
try {
|
|
223
|
-
data = await response.json();
|
|
224
|
-
}
|
|
225
|
-
catch {
|
|
226
|
-
return { status: 'error', message: `Status endpoint returned invalid JSON (HTTP ${response.status})` };
|
|
227
|
-
}
|
|
228
|
-
if (response.ok) {
|
|
229
|
-
if (!isDesignVerifierStatusResult(data, { owner, repo, pr: prNumber, runId })) {
|
|
230
|
-
return { status: 'error', message: `Status endpoint returned an invalid or mismatched result (HTTP ${response.status})` };
|
|
231
|
-
}
|
|
232
|
-
return { status: 'ok', run: data };
|
|
233
|
-
}
|
|
234
|
-
const message = data.message || data.error || `HTTP ${response.status}`;
|
|
235
|
-
if (response.status === 401 || response.status === 403)
|
|
236
|
-
return { status: 'denied', message };
|
|
237
|
-
if (response.status === 404)
|
|
238
|
-
return { status: 'not_found', message };
|
|
239
|
-
if (response.status === 502 || response.status === 503)
|
|
240
|
-
return { status: 'unavailable', message };
|
|
241
|
-
return { status: 'error', message };
|
|
242
|
-
}
|
|
243
|
-
export async function getDesignVerifierHistory(owner, repo, token, limit = 20) {
|
|
244
|
-
const url = haystackApiUrl(`/api/design-verifier/history/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}?limit=${limit}`);
|
|
245
|
-
try {
|
|
246
|
-
const response = await fetch(url, { method: 'GET', headers: apiHeaders(token) });
|
|
247
|
-
const data = await response.json();
|
|
248
|
-
if (response.ok) {
|
|
249
|
-
if (!isDesignVerifierHistoryReport(data, { owner, repo, limit })) {
|
|
250
|
-
return { status: 'error', message: 'History endpoint returned an invalid or mismatched result.' };
|
|
251
|
-
}
|
|
252
|
-
return { status: 'ok', history: data };
|
|
253
|
-
}
|
|
254
|
-
const message = data?.message || data?.error || `HTTP ${response.status}`;
|
|
255
|
-
if (response.status === 401 || response.status === 403)
|
|
256
|
-
return { status: 'denied', message };
|
|
257
|
-
if ([404, 502, 503].includes(response.status))
|
|
258
|
-
return { status: 'unavailable', message };
|
|
259
|
-
return { status: 'error', message };
|
|
260
|
-
}
|
|
261
|
-
catch (error) {
|
|
262
|
-
return { status: 'error', message: error.message };
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
export async function waitForDesignVerifier(owner, repo, prNumber, runId, token, options = {}) {
|
|
266
|
-
const intervalMs = options.intervalMs ?? 3000;
|
|
267
|
-
const timeoutMs = options.timeoutMs ?? 2 * 60 * 60 * 1000;
|
|
268
|
-
const sleep = options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
269
|
-
const deadline = Date.now() + timeoutMs;
|
|
270
|
-
let consecutiveErrors = 0;
|
|
271
|
-
let lastStage;
|
|
272
|
-
for (;;) {
|
|
273
|
-
const loaded = await getDesignVerifierStatus(owner, repo, prNumber, runId, token);
|
|
274
|
-
if (loaded.status !== 'ok') {
|
|
275
|
-
consecutiveErrors += 1;
|
|
276
|
-
if (loaded.status === 'denied' || loaded.status === 'not_found' || consecutiveErrors >= 3) {
|
|
277
|
-
return { status: 'error', message: loaded.message };
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
else {
|
|
281
|
-
consecutiveErrors = 0;
|
|
282
|
-
if (loaded.run.stage !== lastStage) {
|
|
283
|
-
lastStage = loaded.run.stage;
|
|
284
|
-
options.onProgress?.(loaded.run);
|
|
285
|
-
}
|
|
286
|
-
if (['succeeded', 'failed', 'failed-stale'].includes(loaded.run.status)) {
|
|
287
|
-
return { status: 'terminal', run: loaded.run };
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
if (Date.now() >= deadline)
|
|
291
|
-
return { status: 'timeout' };
|
|
292
|
-
await sleep(intervalMs);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
const outcomes = ['healthy', 'degraded', 'invalid', 'failed', 'unknown'];
|
|
2
|
-
export function isDesignVerifierHistoryReport(value, expected) {
|
|
3
|
-
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
4
|
-
return false;
|
|
5
|
-
const report = value;
|
|
6
|
-
if (report.version !== 'dv-cli-history-v1' || report.owner !== expected.owner ||
|
|
7
|
-
report.repo !== expected.repo || report.limit !== expected.limit ||
|
|
8
|
-
!Number.isSafeInteger(report.retentionDays) || report.retentionDays <= 0 ||
|
|
9
|
-
!Array.isArray(report.runs) || report.runs.length > report.limit || !report.summary)
|
|
10
|
-
return false;
|
|
11
|
-
const seen = new Set();
|
|
12
|
-
const counts = { healthy: 0, degraded: 0, invalid: 0, failed: 0, unknown: 0 };
|
|
13
|
-
const blockers = new Map();
|
|
14
|
-
for (const run of report.runs) {
|
|
15
|
-
if (!run || !Number.isSafeInteger(run.pr) || run.pr < 1 || typeof run.runId !== 'string')
|
|
16
|
-
return false;
|
|
17
|
-
const prefix = `${expected.owner}--${expected.repo}--${run.pr}--`;
|
|
18
|
-
if (!run.runId.startsWith(prefix) ||
|
|
19
|
-
!/^[0-9a-f]{12}(?:--attempt-[1-9]\d*)?$/.test(run.runId.slice(prefix.length)) ||
|
|
20
|
-
seen.has(run.runId) || !outcomes.includes(run.outcome) ||
|
|
21
|
-
!['succeeded', 'failed', 'failed-stale'].includes(run.status) ||
|
|
22
|
-
(run.outcome === 'failed') !== (run.status !== 'succeeded') ||
|
|
23
|
-
typeof run.createdAt !== 'string' || !Number.isFinite(Date.parse(run.createdAt)) ||
|
|
24
|
-
(run.finishedAt !== null && (typeof run.finishedAt !== 'string' || !Number.isFinite(Date.parse(run.finishedAt)))) ||
|
|
25
|
-
(run.baseSha !== null && typeof run.baseSha !== 'string') ||
|
|
26
|
-
(run.headSha !== null && typeof run.headSha !== 'string') ||
|
|
27
|
-
(run.admitted !== null && (!Number.isSafeInteger(run.admitted) || run.admitted < 0)) ||
|
|
28
|
-
!Array.isArray(run.losses) || run.losses.some(loss => !loss || typeof loss.code !== 'string' || !loss.code || typeof loss.owner !== 'string' ||
|
|
29
|
-
!loss.owner || !['degraded', 'invalid'].includes(loss.impact) ||
|
|
30
|
-
!Number.isSafeInteger(loss.count) || loss.count < 1))
|
|
31
|
-
return false;
|
|
32
|
-
if (['healthy', 'degraded'].includes(run.outcome) && (run.admitted === null || run.admitted === 0))
|
|
33
|
-
return false;
|
|
34
|
-
seen.add(run.runId);
|
|
35
|
-
counts[run.outcome]++;
|
|
36
|
-
for (const code of new Set(run.losses.map(loss => loss.code))) {
|
|
37
|
-
blockers.set(code, (blockers.get(code) || 0) + 1);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
const summary = report.summary;
|
|
41
|
-
const usableRate = report.runs.length ? (counts.healthy + counts.degraded) / report.runs.length : null;
|
|
42
|
-
if (summary.total !== report.runs.length || summary.usableRate !== usableRate ||
|
|
43
|
-
outcomes.some(outcome => summary[outcome] !== counts[outcome]) ||
|
|
44
|
-
!Array.isArray(summary.topBlockers) || summary.topBlockers.length !== blockers.size)
|
|
45
|
-
return false;
|
|
46
|
-
const seenBlockers = new Set();
|
|
47
|
-
return summary.topBlockers.every(blocker => {
|
|
48
|
-
if (!blocker || seenBlockers.has(blocker.code) || blockers.get(blocker.code) !== blocker.affectedRuns)
|
|
49
|
-
return false;
|
|
50
|
-
seenBlockers.add(blocker.code);
|
|
51
|
-
return true;
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
function terminalSafe(value) {
|
|
55
|
-
return Array.from(value).filter(character => {
|
|
56
|
-
const point = character.codePointAt(0);
|
|
57
|
-
return point >= 32 && !(point >= 127 && point <= 159);
|
|
58
|
-
}).join('');
|
|
59
|
-
}
|
|
60
|
-
export function formatDesignVerifierHistory(report) {
|
|
61
|
-
const { summary } = report;
|
|
62
|
-
const lines = [`Execution history for ${terminalSafe(report.owner)}/${terminalSafe(report.repo)}`,
|
|
63
|
-
`Latest ${summary.total} recorded terminal attempts within ${report.retentionDays} days (limit ${report.limit}).`];
|
|
64
|
-
if (summary.total === 0) {
|
|
65
|
-
lines.push('No recorded attempts in this window. History starts when recording is deployed.');
|
|
66
|
-
return lines.join('\n');
|
|
67
|
-
}
|
|
68
|
-
lines.push(`Usable evidence: ${Math.round(summary.usableRate * 100)}% of attempts (${summary.healthy + summary.degraded}/${summary.total}).`, `Fully healthy: ${summary.healthy}; partially degraded: ${summary.degraded}; invalid: ${summary.invalid}; failed: ${summary.failed}; unknown: ${summary.unknown}.`, 'Usable includes partial evidence from degraded attempts. This measures execution reliability, not bug-detection accuracy.', '');
|
|
69
|
-
for (const run of report.runs) {
|
|
70
|
-
lines.push(`${run.finishedAt || run.createdAt} PR #${run.pr} ${run.outcome} ${run.admitted ?? '?'} admitted cases`, ` ${run.runId}`);
|
|
71
|
-
}
|
|
72
|
-
if (summary.topBlockers.length) {
|
|
73
|
-
lines.push('', 'Most frequent blockers (attempts affected):');
|
|
74
|
-
for (const blocker of summary.topBlockers.slice(0, 5)) {
|
|
75
|
-
lines.push(` ${terminalSafe(blocker.code)}: ${blocker.affectedRuns}`);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return lines.join('\n');
|
|
79
|
-
}
|