@openai/codex-security 0.1.19 → 0.1.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 +585 -833
- package/_bundled_plugin/.codex-plugin/plugin.json +1 -1
- 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/schemas/patch-risk-assessment.schema.json +243 -0
- package/_bundled_plugin/scripts/finalize_scan_contract.py +92 -11
- package/_bundled_plugin/scripts/launch_codex_security_mcp +0 -0
- package/_bundled_plugin/scripts/workbench_cli.py +5 -1
- package/_bundled_plugin/scripts/workbench_db.py +53 -0
- package/_bundled_plugin/skills/assess-patch-risk/SKILL.md +88 -0
- package/_bundled_plugin/skills/assess-patch-risk/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/assess-patch-risk/references/risk-rubric.md +76 -0
- package/_bundled_plugin/skills/assess-patch-risk/scripts/validate_patch_risk_assessment.py +163 -0
- package/_bundled_plugin/skills/fix-finding/SKILL.md +16 -48
- package/dist/api.d.ts +1 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +14 -18
- package/dist/api.js.map +1 -1
- package/dist/bulk-scan-discovery.d.ts +8 -0
- package/dist/bulk-scan-discovery.d.ts.map +1 -1
- package/dist/bulk-scan-discovery.js +21 -25
- package/dist/bulk-scan-discovery.js.map +1 -1
- package/dist/cli.d.ts +27 -4
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +561 -114
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.d.ts +5 -1
- package/dist/cloud-publish.d.ts.map +1 -1
- package/dist/cloud-publish.js +323 -21
- package/dist/cloud-publish.js.map +1 -1
- package/dist/component-plan.d.ts.map +1 -1
- package/dist/component-plan.js +5 -1
- package/dist/component-plan.js.map +1 -1
- package/dist/github.d.ts +161 -0
- package/dist/github.d.ts.map +1 -0
- package/dist/github.js +158 -0
- package/dist/github.js.map +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/linear.d.ts +5 -0
- package/dist/linear.d.ts.map +1 -1
- package/dist/linear.js +8 -3
- package/dist/linear.js.map +1 -1
- package/dist/publication-events.d.ts +40 -13
- package/dist/publication-events.d.ts.map +1 -1
- package/dist/publication-events.js +218 -104
- package/dist/publication-events.js.map +1 -1
- package/dist/publication-store.d.ts +1 -0
- package/dist/publication-store.d.ts.map +1 -1
- package/dist/publication-store.js +73 -26
- package/dist/publication-store.js.map +1 -1
- package/dist/publication.d.ts +5 -0
- package/dist/publication.d.ts.map +1 -1
- package/dist/publication.js +12 -0
- package/dist/publication.js.map +1 -1
- package/dist/publish.d.ts +50 -1
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +640 -256
- package/dist/publish.js.map +1 -1
- package/dist/runtime.d.ts +0 -3
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +258 -185
- package/dist/runtime.js.map +1 -1
- package/dist/scan-comparison.d.ts +3 -0
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +6 -1
- package/dist/scan-comparison.js.map +1 -1
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +1 -0
- package/dist/targets.js.map +1 -1
- package/dist/thread-source.d.ts +8 -0
- package/dist/thread-source.d.ts.map +1 -0
- package/dist/thread-source.js +7 -0
- package/dist/thread-source.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +8 -5
package/dist/github.d.ts
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { Octokit } from "@octokit/core";
|
|
2
|
+
type GitHubAlert = Awaited<ReturnType<typeof fetchGitHubAlert>>;
|
|
3
|
+
export declare const GITHUB_ALERT_STATES: readonly ["open", "closed", "dismissed", "fixed", "all"];
|
|
4
|
+
export interface GitHubCodeScanningImportOptions {
|
|
5
|
+
/** GitHub repository in OWNER/REPO form. */
|
|
6
|
+
repository: string;
|
|
7
|
+
/** Exact alert numbers, regardless of state. Omit to list matching alerts. */
|
|
8
|
+
alertNumbers?: readonly number[];
|
|
9
|
+
/** State used when listing alerts (default: open). */
|
|
10
|
+
state?: (typeof GITHUB_ALERT_STATES)[number];
|
|
11
|
+
/** Git reference to inspect; omitted lists the default branch. */
|
|
12
|
+
ref?: string;
|
|
13
|
+
/** Defaults to GH_HOST or github.com. */
|
|
14
|
+
githubHost?: string;
|
|
15
|
+
/** Omit to use the authenticated GitHub CLI, including its token environment. */
|
|
16
|
+
githubToken?: string;
|
|
17
|
+
signal?: AbortSignal;
|
|
18
|
+
}
|
|
19
|
+
export interface ImportedGitHubCodeScanningAlert {
|
|
20
|
+
source: "github-code-scanning";
|
|
21
|
+
repository: string;
|
|
22
|
+
number: number;
|
|
23
|
+
url: string;
|
|
24
|
+
/** Upstream evidence, not a validated or sealed Codex Security finding. */
|
|
25
|
+
alert: GitHubAlert;
|
|
26
|
+
}
|
|
27
|
+
interface GitHubImportDependencies {
|
|
28
|
+
environment?: NodeJS.ProcessEnv;
|
|
29
|
+
currentDirectory?: string;
|
|
30
|
+
createGitHub?: (host: string, signal?: AbortSignal) => Promise<Octokit>;
|
|
31
|
+
}
|
|
32
|
+
export declare function createAuthenticatedGitHub(host: string, options?: {
|
|
33
|
+
environment?: NodeJS.ProcessEnv;
|
|
34
|
+
currentDirectory?: string;
|
|
35
|
+
token?: string;
|
|
36
|
+
signal?: AbortSignal;
|
|
37
|
+
}): Promise<Octokit>;
|
|
38
|
+
export declare function importGitHubCodeScanningAlerts(options: GitHubCodeScanningImportOptions, dependencies?: GitHubImportDependencies): Promise<ImportedGitHubCodeScanningAlert[]>;
|
|
39
|
+
declare function fetchGitHubAlert(github: Octokit, owner: string, repo: string, alertNumber: number, signal?: AbortSignal): Promise<{
|
|
40
|
+
number: number;
|
|
41
|
+
created_at: string;
|
|
42
|
+
updated_at?: string;
|
|
43
|
+
url: string;
|
|
44
|
+
html_url: string;
|
|
45
|
+
instances_url: string;
|
|
46
|
+
state: "fixed" | "open" | "dismissed" | null;
|
|
47
|
+
fixed_at?: string | null;
|
|
48
|
+
dismissed_by: {
|
|
49
|
+
name?: string | null;
|
|
50
|
+
email?: string | null;
|
|
51
|
+
login: string;
|
|
52
|
+
id: number;
|
|
53
|
+
node_id: string;
|
|
54
|
+
avatar_url: string;
|
|
55
|
+
gravatar_id: string | null;
|
|
56
|
+
url: string;
|
|
57
|
+
html_url: string;
|
|
58
|
+
followers_url: string;
|
|
59
|
+
following_url: string;
|
|
60
|
+
gists_url: string;
|
|
61
|
+
starred_url: string;
|
|
62
|
+
subscriptions_url: string;
|
|
63
|
+
organizations_url: string;
|
|
64
|
+
repos_url: string;
|
|
65
|
+
events_url: string;
|
|
66
|
+
received_events_url: string;
|
|
67
|
+
type: string;
|
|
68
|
+
site_admin: boolean;
|
|
69
|
+
starred_at?: string;
|
|
70
|
+
user_view_type?: string;
|
|
71
|
+
} | null;
|
|
72
|
+
dismissed_at: string | null;
|
|
73
|
+
dismissed_reason: "false positive" | "won't fix" | "used in tests" | null;
|
|
74
|
+
dismissed_comment?: string | null;
|
|
75
|
+
rule: {
|
|
76
|
+
id?: string | null;
|
|
77
|
+
name?: string;
|
|
78
|
+
severity?: "none" | "note" | "warning" | "error" | null;
|
|
79
|
+
security_severity_level?: "low" | "medium" | "high" | "critical" | null;
|
|
80
|
+
description?: string;
|
|
81
|
+
full_description?: string;
|
|
82
|
+
tags?: string[] | null;
|
|
83
|
+
help?: string | null;
|
|
84
|
+
help_uri?: string | null;
|
|
85
|
+
};
|
|
86
|
+
tool: {
|
|
87
|
+
name?: string;
|
|
88
|
+
version?: string | null;
|
|
89
|
+
guid?: string | null;
|
|
90
|
+
};
|
|
91
|
+
most_recent_instance: {
|
|
92
|
+
ref?: string;
|
|
93
|
+
analysis_key?: string;
|
|
94
|
+
environment?: string;
|
|
95
|
+
category?: string;
|
|
96
|
+
state?: "fixed" | "open" | "dismissed" | null;
|
|
97
|
+
commit_sha?: string;
|
|
98
|
+
message?: {
|
|
99
|
+
text?: string;
|
|
100
|
+
};
|
|
101
|
+
location?: {
|
|
102
|
+
path?: string;
|
|
103
|
+
start_line?: number;
|
|
104
|
+
end_line?: number;
|
|
105
|
+
start_column?: number;
|
|
106
|
+
end_column?: number;
|
|
107
|
+
};
|
|
108
|
+
html_url?: string;
|
|
109
|
+
classifications?: ("source" | "generated" | "test" | "library" | null)[];
|
|
110
|
+
};
|
|
111
|
+
dismissal_approved_by?: {
|
|
112
|
+
name?: string | null;
|
|
113
|
+
email?: string | null;
|
|
114
|
+
login: string;
|
|
115
|
+
id: number;
|
|
116
|
+
node_id: string;
|
|
117
|
+
avatar_url: string;
|
|
118
|
+
gravatar_id: string | null;
|
|
119
|
+
url: string;
|
|
120
|
+
html_url: string;
|
|
121
|
+
followers_url: string;
|
|
122
|
+
following_url: string;
|
|
123
|
+
gists_url: string;
|
|
124
|
+
starred_url: string;
|
|
125
|
+
subscriptions_url: string;
|
|
126
|
+
organizations_url: string;
|
|
127
|
+
repos_url: string;
|
|
128
|
+
events_url: string;
|
|
129
|
+
received_events_url: string;
|
|
130
|
+
type: string;
|
|
131
|
+
site_admin: boolean;
|
|
132
|
+
starred_at?: string;
|
|
133
|
+
user_view_type?: string;
|
|
134
|
+
} | null;
|
|
135
|
+
assignees?: {
|
|
136
|
+
name?: string | null;
|
|
137
|
+
email?: string | null;
|
|
138
|
+
login: string;
|
|
139
|
+
id: number;
|
|
140
|
+
node_id: string;
|
|
141
|
+
avatar_url: string;
|
|
142
|
+
gravatar_id: string | null;
|
|
143
|
+
url: string;
|
|
144
|
+
html_url: string;
|
|
145
|
+
followers_url: string;
|
|
146
|
+
following_url: string;
|
|
147
|
+
gists_url: string;
|
|
148
|
+
starred_url: string;
|
|
149
|
+
subscriptions_url: string;
|
|
150
|
+
organizations_url: string;
|
|
151
|
+
repos_url: string;
|
|
152
|
+
events_url: string;
|
|
153
|
+
received_events_url: string;
|
|
154
|
+
type: string;
|
|
155
|
+
site_admin: boolean;
|
|
156
|
+
starred_at?: string;
|
|
157
|
+
user_view_type?: string;
|
|
158
|
+
}[];
|
|
159
|
+
}>;
|
|
160
|
+
export {};
|
|
161
|
+
//# sourceMappingURL=github.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"github.d.ts","sourceRoot":"","sources":["../src/github.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAKxC,KAAK,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAC,CAAC;AAEhE,eAAO,MAAM,mBAAmB,0DAMtB,CAAC;AAEX,MAAM,WAAW,+BAA+B;IAC9C,4CAA4C;IAC5C,UAAU,EAAE,MAAM,CAAC;IACnB,8EAA8E;IAC9E,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,sDAAsD;IACtD,KAAK,CAAC,EAAE,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;IAC7C,kEAAkE;IAClE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,yCAAyC;IACzC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iFAAiF;IACjF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,+BAA+B;IAC9C,MAAM,EAAE,sBAAsB,CAAC;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,2EAA2E;IAC3E,KAAK,EAAE,WAAW,CAAC;CACpB;AAED,UAAU,wBAAwB;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IAChC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CACzE;AAED,wBAAsB,yBAAyB,CAC7C,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE;IACP,WAAW,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IAChC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,WAAW,CAAC;CACjB,GACL,OAAO,CAAC,OAAO,CAAC,CAmClB;AAED,wBAAsB,8BAA8B,CAClD,OAAO,EAAE,+BAA+B,EACxC,YAAY,GAAE,wBAA6B,GAC1C,OAAO,CAAC,+BAA+B,EAAE,CAAC,CAyI5C;AAED,iBAAe,gBAAgB,CAC7B,MAAM,EAAE,OAAO,EACf,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBAasvi1B,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAD5wi1B"}
|
package/dist/github.js
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { execFile as execFileCallback } from "node:child_process";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
import { Octokit } from "@octokit/core";
|
|
4
|
+
import { CodexSecurityError } from "./errors.js";
|
|
5
|
+
import { resolveTrustedExecutable } from "./trusted-executable.js";
|
|
6
|
+
const execFile = promisify(execFileCallback);
|
|
7
|
+
export const GITHUB_ALERT_STATES = [
|
|
8
|
+
"open",
|
|
9
|
+
"closed",
|
|
10
|
+
"dismissed",
|
|
11
|
+
"fixed",
|
|
12
|
+
"all",
|
|
13
|
+
];
|
|
14
|
+
export async function createAuthenticatedGitHub(host, options = {}) {
|
|
15
|
+
options.signal?.throwIfAborted();
|
|
16
|
+
let token = options.token;
|
|
17
|
+
if (token === undefined) {
|
|
18
|
+
const trusted = await resolveTrustedExecutable("gh", options.environment ?? process.env, options.currentDirectory ?? process.cwd());
|
|
19
|
+
if (trusted === null) {
|
|
20
|
+
throw new CodexSecurityError("GitHub CLI is required. Install gh and sign in first.");
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
const { stdout } = await execFile(trusted.executable, ["auth", "token", "--hostname", host], { env: trusted.environment, signal: options.signal });
|
|
24
|
+
token = stdout.trim();
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
options.signal?.throwIfAborted();
|
|
28
|
+
throw new CodexSecurityError("GitHub sign-in is required. Run 'gh auth login' first.");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (token.trim().length === 0) {
|
|
32
|
+
throw new CodexSecurityError("GitHub access token must not be empty.");
|
|
33
|
+
}
|
|
34
|
+
return new Octokit({
|
|
35
|
+
auth: token,
|
|
36
|
+
...(host === "github.com" ? {} : { baseUrl: `https://${host}/api/v3` }),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
export async function importGitHubCodeScanningAlerts(options, dependencies = {}) {
|
|
40
|
+
options.signal?.throwIfAborted();
|
|
41
|
+
const repository = options.repository.trim();
|
|
42
|
+
const parts = /^([a-z0-9_.-]+)\/([a-z0-9_.-]+)$/iu.exec(repository);
|
|
43
|
+
if (parts === null ||
|
|
44
|
+
parts.slice(1).some((part) => /^\.{1,2}$/u.test(part))) {
|
|
45
|
+
throw new CodexSecurityError("GitHub repository must be OWNER/REPO.");
|
|
46
|
+
}
|
|
47
|
+
const owner = parts[1];
|
|
48
|
+
const repo = parts[2];
|
|
49
|
+
const numbers = [...new Set(options.alertNumbers ?? [])];
|
|
50
|
+
if (numbers.some((number) => !Number.isSafeInteger(number) || number < 1)) {
|
|
51
|
+
throw new CodexSecurityError("GitHub alert numbers must be positive integers.");
|
|
52
|
+
}
|
|
53
|
+
const state = options.state ?? "open";
|
|
54
|
+
if (!GITHUB_ALERT_STATES.includes(state)) {
|
|
55
|
+
throw new CodexSecurityError("GitHub alert state is invalid.");
|
|
56
|
+
}
|
|
57
|
+
if (numbers.length > 0 && state !== "open") {
|
|
58
|
+
throw new CodexSecurityError("--github-state only filters lists; use it without --github-alert.");
|
|
59
|
+
}
|
|
60
|
+
const ref = options.ref?.trim();
|
|
61
|
+
if (ref === "") {
|
|
62
|
+
throw new CodexSecurityError("GitHub reference must not be empty.");
|
|
63
|
+
}
|
|
64
|
+
const environment = dependencies.environment ?? process.env;
|
|
65
|
+
const host = options.githubHost?.trim() ??
|
|
66
|
+
(environment["GH_HOST"]?.trim() || "github.com");
|
|
67
|
+
if (host.length === 0) {
|
|
68
|
+
throw new CodexSecurityError("GitHub host must not be empty.");
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
const github = dependencies.createGitHub
|
|
72
|
+
? await dependencies.createGitHub(host, options.signal)
|
|
73
|
+
: await createAuthenticatedGitHub(host, {
|
|
74
|
+
token: options.githubToken,
|
|
75
|
+
environment,
|
|
76
|
+
currentDirectory: dependencies.currentDirectory,
|
|
77
|
+
signal: options.signal,
|
|
78
|
+
});
|
|
79
|
+
const selected = new Map();
|
|
80
|
+
if (numbers.length === 0 || ref !== undefined) {
|
|
81
|
+
let page = 1;
|
|
82
|
+
while (true) {
|
|
83
|
+
options.signal?.throwIfAborted();
|
|
84
|
+
// Octokit's list route omits GitHub's "closed" state.
|
|
85
|
+
const response = await github.request({
|
|
86
|
+
method: "GET",
|
|
87
|
+
url: "/repos/{owner}/{repo}/code-scanning/alerts",
|
|
88
|
+
owner,
|
|
89
|
+
repo,
|
|
90
|
+
per_page: 100,
|
|
91
|
+
page,
|
|
92
|
+
ref,
|
|
93
|
+
state: numbers.length > 0 || state === "all" ? undefined : state,
|
|
94
|
+
request: { signal: options.signal, redirect: "error" },
|
|
95
|
+
});
|
|
96
|
+
for (const alert of response.data) {
|
|
97
|
+
if (numbers.length === 0 || numbers.includes(alert.number)) {
|
|
98
|
+
selected.set(alert.number, alert.most_recent_instance);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (!response.headers.link?.includes('rel="next"') ||
|
|
102
|
+
(numbers.length > 0 && selected.size === numbers.length))
|
|
103
|
+
break;
|
|
104
|
+
page += 1;
|
|
105
|
+
}
|
|
106
|
+
if (numbers.some((number) => !selected.has(number))) {
|
|
107
|
+
throw new CodexSecurityError("One or more selected GitHub alerts were not found on the requested reference.");
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const alerts = [];
|
|
111
|
+
for (const number of numbers.length > 0 ? numbers : selected.keys()) {
|
|
112
|
+
options.signal?.throwIfAborted();
|
|
113
|
+
const alert = await fetchGitHubAlert(github, owner, repo, number, options.signal);
|
|
114
|
+
// Detail requests use the default branch; retain the listed ref's evidence.
|
|
115
|
+
const instance = selected.get(number);
|
|
116
|
+
alerts.push({
|
|
117
|
+
source: "github-code-scanning",
|
|
118
|
+
repository,
|
|
119
|
+
number,
|
|
120
|
+
url: alert.html_url,
|
|
121
|
+
alert: instance === undefined
|
|
122
|
+
? alert
|
|
123
|
+
: { ...alert, most_recent_instance: instance },
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
return alerts;
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
options.signal?.throwIfAborted();
|
|
130
|
+
if (error instanceof CodexSecurityError)
|
|
131
|
+
throw error;
|
|
132
|
+
const status = typeof error === "object" && error !== null && "status" in error
|
|
133
|
+
? error.status
|
|
134
|
+
: undefined;
|
|
135
|
+
if (status === 401)
|
|
136
|
+
throw new CodexSecurityError("GitHub authentication failed.");
|
|
137
|
+
if (status === 403) {
|
|
138
|
+
throw new CodexSecurityError("GitHub denied code scanning access. Check repository permissions, code scanning availability, and API rate limits.");
|
|
139
|
+
}
|
|
140
|
+
if (status === 404) {
|
|
141
|
+
throw new CodexSecurityError("GitHub repository or code scanning alert was not found or is not accessible.");
|
|
142
|
+
}
|
|
143
|
+
if (status === 429)
|
|
144
|
+
throw new CodexSecurityError("GitHub request was rate limited. Wait and retry.");
|
|
145
|
+
// Octokit errors can contain credential-bearing request headers.
|
|
146
|
+
throw new CodexSecurityError(`GitHub code scanning request failed${typeof status === "number" ? ` (HTTP ${status})` : ""}.`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
async function fetchGitHubAlert(github, owner, repo, alertNumber, signal) {
|
|
150
|
+
const response = await github.request("GET /repos/{owner}/{repo}/code-scanning/alerts/{alert_number}", {
|
|
151
|
+
owner,
|
|
152
|
+
repo,
|
|
153
|
+
alert_number: alertNumber,
|
|
154
|
+
request: { signal, redirect: "error" },
|
|
155
|
+
});
|
|
156
|
+
return response.data;
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=github.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"github.js","sourceRoot":"","sources":["../src/github.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AAEnE,MAAM,QAAQ,GAAG,SAAS,CAAC,gBAAgB,CAAC,CAAC;AAG7C,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,MAAM;IACN,QAAQ;IACR,WAAW;IACX,OAAO;IACP,KAAK;CACG,CAAC;AAiCX,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC7C,IAAY,EACZ,UAKI,EAAE;IAEN,OAAO,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC;IACjC,IAAI,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC1B,IA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GAAG,CAC/F,CAAC;IACJ,CAAC;AACH,CAAC;AAED,KAAK,UAAU,gBAAgB,CAC7B,MAAe,EACf,KAAa,EACb,IAAY,EACZ,WAAmB,EACnB,MAAoB;IAEpB,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,OAAO,CACnC,+DAA+D,EAC/D;QACE,KAAK;QACL,IAAI;QACJ,YAAY,EAAE,WAAW;QACzB,OAAO,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE;KACvC,CACF,CAAC;IACF,OAAO,QAAQ,CAAC,IAAI,CAAC;AACvB,CAAC","sourcesContent":["import { execFile as execFileCallback } from \"node:child_process\";\nimport { promisify } from \"node:util\";\nimport { Octokit } from \"@octokit/core\";\nimport { CodexSecurityError } from \"./errors.js\";\nimport { resolveTrustedExecutable } from \"./trusted-executable.js\";\n\nconst execFile = promisify(execFileCallback);\ntype GitHubAlert = Awaited<ReturnType<typeof fetchGitHubAlert>>;\n\nexport const GITHUB_ALERT_STATES = [\n \"open\",\n \"closed\",\n \"dismissed\",\n \"fixed\",\n \"all\",\n] as const;\n\nexport interface GitHubCodeScanningImportOptions {\n /** GitHub repository in OWNER/REPO form. */\n repository: string;\n /** Exact alert numbers, regardless of state. Omit to list matching alerts. */\n alertNumbers?: readonly number[];\n /** State used when listing alerts (default: open). */\n state?: (typeof GITHUB_ALERT_STATES)[number];\n /** Git reference to inspect; omitted lists the default branch. */\n ref?: string;\n /** Defaults to GH_HOST or github.com. */\n githubHost?: string;\n /** Omit to use the authenticated GitHub CLI, including its token environment. */\n githubToken?: string;\n signal?: AbortSignal;\n}\n\nexport interface ImportedGitHubCodeScanningAlert {\n source: \"github-code-scanning\";\n repository: string;\n number: number;\n url: string;\n /** Upstream evidence, not a validated or sealed Codex Security finding. */\n alert: GitHubAlert;\n}\n\ninterface GitHubImportDependencies {\n environment?: NodeJS.ProcessEnv;\n currentDirectory?: string;\n createGitHub?: (host: string, signal?: AbortSignal) => Promise<Octokit>;\n}\n\nexport async function createAuthenticatedGitHub(\n host: string,\n options: {\n environment?: NodeJS.ProcessEnv;\n currentDirectory?: string;\n token?: string;\n signal?: AbortSignal;\n } = {},\n): Promise<Octokit> {\n options.signal?.throwIfAborted();\n let token = options.token;\n if (token === undefined) {\n const trusted = await resolveTrustedExecutable(\n \"gh\",\n options.environment ?? process.env,\n options.currentDirectory ?? process.cwd(),\n );\n if (trusted === null) {\n throw new CodexSecurityError(\n \"GitHub CLI is required. Install gh and sign in first.\",\n );\n }\n try {\n const { stdout } = await execFile(\n trusted.executable,\n [\"auth\", \"token\", \"--hostname\", host],\n { env: trusted.environment, signal: options.signal },\n );\n token = stdout.trim();\n } catch {\n options.signal?.throwIfAborted();\n throw new CodexSecurityError(\n \"GitHub sign-in is required. Run 'gh auth login' first.\",\n );\n }\n }\n if (token.trim().length === 0) {\n throw new CodexSecurityError(\"GitHub access token must not be empty.\");\n }\n return new Octokit({\n auth: token,\n ...(host === \"github.com\" ? {} : { baseUrl: `https://${host}/api/v3` }),\n });\n}\n\nexport async function importGitHubCodeScanningAlerts(\n options: GitHubCodeScanningImportOptions,\n dependencies: GitHubImportDependencies = {},\n): Promise<ImportedGitHubCodeScanningAlert[]> {\n options.signal?.throwIfAborted();\n const repository = options.repository.trim();\n const parts = /^([a-z0-9_.-]+)\\/([a-z0-9_.-]+)$/iu.exec(repository);\n if (\n parts === null ||\n parts.slice(1).some((part) => /^\\.{1,2}$/u.test(part))\n ) {\n throw new CodexSecurityError(\"GitHub repository must be OWNER/REPO.\");\n }\n const owner = parts[1]!;\n const repo = parts[2]!;\n const numbers = [...new Set(options.alertNumbers ?? [])];\n if (numbers.some((number) => !Number.isSafeInteger(number) || number < 1)) {\n throw new CodexSecurityError(\n \"GitHub alert numbers must be positive integers.\",\n );\n }\n const state = options.state ?? \"open\";\n if (!GITHUB_ALERT_STATES.includes(state)) {\n throw new CodexSecurityError(\"GitHub alert state is invalid.\");\n }\n if (numbers.length > 0 && state !== \"open\") {\n throw new CodexSecurityError(\n \"--github-state only filters lists; use it without --github-alert.\",\n );\n }\n const ref = options.ref?.trim();\n if (ref === \"\") {\n throw new CodexSecurityError(\"GitHub reference must not be empty.\");\n }\n const environment = dependencies.environment ?? process.env;\n const host =\n options.githubHost?.trim() ??\n (environment[\"GH_HOST\"]?.trim() || \"github.com\");\n if (host.length === 0) {\n throw new CodexSecurityError(\"GitHub host must not be empty.\");\n }\n\n try {\n const github = dependencies.createGitHub\n ? await dependencies.createGitHub(host, options.signal)\n : await createAuthenticatedGitHub(host, {\n token: options.githubToken,\n environment,\n currentDirectory: dependencies.currentDirectory,\n signal: options.signal,\n });\n const selected = new Map<number, GitHubAlert[\"most_recent_instance\"]>();\n if (numbers.length === 0 || ref !== undefined) {\n let page = 1;\n while (true) {\n options.signal?.throwIfAborted();\n // Octokit's list route omits GitHub's \"closed\" state.\n const response = await github.request<\n Pick<GitHubAlert, \"number\" | \"most_recent_instance\">[]\n >({\n method: \"GET\",\n url: \"/repos/{owner}/{repo}/code-scanning/alerts\",\n owner,\n repo,\n per_page: 100,\n page,\n ref,\n state: numbers.length > 0 || state === \"all\" ? undefined : state,\n request: { signal: options.signal, redirect: \"error\" },\n });\n for (const alert of response.data) {\n if (numbers.length === 0 || numbers.includes(alert.number)) {\n selected.set(alert.number, alert.most_recent_instance);\n }\n }\n if (\n !response.headers.link?.includes('rel=\"next\"') ||\n (numbers.length > 0 && selected.size === numbers.length)\n )\n break;\n page += 1;\n }\n if (numbers.some((number) => !selected.has(number))) {\n throw new CodexSecurityError(\n \"One or more selected GitHub alerts were not found on the requested reference.\",\n );\n }\n }\n const alerts: ImportedGitHubCodeScanningAlert[] = [];\n for (const number of numbers.length > 0 ? numbers : selected.keys()) {\n options.signal?.throwIfAborted();\n const alert = await fetchGitHubAlert(\n github,\n owner,\n repo,\n number,\n options.signal,\n );\n // Detail requests use the default branch; retain the listed ref's evidence.\n const instance = selected.get(number);\n alerts.push({\n source: \"github-code-scanning\",\n repository,\n number,\n url: alert.html_url,\n alert:\n instance === undefined\n ? alert\n : { ...alert, most_recent_instance: instance },\n });\n }\n return alerts;\n } catch (error) {\n options.signal?.throwIfAborted();\n if (error instanceof CodexSecurityError) throw error;\n const status =\n typeof error === \"object\" && error !== null && \"status\" in error\n ? error.status\n : undefined;\n if (status === 401)\n throw new CodexSecurityError(\"GitHub authentication failed.\");\n if (status === 403) {\n throw new CodexSecurityError(\n \"GitHub denied code scanning access. Check repository permissions, code scanning availability, and API rate limits.\",\n );\n }\n if (status === 404) {\n throw new CodexSecurityError(\n \"GitHub repository or code scanning alert was not found or is not accessible.\",\n );\n }\n if (status === 429)\n throw new CodexSecurityError(\n \"GitHub request was rate limited. Wait and retry.\",\n );\n // Octokit errors can contain credential-bearing request headers.\n throw new CodexSecurityError(\n `GitHub code scanning request failed${typeof status === \"number\" ? ` (HTTP ${status})` : \"\"}.`,\n );\n }\n}\n\nasync function fetchGitHubAlert(\n github: Octokit,\n owner: string,\n repo: string,\n alertNumber: number,\n signal?: AbortSignal,\n) {\n const response = await github.request(\n \"GET /repos/{owner}/{repo}/code-scanning/alerts/{alert_number}\",\n {\n owner,\n repo,\n alert_number: alertNumber,\n request: { signal, redirect: \"error\" },\n },\n );\n return response.data;\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -18,8 +18,10 @@ export type { CodexSecurityConfig, JsonObject, JsonValue } from "./config.js";
|
|
|
18
18
|
export { loadContract, requireScanFile } from "./contract.js";
|
|
19
19
|
export type { LoadedContract, ScanExpectation } from "./contract.js";
|
|
20
20
|
export type * from "./models.js";
|
|
21
|
-
export { publishScan } from "./publish.js";
|
|
22
|
-
export
|
|
21
|
+
export { checkScanPublication, publishScan } from "./publish.js";
|
|
22
|
+
export { importGitHubCodeScanningAlerts } from "./github.js";
|
|
23
|
+
export type { GitHubCodeScanningImportOptions, ImportedGitHubCodeScanningAlert, } from "./github.js";
|
|
24
|
+
export type { CheckScanPublicationOptions, CheckScanPublicationResult, PublishScanOptions, PublishScanProgress, PublishScanResult, } from "./publish.js";
|
|
23
25
|
export { ScanResult } from "./result.js";
|
|
24
26
|
export type { RepositoryFinding, ScanResultOptions, TurnResultMetadata, } from "./result.js";
|
|
25
27
|
export { bootstrapPlugin, bundledPluginRoot, cleanupSdkDirectory, createIsolatedHome, createMarketplace, extractPluginZip, importAmbientAuth, MARKETPLACE_NAME, pluginExecutionEnvironment, pluginMetadata, PLUGIN_NAME, prepareOutputDir, resolveCodexCommand, resolvePluginPath, resolvePluginPython, validateOutputDir, } from "./runtime.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,YAAY,EACV,6BAA6B,EAC7B,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC7E,YAAY,EACV,aAAa,EACb,wBAAwB,GACzB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,YAAY,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC5D,YAAY,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACrE,YAAY,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC3E,YAAY,EACV,qBAAqB,EACrB,eAAe,EACf,YAAY,EACZ,kBAAkB,EAClB,WAAW,EACX,aAAa,EACb,oBAAoB,EACpB,uBAAuB,EACvB,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,UAAU,CAAC;AAClB,YAAY,EACV,SAAS,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WAAW,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAC7D,YAAY,EACV,+BAA+B,EAC/B,+BAA+B,GAChC,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,2BAA2B,EAC3B,0BAA0B,EAC1B,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,YAAY,EACV,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,0BAA0B,EAC1B,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,cAAc,CAAC;AACtB,YAAY,EACV,YAAY,EACZ,aAAa,EACb,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,UAAU,EACV,mBAAmB,EACnB,eAAe,EACf,kBAAkB,EAClB,YAAY,GACb,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,gBAAgB,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,sBAAsB,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,8 @@ export { CodexLoginHandle } from "./auth.js";
|
|
|
6
6
|
export { AuthenticationRequiredError, CodexSecurityError, ConfigurationError, ContractValidationError, IncompleteScanError, InvalidTargetError, OutputDirectoryError, OutputDirectoryNotEmptyError, OutputInsideProtectedRootError, PluginBootstrapError, PluginPythonUnavailableError, ScanCostLimitExceededError, ScanInterruptedError, } from "./errors.js";
|
|
7
7
|
export { DEFAULT_CODEX_CONFIG, mergedCodexConfig, writeCodexConfig, } from "./config.js";
|
|
8
8
|
export { loadContract, requireScanFile } from "./contract.js";
|
|
9
|
-
export { publishScan } from "./publish.js";
|
|
9
|
+
export { checkScanPublication, publishScan } from "./publish.js";
|
|
10
|
+
export { importGitHubCodeScanningAlerts } from "./github.js";
|
|
10
11
|
export { ScanResult } from "./result.js";
|
|
11
12
|
export { bootstrapPlugin, bundledPluginRoot, cleanupSdkDirectory, createIsolatedHome, createMarketplace, extractPluginZip, importAmbientAuth, MARKETPLACE_NAME, pluginExecutionEnvironment, pluginMetadata, PLUGIN_NAME, prepareOutputDir, resolveCodexCommand, resolvePluginPath, resolvePluginPython, validateOutputDir, } from "./runtime.js";
|
|
12
13
|
export { DiffTarget, normalizeRepository, normalizeTarget, repositoryRevision, validateMode, } from "./targets.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAQxD,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAK7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAuB7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAG7C,OAAO,EACL,2BAA2B,EAC3B,kBAAkB,EAClB,kBAAkB,EAClB,uBAAuB,EACvB,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,4BAA4B,EAC5B,8BAA8B,EAC9B,oBAAoB,EACpB,4BAA4B,EAC5B,0BAA0B,EAC1B,oBAAoB,GACrB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,aAA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AiB,GAClB,MAAM,cAAc,CAAC;AAOtB,OAAO,EACL,UAAU,EACV,mBAAmB,EACnB,eAAe,EACf,kBAAkB,EAClB,YAAY,GACb,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,sBAAsB,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC","sourcesContent":["export { CodexSecurity, createSecurity } from \"./api.js\";\nexport { runComponentScans } from \"./component-scan.js\";\nexport type {\n ComponentDeduplicationSummary,\n ComponentReceipt,\n ComponentScanOptions,\n ComponentScanEvent,\n ComponentScanResult,\n} from \"./component-scan.js\";\nexport { normalizeComponentPlan, planComponents } from \"./component-plan.js\";\nexport type {\n ComponentPlan,\n ComponentPlanningOptions,\n} from \"./component-plan.js\";\nexport { estimateScanCost } from \"./cost.js\";\nexport type { ScanCost, ScanSessionEvent } from \"./cost.js\";\nexport type { CustomValidationResult } from \"./custom-validation.js\";\nexport type { ScanActivity, ScanActivityStatus } from \"./scan-activity.js\";\nexport type {\n CodexSecurityMetadata,\n DeepScanOptions,\n ScanAuthMode,\n ScanAuthentication,\n ScanOptions,\n ScanPreflight,\n ScanReconnectDetails,\n ScanTrustedAccessStatus,\n ScanWarningDetails,\n ValidationOptions,\n ValidationResult,\n} from \"./api.js\";\nexport type {\n ScanPhase,\n ScanProgress,\n ScanWorkerPhase,\n ScanWorkerStatus,\n} from \"./worker-progress.js\";\nexport { CodexLoginHandle } from \"./auth.js\";\nexport type { AccountStatus, LoginResult } from \"./auth.js\";\n\nexport {\n AuthenticationRequiredError,\n CodexSecurityError,\n ConfigurationError,\n ContractValidationError,\n IncompleteScanError,\n InvalidTargetError,\n OutputDirectoryError,\n OutputDirectoryNotEmptyError,\n OutputInsideProtectedRootError,\n PluginBootstrapError,\n PluginPythonUnavailableError,\n ScanCostLimitExceededError,\n ScanInterruptedError,\n} from \"./errors.js\";\nexport type { ProtectedScanPathKind } from \"./errors.js\";\nexport {\n DEFAULT_CODEX_CONFIG,\n mergedCodexConfig,\n writeCodexConfig,\n} from \"./config.js\";\nexport type { CodexSecurityConfig, JsonObject, JsonValue } from \"./config.js\";\nexport { loadContract, requireScanFile } from \"./contract.js\";\nexport type { LoadedContract, ScanExpectation } from \"./contract.js\";\nexport type * from \"./models.js\";\nexport { checkScanPublication, publishScan } from \"./publish.js\";\nexport { importGitHubCodeScanningAlerts } from \"./github.js\";\nexport type {\n GitHubCodeScanningImportOptions,\n ImportedGitHubCodeScanningAlert,\n} from \"./github.js\";\nexport type {\n CheckScanPublicationOptions,\n CheckScanPublicationResult,\n PublishScanOptions,\n PublishScanProgress,\n PublishScanResult,\n} from \"./publish.js\";\nexport { ScanResult } from \"./result.js\";\nexport type {\n RepositoryFinding,\n ScanResultOptions,\n TurnResultMetadata,\n} from \"./result.js\";\nexport {\n bootstrapPlugin,\n bundledPluginRoot,\n cleanupSdkDirectory,\n createIsolatedHome,\n createMarketplace,\n extractPluginZip,\n importAmbientAuth,\n MARKETPLACE_NAME,\n pluginExecutionEnvironment,\n pluginMetadata,\n PLUGIN_NAME,\n prepareOutputDir,\n resolveCodexCommand,\n resolvePluginPath,\n resolvePluginPython,\n validateOutputDir,\n} from \"./runtime.js\";\nexport type {\n CodexCommand,\n PluginInstall,\n PluginPythonOptions,\n ProcessEnvironment,\n} from \"./runtime.js\";\nexport {\n DiffTarget,\n normalizeRepository,\n normalizeTarget,\n repositoryRevision,\n validateMode,\n} from \"./targets.js\";\nexport type { NormalizedTarget, ScanMode, ScanTarget } from \"./targets.js\";\nexport { BUNDLED_PLUGIN_VERSION, VERSION } from \"./version.js\";\n"]}
|
package/dist/linear.d.ts
CHANGED
|
@@ -16,4 +16,9 @@ export declare function importLinearIssues(options: {
|
|
|
16
16
|
environment: NodeJS.ProcessEnv;
|
|
17
17
|
linearClient?: LinearClientFactory;
|
|
18
18
|
}): Promise<ImportedIssue[]>;
|
|
19
|
+
export declare function isLinearIssueIdentifier(input: string): boolean;
|
|
20
|
+
export declare function linearIssueReference(input: string): {
|
|
21
|
+
id: string;
|
|
22
|
+
workspace?: string;
|
|
23
|
+
};
|
|
19
24
|
//# sourceMappingURL=linear.d.ts.map
|
package/dist/linear.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linear.d.ts","sourceRoot":"","sources":["../src/linear.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,YAAY,EAEb,MAAM,aAAa,CAAC;AAIrB,MAAM,MAAM,mBAAmB,CAC7B,MAAM,SAAS,MAAM,YAAY,GAAG,OAAO,GAAG,UAAU,IACtD,CACF,OAAO,EAAE,qBAAqB,CAAC,OAAO,YAAY,CAAC,CAAC,CAAC,CAAC,KACnD,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;AAEhC,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,MAAM,CAAC,UAAU,EAC9B,QAAQ,CAAC,EAAE,MAAM,GAChB,MAAM,GAAG,SAAS,CAMpB;AAED,wBAAgB,kBAAkB,CAAC,MAAM,SAAS,MAAM,YAAY,EAClE,OAAO,EAAE,qBAAqB,CAAC,OAAO,YAAY,CAAC,CAAC,CAAC,CAAC,EACtD,OAAO,CAAC,EAAE,mBAAmB,CAAC,MAAM,CAAC,GACpC,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,CAG5B;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,QAAQ,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CACd;AAED,wBAAsB,kBAAkB,CAAC,OAAO,EAAE;IAChD,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC,UAAU,CAAC;IAC/B,YAAY,CAAC,EAAE,mBAAmB,CAAC;CACpC,GAAG,OAAO,CAAC,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,CAE9D;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG;IACnD,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAYA"}
|
package/dist/linear.js
CHANGED
|
@@ -104,12 +104,17 @@ function linearIssueFilter(input) {
|
|
|
104
104
|
}
|
|
105
105
|
throw new CodexSecurityError("--linear-filter must be a JSON Linear issue filter.");
|
|
106
106
|
}
|
|
107
|
-
function
|
|
107
|
+
export function isLinearIssueIdentifier(input) {
|
|
108
|
+
return /^[A-Za-z][A-Za-z0-9_-]*-\d+$/u.test(input);
|
|
109
|
+
}
|
|
110
|
+
export function linearIssueReference(input) {
|
|
108
111
|
if (!/^https?:\/\//iu.test(input))
|
|
109
112
|
return { id: input };
|
|
110
113
|
const url = new URL(input);
|
|
111
|
-
const match = /^\/([^/]+)\/issue\/([
|
|
112
|
-
if (url.hostname !== "linear.app" ||
|
|
114
|
+
const match = /^\/([^/]+)\/issue\/([^/]+)(?:\/|$)/iu.exec(url.pathname);
|
|
115
|
+
if (url.hostname !== "linear.app" ||
|
|
116
|
+
match === null ||
|
|
117
|
+
!isLinearIssueIdentifier(match[2])) {
|
|
113
118
|
throw new CodexSecurityError("Linear issue URL is invalid.");
|
|
114
119
|
}
|
|
115
120
|
return { id: match[2], workspace: match[1].toLowerCase() };
|
package/dist/linear.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linear.js","sourceRoot":"","sources":["../src/linear.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,oBAAoB,EACpB,YAAY,EACZ,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAQnE,MAAM,UAAU,mBAAmB,CACjC,WAA8B,EAC9B,QAAiB;IAEjB,OAAO,CACL,QAAQ,EAAE,IAAI,EAAE;QAChB,WAAW,CAAC,+B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AAQ,KAAK,YAAY,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACpD,MAAM,IAAI,kBAAkB,CAAC,8BAA8B,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC,CAAE,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,CAAE,CAAC,WAAW,EAAE,EAAE,CAAC;AAC/D,CAAC","sourcesContent":["import {\n AuthenticationLinearError,\n ForbiddenLinearError,\n LinearClient,\n RatelimitedLinearError,\n} from \"@linear/sdk\";\nimport type { JsonObject } from \"./config.js\";\nimport { CodexSecurityError, safeErrorMessage } from \"./errors.js\";\n\nexport type LinearClientFactory<\n Method extends keyof LinearClient = \"issue\" | \"projects\",\n> = (\n options: ConstructorParameters<typeof LinearClient>[0],\n) => Pick<LinearClient, Method>;\n\nexport function resolveLinearApiKey(\n environment: NodeJS.ProcessEnv,\n explicit?: string,\n): string | undefined {\n return (\n explicit?.trim() ||\n environment[\"CODEX_SECURITY_LINEAR_API_KEY\"]?.trim() ||\n undefined\n );\n}\n\nexport function createLinearClient<Method extends keyof LinearClient>(\n options: ConstructorParameters<typeof LinearClient>[0],\n factory?: LinearClientFactory<Method>,\n): Pick<LinearClient, Method> {\n const configuration = { ...options, redirect: \"error\" as const };\n return factory ? factory(configuration) : new LinearClient(configuration);\n}\n\nexport interface ImportedIssue {\n source: \"linear\";\n id: string;\n url: string;\n text: string;\n}\n\nexport async function importLinearIssues(options: {\n issues: readonly string[];\n project?: string;\n filter?: string;\n apiKey?: string;\n environment: NodeJS.ProcessEnv;\n linearClient?: LinearClientFactory;\n}): Promise<ImportedIssue[]> {\n const apiKey =\n resolveLinearApiKey(options.environment, options.apiKey) ||\n options.environment[\"LINEAR_API_KEY\"]?.trim();\n const accessToken = options.environment[\"LINEAR_ACCESS_TOKEN\"]?.trim();\n const credential = apiKey || accessToken;\n if (!credential) {\n throw new CodexSecurityError(\n \"Linear access requires CODEX_SECURITY_LINEAR_API_KEY, LINEAR_API_KEY, or LINEAR_ACCESS_TOKEN.\",\n );\n }\n\n const client = createLinearClient(\n apiKey ? { apiKey } : { accessToken },\n options.linearClient,\n );\n\n try {\n const issues: Awaited<ReturnType<LinearClient[\"issue\"]>>[] = [];\n if (options.project !== undefined) {\n const suppliedFilter = linearIssueFilter(options.filter);\n const filter = Object.hasOwn(suppliedFilter, \"state\")\n ? suppliedFilter\n : {\n state: { type: { nin: [\"completed\", \"canceled\"] } },\n ...suppliedFilter,\n };\n const projects = await client.projects({\n filter: { name: { eqIgnoreCase: options.project } },\n first: 2,\n });\n if (projects.nodes.length !== 1) {\n throw new CodexSecurityError(\n `Linear project \"${options.project}\" ${projects.nodes.length === 0 ? \"was not found or is not accessible\" : \"is ambiguous\"}.`,\n );\n }\n\n const page = await projects.nodes[0]!.issues({ first: 50, filter });\n while (page.pageInfo.hasNextPage) await page.fetchNext();\n issues.push(...page.nodes);\n if (issues.length === 0) {\n throw new CodexSecurityError(\n `No open Linear issues matched project \"${options.project}\" and its filter.`,\n );\n }\n } else {\n for (const input of options.issues) {\n const { id, workspace } = linearIssueReference(input);\n const issue = await client.issue(id);\n if (!issue) {\n throw new CodexSecurityError(\n `Linear issue \"${id}\" was not found or is not accessible.`,\n );\n }\n if (\n workspace !== undefined &&\n linearIssueReference(issue.url).workspace !== workspace\n ) {\n throw new CodexSecurityError(\n \"Fetched Linear issue does not match the workspace in the selected URL.\",\n );\n }\n issues.push(issue);\n }\n }\n\n const imports: ImportedIssue[] = [];\n for (const issue of issues) {\n const comments = await issue.comments({ first: 50 });\n while (comments.pageInfo.hasNextPage) await comments.fetchNext();\n imports.push({\n source: \"linear\",\n id: issue.identifier,\n url: issue.url,\n text: [\n `Title: ${issue.title}`,\n `<description>\\n${issue.description ?? \"\"}\\n</description>`,\n ...comments.nodes.map(\n ({ url, body }) => `<comment>\\nURL: ${url}\\n\\n${body}\\n</comment>`,\n ),\n ].join(\"\\n\\n\"),\n });\n }\n return imports;\n } catch (error) {\n if (error instanceof CodexSecurityError) throw error;\n if (\n error instanceof AuthenticationLinearError ||\n error instanceof ForbiddenLinearError\n ) {\n throw new CodexSecurityError(\"Linear authentication failed.\");\n }\n if (error instanceof RatelimitedLinearError) {\n throw new CodexSecurityError(\n \"Linear request was rate limited. Wait and retry.\",\n );\n }\n const message = safeErrorMessage(error);\n throw new CodexSecurityError(\n `Linear request failed: ${message.includes(credential) ? \"[redacted]\" : message}`,\n );\n }\n}\n\nfunction linearIssueFilter(input: string | undefined): JsonObject {\n if (input === undefined) return {};\n let filter: unknown;\n try {\n filter = JSON.parse(input);\n } catch {\n filter = null;\n }\n if (typeof filter === \"object\" && filter !== null && !Array.isArray(filter)) {\n return filter as JsonObject;\n }\n throw new CodexSecurityError(\n \"--linear-filter must be a JSON Linear issue filter.\",\n );\n}\n\nfunction linearIssueReference(input: string): {\n id: string;\n workspace?: string;\n} {\n if (!/^https?:\\/\\//iu.test(input)) return { id: input };\n const url = new URL(input);\n const match = /^\\/([^/]+)\\/issue\\/([A-Z][A-Z0-9]*-\\d+)(?:\\/|$)/iu.exec(\n url.pathname,\n );\n if (url.hostname !== \"linear.app\" || match === null) {\n throw new CodexSecurityError(\"Linear issue URL is invalid.\");\n }\n return { id: match[2]!, workspace: match[1]!.toLowerCase() };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"linear.js","sourceRoot":"","sources":["../src/linear.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,oBAAoB,EACpB,YAAY,EACZ,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAQnE,MAAM,UAAU,mBAAmB,CACjC,WAA8B,EAC9B,QAAiB;IAEjB,OAAO,CACL,QAAQ,EAAE,IAAI,EAAE;QAChB,WAAW,CAAC,+BAA+B,CAAC,EAAE,IAAI,EAAE;QACpD,SAAS,CACV,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,kB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AAC;IACxE,IACE,GAAG,CAAC,QAAQ,KAAK,YAAY;QAC7B,KAAK,KAAK,IAAI;QACd,CAAC,uBAAuB,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC,EACnC,CAAC;QACD,MAAM,IAAI,kBAAkB,CAAC,8BAA8B,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC,CAAE,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,CAAE,CAAC,WAAW,EAAE,EAAE,CAAC;AAC/D,CAAC","sourcesContent":["import {\n AuthenticationLinearError,\n ForbiddenLinearError,\n LinearClient,\n RatelimitedLinearError,\n} from \"@linear/sdk\";\nimport type { JsonObject } from \"./config.js\";\nimport { CodexSecurityError, safeErrorMessage } from \"./errors.js\";\n\nexport type LinearClientFactory<\n Method extends keyof LinearClient = \"issue\" | \"projects\",\n> = (\n options: ConstructorParameters<typeof LinearClient>[0],\n) => Pick<LinearClient, Method>;\n\nexport function resolveLinearApiKey(\n environment: NodeJS.ProcessEnv,\n explicit?: string,\n): string | undefined {\n return (\n explicit?.trim() ||\n environment[\"CODEX_SECURITY_LINEAR_API_KEY\"]?.trim() ||\n undefined\n );\n}\n\nexport function createLinearClient<Method extends keyof LinearClient>(\n options: ConstructorParameters<typeof LinearClient>[0],\n factory?: LinearClientFactory<Method>,\n): Pick<LinearClient, Method> {\n const configuration = { ...options, redirect: \"error\" as const };\n return factory ? factory(configuration) : new LinearClient(configuration);\n}\n\nexport interface ImportedIssue {\n source: \"linear\";\n id: string;\n url: string;\n text: string;\n}\n\nexport async function importLinearIssues(options: {\n issues: readonly string[];\n project?: string;\n filter?: string;\n apiKey?: string;\n environment: NodeJS.ProcessEnv;\n linearClient?: LinearClientFactory;\n}): Promise<ImportedIssue[]> {\n const apiKey =\n resolveLinearApiKey(options.environment, options.apiKey) ||\n options.environment[\"LINEAR_API_KEY\"]?.trim();\n const accessToken = options.environment[\"LINEAR_ACCESS_TOKEN\"]?.trim();\n const credential = apiKey || accessToken;\n if (!credential) {\n throw new CodexSecurityError(\n \"Linear access requires CODEX_SECURITY_LINEAR_API_KEY, LINEAR_API_KEY, or LINEAR_ACCESS_TOKEN.\",\n );\n }\n\n const client = createLinearClient(\n apiKey ? { apiKey } : { accessToken },\n options.linearClient,\n );\n\n try {\n const issues: Awaited<ReturnType<LinearClient[\"issue\"]>>[] = [];\n if (options.project !== undefined) {\n const suppliedFilter = linearIssueFilter(options.filter);\n const filter = Object.hasOwn(suppliedFilter, \"state\")\n ? suppliedFilter\n : {\n state: { type: { nin: [\"completed\", \"canceled\"] } },\n ...suppliedFilter,\n };\n const projects = await client.projects({\n filter: { name: { eqIgnoreCase: options.project } },\n first: 2,\n });\n if (projects.nodes.length !== 1) {\n throw new CodexSecurityError(\n `Linear project \"${options.project}\" ${projects.nodes.length === 0 ? \"was not found or is not accessible\" : \"is ambiguous\"}.`,\n );\n }\n\n const page = await projects.nodes[0]!.issues({ first: 50, filter });\n while (page.pageInfo.hasNextPage) await page.fetchNext();\n issues.push(...page.nodes);\n if (issues.length === 0) {\n throw new CodexSecurityError(\n `No open Linear issues matched project \"${options.project}\" and its filter.`,\n );\n }\n } else {\n for (const input of options.issues) {\n const { id, workspace } = linearIssueReference(input);\n const issue = await client.issue(id);\n if (!issue) {\n throw new CodexSecurityError(\n `Linear issue \"${id}\" was not found or is not accessible.`,\n );\n }\n if (\n workspace !== undefined &&\n linearIssueReference(issue.url).workspace !== workspace\n ) {\n throw new CodexSecurityError(\n \"Fetched Linear issue does not match the workspace in the selected URL.\",\n );\n }\n issues.push(issue);\n }\n }\n\n const imports: ImportedIssue[] = [];\n for (const issue of issues) {\n const comments = await issue.comments({ first: 50 });\n while (comments.pageInfo.hasNextPage) await comments.fetchNext();\n imports.push({\n source: \"linear\",\n id: issue.identifier,\n url: issue.url,\n text: [\n `Title: ${issue.title}`,\n `<description>\\n${issue.description ?? \"\"}\\n</description>`,\n ...comments.nodes.map(\n ({ url, body }) => `<comment>\\nURL: ${url}\\n\\n${body}\\n</comment>`,\n ),\n ].join(\"\\n\\n\"),\n });\n }\n return imports;\n } catch (error) {\n if (error instanceof CodexSecurityError) throw error;\n if (\n error instanceof AuthenticationLinearError ||\n error instanceof ForbiddenLinearError\n ) {\n throw new CodexSecurityError(\"Linear authentication failed.\");\n }\n if (error instanceof RatelimitedLinearError) {\n throw new CodexSecurityError(\n \"Linear request was rate limited. Wait and retry.\",\n );\n }\n const message = safeErrorMessage(error);\n throw new CodexSecurityError(\n `Linear request failed: ${message.includes(credential) ? \"[redacted]\" : message}`,\n );\n }\n}\n\nfunction linearIssueFilter(input: string | undefined): JsonObject {\n if (input === undefined) return {};\n let filter: unknown;\n try {\n filter = JSON.parse(input);\n } catch {\n filter = null;\n }\n if (typeof filter === \"object\" && filter !== null && !Array.isArray(filter)) {\n return filter as JsonObject;\n }\n throw new CodexSecurityError(\n \"--linear-filter must be a JSON Linear issue filter.\",\n );\n}\n\nexport function isLinearIssueIdentifier(input: string): boolean {\n return /^[A-Za-z][A-Za-z0-9_-]*-\\d+$/u.test(input);\n}\n\nexport function linearIssueReference(input: string): {\n id: string;\n workspace?: string;\n} {\n if (!/^https?:\\/\\//iu.test(input)) return { id: input };\n const url = new URL(input);\n const match = /^\\/([^/]+)\\/issue\\/([^/]+)(?:\\/|$)/iu.exec(url.pathname);\n if (\n url.hostname !== \"linear.app\" ||\n match === null ||\n !isLinearIssueIdentifier(match[2]!)\n ) {\n throw new CodexSecurityError(\"Linear issue URL is invalid.\");\n }\n return { id: match[2]!, workspace: match[1]!.toLowerCase() };\n}\n"]}
|
|
@@ -1,16 +1,43 @@
|
|
|
1
|
-
import type
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
issueIdentifier: string;
|
|
7
|
-
url?: string;
|
|
8
|
-
}>;
|
|
9
|
-
failed: Array<{
|
|
10
|
-
findingId: string;
|
|
11
|
-
error: string;
|
|
12
|
-
}>;
|
|
1
|
+
import { type PreparedPublicationIssue, type PreparedScanPublication } from "./publication.js";
|
|
2
|
+
export declare const MISSING_PUBLICATION_IDENTIFIER_ERROR = "The connected Linear app did not return a created issue identifier.";
|
|
3
|
+
export interface PublicationClaim {
|
|
4
|
+
kind: "identifier" | "entityId" | "url";
|
|
5
|
+
value: string;
|
|
13
6
|
}
|
|
14
|
-
export
|
|
7
|
+
export type ClaimResolution = {
|
|
8
|
+
state: "absent";
|
|
9
|
+
claims: PublicationClaim[];
|
|
10
|
+
} | {
|
|
11
|
+
state: "conflicting";
|
|
12
|
+
claims: PublicationClaim[];
|
|
13
|
+
} | {
|
|
14
|
+
state: "resolved";
|
|
15
|
+
claims: PublicationClaim[];
|
|
16
|
+
issueIdentifier: string;
|
|
17
|
+
url?: string;
|
|
18
|
+
};
|
|
19
|
+
export interface CompletedCreateEvidence {
|
|
20
|
+
source: "event";
|
|
21
|
+
status: "completed";
|
|
22
|
+
rawLine: string;
|
|
23
|
+
ownerFindingId?: string;
|
|
24
|
+
argumentsValid: boolean;
|
|
25
|
+
resolution: ClaimResolution;
|
|
26
|
+
}
|
|
27
|
+
export interface FailedCreateEvidence {
|
|
28
|
+
source: "event";
|
|
29
|
+
status: "failed";
|
|
30
|
+
rawLine: string;
|
|
31
|
+
ownerFindingId?: string;
|
|
32
|
+
argumentsValid: boolean;
|
|
33
|
+
resolution: ClaimResolution;
|
|
34
|
+
error: string;
|
|
35
|
+
}
|
|
36
|
+
export type PublicationEventEvidence = CompletedCreateEvidence | FailedCreateEvidence;
|
|
37
|
+
export declare function collectPublicationEvents(output: string, publication: PreparedScanPublication, failureMessage: string): PublicationEventEvidence[];
|
|
38
|
+
export declare function hasExpectedPublicationArguments(publication: PreparedScanPublication, issue: PreparedPublicationIssue, actual: unknown): boolean;
|
|
15
39
|
export declare function matchPublicationIssue(publication: PreparedScanPublication, arguments_: Record<string, unknown>): PreparedPublicationIssue | undefined;
|
|
40
|
+
export declare function resolvePublicationClaims(value: unknown): ClaimResolution;
|
|
41
|
+
export declare function resolveClaims(claims: readonly PublicationClaim[]): ClaimResolution;
|
|
42
|
+
export declare function publicationClaimAliases(claim: PublicationClaim): PublicationClaim[];
|
|
16
43
|
//# sourceMappingURL=publication-events.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publication-events.d.ts","sourceRoot":"","sources":["../src/publication-events.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"publication-events.d.ts","sourceRoot":"","sources":["../src/publication-events.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC7B,MAAM,kBAAkB,CAAC;AAE1B,eAAO,MAAM,oCAAoC,wEACsB,CAAC;AAExE,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,YAAY,GAAG,UAAU,GAAG,KAAK,CAAC;IACxC,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,eAAe,GACvB;IAAE,KAAK,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,gBAAgB,EAAE,CAAA;CAAE,GAC/C;IAAE,KAAK,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE,gBAAgB,EAAE,CAAA;CAAE,GACpD;IACE,KAAK,EAAE,UAAU,CAAC;IAClB,MAAM,EAAE,gBAAgB,EAAE,CAAC;IAC3B,eAAe,EAAE,MAAM,CAAC;IACxB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEN,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,WAAW,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,OAAO,CAAC;IACxB,UAAU,EAAE,eAAe,CAAC;CAC7B;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,QAAQ,CAAC;IACjB,OAAO,EAAE,MAAM,C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