@haystackeditor/cli 0.15.19 → 0.15.21
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 +100 -1
- package/dist/assets/skills/map-your-system.md +9 -4
- package/dist/commands/ask.js +2 -2
- package/dist/commands/config.d.ts +9 -0
- package/dist/commands/config.js +46 -14
- package/dist/commands/dismiss.d.ts +15 -3
- package/dist/commands/dismiss.js +66 -116
- package/dist/commands/mcp.js +96 -1
- package/dist/commands/policy.js +31 -12
- package/dist/commands/pr-status.d.ts +125 -2
- package/dist/commands/pr-status.js +88 -73
- package/dist/commands/pr.d.ts +1 -7
- package/dist/commands/pr.js +10 -21
- package/dist/commands/request-review.d.ts +12 -1
- package/dist/commands/request-review.js +42 -65
- package/dist/commands/review.d.ts +1 -0
- package/dist/commands/review.js +58 -60
- package/dist/commands/setup.js +4 -1
- package/dist/commands/submit.d.ts +3 -0
- package/dist/commands/submit.js +178 -38
- package/dist/commands/system-map.d.ts +42 -0
- package/dist/commands/system-map.js +228 -0
- package/dist/commands/tokens.js +3 -2
- package/dist/commands/traces.js +2 -2
- package/dist/commands/triage.d.ts +1 -6
- package/dist/commands/triage.js +51 -55
- package/dist/commands/verify-core.d.ts +424 -0
- package/dist/commands/verify-core.js +753 -0
- package/dist/commands/verify-mcp.d.ts +8 -0
- package/dist/commands/verify-mcp.js +458 -0
- package/dist/commands/verify-ops.d.ts +158 -0
- package/dist/commands/verify-ops.js +1148 -0
- package/dist/commands/verify-reseal.d.ts +9 -0
- package/dist/commands/verify-reseal.js +148 -0
- package/dist/commands/verify-sandboxes.d.ts +95 -0
- package/dist/commands/verify-sandboxes.js +352 -0
- package/dist/commands/verify.d.ts +11 -0
- package/dist/commands/verify.js +97 -0
- package/dist/index.js +343 -20
- package/dist/schema.d.ts +4 -0
- package/dist/schema.js +4 -0
- package/dist/states.d.ts +29 -0
- package/dist/states.js +46 -0
- package/dist/triage/runner.d.ts +7 -0
- package/dist/triage/runner.js +2 -2
- package/dist/types.d.ts +54 -0
- package/dist/types.js +15 -0
- package/dist/utils/action-output.d.ts +24 -0
- package/dist/utils/action-output.js +26 -0
- package/dist/utils/analysis-api.d.ts +11 -0
- package/dist/utils/analysis-api.js +29 -3
- package/dist/utils/auth.js +7 -0
- package/dist/utils/git.d.ts +4 -1
- package/dist/utils/git.js +17 -7
- package/dist/utils/haystack-api.d.ts +15 -0
- package/dist/utils/haystack-api.js +58 -7
- package/dist/utils/pr-ref.d.ts +27 -0
- package/dist/utils/pr-ref.js +56 -0
- package/package.json +2 -2
- package/schemas/action.v1.json +22 -0
- package/schemas/error.v1.json +14 -0
- package/schemas/pr-status.v1.json +61 -0
- package/schemas/pr.v1.json +80 -17
- package/schemas/setup.v1.json +66 -12
- package/schemas/submit.v1.json +88 -0
- package/schemas/triage.v1.json +71 -18
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `haystack system-map validate` — instant feedback on `.haystack/system.yml`.
|
|
3
|
+
*
|
|
4
|
+
* The system map holds customer-declared facts about how their system WORKS
|
|
5
|
+
* (build, boot, seed, log in, observe) so Haystack QA can run it. It never
|
|
6
|
+
* selects tests — Haystack decides what to test from each PR's diff. The
|
|
7
|
+
* `/map-your-system` skill authors the file; this command lets a user (or
|
|
8
|
+
* their coding agent) check it before committing, instead of waiting for the
|
|
9
|
+
* next QA run to reject it.
|
|
10
|
+
*
|
|
11
|
+
* Source-of-truth note: the QA pipeline's own loader for this file
|
|
12
|
+
* (`analysis/src/agents/systemMap.ts`) lives on the incoming QA-replay
|
|
13
|
+
* subsystem branch and is NOT on main yet — until it lands, this command is
|
|
14
|
+
* the only validator of the format, and its rules were copied verbatim from
|
|
15
|
+
* that loader. Once the subsystem merges, the analysis-side loader becomes
|
|
16
|
+
* the source of truth (it is a separate deployable the CLI cannot import),
|
|
17
|
+
* and rule changes must update both in the same PR.
|
|
18
|
+
*/
|
|
19
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
20
|
+
import { join } from 'node:path';
|
|
21
|
+
import chalk from 'chalk';
|
|
22
|
+
import { parse as parseYaml } from 'yaml';
|
|
23
|
+
import { findGitRoot } from '../utils/hooks.js';
|
|
24
|
+
const SYSTEM_MAP_RELATIVE_PATHS = ['.haystack/system.yml', '.haystack/system.yaml'];
|
|
25
|
+
/**
|
|
26
|
+
* Keys whose presence means the file is steering test selection rather than
|
|
27
|
+
* describing the system. Rejected structurally so the "facts in, never test
|
|
28
|
+
* selection in" rule cannot erode.
|
|
29
|
+
*/
|
|
30
|
+
const TEST_SELECTION_KEYS = new Set([
|
|
31
|
+
'scenarios', 'tests', 'tests_to_run', 'run_tests', 'skip', 'skip_tests',
|
|
32
|
+
'focus', 'only', 'exclude', 'test_plan', 'experiments',
|
|
33
|
+
]);
|
|
34
|
+
/** Values that look like credentials rather than references to them. */
|
|
35
|
+
const SECRET_VALUE_RES = [
|
|
36
|
+
{ name: 'AWS access key', re: /AKIA[0-9A-Z]{16}/ },
|
|
37
|
+
{ name: 'GitHub token', re: /gh[pousr]_[A-Za-z0-9]{36,}/ },
|
|
38
|
+
{ name: 'API key', re: /sk-[A-Za-z0-9_-]{24,}/ },
|
|
39
|
+
{ name: 'private key block', re: /-----BEGIN [A-Z ]*PRIVATE KEY-----/ },
|
|
40
|
+
{ name: 'password-like assignment', re: /(password|passwd|secret)\s*[:=]\s*\S{8,}/i },
|
|
41
|
+
];
|
|
42
|
+
export function validateSystemMapText(rawYaml) {
|
|
43
|
+
const issues = [];
|
|
44
|
+
let doc;
|
|
45
|
+
try {
|
|
46
|
+
doc = parseYaml(rawYaml);
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
return {
|
|
50
|
+
issues: [{ severity: 'error', path: '(root)', message: `YAML parse error: ${error.message}` }],
|
|
51
|
+
summary: null,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
if (!doc || typeof doc !== 'object' || Array.isArray(doc)) {
|
|
55
|
+
return {
|
|
56
|
+
issues: [{ severity: 'error', path: '(root)', message: 'System map must be a mapping' }],
|
|
57
|
+
summary: null,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const root = doc;
|
|
61
|
+
if (root.version !== 1 && root.version !== '1') {
|
|
62
|
+
issues.push({ severity: 'error', path: 'version', message: 'version must be 1' });
|
|
63
|
+
}
|
|
64
|
+
for (const key of Object.keys(root)) {
|
|
65
|
+
if (TEST_SELECTION_KEYS.has(key)) {
|
|
66
|
+
issues.push({
|
|
67
|
+
severity: 'error',
|
|
68
|
+
path: key,
|
|
69
|
+
message: `"${key}" steers test selection — the system map may only describe how the system works. Haystack decides what to test from the diff.`,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
scanForSecrets(root, '(root)', issues);
|
|
74
|
+
validateCommands(root, issues);
|
|
75
|
+
if (issues.some((issue) => issue.severity === 'error')) {
|
|
76
|
+
return { issues, summary: null };
|
|
77
|
+
}
|
|
78
|
+
return { issues, summary: summarize(root) };
|
|
79
|
+
}
|
|
80
|
+
function scanForSecrets(value, atPath, issues) {
|
|
81
|
+
if (typeof value === 'string') {
|
|
82
|
+
for (const { name, re } of SECRET_VALUE_RES) {
|
|
83
|
+
if (re.test(value)) {
|
|
84
|
+
issues.push({
|
|
85
|
+
severity: 'error',
|
|
86
|
+
path: atPath,
|
|
87
|
+
message: `Value looks like a ${name}. Facts must reference env var NAMES; secret values are injected out-of-band.`,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (Array.isArray(value)) {
|
|
94
|
+
value.forEach((entry, index) => scanForSecrets(entry, `${atPath}[${index}]`, issues));
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (value && typeof value === 'object') {
|
|
98
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
99
|
+
scanForSecrets(entry, atPath === '(root)' ? key : `${atPath}.${key}`, issues);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function validateCommands(root, issues) {
|
|
104
|
+
const requireString = (value, atPath) => {
|
|
105
|
+
if (typeof value !== 'string' || value.trim().length === 0) {
|
|
106
|
+
issues.push({ severity: 'error', path: atPath, message: 'must be a non-empty string command' });
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const env = root.environment;
|
|
110
|
+
if (env?.setup !== undefined) {
|
|
111
|
+
if (!Array.isArray(env.setup)) {
|
|
112
|
+
issues.push({ severity: 'error', path: 'environment.setup', message: 'must be a list of { run } steps' });
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
env.setup.forEach((step, index) => requireString(step?.run, `environment.setup[${index}].run`));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
// Not in the QA loader's checks (yet): a scalar here would silently compile
|
|
119
|
+
// into per-character garbage via Object.entries — reject it as malformed.
|
|
120
|
+
if (env?.toolchain !== undefined && !isPlainObject(env.toolchain)) {
|
|
121
|
+
issues.push({
|
|
122
|
+
severity: 'error',
|
|
123
|
+
path: 'environment.toolchain',
|
|
124
|
+
message: 'must be a mapping of tool name → version (e.g. { node: "22" })',
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
const services = root.services;
|
|
128
|
+
for (const [name, service] of Object.entries(services ?? {})) {
|
|
129
|
+
requireString(service?.boot, `services.${name}.boot`);
|
|
130
|
+
}
|
|
131
|
+
const personas = root.data?.personas;
|
|
132
|
+
for (const [name, persona] of Object.entries(personas ?? {})) {
|
|
133
|
+
requireString(persona?.login, `data.personas.${name}.login`);
|
|
134
|
+
}
|
|
135
|
+
const artifacts = root.artifacts;
|
|
136
|
+
for (const [name, artifact] of Object.entries(artifacts ?? {})) {
|
|
137
|
+
const decl = artifact;
|
|
138
|
+
if (decl?.kind !== 'container-image') {
|
|
139
|
+
issues.push({
|
|
140
|
+
severity: 'error',
|
|
141
|
+
path: `artifacts.${name}.kind`,
|
|
142
|
+
message: 'must be "container-image" (the only artifact kind supported today)',
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
requireString(decl?.reference, `artifacts.${name}.reference`);
|
|
146
|
+
if (decl?.boot !== undefined) {
|
|
147
|
+
if (!Array.isArray(decl.boot)) {
|
|
148
|
+
issues.push({ severity: 'error', path: `artifacts.${name}.boot`, message: 'must be a list of { name } boot modes' });
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
decl.boot.forEach((mode, index) => requireString(mode?.name, `artifacts.${name}.boot[${index}].name`));
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function isPlainObject(value) {
|
|
157
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
158
|
+
}
|
|
159
|
+
function summarize(root) {
|
|
160
|
+
const env = (root.environment ?? {});
|
|
161
|
+
const data = (root.data ?? {});
|
|
162
|
+
const observability = (root.observability ?? {});
|
|
163
|
+
const testing = (root.testing ?? {});
|
|
164
|
+
return {
|
|
165
|
+
setup_steps: Array.isArray(env.setup) ? env.setup.length : 0,
|
|
166
|
+
toolchain_entries: isPlainObject(env.toolchain) ? Object.keys(env.toolchain).length : 0,
|
|
167
|
+
services: Object.keys((root.services ?? {})),
|
|
168
|
+
personas: Object.keys(data.personas ?? {}),
|
|
169
|
+
data_commands: (data.seed ? 1 : 0) + (data.reset ? 1 : 0),
|
|
170
|
+
observability_entries: (Array.isArray(observability.logs) ? observability.logs.length : 0) + (observability.inspect_db ? 1 : 0),
|
|
171
|
+
external_services: Object.keys((root.external_services ?? {})),
|
|
172
|
+
testing_entries: Object.keys(testing).length,
|
|
173
|
+
constraints: Array.isArray(root.constraints) ? root.constraints.length : 0,
|
|
174
|
+
artifacts: Object.keys((root.artifacts ?? {})),
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
export async function systemMapValidateCommand(options) {
|
|
178
|
+
const root = findGitRoot() ?? process.cwd();
|
|
179
|
+
const relativePath = SYSTEM_MAP_RELATIVE_PATHS.find((candidate) => existsSync(join(root, candidate)));
|
|
180
|
+
if (!relativePath) {
|
|
181
|
+
if (options.json) {
|
|
182
|
+
console.log(JSON.stringify({ status: 'missing', path: SYSTEM_MAP_RELATIVE_PATHS[0], issues: [] }, null, 2));
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
console.error(chalk.red(`No system map found at ${SYSTEM_MAP_RELATIVE_PATHS[0]}.`) +
|
|
186
|
+
' Run the /map-your-system skill in your coding agent (installed via `haystack skills install`) to create one.');
|
|
187
|
+
}
|
|
188
|
+
process.exit(1);
|
|
189
|
+
}
|
|
190
|
+
const { issues, summary } = validateSystemMapText(readFileSync(join(root, relativePath), 'utf-8'));
|
|
191
|
+
const ok = summary !== null;
|
|
192
|
+
if (options.json) {
|
|
193
|
+
console.log(JSON.stringify({ status: ok ? 'valid' : 'invalid', path: relativePath, issues, summary }, null, 2));
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
for (const issue of issues) {
|
|
197
|
+
const bullet = issue.severity === 'error' ? chalk.red('✗') : chalk.yellow('•');
|
|
198
|
+
console.log(`${bullet} ${chalk.white(issue.path)}: ${issue.message}`);
|
|
199
|
+
}
|
|
200
|
+
if (!ok) {
|
|
201
|
+
console.log();
|
|
202
|
+
console.log(chalk.red(`${relativePath} is invalid — fix the errors above.`));
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
const declared = [];
|
|
206
|
+
if (summary.setup_steps)
|
|
207
|
+
declared.push(`${summary.setup_steps} setup step(s)`);
|
|
208
|
+
if (summary.services.length)
|
|
209
|
+
declared.push(`services: ${summary.services.join(', ')}`);
|
|
210
|
+
if (summary.personas.length)
|
|
211
|
+
declared.push(`personas: ${summary.personas.join(', ')}`);
|
|
212
|
+
if (summary.data_commands)
|
|
213
|
+
declared.push(`${summary.data_commands} data command(s)`);
|
|
214
|
+
if (summary.external_services.length)
|
|
215
|
+
declared.push(`external: ${summary.external_services.join(', ')}`);
|
|
216
|
+
if (summary.artifacts.length)
|
|
217
|
+
declared.push(`artifacts: ${summary.artifacts.join(', ')}`);
|
|
218
|
+
if (summary.testing_entries)
|
|
219
|
+
declared.push('testing');
|
|
220
|
+
if (summary.constraints)
|
|
221
|
+
declared.push(`${summary.constraints} constraint(s)`);
|
|
222
|
+
console.log(chalk.green(`✓ ${relativePath} is valid`) + (declared.length ? chalk.dim(` — ${declared.join('; ')}`) : ''));
|
|
223
|
+
console.log(chalk.dim('When Haystack QA runs on this repo, each entry is treated as a declared fact and checked against run receipts.'));
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (!ok)
|
|
227
|
+
process.exit(1);
|
|
228
|
+
}
|
package/dist/commands/tokens.js
CHANGED
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
*/
|
|
27
27
|
import chalk from 'chalk';
|
|
28
28
|
import { loadToken, readHeadlessToken, writeHeadlessToken, clearHeadlessToken } from '../utils/auth.js';
|
|
29
|
+
import { classifyHttpError } from '../utils/haystack-api.js';
|
|
29
30
|
const HEADLESS_BASE = process.env.HAYSTACK_API_BASE ?? 'https://haystackeditor.com';
|
|
30
31
|
export async function headlessLoginCommand(opts) {
|
|
31
32
|
if (opts.token) {
|
|
@@ -139,7 +140,7 @@ export async function listTokensCommand(opts) {
|
|
|
139
140
|
headers: { Authorization: `Bearer ${token}`, 'User-Agent': 'Haystack-CLI' },
|
|
140
141
|
});
|
|
141
142
|
if (!res.ok) {
|
|
142
|
-
console.error(chalk.red(
|
|
143
|
+
console.error(chalk.red((await classifyHttpError(res, 'Token list')).message));
|
|
143
144
|
process.exit(1);
|
|
144
145
|
}
|
|
145
146
|
const data = (await res.json());
|
|
@@ -169,7 +170,7 @@ export async function revokeTokenCommand(id) {
|
|
|
169
170
|
headers: { Authorization: `Bearer ${token}`, 'User-Agent': 'Haystack-CLI' },
|
|
170
171
|
});
|
|
171
172
|
if (!res.ok) {
|
|
172
|
-
console.error(chalk.red(`revoke
|
|
173
|
+
console.error(chalk.red((await classifyHttpError(res, `Token revoke (${id})`)).message));
|
|
173
174
|
process.exit(1);
|
|
174
175
|
}
|
|
175
176
|
// If the revoked token is the one currently on disk, clear it so we
|
package/dist/commands/traces.js
CHANGED
|
@@ -2,7 +2,7 @@ import chalk from 'chalk';
|
|
|
2
2
|
import { loadToken } from '../utils/auth.js';
|
|
3
3
|
import { fetchAnalysisArtifact, fetchGitHubJson } from '../utils/haystack-api.js';
|
|
4
4
|
import { withSchema } from '../schema.js';
|
|
5
|
-
import { parsePrRef } from '
|
|
5
|
+
import { parsePrRef } from '../utils/pr-ref.js';
|
|
6
6
|
function publicCheckpoint(trace) {
|
|
7
7
|
return {
|
|
8
8
|
checkpoint_id: trace.checkpointId,
|
|
@@ -16,7 +16,7 @@ function publicCheckpoint(trace) {
|
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
18
|
async function tokenAndHead(ref) {
|
|
19
|
-
const pr = parsePrRef(ref);
|
|
19
|
+
const pr = parsePrRef(ref, 'traces list');
|
|
20
20
|
const token = await loadToken({ owner: pr.owner, repo: pr.repo });
|
|
21
21
|
if (!token)
|
|
22
22
|
throw new Error('Not authenticated. Run `haystack login` first.');
|
|
@@ -20,21 +20,16 @@
|
|
|
20
20
|
* (default) Rich terminal output
|
|
21
21
|
*/
|
|
22
22
|
import type { RatingSynthesis, AutoFixManifest } from '../utils/analysis-api.js';
|
|
23
|
+
import { type ParsedPR } from '../utils/pr-ref.js';
|
|
23
24
|
export interface TriageOptions {
|
|
24
25
|
json?: boolean;
|
|
25
26
|
wait?: boolean;
|
|
26
27
|
hook?: boolean;
|
|
27
28
|
clear?: boolean;
|
|
28
29
|
}
|
|
29
|
-
interface ParsedPR {
|
|
30
|
-
owner: string;
|
|
31
|
-
repo: string;
|
|
32
|
-
prNumber: number;
|
|
33
|
-
}
|
|
34
30
|
export declare function buildJsonOutput(pr: ParsedPR, headSha: string | null, synthesis: RatingSynthesis, manifest?: AutoFixManifest | null): Record<string, unknown>;
|
|
35
31
|
export declare function buildJsonState(pr: ParsedPR, status: 'pending' | 'failed' | 'unavailable', message?: string): Record<string, unknown>;
|
|
36
32
|
export declare function fetchTriageHeadSha(pr: ParsedPR, token?: string): Promise<string | null>;
|
|
37
33
|
export declare function triageCommand(identifier: string | undefined, options: TriageOptions): Promise<void>;
|
|
38
34
|
/** Pure read path for MCP: returns a public payload without writing stdout or exiting. */
|
|
39
35
|
export declare function fetchTriagePayload(identifier: string): Promise<Record<string, unknown>>;
|
|
40
|
-
export {};
|
package/dist/commands/triage.js
CHANGED
|
@@ -22,53 +22,13 @@
|
|
|
22
22
|
import chalk from 'chalk';
|
|
23
23
|
import WebSocket from 'ws';
|
|
24
24
|
import { checkAnalysisReady, fetchRatingSynthesis, fetchAutoFixManifest } from '../utils/analysis-api.js';
|
|
25
|
-
import { parseRemoteUrl } from '../utils/git.js';
|
|
26
25
|
import { loadToken } from '../utils/auth.js';
|
|
27
26
|
import { loadPendingSubmit, updatePendingSubmit, clearPendingSubmit } from '../utils/pending-state.js';
|
|
27
|
+
import { parsePrRef } from '../utils/pr-ref.js';
|
|
28
|
+
import { toPublicVerdict } from '../states.js';
|
|
28
29
|
import { withSchema } from '../schema.js';
|
|
29
30
|
import { fetchGitHubJson } from '../utils/haystack-api.js';
|
|
30
31
|
// ============================================================================
|
|
31
|
-
// PR identifier parsing
|
|
32
|
-
// ============================================================================
|
|
33
|
-
/**
|
|
34
|
-
* Parse a PR identifier from various formats:
|
|
35
|
-
* 123 -> uses current repo
|
|
36
|
-
* #123 -> uses current repo
|
|
37
|
-
* owner/repo#123 -> fully qualified
|
|
38
|
-
* https://github.com/owner/repo/pull/123 -> GitHub URL
|
|
39
|
-
*/
|
|
40
|
-
function parsePRIdentifier(identifier) {
|
|
41
|
-
// GitHub URL: https://github.com/owner/repo/pull/123
|
|
42
|
-
const urlMatch = identifier.match(/^https?:\/\/github\.com\/([^/]+)\/([^/]+)\/pull\/(\d+)\/?$/);
|
|
43
|
-
if (urlMatch) {
|
|
44
|
-
return { owner: urlMatch[1], repo: urlMatch[2], prNumber: parseInt(urlMatch[3], 10) };
|
|
45
|
-
}
|
|
46
|
-
// Fully qualified: owner/repo#123
|
|
47
|
-
const qualifiedMatch = identifier.match(/^([^/]+)\/([^#]+)#(\d+)$/);
|
|
48
|
-
if (qualifiedMatch) {
|
|
49
|
-
return { owner: qualifiedMatch[1], repo: qualifiedMatch[2], prNumber: parseInt(qualifiedMatch[3], 10) };
|
|
50
|
-
}
|
|
51
|
-
// Bare number: 123 or #123
|
|
52
|
-
const numberMatch = identifier.match(/^#?(\d+)$/);
|
|
53
|
-
if (numberMatch) {
|
|
54
|
-
const prNumber = parseInt(numberMatch[1], 10);
|
|
55
|
-
// Infer owner/repo from git remote
|
|
56
|
-
try {
|
|
57
|
-
const remote = parseRemoteUrl('origin');
|
|
58
|
-
return { owner: remote.owner, repo: remote.repo, prNumber };
|
|
59
|
-
}
|
|
60
|
-
catch {
|
|
61
|
-
throw new Error(`Cannot determine repository for PR #${prNumber}.\n` +
|
|
62
|
-
`Use the full format: haystack triage owner/repo#${prNumber}`);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
throw new Error(`Invalid PR identifier: "${identifier}"\n\n` +
|
|
66
|
-
`Accepted formats:\n` +
|
|
67
|
-
` haystack triage 123\n` +
|
|
68
|
-
` haystack triage owner/repo#123\n` +
|
|
69
|
-
` haystack triage https://github.com/owner/repo/pull/123`);
|
|
70
|
-
}
|
|
71
|
-
// ============================================================================
|
|
72
32
|
// Output formatting
|
|
73
33
|
// ============================================================================
|
|
74
34
|
/**
|
|
@@ -121,13 +81,11 @@ function printRichOutput(pr, synthesis, manifest) {
|
|
|
121
81
|
console.log(` ${chalk.dim(reviewUrl)}\n`);
|
|
122
82
|
}
|
|
123
83
|
export function buildJsonOutput(pr, headSha, synthesis, manifest) {
|
|
124
|
-
const verdict = synthesis.analysisVerdict
|
|
125
|
-
?? (synthesis.haystackRating >= 5 ? 'clean' : 'has-issues');
|
|
126
84
|
const payload = {
|
|
127
85
|
ref: `${pr.owner}/${pr.repo}#${pr.prNumber}`,
|
|
128
86
|
head_sha: headSha,
|
|
129
87
|
status: 'complete',
|
|
130
|
-
verdict:
|
|
88
|
+
verdict: toPublicVerdict(synthesis.analysisVerdict, synthesis.haystackRating),
|
|
131
89
|
rating: synthesis.haystackRating,
|
|
132
90
|
human_review_reasons: synthesis.humanReviewReasons ?? [],
|
|
133
91
|
findings: (synthesis.synthesisDisplay || []).map((f) => ({
|
|
@@ -344,7 +302,7 @@ async function waitForAnalysis(owner, repo, prNumber, timeoutMs, token, quiet) {
|
|
|
344
302
|
function resolvePR(identifier, options) {
|
|
345
303
|
if (identifier) {
|
|
346
304
|
try {
|
|
347
|
-
return
|
|
305
|
+
return parsePrRef(identifier, 'triage');
|
|
348
306
|
}
|
|
349
307
|
catch (err) {
|
|
350
308
|
console.error(chalk.red(`\n${err.message}\n`));
|
|
@@ -355,7 +313,13 @@ function resolvePR(identifier, options) {
|
|
|
355
313
|
const pending = loadPendingSubmit();
|
|
356
314
|
if (!pending) {
|
|
357
315
|
if (options.json) {
|
|
358
|
-
|
|
316
|
+
// Versioned error envelope (the old `{"status":"none"}` matched no
|
|
317
|
+
// schema); the caller asked for a triage and there is nothing to triage.
|
|
318
|
+
console.log(JSON.stringify(withSchema('error', {
|
|
319
|
+
status: 'error',
|
|
320
|
+
error: 'No pending submit to triage. Pass a PR identifier: haystack triage owner/repo#123 --json',
|
|
321
|
+
}), null, 2));
|
|
322
|
+
process.exitCode = 1;
|
|
359
323
|
}
|
|
360
324
|
else if (!options.hook) {
|
|
361
325
|
console.log(chalk.dim('No pending submits. Pass a PR number to triage a specific PR.\n'));
|
|
@@ -371,7 +335,16 @@ export async function triageCommand(identifier, options) {
|
|
|
371
335
|
// Handle --clear
|
|
372
336
|
if (options.clear) {
|
|
373
337
|
clearPendingSubmit();
|
|
374
|
-
if (
|
|
338
|
+
if (options.json) {
|
|
339
|
+
// stdout stays pure JSON in --json mode; use the shared action envelope.
|
|
340
|
+
console.log(JSON.stringify(withSchema('action', {
|
|
341
|
+
action: 'clear_pending',
|
|
342
|
+
status: 'ok',
|
|
343
|
+
ref: null,
|
|
344
|
+
detail: 'Pending submit state cleared.',
|
|
345
|
+
}), null, 2));
|
|
346
|
+
}
|
|
347
|
+
else if (!options.hook) {
|
|
375
348
|
console.log(chalk.dim('Pending submit state cleared.'));
|
|
376
349
|
}
|
|
377
350
|
return;
|
|
@@ -474,12 +447,35 @@ export async function triageCommand(identifier, options) {
|
|
|
474
447
|
}
|
|
475
448
|
if (!analysisReady)
|
|
476
449
|
return;
|
|
477
|
-
// Fetch the full rating synthesis and auto-fix manifest in parallel
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
450
|
+
// Fetch the full rating synthesis and auto-fix manifest in parallel.
|
|
451
|
+
// Auth failures throw a classified error — report it as failed (with the
|
|
452
|
+
// remediation) rather than the old behavior of "not available yet, retry".
|
|
453
|
+
let synthesis;
|
|
454
|
+
let autoFixManifest;
|
|
455
|
+
let headSha;
|
|
456
|
+
try {
|
|
457
|
+
[synthesis, autoFixManifest, headSha] = await Promise.all([
|
|
458
|
+
fetchRatingSynthesis(pr.owner, pr.repo, pr.prNumber, token),
|
|
459
|
+
fetchAutoFixManifest(pr.owner, pr.repo, pr.prNumber, token),
|
|
460
|
+
fetchTriageHeadSha(pr, token),
|
|
461
|
+
]);
|
|
462
|
+
}
|
|
463
|
+
catch (err) {
|
|
464
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
465
|
+
if (options.hook) {
|
|
466
|
+
// Session-start hooks must never fail the session — match the
|
|
467
|
+
// status-check error path above: print the failed line, exit 0.
|
|
468
|
+
printHookOutput(pr, null, null, 'failed');
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
if (options.json) {
|
|
472
|
+
printJsonState(pr, 'failed', message);
|
|
473
|
+
}
|
|
474
|
+
else {
|
|
475
|
+
console.error(chalk.red(`\n ${message}\n`));
|
|
476
|
+
}
|
|
477
|
+
process.exit(1);
|
|
478
|
+
}
|
|
483
479
|
// Update pending state if this PR matches the pending submit
|
|
484
480
|
updatePendingSubmitIfExists(pr, synthesis ? 'completed' : undefined);
|
|
485
481
|
if (!synthesis) {
|
|
@@ -520,7 +516,7 @@ export async function triageCommand(identifier, options) {
|
|
|
520
516
|
}
|
|
521
517
|
/** Pure read path for MCP: returns a public payload without writing stdout or exiting. */
|
|
522
518
|
export async function fetchTriagePayload(identifier) {
|
|
523
|
-
const pr =
|
|
519
|
+
const pr = parsePrRef(identifier, 'triage');
|
|
524
520
|
const token = await loadToken({ owner: pr.owner, repo: pr.repo }) || undefined;
|
|
525
521
|
const ready = await checkAnalysisReady(pr.owner, pr.repo, pr.prNumber, token);
|
|
526
522
|
if (ready.status === 'pending')
|