@haystackeditor/cli 0.15.26 → 0.15.28
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 +52 -23
- package/dist/assets/hooks/agent-context/detect.ts +7 -7
- package/dist/assets/hooks/agent-context/parsers/claude.ts +1 -1
- package/dist/assets/hooks/package-lock.json +598 -0
- package/dist/assets/hooks/scripts/commit-msg.sh +1 -3
- package/dist/assets/hooks/scripts/post-commit.sh +1 -3
- package/dist/assets/hooks/scripts/pre-push.sh +1 -4
- package/dist/assets/hooks/scripts/prepare-commit-msg.sh +1 -2
- package/dist/assets/skills/map-cloud-verifier-universe/SKILL.md +2051 -0
- package/dist/assets/skills/map-cloud-verifier-universe/agents/openai.yaml +4 -0
- package/dist/assets/skills/map-cloud-verifier-universe/references/output-contract.md +3411 -0
- package/dist/assets/telemetry/browser-runtime.js +1469 -0
- package/dist/assets/telemetry/runtime.cjs +1503 -0
- package/dist/commands/cloud-verifier-behaviors.d.ts +27 -0
- package/dist/commands/cloud-verifier-behaviors.js +218 -0
- package/dist/commands/cloud-verifier-data-store-census.d.ts +47 -0
- package/dist/commands/cloud-verifier-data-store-census.js +539 -0
- package/dist/commands/cloud-verifier-data-store-drift.d.ts +42 -0
- package/dist/commands/cloud-verifier-data-store-drift.js +158 -0
- package/dist/commands/cloud-verifier-identity-census.d.ts +88 -0
- package/dist/commands/cloud-verifier-identity-census.js +4057 -0
- package/dist/commands/cloud-verifier-materialization.d.ts +16 -0
- package/dist/commands/cloud-verifier-materialization.js +704 -0
- package/dist/commands/cloud-verifier-pascal-selector-census.d.ts +29 -0
- package/dist/commands/cloud-verifier-pascal-selector-census.js +1382 -0
- package/dist/commands/cloud-verifier-python-manifest-selector-census.d.ts +27 -0
- package/dist/commands/cloud-verifier-python-manifest-selector-census.js +2015 -0
- package/dist/commands/cloud-verifier-specialized-operational-census.d.ts +51 -0
- package/dist/commands/cloud-verifier-specialized-operational-census.js +11432 -0
- package/dist/commands/cloud-verifier-universe.d.ts +31 -0
- package/dist/commands/cloud-verifier-universe.js +10178 -0
- package/dist/commands/design-verify.d.ts +31 -0
- package/dist/commands/design-verify.js +285 -0
- package/dist/commands/hooks.d.ts +1 -5
- package/dist/commands/hooks.js +12 -114
- package/dist/commands/install-session-hooks.d.ts +2 -2
- package/dist/commands/install-session-hooks.js +71 -21
- package/dist/commands/mcp.js +1 -34
- package/dist/commands/pr.js +2 -7
- package/dist/commands/prepare-universe-review.d.ts +115 -0
- package/dist/commands/prepare-universe-review.js +1092 -0
- package/dist/commands/production-source-deny-policy.d.ts +15 -0
- package/dist/commands/production-source-deny-policy.js +100 -0
- package/dist/commands/scaffold-provisional-universe.d.ts +468 -0
- package/dist/commands/scaffold-provisional-universe.js +808 -0
- package/dist/commands/schema-cmd.js +32 -0
- package/dist/commands/setup.d.ts +1 -2
- package/dist/commands/setup.js +18 -272
- package/dist/commands/skills.d.ts +2 -2
- package/dist/commands/skills.js +415 -47
- package/dist/commands/submit.js +1 -2
- package/dist/commands/telemetry.d.ts +53 -0
- package/dist/commands/telemetry.js +832 -0
- package/dist/commands/verify-hosted.d.ts +13 -0
- package/dist/commands/verify-hosted.js +49 -1
- package/dist/commands/verify-precompute.d.ts +19 -0
- package/dist/commands/verify-precompute.js +328 -0
- package/dist/index.js +168 -47
- package/dist/schema.d.ts +1 -2
- package/dist/schema.js +1 -2
- package/dist/triage/prompts.d.ts +0 -7
- package/dist/triage/prompts.js +0 -145
- package/dist/triage/runner.js +10 -28
- package/dist/triage/types.d.ts +1 -8
- package/dist/types.d.ts +8 -8
- package/dist/types.js +1 -1
- package/dist/utils/design-verifier-api.d.ts +200 -0
- package/dist/utils/design-verifier-api.js +271 -0
- package/dist/utils/design-verifier-result.d.ts +57 -0
- package/dist/utils/design-verifier-result.js +345 -0
- package/dist/utils/git.d.ts +5 -1
- package/dist/utils/git.js +19 -9
- package/dist/utils/github-api.js +11 -14
- package/dist/utils/haystack-api.d.ts +2 -0
- package/dist/utils/haystack-api.js +10 -3
- package/dist/utils/hooks.d.ts +1 -15
- package/dist/utils/hooks.js +3 -128
- package/dist/utils/telemetry.d.ts +2 -0
- package/dist/utils/telemetry.js +81 -8
- package/package.json +8 -2
- package/schemas/cloud-verifier.v1.json +69 -3
- package/schemas/{pr.v2.json → pr.v3.json} +3 -12
- package/dist/commands/traces.d.ts +0 -48
- package/dist/commands/traces.js +0 -92
- package/dist/triage/traces.d.ts +0 -20
- package/dist/triage/traces.js +0 -311
- package/schemas/traces.v1.json +0 -53
package/dist/types.d.ts
CHANGED
|
@@ -709,14 +709,14 @@ declare const SecretDeclarationSchema: z.ZodObject<{
|
|
|
709
709
|
}>;
|
|
710
710
|
declare const TriageConfigSchema: z.ZodObject<{
|
|
711
711
|
/** Per-checker max agentic turns. Unspecified checkers use built-in defaults. */
|
|
712
|
-
maxTurns: z.ZodOptional<z.ZodRecord<z.ZodEnum<["code-review", "rules-validator"
|
|
712
|
+
maxTurns: z.ZodOptional<z.ZodRecord<z.ZodEnum<["code-review", "rules-validator"]>, z.ZodNumber>>;
|
|
713
713
|
/** Wall-clock timeout per checker, in milliseconds. */
|
|
714
714
|
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
715
715
|
}, "strip", z.ZodTypeAny, {
|
|
716
|
-
maxTurns?: Partial<Record<"code-review" | "rules-validator"
|
|
716
|
+
maxTurns?: Partial<Record<"code-review" | "rules-validator", number>> | undefined;
|
|
717
717
|
timeoutMs?: number | undefined;
|
|
718
718
|
}, {
|
|
719
|
-
maxTurns?: Partial<Record<"code-review" | "rules-validator"
|
|
719
|
+
maxTurns?: Partial<Record<"code-review" | "rules-validator", number>> | undefined;
|
|
720
720
|
timeoutMs?: number | undefined;
|
|
721
721
|
}>;
|
|
722
722
|
declare const PreferencesSchema: z.ZodObject<{
|
|
@@ -1315,14 +1315,14 @@ export declare const HaystackConfigSchema: z.ZodObject<{
|
|
|
1315
1315
|
/** Pre-PR triage configuration (turn budgets, timeouts) */
|
|
1316
1316
|
triage: z.ZodOptional<z.ZodObject<{
|
|
1317
1317
|
/** Per-checker max agentic turns. Unspecified checkers use built-in defaults. */
|
|
1318
|
-
maxTurns: z.ZodOptional<z.ZodRecord<z.ZodEnum<["code-review", "rules-validator"
|
|
1318
|
+
maxTurns: z.ZodOptional<z.ZodRecord<z.ZodEnum<["code-review", "rules-validator"]>, z.ZodNumber>>;
|
|
1319
1319
|
/** Wall-clock timeout per checker, in milliseconds. */
|
|
1320
1320
|
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
1321
1321
|
}, "strip", z.ZodTypeAny, {
|
|
1322
|
-
maxTurns?: Partial<Record<"code-review" | "rules-validator"
|
|
1322
|
+
maxTurns?: Partial<Record<"code-review" | "rules-validator", number>> | undefined;
|
|
1323
1323
|
timeoutMs?: number | undefined;
|
|
1324
1324
|
}, {
|
|
1325
|
-
maxTurns?: Partial<Record<"code-review" | "rules-validator"
|
|
1325
|
+
maxTurns?: Partial<Record<"code-review" | "rules-validator", number>> | undefined;
|
|
1326
1326
|
timeoutMs?: number | undefined;
|
|
1327
1327
|
}>>;
|
|
1328
1328
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -1455,7 +1455,7 @@ export declare const HaystackConfigSchema: z.ZodObject<{
|
|
|
1455
1455
|
description?: string | undefined;
|
|
1456
1456
|
}> | undefined;
|
|
1457
1457
|
triage?: {
|
|
1458
|
-
maxTurns?: Partial<Record<"code-review" | "rules-validator"
|
|
1458
|
+
maxTurns?: Partial<Record<"code-review" | "rules-validator", number>> | undefined;
|
|
1459
1459
|
timeoutMs?: number | undefined;
|
|
1460
1460
|
} | undefined;
|
|
1461
1461
|
}, {
|
|
@@ -1588,7 +1588,7 @@ export declare const HaystackConfigSchema: z.ZodObject<{
|
|
|
1588
1588
|
description?: string | undefined;
|
|
1589
1589
|
}> | undefined;
|
|
1590
1590
|
triage?: {
|
|
1591
|
-
maxTurns?: Partial<Record<"code-review" | "rules-validator"
|
|
1591
|
+
maxTurns?: Partial<Record<"code-review" | "rules-validator", number>> | undefined;
|
|
1592
1592
|
timeoutMs?: number | undefined;
|
|
1593
1593
|
} | undefined;
|
|
1594
1594
|
}>;
|
package/dist/types.js
CHANGED
|
@@ -272,7 +272,7 @@ const SecretDeclarationSchema = z.object({
|
|
|
272
272
|
// =============================================================================
|
|
273
273
|
// TRIAGE CONFIGURATION
|
|
274
274
|
// =============================================================================
|
|
275
|
-
const TriageCheckerNameSchema = z.enum(['code-review', 'rules-validator'
|
|
275
|
+
const TriageCheckerNameSchema = z.enum(['code-review', 'rules-validator']);
|
|
276
276
|
const TriageConfigSchema = z.object({
|
|
277
277
|
/** Per-checker max agentic turns. Unspecified checkers use built-in defaults. */
|
|
278
278
|
maxTurns: z.record(TriageCheckerNameSchema, z.number().int().positive()).optional(),
|
|
@@ -0,0 +1,200 @@
|
|
|
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
|
+
export type DesignVerifierTriggerResult = {
|
|
11
|
+
status: 'started' | 'queued' | 'duplicate';
|
|
12
|
+
runId: string;
|
|
13
|
+
} | {
|
|
14
|
+
status: 'denied';
|
|
15
|
+
message: string;
|
|
16
|
+
} | {
|
|
17
|
+
status: 'rate_limited';
|
|
18
|
+
message: string;
|
|
19
|
+
} | {
|
|
20
|
+
status: 'unavailable';
|
|
21
|
+
message: string;
|
|
22
|
+
} | {
|
|
23
|
+
status: 'error';
|
|
24
|
+
message: string;
|
|
25
|
+
};
|
|
26
|
+
export interface DesignVerifierCommandSpec {
|
|
27
|
+
cwd: string;
|
|
28
|
+
argv: string[];
|
|
29
|
+
env: Record<string, string>;
|
|
30
|
+
timeoutMs?: number;
|
|
31
|
+
}
|
|
32
|
+
export interface DesignVerifierExecutionDiagnostic {
|
|
33
|
+
diagnosticId: string;
|
|
34
|
+
kind: string;
|
|
35
|
+
message: string;
|
|
36
|
+
type?: string;
|
|
37
|
+
code?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface DesignVerifierExecutionSummary {
|
|
40
|
+
side: 'base1' | 'base2' | 'head';
|
|
41
|
+
status: 'completed' | 'failed' | 'missing';
|
|
42
|
+
commandExitCode: number | null;
|
|
43
|
+
durationMs: number | null;
|
|
44
|
+
scenarioError: string | null;
|
|
45
|
+
diagnostics: DesignVerifierExecutionDiagnostic[];
|
|
46
|
+
diagnosticsOmitted: number;
|
|
47
|
+
outputExcerpt: Array<{
|
|
48
|
+
stream: 'stdout' | 'stderr' | 'system' | 'output';
|
|
49
|
+
text: string;
|
|
50
|
+
}>;
|
|
51
|
+
outputLinesOmitted: number;
|
|
52
|
+
traceArtifact: string;
|
|
53
|
+
outputArtifact: string;
|
|
54
|
+
}
|
|
55
|
+
export type DesignVerifierUniverseRole = 'control-before' | 'before' | 'after';
|
|
56
|
+
export interface DesignVerifierUniverseSummary {
|
|
57
|
+
version: 'dv-case-universe-summary-v1';
|
|
58
|
+
universeId: string;
|
|
59
|
+
caseRunId: string;
|
|
60
|
+
caseId: string;
|
|
61
|
+
role: DesignVerifierUniverseRole;
|
|
62
|
+
revision: string;
|
|
63
|
+
capabilities: Array<'inspect' | 'query' | 'replay' | 'exec'>;
|
|
64
|
+
lease: {
|
|
65
|
+
state: 'leased' | 'released';
|
|
66
|
+
expiresAt: string | null;
|
|
67
|
+
available: boolean;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export interface DesignVerifierUniverseAction {
|
|
71
|
+
version: 'dv-universe-action-v1';
|
|
72
|
+
actionId: string;
|
|
73
|
+
runId: string;
|
|
74
|
+
caseId: string;
|
|
75
|
+
universe: DesignVerifierUniverseRole;
|
|
76
|
+
universeId: string;
|
|
77
|
+
action: 'replay' | 'exec';
|
|
78
|
+
command: {
|
|
79
|
+
cwd: string;
|
|
80
|
+
argv: string[];
|
|
81
|
+
timeoutMs: number;
|
|
82
|
+
};
|
|
83
|
+
status: 'queued' | 'running' | 'completed' | 'failed';
|
|
84
|
+
createdAt: string;
|
|
85
|
+
startedAt: string | null;
|
|
86
|
+
finishedAt: string | null;
|
|
87
|
+
result: {
|
|
88
|
+
exitCode: number | null;
|
|
89
|
+
stdout: string;
|
|
90
|
+
stderr: string;
|
|
91
|
+
stdoutOmittedBytes: number;
|
|
92
|
+
stderrOmittedBytes: number;
|
|
93
|
+
durationMs: number;
|
|
94
|
+
} | null;
|
|
95
|
+
error: string | null;
|
|
96
|
+
}
|
|
97
|
+
export interface DesignVerifierStageTiming {
|
|
98
|
+
stage: 'prepare' | 'bake' | 'blast-radius' | 'prefetch' | 'case-design' | 'verdict';
|
|
99
|
+
status: string;
|
|
100
|
+
durationMs: number | null;
|
|
101
|
+
completedAt: string | null;
|
|
102
|
+
source: 'phase-artifact' | 'phase-artifact-clock' | 'cache-hit' | 'missing';
|
|
103
|
+
breakdownMs: Record<string, number>;
|
|
104
|
+
pollCount?: number;
|
|
105
|
+
}
|
|
106
|
+
export interface DesignVerifierTimingSummary {
|
|
107
|
+
admissionMs: number | null;
|
|
108
|
+
pipelineDurationMs: number | null;
|
|
109
|
+
recordedStageMs: number;
|
|
110
|
+
unattributedMs: number | null;
|
|
111
|
+
stages: DesignVerifierStageTiming[];
|
|
112
|
+
}
|
|
113
|
+
export interface DesignVerifierStatusResult {
|
|
114
|
+
version: 'dv-cli-status-v1';
|
|
115
|
+
runId: string;
|
|
116
|
+
owner: string;
|
|
117
|
+
repo: string;
|
|
118
|
+
pr: number;
|
|
119
|
+
baseSha: string | null;
|
|
120
|
+
headSha: string | null;
|
|
121
|
+
status: string;
|
|
122
|
+
stage: string | null;
|
|
123
|
+
createdAt: string | null;
|
|
124
|
+
startedAt: string | null;
|
|
125
|
+
finishedAt: string | null;
|
|
126
|
+
durationMs: number | null;
|
|
127
|
+
error: string | null;
|
|
128
|
+
result?: {
|
|
129
|
+
verdict: Record<string, any>;
|
|
130
|
+
cases: Array<Record<string, any>>;
|
|
131
|
+
scenarios: Array<Record<string, any> & {
|
|
132
|
+
executions?: DesignVerifierExecutionSummary[];
|
|
133
|
+
universes?: DesignVerifierUniverseSummary[];
|
|
134
|
+
}>;
|
|
135
|
+
changedFiles: string[];
|
|
136
|
+
timings?: DesignVerifierTimingSummary;
|
|
137
|
+
probes: Array<{
|
|
138
|
+
caseId: string;
|
|
139
|
+
title: string;
|
|
140
|
+
files: string[];
|
|
141
|
+
validate: DesignVerifierCommandSpec | null;
|
|
142
|
+
run: DesignVerifierCommandSpec | null;
|
|
143
|
+
}>;
|
|
144
|
+
replay: {
|
|
145
|
+
artifactPrefix: string;
|
|
146
|
+
keys: Record<string, string>;
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
export type DesignVerifierStatusFetchResult = {
|
|
151
|
+
status: 'ok';
|
|
152
|
+
run: DesignVerifierStatusResult;
|
|
153
|
+
} | {
|
|
154
|
+
status: 'not_found' | 'denied' | 'unavailable' | 'error';
|
|
155
|
+
message: string;
|
|
156
|
+
};
|
|
157
|
+
export type DesignVerifierUniverseActionFetchResult = {
|
|
158
|
+
status: 'ok';
|
|
159
|
+
action: DesignVerifierUniverseAction;
|
|
160
|
+
} | {
|
|
161
|
+
status: 'not_found' | 'denied' | 'unavailable' | 'error';
|
|
162
|
+
message: string;
|
|
163
|
+
};
|
|
164
|
+
export declare function startDesignVerifierUniverseAction(owner: string, repo: string, prNumber: number, runId: string, token: string, request: {
|
|
165
|
+
caseId: string;
|
|
166
|
+
universe: DesignVerifierUniverseRole;
|
|
167
|
+
action: 'replay' | 'exec';
|
|
168
|
+
argv?: string[];
|
|
169
|
+
cwd?: string;
|
|
170
|
+
timeoutMs?: number;
|
|
171
|
+
}): Promise<DesignVerifierUniverseActionFetchResult>;
|
|
172
|
+
export declare function getDesignVerifierUniverseAction(owner: string, repo: string, prNumber: number, runId: string, actionId: string, token: string): Promise<DesignVerifierUniverseActionFetchResult>;
|
|
173
|
+
export declare function waitForDesignVerifierUniverseAction(owner: string, repo: string, prNumber: number, runId: string, actionId: string, token: string, options?: {
|
|
174
|
+
intervalMs?: number;
|
|
175
|
+
timeoutMs?: number;
|
|
176
|
+
}): Promise<{
|
|
177
|
+
status: 'terminal';
|
|
178
|
+
action: DesignVerifierUniverseAction;
|
|
179
|
+
} | {
|
|
180
|
+
status: 'timeout';
|
|
181
|
+
} | {
|
|
182
|
+
status: 'error';
|
|
183
|
+
message: string;
|
|
184
|
+
}>;
|
|
185
|
+
export declare function triggerDesignVerifier(owner: string, repo: string, prNumber: number, token: string): Promise<DesignVerifierTriggerResult>;
|
|
186
|
+
export declare function getDesignVerifierStatus(owner: string, repo: string, prNumber: number, runId: string, token: string): Promise<DesignVerifierStatusFetchResult>;
|
|
187
|
+
export declare function waitForDesignVerifier(owner: string, repo: string, prNumber: number, runId: string, token: string, options?: {
|
|
188
|
+
intervalMs?: number;
|
|
189
|
+
timeoutMs?: number;
|
|
190
|
+
onProgress?: (run: DesignVerifierStatusResult) => void;
|
|
191
|
+
sleep?: (ms: number) => Promise<void>;
|
|
192
|
+
}): Promise<{
|
|
193
|
+
status: 'terminal';
|
|
194
|
+
run: DesignVerifierStatusResult;
|
|
195
|
+
} | {
|
|
196
|
+
status: 'timeout';
|
|
197
|
+
} | {
|
|
198
|
+
status: 'error';
|
|
199
|
+
message: string;
|
|
200
|
+
}>;
|
|
@@ -0,0 +1,271 @@
|
|
|
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
|
+
function isDuration(value) {
|
|
12
|
+
return value === null || (typeof value === 'number' && Number.isFinite(value) && value >= 0);
|
|
13
|
+
}
|
|
14
|
+
function isTimestamp(value) {
|
|
15
|
+
return value === null || (typeof value === 'string' && Number.isFinite(Date.parse(value)));
|
|
16
|
+
}
|
|
17
|
+
function isTimingSummary(value) {
|
|
18
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
19
|
+
return false;
|
|
20
|
+
const timing = value;
|
|
21
|
+
if (!isDuration(timing.admissionMs) || !isDuration(timing.pipelineDurationMs) ||
|
|
22
|
+
typeof timing.recordedStageMs !== 'number' || !isDuration(timing.recordedStageMs) ||
|
|
23
|
+
!isDuration(timing.unattributedMs) ||
|
|
24
|
+
!Array.isArray(timing.stages))
|
|
25
|
+
return false;
|
|
26
|
+
const expectedStages = ['prepare', 'bake', 'blast-radius', 'prefetch', 'case-design', 'verdict'];
|
|
27
|
+
return timing.stages.length === expectedStages.length && timing.stages.every((stage, index) => stage && typeof stage === 'object' && stage.stage === expectedStages[index] &&
|
|
28
|
+
typeof stage.status === 'string' && isDuration(stage.durationMs) && isTimestamp(stage.completedAt) &&
|
|
29
|
+
['phase-artifact', 'phase-artifact-clock', 'cache-hit', 'missing'].includes(stage.source) &&
|
|
30
|
+
stage.breakdownMs && typeof stage.breakdownMs === 'object' && !Array.isArray(stage.breakdownMs) &&
|
|
31
|
+
Object.values(stage.breakdownMs).every((duration) => typeof duration === 'number' && isDuration(duration)));
|
|
32
|
+
}
|
|
33
|
+
function isDesignVerifierStatusResult(value, expected) {
|
|
34
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
35
|
+
return false;
|
|
36
|
+
const run = value;
|
|
37
|
+
if (run.version !== 'dv-cli-status-v1' || run.runId !== expected.runId ||
|
|
38
|
+
run.owner !== expected.owner || run.repo !== expected.repo || run.pr !== expected.pr ||
|
|
39
|
+
typeof run.status !== 'string')
|
|
40
|
+
return false;
|
|
41
|
+
if (run.status !== 'succeeded')
|
|
42
|
+
return true;
|
|
43
|
+
return !!run.result && typeof run.result === 'object' &&
|
|
44
|
+
run.result.verdict && typeof run.result.verdict === 'object' &&
|
|
45
|
+
Array.isArray(run.result.cases) && Array.isArray(run.result.scenarios) &&
|
|
46
|
+
Array.isArray(run.result.changedFiles) && Array.isArray(run.result.probes) &&
|
|
47
|
+
(run.result.timings === undefined || isTimingSummary(run.result.timings)) &&
|
|
48
|
+
run.result.replay && typeof run.result.replay === 'object';
|
|
49
|
+
}
|
|
50
|
+
function apiHeaders(token) {
|
|
51
|
+
return {
|
|
52
|
+
'Cache-Control': 'no-cache',
|
|
53
|
+
'User-Agent': 'Haystack-CLI',
|
|
54
|
+
Authorization: `Bearer ${token}`,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function isUniverseAction(value, expected) {
|
|
58
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
59
|
+
return false;
|
|
60
|
+
const action = value;
|
|
61
|
+
return action.version === 'dv-universe-action-v1' && action.runId === expected.runId &&
|
|
62
|
+
(expected.actionId === undefined || action.actionId === expected.actionId) &&
|
|
63
|
+
(expected.caseId === undefined || action.caseId === expected.caseId) &&
|
|
64
|
+
(expected.universe === undefined || action.universe === expected.universe) &&
|
|
65
|
+
/^action-[0-9a-f-]{36}$/.test(action.actionId || '') &&
|
|
66
|
+
/^universe-[0-9a-f]{24}$/.test(action.universeId || '') &&
|
|
67
|
+
['control-before', 'before', 'after'].includes(action.universe) &&
|
|
68
|
+
['replay', 'exec'].includes(action.action) &&
|
|
69
|
+
['queued', 'running', 'completed', 'failed'].includes(action.status) &&
|
|
70
|
+
action.command && Array.isArray(action.command.argv) && typeof action.command.cwd === 'string';
|
|
71
|
+
}
|
|
72
|
+
function universeActionPath(owner, repo, prNumber, runId) {
|
|
73
|
+
return `/api/design-verifier/universe/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/${prNumber}/${encodeURIComponent(runId)}`;
|
|
74
|
+
}
|
|
75
|
+
async function parseUniverseActionResponse(response, expected) {
|
|
76
|
+
let data = {};
|
|
77
|
+
try {
|
|
78
|
+
data = await response.json();
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return { status: 'error', message: `Universe endpoint returned invalid JSON (HTTP ${response.status})` };
|
|
82
|
+
}
|
|
83
|
+
if (response.ok) {
|
|
84
|
+
if (!isUniverseAction(data, expected)) {
|
|
85
|
+
return { status: 'error', message: `Universe endpoint returned an invalid or mismatched result (HTTP ${response.status})` };
|
|
86
|
+
}
|
|
87
|
+
return { status: 'ok', action: data };
|
|
88
|
+
}
|
|
89
|
+
const message = data.message || data.error || `HTTP ${response.status}`;
|
|
90
|
+
if (response.status === 401 || response.status === 403)
|
|
91
|
+
return { status: 'denied', message };
|
|
92
|
+
if (response.status === 404 || response.status === 410)
|
|
93
|
+
return { status: 'not_found', message };
|
|
94
|
+
if (response.status === 502 || response.status === 503)
|
|
95
|
+
return { status: 'unavailable', message };
|
|
96
|
+
return { status: 'error', message };
|
|
97
|
+
}
|
|
98
|
+
export async function startDesignVerifierUniverseAction(owner, repo, prNumber, runId, token, request) {
|
|
99
|
+
let response;
|
|
100
|
+
try {
|
|
101
|
+
response = await fetch(haystackApiUrl(universeActionPath(owner, repo, prNumber, runId)), {
|
|
102
|
+
method: 'POST',
|
|
103
|
+
headers: { ...apiHeaders(token), 'Content-Type': 'application/json' },
|
|
104
|
+
body: JSON.stringify(request),
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
catch (err) {
|
|
108
|
+
return { status: 'error', message: err.message };
|
|
109
|
+
}
|
|
110
|
+
return parseUniverseActionResponse(response, {
|
|
111
|
+
runId,
|
|
112
|
+
caseId: request.caseId,
|
|
113
|
+
universe: request.universe,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
export async function getDesignVerifierUniverseAction(owner, repo, prNumber, runId, actionId, token) {
|
|
117
|
+
const path = universeActionPath(owner, repo, prNumber, runId);
|
|
118
|
+
let response;
|
|
119
|
+
try {
|
|
120
|
+
response = await fetch(haystackApiUrl(`${path}?actionId=${encodeURIComponent(actionId)}`), {
|
|
121
|
+
method: 'GET',
|
|
122
|
+
headers: apiHeaders(token),
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
catch (err) {
|
|
126
|
+
return { status: 'error', message: err.message };
|
|
127
|
+
}
|
|
128
|
+
return parseUniverseActionResponse(response, { runId, actionId });
|
|
129
|
+
}
|
|
130
|
+
export async function waitForDesignVerifierUniverseAction(owner, repo, prNumber, runId, actionId, token, options = {}) {
|
|
131
|
+
const intervalMs = options.intervalMs ?? 1_000;
|
|
132
|
+
const deadline = Date.now() + (options.timeoutMs ?? 10 * 60_000);
|
|
133
|
+
let consecutiveErrors = 0;
|
|
134
|
+
for (;;) {
|
|
135
|
+
const loaded = await getDesignVerifierUniverseAction(owner, repo, prNumber, runId, actionId, token);
|
|
136
|
+
if (loaded.status === 'ok') {
|
|
137
|
+
consecutiveErrors = 0;
|
|
138
|
+
if (['completed', 'failed'].includes(loaded.action.status)) {
|
|
139
|
+
return { status: 'terminal', action: loaded.action };
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
consecutiveErrors += 1;
|
|
144
|
+
if (loaded.status === 'denied' || loaded.status === 'not_found' || consecutiveErrors >= 3) {
|
|
145
|
+
return { status: 'error', message: loaded.message };
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (Date.now() >= deadline)
|
|
149
|
+
return { status: 'timeout' };
|
|
150
|
+
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
export async function triggerDesignVerifier(owner, repo, prNumber, token) {
|
|
154
|
+
const url = haystackApiUrl(`/api/design-verifier/trigger/${owner}/${repo}/${prNumber}`);
|
|
155
|
+
let response;
|
|
156
|
+
try {
|
|
157
|
+
response = await fetch(url, {
|
|
158
|
+
method: 'POST',
|
|
159
|
+
headers: { ...apiHeaders(token), 'Content-Type': 'application/json' },
|
|
160
|
+
body: '{}',
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
catch (err) {
|
|
164
|
+
return { status: 'error', message: err.message };
|
|
165
|
+
}
|
|
166
|
+
let data = {};
|
|
167
|
+
let parseFailed = false;
|
|
168
|
+
try {
|
|
169
|
+
data = await response.json();
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
// Recorded, not swallowed: non-OK statuses are classified below; a 2xx
|
|
173
|
+
// with an unparseable body becomes an explicit error rather than a
|
|
174
|
+
// silently-empty success.
|
|
175
|
+
parseFailed = true;
|
|
176
|
+
}
|
|
177
|
+
if (parseFailed && response.ok) {
|
|
178
|
+
return { status: 'error', message: `Trigger endpoint returned invalid JSON (HTTP ${response.status})` };
|
|
179
|
+
}
|
|
180
|
+
if (response.ok) {
|
|
181
|
+
const outcome = data.outcome === 'queued' || data.outcome === 'duplicate' ? data.outcome : 'started';
|
|
182
|
+
if (!data.runId) {
|
|
183
|
+
return { status: 'error', message: `Trigger succeeded but no runId was returned (HTTP ${response.status})` };
|
|
184
|
+
}
|
|
185
|
+
return { status: outcome, runId: data.runId };
|
|
186
|
+
}
|
|
187
|
+
const message = data.message || data.error || `HTTP ${response.status}`;
|
|
188
|
+
// API Gateway answers 403 "Missing Authentication Token" for routes that
|
|
189
|
+
// do not exist — which is exactly what the flag-gated backend looks like
|
|
190
|
+
// before enable_design_verifier is on. The worker's own denials carry
|
|
191
|
+
// specific error codes/messages, so this signature is unambiguous.
|
|
192
|
+
if (response.status === 403 && data.message === 'Missing Authentication Token') {
|
|
193
|
+
return { status: 'unavailable', message: 'Design verifier is not enabled in this environment yet.' };
|
|
194
|
+
}
|
|
195
|
+
if (response.status === 401 || response.status === 403)
|
|
196
|
+
return { status: 'denied', message };
|
|
197
|
+
if (response.status === 429)
|
|
198
|
+
return { status: 'rate_limited', message };
|
|
199
|
+
if (response.status === 404) {
|
|
200
|
+
// Two distinct 404s share this status: the worker's own pr_not_found
|
|
201
|
+
// (carries an error code and a specific message) versus the AWS gateway
|
|
202
|
+
// 404 for the flag-gated /v3/design-verifier route not being enabled
|
|
203
|
+
// yet. Only the latter means "feature unavailable".
|
|
204
|
+
if (data.error === 'pr_not_found') {
|
|
205
|
+
return { status: 'error', message };
|
|
206
|
+
}
|
|
207
|
+
return { status: 'unavailable', message: 'Design verifier is not enabled in this environment yet.' };
|
|
208
|
+
}
|
|
209
|
+
return { status: 'error', message };
|
|
210
|
+
}
|
|
211
|
+
export async function getDesignVerifierStatus(owner, repo, prNumber, runId, token) {
|
|
212
|
+
const url = haystackApiUrl(`/api/design-verifier/status/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/${prNumber}/${encodeURIComponent(runId)}`);
|
|
213
|
+
let response;
|
|
214
|
+
try {
|
|
215
|
+
response = await fetch(url, { method: 'GET', headers: apiHeaders(token) });
|
|
216
|
+
}
|
|
217
|
+
catch (err) {
|
|
218
|
+
return { status: 'error', message: err.message };
|
|
219
|
+
}
|
|
220
|
+
let data = {};
|
|
221
|
+
try {
|
|
222
|
+
data = await response.json();
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
|
+
return { status: 'error', message: `Status endpoint returned invalid JSON (HTTP ${response.status})` };
|
|
226
|
+
}
|
|
227
|
+
if (response.ok) {
|
|
228
|
+
if (!isDesignVerifierStatusResult(data, { owner, repo, pr: prNumber, runId })) {
|
|
229
|
+
return { status: 'error', message: `Status endpoint returned an invalid or mismatched result (HTTP ${response.status})` };
|
|
230
|
+
}
|
|
231
|
+
return { status: 'ok', run: data };
|
|
232
|
+
}
|
|
233
|
+
const message = data.message || data.error || `HTTP ${response.status}`;
|
|
234
|
+
if (response.status === 401 || response.status === 403)
|
|
235
|
+
return { status: 'denied', message };
|
|
236
|
+
if (response.status === 404)
|
|
237
|
+
return { status: 'not_found', message };
|
|
238
|
+
if (response.status === 502 || response.status === 503)
|
|
239
|
+
return { status: 'unavailable', message };
|
|
240
|
+
return { status: 'error', message };
|
|
241
|
+
}
|
|
242
|
+
export async function waitForDesignVerifier(owner, repo, prNumber, runId, token, options = {}) {
|
|
243
|
+
const intervalMs = options.intervalMs ?? 3000;
|
|
244
|
+
const timeoutMs = options.timeoutMs ?? 2 * 60 * 60 * 1000;
|
|
245
|
+
const sleep = options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
246
|
+
const deadline = Date.now() + timeoutMs;
|
|
247
|
+
let consecutiveErrors = 0;
|
|
248
|
+
let lastStage;
|
|
249
|
+
for (;;) {
|
|
250
|
+
const loaded = await getDesignVerifierStatus(owner, repo, prNumber, runId, token);
|
|
251
|
+
if (loaded.status !== 'ok') {
|
|
252
|
+
consecutiveErrors += 1;
|
|
253
|
+
if (loaded.status === 'denied' || loaded.status === 'not_found' || consecutiveErrors >= 3) {
|
|
254
|
+
return { status: 'error', message: loaded.message };
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
consecutiveErrors = 0;
|
|
259
|
+
if (loaded.run.stage !== lastStage) {
|
|
260
|
+
lastStage = loaded.run.stage;
|
|
261
|
+
options.onProgress?.(loaded.run);
|
|
262
|
+
}
|
|
263
|
+
if (['succeeded', 'failed', 'failed-stale'].includes(loaded.run.status)) {
|
|
264
|
+
return { status: 'terminal', run: loaded.run };
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
if (Date.now() >= deadline)
|
|
268
|
+
return { status: 'timeout' };
|
|
269
|
+
await sleep(intervalMs);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { DesignVerifierCommandSpec, DesignVerifierExecutionSummary, DesignVerifierStatusResult, DesignVerifierTimingSummary, DesignVerifierUniverseSummary } from './design-verifier-api.js';
|
|
2
|
+
export type DesignVerifierAgentVerdict = 'fix_confirmed' | 'anomaly_candidate' | 'no_unexpected_change' | 'inconclusive';
|
|
3
|
+
export interface DesignVerifierAgentCase {
|
|
4
|
+
id: string;
|
|
5
|
+
title: string;
|
|
6
|
+
story: string;
|
|
7
|
+
expectedHead: string;
|
|
8
|
+
verdict: 'confirmed' | 'finding' | 'clean' | 'inconclusive';
|
|
9
|
+
findingKind: string | null;
|
|
10
|
+
findingKinds: string[];
|
|
11
|
+
baseStable: boolean | null;
|
|
12
|
+
observations: Array<{
|
|
13
|
+
path: string;
|
|
14
|
+
base: unknown;
|
|
15
|
+
baseRepeat: unknown;
|
|
16
|
+
head: unknown;
|
|
17
|
+
controlObservedAtSamePath: boolean;
|
|
18
|
+
controlObservedAtAncestorPath: boolean;
|
|
19
|
+
controlObservedAtDescendantPath: boolean;
|
|
20
|
+
}>;
|
|
21
|
+
generatedFiles: string[];
|
|
22
|
+
executedCommand: DesignVerifierCommandSpec | null;
|
|
23
|
+
executions: DesignVerifierExecutionSummary[];
|
|
24
|
+
universes: DesignVerifierUniverseSummary[];
|
|
25
|
+
infrastructure: {
|
|
26
|
+
verified: boolean;
|
|
27
|
+
recipeId: string | null;
|
|
28
|
+
freshInstances: number;
|
|
29
|
+
baseRepeat: string | null;
|
|
30
|
+
errors: string[];
|
|
31
|
+
} | null;
|
|
32
|
+
}
|
|
33
|
+
export interface DesignVerifierAgentReport {
|
|
34
|
+
ok: boolean;
|
|
35
|
+
status: 'complete' | 'failed';
|
|
36
|
+
verdict: DesignVerifierAgentVerdict;
|
|
37
|
+
headline: string;
|
|
38
|
+
explanation: string;
|
|
39
|
+
runId: string;
|
|
40
|
+
repository: string;
|
|
41
|
+
pullRequest: number;
|
|
42
|
+
revisions: {
|
|
43
|
+
base: string | null;
|
|
44
|
+
head: string | null;
|
|
45
|
+
};
|
|
46
|
+
durationMs: number | null;
|
|
47
|
+
timings: DesignVerifierTimingSummary | null;
|
|
48
|
+
changedFiles: string[];
|
|
49
|
+
cases: DesignVerifierAgentCase[];
|
|
50
|
+
inspectCommand: string;
|
|
51
|
+
replay: Record<string, unknown> | null;
|
|
52
|
+
error: string | null;
|
|
53
|
+
exitCode: 0 | 1 | 2;
|
|
54
|
+
}
|
|
55
|
+
export declare function buildDesignVerifierAgentReport(run: DesignVerifierStatusResult): DesignVerifierAgentReport;
|
|
56
|
+
export declare function formatDesignVerifierAgentReport(report: DesignVerifierAgentReport): string;
|
|
57
|
+
export declare function designVerifierStageLabel(stage: string | null): string;
|