@openai/codex-security 0.1.18 → 0.1.19

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 CHANGED
@@ -730,6 +730,80 @@ and scans stopped at their configured cost limit do not start another turn.
730
730
  invocation and defaults to `1`. Results remain under `--output-dir`; rerun the
731
731
  same command to resume.
732
732
 
733
+ ### Publish multiple completed scans to Cloud
734
+
735
+ Choose completed scans from your local history:
736
+
737
+ ```bash
738
+ npx @openai/codex-security publish scan --to cloud --dry-run --json
739
+ ```
740
+
741
+ The picker shows each scan's repository, finding count, age, and scan ID.
742
+ Choose scans, then select **Done**. No scans are selected automatically.
743
+
744
+ For scripts, repeat `--scan` with saved scan IDs or unique ID prefixes (at
745
+ least eight characters):
746
+
747
+ ```bash
748
+ npx @openai/codex-security publish scan \
749
+ --scan SCAN_ID_A --scan SCAN_ID_B \
750
+ --to cloud --dry-run --json
751
+ ```
752
+
753
+ Use `scans list --json` to find IDs for the current repository. `--scan latest`
754
+ selects its latest completed scan. The CLI resolves IDs through saved history,
755
+ processes each selected scan once, and checks that its sealed artifacts match
756
+ the selected ID. The artifacts must still be available locally.
757
+
758
+ `--dry-run` validates the scans and prints their findings without uploading or
759
+ requiring a login. Remove `--dry-run` to upload. Live uploads require ChatGPT
760
+ credentials explicitly stored in a file. Set this in your Codex `config.toml`,
761
+ then sign in with ChatGPT again:
762
+
763
+ ```toml
764
+ cli_auth_credentials_store = "file"
765
+ ```
766
+
767
+ Automatic and keyring credential storage are not accepted for Cloud
768
+ publication, even when an `auth.json` file exists, because that file may be
769
+ stale and belong to a different account. The CLI sends one scan at a time,
770
+ with each scan's findings and metadata in a separate request.
771
+
772
+ For artifacts outside local history, use repeated `--scan-dir PATH` instead.
773
+ A single positional directory is still accepted and can be combined with
774
+ `--scan-dir`. Do not combine directory inputs with `--scan`. Each directory
775
+ must contain one completed, sealed scan; bulk-run directories and
776
+ `results.jsonl` files are not accepted. Relative paths start at the current
777
+ directory, and `~/...` starts at your home directory. Each resolved directory
778
+ is processed once.
779
+
780
+ For multiple distinct scans, output contains:
781
+
782
+ - `results`: receipts or dry-run previews, each with its `scanId` and `scanDir`.
783
+ - `failed`: errors with `scanDir` and, for saved selections, `scanId`.
784
+ - `notAttempted`: saved scan IDs, or paths for directory inputs, that the command
785
+ did not reach before cancellation.
786
+
787
+ For one distinct scan, the CLI returns the scan result directly,
788
+ without the batch fields above.
789
+
790
+ The CLI continues after a failed scan and exits with code `2` if any scan
791
+ fails. Ctrl-C or SIGTERM stops new requests and returns the results collected
792
+ so far. When cancellation stops work before every requested publication is
793
+ confirmed, the exit code is `130` for Ctrl-C and `143` for SIGTERM. If the
794
+ single response or final batch response has already confirmed the complete
795
+ publication, the command exits with code `0`. Cloud publication receipts
796
+ appear in command output; the CLI does not save them to scan history.
797
+
798
+ A successful receipt contains one opaque Cloud finding ID for each submitted
799
+ finding, in request order. These are not local finding IDs. The CLI verifies
800
+ the authenticated response status, count, and ID uniqueness, but cannot map
801
+ opaque server IDs back to individual local findings independently.
802
+
803
+ The CLI never retries an upload automatically. An upload with a missing or
804
+ invalid receipt may already have been accepted. Check whether Cloud accepted
805
+ that scan before retrying it. Do not resend scans with confirmed receipts.
806
+
733
807
  ### Custom validation
734
808
 
735
809
  Use a prompt file to replace the final validation step in a standard or diff
@@ -802,17 +876,21 @@ Publish every finding from a completed standard, deep, or scoped scan to one
802
876
  Linear team:
803
877
 
804
878
  ```bash
805
- npx @openai/codex-security publish scan /path/to/completed-scan \
879
+ npx @openai/codex-security publish scan --scan SCAN_ID \
806
880
  --to linear \
807
881
  --linear-team TEAM_ID
808
882
  ```
809
883
 
884
+ Linear accepts one scan. Use a saved scan ID, a unique ID prefix, or `latest`.
885
+ For external artifacts, a positional directory or `--scan-dir PATH` is also
886
+ accepted.
887
+
810
888
  Add `--linear-project PROJECT_ID` to place the issues in a Linear project.
811
889
  The existing `--project` flag remains an alias. Without a project, issues are
812
890
  created directly in the selected team.
813
891
 
814
892
  To choose from all completed scans saved in your local scan history, omit the
815
- scan directory. The selector highlights each repository and shows its finding
893
+ scan selector. The selector highlights each repository and shows its finding
816
894
  count, relative run time, and abbreviated scan ID:
817
895
 
818
896
  ```bash
@@ -1025,8 +1103,9 @@ for a personal API key, or `LINEAR_ACCESS_TOKEN` for an OAuth access token.
1025
1103
  `LINEAR_API_KEY` is also accepted. `--linear-api-key KEY` overrides these
1026
1104
  environment settings; prefer the environment variable to keep keys out of shell
1027
1105
  history. Imported content is always literal, and issue URLs must match the
1028
- selected workspace. Linear access is read-only, and its credentials are not
1029
- passed to the patch subprocess.
1106
+ selected workspace. Each imported issue includes its title, description, and
1107
+ all comments with their source links. Linear access is read-only, and its
1108
+ credentials are not passed to the patch subprocess.
1030
1109
 
1031
1110
  Use `verify-fix` to check whether an existing security fix actually closes its
1032
1111
  original vulnerability without modifying the repository. Pass a finding
package/dist/cli.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { CodexSecurity } from "./api.js";
3
+ import { publishScanToCloud } from "./cloud-publish.js";
3
4
  import { type BulkScanDiscoveryDependencies, type BulkScanPrompt } from "./bulk-scan-discovery.js";
4
5
  import { type CodexSecurityConfig, type ExternalModelProvider, type JsonObject } from "./config.js";
5
6
  import { type LinearClientFactory } from "./linear.js";
@@ -52,6 +53,7 @@ interface CliDependencies {
52
53
  scanAuthenticationPrompt?: Pick<BulkScanPrompt, "isInteractive" | "select">;
53
54
  publishPrompt?: Pick<BulkScanPrompt, "isInteractive" | "select">;
54
55
  publishScan?: typeof publishScan;
56
+ publishScanToCloud?: typeof publishScanToCloud;
55
57
  confirmPatchReview?: (question: string) => Promise<boolean>;
56
58
  patchEditor?: (repository: string, findings: readonly Finding[]) => Promise<PatchSelection | null>;
57
59
  currentDirectory(): string;
package/dist/cli.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AA2CA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W,cAAc,IAAI,MAAM,CAKlC;IAEM,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAK5B,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAiBjC,SAAS,IAAI,IAAI;IAwCjB,eAAe,CAAC,KAAK,EAAE,MAAM,IAAI,GAAG,IAAI;CAoChD"}
package/dist/cli.js CHANGED
@@ -13,6 +13,7 @@ import { Cli, z } from "incur";
13
13
  import { parse as parseToml } from "smol-toml";
14
14
  import { classifyConnectionFailure, createSecurityInternal, listRepositoryFindings, SCAN_AUTH_MODES, scanAuthentication, } from "./api.js";
15
15
  import { accountStatus } from "./auth.js";
16
+ import { publishScanToCloud, } from "./cloud-publish.js";
16
17
  import { createBulkScanDiscoveryDependencies, runBulkScanWizard, } from "./bulk-scan-discovery.js";
17
18
  import { DEFAULT_CODEX_CONFIG, EXTERNAL_CODEX_PROVIDERS, isExternalModelProvider, mergedCodexConfig, scanModelConfiguration, scanModelProvider, } from "./config.js";
18
19
  import { formatUsd } from "./cost.js";
@@ -98,6 +99,7 @@ const VALUE_OPTIONS = new Set([
98
99
  "--patch-severity",
99
100
  "--resume-pr",
100
101
  "--scan",
102
+ "--scan-dir",
101
103
  "--severity",
102
104
  "--max-cost",
103
105
  "--workers",
@@ -1329,7 +1331,21 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
1329
1331
  .describe("Completed scan directory; omit to select a saved scan."),
1330
1332
  }),
1331
1333
  options: z.object({
1332
- to: z.literal("linear").describe("Publication destination."),
1334
+ scan: z
1335
+ .array(optionValue("--scan"))
1336
+ .default([])
1337
+ .describe("Saved scan ID, unique prefix, or latest; repeat for multiple scans (Linear accepts one)."),
1338
+ scanDir: z
1339
+ .array(optionValue("--scan-dir"))
1340
+ .default([])
1341
+ .describe("External completed scan directory; repeat for multiple scans (Linear accepts one)."),
1342
+ // Cloud remains an internal destination, omitted from public discovery.
1343
+ to: z
1344
+ .string()
1345
+ .refine((value) => value === "linear" || value === "cloud", {
1346
+ message: "Unsupported publication destination. Use --to linear.",
1347
+ })
1348
+ .describe("Publication destination (linear)."),
1333
1349
  linearTeam: optionValue("--linear-team")
1334
1350
  .optional()
1335
1351
  .describe("Linear team ID; defaults to CODEX_SECURITY_LINEAR_TEAM."),
@@ -1353,15 +1369,58 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
1353
1369
  async run({ args, format, formatExplicit, options }) {
1354
1370
  const controller = new AbortController();
1355
1371
  let presentation;
1372
+ let cloudBatch;
1356
1373
  const cancel = (signal) => {
1357
1374
  presentation?.stop();
1358
1375
  controller.abort(signal);
1359
1376
  };
1377
+ const finishCancellation = (error) => {
1378
+ const signal = controller.signal.reason;
1379
+ if (signal !== "SIGINT" && signal !== "SIGTERM")
1380
+ return false;
1381
+ const reason = signal === "SIGINT"
1382
+ ? "Publication canceled by Ctrl-C."
1383
+ : "Publication terminated by SIGTERM.";
1384
+ const recovery = error === undefined || error === signal
1385
+ ? ""
1386
+ : ` ${diagnosticValue(safeErrorMessage(error))}`;
1387
+ errorOutput.write(`codex-security: ${reason}${recovery}\n`);
1388
+ exitCode = signal === "SIGINT" ? 130 : 143;
1389
+ return true;
1390
+ };
1360
1391
  const onInterrupt = () => cancel("SIGINT");
1361
1392
  const onTerminate = () => cancel("SIGTERM");
1362
1393
  let observingSignals = false;
1363
1394
  try {
1364
- const linearApiKey = resolveLinearApiKey(dependencies.environment, options.linearApiKey);
1395
+ const currentDirectory = dependencies.currentDirectory();
1396
+ const directories = [
1397
+ ...new Set([
1398
+ ...(args.scanDir === undefined ? [] : [args.scanDir]),
1399
+ ...options.scanDir,
1400
+ ].map((directory) => resolveCliPath(currentDirectory, directory))),
1401
+ ];
1402
+ if (directories.length > 1 && options.to !== "cloud") {
1403
+ throw new CodexSecurityError("Multiple scan directories are only supported with --to cloud.");
1404
+ }
1405
+ if (options.scan.length > 0 && directories.length > 0) {
1406
+ throw new CodexSecurityError("Use --scan or scan directory inputs, not both.");
1407
+ }
1408
+ if (new Set(options.scan).size > 1 && options.to !== "cloud") {
1409
+ throw new CodexSecurityError("Multiple scans are only supported with --to cloud.");
1410
+ }
1411
+ if (options.to === "cloud" &&
1412
+ [
1413
+ options.linearTeam,
1414
+ options.linearApiKey,
1415
+ options.linearProject,
1416
+ options.project,
1417
+ options.linearAssignee,
1418
+ ].some((value) => value !== undefined)) {
1419
+ throw new CodexSecurityError("Cloud publication cannot be combined with Linear options.");
1420
+ }
1421
+ const linearApiKey = options.to === "linear"
1422
+ ? resolveLinearApiKey(dependencies.environment, options.linearApiKey)
1423
+ : undefined;
1365
1424
  const assigneeId = options.linearAssignee?.trim();
1366
1425
  if (options.linearAssignee !== undefined && !assigneeId) {
1367
1426
  throw new CodexSecurityError("--linear-assignee must not be empty.");
@@ -1370,8 +1429,9 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
1370
1429
  throw new CodexSecurityError("--linear-assignee requires --linear-api-key or CODEX_SECURITY_LINEAR_API_KEY.");
1371
1430
  }
1372
1431
  const teamId = options.linearTeam?.trim() ||
1373
- dependencies.environment["CODEX_SECURITY_LINEAR_TEAM"]?.trim();
1374
- if (!teamId) {
1432
+ dependencies.environment["CODEX_SECURITY_LINEAR_TEAM"]?.trim() ||
1433
+ "";
1434
+ if (options.to === "linear" && !teamId) {
1375
1435
  throw new CodexSecurityError("--linear-team or CODEX_SECURITY_LINEAR_TEAM is required.");
1376
1436
  }
1377
1437
  if (options.linearProject !== undefined &&
@@ -1387,7 +1447,20 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
1387
1447
  const projectId = selectedProject ||
1388
1448
  dependencies.environment["CODEX_SECURITY_LINEAR_PROJECT"]?.trim() ||
1389
1449
  undefined;
1390
- let scanDir = args.scanDir;
1450
+ if (options.to === "cloud") {
1451
+ dependencies.addSignalListener("SIGINT", onInterrupt);
1452
+ dependencies.addSignalListener("SIGTERM", onTerminate);
1453
+ observingSignals = true;
1454
+ }
1455
+ const selectedScans = directories.map((scanDir) => ({ scanDir }));
1456
+ for (const requestedId of new Set(options.scan)) {
1457
+ controller.signal.throwIfAborted();
1458
+ const scan = await resolvePublicationScan(requestedId, dependencies);
1459
+ if (!selectedScans.some(({ scanId }) => scanId === scan.scanId)) {
1460
+ selectedScans.push(scan);
1461
+ }
1462
+ }
1463
+ let scanDir = selectedScans[0]?.scanDir;
1391
1464
  let publicationRepository = scanDir === undefined ? "scan" : basename(scanDir);
1392
1465
  if (scanDir === undefined) {
1393
1466
  const prompt = dependencies.publishPrompt ??
@@ -1397,7 +1470,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
1397
1470
  currentDirectory: dependencies.currentDirectory,
1398
1471
  }).prompt;
1399
1472
  if (!prompt.isInteractive()) {
1400
- throw new CodexSecurityError("Interactive scan selection requires a terminal. Provide a completed scan directory: codex-security publish scan /path/to/sealed-scan --to linear --linear-team TEAM_ID.");
1473
+ throw new CodexSecurityError(`Interactive scan selection requires a terminal. Select a saved scan: codex-security publish scan --scan SCAN_ID --to ${options.to}${options.to === "linear" ? " --linear-team TEAM_ID" : ""}.`);
1401
1474
  }
1402
1475
  const saved = await dependencies.runWorkbench([
1403
1476
  "list-scans",
@@ -1415,7 +1488,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
1415
1488
  if (typeof directory !== "string" || directory.length === 0) {
1416
1489
  return undefined;
1417
1490
  }
1418
- const metadata = await lstat(resolve(dependencies.currentDirectory(), directory)).catch(() => undefined);
1491
+ const metadata = await lstat(resolveCliPath(currentDirectory, directory)).catch(() => undefined);
1419
1492
  return metadata?.isDirectory() === true &&
1420
1493
  !metadata.isSymbolicLink()
1421
1494
  ? scan
@@ -1426,6 +1499,7 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
1426
1499
  dependencies.environment["NO_COLOR"] === undefined &&
1427
1500
  dependencies.environment["TERM"] !== "dumb";
1428
1501
  const repositories = new Map();
1502
+ const scansById = new Map();
1429
1503
  const rows = scans.flatMap((scan) => {
1430
1504
  if (!isJsonObject(scan))
1431
1505
  return [];
@@ -1470,13 +1544,17 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
1470
1544
  .replace(/\s+/gu, " ")
1471
1545
  .slice(-6)}`;
1472
1546
  repositories.set(directory, repository);
1547
+ scansById.set(scanId, {
1548
+ scanId,
1549
+ scanDir: resolveCliPath(currentDirectory, directory),
1550
+ });
1473
1551
  return [
1474
1552
  {
1475
1553
  repository,
1476
1554
  findings,
1477
1555
  age: publicationScanAge(timestamp, now),
1478
1556
  scanId: shortScanId,
1479
- value: directory,
1557
+ value: options.to === "cloud" ? scanId : directory,
1480
1558
  },
1481
1559
  ];
1482
1560
  });
@@ -1507,10 +1585,100 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
1507
1585
  value: row.value,
1508
1586
  };
1509
1587
  });
1510
- scanDir = await prompt.select("Which completed scan would you like to publish?", choices, { header });
1588
+ if (options.to === "cloud") {
1589
+ let remaining = choices;
1590
+ while (true) {
1591
+ controller.signal.throwIfAborted();
1592
+ const selected = await prompt.select("Which completed scans would you like to publish?", selectedScans.length === 0
1593
+ ? remaining
1594
+ : [
1595
+ {
1596
+ label: `Done (${selectedScans.length} selected)`,
1597
+ value: "",
1598
+ },
1599
+ ...remaining,
1600
+ ], { header }, controller.signal);
1601
+ controller.signal.throwIfAborted();
1602
+ if (selected === "")
1603
+ break;
1604
+ selectedScans.push(scansById.get(selected));
1605
+ remaining = remaining.filter(({ value }) => value !== selected);
1606
+ }
1607
+ scanDir = selectedScans[0].scanDir;
1608
+ }
1609
+ else {
1610
+ scanDir = await prompt.select("Which completed scan would you like to publish?", choices, { header });
1611
+ selectedScans.push({ scanDir });
1612
+ }
1511
1613
  publicationRepository =
1512
1614
  repositories.get(scanDir) ?? basename(scanDir);
1513
1615
  }
1616
+ if (options.to === "cloud") {
1617
+ const seenDirectories = new Set();
1618
+ for (let index = 0; index < selectedScans.length;) {
1619
+ const selected = selectedScans[index];
1620
+ const canonical = await realpath(selected.scanDir).catch(() => selected.scanDir);
1621
+ const identity = process.platform === "win32"
1622
+ ? canonical.toLowerCase()
1623
+ : canonical;
1624
+ if (seenDirectories.has(identity)) {
1625
+ selectedScans.splice(index, 1);
1626
+ continue;
1627
+ }
1628
+ seenDirectories.add(identity);
1629
+ selected.scanDir = canonical;
1630
+ index++;
1631
+ }
1632
+ scanDir = selectedScans[0].scanDir;
1633
+ controller.signal.throwIfAborted();
1634
+ if (selectedScans.length > 1) {
1635
+ cloudBatch = {
1636
+ results: [],
1637
+ failed: [],
1638
+ notAttempted: selectedScans.map(({ scanId, scanDir }) => scanId ?? scanDir),
1639
+ };
1640
+ // Keep each scan's provenance and acceptance receipt separate. Never
1641
+ // retry a failed POST: a lost response may still have been accepted.
1642
+ for (const { scanDir: directory, scanId } of selectedScans) {
1643
+ if (controller.signal.aborted) {
1644
+ finishCancellation();
1645
+ break;
1646
+ }
1647
+ cloudBatch.notAttempted.shift();
1648
+ try {
1649
+ const result = await (dependencies.publishScanToCloud ?? publishScanToCloud)(directory, {
1650
+ environment: dependencies.environment,
1651
+ dryRun: options.dryRun,
1652
+ signal: controller.signal,
1653
+ ...(scanId === undefined ? {} : { expectedScanId: scanId }),
1654
+ });
1655
+ cloudBatch.results.push({ scanDir: directory, ...result });
1656
+ }
1657
+ catch (error) {
1658
+ const message = safeErrorMessage(error);
1659
+ cloudBatch.failed.push({
1660
+ scanDir: directory,
1661
+ ...(scanId === undefined ? {} : { scanId }),
1662
+ error: message,
1663
+ });
1664
+ if (controller.signal.aborted)
1665
+ throw error;
1666
+ exitCode = 2;
1667
+ errorOutput.write(`codex-security: ${diagnosticValue(safeErrorMessage(scanId ?? directory))}: ${diagnosticValue(message)}\n`);
1668
+ }
1669
+ }
1670
+ return cloudBatch;
1671
+ }
1672
+ const result = await (dependencies.publishScanToCloud ?? publishScanToCloud)(resolveCliPath(currentDirectory, scanDir), {
1673
+ environment: dependencies.environment,
1674
+ dryRun: options.dryRun,
1675
+ signal: controller.signal,
1676
+ ...(selectedScans[0]?.scanId === undefined
1677
+ ? {}
1678
+ : { expectedScanId: selectedScans[0].scanId }),
1679
+ });
1680
+ return { ...result };
1681
+ }
1514
1682
  const progress = new PublicationProgressPresenter(errorOutput, dependencies, publicationRepository);
1515
1683
  presentation = progress;
1516
1684
  if (!options.dryRun) {
@@ -1521,8 +1689,11 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
1521
1689
  }
1522
1690
  let result;
1523
1691
  try {
1524
- result = await (dependencies.publishScan ?? publishScan)(resolve(dependencies.currentDirectory(), scanDir), {
1525
- destination: options.to,
1692
+ result = await (dependencies.publishScan ?? publishScan)(resolveCliPath(currentDirectory, scanDir), {
1693
+ destination: "linear",
1694
+ ...(selectedScans[0]?.scanId === undefined
1695
+ ? {}
1696
+ : { expectedScanId: selectedScans[0].scanId }),
1526
1697
  teamId,
1527
1698
  ...(projectId === undefined ? {} : { projectId }),
1528
1699
  dryRun: options.dryRun,
@@ -1560,22 +1731,11 @@ export async function main(argv = process.argv.slice(2), output = process.stdout
1560
1731
  return { ...result };
1561
1732
  }
1562
1733
  catch (error) {
1563
- const signal = controller.signal.reason;
1564
- if (signal === "SIGINT" || signal === "SIGTERM") {
1565
- const reason = signal === "SIGINT"
1566
- ? "Publication canceled by Ctrl-C."
1567
- : "Publication terminated by SIGTERM.";
1568
- const recovery = error === signal
1569
- ? ""
1570
- : ` ${diagnosticValue(safeErrorMessage(error))}`;
1571
- errorOutput.write(`codex-security: ${reason}${recovery}\n`);
1572
- exitCode = signal === "SIGINT" ? 130 : 143;
1573
- }
1574
- else {
1575
- errorOutput.write(`codex-security: ${errorMessage(error)}\n`);
1734
+ if (!finishCancellation(error)) {
1735
+ errorOutput.write(`codex-security: ${options.to === "cloud" ? safeErrorMessage(error) : errorMessage(error)}\n`);
1576
1736
  exitCode = 2;
1577
1737
  }
1578
- return undefined;
1738
+ return cloudBatch;
1579
1739
  }
1580
1740
  finally {
1581
1741
  if (observingSignals) {
@@ -3089,6 +3249,55 @@ async function* workbenchFindings(arguments_, dependencies) {
3089
3249
  offset = typeof page.nextOffset === "number" ? page.nextOffset : undefined;
3090
3250
  } while (offset !== undefined);
3091
3251
  }
3252
+ async function resolvePublicationScan(requestedId, dependencies) {
3253
+ let scanId = requestedId;
3254
+ if (scanId === "latest") {
3255
+ const history = await dependencies.runWorkbench([
3256
+ "list-scans",
3257
+ "--repository",
3258
+ resolve(dependencies.currentDirectory()),
3259
+ "--status",
3260
+ "complete",
3261
+ ]);
3262
+ const scans = history["scans"];
3263
+ const latest = Array.isArray(scans) ? scans[0] : undefined;
3264
+ if (latest === undefined ||
3265
+ !isJsonObject(latest) ||
3266
+ typeof latest["scanId"] !== "string") {
3267
+ throw new CodexSecurityError("No completed saved scan was found for this repository.");
3268
+ }
3269
+ scanId = latest["scanId"];
3270
+ }
3271
+ const context = await dependencies.runWorkbench([
3272
+ "get-scan",
3273
+ "--scan-id",
3274
+ scanId,
3275
+ ]);
3276
+ const scan = context["scan"];
3277
+ if (scan === undefined ||
3278
+ !isJsonObject(scan) ||
3279
+ typeof scan["scanId"] !== "string") {
3280
+ throw new CodexSecurityError(`Could not read saved scan ${scanId}.`);
3281
+ }
3282
+ scanId = scan["scanId"];
3283
+ const progress = scan["progress"];
3284
+ if (progress === undefined ||
3285
+ !isJsonObject(progress) ||
3286
+ progress["status"] !== "complete") {
3287
+ throw new CodexSecurityError(`Scan ${scanId} is not complete.`);
3288
+ }
3289
+ const storedDirectory = scan["scanDir"];
3290
+ const scanDir = typeof storedDirectory === "string" && storedDirectory.length > 0
3291
+ ? resolveCliPath(dependencies.currentDirectory(), storedDirectory)
3292
+ : undefined;
3293
+ const metadata = scanDir === undefined
3294
+ ? undefined
3295
+ : await lstat(scanDir).catch(() => undefined);
3296
+ if (scanDir === undefined || metadata?.isDirectory() !== true) {
3297
+ throw new CodexSecurityError(`Artifacts for scan ${scanId} are unavailable. Restore the completed scan artifacts or run a new scan.`);
3298
+ }
3299
+ return { ...scan, scanId, scanDir };
3300
+ }
3092
3301
  async function selectSavedFindings(identifiers, requestedScanId, severity, dependencies) {
3093
3302
  if (identifiers.some((identifier) => !isFindingIdentifier(identifier))) {
3094
3303
  throw new CodexSecurityError("Saved scan patching accepts only finding identifiers.");