@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
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import { isLinearIssueIdentifier, linearIssueReference } from "./linear.js";
|
|
2
|
+
import { linearPublicationArguments, } from "./publication.js";
|
|
3
|
+
export const MISSING_PUBLICATION_IDENTIFIER_ERROR = "The connected Linear app did not return a created issue identifier.";
|
|
1
4
|
export function collectPublicationEvents(output, publication, failureMessage) {
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
for (const line of output.split(/\r?\n/)) {
|
|
6
|
-
if (line.trim().length === 0)
|
|
5
|
+
const evidence = [];
|
|
6
|
+
for (const rawLine of output.split(/\r?\n/)) {
|
|
7
|
+
if (rawLine.trim().length === 0)
|
|
7
8
|
continue;
|
|
8
9
|
let event;
|
|
9
10
|
try {
|
|
10
|
-
event = JSON.parse(
|
|
11
|
+
event = JSON.parse(rawLine);
|
|
11
12
|
}
|
|
12
13
|
catch {
|
|
13
14
|
continue;
|
|
@@ -15,125 +16,238 @@ export function collectPublicationEvents(output, publication, failureMessage) {
|
|
|
15
16
|
if (!isRecord(event) || event["type"] !== "item.completed")
|
|
16
17
|
continue;
|
|
17
18
|
const item = event["item"];
|
|
18
|
-
if (!
|
|
19
|
-
item["type"] !== "mcp_tool_call" ||
|
|
20
|
-
item["server"] !== "codex_apps" ||
|
|
21
|
-
(item["tool"] !== "linear.save_issue" &&
|
|
22
|
-
item["tool"] !== "linear_save_issue")) {
|
|
19
|
+
if (!isLinearCreateCall(item))
|
|
23
20
|
continue;
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
? matchPublicationIssue(publication, args)
|
|
21
|
+
const arguments_ = item["arguments"];
|
|
22
|
+
const owner = isRecord(arguments_)
|
|
23
|
+
? matchPublicationIssue(publication, arguments_)
|
|
28
24
|
: undefined;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
25
|
+
const argumentsValid = owner !== undefined &&
|
|
26
|
+
hasExpectedPublicationArguments(publication, owner, arguments_);
|
|
27
|
+
if (item["status"] === "completed") {
|
|
28
|
+
evidence.push({
|
|
29
|
+
source: "event",
|
|
30
|
+
status: "completed",
|
|
31
|
+
rawLine,
|
|
32
|
+
...(owner === undefined ? {} : { ownerFindingId: owner.findingId }),
|
|
33
|
+
argumentsValid,
|
|
34
|
+
resolution: resolvePublicationClaims(item["result"]),
|
|
35
|
+
});
|
|
35
36
|
continue;
|
|
36
37
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
const error = item["error"];
|
|
39
|
+
evidence.push({
|
|
40
|
+
source: "event",
|
|
41
|
+
status: "failed",
|
|
42
|
+
rawLine,
|
|
43
|
+
...(owner === undefined ? {} : { ownerFindingId: owner.findingId }),
|
|
44
|
+
argumentsValid,
|
|
45
|
+
resolution: resolvePublicationClaims(item["result"]),
|
|
46
|
+
error: isRecord(error) && typeof error["message"] === "string"
|
|
40
47
|
? error["message"]
|
|
41
|
-
: failureMessage
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
const saved = savedIssue(item["result"]);
|
|
45
|
-
if (saved === undefined) {
|
|
46
|
-
failed.set(issue.findingId, "The connected Linear app did not return a created issue identifier.");
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
created.set(issue.findingId, {
|
|
50
|
-
findingId: issue.findingId,
|
|
51
|
-
occurrenceId: issue.occurrenceId,
|
|
52
|
-
issueIdentifier: saved.issueIdentifier,
|
|
53
|
-
...(saved.url === undefined ? {} : { url: saved.url }),
|
|
48
|
+
: failureMessage,
|
|
54
49
|
});
|
|
55
50
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return [];
|
|
65
|
-
const result = created.get(issue.findingId);
|
|
66
|
-
return result === undefined ? [] : [result];
|
|
67
|
-
}),
|
|
68
|
-
failed: publication.issues.flatMap((issue) => {
|
|
69
|
-
const error = failed.get(issue.findingId);
|
|
70
|
-
if (error !== undefined)
|
|
71
|
-
return [{ findingId: issue.findingId, error }];
|
|
72
|
-
return created.has(issue.findingId)
|
|
73
|
-
? []
|
|
74
|
-
: [{ findingId: issue.findingId, error: failureMessage }];
|
|
75
|
-
}),
|
|
76
|
-
};
|
|
51
|
+
return evidence;
|
|
52
|
+
}
|
|
53
|
+
export function hasExpectedPublicationArguments(publication, issue, actual) {
|
|
54
|
+
if (!isRecord(actual))
|
|
55
|
+
return false;
|
|
56
|
+
const expected = linearPublicationArguments(publication.destination, issue);
|
|
57
|
+
return (Object.keys(actual).length === Object.keys(expected).length &&
|
|
58
|
+
Object.entries(expected).every(([key, value]) => Object.hasOwn(actual, key) && Object.is(actual[key], value)));
|
|
77
59
|
}
|
|
78
60
|
export function matchPublicationIssue(publication, arguments_) {
|
|
61
|
+
const exactMatches = publication.issues.filter((issue) => hasExpectedPublicationArguments(publication, issue, arguments_));
|
|
62
|
+
if (exactMatches.length === 1)
|
|
63
|
+
return exactMatches[0];
|
|
79
64
|
const description = arguments_["description"];
|
|
80
|
-
if (typeof description !== "string")
|
|
65
|
+
if (typeof description !== "string")
|
|
81
66
|
return undefined;
|
|
82
|
-
|
|
83
|
-
const matches = publication.issues.filter((issue) => descriptionIdentifiesIssue(description, issue));
|
|
84
|
-
return matches.length === 1 ? matches[0] : undefined;
|
|
85
|
-
}
|
|
86
|
-
function descriptionIdentifiesIssue(description, issue) {
|
|
87
|
-
return (containsIdentifier(description, issue.findingId) &&
|
|
67
|
+
const matches = publication.issues.filter((issue) => containsIdentifier(description, issue.findingId) &&
|
|
88
68
|
containsIdentifier(description, issue.occurrenceId));
|
|
69
|
+
return matches.length === 1 ? matches[0] : undefined;
|
|
89
70
|
}
|
|
90
|
-
function
|
|
91
|
-
const
|
|
92
|
-
|
|
71
|
+
export function resolvePublicationClaims(value) {
|
|
72
|
+
const claims = [];
|
|
73
|
+
collectPublicationClaims(value, claims);
|
|
74
|
+
return resolveClaims(claims);
|
|
93
75
|
}
|
|
94
|
-
function
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
76
|
+
export function resolveClaims(claims) {
|
|
77
|
+
const seen = new Set();
|
|
78
|
+
const normalized = claims.flatMap((claim) => {
|
|
79
|
+
const trimmed = claim.value.trim();
|
|
80
|
+
if (trimmed.length === 0)
|
|
81
|
+
return [];
|
|
82
|
+
const value = isCanonicalUuid(trimmed) ? trimmed.toLowerCase() : trimmed;
|
|
83
|
+
return [{ kind: claim.kind, value }];
|
|
84
|
+
});
|
|
85
|
+
const retained = normalized
|
|
86
|
+
.filter((claim) => {
|
|
87
|
+
const key = `${claim.kind}\0${claim.value}`;
|
|
88
|
+
if (seen.has(key))
|
|
89
|
+
return false;
|
|
90
|
+
seen.add(key);
|
|
91
|
+
return true;
|
|
92
|
+
})
|
|
93
|
+
.sort(compareClaims);
|
|
94
|
+
const identifiers = new Set(retained
|
|
95
|
+
.filter((claim) => claim.kind === "identifier")
|
|
96
|
+
.map((claim) => claim.value));
|
|
97
|
+
const entityIds = new Set(retained
|
|
98
|
+
.filter((claim) => claim.kind === "entityId")
|
|
99
|
+
.map((claim) => claim.value));
|
|
100
|
+
const urls = new Set(retained
|
|
101
|
+
.filter((claim) => claim.kind === "url")
|
|
102
|
+
.map((claim) => claim.value));
|
|
103
|
+
const canonicalUrls = new Set([...urls].map(canonicalPublicationUrlClaim));
|
|
104
|
+
const urlContradictsIdentifier = identifiers.size > 0 &&
|
|
105
|
+
[...urls]
|
|
106
|
+
.map(linearIssueReferenceFromUrl)
|
|
107
|
+
.some((reference) => reference !== undefined && !identifiers.has(reference.id));
|
|
108
|
+
const overlappingIdentity = [...identifiers].some((identifier) => entityIds.has(identifier));
|
|
109
|
+
if (identifiers.size > 1 ||
|
|
110
|
+
entityIds.size > 1 ||
|
|
111
|
+
canonicalUrls.size > 1 ||
|
|
112
|
+
urlContradictsIdentifier ||
|
|
113
|
+
overlappingIdentity) {
|
|
114
|
+
return { state: "conflicting", claims: retained };
|
|
115
|
+
}
|
|
116
|
+
if (identifiers.size === 0) {
|
|
117
|
+
return { state: "absent", claims: retained };
|
|
112
118
|
}
|
|
113
|
-
|
|
114
|
-
|
|
119
|
+
return {
|
|
120
|
+
state: "resolved",
|
|
121
|
+
claims: retained,
|
|
122
|
+
issueIdentifier: identifiers.values().next().value,
|
|
123
|
+
...(urls.size === 0 ? {} : { url: urls.values().next().value }),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function isLinearCreateCall(item) {
|
|
127
|
+
return (isRecord(item) &&
|
|
128
|
+
item["type"] === "mcp_tool_call" &&
|
|
129
|
+
item["server"] === "codex_apps" &&
|
|
130
|
+
(item["tool"] === "linear.save_issue" ||
|
|
131
|
+
item["tool"] === "linear_save_issue"));
|
|
132
|
+
}
|
|
133
|
+
function collectPublicationClaims(value, claims) {
|
|
134
|
+
const visited = new Set();
|
|
135
|
+
const pending = [value];
|
|
136
|
+
while (pending.length > 0) {
|
|
137
|
+
const candidate = pending.pop();
|
|
138
|
+
if (!isRecord(candidate) || visited.has(candidate))
|
|
115
139
|
continue;
|
|
116
|
-
|
|
140
|
+
visited.add(candidate);
|
|
141
|
+
collectDirectClaims(candidate, claims);
|
|
117
142
|
const data = candidate["data"];
|
|
118
|
-
|
|
119
|
-
candidate,
|
|
120
|
-
|
|
143
|
+
const nested = [
|
|
144
|
+
candidate["structured_content"],
|
|
145
|
+
candidate["structuredContent"],
|
|
146
|
+
candidate["issue"],
|
|
121
147
|
isRecord(data) ? data["issue"] : undefined,
|
|
122
|
-
]
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
148
|
+
];
|
|
149
|
+
if (Array.isArray(candidate["content"])) {
|
|
150
|
+
for (const content of candidate["content"]) {
|
|
151
|
+
if (!isRecord(content) || typeof content["text"] !== "string") {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
try {
|
|
155
|
+
nested.push(JSON.parse(content["text"]));
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
128
160
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
};
|
|
161
|
+
}
|
|
162
|
+
for (let index = nested.length - 1; index >= 0; index -= 1) {
|
|
163
|
+
if (isRecord(nested[index]))
|
|
164
|
+
pending.push(nested[index]);
|
|
134
165
|
}
|
|
135
166
|
}
|
|
136
|
-
|
|
167
|
+
}
|
|
168
|
+
function collectDirectClaims(candidate, claims) {
|
|
169
|
+
for (const field of ["identifier", "issueIdentifier", "key", "id"]) {
|
|
170
|
+
const claim = classifyIdentityClaim(field, candidate[field]);
|
|
171
|
+
if (claim !== undefined)
|
|
172
|
+
claims.push(claim);
|
|
173
|
+
}
|
|
174
|
+
const url = candidate["url"];
|
|
175
|
+
const normalizedUrl = normalizeNonemptyString(url);
|
|
176
|
+
if (normalizedUrl !== undefined) {
|
|
177
|
+
claims.push({ kind: "url", value: normalizedUrl });
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
function classifyIdentityClaim(field, value) {
|
|
181
|
+
const normalized = normalizeNonemptyString(value);
|
|
182
|
+
if (normalized === undefined)
|
|
183
|
+
return undefined;
|
|
184
|
+
if (isCanonicalUuid(normalized)) {
|
|
185
|
+
return { kind: "entityId", value: normalized };
|
|
186
|
+
}
|
|
187
|
+
if (field === "identifier" || field === "issueIdentifier") {
|
|
188
|
+
return { kind: "identifier", value: normalized };
|
|
189
|
+
}
|
|
190
|
+
if (isLinearIssueIdentifier(normalized)) {
|
|
191
|
+
return { kind: "identifier", value: normalized };
|
|
192
|
+
}
|
|
193
|
+
return field === "id" ? { kind: "entityId", value: normalized } : undefined;
|
|
194
|
+
}
|
|
195
|
+
function compareClaims(left, right) {
|
|
196
|
+
const order = { identifier: 0, entityId: 1, url: 2 };
|
|
197
|
+
const kindOrder = order[left.kind] - order[right.kind];
|
|
198
|
+
if (kindOrder !== 0)
|
|
199
|
+
return kindOrder;
|
|
200
|
+
if (left.value === right.value)
|
|
201
|
+
return 0;
|
|
202
|
+
return left.value < right.value ? -1 : 1;
|
|
203
|
+
}
|
|
204
|
+
function isCanonicalUuid(value) {
|
|
205
|
+
return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/iu.test(value);
|
|
206
|
+
}
|
|
207
|
+
function linearIssueReferenceFromUrl(value) {
|
|
208
|
+
let url;
|
|
209
|
+
try {
|
|
210
|
+
url = new URL(value);
|
|
211
|
+
}
|
|
212
|
+
catch {
|
|
213
|
+
return undefined;
|
|
214
|
+
}
|
|
215
|
+
if (url.protocol !== "https:" || url.hostname !== "linear.app") {
|
|
216
|
+
return undefined;
|
|
217
|
+
}
|
|
218
|
+
try {
|
|
219
|
+
const reference = linearIssueReference(value);
|
|
220
|
+
return reference.workspace === undefined
|
|
221
|
+
? undefined
|
|
222
|
+
: { id: reference.id, workspace: reference.workspace };
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
|
+
return undefined;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
function canonicalPublicationUrlClaim(value) {
|
|
229
|
+
const reference = linearIssueReferenceFromUrl(value);
|
|
230
|
+
return reference === undefined
|
|
231
|
+
? `raw:\0${value}`
|
|
232
|
+
: `linear:\0${reference.workspace}\0${reference.id}`;
|
|
233
|
+
}
|
|
234
|
+
export function publicationClaimAliases(claim) {
|
|
235
|
+
if (claim.kind !== "url")
|
|
236
|
+
return [claim];
|
|
237
|
+
const reference = linearIssueReferenceFromUrl(claim.value);
|
|
238
|
+
return reference === undefined
|
|
239
|
+
? [claim]
|
|
240
|
+
: [claim, { kind: "identifier", value: reference.id }];
|
|
241
|
+
}
|
|
242
|
+
function normalizeNonemptyString(value) {
|
|
243
|
+
if (typeof value !== "string")
|
|
244
|
+
return undefined;
|
|
245
|
+
const normalized = value.trim();
|
|
246
|
+
return normalized.length === 0 ? undefined : normalized;
|
|
247
|
+
}
|
|
248
|
+
function containsIdentifier(value, identifier) {
|
|
249
|
+
const escaped = identifier.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
250
|
+
return new RegExp(`(?<![\\w-])${escaped}(?![\\w-])`, "u").test(value);
|
|
137
251
|
}
|
|
138
252
|
function isRecord(value) {
|
|
139
253
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publication-events.js","sourceRoot":"","sources":["../src/publication-events.ts"],"names":[],"mappings":"AAeA,MAAM,UAAU,wBAAwB,CACtC,MAAc,EACd,WAAoC,EACpC,cAAsB;IAEtB,MAAM,OAAO,GAAG,IAAI,GAAG,EAGpB,CAAC;IACJ,MAAM,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;IACzC,MAAM,UAAU,GAAa,EAAE,CAAC;IAEhC,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;QACzC,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC;YAAE,SAAS;QACvC,IAAI,KAAc,CAAC;QACnB,IAAI,CAAC;YACH,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAY,CAAC;QACtC,CAAC;QAAC,MAAM,CAAC;YACP,SAAS;QACX,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,gBAAgB;YAAE,SAAS;QACrE,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;QAC3B,IACE,CAAC,QAAQ,CAAC,IAAI,CAAC;YACf,IAAI,CAAC,MAAM,CAAC,KAAK,eAAe;YAChC,IAAI,CAAC,QAAQ,CAAC,KAAK,YAAY;YAC/B,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,mBAAmB;gBACnC,IAAI,CAAC,MAAM,CAAC,KAAK,mBAAmB,CAAC,EACvC,CAAC;YACD,SAAS;QACX,CAAC;QAED,MAAM,IAAI,GA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KAAK,CAAC,CAAC;YACzB,OAAO;gBACL,eAAe,EAAE,UAAU;gBAC3B,GAAG,CAAC,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC;aACvE,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC","sourcesContent":["import type {\n PreparedPublicationIssue,\n PreparedScanPublication,\n} from \"./publication.js\";\n\nexport interface CollectedPublicationEvents {\n created: Array<{\n findingId: string;\n occurrenceId: string;\n issueIdentifier: string;\n url?: string;\n }>;\n failed: Array<{ findingId: string; error: string }>;\n}\n\nexport function collectPublicationEvents(\n output: string,\n publication: PreparedScanPublication,\n failureMessage: string,\n): CollectedPublicationEvents {\n const created = new Map<\n string,\n CollectedPublicationEvents[\"created\"][number]\n >();\n const failed = new Map<string, string>();\n const unexpected: string[] = [];\n\n for (const line of output.split(/\\r?\\n/)) {\n if (line.trim().length === 0) continue;\n let event: unknown;\n try {\n event = JSON.parse(line) as unknown;\n } catch {\n continue;\n }\n if (!isRecord(event) || event[\"type\"] !== \"item.completed\") continue;\n const item = event[\"item\"];\n if (\n !isRecord(item) ||\n item[\"type\"] !== \"mcp_tool_call\" ||\n item[\"server\"] !== \"codex_apps\" ||\n (item[\"tool\"] !== \"linear.save_issue\" &&\n item[\"tool\"] !== \"linear_save_issue\")\n ) {\n continue;\n }\n\n const args = item[\"arguments\"];\n const issue = isRecord(args)\n ? matchPublicationIssue(publication, args)\n : undefined;\n if (issue === undefined) {\n unexpected.push(\"Codex attempted to create an unexpected Linear issue.\");\n continue;\n }\n if (failed.has(issue.findingId) || created.has(issue.findingId)) {\n failed.set(\n issue.findingId,\n \"Codex attempted to create more than one Linear issue for this finding.\",\n );\n continue;\n }\n if (item[\"status\"] !== \"completed\") {\n const error = item[\"error\"];\n failed.set(\n issue.findingId,\n isRecord(error) && typeof error[\"message\"] === \"string\"\n ? error[\"message\"]\n : failureMessage,\n );\n continue;\n }\n\n const saved = savedIssue(item[\"result\"]);\n if (saved === undefined) {\n failed.set(\n issue.findingId,\n \"The connected Linear app did not return a created issue identifier.\",\n );\n continue;\n }\n created.set(issue.findingId, {\n findingId: issue.findingId,\n occurrenceId: issue.occurrenceId,\n issueIdentifier: saved.issueIdentifier,\n ...(saved.url === undefined ? {} : { url: saved.url }),\n });\n }\n\n if (unexpected.length > 0 && publication.issues.length > 0) {\n const target =\n publication.issues.find((issue) => !created.has(issue.findingId)) ??\n publication.issues[0]!;\n failed.set(target.findingId, unexpected.join(\" \"));\n }\n\n return {\n created: publication.issues.flatMap((issue) => {\n if (failed.has(issue.findingId)) return [];\n const result = created.get(issue.findingId);\n return result === undefined ? [] : [result];\n }),\n failed: publication.issues.flatMap((issue) => {\n const error = failed.get(issue.findingId);\n if (error !== undefined) return [{ findingId: issue.findingId, error }];\n return created.has(issue.findingId)\n ? []\n : [{ findingId: issue.findingId, error: failureMessage }];\n }),\n };\n}\n\nexport function matchPublicationIssue(\n publication: PreparedScanPublication,\n arguments_: Record<string, unknown>,\n): PreparedPublicationIssue | undefined {\n const description = arguments_[\"description\"];\n if (typeof description !== \"string\") {\n return undefined;\n }\n\n const matches = publication.issues.filter((issue) =>\n descriptionIdentifiesIssue(description, issue),\n );\n return matches.length === 1 ? matches[0] : undefined;\n}\n\nfunction descriptionIdentifiesIssue(\n description: string,\n issue: PreparedPublicationIssue,\n): boolean {\n return (\n containsIdentifier(description, issue.findingId) &&\n containsIdentifier(description, issue.occurrenceId)\n );\n}\n\nfunction containsIdentifier(value: string, identifier: string): boolean {\n const escaped = identifier.replace(/[.*+?^${}()|[\\]\\\\]/gu, \"\\\\$&\");\n return new RegExp(`(?<![\\\\w-])${escaped}(?![\\\\w-])`, \"u\").test(value);\n}\n\nfunction savedIssue(\n result: unknown,\n): { issueIdentifier: string; url?: string } | undefined {\n if (!isRecord(result)) return undefined;\n const candidates: unknown[] = [\n result[\"structured_content\"],\n result[\"structuredContent\"],\n ];\n if (Array.isArray(result[\"content\"])) {\n for (const content of result[\"content\"]) {\n if (!isRecord(content) || typeof content[\"text\"] !== \"string\") continue;\n try {\n candidates.push(JSON.parse(content[\"text\"]) as unknown);\n } catch {\n continue;\n }\n }\n }\n\n for (const candidate of candidates) {\n if (!isRecord(candidate)) continue;\n const nested = candidate[\"issue\"];\n const data = candidate[\"data\"];\n for (const value of [\n candidate,\n nested,\n isRecord(data) ? data[\"issue\"] : undefined,\n ]) {\n if (!isRecord(value)) continue;\n const identifier =\n value[\"identifier\"] ?? value[\"issueIdentifier\"] ?? value[\"id\"];\n if (typeof identifier !== \"string\" || identifier.trim().length === 0) {\n continue;\n }\n const url = value[\"url\"];\n return {\n issueIdentifier: identifier,\n ...(typeof url !== \"string\" || url.trim().length === 0 ? {} : { url }),\n };\n }\n }\n return undefined;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"publication-events.js","sourceRoot":"","sources":["../src/publication-events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EACL,0BAA0B,GAG3B,MAAM,kBAAkB,CAAC;AAE1B,MAAM,CAAC,MAAM,oCAAoC,GAC/C,qEAAqE,CAAC;AAwCxE,MAAM,UAAU,wBAAwB,CACtC,MAAc,EACd,WAAoC,EACpC,cAAsB;IAEtB,MAAM,QAAQ,GAA+B,EAAE,CAAC;IAEhD,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,OAAO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AG,KAAK,CAAC,IAAI,EAAE,CAAC;IAChC,OAAO,UAAU,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC;AAC1D,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAa,EAAE,UAAkB;IAC3D,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,sBAAsB,EAAE,MAAM,CAAC,CAAC;IACnE,OAAO,IAAI,MAAM,CAAC,cAAc,OAAO,YAAY,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACxE,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC","sourcesContent":["import { isLinearIssueIdentifier, linearIssueReference } from \"./linear.js\";\nimport {\n linearPublicationArguments,\n type PreparedPublicationIssue,\n type PreparedScanPublication,\n} from \"./publication.js\";\n\nexport const MISSING_PUBLICATION_IDENTIFIER_ERROR =\n \"The connected Linear app did not return a created issue identifier.\";\n\nexport interface PublicationClaim {\n kind: \"identifier\" | \"entityId\" | \"url\";\n value: string;\n}\n\nexport type ClaimResolution =\n | { state: \"absent\"; claims: PublicationClaim[] }\n | { state: \"conflicting\"; claims: PublicationClaim[] }\n | {\n state: \"resolved\";\n claims: PublicationClaim[];\n issueIdentifier: string;\n url?: string;\n };\n\nexport interface CompletedCreateEvidence {\n source: \"event\";\n status: \"completed\";\n rawLine: string;\n ownerFindingId?: string;\n argumentsValid: boolean;\n resolution: ClaimResolution;\n}\n\nexport interface FailedCreateEvidence {\n source: \"event\";\n status: \"failed\";\n rawLine: string;\n ownerFindingId?: string;\n argumentsValid: boolean;\n resolution: ClaimResolution;\n error: string;\n}\n\nexport type PublicationEventEvidence =\n | CompletedCreateEvidence\n | FailedCreateEvidence;\n\nexport function collectPublicationEvents(\n output: string,\n publication: PreparedScanPublication,\n failureMessage: string,\n): PublicationEventEvidence[] {\n const evidence: PublicationEventEvidence[] = [];\n\n for (const rawLine of output.split(/\\r?\\n/)) {\n if (rawLine.trim().length === 0) continue;\n let event: unknown;\n try {\n event = JSON.parse(rawLine) as unknown;\n } catch {\n continue;\n }\n if (!isRecord(event) || event[\"type\"] !== \"item.completed\") continue;\n const item = event[\"item\"];\n if (!isLinearCreateCall(item)) continue;\n\n const arguments_ = item[\"arguments\"];\n const owner = isRecord(arguments_)\n ? matchPublicationIssue(publication, arguments_)\n : undefined;\n const argumentsValid =\n owner !== undefined &&\n hasExpectedPublicationArguments(publication, owner, arguments_);\n if (item[\"status\"] === \"completed\") {\n evidence.push({\n source: \"event\",\n status: \"completed\",\n rawLine,\n ...(owner === undefined ? {} : { ownerFindingId: owner.findingId }),\n argumentsValid,\n resolution: resolvePublicationClaims(item[\"result\"]),\n });\n continue;\n }\n\n const error = item[\"error\"];\n evidence.push({\n source: \"event\",\n status: \"failed\",\n rawLine,\n ...(owner === undefined ? {} : { ownerFindingId: owner.findingId }),\n argumentsValid,\n resolution: resolvePublicationClaims(item[\"result\"]),\n error:\n isRecord(error) && typeof error[\"message\"] === \"string\"\n ? error[\"message\"]\n : failureMessage,\n });\n }\n\n return evidence;\n}\n\nexport function hasExpectedPublicationArguments(\n publication: PreparedScanPublication,\n issue: PreparedPublicationIssue,\n actual: unknown,\n): boolean {\n if (!isRecord(actual)) return false;\n const expected = linearPublicationArguments(publication.destination, issue);\n return (\n Object.keys(actual).length === Object.keys(expected).length &&\n Object.entries(expected).every(\n ([key, value]) =>\n Object.hasOwn(actual, key) && Object.is(actual[key], value),\n )\n );\n}\n\nexport function matchPublicationIssue(\n publication: PreparedScanPublication,\n arguments_: Record<string, unknown>,\n): PreparedPublicationIssue | undefined {\n const exactMatches = publication.issues.filter((issue) =>\n hasExpectedPublicationArguments(publication, issue, arguments_),\n );\n if (exactMatches.length === 1) return exactMatches[0];\n\n const description = arguments_[\"description\"];\n if (typeof description !== \"string\") return undefined;\n const matches = publication.issues.filter(\n (issue) =>\n containsIdentifier(description, issue.findingId) &&\n containsIdentifier(description, issue.occurrenceId),\n );\n return matches.length === 1 ? matches[0] : undefined;\n}\n\nexport function resolvePublicationClaims(value: unknown): ClaimResolution {\n const claims: PublicationClaim[] = [];\n collectPublicationClaims(value, claims);\n return resolveClaims(claims);\n}\n\nexport function resolveClaims(\n claims: readonly PublicationClaim[],\n): ClaimResolution {\n const seen = new Set<string>();\n const normalized = claims.flatMap<PublicationClaim>((claim) => {\n const trimmed = claim.value.trim();\n if (trimmed.length === 0) return [];\n const value = isCanonicalUuid(trimmed) ? trimmed.toLowerCase() : trimmed;\n return [{ kind: claim.kind, value }];\n });\n const retained = normalized\n .filter((claim) => {\n const key = `${claim.kind}\\0${claim.value}`;\n if (seen.has(key)) return false;\n seen.add(key);\n return true;\n })\n .sort(compareClaims);\n const identifiers = new Set(\n retained\n .filter((claim) => claim.kind === \"identifier\")\n .map((claim) => claim.value),\n );\n const entityIds = new Set(\n retained\n .filter((claim) => claim.kind === \"entityId\")\n .map((claim) => claim.value),\n );\n const urls = new Set(\n retained\n .filter((claim) => claim.kind === \"url\")\n .map((claim) => claim.value),\n );\n const canonicalUrls = new Set([...urls].map(canonicalPublicationUrlClaim));\n const urlContradictsIdentifier =\n identifiers.size > 0 &&\n [...urls]\n .map(linearIssueReferenceFromUrl)\n .some(\n (reference) =>\n reference !== undefined && !identifiers.has(reference.id),\n );\n const overlappingIdentity = [...identifiers].some((identifier) =>\n entityIds.has(identifier),\n );\n if (\n identifiers.size > 1 ||\n entityIds.size > 1 ||\n canonicalUrls.size > 1 ||\n urlContradictsIdentifier ||\n overlappingIdentity\n ) {\n return { state: \"conflicting\", claims: retained };\n }\n if (identifiers.size === 0) {\n return { state: \"absent\", claims: retained };\n }\n return {\n state: \"resolved\",\n claims: retained,\n issueIdentifier: identifiers.values().next().value!,\n ...(urls.size === 0 ? {} : { url: urls.values().next().value! }),\n };\n}\n\nfunction isLinearCreateCall(item: unknown): item is Record<string, unknown> {\n return (\n isRecord(item) &&\n item[\"type\"] === \"mcp_tool_call\" &&\n item[\"server\"] === \"codex_apps\" &&\n (item[\"tool\"] === \"linear.save_issue\" ||\n item[\"tool\"] === \"linear_save_issue\")\n );\n}\n\nfunction collectPublicationClaims(\n value: unknown,\n claims: PublicationClaim[],\n): void {\n const visited = new Set<Record<string, unknown>>();\n const pending: unknown[] = [value];\n while (pending.length > 0) {\n const candidate = pending.pop();\n if (!isRecord(candidate) || visited.has(candidate)) continue;\n visited.add(candidate);\n collectDirectClaims(candidate, claims);\n\n const data = candidate[\"data\"];\n const nested: unknown[] = [\n candidate[\"structured_content\"],\n candidate[\"structuredContent\"],\n candidate[\"issue\"],\n isRecord(data) ? data[\"issue\"] : undefined,\n ];\n if (Array.isArray(candidate[\"content\"])) {\n for (const content of candidate[\"content\"]) {\n if (!isRecord(content) || typeof content[\"text\"] !== \"string\") {\n continue;\n }\n try {\n nested.push(JSON.parse(content[\"text\"]) as unknown);\n } catch {\n continue;\n }\n }\n }\n for (let index = nested.length - 1; index >= 0; index -= 1) {\n if (isRecord(nested[index])) pending.push(nested[index]);\n }\n }\n}\n\nfunction collectDirectClaims(\n candidate: Record<string, unknown>,\n claims: PublicationClaim[],\n): void {\n for (const field of [\"identifier\", \"issueIdentifier\", \"key\", \"id\"] as const) {\n const claim = classifyIdentityClaim(field, candidate[field]);\n if (claim !== undefined) claims.push(claim);\n }\n const url = candidate[\"url\"];\n const normalizedUrl = normalizeNonemptyString(url);\n if (normalizedUrl !== undefined) {\n claims.push({ kind: \"url\", value: normalizedUrl });\n }\n}\n\nfunction classifyIdentityClaim(\n field: \"identifier\" | \"issueIdentifier\" | \"key\" | \"id\",\n value: unknown,\n): PublicationClaim | undefined {\n const normalized = normalizeNonemptyString(value);\n if (normalized === undefined) return undefined;\n if (isCanonicalUuid(normalized)) {\n return { kind: \"entityId\", value: normalized };\n }\n if (field === \"identifier\" || field === \"issueIdentifier\") {\n return { kind: \"identifier\", value: normalized };\n }\n if (isLinearIssueIdentifier(normalized)) {\n return { kind: \"identifier\", value: normalized };\n }\n return field === \"id\" ? { kind: \"entityId\", value: normalized } : undefined;\n}\n\nfunction compareClaims(\n left: PublicationClaim,\n right: PublicationClaim,\n): number {\n const order = { identifier: 0, entityId: 1, url: 2 } as const;\n const kindOrder = order[left.kind] - order[right.kind];\n if (kindOrder !== 0) return kindOrder;\n if (left.value === right.value) return 0;\n return left.value < right.value ? -1 : 1;\n}\n\nfunction isCanonicalUuid(value: string): boolean {\n return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/iu.test(\n value,\n );\n}\n\nfunction linearIssueReferenceFromUrl(\n value: string,\n): { id: string; workspace: string } | undefined {\n let url: URL;\n try {\n url = new URL(value);\n } catch {\n return undefined;\n }\n if (url.protocol !== \"https:\" || url.hostname !== \"linear.app\") {\n return undefined;\n }\n try {\n const reference = linearIssueReference(value);\n return reference.workspace === undefined\n ? undefined\n : { id: reference.id, workspace: reference.workspace };\n } catch {\n return undefined;\n }\n}\n\nfunction canonicalPublicationUrlClaim(value: string): string {\n const reference = linearIssueReferenceFromUrl(value);\n return reference === undefined\n ? `raw:\\0${value}`\n : `linear:\\0${reference.workspace}\\0${reference.id}`;\n}\n\nexport function publicationClaimAliases(\n claim: PublicationClaim,\n): PublicationClaim[] {\n if (claim.kind !== \"url\") return [claim];\n const reference = linearIssueReferenceFromUrl(claim.value);\n return reference === undefined\n ? [claim]\n : [claim, { kind: \"identifier\", value: reference.id }];\n}\n\nfunction normalizeNonemptyString(value: unknown): string | undefined {\n if (typeof value !== \"string\") return undefined;\n const normalized = value.trim();\n return normalized.length === 0 ? undefined : normalized;\n}\n\nfunction containsIdentifier(value: string, identifier: string): boolean {\n const escaped = identifier.replace(/[.*+?^${}()|[\\]\\\\]/gu, \"\\\\$&\");\n return new RegExp(`(?<![\\\\w-])${escaped}(?![\\\\w-])`, \"u\").test(value);\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { PreparedScanPublication } from "./publication.js";
|
|
2
2
|
import type { PublishedScanIssue } from "./publish.js";
|
|
3
|
+
export declare function inspectPublicationStore(publication: PreparedScanPublication, environment: NodeJS.ProcessEnv, signal?: AbortSignal): Promise<PublishedScanIssue[]>;
|
|
3
4
|
export declare function preparePublicationStore(publication: PreparedScanPublication, environment: NodeJS.ProcessEnv): Promise<void>;
|
|
4
5
|
export declare function recordPublishedIssues(publication: PreparedScanPublication, issues: readonly PublishedScanIssue[], environment: NodeJS.ProcessEnv): Promise<PublishedScanIssue[]>;
|
|
5
6
|
//# sourceMappingURL=publication-store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publication-store.d.ts","sourceRoot":"","sources":["../src/publication-store.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"publication-store.d.ts","sourceRoot":"","sources":["../src/publication-store.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AASvD,wBAAsB,uBAAuB,CAC3C,WAAW,EAAE,uBAAuB,EACpC,WAAW,EAAE,MAAM,CAAC,UAAU,EAC9B,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAkC/B;AAED,wBAAsB,uBAAuB,CAC3C,WAAW,EAAE,uBAAuB,EACpC,WAAW,EAAE,MAAM,CAAC,UAAU,GAC7B,OAAO,CAAC,IAAI,CAAC,CAcf;AAED,wBAAsB,qBAAqB,CACzC,WAAW,EAAE,uBAAuB,EACpC,MAAM,EAAE,SAAS,kBAAkB,EAAE,EACrC,WAAW,EAAE,MAAM,CAAC,UAAU,GAC7B,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAuC/B"}
|
|
@@ -1,7 +1,31 @@
|
|
|
1
|
-
import { mkdtemp, rm, stat, writeFile } from "node:fs/promises";
|
|
1
|
+
import { mkdtemp, realpath, rm, stat, writeFile } from "node:fs/promises";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
2
3
|
import { join } from "node:path";
|
|
3
4
|
import { CodexSecurityError } from "./errors.js";
|
|
4
|
-
import { bundledPluginRoot, codexSecurityStateDirectory, resolvePluginPython, runWorkbench, } from "./runtime.js";
|
|
5
|
+
import { bundledPluginRoot, codexSecurityStateDirectory, requireOutputOutsideRepository, resolvePluginPython, runWorkbench, } from "./runtime.js";
|
|
6
|
+
export async function inspectPublicationStore(publication, environment, signal) {
|
|
7
|
+
const result = await runPublicationWorkbench("inspect-linear-publication", publication, environment, undefined, signal);
|
|
8
|
+
const recorded = result["recorded"];
|
|
9
|
+
if (!matchesPublication(result, publication) ||
|
|
10
|
+
result["findingCount"] !== publication.issues.length ||
|
|
11
|
+
!Array.isArray(recorded)) {
|
|
12
|
+
throw invalidPublicationRecords();
|
|
13
|
+
}
|
|
14
|
+
const expected = new Map(publication.issues.map((issue) => [issue.findingId, issue.occurrenceId]));
|
|
15
|
+
const found = new Map();
|
|
16
|
+
for (const value of recorded) {
|
|
17
|
+
const issue = readPublicationRecord(value);
|
|
18
|
+
if (expected.get(issue.findingId) !== issue.occurrenceId ||
|
|
19
|
+
found.has(issue.findingId)) {
|
|
20
|
+
throw invalidPublicationRecords();
|
|
21
|
+
}
|
|
22
|
+
found.set(issue.findingId, issue);
|
|
23
|
+
}
|
|
24
|
+
return publication.issues.flatMap(({ findingId }) => {
|
|
25
|
+
const issue = found.get(findingId);
|
|
26
|
+
return issue === undefined ? [] : [issue];
|
|
27
|
+
});
|
|
28
|
+
}
|
|
5
29
|
export async function preparePublicationStore(publication, environment) {
|
|
6
30
|
const result = await runPublicationWorkbench("prepare-linear-publication", publication, environment);
|
|
7
31
|
if (result["scanId"] !== publication.scanId ||
|
|
@@ -12,12 +36,7 @@ export async function preparePublicationStore(publication, environment) {
|
|
|
12
36
|
export async function recordPublishedIssues(publication, issues, environment) {
|
|
13
37
|
const result = await runPublicationWorkbench("record-linear-publications", publication, environment, issues);
|
|
14
38
|
const created = result["created"];
|
|
15
|
-
|
|
16
|
-
if (result["scanId"] !== publication.scanId ||
|
|
17
|
-
!isRecord(destination) ||
|
|
18
|
-
destination["type"] !== publication.destination.type ||
|
|
19
|
-
destination["teamId"] !== publication.destination.teamId ||
|
|
20
|
-
destination["projectId"] !== publication.destination.projectId ||
|
|
39
|
+
if (!matchesPublication(result, publication) ||
|
|
21
40
|
!Array.isArray(created) ||
|
|
22
41
|
created.length !== issues.length) {
|
|
23
42
|
throw invalidPublicationRecords();
|
|
@@ -32,24 +51,19 @@ export async function recordPublishedIssues(publication, issues, environment) {
|
|
|
32
51
|
}
|
|
33
52
|
return created.map((value, index) => {
|
|
34
53
|
const expectedIssue = ordered[index];
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
(
|
|
41
|
-
(expectedIssue.url !== undefined && value["url"] !== expectedIssue.url)) {
|
|
54
|
+
const issue = readPublicationRecord(value);
|
|
55
|
+
if (expectedIssue === undefined ||
|
|
56
|
+
issue.findingId !== expectedIssue.findingId ||
|
|
57
|
+
issue.occurrenceId !== expectedIssue.occurrenceId ||
|
|
58
|
+
issue.issueIdentifier !== expectedIssue.issueIdentifier ||
|
|
59
|
+
(expectedIssue.url !== undefined && issue.url !== expectedIssue.url)) {
|
|
42
60
|
throw invalidPublicationRecords();
|
|
43
61
|
}
|
|
44
|
-
return
|
|
45
|
-
findingId: value["findingId"],
|
|
46
|
-
occurrenceId: value["occurrenceId"],
|
|
47
|
-
issueIdentifier: value["issueIdentifier"],
|
|
48
|
-
...(typeof value["url"] === "string" ? { url: value["url"] } : {}),
|
|
49
|
-
};
|
|
62
|
+
return issue;
|
|
50
63
|
});
|
|
51
64
|
}
|
|
52
|
-
async function runPublicationWorkbench(command, publication, environment, issues) {
|
|
65
|
+
async function runPublicationWorkbench(command, publication, environment, issues, signal) {
|
|
66
|
+
signal?.throwIfAborted();
|
|
53
67
|
const stateDirectory = codexSecurityStateDirectory(environment);
|
|
54
68
|
const database = join(stateDirectory, "workbench.sqlite3");
|
|
55
69
|
try {
|
|
@@ -63,14 +77,22 @@ async function runPublicationWorkbench(command, publication, environment, issues
|
|
|
63
77
|
resolvePluginPython({
|
|
64
78
|
environment,
|
|
65
79
|
protectedRoot: publication.scanDirectory,
|
|
80
|
+
...(signal === undefined ? {} : { signal }),
|
|
66
81
|
}),
|
|
67
82
|
bundledPluginRoot(),
|
|
68
83
|
]);
|
|
84
|
+
signal?.throwIfAborted();
|
|
69
85
|
const findings = publication.issues.map(({ findingId, occurrenceId }) => ({
|
|
70
86
|
findingId,
|
|
71
87
|
occurrenceId,
|
|
72
88
|
}));
|
|
73
|
-
|
|
89
|
+
let temporaryRoot = stateDirectory;
|
|
90
|
+
if (command === "inspect-linear-publication") {
|
|
91
|
+
temporaryRoot = await realpath(tmpdir());
|
|
92
|
+
const scanRoot = await realpath(publication.scanDirectory);
|
|
93
|
+
requireOutputOutsideRepository(scanRoot, temporaryRoot, "temporary");
|
|
94
|
+
}
|
|
95
|
+
const directory = await mkdtemp(join(temporaryRoot, "publication-"));
|
|
74
96
|
try {
|
|
75
97
|
const input = join(directory, "publication.json");
|
|
76
98
|
await writeFile(input, JSON.stringify({
|
|
@@ -84,15 +106,40 @@ async function runPublicationWorkbench(command, publication, environment, issues
|
|
|
84
106
|
python,
|
|
85
107
|
pluginRoot,
|
|
86
108
|
environment,
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
109
|
+
...(signal === undefined ? {} : { signal }),
|
|
110
|
+
failureMessage: command === "record-linear-publications"
|
|
111
|
+
? "Could not persist created Linear issues in the local Codex Security scan history"
|
|
112
|
+
: "Cannot publish findings without their existing local Codex Security scan history",
|
|
90
113
|
}, [command, "--input-file", input]);
|
|
91
114
|
}
|
|
92
115
|
finally {
|
|
93
116
|
await rm(directory, { recursive: true, force: true }).catch(() => undefined);
|
|
94
117
|
}
|
|
95
118
|
}
|
|
119
|
+
function matchesPublication(result, publication) {
|
|
120
|
+
const destination = result["destination"];
|
|
121
|
+
return (result["scanId"] === publication.scanId &&
|
|
122
|
+
isRecord(destination) &&
|
|
123
|
+
destination["type"] === publication.destination.type &&
|
|
124
|
+
destination["teamId"] === publication.destination.teamId &&
|
|
125
|
+
destination["projectId"] === publication.destination.projectId);
|
|
126
|
+
}
|
|
127
|
+
function readPublicationRecord(value) {
|
|
128
|
+
if (!isRecord(value) ||
|
|
129
|
+
typeof value["findingId"] !== "string" ||
|
|
130
|
+
typeof value["occurrenceId"] !== "string" ||
|
|
131
|
+
typeof value["issueIdentifier"] !== "string" ||
|
|
132
|
+
!value["issueIdentifier"].trim() ||
|
|
133
|
+
(value["url"] !== undefined && typeof value["url"] !== "string")) {
|
|
134
|
+
throw invalidPublicationRecords();
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
findingId: value["findingId"],
|
|
138
|
+
occurrenceId: value["occurrenceId"],
|
|
139
|
+
issueIdentifier: value["issueIdentifier"],
|
|
140
|
+
...(typeof value["url"] === "string" ? { url: value["url"] } : {}),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
96
143
|
function invalidPublicationRecords() {
|
|
97
144
|
return new CodexSecurityError("The workbench returned invalid persisted Linear publication records.");
|
|
98
145
|
}
|