@openai/codex-security 0.6.0 → 0.8.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 +76 -39
- package/_bundled_plugin/.mcp.json +1 -0
- package/_bundled_plugin/examples/completed-scan/findings.json +34 -34
- package/_bundled_plugin/examples/completed-scan/report.md +22 -31
- package/_bundled_plugin/examples/completed-scan/scan-manifest.json +27 -29
- package/_bundled_plugin/examples/{completed-scan → legacy-completed-scan}/coverage.json +1 -0
- package/_bundled_plugin/examples/legacy-completed-scan/findings.json +57 -0
- package/_bundled_plugin/examples/legacy-completed-scan/report.md +98 -0
- package/_bundled_plugin/examples/legacy-completed-scan/scan-manifest.json +43 -0
- package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/helpers.mjs.br.part-001 +0 -0
- package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +1 -1
- package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
- package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-002 +0 -0
- package/_bundled_plugin/references/access-advisory.md +11 -0
- package/_bundled_plugin/references/core-scan.md +30 -77
- package/_bundled_plugin/references/final-report.md +50 -184
- package/_bundled_plugin/references/scan-artifacts.md +5 -5
- package/_bundled_plugin/references/scan-contract.md +12 -12
- package/_bundled_plugin/references/scan-prologue.md +1 -1
- package/_bundled_plugin/references/scan-runtime.md +1 -5
- package/_bundled_plugin/references/threat-model.md +33 -41
- package/_bundled_plugin/schemas/coverage.schema.json +12 -1
- package/_bundled_plugin/schemas/scan-manifest.schema.json +37 -11
- package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +38 -1
- package/_bundled_plugin/schemas/tools/scan-draft.schema.json +5 -5
- package/_bundled_plugin/scripts/deep_scan_config.py +39 -39
- package/_bundled_plugin/scripts/deep_scan_workbench.py +146 -86
- package/_bundled_plugin/scripts/finalize_scan_contract.py +249 -76
- package/_bundled_plugin/scripts/report_projection.py +49 -17
- package/_bundled_plugin/scripts/review_state.py +68 -0
- package/_bundled_plugin/scripts/threat_model_projection.py +4 -2
- package/_bundled_plugin/scripts/validate_scan_contract.py +1 -2
- package/_bundled_plugin/scripts/windows_scan_local_files.py +43 -14
- package/_bundled_plugin/scripts/workbench/retained_coverage.py +3230 -0
- package/_bundled_plugin/scripts/workbench/retained_records.py +627 -0
- package/_bundled_plugin/scripts/workbench/saved_coverage.py +651 -8
- package/_bundled_plugin/scripts/workbench/saved_outputs.py +72 -0
- package/_bundled_plugin/scripts/workbench/saved_sources.py +730 -0
- package/_bundled_plugin/scripts/workbench_cli.py +3 -0
- package/_bundled_plugin/scripts/workbench_constants.py +0 -1
- package/_bundled_plugin/scripts/workbench_coverage_receipts.py +479 -0
- package/_bundled_plugin/scripts/workbench_db.py +55 -171
- package/_bundled_plugin/scripts/workbench_feedback.py +0 -1
- package/_bundled_plugin/scripts/workbench_finding_workflows.py +51 -9
- package/_bundled_plugin/scripts/workbench_native_indexes.py +56 -44
- package/_bundled_plugin/scripts/workbench_saved_results.py +808 -2389
- package/_bundled_plugin/scripts/workbench_scan_history.py +77 -7
- package/_bundled_plugin/scripts/workbench_schema.py +1 -1
- package/_bundled_plugin/scripts/workbench_source_scopes.py +4 -1
- package/_bundled_plugin/scripts/workbench_target.py +142 -17
- package/_bundled_plugin/scripts/workbench_validation.py +9 -2
- package/_bundled_plugin/shared/workbench-history-repairs.json +21 -0
- package/_bundled_plugin/shared/workbench-migrations.json +28 -0
- package/_bundled_plugin/skills/assess-patch-risk/SKILL.md +3 -14
- package/_bundled_plugin/skills/assess-patch-risk/references/windows-validation.md +14 -0
- package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +38 -103
- package/_bundled_plugin/skills/attack-path-analysis/references/attack-path-facts.md +11 -73
- package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +57 -116
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +28 -51
- package/_bundled_plugin/skills/define-security-policy/SKILL.md +9 -9
- package/_bundled_plugin/skills/finding-discovery/SKILL.md +26 -140
- package/_bundled_plugin/skills/fix-finding/SKILL.md +9 -28
- package/_bundled_plugin/skills/propose-security-hardening/SKILL.md +28 -218
- package/_bundled_plugin/skills/propose-security-hardening/references/proposal-format.md +29 -424
- package/_bundled_plugin/skills/publish-findings/SKILL.md +32 -24
- package/_bundled_plugin/skills/publish-findings/references/wiz-import.md +64 -0
- package/_bundled_plugin/skills/security-diff-scan/SKILL.md +12 -12
- package/_bundled_plugin/skills/security-scan/SKILL.md +29 -17
- package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +11 -17
- package/_bundled_plugin/skills/security-scan/references/scan-artifacts-and-ledger.md +52 -69
- package/_bundled_plugin/skills/threat-model/SKILL.md +16 -9
- package/_bundled_plugin/skills/track-findings/SKILL.md +1 -1
- package/_bundled_plugin/skills/triage-finding/SKILL.md +5 -15
- package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +6 -6
- package/_bundled_plugin/skills/validation/SKILL.md +42 -104
- package/_bundled_plugin/skills/validation/references/validation-guidance.md +21 -106
- package/_bundled_plugin/skills/verify-fix/SKILL.md +4 -2
- package/_bundled_plugin/skills/vulnerability-writeup/SKILL.md +21 -159
- package/_bundled_plugin/skills/vulnerability-writeup/references/report-format.md +18 -60
- package/dist/api.d.ts +5 -3
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +359 -53
- package/dist/api.js.map +1 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +4 -1
- package/dist/auth.js.map +1 -1
- package/dist/cli.d.ts +2 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +696 -430
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.d.ts.map +1 -1
- package/dist/cloud-publish.js +2 -23
- package/dist/cloud-publish.js.map +1 -1
- package/dist/component-scan.d.ts +8 -2
- package/dist/component-scan.d.ts.map +1 -1
- package/dist/component-scan.js +2 -0
- package/dist/component-scan.js.map +1 -1
- package/dist/contract.d.ts +5 -2
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +93 -45
- package/dist/contract.js.map +1 -1
- package/dist/cost.d.ts +18 -0
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +107 -12
- package/dist/cost.js.map +1 -1
- package/dist/coverage-presentation.d.ts +6 -0
- package/dist/coverage-presentation.d.ts.map +1 -0
- package/dist/coverage-presentation.js +34 -0
- package/dist/coverage-presentation.js.map +1 -0
- package/dist/custom-publish.js +2 -2
- package/dist/custom-publish.js.map +1 -1
- package/dist/custom-validation-prompt.js +5 -5
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/custom-validation.d.ts.map +1 -1
- package/dist/custom-validation.js +47 -19
- package/dist/custom-validation.js.map +1 -1
- package/dist/deduplication/checkpointed-review.d.ts.map +1 -1
- package/dist/deduplication/checkpointed-review.js +3 -1
- package/dist/deduplication/checkpointed-review.js.map +1 -1
- package/dist/deduplication/codex-review.d.ts.map +1 -1
- package/dist/deduplication/codex-review.js +2 -2
- package/dist/deduplication/codex-review.js.map +1 -1
- package/dist/deduplication/deduplication-prompts.d.ts +1 -0
- package/dist/deduplication/deduplication-prompts.d.ts.map +1 -1
- package/dist/deduplication/deduplication-prompts.js +3 -0
- package/dist/deduplication/deduplication-prompts.js.map +1 -1
- package/dist/deduplication/records-protocol.d.ts.map +1 -1
- package/dist/deduplication/records-protocol.js +21 -1
- package/dist/deduplication/records-protocol.js.map +1 -1
- package/dist/deduplication/scan.d.ts.map +1 -1
- package/dist/deduplication/scan.js +9 -7
- package/dist/deduplication/scan.js.map +1 -1
- package/dist/endor-findings.d.ts +4 -3
- package/dist/endor-findings.d.ts.map +1 -1
- package/dist/endor-findings.js +16 -11
- package/dist/endor-findings.js.map +1 -1
- package/dist/external-findings-import.d.ts.map +1 -1
- package/dist/external-findings-import.js +13 -5
- package/dist/external-findings-import.js.map +1 -1
- package/dist/external-findings-local.d.ts +1 -0
- package/dist/external-findings-local.d.ts.map +1 -1
- package/dist/external-findings-local.js +14 -3
- package/dist/external-findings-local.js.map +1 -1
- package/dist/external-findings-publish.d.ts +2 -1
- package/dist/external-findings-publish.d.ts.map +1 -1
- package/dist/external-findings-publish.js +64 -28
- package/dist/external-findings-publish.js.map +1 -1
- package/dist/external-findings-read.d.ts +12 -1
- package/dist/external-findings-read.d.ts.map +1 -1
- package/dist/external-findings-read.js +25 -6
- package/dist/external-findings-read.js.map +1 -1
- package/dist/external-findings.d.ts +2 -0
- package/dist/external-findings.d.ts.map +1 -1
- package/dist/external-findings.js.map +1 -1
- package/dist/external-import-contract.d.ts +7 -1
- package/dist/external-import-contract.d.ts.map +1 -1
- package/dist/external-import-contract.js +63 -31
- package/dist/external-import-contract.js.map +1 -1
- package/dist/external-imports-feature.d.ts +6 -0
- package/dist/external-imports-feature.d.ts.map +1 -0
- package/dist/external-imports-feature.js +51 -0
- package/dist/external-imports-feature.js.map +1 -0
- package/dist/finding-workflow.d.ts +24 -5
- package/dist/finding-workflow.d.ts.map +1 -1
- package/dist/finding-workflow.js +24 -9
- package/dist/finding-workflow.js.map +1 -1
- package/dist/github-advisories.d.ts.map +1 -1
- package/dist/github-advisories.js +3 -1
- package/dist/github-advisories.js.map +1 -1
- package/dist/github-findings.d.ts +4 -3
- package/dist/github-findings.d.ts.map +1 -1
- package/dist/github-findings.js +16 -14
- package/dist/github-findings.js.map +1 -1
- package/dist/host-protocol.d.ts +1 -1
- package/dist/host-protocol.d.ts.map +1 -1
- package/dist/host-protocol.js +2 -2
- package/dist/host-protocol.js.map +1 -1
- package/dist/hosted-remediation.d.ts.map +1 -1
- package/dist/hosted-remediation.js +19 -2
- package/dist/hosted-remediation.js.map +1 -1
- package/dist/hosted-scan.d.ts +1 -1
- package/dist/hosted-scan.d.ts.map +1 -1
- package/dist/hosted-scan.js +0 -6
- package/dist/hosted-scan.js.map +1 -1
- package/dist/import-scan.js +17 -17
- package/dist/import-scan.js.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/knowledge-base.d.ts +1 -0
- package/dist/knowledge-base.d.ts.map +1 -1
- package/dist/knowledge-base.js +20 -8
- package/dist/knowledge-base.js.map +1 -1
- package/dist/mock-scan.d.ts +1 -2
- package/dist/mock-scan.d.ts.map +1 -1
- package/dist/mock-scan.js +12 -17
- package/dist/mock-scan.js.map +1 -1
- package/dist/models.d.ts +10 -1
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js.map +1 -1
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +1 -6
- package/dist/multiscan.js.map +1 -1
- package/dist/native-json-findings.d.ts +30 -0
- package/dist/native-json-findings.d.ts.map +1 -0
- package/dist/native-json-findings.js +114 -0
- package/dist/native-json-findings.js.map +1 -0
- package/dist/opengrep-findings.d.ts +10 -0
- package/dist/opengrep-findings.d.ts.map +1 -0
- package/dist/opengrep-findings.js +198 -0
- package/dist/opengrep-findings.js.map +1 -0
- package/dist/owner-evidence.d.ts +2 -0
- package/dist/owner-evidence.d.ts.map +1 -1
- package/dist/owner-evidence.js +2 -1
- package/dist/owner-evidence.js.map +1 -1
- package/dist/patch-tui.d.ts.map +1 -1
- package/dist/patch-tui.js +2 -0
- package/dist/patch-tui.js.map +1 -1
- package/dist/publication.js +1 -2
- package/dist/publication.js.map +1 -1
- package/dist/publish.d.ts +2 -0
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +1 -1
- package/dist/publish.js.map +1 -1
- package/dist/record.d.ts +1 -0
- package/dist/record.d.ts.map +1 -1
- package/dist/record.js +10 -0
- package/dist/record.js.map +1 -1
- package/dist/remediation.d.ts +1 -25
- package/dist/remediation.d.ts.map +1 -1
- package/dist/remediation.js +3 -24
- package/dist/remediation.js.map +1 -1
- package/dist/result.d.ts +5 -3
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +9 -6
- package/dist/result.js.map +1 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +7 -7
- package/dist/runtime.js.map +1 -1
- package/dist/scan-dashboard.d.ts +5 -3
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +79 -26
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-history-renderer.d.ts.map +1 -1
- package/dist/scan-history-renderer.js +9 -3
- package/dist/scan-history-renderer.js.map +1 -1
- package/dist/scan-owner-suggestions.d.ts +1 -1
- package/dist/scan-owner-suggestions.d.ts.map +1 -1
- package/dist/scan-owner-suggestions.js +4 -4
- package/dist/scan-owner-suggestions.js.map +1 -1
- package/dist/scan-usage-display.d.ts +8 -0
- package/dist/scan-usage-display.d.ts.map +1 -0
- package/dist/scan-usage-display.js +46 -0
- package/dist/scan-usage-display.js.map +1 -0
- package/dist/scanner-import.d.ts +1 -1
- package/dist/scanner-import.d.ts.map +1 -1
- package/dist/scanner-import.js +7 -3
- package/dist/scanner-import.js.map +1 -1
- package/dist/security-policy.d.ts.map +1 -1
- package/dist/security-policy.js +17 -22
- package/dist/security-policy.js.map +1 -1
- package/dist/semgrep-findings.d.ts +4 -3
- package/dist/semgrep-findings.d.ts.map +1 -1
- package/dist/semgrep-findings.js +22 -89
- package/dist/semgrep-findings.js.map +1 -1
- package/dist/skill-authentication.d.ts +18 -0
- package/dist/skill-authentication.d.ts.map +1 -0
- package/dist/skill-authentication.js +82 -0
- package/dist/skill-authentication.js.map +1 -0
- package/dist/snyk-findings.d.ts +5 -4
- package/dist/snyk-findings.d.ts.map +1 -1
- package/dist/snyk-findings.js +18 -17
- package/dist/snyk-findings.js.map +1 -1
- package/dist/suggest-owners.d.ts +4 -1
- package/dist/suggest-owners.d.ts.map +1 -1
- package/dist/suggest-owners.js +53 -21
- package/dist/suggest-owners.js.map +1 -1
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +4 -1
- package/dist/targets.js.map +1 -1
- package/dist/wiz-csv.d.ts +2 -1
- package/dist/wiz-csv.d.ts.map +1 -1
- package/dist/wiz-csv.js +3 -3
- package/dist/wiz-csv.js.map +1 -1
- package/dist/wiz-findings.d.ts +2 -1
- package/dist/wiz-findings.d.ts.map +1 -1
- package/dist/wiz-findings.js +27 -23
- package/dist/wiz-findings.js.map +1 -1
- package/docs/classify-severity-records.md +3 -4
- package/docs/cli.md +171 -41
- package/docs/dedupe-records.md +15 -1
- package/docs/findings-service.md +119 -118
- package/docs/hosted-remediation.md +19 -17
- package/docs/hosted-scans.md +37 -11
- package/package.json +9 -9
- package/_bundled_plugin/scripts/generate_in_scope_files.py +0 -277
- package/_bundled_plugin/scripts/generate_rank_input.py +0 -350
- package/_bundled_plugin/scripts/rank_preview.py +0 -129
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { posix } from "node:path";
|
|
2
|
+
import { validateExternalEvidenceJson, validateExternalReport, } from "./external-import-contract.js";
|
|
3
|
+
import { canonicalJson } from "./record.js";
|
|
4
|
+
import { errorMessage } from "./errors.js";
|
|
5
|
+
import { messageText, parseNativeJsonResult, projectNativeJsonResult, sourceRepositoryUrl, } from "./native-json-findings.js";
|
|
6
|
+
import { array, readScannerJson, record, relativePath, requiredText, stableId, } from "./scanner-import.js";
|
|
7
|
+
/** Import native scanner evidence without assigning a Codex assessment. */
|
|
8
|
+
export function normalizeOpenGrepFindings(input, options, target = "cloud") {
|
|
9
|
+
const document = record(input, "OpenGrep report");
|
|
10
|
+
const repositoryUrl = sourceRepositoryUrl(options?.sourceRepositoryUrl, "OpenGrep");
|
|
11
|
+
const version = requiredText(document["version"], "OpenGrep version");
|
|
12
|
+
const { results, ...report } = document;
|
|
13
|
+
const values = array(results, "OpenGrep results");
|
|
14
|
+
const errors = array(report["errors"], "OpenGrep errors");
|
|
15
|
+
validateExternalReport(report);
|
|
16
|
+
const projection = {
|
|
17
|
+
origin: "OpenGrep",
|
|
18
|
+
repositoryUrl,
|
|
19
|
+
severity: () => "unknown",
|
|
20
|
+
reportContext: { version },
|
|
21
|
+
target,
|
|
22
|
+
scanErrorCount: errors.length,
|
|
23
|
+
};
|
|
24
|
+
const output = {
|
|
25
|
+
read: values.length,
|
|
26
|
+
findings: [],
|
|
27
|
+
excluded: [],
|
|
28
|
+
report: structuredClone(report),
|
|
29
|
+
};
|
|
30
|
+
function exclude(position, id, error) {
|
|
31
|
+
output.excluded.push({
|
|
32
|
+
position,
|
|
33
|
+
source_finding_id: id,
|
|
34
|
+
reason: errorMessage(error),
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function projectGroup(observations) {
|
|
38
|
+
const results = observations.map(({ parsed }) => parsed.result);
|
|
39
|
+
if (results.length === 1)
|
|
40
|
+
return projectNativeJsonResult(observations[0].parsed, {
|
|
41
|
+
...projection,
|
|
42
|
+
observations: results,
|
|
43
|
+
});
|
|
44
|
+
const sourceData = {
|
|
45
|
+
report: { version },
|
|
46
|
+
scan_error_count: errors.length,
|
|
47
|
+
results,
|
|
48
|
+
};
|
|
49
|
+
// Replacing [] with the same raw results adds the same wire bytes to every candidate.
|
|
50
|
+
const rawBytes = validateExternalEvidenceJson({ source_data: sourceData }, target) -
|
|
51
|
+
validateExternalEvidenceJson({ source_data: { ...sourceData, results: [] } }, target);
|
|
52
|
+
let projectionError;
|
|
53
|
+
for (const { parsed } of observations) {
|
|
54
|
+
try {
|
|
55
|
+
const evidence = projectNativeJsonResult(parsed, {
|
|
56
|
+
...projection,
|
|
57
|
+
observations: [],
|
|
58
|
+
});
|
|
59
|
+
validateExternalEvidenceJson(evidence, target, rawBytes);
|
|
60
|
+
evidence.source_data["results"] = results;
|
|
61
|
+
return evidence;
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
projectionError ??= error;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
throw projectionError;
|
|
68
|
+
}
|
|
69
|
+
function retainPublishableTraces(observations, id) {
|
|
70
|
+
const emptyWrapperBytes = validateExternalEvidenceJson({ source_data: { results: [] } }, target);
|
|
71
|
+
function sizeWithTrace(observation, evidenceBytes) {
|
|
72
|
+
return validateExternalEvidenceJson({ source_data: { results: [observation.parsed.result] } }, target, evidenceBytes - emptyWrapperBytes);
|
|
73
|
+
}
|
|
74
|
+
const singletonErrors = new Map();
|
|
75
|
+
let smallestProjectionBytes = Infinity;
|
|
76
|
+
let coreRawBytes = 0;
|
|
77
|
+
for (const observation of observations) {
|
|
78
|
+
try {
|
|
79
|
+
const evidence = projectNativeJsonResult(observation.parsed, {
|
|
80
|
+
...projection,
|
|
81
|
+
observations: [],
|
|
82
|
+
});
|
|
83
|
+
const projectedBytes = validateExternalEvidenceJson(evidence, target);
|
|
84
|
+
const singletonBytes = sizeWithTrace(observation, projectedBytes);
|
|
85
|
+
coreRawBytes += singletonBytes - projectedBytes;
|
|
86
|
+
smallestProjectionBytes = Math.min(smallestProjectionBytes, projectedBytes);
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
singletonErrors.set(observation, errorMessage(error));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (!singletonErrors.size)
|
|
93
|
+
return observations;
|
|
94
|
+
// Reserve every independently publishable trace, including the commas in
|
|
95
|
+
// their results array, before trying raw-only traces in canonical order.
|
|
96
|
+
const coreCount = observations.length - singletonErrors.size;
|
|
97
|
+
let groupBytes = smallestProjectionBytes + coreRawBytes + coreCount - 1;
|
|
98
|
+
return observations.filter((observation) => {
|
|
99
|
+
let reason = singletonErrors.get(observation);
|
|
100
|
+
if (reason === undefined)
|
|
101
|
+
return true;
|
|
102
|
+
if (coreCount) {
|
|
103
|
+
try {
|
|
104
|
+
groupBytes = sizeWithTrace(observation, groupBytes + 1);
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
const groupReason = errorMessage(error);
|
|
109
|
+
if (groupReason !== reason)
|
|
110
|
+
reason = `${groupReason} This trace also fails standalone validation. ${reason}`;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exclude(observation.position, id, reason);
|
|
114
|
+
return false;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
const groups = new Map();
|
|
118
|
+
for (const [index, value] of values.entries()) {
|
|
119
|
+
let id = null;
|
|
120
|
+
try {
|
|
121
|
+
const parsed = parseNativeJsonResult(value, "OpenGrep");
|
|
122
|
+
if (parsed.path !== null) {
|
|
123
|
+
// Validate the emitted spelling across platforms, keeping literal POSIX backslashes.
|
|
124
|
+
const path = posix.normalize(parsed.rawPath);
|
|
125
|
+
parsed.path =
|
|
126
|
+
relativePath(posix.normalize(path.replaceAll("\\", "/"))) === null
|
|
127
|
+
? null
|
|
128
|
+
: path;
|
|
129
|
+
}
|
|
130
|
+
// Native fingerprint counters change when another analysis pass adds matches.
|
|
131
|
+
// A source move creates a new occurrence; this is not cross-revision matching.
|
|
132
|
+
id = stableId("opengrep-location", [
|
|
133
|
+
parsed.rule,
|
|
134
|
+
parsed.path ?? parsed.rawPath,
|
|
135
|
+
parsed.line,
|
|
136
|
+
parsed.column,
|
|
137
|
+
parsed.endLine,
|
|
138
|
+
parsed.endColumn,
|
|
139
|
+
]);
|
|
140
|
+
messageText(parsed.extra["message"], "OpenGrep");
|
|
141
|
+
const group = groups.get(id) ?? [];
|
|
142
|
+
group.push({ position: index + 1, parsed });
|
|
143
|
+
groups.set(id, group);
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
exclude(index + 1, id, error);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
for (const [id, observations] of [...groups].sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0)) {
|
|
150
|
+
const ordered = observations.length === 1
|
|
151
|
+
? observations
|
|
152
|
+
: observations
|
|
153
|
+
.flatMap((observation) => {
|
|
154
|
+
try {
|
|
155
|
+
const result = structuredClone(observation.parsed.result);
|
|
156
|
+
validateExternalEvidenceJson({ source_data: { results: [result] } }, target);
|
|
157
|
+
observation.parsed.result = result;
|
|
158
|
+
return [{ observation, key: canonicalJson(result) }];
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
exclude(observation.position, id, error);
|
|
162
|
+
return [];
|
|
163
|
+
}
|
|
164
|
+
})
|
|
165
|
+
.sort((left, right) => left.key < right.key ? -1 : left.key > right.key ? 1 : 0)
|
|
166
|
+
.map(({ observation }) => observation);
|
|
167
|
+
if (!ordered.length)
|
|
168
|
+
continue;
|
|
169
|
+
let retained = ordered;
|
|
170
|
+
try {
|
|
171
|
+
let evidence;
|
|
172
|
+
try {
|
|
173
|
+
evidence = projectGroup(retained);
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
if (retained.length === 1)
|
|
177
|
+
throw error;
|
|
178
|
+
retained = retainPublishableTraces(retained, id);
|
|
179
|
+
if (!retained.length)
|
|
180
|
+
continue;
|
|
181
|
+
if (retained.length === ordered.length)
|
|
182
|
+
throw error;
|
|
183
|
+
evidence = projectGroup(retained);
|
|
184
|
+
}
|
|
185
|
+
output.findings.push({ source_finding_id: id, evidence });
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
for (const observation of retained)
|
|
189
|
+
exclude(observation.position, id, error);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
output.excluded.sort((left, right) => left.position - right.position);
|
|
193
|
+
return output;
|
|
194
|
+
}
|
|
195
|
+
export async function readOpenGrepFindings(path, options, target = "cloud") {
|
|
196
|
+
return normalizeOpenGrepFindings(await readScannerJson(path), options, target);
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=opengrep-findings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opengrep-findings.js","sourceRoot":"","sources":["../src/opengrep-findings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAClC,OAAO,EACL,4BAA4B,EAC5B,sBAAsB,GAEvB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EACL,WAAW,EACX,qBAAqB,EACrB,uBAAuB,EACvB,mBAAmB,GACpB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,KAAK,EACL,eAAe,EACf,MAAM,EACN,YAAY,EACZ,YAAY,EACZ,QAAQ,GACT,MAAM,qBAAqB,CAAC;AAO7B,2EAA2E;AAC3E,MAAM,UAAU,yBAAyB,CACvC,KAAc,EACd,OAA8B,EAC9B,MAAM,GAAyB,OAAO;IAEtC,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC;IAClD,MAAM,aAAa,GAAG,mBAAmB,CACvC,OAAO,EAAE,mBAAmB,EAC5B,UAAU,CACX,CAAC;IACF,MAAM,OAAO,GAAG,YAAY,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,kBAAkB,CAAC,CAAC;IACtE,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,EAAE,GAAG,QAAQ,CAAC;IACxC,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC;IAClD,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,iBAAiB,CAAC,CAAC;IAC1D,sBAAsB,CAAC,MAAM,CAAC,CAAC;IAC/B,MAAM,UAAU,GAAG;QACjB,MAAM,EAAE,UAAU;QAClB,aAAa;QACb,QAAQ,EAAE,GAAG,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ACZ,OAA8B,EAC9B,MAAM,GAAyB,OAAO;IAEtC,OAAO,yBAAyB,CAC9B,MAAM,eAAe,CAAC,IAAI,CAAC,EAC3B,OAAO,EACP,MAAM,CACP,CAAC;AACJ,CAAC","sourcesContent":["import { posix } from \"node:path\";\nimport {\n validateExternalEvidenceJson,\n validateExternalReport,\n type ExternalImportTarget,\n} from \"./external-import-contract.js\";\nimport { canonicalJson } from \"./record.js\";\nimport { errorMessage } from \"./errors.js\";\nimport type { ExternalFindings } from \"./external-findings.js\";\nimport {\n messageText,\n parseNativeJsonResult,\n projectNativeJsonResult,\n sourceRepositoryUrl,\n} from \"./native-json-findings.js\";\nimport {\n array,\n readScannerJson,\n record,\n relativePath,\n requiredText,\n stableId,\n} from \"./scanner-import.js\";\n\nexport interface OpenGrepImportOptions {\n /** Source repository declared by the caller, independent of the destination. */\n sourceRepositoryUrl: string;\n}\n\n/** Import native scanner evidence without assigning a Codex assessment. */\nexport function normalizeOpenGrepFindings(\n input: unknown,\n options: OpenGrepImportOptions,\n target: ExternalImportTarget = \"cloud\",\n): ExternalFindings {\n const document = record(input, \"OpenGrep report\");\n const repositoryUrl = sourceRepositoryUrl(\n options?.sourceRepositoryUrl,\n \"OpenGrep\",\n );\n const version = requiredText(document[\"version\"], \"OpenGrep version\");\n const { results, ...report } = document;\n const values = array(results, \"OpenGrep results\");\n const errors = array(report[\"errors\"], \"OpenGrep errors\");\n validateExternalReport(report);\n const projection = {\n origin: \"OpenGrep\",\n repositoryUrl,\n severity: () => \"unknown\",\n reportContext: { version },\n target,\n scanErrorCount: errors.length,\n };\n const output: ExternalFindings = {\n read: values.length,\n findings: [],\n excluded: [],\n report: structuredClone(report),\n };\n type Observation = {\n position: number;\n parsed: ReturnType<typeof parseNativeJsonResult>;\n };\n function exclude(position: number, id: string | null, error: unknown) {\n output.excluded.push({\n position,\n source_finding_id: id,\n reason: errorMessage(error),\n });\n }\n function projectGroup(observations: Observation[]) {\n const results = observations.map(({ parsed }) => parsed.result);\n if (results.length === 1)\n return projectNativeJsonResult(observations[0]!.parsed, {\n ...projection,\n observations: results,\n });\n const sourceData = {\n report: { version },\n scan_error_count: errors.length,\n results,\n };\n // Replacing [] with the same raw results adds the same wire bytes to every candidate.\n const rawBytes =\n validateExternalEvidenceJson({ source_data: sourceData }, target) -\n validateExternalEvidenceJson(\n { source_data: { ...sourceData, results: [] } },\n target,\n );\n let projectionError: unknown;\n for (const { parsed } of observations) {\n try {\n const evidence = projectNativeJsonResult(parsed, {\n ...projection,\n observations: [],\n });\n validateExternalEvidenceJson(evidence, target, rawBytes);\n evidence.source_data![\"results\"] = results;\n return evidence;\n } catch (error) {\n projectionError ??= error;\n }\n }\n throw projectionError;\n }\n function retainPublishableTraces(observations: Observation[], id: string) {\n const emptyWrapperBytes = validateExternalEvidenceJson(\n { source_data: { results: [] } },\n target,\n );\n function sizeWithTrace(observation: Observation, evidenceBytes: number) {\n return validateExternalEvidenceJson(\n { source_data: { results: [observation.parsed.result] } },\n target,\n evidenceBytes - emptyWrapperBytes,\n );\n }\n const singletonErrors = new Map<Observation, string>();\n let smallestProjectionBytes = Infinity;\n let coreRawBytes = 0;\n for (const observation of observations) {\n try {\n const evidence = projectNativeJsonResult(observation.parsed, {\n ...projection,\n observations: [],\n });\n const projectedBytes = validateExternalEvidenceJson(evidence, target);\n const singletonBytes = sizeWithTrace(observation, projectedBytes);\n coreRawBytes += singletonBytes - projectedBytes;\n smallestProjectionBytes = Math.min(\n smallestProjectionBytes,\n projectedBytes,\n );\n } catch (error) {\n singletonErrors.set(observation, errorMessage(error));\n }\n }\n if (!singletonErrors.size) return observations;\n // Reserve every independently publishable trace, including the commas in\n // their results array, before trying raw-only traces in canonical order.\n const coreCount = observations.length - singletonErrors.size;\n let groupBytes = smallestProjectionBytes + coreRawBytes + coreCount - 1;\n return observations.filter((observation) => {\n let reason = singletonErrors.get(observation);\n if (reason === undefined) return true;\n if (coreCount) {\n try {\n groupBytes = sizeWithTrace(observation, groupBytes + 1);\n return true;\n } catch (error) {\n const groupReason = errorMessage(error);\n if (groupReason !== reason)\n reason = `${groupReason} This trace also fails standalone validation. ${reason}`;\n }\n }\n exclude(observation.position, id, reason);\n return false;\n });\n }\n const groups = new Map<string, Observation[]>();\n for (const [index, value] of values.entries()) {\n let id: string | null = null;\n try {\n const parsed = parseNativeJsonResult(value, \"OpenGrep\");\n if (parsed.path !== null) {\n // Validate the emitted spelling across platforms, keeping literal POSIX backslashes.\n const path = posix.normalize(parsed.rawPath);\n parsed.path =\n relativePath(posix.normalize(path.replaceAll(\"\\\\\", \"/\"))) === null\n ? null\n : path;\n }\n // Native fingerprint counters change when another analysis pass adds matches.\n // A source move creates a new occurrence; this is not cross-revision matching.\n id = stableId(\"opengrep-location\", [\n parsed.rule,\n parsed.path ?? parsed.rawPath,\n parsed.line,\n parsed.column,\n parsed.endLine,\n parsed.endColumn,\n ]);\n messageText(parsed.extra[\"message\"], \"OpenGrep\");\n const group = groups.get(id) ?? [];\n group.push({ position: index + 1, parsed });\n groups.set(id, group);\n } catch (error) {\n exclude(index + 1, id, error);\n }\n }\n for (const [id, observations] of [...groups].sort(([left], [right]) =>\n left < right ? -1 : left > right ? 1 : 0,\n )) {\n const ordered =\n observations.length === 1\n ? observations\n : observations\n .flatMap((observation) => {\n try {\n const result = structuredClone(observation.parsed.result);\n validateExternalEvidenceJson(\n { source_data: { results: [result] } },\n target,\n );\n observation.parsed.result = result;\n return [{ observation, key: canonicalJson(result) }];\n } catch (error) {\n exclude(observation.position, id, error);\n return [];\n }\n })\n .sort((left, right) =>\n left.key < right.key ? -1 : left.key > right.key ? 1 : 0,\n )\n .map(({ observation }) => observation);\n if (!ordered.length) continue;\n let retained = ordered;\n try {\n let evidence;\n try {\n evidence = projectGroup(retained);\n } catch (error) {\n if (retained.length === 1) throw error;\n retained = retainPublishableTraces(retained, id);\n if (!retained.length) continue;\n if (retained.length === ordered.length) throw error;\n evidence = projectGroup(retained);\n }\n output.findings.push({ source_finding_id: id, evidence });\n } catch (error) {\n for (const observation of retained)\n exclude(observation.position, id, error);\n }\n }\n output.excluded.sort((left, right) => left.position - right.position);\n return output;\n}\n\nexport async function readOpenGrepFindings(\n path: string,\n options: OpenGrepImportOptions,\n target: ExternalImportTarget = \"cloud\",\n): Promise<ExternalFindings> {\n return normalizeOpenGrepFindings(\n await readScannerJson(path),\n options,\n target,\n );\n}\n"]}
|
package/dist/owner-evidence.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export interface OwnerEvidence {
|
|
|
9
9
|
kind: "source" | "blame" | "history" | "codeowners";
|
|
10
10
|
path: string;
|
|
11
11
|
commit: string;
|
|
12
|
+
/** Original blamed commit; blame citations keep commit at the checkout revision. */
|
|
13
|
+
blameCommit?: string;
|
|
12
14
|
startLine?: number;
|
|
13
15
|
endLine?: number;
|
|
14
16
|
rule?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"owner-evidence.d.ts","sourceRoot":"","sources":["../src/owner-evidence.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAUxD,OAAO,EAGL,KAAK,iBAAiB,EACvB,MAAM,iBAAiB,CAAC;AAIzB,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,QAAQ,GAAG,OAAO,GAAG,SAAS,GAAG,YAAY,CAAC;IACpD,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAED,M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AC;CAC9B;AAED,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,aAAa,EAAE,CAAC;IAC5B,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,SAAS,EAAE,iBAAiB,GAAG,IAAI,CAAC;CACrC;AAED,qFAAqF;AACrF,wBAAsB,eAAe,CACnC,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,CAAC,UAAU,EAC9B,MAAM,CAAC,EAAE,WAAW;mBA0DE,MAAM,EAAE;;oBAWP,MAAM;;;;;;GAwB9B;AAyCD,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,YAAY,EACrB,UAAU,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC,GACtD,OAAO,CAAC,YAAY,CAAC,CAsLvB"}
|
package/dist/owner-evidence.js
CHANGED
|
@@ -214,7 +214,7 @@ export async function collectOwnerEvidence(finding, repository) {
|
|
|
214
214
|
const index = identityIndex(name, email);
|
|
215
215
|
const previous = context.evidence.at(-1);
|
|
216
216
|
if (previous?.kind === "blame" &&
|
|
217
|
-
previous.
|
|
217
|
+
previous.blameCommit === commit &&
|
|
218
218
|
previous.identityIndex === index &&
|
|
219
219
|
previous.endLine === line - 1) {
|
|
220
220
|
previous.endLine = line;
|
|
@@ -224,6 +224,7 @@ export async function collectOwnerEvidence(finding, repository) {
|
|
|
224
224
|
kind: "blame",
|
|
225
225
|
path,
|
|
226
226
|
commit: revision,
|
|
227
|
+
blameCommit: commit,
|
|
227
228
|
startLine: line,
|
|
228
229
|
endLine: line,
|
|
229
230
|
content: `Authored in ${commit}.`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"owner-evidence.js","sourceRoot":"","sources":["../src/owner-evidence.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,KAAK,EAAE,OAAO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AS,EAAE,IAAI;4BACf,OAAO,EAAE,IAAI;4BACb,OAAO,EAAE,eAAe,MAAM,GAAG;4BACjC,aAAa,EAAE,KAAK;yBACrB,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QACD,MAAM,OAAO,GAAG,CACd,MAAM,GAAG,CACP,KAAK,EACL,kBAAkB,EAClB,qBAAqB,EACrB,YAAY,EACZ,eAAe,EACf,wCAAwC,EACxC,IAAI,EACJ,QAAQ,EACR,IAAI,EACJ,IAAI,CACL,CACF,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACd,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;YAC3D,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,KAAK,CACxD,KAAK,EACL,KAAK,GAAG,CAAC,CACkC,CAAC;YAC9C,IAAI,KAAK,CAAC,IAAI,EAAE;gBACd,GAAG,CAAC;oBACF,IAAI,EAAE,SAAS;oBACf,IAAI;oBACJ,MAAM;oBACN,OAAO,EAAE,GAAG,IAAI,KAAK,OAAO,EAAE;oBAC9B,aAAa,EAAE,aAAa,CAAC,IAAI,EAAE,KAAK,CAAC;iBAC1C,CAAC,CAAC;QACP,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { execFile as execFileCallback } from \"node:child_process\";\nimport { lstat, readdir, realpath } from \"node:fs/promises\";\nimport { join, relative } from \"node:path\";\nimport { promisify } from \"node:util\";\nimport { CodexSecurityError, InvalidTargetError } from \"./errors.js\";\nimport type { OwnerFinding } from \"./suggest-owners.js\";\nimport {\n nullIfMissingFile,\n enclosingGitWorktreeRoot,\n gitMetadataDirectories,\n normalizeRepository,\n relativePathIsOutside,\n validatedGitEnvironment,\n} from \"./targets.js\";\nimport { resolveTrustedExecutable } from \"./trusted-executable.js\";\nimport {\n codeownersForPath,\n parseCodeowners,\n type CodeownerIdentity,\n} from \"./codeowners.js\";\n\nconst execFile = promisify(execFileCallback);\n\nexport interface OwnerIdentity {\n name: string;\n email: string;\n}\n\nexport interface OwnerEvidence {\n id: string;\n kind: \"source\" | \"blame\" | \"history\" | \"codeowners\";\n path: string;\n commit: string;\n startLine?: number;\n endLine?: number;\n rule?: string;\n matchedPath?: string;\n content: string;\n identityIndex: number | null;\n}\n\nexport interface OwnerContext {\n identities: OwnerIdentity[];\n evidence: OwnerEvidence[];\n limitations: string[];\n codeowner: CodeownerIdentity | null;\n}\n\n/** Read committed objects, so dirty files and source symlinks are never followed. */\nexport async function ownerRepository(\n repository: string,\n environment: NodeJS.ProcessEnv,\n signal?: AbortSignal,\n) {\n repository = await normalizeRepository(repository, signal);\n validatedGitEnvironment(environment);\n repository =\n (await enclosingGitWorktreeRoot(repository, signal, {\n requireIfPresent: true,\n })) ?? repository;\n const executable = await resolveTrustedExecutable(\n \"git\",\n environment,\n repository,\n );\n if (executable === null)\n throw new CodexSecurityError(\"Git is required to suggest owners.\");\n const run = async (cwd: string, args: string[], encoding: BufferEncoding) => {\n signal?.throwIfAborted();\n const { stdout } = await execFile(executable.executable, args, {\n cwd,\n env: { ...executable.environment, GIT_NO_LAZY_FETCH: \"1\" },\n signal,\n maxBuffer: Infinity,\n encoding: \"buffer\",\n });\n return stdout.toString(encoding);\n };\n const [gitDirectory, commonDirectory, ...objectDirectories] =\n await gitMetadataDirectories(repository, signal, {\n includeLocalObjects: true,\n });\n const metadataDirectories = [...new Set([gitDirectory, commonDirectory])];\n if (\n objectDirectories.some((path) =>\n metadataDirectories.every((root) =>\n relativePathIsOutside(relative(root, path)),\n ),\n )\n ) {\n throw new InvalidTargetError(\n \"Git objects are not bound to the selected checkout. Use a checkout that does not borrow external object stores.\",\n );\n }\n await requireBoundMetadata(metadataDirectories, objectDirectories, signal);\n // Blame otherwise reads an uncommitted .mailmap from the working directory.\n const gitOutput = (encoding: BufferEncoding, ...args: string[]) =>\n run(\n gitDirectory,\n [\n `--git-dir=${gitDirectory}`,\n \"--literal-pathspecs\",\n \"-c\",\n \"core.bare=true\",\n \"-c\",\n \"i18n.logOutputEncoding=UTF-8\",\n ...args,\n ],\n encoding,\n );\n const git = (...args: string[]) => gitOutput(\"utf8\", ...args);\n const revision = (await git(\"rev-parse\", \"--verify\", \"HEAD^{commit}\")).trim();\n const files = new Set(\n (await gitOutput(\"latin1\", \"ls-tree\", \"-r\", \"-z\", \"--full-tree\", revision))\n .split(\"\\0\")\n .filter((record) => /^100(?:644|755) blob /u.test(record))\n .map((record) => record.slice(record.indexOf(\"\\t\") + 1)),\n );\n const shallow =\n (await git(\"rev-parse\", \"--is-shallow-repository\")).trim() === \"true\";\n // Latin-1 keys preserve Git's filename bytes, including unrelated non-UTF-8 names.\n const hasFile = (path: string) =>\n path.isWellFormed() && files.has(Buffer.from(path).toString(\"latin1\"));\n const loadCodeowners = async () => {\n const path = [\".github/CODEOWNERS\", \"CODEOWNERS\", \"docs/CODEOWNERS\"].find(\n hasFile,\n );\n if (path === undefined) return null;\n const source = await git(\"cat-file\", \"blob\", `${revision}:${path}`);\n // GitHub requires CODEOWNERS to be under 3 MB.\n return {\n path,\n rules:\n Buffer.byteLength(source) >= 3_000_000 ? null : parseCodeowners(source),\n };\n };\n let codeowners: ReturnType<typeof loadCodeowners> | undefined;\n return {\n git,\n revision,\n hasFile,\n shallow,\n // Keep the load lazy so failures remain inside per-finding error handling.\n codeowners: () => (codeowners ??= loadCodeowners()),\n };\n}\n\n/** Neither references nor objects may link into another checkout. */\nasync function requireBoundMetadata(\n metadataDirectories: string[],\n objectDirectories: string[],\n signal?: AbortSignal,\n): Promise<void> {\n const pending = [\n ...objectDirectories,\n ...metadataDirectories.flatMap((directory) =>\n [\"HEAD\", \"refs\", \"packed-refs\", \"reftable\"].map((name) =>\n join(directory, name),\n ),\n ),\n ];\n const visited = new Set<string>();\n while (pending.length > 0) {\n signal?.throwIfAborted();\n const path = pending.pop()!;\n if (visited.has(path)) continue;\n visited.add(path);\n const entry = await lstat(path).catch(nullIfMissingFile);\n if (entry?.isSymbolicLink()) {\n const destination = await realpath(path);\n if (\n metadataDirectories.every((root) =>\n relativePathIsOutside(relative(root, destination)),\n )\n ) {\n throw new InvalidTargetError(\n \"Git metadata is not bound to the selected checkout. Select the intended checkout or repair its Git metadata.\",\n );\n }\n pending.push(destination);\n } else if (entry?.isDirectory()) {\n for (const name of await readdir(path)) pending.push(join(path, name));\n }\n }\n}\n\nexport async function collectOwnerEvidence(\n finding: OwnerFinding,\n repository: Awaited<ReturnType<typeof ownerRepository>>,\n): Promise<OwnerContext> {\n const { git, revision, hasFile, shallow } = repository;\n const context: OwnerContext = {\n identities: [],\n evidence: [],\n codeowner: null,\n limitations: [\n \"Git authors are not verified tracker accounts or proof of current employment.\",\n ],\n };\n if (shallow)\n context.limitations.push(\n \"This checkout has shallow history; earlier contributors may be missing.\",\n );\n const stale =\n finding.sourceRevision !== undefined && finding.sourceRevision !== revision;\n if (stale)\n context.limitations.push(\n \"The finding revision differs from HEAD; its line ranges were not used.\",\n );\n if (finding.locations.length === 0)\n context.limitations.push(\"No source locations were supplied.\");\n const identityIndex = (name: string, email: string) => {\n const index = context.identities.findIndex(\n (identity) => identity.email === email,\n );\n if (index !== -1) return index;\n return context.identities.push({ name, email }) - 1;\n };\n const add = (item: Omit<OwnerEvidence, \"id\">) => {\n context.evidence.push({ id: `e${context.evidence.length + 1}`, ...item });\n };\n const codeowners = await repository.codeowners();\n if (codeowners !== null) {\n if (codeowners.rules === null) {\n context.limitations.push(\n \"CODEOWNERS meets or exceeds GitHub's 3 MB file-size limit and was ignored.\",\n );\n } else {\n for (const { path } of finding.locations) {\n if (!hasFile(path)) continue;\n const rule = codeownersForPath(codeowners.rules, path);\n if (rule === undefined) continue;\n const owner = rule.owners[0];\n if (owner === undefined) continue;\n context.codeowner = owner;\n context.limitations.push(\n \"CODEOWNERS identities are declarations; their existence and repository access are not verified.\",\n );\n add({\n kind: \"codeowners\",\n path: codeowners.path,\n commit: revision,\n startLine: rule.line,\n endLine: rule.line,\n rule: rule.rule,\n matchedPath: path,\n content: rule.rule,\n identityIndex: null,\n });\n return context;\n }\n }\n }\n for (const path of new Set(finding.locations.map(({ path }) => path))) {\n if (!hasFile(path)) {\n context.limitations.push(`Not a regular file at HEAD: ${path}`);\n continue;\n }\n const source = await git(\"cat-file\", \"blob\", `${revision}:${path}`);\n if (!source || source.includes(\"\\0\")) {\n context.limitations.push(`Source is empty or binary: ${path}`);\n continue;\n }\n const lines = source.replace(/\\n$/u, \"\").split(\"\\n\");\n const locations = stale\n ? [{ path }]\n : finding.locations.filter((location) => location.path === path);\n for (const location of locations) {\n const start = location.startLine ?? 1;\n if (start > lines.length) {\n context.limitations.push(\n `Finding line is outside the committed file: ${path}:${start}`,\n );\n continue;\n }\n // Include surrounding code for the model, but attribute only the affected lines.\n const end = Math.min(\n location.endLine ?? location.startLine ?? lines.length,\n lines.length,\n );\n const excerptStart = Math.max(1, start - 10);\n const excerptEnd = Math.min(lines.length, end + 10);\n add({\n kind: \"source\",\n path,\n commit: revision,\n startLine: excerptStart,\n endLine: excerptEnd,\n content: lines\n .slice(excerptStart - 1, excerptEnd)\n .map((line, index) => `${excerptStart + index}: ${line}`)\n .join(\"\\n\"),\n identityIndex: null,\n });\n const blame = await git(\n \"blame\",\n \"--line-porcelain\",\n \"--no-textconv\",\n \"--ignore-revs-file=\",\n \"-L\",\n `${start},${end}`,\n revision,\n \"--\",\n path,\n );\n let commit = \"\",\n name = \"\",\n email = \"\",\n line = 0;\n for (const value of blame.split(\"\\n\")) {\n const header = /^([a-f0-9]{40,64}) \\d+ (\\d+)(?: \\d+)?$/u.exec(value);\n if (header) {\n commit = header[1]!;\n line = Number(header[2]);\n } else if (value.startsWith(\"author \")) name = value.slice(7);\n else if (value.startsWith(\"author-mail <\")) email = value.slice(13, -1);\n else if (value.startsWith(\"\\t\") && email.trim()) {\n const index = identityIndex(name, email);\n const previous = context.evidence.at(-1);\n if (\n previous?.kind === \"blame\" &&\n previous.content === `Authored in ${commit}.` &&\n previous.identityIndex === index &&\n previous.endLine === line - 1\n ) {\n previous.endLine = line;\n } else {\n add({\n kind: \"blame\",\n path,\n commit: revision,\n startLine: line,\n endLine: line,\n content: `Authored in ${commit}.`,\n identityIndex: index,\n });\n }\n }\n }\n }\n const history = (\n await git(\n \"log\",\n \"--no-use-mailmap\",\n \"--no-show-signature\",\n \"--no-notes\",\n \"--no-decorate\",\n \"--format=%H%x00%an%x00%ae%x00%aI%x00%s\",\n \"-z\",\n revision,\n \"--\",\n path,\n )\n ).split(\"\\0\");\n for (let index = 0; index + 4 < history.length; index += 5) {\n const [commit, name, email, date, subject] = history.slice(\n index,\n index + 5,\n ) as [string, string, string, string, string];\n if (email.trim())\n add({\n kind: \"history\",\n path,\n commit,\n content: `${date}: ${subject}`,\n identityIndex: identityIndex(name, email),\n });\n }\n }\n return context;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"owner-evidence.js","sourceRoot":"","sources":["../src/owner-evidence.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAErE,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACxB,sBAAsB,EACtB,mBAAmB,EACnB,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EACL,iBAA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AG,CAAC,EAAE,KAAK,GAAG,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;YAC3D,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,KAAK,CACxD,KAAK,EACL,KAAK,GAAG,CAAC,CACkC,CAAC;YAC9C,IAAI,KAAK,CAAC,IAAI,EAAE;gBACd,GAAG,CAAC;oBACF,IAAI,EAAE,SAAS;oBACf,IAAI;oBACJ,MAAM;oBACN,OAAO,EAAE,GAAG,IAAI,KAAK,OAAO,EAAE;oBAC9B,aAAa,EAAE,aAAa,CAAC,IAAI,EAAE,KAAK,CAAC;iBAC1C,CAAC,CAAC;QACP,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { execFile as execFileCallback } from \"node:child_process\";\nimport { lstat, readdir, realpath } from \"node:fs/promises\";\nimport { join, relative } from \"node:path\";\nimport { promisify } from \"node:util\";\nimport { CodexSecurityError, InvalidTargetError } from \"./errors.js\";\nimport type { OwnerFinding } from \"./suggest-owners.js\";\nimport {\n nullIfMissingFile,\n enclosingGitWorktreeRoot,\n gitMetadataDirectories,\n normalizeRepository,\n relativePathIsOutside,\n validatedGitEnvironment,\n} from \"./targets.js\";\nimport { resolveTrustedExecutable } from \"./trusted-executable.js\";\nimport {\n codeownersForPath,\n parseCodeowners,\n type CodeownerIdentity,\n} from \"./codeowners.js\";\n\nconst execFile = promisify(execFileCallback);\n\nexport interface OwnerIdentity {\n name: string;\n email: string;\n}\n\nexport interface OwnerEvidence {\n id: string;\n kind: \"source\" | \"blame\" | \"history\" | \"codeowners\";\n path: string;\n commit: string;\n /** Original blamed commit; blame citations keep commit at the checkout revision. */\n blameCommit?: string;\n startLine?: number;\n endLine?: number;\n rule?: string;\n matchedPath?: string;\n content: string;\n identityIndex: number | null;\n}\n\nexport interface OwnerContext {\n identities: OwnerIdentity[];\n evidence: OwnerEvidence[];\n limitations: string[];\n codeowner: CodeownerIdentity | null;\n}\n\n/** Read committed objects, so dirty files and source symlinks are never followed. */\nexport async function ownerRepository(\n repository: string,\n environment: NodeJS.ProcessEnv,\n signal?: AbortSignal,\n) {\n repository = await normalizeRepository(repository, signal);\n validatedGitEnvironment(environment);\n repository =\n (await enclosingGitWorktreeRoot(repository, signal, {\n requireIfPresent: true,\n })) ?? repository;\n const executable = await resolveTrustedExecutable(\n \"git\",\n environment,\n repository,\n );\n if (executable === null)\n throw new CodexSecurityError(\"Git is required to suggest owners.\");\n const run = async (cwd: string, args: string[], encoding: BufferEncoding) => {\n signal?.throwIfAborted();\n const { stdout } = await execFile(executable.executable, args, {\n cwd,\n env: { ...executable.environment, GIT_NO_LAZY_FETCH: \"1\" },\n signal,\n maxBuffer: Infinity,\n encoding: \"buffer\",\n });\n return stdout.toString(encoding);\n };\n const [gitDirectory, commonDirectory, ...objectDirectories] =\n await gitMetadataDirectories(repository, signal, {\n includeLocalObjects: true,\n });\n const metadataDirectories = [...new Set([gitDirectory, commonDirectory])];\n if (\n objectDirectories.some((path) =>\n metadataDirectories.every((root) =>\n relativePathIsOutside(relative(root, path)),\n ),\n )\n ) {\n throw new InvalidTargetError(\n \"Git objects are not bound to the selected checkout. Use a checkout that does not borrow external object stores.\",\n );\n }\n await requireBoundMetadata(metadataDirectories, objectDirectories, signal);\n // Blame otherwise reads an uncommitted .mailmap from the working directory.\n const gitOutput = (encoding: BufferEncoding, ...args: string[]) =>\n run(\n gitDirectory,\n [\n `--git-dir=${gitDirectory}`,\n \"--literal-pathspecs\",\n \"-c\",\n \"core.bare=true\",\n \"-c\",\n \"i18n.logOutputEncoding=UTF-8\",\n ...args,\n ],\n encoding,\n );\n const git = (...args: string[]) => gitOutput(\"utf8\", ...args);\n const revision = (await git(\"rev-parse\", \"--verify\", \"HEAD^{commit}\")).trim();\n const files = new Set(\n (await gitOutput(\"latin1\", \"ls-tree\", \"-r\", \"-z\", \"--full-tree\", revision))\n .split(\"\\0\")\n .filter((record) => /^100(?:644|755) blob /u.test(record))\n .map((record) => record.slice(record.indexOf(\"\\t\") + 1)),\n );\n const shallow =\n (await git(\"rev-parse\", \"--is-shallow-repository\")).trim() === \"true\";\n // Latin-1 keys preserve Git's filename bytes, including unrelated non-UTF-8 names.\n const hasFile = (path: string) =>\n path.isWellFormed() && files.has(Buffer.from(path).toString(\"latin1\"));\n const loadCodeowners = async () => {\n const path = [\".github/CODEOWNERS\", \"CODEOWNERS\", \"docs/CODEOWNERS\"].find(\n hasFile,\n );\n if (path === undefined) return null;\n const source = await git(\"cat-file\", \"blob\", `${revision}:${path}`);\n // GitHub requires CODEOWNERS to be under 3 MB.\n return {\n path,\n rules:\n Buffer.byteLength(source) >= 3_000_000 ? null : parseCodeowners(source),\n };\n };\n let codeowners: ReturnType<typeof loadCodeowners> | undefined;\n return {\n git,\n revision,\n hasFile,\n shallow,\n // Keep the load lazy so failures remain inside per-finding error handling.\n codeowners: () => (codeowners ??= loadCodeowners()),\n };\n}\n\n/** Neither references nor objects may link into another checkout. */\nasync function requireBoundMetadata(\n metadataDirectories: string[],\n objectDirectories: string[],\n signal?: AbortSignal,\n): Promise<void> {\n const pending = [\n ...objectDirectories,\n ...metadataDirectories.flatMap((directory) =>\n [\"HEAD\", \"refs\", \"packed-refs\", \"reftable\"].map((name) =>\n join(directory, name),\n ),\n ),\n ];\n const visited = new Set<string>();\n while (pending.length > 0) {\n signal?.throwIfAborted();\n const path = pending.pop()!;\n if (visited.has(path)) continue;\n visited.add(path);\n const entry = await lstat(path).catch(nullIfMissingFile);\n if (entry?.isSymbolicLink()) {\n const destination = await realpath(path);\n if (\n metadataDirectories.every((root) =>\n relativePathIsOutside(relative(root, destination)),\n )\n ) {\n throw new InvalidTargetError(\n \"Git metadata is not bound to the selected checkout. Select the intended checkout or repair its Git metadata.\",\n );\n }\n pending.push(destination);\n } else if (entry?.isDirectory()) {\n for (const name of await readdir(path)) pending.push(join(path, name));\n }\n }\n}\n\nexport async function collectOwnerEvidence(\n finding: OwnerFinding,\n repository: Awaited<ReturnType<typeof ownerRepository>>,\n): Promise<OwnerContext> {\n const { git, revision, hasFile, shallow } = repository;\n const context: OwnerContext = {\n identities: [],\n evidence: [],\n codeowner: null,\n limitations: [\n \"Git authors are not verified tracker accounts or proof of current employment.\",\n ],\n };\n if (shallow)\n context.limitations.push(\n \"This checkout has shallow history; earlier contributors may be missing.\",\n );\n const stale =\n finding.sourceRevision !== undefined && finding.sourceRevision !== revision;\n if (stale)\n context.limitations.push(\n \"The finding revision differs from HEAD; its line ranges were not used.\",\n );\n if (finding.locations.length === 0)\n context.limitations.push(\"No source locations were supplied.\");\n const identityIndex = (name: string, email: string) => {\n const index = context.identities.findIndex(\n (identity) => identity.email === email,\n );\n if (index !== -1) return index;\n return context.identities.push({ name, email }) - 1;\n };\n const add = (item: Omit<OwnerEvidence, \"id\">) => {\n context.evidence.push({ id: `e${context.evidence.length + 1}`, ...item });\n };\n const codeowners = await repository.codeowners();\n if (codeowners !== null) {\n if (codeowners.rules === null) {\n context.limitations.push(\n \"CODEOWNERS meets or exceeds GitHub's 3 MB file-size limit and was ignored.\",\n );\n } else {\n for (const { path } of finding.locations) {\n if (!hasFile(path)) continue;\n const rule = codeownersForPath(codeowners.rules, path);\n if (rule === undefined) continue;\n const owner = rule.owners[0];\n if (owner === undefined) continue;\n context.codeowner = owner;\n context.limitations.push(\n \"CODEOWNERS identities are declarations; their existence and repository access are not verified.\",\n );\n add({\n kind: \"codeowners\",\n path: codeowners.path,\n commit: revision,\n startLine: rule.line,\n endLine: rule.line,\n rule: rule.rule,\n matchedPath: path,\n content: rule.rule,\n identityIndex: null,\n });\n return context;\n }\n }\n }\n for (const path of new Set(finding.locations.map(({ path }) => path))) {\n if (!hasFile(path)) {\n context.limitations.push(`Not a regular file at HEAD: ${path}`);\n continue;\n }\n const source = await git(\"cat-file\", \"blob\", `${revision}:${path}`);\n if (!source || source.includes(\"\\0\")) {\n context.limitations.push(`Source is empty or binary: ${path}`);\n continue;\n }\n const lines = source.replace(/\\n$/u, \"\").split(\"\\n\");\n const locations = stale\n ? [{ path }]\n : finding.locations.filter((location) => location.path === path);\n for (const location of locations) {\n const start = location.startLine ?? 1;\n if (start > lines.length) {\n context.limitations.push(\n `Finding line is outside the committed file: ${path}:${start}`,\n );\n continue;\n }\n // Include surrounding code for the model, but attribute only the affected lines.\n const end = Math.min(\n location.endLine ?? location.startLine ?? lines.length,\n lines.length,\n );\n const excerptStart = Math.max(1, start - 10);\n const excerptEnd = Math.min(lines.length, end + 10);\n add({\n kind: \"source\",\n path,\n commit: revision,\n startLine: excerptStart,\n endLine: excerptEnd,\n content: lines\n .slice(excerptStart - 1, excerptEnd)\n .map((line, index) => `${excerptStart + index}: ${line}`)\n .join(\"\\n\"),\n identityIndex: null,\n });\n const blame = await git(\n \"blame\",\n \"--line-porcelain\",\n \"--no-textconv\",\n \"--ignore-revs-file=\",\n \"-L\",\n `${start},${end}`,\n revision,\n \"--\",\n path,\n );\n let commit = \"\",\n name = \"\",\n email = \"\",\n line = 0;\n for (const value of blame.split(\"\\n\")) {\n const header = /^([a-f0-9]{40,64}) \\d+ (\\d+)(?: \\d+)?$/u.exec(value);\n if (header) {\n commit = header[1]!;\n line = Number(header[2]);\n } else if (value.startsWith(\"author \")) name = value.slice(7);\n else if (value.startsWith(\"author-mail <\")) email = value.slice(13, -1);\n else if (value.startsWith(\"\\t\") && email.trim()) {\n const index = identityIndex(name, email);\n const previous = context.evidence.at(-1);\n if (\n previous?.kind === \"blame\" &&\n previous.blameCommit === commit &&\n previous.identityIndex === index &&\n previous.endLine === line - 1\n ) {\n previous.endLine = line;\n } else {\n add({\n kind: \"blame\",\n path,\n commit: revision,\n blameCommit: commit,\n startLine: line,\n endLine: line,\n content: `Authored in ${commit}.`,\n identityIndex: index,\n });\n }\n }\n }\n }\n const history = (\n await git(\n \"log\",\n \"--no-use-mailmap\",\n \"--no-show-signature\",\n \"--no-notes\",\n \"--no-decorate\",\n \"--format=%H%x00%an%x00%ae%x00%aI%x00%s\",\n \"-z\",\n revision,\n \"--\",\n path,\n )\n ).split(\"\\0\");\n for (let index = 0; index + 4 < history.length; index += 5) {\n const [commit, name, email, date, subject] = history.slice(\n index,\n index + 5,\n ) as [string, string, string, string, string];\n if (email.trim())\n add({\n kind: \"history\",\n path,\n commit,\n content: `${date}: ${subject}`,\n identityIndex: identityIndex(name, email),\n });\n }\n }\n return context;\n}\n"]}
|
package/dist/patch-tui.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patch-tui.d.ts","sourceRoot":"","sources":["../src/patch-tui.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAuB,MAAM,aAAa,CAAC;AAEhE,QAAA,MAAM,eAAe;aACnB,QAAQ,EAAE,WAAW;aACrB,IAAI,EAAE,KAAK;aACX,MAAM,EAAE,QAAQ;aAChB,GAAG,EAAE,YAAY;CACT,CAAC;AAEX,KAAK,aAAa,GAAG,MAAM,OAAO,eAAe,CAAC;AAgClD,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,aAAa,CAAC;IACxB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,UAAU,aAAa;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAC;IAC7B,UAAU,CAAC,SAAS,EAAE,cAAc,GAAG,IAAI,GAAG,IAAI,CAAC;IACnD,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;
|
|
1
|
+
{"version":3,"file":"patch-tui.d.ts","sourceRoot":"","sources":["../src/patch-tui.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAuB,MAAM,aAAa,CAAC;AAEhE,QAAA,MAAM,eAAe;aACnB,QAAQ,EAAE,WAAW;aACrB,IAAI,EAAE,KAAK;aACX,MAAM,EAAE,QAAQ;aAChB,GAAG,EAAE,YAAY;CACT,CAAC;AAEX,KAAK,aAAa,GAAG,MAAM,OAAO,eAAe,CAAC;AAgClD,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,aAAa,CAAC;IACxB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,UAAU,aAAa;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAC;IAC7B,UAAU,CAAC,SAAS,EAAE,cAAc,GAAG,IAAI,GAAG,IAAI,CAAC;IACnD,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAgTD,wBAAgB,QAAQ,CAAC,EACvB,UAAU,EACV,QAAQ,EACR,UAAU,EACV,KAA6C,GAC9C,EAAE,aAAa,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CA4TnC;AAED,wBAAsB,WAAW,CAC/B,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,SAAS,OAAO,EAAE,EAC5B,EACE,KAAqB,EACrB,MAAuB,EACvB,KAAK,GACN,GAAE;IACD,KAAK,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC,WAAW,CAAC;IAC5B,KAAK,CAAC,EAAE,OAAO,CAAC;CACZ,GACL,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAyBhC"}
|
package/dist/patch-tui.js
CHANGED
|
@@ -127,6 +127,8 @@ function locationSource(repository, location) {
|
|
|
127
127
|
return [];
|
|
128
128
|
}
|
|
129
129
|
const source = readFileSync(path, "utf8").split(/\r?\n/u);
|
|
130
|
+
if (source.at(-1) === "")
|
|
131
|
+
source.pop();
|
|
130
132
|
const first = Math.max(0, location.startLine - 4);
|
|
131
133
|
const last = Math.min(source.length, (location.endLine ?? location.startLine) + 3);
|
|
132
134
|
return numberedCode(source.slice(first, last), first + 1, location);
|