@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,100 +0,0 @@
|
|
|
1
|
-
// Which repository paths never reach a reviewer snapshot. Relocated verbatim
|
|
2
|
-
// from the customer-replica connector protocol package when that customer-side
|
|
3
|
-
// plumbing was removed: Haystack builds replicas itself, so the only consumer
|
|
4
|
-
// left is `haystack skills prepare-universe-review`.
|
|
5
|
-
export const CUSTOMER_REPLICA_PRODUCTION_SOURCE_DENY_POLICY = {
|
|
6
|
-
schemaVersion: 2,
|
|
7
|
-
policyId: 'haystack-production-source-no-existing-tests-v2',
|
|
8
|
-
deniedDirectoryNames: [
|
|
9
|
-
'.git', '.haystack', '.nyc_output', '.pytest_cache', '__tests__', 'acceptance-test',
|
|
10
|
-
'acceptance-tests', 'acceptance_test', 'acceptance_tests', 'cypress',
|
|
11
|
-
'e2e', 'integration-test', 'integration-tests',
|
|
12
|
-
'integration_test', 'integration_tests', 'playwright',
|
|
13
|
-
'playwright-report', 'system-test',
|
|
14
|
-
'system-tests', 'system_test', 'system_tests', 'test', 'test-data',
|
|
15
|
-
'test-results', 'testdata', 'tests',
|
|
16
|
-
],
|
|
17
|
-
conditionalDirectoryNames: [
|
|
18
|
-
'__fixtures__', '__mocks__', '__snapshots__', 'fixtures', 'mocks',
|
|
19
|
-
'snapshots', 'spec', 'specs',
|
|
20
|
-
],
|
|
21
|
-
conditionalDirectoryRule: 'exclude root spec/specs when a test framework is detected; exclude fixture/mock/snapshot components only below a detected test root',
|
|
22
|
-
deniedFilePatterns: [
|
|
23
|
-
'*.test.{js,jsx,ts,tsx,mjs,cjs}',
|
|
24
|
-
'*.spec.{js,jsx,ts,tsx,mjs,cjs,rb}',
|
|
25
|
-
'*.e2e.{js,jsx,ts,tsx}',
|
|
26
|
-
'*.e2e-spec.{js,jsx,ts,tsx}',
|
|
27
|
-
'test-*.{js,jsx,ts,tsx,py,rb,go,rs}',
|
|
28
|
-
'*-test.{js,jsx,ts,tsx,py,rb,go,rs}',
|
|
29
|
-
'*_test.{py,go,rs,cc,cpp}',
|
|
30
|
-
'*_tests.{py,rb}',
|
|
31
|
-
'test_*.py',
|
|
32
|
-
'*_unittest.{cc,cpp,py}',
|
|
33
|
-
'*Test.{java,kt,kts,scala,groovy,cs,php,swift}',
|
|
34
|
-
'*Tests.{java,kt,kts,scala,groovy,cs,php,swift}',
|
|
35
|
-
'*ITCase.{java,kt,kts,scala,groovy,cs,php,swift}',
|
|
36
|
-
'*.{snap,golden,approved}',
|
|
37
|
-
'{jest,vitest,playwright,cypress}.config.*',
|
|
38
|
-
'karma.conf.*', 'mocha.config.*', 'pytest.ini', 'tox.ini',
|
|
39
|
-
'.coveragerc', 'junit*.xml',
|
|
40
|
-
],
|
|
41
|
-
inlineTestScan: {
|
|
42
|
-
maximumTextFileBytes: 2 * 1024 * 1024,
|
|
43
|
-
oversizedTextFileAction: 'reject',
|
|
44
|
-
binaryFileAction: 'retain',
|
|
45
|
-
markerRuleIds: [
|
|
46
|
-
'rust-cfg-test', 'zig-inline-test', 'vitest-import-meta',
|
|
47
|
-
'deno-inline-test', 'bun-inline-test', 'c-unit-test-conditional',
|
|
48
|
-
'rust-test-attribute', 'jvm-test-annotation',
|
|
49
|
-
'dotnet-test-attribute', 'xctest-case', 'python-unittest-case',
|
|
50
|
-
'python-test-function',
|
|
51
|
-
],
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
export function isCustomerReplicaProductionSourceDeniedPath(path) {
|
|
55
|
-
const components = path.split('/');
|
|
56
|
-
if (components.slice(0, -1).some(component => CUSTOMER_REPLICA_PRODUCTION_SOURCE_DENY_POLICY.deniedDirectoryNames
|
|
57
|
-
.some(denied => denied === component.toLowerCase())))
|
|
58
|
-
return true;
|
|
59
|
-
const name = components[components.length - 1];
|
|
60
|
-
const lowerName = name.toLowerCase();
|
|
61
|
-
const dot = name.lastIndexOf('.');
|
|
62
|
-
const stem = dot > 0 && dot < name.length - 1 ? name.slice(0, dot) : name;
|
|
63
|
-
const extension = dot > 0 && dot < name.length - 1
|
|
64
|
-
? name.slice(dot + 1).toLowerCase()
|
|
65
|
-
: '';
|
|
66
|
-
const lowerStem = stem.toLowerCase();
|
|
67
|
-
const js = new Set(['js', 'jsx', 'ts', 'tsx', 'mjs', 'cjs']);
|
|
68
|
-
if (js.has(extension) && /\.(?:test|e2e|e2e-spec)$/i.test(stem))
|
|
69
|
-
return true;
|
|
70
|
-
if ((js.has(extension) || extension === 'rb') && /\.spec$/i.test(stem)) {
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
if (new Set([...js, 'py', 'rb', 'go', 'rs']).has(extension)
|
|
74
|
-
&& (lowerStem.startsWith('test-') || lowerStem.endsWith('-test')))
|
|
75
|
-
return true;
|
|
76
|
-
if (new Set(['py', 'go', 'rs', 'cc', 'cpp']).has(extension)
|
|
77
|
-
&& lowerStem.endsWith('_test'))
|
|
78
|
-
return true;
|
|
79
|
-
if (new Set(['py', 'rb']).has(extension) && lowerStem.endsWith('_tests')) {
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
if (extension === 'py' && lowerStem.startsWith('test_'))
|
|
83
|
-
return true;
|
|
84
|
-
if (new Set(['cc', 'cpp', 'py']).has(extension)
|
|
85
|
-
&& lowerStem.endsWith('_unittest'))
|
|
86
|
-
return true;
|
|
87
|
-
if (new Set(['java', 'kt', 'kts', 'scala', 'groovy', 'cs', 'php', 'swift'])
|
|
88
|
-
.has(extension)
|
|
89
|
-
&& (stem.endsWith('Test') || stem.endsWith('Tests') || stem.endsWith('ITCase')))
|
|
90
|
-
return true;
|
|
91
|
-
if (new Set(['snap', 'golden', 'approved']).has(extension))
|
|
92
|
-
return true;
|
|
93
|
-
if (/^(?:jest|vitest|playwright|cypress)\.config\..+$/i.test(name))
|
|
94
|
-
return true;
|
|
95
|
-
if (/^karma\.conf\..+$/i.test(name) || /^mocha\.config\..+$/i.test(name)) {
|
|
96
|
-
return true;
|
|
97
|
-
}
|
|
98
|
-
return new Set(['.coveragerc', 'pytest.ini', 'tox.ini']).has(lowerName)
|
|
99
|
-
|| /^junit.*\.xml$/i.test(name);
|
|
100
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* request-review command — Tag a PR as needing human review after creation.
|
|
3
|
-
*
|
|
4
|
-
* haystack request-review <pr> [reviewer]
|
|
5
|
-
*
|
|
6
|
-
* Adds the `haystack:needs-review` label to the PR. Optionally requests
|
|
7
|
-
* review from a specific GitHub user. The PR will move to the
|
|
8
|
-
* "Needs Assignment" or "Awaiting Review" bucket in the Haystack feed.
|
|
9
|
-
*
|
|
10
|
-
* Accepts a PR identifier in several formats:
|
|
11
|
-
* 123 # Uses current repo's owner/repo
|
|
12
|
-
* owner/repo#123 # Fully qualified
|
|
13
|
-
* https://github.com/owner/repo/pull/123 # GitHub URL
|
|
14
|
-
*/
|
|
15
|
-
import chalk from 'chalk';
|
|
16
|
-
import { emitActionPayload, failAction } from '../utils/action-output.js';
|
|
17
|
-
import { resolveAuthContext } from '../utils/auth.js';
|
|
18
|
-
import { parsePrRef } from '../utils/pr-ref.js';
|
|
19
|
-
import { ensureHaystackLabels, addLabelsToIssue, requestReviewers, } from '../utils/github-api.js';
|
|
20
|
-
/** Apply the needs-review label (and optional reviewer). Throws on failure. */
|
|
21
|
-
export async function performRequestReview(identifier, reviewer) {
|
|
22
|
-
const pr = parsePrRef(identifier, 'request-review');
|
|
23
|
-
const authContext = await resolveAuthContext({ owner: pr.owner, repo: pr.repo });
|
|
24
|
-
const ref = `${pr.owner}/${pr.repo}#${pr.prNumber}`;
|
|
25
|
-
await ensureHaystackLabels(pr.owner, pr.repo, ['haystack:needs-review'], authContext.token);
|
|
26
|
-
await addLabelsToIssue(pr.owner, pr.repo, pr.prNumber, ['haystack:needs-review'], authContext.token);
|
|
27
|
-
let reviewerRequestFailed = null;
|
|
28
|
-
if (reviewer) {
|
|
29
|
-
try {
|
|
30
|
-
await requestReviewers(pr.owner, pr.repo, pr.prNumber, [reviewer], authContext.token);
|
|
31
|
-
}
|
|
32
|
-
catch (err) {
|
|
33
|
-
// Label was added successfully, just the reviewer request failed —
|
|
34
|
-
// report the partial outcome instead of failing the whole action.
|
|
35
|
-
reviewerRequestFailed = err.message;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return {
|
|
39
|
-
action: 'request_review',
|
|
40
|
-
status: 'ok',
|
|
41
|
-
ref,
|
|
42
|
-
reviewer: reviewer && !reviewerRequestFailed ? reviewer : null,
|
|
43
|
-
reviewer_request_failed: reviewerRequestFailed,
|
|
44
|
-
detail: reviewer && !reviewerRequestFailed
|
|
45
|
-
? `Review requested from ${reviewer}; the PR moves to the "Needs Assignment" queue.`
|
|
46
|
-
: 'PR marked for human review; it moves to the "Needs Assignment" queue.',
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
export async function requestReviewCommand(identifier, reviewer, options = {}) {
|
|
50
|
-
if (!options.json)
|
|
51
|
-
console.log(chalk.dim(`\nRequesting review for ${identifier}...`));
|
|
52
|
-
let payload;
|
|
53
|
-
try {
|
|
54
|
-
payload = await performRequestReview(identifier, reviewer);
|
|
55
|
-
}
|
|
56
|
-
catch (err) {
|
|
57
|
-
failAction(options.json, 'request_review', null, err.message);
|
|
58
|
-
return; // unreachable — satisfies TS narrowing
|
|
59
|
-
}
|
|
60
|
-
if (options.json) {
|
|
61
|
-
emitActionPayload(payload);
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
if (payload.reviewer) {
|
|
65
|
-
console.log(chalk.green(`\n Review requested from ${payload.reviewer} on ${payload.ref}`));
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
console.log(chalk.green(`\n Marked ${payload.ref} for human review`));
|
|
69
|
-
if (payload.reviewer_request_failed) {
|
|
70
|
-
console.log(chalk.yellow(` Could not request reviewer "${reviewer}": ${payload.reviewer_request_failed}`));
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
console.log(chalk.dim(' The PR will appear in the "Needs Assignment" queue in the feed.\n'));
|
|
74
|
-
}
|
package/dist/commands/review.js
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* review command — Trigger a fresh Haystack analysis for a PR.
|
|
3
|
-
*
|
|
4
|
-
* haystack review [pr] [--no-wait]
|
|
5
|
-
*
|
|
6
|
-
* Haystack runs a full analysis when a PR is opened (or marked ready);
|
|
7
|
-
* later pushes only get a resolution check against the existing findings.
|
|
8
|
-
* This command is the explicit escape hatch: it re-runs full detection on
|
|
9
|
-
* the PR's current head — use it after substantial new commits, or any
|
|
10
|
-
* time you want a fresh second opinion.
|
|
11
|
-
*
|
|
12
|
-
* When called without a PR identifier, reads the last submitted PR from
|
|
13
|
-
* `.haystack/pending-submit.json` (written by `haystack submit`).
|
|
14
|
-
*
|
|
15
|
-
* Accepts a PR identifier in several formats:
|
|
16
|
-
* haystack review # Last submitted PR
|
|
17
|
-
* haystack review 123 # Uses current repo's owner/repo
|
|
18
|
-
* haystack review owner/repo#123 # Fully qualified
|
|
19
|
-
* haystack review https://github.com/owner/repo/pull/123
|
|
20
|
-
*/
|
|
21
|
-
import chalk from 'chalk';
|
|
22
|
-
import { emitActionPayload, failAction } from '../utils/action-output.js';
|
|
23
|
-
import { triggerAnalysis, fetchTriggerStatus } from '../utils/analysis-api.js';
|
|
24
|
-
import { fetchTriageHeadSha } from './triage.js';
|
|
25
|
-
import { loadToken } from '../utils/auth.js';
|
|
26
|
-
import { loadPendingSubmit } from '../utils/pending-state.js';
|
|
27
|
-
import { parsePrRef } from '../utils/pr-ref.js';
|
|
28
|
-
import { triageCommand } from './triage.js';
|
|
29
|
-
// ============================================================================
|
|
30
|
-
// Constants
|
|
31
|
-
// ============================================================================
|
|
32
|
-
const STATUS_POLL_INTERVAL_MS = 10_000;
|
|
33
|
-
// Full analyses regularly take 10+ minutes on large PRs; this bounds the
|
|
34
|
-
// CLI's wait, not the analysis itself (results land on the feed regardless).
|
|
35
|
-
const STATUS_POLL_TIMEOUT_MS = 25 * 60 * 1000;
|
|
36
|
-
function resolvePR(identifier, json) {
|
|
37
|
-
if (identifier) {
|
|
38
|
-
try {
|
|
39
|
-
return parsePrRef(identifier, 'review');
|
|
40
|
-
}
|
|
41
|
-
catch (err) {
|
|
42
|
-
failAction(json, 'trigger_review', null, err.message);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
const pending = loadPendingSubmit();
|
|
46
|
-
if (!pending) {
|
|
47
|
-
console.log(chalk.dim('No pending submits. Pass a PR number to review a specific PR.\n'));
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
return { owner: pending.owner, repo: pending.repo, prNumber: pending.prNumber };
|
|
51
|
-
}
|
|
52
|
-
// ============================================================================
|
|
53
|
-
// Waiting
|
|
54
|
-
// ============================================================================
|
|
55
|
-
async function waitForRun(requestId, token) {
|
|
56
|
-
const deadline = Date.now() + STATUS_POLL_TIMEOUT_MS;
|
|
57
|
-
let consecutiveErrors = 0;
|
|
58
|
-
while (Date.now() < deadline) {
|
|
59
|
-
const result = await fetchTriggerStatus(requestId, token);
|
|
60
|
-
if (result.status === 'COMPLETED')
|
|
61
|
-
return 'completed';
|
|
62
|
-
if (result.status === 'FAILED')
|
|
63
|
-
return 'failed';
|
|
64
|
-
if (result.status === 'SUPERSEDED')
|
|
65
|
-
return 'superseded';
|
|
66
|
-
if (result.status === 'error') {
|
|
67
|
-
consecutiveErrors++;
|
|
68
|
-
if (consecutiveErrors >= 5)
|
|
69
|
-
return 'failed';
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
consecutiveErrors = 0;
|
|
73
|
-
}
|
|
74
|
-
process.stderr.write(`\r ${chalk.dim('Analysis in progress...')}${' '.repeat(5)}`);
|
|
75
|
-
// Deliberately NOT unref'd: during the wait this timer can be the only
|
|
76
|
-
// live handle, and an unref'd timer lets Node exit mid-wait.
|
|
77
|
-
await new Promise((resolve) => {
|
|
78
|
-
setTimeout(resolve, STATUS_POLL_INTERVAL_MS);
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
return 'timeout';
|
|
82
|
-
}
|
|
83
|
-
// ============================================================================
|
|
84
|
-
// Main command
|
|
85
|
-
// ============================================================================
|
|
86
|
-
export async function reviewCommand(identifier, options) {
|
|
87
|
-
if (options.json && identifier === undefined && !loadPendingSubmit()) {
|
|
88
|
-
failAction(true, 'trigger_review', null, 'No pending submit to review. Pass a PR identifier: haystack review owner/repo#123 --json');
|
|
89
|
-
}
|
|
90
|
-
const pr = resolvePR(identifier, options.json);
|
|
91
|
-
if (!pr)
|
|
92
|
-
return;
|
|
93
|
-
const prLabel = `${pr.owner}/${pr.repo}#${pr.prNumber}`;
|
|
94
|
-
let token = null;
|
|
95
|
-
try {
|
|
96
|
-
token = await loadToken({ owner: pr.owner, repo: pr.repo });
|
|
97
|
-
}
|
|
98
|
-
catch (err) {
|
|
99
|
-
failAction(options.json, 'trigger_review', prLabel, `Could not load Haystack credentials: ${err.message}`);
|
|
100
|
-
}
|
|
101
|
-
if (!token) {
|
|
102
|
-
failAction(options.json, 'trigger_review', prLabel, 'Triggering an analysis requires authentication. Run `haystack login` first.');
|
|
103
|
-
return; // unreachable — satisfies TS narrowing
|
|
104
|
-
}
|
|
105
|
-
if (!options.json)
|
|
106
|
-
console.log(chalk.dim(`\nRequesting a fresh analysis for ${prLabel}...`));
|
|
107
|
-
// Resolve the current head so ingestion's dedup compares commits — an
|
|
108
|
-
// in-flight run for an OLDER head must be superseded, not reused. A
|
|
109
|
-
// failed metadata fetch degrades to a head-less trigger (the dedup is a
|
|
110
|
-
// freshness aid, not a correctness requirement) instead of crashing.
|
|
111
|
-
let headSha;
|
|
112
|
-
try {
|
|
113
|
-
headSha = await fetchTriageHeadSha(pr, token) ?? undefined;
|
|
114
|
-
}
|
|
115
|
-
catch (err) {
|
|
116
|
-
console.error(chalk.dim(` Could not resolve the PR head (${err.message}) — continuing without it.`));
|
|
117
|
-
}
|
|
118
|
-
const trigger = await triggerAnalysis(pr.owner, pr.repo, pr.prNumber, token, headSha);
|
|
119
|
-
if (trigger.status === 'rate_limited') {
|
|
120
|
-
const retryHint = trigger.retryAfterSeconds
|
|
121
|
-
? ` Try again in ~${Math.ceil(trigger.retryAfterSeconds / 60)} minute(s).`
|
|
122
|
-
: '';
|
|
123
|
-
failAction(options.json, 'trigger_review', prLabel, `${trigger.message}${retryHint}`);
|
|
124
|
-
}
|
|
125
|
-
if (trigger.status === 'denied') {
|
|
126
|
-
failAction(options.json, 'trigger_review', prLabel, trigger.message);
|
|
127
|
-
}
|
|
128
|
-
if (trigger.status === 'error') {
|
|
129
|
-
failAction(options.json, 'trigger_review', prLabel, `Failed to trigger analysis: ${trigger.message}`);
|
|
130
|
-
return; // unreachable — satisfies TS narrowing
|
|
131
|
-
}
|
|
132
|
-
if (!options.json) {
|
|
133
|
-
if (trigger.status === 'already_processing') {
|
|
134
|
-
console.log(chalk.yellow(' An analysis for this PR is already running — waiting on it instead.'));
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
console.log(chalk.green(' Analysis started.'));
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
/** One envelope for every terminal state of the trigger. */
|
|
141
|
-
const emitJson = (runStatus, detail, done) => {
|
|
142
|
-
emitActionPayload({
|
|
143
|
-
action: 'trigger_review',
|
|
144
|
-
status: 'ok',
|
|
145
|
-
ref: prLabel,
|
|
146
|
-
detail,
|
|
147
|
-
request_id: trigger.requestId,
|
|
148
|
-
run_status: runStatus,
|
|
149
|
-
next: done ? `haystack triage ${prLabel} --json` : null,
|
|
150
|
-
});
|
|
151
|
-
};
|
|
152
|
-
if (options.wait === false) {
|
|
153
|
-
if (options.json) {
|
|
154
|
-
emitJson(trigger.status, 'Analysis triggered; not waiting for completion.', true);
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
console.log(chalk.dim(' Check results later with: ') + chalk.cyan(`haystack triage ${prLabel}`));
|
|
158
|
-
console.log(chalk.dim(' Or view the review: ') + chalk.cyan(`https://haystackeditor.com/review/${pr.owner}/${pr.repo}/${pr.prNumber}\n`));
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
const outcome = await waitForRun(trigger.requestId, token);
|
|
162
|
-
process.stderr.write('\r' + ' '.repeat(60) + '\r');
|
|
163
|
-
if (outcome === 'failed') {
|
|
164
|
-
failAction(options.json, 'trigger_review', prLabel, `Analysis run failed. Check the review page: https://haystackeditor.com/review/${pr.owner}/${pr.repo}/${pr.prNumber}`);
|
|
165
|
-
}
|
|
166
|
-
if (outcome === 'superseded') {
|
|
167
|
-
if (options.json) {
|
|
168
|
-
emitJson('superseded', 'This run was superseded by a newer analysis (a push likely landed meanwhile). The latest results stand.', true);
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
console.log(chalk.yellow('\n This run was superseded by a newer analysis (a push likely landed meanwhile).'));
|
|
172
|
-
console.log(chalk.dim(' Showing the latest results instead.'));
|
|
173
|
-
await triageCommand(prLabel, { wait: false });
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
if (outcome === 'timeout') {
|
|
177
|
-
if (options.json) {
|
|
178
|
-
emitJson('running', 'Still running after 25 minutes; the analysis continues server-side.', true);
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
console.log(chalk.yellow('\n Still running after 25 minutes — giving up on waiting.'));
|
|
182
|
-
console.log(chalk.dim(' Check results later with: ') + chalk.cyan(`haystack triage ${prLabel}\n`));
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
// Completed — render results through the triage view (no extra wait).
|
|
186
|
-
if (options.json) {
|
|
187
|
-
emitJson('completed', 'Analysis completed.', true);
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
await triageCommand(prLabel, { wait: false });
|
|
191
|
-
}
|
package/dist/commands/rules.js
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `haystack rules edit|validate` — manage .haystack/pr-rules.yml.
|
|
3
|
-
*
|
|
4
|
-
* Why local, not server-round-trip:
|
|
5
|
-
* pr-rules.yml is the source of truth, checked into the repo. The CLI's job
|
|
6
|
-
* is to make it ergonomic to edit (open in $EDITOR) and to fail loudly if
|
|
7
|
-
* the file would break the server-side parser (`packages/custom-rules`).
|
|
8
|
-
* The same parser is used here so "validate passes locally" == "won't
|
|
9
|
-
* break the next PR analysis."
|
|
10
|
-
*/
|
|
11
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync, statSync } from 'node:fs';
|
|
12
|
-
import { spawnSync } from 'node:child_process';
|
|
13
|
-
import { resolve, dirname } from 'node:path';
|
|
14
|
-
import chalk from 'chalk';
|
|
15
|
-
const RULES_PATH = '.haystack/pr-rules.yml';
|
|
16
|
-
const STARTER_YAML = `version: 1
|
|
17
|
-
|
|
18
|
-
rules:
|
|
19
|
-
# Replace with your own rules. Each rule is either type: llm (judged by an
|
|
20
|
-
# LLM) or type: deterministic (regex / structural). See
|
|
21
|
-
# packages/custom-rules/README.md for the full schema.
|
|
22
|
-
- id: EXAMPLE001
|
|
23
|
-
name: Example rule
|
|
24
|
-
type: llm
|
|
25
|
-
severity: info
|
|
26
|
-
message: Replace this rule with one that matters to your team
|
|
27
|
-
llm:
|
|
28
|
-
prompt: >
|
|
29
|
-
This is a placeholder. Edit .haystack/pr-rules.yml and remove this rule.
|
|
30
|
-
`;
|
|
31
|
-
function rulesAbsPath() {
|
|
32
|
-
return resolve(process.cwd(), RULES_PATH);
|
|
33
|
-
}
|
|
34
|
-
export async function editRulesCommand() {
|
|
35
|
-
const path = rulesAbsPath();
|
|
36
|
-
if (!existsSync(path)) {
|
|
37
|
-
mkdirSync(dirname(path), { recursive: true });
|
|
38
|
-
writeFileSync(path, STARTER_YAML, 'utf8');
|
|
39
|
-
console.log(chalk.dim(`Created ${RULES_PATH} with a starter rule.`));
|
|
40
|
-
}
|
|
41
|
-
const editor = process.env.VISUAL ?? process.env.EDITOR;
|
|
42
|
-
if (!editor) {
|
|
43
|
-
console.error(chalk.red('No $EDITOR or $VISUAL set.') +
|
|
44
|
-
`\nOpen ${chalk.bold(RULES_PATH)} manually, then run ` +
|
|
45
|
-
chalk.bold('haystack rules validate') + ' to check it.');
|
|
46
|
-
process.exit(2);
|
|
47
|
-
}
|
|
48
|
-
const before = statSync(path).mtimeMs;
|
|
49
|
-
const result = spawnSync(editor, [path], { stdio: 'inherit' });
|
|
50
|
-
if (result.status !== 0) {
|
|
51
|
-
console.error(chalk.red(`Editor exited with status ${result.status}.`));
|
|
52
|
-
process.exit(result.status ?? 1);
|
|
53
|
-
}
|
|
54
|
-
const after = statSync(path).mtimeMs;
|
|
55
|
-
if (after === before) {
|
|
56
|
-
console.log(chalk.dim('No changes.'));
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
console.log(chalk.dim('Validating…'));
|
|
60
|
-
await validateRulesCommand({ silent: false });
|
|
61
|
-
}
|
|
62
|
-
export async function validateRulesCommand(opts = {}) {
|
|
63
|
-
const path = rulesAbsPath();
|
|
64
|
-
if (!existsSync(path)) {
|
|
65
|
-
console.error(chalk.red(`${RULES_PATH} not found.`));
|
|
66
|
-
console.error(`Run ${chalk.bold('haystack rules edit')} to create one.`);
|
|
67
|
-
process.exit(1);
|
|
68
|
-
}
|
|
69
|
-
const raw = readFileSync(path, 'utf8');
|
|
70
|
-
// Use the canonical parser. Importing dynamically keeps the CLI's hot path
|
|
71
|
-
// free of haystack-custom-rules unless this subcommand is actually run.
|
|
72
|
-
let parser = null;
|
|
73
|
-
try {
|
|
74
|
-
parser = (await import('haystack-custom-rules'));
|
|
75
|
-
}
|
|
76
|
-
catch (err) {
|
|
77
|
-
console.error(chalk.red('Could not load the rules parser (haystack-custom-rules).'), err instanceof Error ? err.message : err);
|
|
78
|
-
console.error(chalk.dim('The CLI uses the same parser as the server. If this failed, the workspace install is incomplete — run `pnpm install` from the repo root.'));
|
|
79
|
-
process.exit(1);
|
|
80
|
-
}
|
|
81
|
-
try {
|
|
82
|
-
const cfg = parser.parseRulesYaml(raw);
|
|
83
|
-
const ruleCount = cfg.rules?.length ?? 0;
|
|
84
|
-
if (!opts.silent) {
|
|
85
|
-
console.log(chalk.green(`✓ ${RULES_PATH} is valid (${ruleCount} rule${ruleCount === 1 ? '' : 's'}).`));
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
catch (err) {
|
|
89
|
-
console.error(chalk.red(`✗ ${RULES_PATH} is invalid:`));
|
|
90
|
-
if (err && typeof err === 'object' && 'message' in err) {
|
|
91
|
-
console.error(` ${err.message}`);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
console.error(' ' + String(err));
|
|
95
|
-
}
|
|
96
|
-
process.exit(1);
|
|
97
|
-
}
|
|
98
|
-
}
|