@openai/codex-security 0.1.15 → 0.1.16
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 +20 -0
- package/_bundled_plugin/references/sarif-adapter.md +3 -1
- package/_bundled_plugin/scripts/finalize_scan_contract.py +67 -6
- package/_bundled_plugin/skills/verify-fix/SKILL.md +44 -0
- package/_bundled_plugin/skills/verify-fix/agents/openai.yaml +4 -0
- package/dist/cli.d.ts +7 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +446 -19
- package/dist/cli.js.map +1 -1
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +3 -0
- package/dist/cost.js.map +1 -1
- package/dist/scan-dashboard.d.ts +1 -1
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +8 -5
- package/dist/scan-dashboard.js.map +1 -1
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -352,6 +352,148 @@ class PublicationProgressPresenter {
|
|
|
352
352
|
this.#stream.write(`${visible}\n`);
|
|
353
353
|
}
|
|
354
354
|
}
|
|
355
|
+
class VerificationProgressPresenter {
|
|
356
|
+
#stream;
|
|
357
|
+
#dependencies;
|
|
358
|
+
#repository;
|
|
359
|
+
#total;
|
|
360
|
+
#seenActivities = new Set();
|
|
361
|
+
#reasoning = new Map();
|
|
362
|
+
#dashboard = null;
|
|
363
|
+
constructor(stream, dependencies, repository, total) {
|
|
364
|
+
this.#stream = stream;
|
|
365
|
+
this.#dependencies = dependencies;
|
|
366
|
+
this.#repository = repository;
|
|
367
|
+
this.#total = total;
|
|
368
|
+
}
|
|
369
|
+
start() {
|
|
370
|
+
if (this.#stream.isTTY === true &&
|
|
371
|
+
this.#dependencies.environment["CI"] === undefined &&
|
|
372
|
+
this.#dependencies.environment["TERM"] !== "dumb") {
|
|
373
|
+
const dashboard = new ScanDashboard(this.#stream, {
|
|
374
|
+
repository: this.#repository,
|
|
375
|
+
presentation: "verification",
|
|
376
|
+
clock: this.#dependencies,
|
|
377
|
+
color: this.#dependencies.environment["NO_COLOR"] === undefined,
|
|
378
|
+
sanitize: safeErrorMessage,
|
|
379
|
+
});
|
|
380
|
+
dashboard.setPublicationProgress(0, this.#total);
|
|
381
|
+
dashboard.setStage(`Verifying findings · 0/${this.#total}`);
|
|
382
|
+
try {
|
|
383
|
+
dashboard.start();
|
|
384
|
+
this.#dashboard = dashboard;
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
catch {
|
|
388
|
+
try {
|
|
389
|
+
dashboard.stop();
|
|
390
|
+
}
|
|
391
|
+
catch { }
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
this.#write(`Verifying ${this.#total} finding${this.#total === 1 ? "" : "s"} against the current checkout.`);
|
|
395
|
+
}
|
|
396
|
+
observe(event) {
|
|
397
|
+
const method = event["method"];
|
|
398
|
+
const params = event["params"];
|
|
399
|
+
if (typeof params !== "object" ||
|
|
400
|
+
params === null ||
|
|
401
|
+
Array.isArray(params)) {
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
const values = params;
|
|
405
|
+
let normalized;
|
|
406
|
+
if (method === "item/reasoning/summaryTextDelta") {
|
|
407
|
+
const id = values["itemId"];
|
|
408
|
+
const delta = values["delta"];
|
|
409
|
+
if (typeof id !== "string" || typeof delta !== "string")
|
|
410
|
+
return;
|
|
411
|
+
const text = `${this.#reasoning.get(id) ?? ""}${delta}`;
|
|
412
|
+
this.#reasoning.set(id, text);
|
|
413
|
+
normalized = {
|
|
414
|
+
type: "item.updated",
|
|
415
|
+
item: { id, type: "reasoning", text },
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
else if (method === "item/started" || method === "item/completed") {
|
|
419
|
+
const item = values["item"];
|
|
420
|
+
if (typeof item !== "object" || item === null || Array.isArray(item)) {
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
const current = item;
|
|
424
|
+
const type = current["type"];
|
|
425
|
+
let converted;
|
|
426
|
+
if (type === "commandExecution") {
|
|
427
|
+
converted = { ...current, type: "command_execution" };
|
|
428
|
+
}
|
|
429
|
+
else if (type === "mcpToolCall") {
|
|
430
|
+
converted = { ...current, type: "mcp_tool_call" };
|
|
431
|
+
}
|
|
432
|
+
else if (type === "agentMessage") {
|
|
433
|
+
if (current["phase"] !== "commentary")
|
|
434
|
+
return;
|
|
435
|
+
converted = { ...current, type: "agent_message" };
|
|
436
|
+
}
|
|
437
|
+
else if (type === "reasoning") {
|
|
438
|
+
const summary = current["summary"];
|
|
439
|
+
const text = Array.isArray(summary)
|
|
440
|
+
? summary
|
|
441
|
+
.filter((entry) => typeof entry === "string")
|
|
442
|
+
.join("\n")
|
|
443
|
+
: current["text"];
|
|
444
|
+
if (typeof text !== "string")
|
|
445
|
+
return;
|
|
446
|
+
converted = { ...current, text };
|
|
447
|
+
}
|
|
448
|
+
else {
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
normalized = {
|
|
452
|
+
type: method === "item/started" ? "item.started" : "item.completed",
|
|
453
|
+
item: converted,
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
else {
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
for (const activity of scanActivitiesFromEvent(normalized, this.#repository)) {
|
|
460
|
+
if (this.#dashboard !== null) {
|
|
461
|
+
this.#dashboard.record(activity);
|
|
462
|
+
continue;
|
|
463
|
+
}
|
|
464
|
+
const key = `${activity.id}\0${activity.description}`;
|
|
465
|
+
if (this.#seenActivities.has(key))
|
|
466
|
+
continue;
|
|
467
|
+
this.#seenActivities.add(key);
|
|
468
|
+
const label = activity.kind === "reasoning" || activity.kind === "message"
|
|
469
|
+
? "Codex"
|
|
470
|
+
: "Tool";
|
|
471
|
+
this.#write(`${label}: ${activity.description}`);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
complete(results) {
|
|
475
|
+
if (this.#dashboard === null)
|
|
476
|
+
return;
|
|
477
|
+
this.#dashboard.setPublicationProgress(results.length, this.#total);
|
|
478
|
+
this.#dashboard.setStage(`Verification complete · ${results.length}/${this.#total}`);
|
|
479
|
+
for (const result of results) {
|
|
480
|
+
this.#dashboard.note(`${result.status.toUpperCase()} ${result.id}`);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
stop() {
|
|
484
|
+
try {
|
|
485
|
+
this.#dashboard?.stop();
|
|
486
|
+
}
|
|
487
|
+
catch { }
|
|
488
|
+
this.#dashboard = null;
|
|
489
|
+
}
|
|
490
|
+
#write(message) {
|
|
491
|
+
try {
|
|
492
|
+
this.#stream.write(`${safePatchText(message)}\n`);
|
|
493
|
+
}
|
|
494
|
+
catch { }
|
|
495
|
+
}
|
|
496
|
+
}
|
|
355
497
|
function effortOption() {
|
|
356
498
|
return z
|
|
357
499
|
.enum(MODEL_REASONING_EFFORTS, {
|
|
@@ -449,6 +591,11 @@ const findingPatchSchema = z.object({
|
|
|
449
591
|
verification: z.string().optional(),
|
|
450
592
|
reason: z.string().optional(),
|
|
451
593
|
});
|
|
594
|
+
const findingVerificationSchema = z.object({
|
|
595
|
+
id: z.string(),
|
|
596
|
+
status: z.enum(["fixed", "still_vulnerable", "inconclusive"]),
|
|
597
|
+
evidence: z.string().trim().min(1),
|
|
598
|
+
});
|
|
452
599
|
const DEFAULT_DEPENDENCIES = {
|
|
453
600
|
createSecurity: (config) => createSecurityInternal(config, { surface: "cli" }),
|
|
454
601
|
environment: process.env,
|
|
@@ -625,8 +772,11 @@ export async function runCodexSkillCommand(args, output, command = resolveCodexC
|
|
|
625
772
|
readSkillCommandOutput(invocation.stdout, output.appServer === undefined
|
|
626
773
|
? undefined
|
|
627
774
|
: {
|
|
775
|
+
directory: output.appServer.directory,
|
|
628
776
|
prompt: output.appServer.prompt,
|
|
629
777
|
input: invocation.stdin,
|
|
778
|
+
sandbox: output.appServer.sandbox,
|
|
779
|
+
onEvent: output.appServer.onEvent,
|
|
630
780
|
}),
|
|
631
781
|
new Promise((resolve) => {
|
|
632
782
|
forceCaptureCompletion = () => resolve(undefined);
|
|
@@ -1404,7 +1554,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1404
1554
|
},
|
|
1405
1555
|
});
|
|
1406
1556
|
const cli = Cli.create("codex-security", {
|
|
1407
|
-
description: "Run, validate, patch, export, and publish Codex Security findings.",
|
|
1557
|
+
description: "Run, validate, patch, verify fixes, export, and publish Codex Security findings.",
|
|
1408
1558
|
version: VERSION,
|
|
1409
1559
|
mcp: {
|
|
1410
1560
|
command: "npx --yes @openai/codex-security --mcp",
|
|
@@ -1914,6 +2064,164 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
|
|
|
1914
2064
|
errorOutput.write(`codex-security: ${errorMessage(error)}\n`);
|
|
1915
2065
|
}
|
|
1916
2066
|
},
|
|
2067
|
+
})
|
|
2068
|
+
.command("verify-fix", {
|
|
2069
|
+
description: "Verify existing security fixes without changing the repository.",
|
|
2070
|
+
destructive: false,
|
|
2071
|
+
mcp: false,
|
|
2072
|
+
args: z.object({
|
|
2073
|
+
"findings...": z
|
|
2074
|
+
.string()
|
|
2075
|
+
.min(1, "A finding must not be empty.")
|
|
2076
|
+
.optional()
|
|
2077
|
+
.describe("Finding text, a file, or a saved finding identifier."),
|
|
2078
|
+
}),
|
|
2079
|
+
options: z.object({
|
|
2080
|
+
effort: effortOption(),
|
|
2081
|
+
scan: optionValue("--scan")
|
|
2082
|
+
.optional()
|
|
2083
|
+
.describe("Verify open findings from a saved scan."),
|
|
2084
|
+
severity: z
|
|
2085
|
+
.enum(REPORTABLE_SEVERITIES)
|
|
2086
|
+
.optional()
|
|
2087
|
+
.describe("Verify saved findings at or above LEVEL."),
|
|
2088
|
+
linearIssue: z
|
|
2089
|
+
.array(optionValue("--linear-issue"))
|
|
2090
|
+
.default([])
|
|
2091
|
+
.describe("Linear issue identifier or URL; repeat for more issues."),
|
|
2092
|
+
linearProject: optionValue("--linear-project")
|
|
2093
|
+
.optional()
|
|
2094
|
+
.describe("Verify issues in this Linear project."),
|
|
2095
|
+
linearFilter: optionValue("--linear-filter")
|
|
2096
|
+
.optional()
|
|
2097
|
+
.describe("JSON Linear issue filter for --linear-project."),
|
|
2098
|
+
linearApiKey: linearApiKeyOption(),
|
|
2099
|
+
codex: z
|
|
2100
|
+
.array(optionValue("--codex"))
|
|
2101
|
+
.default([])
|
|
2102
|
+
.describe('Repeat TOML model="gpt-5.6-terra" or model_reasoning_effort="high" only.'),
|
|
2103
|
+
}),
|
|
2104
|
+
output: z.record(z.string(), z.unknown()).optional(),
|
|
2105
|
+
async run({ format, options }) {
|
|
2106
|
+
try {
|
|
2107
|
+
const linear = options.linearIssue.length > 0 || !!options.linearProject;
|
|
2108
|
+
if (options.linearIssue.length > 0 && options.linearProject) {
|
|
2109
|
+
throw new CodexSecurityError("Use either --linear-issue or --linear-project, not both.");
|
|
2110
|
+
}
|
|
2111
|
+
if (options.linearFilter && !options.linearProject) {
|
|
2112
|
+
throw new CodexSecurityError("--linear-filter requires --linear-project.");
|
|
2113
|
+
}
|
|
2114
|
+
if (options.linearApiKey !== undefined && !linear) {
|
|
2115
|
+
throw new CodexSecurityError("--linear-api-key requires --linear-issue or --linear-project.");
|
|
2116
|
+
}
|
|
2117
|
+
const savedFindings = options.scan !== undefined ||
|
|
2118
|
+
(positionals.length > 0 && positionals.every(isFindingIdentifier));
|
|
2119
|
+
if (savedFindings && linear) {
|
|
2120
|
+
throw new CodexSecurityError("Saved findings cannot be combined with Linear issues or projects.");
|
|
2121
|
+
}
|
|
2122
|
+
if (options.severity !== undefined && !savedFindings) {
|
|
2123
|
+
throw new CodexSecurityError("--severity requires a saved finding identifier or --scan.");
|
|
2124
|
+
}
|
|
2125
|
+
if (positionals.length === 0 && !linear && !savedFindings) {
|
|
2126
|
+
throw new CodexSecurityError("Verify-fix requires a finding, --scan, --linear-issue, or --linear-project.");
|
|
2127
|
+
}
|
|
2128
|
+
const selected = savedFindings
|
|
2129
|
+
? await selectSavedFindings(positionals, options.scan, options.severity, dependencies)
|
|
2130
|
+
: undefined;
|
|
2131
|
+
const imports = linear
|
|
2132
|
+
? await importLinearIssues({
|
|
2133
|
+
issues: options.linearIssue,
|
|
2134
|
+
project: options.linearProject,
|
|
2135
|
+
filter: options.linearFilter,
|
|
2136
|
+
apiKey: options.linearApiKey,
|
|
2137
|
+
environment: dependencies.environment,
|
|
2138
|
+
linearClient: dependencies.linearClient,
|
|
2139
|
+
})
|
|
2140
|
+
: [];
|
|
2141
|
+
const identifiers = selected === undefined
|
|
2142
|
+
? [
|
|
2143
|
+
...positionals.map((_finding, index) => `finding-${index + 1}`),
|
|
2144
|
+
...imports.map(({ id }) => id),
|
|
2145
|
+
]
|
|
2146
|
+
: selected.findings.map(({ occurrenceId }) => occurrenceId);
|
|
2147
|
+
if (new Set(identifiers).size !== identifiers.length) {
|
|
2148
|
+
throw new CodexSecurityError("Verification inputs must have unique finding or issue identifiers.");
|
|
2149
|
+
}
|
|
2150
|
+
const repository = selected?.repository ?? dependencies.currentDirectory();
|
|
2151
|
+
let results = [];
|
|
2152
|
+
if (identifiers.length > 0) {
|
|
2153
|
+
const environment = imports.length === 0
|
|
2154
|
+
? undefined
|
|
2155
|
+
: Object.fromEntries(Object.entries(dependencies.environment).filter(([name]) => !/^(?:CODEX_SECURITY_)?LINEAR_(?:API_KEY|ACCESS_TOKEN)$/iu.test(name)));
|
|
2156
|
+
let response = "";
|
|
2157
|
+
const verificationOutput = {
|
|
2158
|
+
write(value) {
|
|
2159
|
+
response += value.toString();
|
|
2160
|
+
return true;
|
|
2161
|
+
},
|
|
2162
|
+
};
|
|
2163
|
+
const progress = new VerificationProgressPresenter(errorOutput, dependencies, repository, identifiers.length);
|
|
2164
|
+
progress.start();
|
|
2165
|
+
try {
|
|
2166
|
+
exitCode = await runSkill("verify-fix", selected === undefined ? [...positionals, ...imports] : [], options.codex, options.effort, verificationOutput, errorOutput, dependencies, {
|
|
2167
|
+
directory: repository,
|
|
2168
|
+
...(selected === undefined
|
|
2169
|
+
? {}
|
|
2170
|
+
: { findings: selected.findings }),
|
|
2171
|
+
verificationIds: identifiers,
|
|
2172
|
+
environment,
|
|
2173
|
+
onEvent: progress.observe.bind(progress),
|
|
2174
|
+
});
|
|
2175
|
+
if (exitCode !== 0) {
|
|
2176
|
+
if (exitCode !== 130 && exitCode !== 143)
|
|
2177
|
+
exitCode = 2;
|
|
2178
|
+
return undefined;
|
|
2179
|
+
}
|
|
2180
|
+
let reported;
|
|
2181
|
+
try {
|
|
2182
|
+
reported = JSON.parse(response);
|
|
2183
|
+
}
|
|
2184
|
+
catch {
|
|
2185
|
+
throw new CodexSecurityError("Verification results were not valid JSON.");
|
|
2186
|
+
}
|
|
2187
|
+
const parsed = z
|
|
2188
|
+
.object({ results: z.array(findingVerificationSchema) })
|
|
2189
|
+
.safeParse(reported);
|
|
2190
|
+
if (!parsed.success ||
|
|
2191
|
+
parsed.data.results.length !== identifiers.length ||
|
|
2192
|
+
parsed.data.results.some(({ id }, index) => id !== identifiers[index])) {
|
|
2193
|
+
throw new CodexSecurityError("Codex did not return an evidence-backed verification result for every finding.");
|
|
2194
|
+
}
|
|
2195
|
+
results = parsed.data.results;
|
|
2196
|
+
progress.complete(results);
|
|
2197
|
+
exitCode = results.some(({ status }) => status === "inconclusive")
|
|
2198
|
+
? 2
|
|
2199
|
+
: results.some(({ status }) => status === "still_vulnerable")
|
|
2200
|
+
? 1
|
|
2201
|
+
: 0;
|
|
2202
|
+
}
|
|
2203
|
+
finally {
|
|
2204
|
+
progress.stop();
|
|
2205
|
+
}
|
|
2206
|
+
}
|
|
2207
|
+
if (format === "json" || format === "jsonl") {
|
|
2208
|
+
return {
|
|
2209
|
+
repository,
|
|
2210
|
+
...(selected === undefined ? {} : { scanId: selected.scanId }),
|
|
2211
|
+
results,
|
|
2212
|
+
};
|
|
2213
|
+
}
|
|
2214
|
+
for (const result of results) {
|
|
2215
|
+
output.write(`${result.status.toUpperCase()} ${safePatchText(result.id)}: ${safePatchText(result.evidence)}\n`);
|
|
2216
|
+
}
|
|
2217
|
+
return undefined;
|
|
2218
|
+
}
|
|
2219
|
+
catch (error) {
|
|
2220
|
+
exitCode = 2;
|
|
2221
|
+
errorOutput.write(`codex-security: ${safeErrorMessage(error)}\n`);
|
|
2222
|
+
return undefined;
|
|
2223
|
+
}
|
|
2224
|
+
},
|
|
1917
2225
|
})
|
|
1918
2226
|
.command("patch", {
|
|
1919
2227
|
description: "Patch one or more security issues.",
|
|
@@ -2334,6 +2642,7 @@ function validateCliArguments(argv, positionals) {
|
|
|
2334
2642
|
"export",
|
|
2335
2643
|
"publish",
|
|
2336
2644
|
"validate",
|
|
2645
|
+
"verify-fix",
|
|
2337
2646
|
"patch",
|
|
2338
2647
|
"login",
|
|
2339
2648
|
"logout",
|
|
@@ -2428,6 +2737,7 @@ function validateCliArguments(argv, positionals) {
|
|
|
2428
2737
|
}
|
|
2429
2738
|
}
|
|
2430
2739
|
if (command !== "validate" &&
|
|
2740
|
+
command !== "verify-fix" &&
|
|
2431
2741
|
command !== "patch" &&
|
|
2432
2742
|
positionals.length >
|
|
2433
2743
|
(command === "logout" || command === "info"
|
|
@@ -2839,13 +3149,25 @@ async function runSkill(skill, inputs, codexOverrides, effort, stdout, stderr, d
|
|
|
2839
3149
|
contents.push(contentsOrLiteral);
|
|
2840
3150
|
}
|
|
2841
3151
|
const plugin = await bundledPluginRoot();
|
|
2842
|
-
const
|
|
3152
|
+
const verify = skill === "verify-fix";
|
|
3153
|
+
const inputLabel = skill === "validation" || verify ? "Findings" : "Issues";
|
|
2843
3154
|
const prompt = [
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
3155
|
+
...(verify
|
|
3156
|
+
? [
|
|
3157
|
+
"Use the bundled $codex-security:verify-fix skill. Its complete instructions and shared assessment reference are provided below; do not reread either file.",
|
|
3158
|
+
await readFile(join(plugin, "skills", "verify-fix", "SKILL.md"), "utf8"),
|
|
3159
|
+
"Shared static finding assessment reference:",
|
|
3160
|
+
await readFile(join(plugin, "references", "static-finding-assessment.md"), "utf8"),
|
|
3161
|
+
`Expected result identifiers (JSON array): ${JSON.stringify(options.verificationIds)}`,
|
|
3162
|
+
"Return exactly one evidence-backed result per expected identifier in the same order, following the skill's JSON result contract.",
|
|
3163
|
+
]
|
|
2847
3164
|
: [
|
|
2848
|
-
|
|
3165
|
+
`Use the bundled $codex-security:${skill} skill at ${JSON.stringify(join(plugin, "skills", skill, "SKILL.md"))}.`,
|
|
3166
|
+
...(options.findings === undefined
|
|
3167
|
+
? []
|
|
3168
|
+
: [
|
|
3169
|
+
'Return exactly one JSON object with a "patches" array. Include one object for every supplied finding: {"occurrenceId":"...","status":"verified|no_change|blocked|failed","files":["relative/path"],"verification":"proof that the original issue is fixed and legitimate behavior still works","reason":"required for blocked or failed outcomes"}. Use "verified" only after the original issue no longer reproduces and relevant checks pass. Preserve unrelated local changes.',
|
|
3170
|
+
]),
|
|
2849
3171
|
]),
|
|
2850
3172
|
...(options.findingInstructions === undefined
|
|
2851
3173
|
? []
|
|
@@ -2857,11 +3179,12 @@ async function runSkill(skill, inputs, codexOverrides, effort, stdout, stderr, d
|
|
|
2857
3179
|
JSON.stringify(contents),
|
|
2858
3180
|
].join("\n");
|
|
2859
3181
|
const patch = skill === "fix-finding";
|
|
3182
|
+
const appServer = patch || verify;
|
|
2860
3183
|
return dependencies.runCodex([
|
|
2861
|
-
...(
|
|
3184
|
+
...(appServer ? ["app-server"] : ["exec", "--ignore-user-config"]),
|
|
2862
3185
|
"--disable",
|
|
2863
3186
|
"plugins",
|
|
2864
|
-
...(
|
|
3187
|
+
...(appServer ? [] : ["--ephemeral", "--color", "never", "--json"]),
|
|
2865
3188
|
"--config",
|
|
2866
3189
|
`model=${JSON.stringify(model)}`,
|
|
2867
3190
|
"--config",
|
|
@@ -2874,10 +3197,11 @@ async function runSkill(skill, inputs, codexOverrides, effort, stdout, stderr, d
|
|
|
2874
3197
|
`model_providers.${options.provider}.${key}=${JSON.stringify(value)}`,
|
|
2875
3198
|
]),
|
|
2876
3199
|
"--config",
|
|
2877
|
-
'approval_policy="never"',
|
|
3200
|
+
verify ? 'approval_policy="on-request"' : 'approval_policy="never"',
|
|
3201
|
+
...(verify ? ["--config", 'approvals_reviewer="auto_review"'] : []),
|
|
2878
3202
|
"--config",
|
|
2879
3203
|
'responses_api_metadata.codex_security_surface="cli"',
|
|
2880
|
-
...(
|
|
3204
|
+
...(appServer
|
|
2881
3205
|
? []
|
|
2882
3206
|
: [
|
|
2883
3207
|
"--sandbox",
|
|
@@ -2888,10 +3212,21 @@ async function runSkill(skill, inputs, codexOverrides, effort, stdout, stderr, d
|
|
|
2888
3212
|
prompt,
|
|
2889
3213
|
]),
|
|
2890
3214
|
], {
|
|
2891
|
-
command: patch ? "patch" : "validate",
|
|
3215
|
+
command: verify ? "verify-fix" : patch ? "patch" : "validate",
|
|
2892
3216
|
stdout,
|
|
2893
3217
|
stderr,
|
|
2894
|
-
...(
|
|
3218
|
+
...(appServer
|
|
3219
|
+
? {
|
|
3220
|
+
appServer: {
|
|
3221
|
+
directory,
|
|
3222
|
+
prompt,
|
|
3223
|
+
...(verify ? { sandbox: "read-only" } : {}),
|
|
3224
|
+
...(options.onEvent === undefined
|
|
3225
|
+
? {}
|
|
3226
|
+
: { onEvent: options.onEvent }),
|
|
3227
|
+
},
|
|
3228
|
+
}
|
|
3229
|
+
: {}),
|
|
2895
3230
|
}, options.environment);
|
|
2896
3231
|
}
|
|
2897
3232
|
export async function readSkillCommandOutput(stream, appServer) {
|
|
@@ -2904,6 +3239,19 @@ export async function readSkillCommandOutput(stream, appServer) {
|
|
|
2904
3239
|
const send = (request) => {
|
|
2905
3240
|
appServer?.input.write(`${JSON.stringify(request)}\n`);
|
|
2906
3241
|
};
|
|
3242
|
+
const startThread = (config) => {
|
|
3243
|
+
send({
|
|
3244
|
+
id: 2,
|
|
3245
|
+
method: "thread/start",
|
|
3246
|
+
// An explicit cwd makes Codex persist trust for a new project.
|
|
3247
|
+
// Inherit the child process cwd and preserve the user's decision.
|
|
3248
|
+
params: {
|
|
3249
|
+
approvalPolicy: appServer?.sandbox === "read-only" ? "on-request" : "never",
|
|
3250
|
+
sandbox: appServer?.sandbox ?? "workspace-write",
|
|
3251
|
+
...(config === undefined ? {} : { config }),
|
|
3252
|
+
},
|
|
3253
|
+
});
|
|
3254
|
+
};
|
|
2907
3255
|
if (appServer !== undefined) {
|
|
2908
3256
|
send({
|
|
2909
3257
|
id: 1,
|
|
@@ -2928,6 +3276,18 @@ export async function readSkillCommandOutput(stream, appServer) {
|
|
|
2928
3276
|
}
|
|
2929
3277
|
const value = event;
|
|
2930
3278
|
if (appServer !== undefined) {
|
|
3279
|
+
const params = value["params"];
|
|
3280
|
+
if (typeof params === "object" &&
|
|
3281
|
+
params !== null &&
|
|
3282
|
+
"threadId" in params &&
|
|
3283
|
+
params.threadId === threadId &&
|
|
3284
|
+
"turnId" in params &&
|
|
3285
|
+
params.turnId === turnId) {
|
|
3286
|
+
try {
|
|
3287
|
+
appServer.onEvent?.(value);
|
|
3288
|
+
}
|
|
3289
|
+
catch { }
|
|
3290
|
+
}
|
|
2931
3291
|
if (value["id"] !== undefined) {
|
|
2932
3292
|
if (typeof value["method"] === "string") {
|
|
2933
3293
|
send({
|
|
@@ -2941,13 +3301,80 @@ export async function readSkillCommandOutput(stream, appServer) {
|
|
|
2941
3301
|
}
|
|
2942
3302
|
else if (value["id"] === 1) {
|
|
2943
3303
|
send({ method: "notifications/initialized" });
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
3304
|
+
if (appServer.sandbox === "read-only") {
|
|
3305
|
+
if (appServer.directory === undefined) {
|
|
3306
|
+
error =
|
|
3307
|
+
"Codex did not receive the repository directory required for read-only verification.";
|
|
3308
|
+
appServer.input.end();
|
|
3309
|
+
continue;
|
|
3310
|
+
}
|
|
3311
|
+
send({
|
|
3312
|
+
id: 4,
|
|
3313
|
+
method: "config/read",
|
|
3314
|
+
params: {
|
|
3315
|
+
cwd: appServer.directory,
|
|
3316
|
+
includeLayers: true,
|
|
3317
|
+
},
|
|
3318
|
+
});
|
|
3319
|
+
}
|
|
3320
|
+
else {
|
|
3321
|
+
startThread();
|
|
3322
|
+
}
|
|
3323
|
+
}
|
|
3324
|
+
else if (value["id"] === 4 && appServer.sandbox === "read-only") {
|
|
3325
|
+
const result = value["result"];
|
|
3326
|
+
const layers = typeof result === "object" && result !== null && "layers" in result
|
|
3327
|
+
? result.layers
|
|
3328
|
+
: undefined;
|
|
3329
|
+
if (!Array.isArray(layers)) {
|
|
3330
|
+
error =
|
|
3331
|
+
"Codex did not provide the configuration layers required for read-only verification.";
|
|
3332
|
+
appServer.input.end();
|
|
3333
|
+
continue;
|
|
3334
|
+
}
|
|
3335
|
+
const repositoryServers = new Set();
|
|
3336
|
+
const configuredServers = new Set();
|
|
3337
|
+
for (const layer of layers) {
|
|
3338
|
+
if (typeof layer !== "object" || layer === null)
|
|
3339
|
+
continue;
|
|
3340
|
+
const name = layer["name"];
|
|
3341
|
+
const configuration = layer["config"];
|
|
3342
|
+
if (typeof name !== "object" ||
|
|
3343
|
+
name === null ||
|
|
3344
|
+
typeof configuration !== "object" ||
|
|
3345
|
+
configuration === null) {
|
|
3346
|
+
continue;
|
|
3347
|
+
}
|
|
3348
|
+
const servers = configuration["mcp_servers"];
|
|
3349
|
+
if (typeof servers !== "object" || servers === null)
|
|
3350
|
+
continue;
|
|
3351
|
+
if (name["type"] === "project") {
|
|
3352
|
+
if (layer["disabledReason"] !== undefined)
|
|
3353
|
+
continue;
|
|
3354
|
+
for (const server of Object.keys(servers)) {
|
|
3355
|
+
repositoryServers.add(server);
|
|
3356
|
+
}
|
|
3357
|
+
}
|
|
3358
|
+
else {
|
|
3359
|
+
for (const server of Object.keys(servers)) {
|
|
3360
|
+
configuredServers.add(server);
|
|
3361
|
+
}
|
|
3362
|
+
}
|
|
3363
|
+
}
|
|
3364
|
+
const conflict = [...repositoryServers].find((server) => configuredServers.has(server));
|
|
3365
|
+
if (conflict !== undefined) {
|
|
3366
|
+
error = `Repository-local MCP server ${JSON.stringify(conflict)} overrides a configured integration; remove the repository override before verifying fixes.`;
|
|
3367
|
+
appServer.input.end();
|
|
3368
|
+
continue;
|
|
3369
|
+
}
|
|
3370
|
+
startThread(repositoryServers.size === 0
|
|
3371
|
+
? undefined
|
|
3372
|
+
: {
|
|
3373
|
+
mcp_servers: Object.fromEntries([...repositoryServers].map((server) => [
|
|
3374
|
+
server,
|
|
3375
|
+
{ enabled: false },
|
|
3376
|
+
])),
|
|
3377
|
+
});
|
|
2951
3378
|
}
|
|
2952
3379
|
else if (value["id"] === 2) {
|
|
2953
3380
|
threadId = value["result"].thread.id;
|