@openai/codex-security 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/_bundled_plugin/.codex-plugin/plugin.json +5 -5
  2. package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
  3. package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
  4. package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -0
  5. package/_bundled_plugin/mcp/permission-profile-preflight.mjs +13 -20
  6. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  7. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  8. package/_bundled_plugin/references/final-report.md +1 -1
  9. package/_bundled_plugin/schemas/coverage.schema.json +45 -126
  10. package/_bundled_plugin/schemas/findings.schema.json +140 -427
  11. package/_bundled_plugin/schemas/patch-risk-assessment.schema.json +106 -119
  12. package/_bundled_plugin/schemas/scan-manifest.schema.json +73 -188
  13. package/_bundled_plugin/scripts/finalize_scan_contract.py +7 -6
  14. package/_bundled_plugin/scripts/generate_rank_input.py +25 -106
  15. package/_bundled_plugin/scripts/report_projection.py +35 -13
  16. package/_bundled_plugin/scripts/workbench_cli.py +9 -6
  17. package/_bundled_plugin/scripts/workbench_db.py +51 -16
  18. package/_bundled_plugin/scripts/workbench_publication.py +216 -247
  19. package/_bundled_plugin/scripts/workbench_scan_usage.py +173 -10
  20. package/_bundled_plugin/scripts/workbench_validation.py +15 -1
  21. package/_bundled_plugin/shared/workbench-migrations.json +17 -0
  22. package/_bundled_plugin/skills/deep-security-scan/SKILL.md +1 -1
  23. package/_bundled_plugin/skills/deep-security-scan/agents/openai.yaml +1 -1
  24. package/_bundled_plugin/skills/security-diff-scan/agents/openai.yaml +1 -1
  25. package/_bundled_plugin/skills/security-scan/SKILL.md +1 -1
  26. package/_bundled_plugin/skills/security-scan/agents/openai.yaml +1 -1
  27. package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +1 -1
  28. package/_bundled_plugin/skills/security-scan/references/scan-artifacts-and-ledger.md +2 -0
  29. package/_bundled_plugin/skills/track-findings/SKILL.md +8 -4
  30. package/_bundled_plugin/skills/track-findings/agents/openai.yaml +1 -1
  31. package/_bundled_plugin/skills/track-findings/references/github-security-advisories.md +1 -1
  32. package/dist/api.d.ts +3 -0
  33. package/dist/api.d.ts.map +1 -1
  34. package/dist/api.js +212 -3
  35. package/dist/api.js.map +1 -1
  36. package/dist/cli.d.ts.map +1 -1
  37. package/dist/cli.js +15 -5
  38. package/dist/cli.js.map +1 -1
  39. package/dist/component-plan.js +1 -1
  40. package/dist/component-plan.js.map +1 -1
  41. package/dist/component-scan.d.ts.map +1 -1
  42. package/dist/component-scan.js +5 -4
  43. package/dist/component-scan.js.map +1 -1
  44. package/dist/contract.d.ts +1 -0
  45. package/dist/contract.d.ts.map +1 -1
  46. package/dist/contract.js +4 -3
  47. package/dist/contract.js.map +1 -1
  48. package/dist/custom-validation-prompt.js +1 -1
  49. package/dist/custom-validation-prompt.js.map +1 -1
  50. package/dist/deduplication/codex-review.d.ts +1 -5
  51. package/dist/deduplication/codex-review.d.ts.map +1 -1
  52. package/dist/deduplication/codex-review.js +2 -2
  53. package/dist/deduplication/codex-review.js.map +1 -1
  54. package/dist/deduplication/deduplication-reviewer.d.ts +1 -1
  55. package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
  56. package/dist/deduplication/deduplication-reviewer.js +1 -1
  57. package/dist/deduplication/deduplication-reviewer.js.map +1 -1
  58. package/dist/deduplication/records-protocol.d.ts +3 -8
  59. package/dist/deduplication/records-protocol.d.ts.map +1 -1
  60. package/dist/deduplication/records-protocol.js +11 -171
  61. package/dist/deduplication/records-protocol.js.map +1 -1
  62. package/dist/deep-progress.d.ts +15 -1
  63. package/dist/deep-progress.d.ts.map +1 -1
  64. package/dist/deep-progress.js +15 -16
  65. package/dist/deep-progress.js.map +1 -1
  66. package/dist/executable-path.d.ts +2 -0
  67. package/dist/executable-path.d.ts.map +1 -0
  68. package/dist/executable-path.js +12 -0
  69. package/dist/executable-path.js.map +1 -0
  70. package/dist/feedback.d.ts +1 -4
  71. package/dist/feedback.d.ts.map +1 -1
  72. package/dist/feedback.js +1 -1
  73. package/dist/feedback.js.map +1 -1
  74. package/dist/host-protocol.d.ts +19 -0
  75. package/dist/host-protocol.d.ts.map +1 -0
  76. package/dist/host-protocol.js +270 -0
  77. package/dist/host-protocol.js.map +1 -0
  78. package/dist/hosted-scan-protocol.d.ts +4 -0
  79. package/dist/hosted-scan-protocol.d.ts.map +1 -0
  80. package/dist/hosted-scan-protocol.js +25 -0
  81. package/dist/hosted-scan-protocol.js.map +1 -0
  82. package/dist/hosted-scan.d.ts +117 -0
  83. package/dist/hosted-scan.d.ts.map +1 -0
  84. package/dist/hosted-scan.js +260 -0
  85. package/dist/hosted-scan.js.map +1 -0
  86. package/dist/index.d.ts +3 -0
  87. package/dist/index.d.ts.map +1 -1
  88. package/dist/index.js +1 -0
  89. package/dist/index.js.map +1 -1
  90. package/dist/multiscan.d.ts.map +1 -1
  91. package/dist/multiscan.js +47 -9
  92. package/dist/multiscan.js.map +1 -1
  93. package/dist/publication-store.d.ts.map +1 -1
  94. package/dist/publication-store.js +73 -63
  95. package/dist/publication-store.js.map +1 -1
  96. package/dist/publication.d.ts +0 -2
  97. package/dist/publication.d.ts.map +1 -1
  98. package/dist/publication.js +0 -5
  99. package/dist/publication.js.map +1 -1
  100. package/dist/runtime.d.ts +5 -2
  101. package/dist/runtime.d.ts.map +1 -1
  102. package/dist/runtime.js +5 -38
  103. package/dist/runtime.js.map +1 -1
  104. package/dist/scan-executor.d.ts +104 -0
  105. package/dist/scan-executor.d.ts.map +1 -0
  106. package/dist/scan-executor.js +62 -0
  107. package/dist/scan-executor.js.map +1 -0
  108. package/dist/targets.d.ts.map +1 -1
  109. package/dist/targets.js +17 -25
  110. package/dist/targets.js.map +1 -1
  111. package/dist/worker-progress.d.ts +43 -11
  112. package/dist/worker-progress.d.ts.map +1 -1
  113. package/dist/worker-progress.js +21 -37
  114. package/dist/worker-progress.js.map +1 -1
  115. package/docs/cli.md +12 -2
  116. package/docs/hosted-scans.md +242 -0
  117. package/package.json +9 -7
  118. package/schemas/hosted-scan-v2.fixture.json +145 -0
@@ -1 +1 @@
1
- {"version":3,"file":"deep-progress.js","sourceRoot":"","sources":["../src/deep-progress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAgBtD,MAAM,8BAA8B,GAAG,KAAK,CAAC;AAE7C,MAAM,OAAO,uBAAuB;IACzB,QAAQ,CAAiC;IAClD,MAAM,GAA0B,IAAI,CAAC;IACrC,QAAQ,GAAyB,IAAI,CAAC;IAC7B,gBAAgB,GAAG,IAAI,eAAe,EAAE,CAAC;IAClD,aAAa,GAA4B,IAAI,CAAC;IAE9C,YAAmB,OAAuC;QACxD,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAEM,KAAK;QACV,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI,IAAI,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,OAAO;YAAE,OAAO;QACzE,MAAM,IAAI,GAAG,GAAG,EAAE;YAChB,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;gBAC3C,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;YACjC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;QACF,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC,IAAI,EAAE,8BAA8B,CAAC,CAAC;QAChE,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QACpB,IAAI,EAAE,CAAC;IACT,CAAC;IAEM,KAAK,CAAC,OAAO;QAClB,IAAI,IAAI,CAAC,gBAAgB,CAAC,MAAM,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ACJ,CAAC","sourcesContent":["import { isRecord } from \"./record.js\";\nimport { isSafeNonNegativeInteger } from \"./value.js\";\n\nexport interface DeepScanProgress {\n completed: number;\n active: number;\n maximum: number;\n /** Whether the coordinator is reducing results or has finished. */\n consolidating?: boolean;\n}\n\ninterface DeepScanProgressTrackerOptions {\n read: (signal: AbortSignal) => Promise<unknown>;\n onProgress: (progress: DeepScanProgress) => void;\n onError?: (error: unknown) => void;\n}\n\nconst DEEP_PROGRESS_POLL_INTERVAL_MS = 5_000;\n\nexport class DeepScanProgressTracker {\n readonly #options: DeepScanProgressTrackerOptions;\n #timer: NodeJS.Timeout | null = null;\n #pending: Promise<void> | null = null;\n readonly #abortController = new AbortController();\n #lastProgress: DeepScanProgress | null = null;\n\n public constructor(options: DeepScanProgressTrackerOptions) {\n this.#options = options;\n }\n\n public start(): void {\n if (this.#timer !== null || this.#abortController.signal.aborted) return;\n const poll = () => {\n void this.refresh().catch((error: unknown) => {\n this.#options.onError?.(error);\n });\n };\n this.#timer = setInterval(poll, DEEP_PROGRESS_POLL_INTERVAL_MS);\n this.#timer.unref();\n poll();\n }\n\n public async refresh(): Promise<void> {\n if (this.#abortController.signal.aborted) return;\n if (this.#pending !== null) return await this.#pending;\n const abortController = this.#abortController;\n let update: Promise<void> | null = null;\n update = (async () => {\n try {\n const progress = deepScanProgressFromWorkbench(\n await this.#options.read(abortController.signal),\n );\n if (\n abortController.signal.aborted ||\n progress === null ||\n (progress.completed === this.#lastProgress?.completed &&\n progress.active === this.#lastProgress?.active &&\n progress.maximum === this.#lastProgress?.maximum &&\n progress.consolidating === this.#lastProgress?.consolidating)\n ) {\n return;\n }\n this.#lastProgress = progress;\n this.#options.onProgress(progress);\n } catch (error) {\n if (abortController.signal.aborted) return;\n throw error;\n } finally {\n if (this.#pending === update) this.#pending = null;\n }\n })();\n this.#pending = update;\n await update;\n }\n\n public stop(): void {\n if (this.#abortController.signal.aborted) return;\n clearInterval(this.#timer ?? undefined);\n this.#timer = null;\n this.#abortController.abort();\n }\n}\n\nexport function deepScanProgressFromWorkbench(\n result: unknown,\n): DeepScanProgress | null {\n if (!isRecord(result) || !isRecord(result[\"scan\"])) return null;\n const progress = result[\"scan\"][\"progress\"];\n if (!isRecord(progress)) return null;\n const independentReviews = progress[\"independentReviews\"];\n if (independentReviews === undefined) return null;\n if (isRecord(independentReviews)) {\n const { completed, active, maximum, consolidating } = independentReviews;\n if (\n isSafeNonNegativeInteger(completed) &&\n isSafeNonNegativeInteger(active) &&\n isSafeNonNegativeInteger(maximum) &&\n maximum > 0 &&\n (consolidating === undefined || typeof consolidating === \"boolean\")\n ) {\n return {\n completed,\n active,\n maximum,\n ...(typeof consolidating === \"boolean\" ? { consolidating } : {}),\n };\n }\n }\n throw new Error(\n \"Codex Security workbench returned invalid Deep Scan progress.\",\n );\n}\n"]}
1
+ {"version":3,"file":"deep-progress.js","sourceRoot":"","sources":["../src/deep-progress.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,cAAc,GAAG,CAAC;KACrB,MAAM,CAAC;IACN,SAAS,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE;IAChC,MAAM,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE;IAC7B,OAAO,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;IAC3B,aAAa,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;CACtC,CAAC;KACD,SAAS,CAAC,CAAC,EAAE,aAAa,EAAE,GAAG,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;IAC5C,GAAG,MAAM;IACT,GAAG,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC;CAC1D,CAAC,CAAC,CAAC;AAaN,MAAM,8BAA8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AAI,CAAC;IAChE,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,UAAU,CAAC,CAAC;IAC5C,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAAE,OAAO,IAAI,CAAC;IACrC,MAAM,kBAAkB,GAAG,QAAQ,CAAC,oBAAoB,CAAC,CAAC;IAC1D,IAAI,kBAAkB,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IAClD,MAAM,MAAM,GAAG,cAAc,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC;IAC5D,IAAI,MAAM,CAAC,OAAO;QAAE,OAAO,MAAM,CAAC,IAAI,CAAC;IACvC,MAAM,IAAI,KAAK,CACb,+DAA+D,CAChE,CAAC;AACJ,CAAC","sourcesContent":["import { isRecord } from \"./record.js\";\nimport { z } from \"zod\";\n\nconst progressSchema = z\n .object({\n completed: z.int().nonnegative(),\n active: z.int().nonnegative(),\n maximum: z.int().positive(),\n consolidating: z.boolean().optional(),\n })\n .transform(({ consolidating, ...counts }) => ({\n ...counts,\n ...(consolidating === undefined ? {} : { consolidating }),\n }));\n\nexport interface DeepScanProgress extends z.output<typeof progressSchema> {\n /** Whether the coordinator is reducing results or has finished. */\n consolidating?: boolean;\n}\n\ninterface DeepScanProgressTrackerOptions {\n read: (signal: AbortSignal) => Promise<unknown>;\n onProgress: (progress: DeepScanProgress) => void;\n onError?: (error: unknown) => void;\n}\n\nconst DEEP_PROGRESS_POLL_INTERVAL_MS = 5_000;\n\nexport class DeepScanProgressTracker {\n readonly #options: DeepScanProgressTrackerOptions;\n #timer: NodeJS.Timeout | null = null;\n #pending: Promise<void> | null = null;\n readonly #abortController = new AbortController();\n #lastProgress: DeepScanProgress | null = null;\n\n public constructor(options: DeepScanProgressTrackerOptions) {\n this.#options = options;\n }\n\n public start(): void {\n if (this.#timer !== null || this.#abortController.signal.aborted) return;\n const poll = () => {\n void this.refresh().catch((error: unknown) => {\n this.#options.onError?.(error);\n });\n };\n this.#timer = setInterval(poll, DEEP_PROGRESS_POLL_INTERVAL_MS);\n this.#timer.unref();\n poll();\n }\n\n public async refresh(): Promise<void> {\n if (this.#abortController.signal.aborted) return;\n if (this.#pending !== null) return await this.#pending;\n const abortController = this.#abortController;\n let update: Promise<void> | null = null;\n update = (async () => {\n try {\n const progress = deepScanProgressFromWorkbench(\n await this.#options.read(abortController.signal),\n );\n if (\n abortController.signal.aborted ||\n progress === null ||\n (progress.completed === this.#lastProgress?.completed &&\n progress.active === this.#lastProgress?.active &&\n progress.maximum === this.#lastProgress?.maximum &&\n progress.consolidating === this.#lastProgress?.consolidating)\n ) {\n return;\n }\n this.#lastProgress = progress;\n this.#options.onProgress(progress);\n } catch (error) {\n if (abortController.signal.aborted) return;\n throw error;\n } finally {\n if (this.#pending === update) this.#pending = null;\n }\n })();\n this.#pending = update;\n await update;\n }\n\n public stop(): void {\n if (this.#abortController.signal.aborted) return;\n clearInterval(this.#timer ?? undefined);\n this.#timer = null;\n this.#abortController.abort();\n }\n}\n\nexport function deepScanProgressFromWorkbench(\n result: unknown,\n): DeepScanProgress | null {\n if (!isRecord(result) || !isRecord(result[\"scan\"])) return null;\n const progress = result[\"scan\"][\"progress\"];\n if (!isRecord(progress)) return null;\n const independentReviews = progress[\"independentReviews\"];\n if (independentReviews === undefined) return null;\n const parsed = progressSchema.safeParse(independentReviews);\n if (parsed.success) return parsed.data;\n throw new Error(\n \"Codex Security workbench returned invalid Deep Scan progress.\",\n );\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export declare function executablePathForSpawn(command: string): string;
2
+ //# sourceMappingURL=executable-path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executable-path.d.ts","sourceRoot":"","sources":["../src/executable-path.ts"],"names":[],"mappings":"AAGA,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAQ9D"}
@@ -0,0 +1,12 @@
1
+ /* Generated from plugin executable-path.ts. Run `pnpm generate:models`. */
2
+ import { win32 } from "node:path";
3
+ export function executablePathForSpawn(command) {
4
+ if (process.platform !== "win32" || !win32.isAbsolute(command))
5
+ return command;
6
+ // Root-relative paths still depend on the child's drive and working directory.
7
+ const root = win32.parse(command).root;
8
+ return root === "\\" || root === "/"
9
+ ? command
10
+ : win32.toNamespacedPath(command);
11
+ }
12
+ //# sourceMappingURL=executable-path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executable-path.js","sourceRoot":"","sources":["../src/executable-path.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAElC,MAAM,UAAU,sBAAsB,CAAC,OAAe;IACpD,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC;QAC5D,OAAO,OAAO,CAAC;IACjB,+EAA+E;IAC/E,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC;IACvC,OAAO,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,GAAG;QAClC,CAAC,CAAC,OAAO;QACT,CAAC,CAAC,KAAK,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;AACtC,CAAC","sourcesContent":["/* Generated from plugin executable-path.ts. Run `pnpm generate:models`. */\nimport { win32 } from \"node:path\";\n\nexport function executablePathForSpawn(command: string): string {\n if (process.platform !== \"win32\" || !win32.isAbsolute(command))\n return command;\n // Root-relative paths still depend on the child's drive and working directory.\n const root = win32.parse(command).root;\n return root === \"\\\\\" || root === \"/\"\n ? command\n : win32.toNamespacedPath(command);\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { type ChildProcessWithoutNullStreams, type SpawnOptionsWithoutStdio } from "node:child_process";
1
+ import { type StartCodex } from "./runtime.js";
2
2
  import { type ScanLogSource } from "./scan-logs.js";
3
3
  interface FeedbackOptions {
4
4
  reason: string;
@@ -8,9 +8,6 @@ interface FeedbackOptions {
8
8
  workingDirectory: string;
9
9
  signal?: AbortSignal;
10
10
  }
11
- type StartCodex = (command: string, args: readonly string[], options: SpawnOptionsWithoutStdio & {
12
- stdio: ["pipe", "pipe", "pipe"];
13
- }) => ChildProcessWithoutNullStreams;
14
11
  export declare function sendFeedback(options: FeedbackOptions, startCodex?: StartCodex): Promise<{
15
12
  feedbackId: string;
16
13
  scanId: string | null;
@@ -1 +1 @@
1
- {"version":3,"file":"feedback.d.ts","sourceRoot":"","sources":["../src/feedback.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,8BAA8B,EACnC,KAAK,wBAAwB,EAC9B,MAAM,oBAAoB,CAAC;AAY5B,OAAO,EAAqB,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAQvE,UAAU,eAAe;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,OAAO,CAAC;IACrB,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC,UAAU,CAAC;IAC/B,gBAAgB,EAAE,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,KAAK,UAAU,GAAG,CAChB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,OAAO,EAAE,wBAAwB,GAAG;IAAE,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,KACpE,8BAA8B,CAAC;AAEpC,wBAAsB,YAAY,CAChC,OAAO,EAAE,eAAe,EACxB,UAAU,GAAE,UAAkB;;;;GA4K/B"}
1
+ {"version":3,"file":"feedback.d.ts","sourceRoot":"","sources":["../src/feedback.ts"],"names":[],"mappings":"AAOA,OAAO,EAIL,KAAK,UAAU,EAChB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAqB,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAQvE,UAAU,eAAe;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,OAAO,CAAC;IACrB,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC,UAAU,CAAC;IAC/B,gBAAgB,EAAE,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,wBAAsB,YAAY,CAChC,OAAO,EAAE,eAAe,EACxB,UAAU,GAAE,UAAkB;;;;GA4K/B"}
package/dist/feedback.js CHANGED
@@ -1,4 +1,4 @@
1
- import { spawn, } from "node:child_process";
1
+ import { spawn } from "node:child_process";
2
2
  import { mkdtemp, rm, writeFile } from "node:fs/promises";
3
3
  import { tmpdir } from "node:os";
4
4
  import { join } from "node:path";
@@ -1 +1 @@
1
- {"version":3,"file":"feedback.js","sourceRoot":"","sources":["../src/feedback.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,GAGN,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EACL,2BAA2B,EAC3B,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,iBAAiB,EAAsB,MAAM,gBAAgB,CAAC;AACvE,OAAO,EACL,sBAAsB,EACtB,wBAAwB,EACxB,iBAAiB,EACjB,OAAO,GACR,MAAM,cAAc,CAAC;AAiBtB,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,OAAwB,EACxB,UAAU,GAAe,KAAK;IAE9B,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,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QACT,IAAI,SAAS,KAAK,SAAS;YACzB,MAAM,EAAE,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1D,CAAC;AACH,CAAC","sourcesContent":["import {\n spawn,\n type ChildProcessWithoutNullStreams,\n type SpawnOptionsWithoutStdio,\n} from \"node:child_process\";\nimport { mkdtemp, rm, writeFile } from \"node:fs/promises\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { createInterface } from \"node:readline\";\nimport { configuredCodexHome, readCodexHomeConfig } from \"./auth.js\";\nimport { CodexSecurityError } from \"./errors.js\";\nimport {\n codexSecurityCredentialHome,\n executablePathForSpawn,\n resolveCodexCommand,\n} from \"./runtime.js\";\nimport { readSavedScanLogs, type ScanLogSource } from \"./scan-logs.js\";\nimport {\n BUNDLED_PLUGIN_VERSION,\n CODEX_EXECUTABLE_VERSION,\n CODEX_SDK_VERSION,\n VERSION,\n} from \"./version.js\";\n\ninterface FeedbackOptions {\n reason: string;\n includeLogs: boolean;\n scan?: ScanLogSource;\n environment: NodeJS.ProcessEnv;\n workingDirectory: string;\n signal?: AbortSignal;\n}\n\ntype StartCodex = (\n command: string,\n args: readonly string[],\n options: SpawnOptionsWithoutStdio & { stdio: [\"pipe\", \"pipe\", \"pipe\"] },\n) => ChildProcessWithoutNullStreams;\n\nexport async function sendFeedback(\n options: FeedbackOptions,\n startCodex: StartCodex = spawn,\n) {\n const { scan, environment, includeLogs } = options;\n options.signal?.throwIfAborted();\n const codexHome = codexSecurityCredentialHome(environment);\n const config = await readCodexHomeConfig(environment);\n const feedback = config[\"feedback\"] as { enabled?: boolean } | undefined;\n if (feedback?.enabled === false) {\n throw new CodexSecurityError(\n \"Sending feedback is disabled by configuration.\",\n );\n }\n\n let directory: string | undefined;\n try {\n const extraLogFiles: string[] = [];\n if (includeLogs && scan !== undefined) {\n try {\n const logs = await readSavedScanLogs(\n scan,\n [codexHome, configuredCodexHome(environment)],\n { allowMissingRoot: true },\n );\n if (logs.sessions.length > 0) {\n directory = await mkdtemp(join(tmpdir(), \"codex-security-feedback-\"));\n const path = join(directory, \"scan-logs.json\");\n await writeFile(path, JSON.stringify(logs), { mode: 0o600 });\n extraLogFiles.push(path);\n }\n } catch {\n options.signal?.throwIfAborted();\n console.warn(\n \"Codex Security could not attach saved scan logs; sending feedback with available Codex logs.\",\n );\n }\n }\n\n options.signal?.throwIfAborted();\n const command = resolveCodexCommand(environment);\n const child = startCodex(\n executablePathForSpawn(command.command),\n [\"app-server\", \"--stdio\"],\n {\n cwd: options.workingDirectory,\n env: { ...environment, CODEX_HOME: codexHome },\n stdio: [\"pipe\", \"pipe\", \"pipe\"],\n windowsHide: true,\n signal: options.signal,\n },\n );\n const uploaded = Promise.withResolvers<string>();\n let stderr = \"\";\n let stdinError: Error | undefined;\n const closed = new Promise<void>((resolve) => {\n child.once(\"close\", () => {\n uploaded.reject(\n new CodexSecurityError(\n stderr || \"Codex exited before feedback was uploaded.\",\n ),\n );\n resolve();\n });\n });\n child.once(\"error\", uploaded.reject);\n child.stdin.on(\"error\", (error: Error) => {\n stdinError ??= error;\n uploaded.reject(error);\n });\n child.stderr.setEncoding(\"utf8\").on(\"data\", (chunk: string) => {\n stderr += chunk;\n });\n const send = (message: object) =>\n child.stdin.write(`${JSON.stringify(message)}\\n`);\n const lines = createInterface({ input: child.stdout, crlfDelay: Infinity });\n const releaseCanceledPipes = () => {\n if (!options.signal?.aborted) return;\n uploaded.reject(options.signal.reason);\n if (child.exitCode === null && child.signalCode === null) return;\n lines.close();\n child.stdin.destroy();\n child.stdout.destroy();\n child.stderr.destroy();\n };\n options.signal?.addEventListener(\"abort\", releaseCanceledPipes, {\n once: true,\n });\n child.once(\"exit\", releaseCanceledPipes);\n lines.on(\"line\", (line) => {\n try {\n const message = JSON.parse(line) as {\n id?: number;\n method?: string;\n error?: { message: string };\n result?: { threadId?: string };\n };\n if (message.method !== undefined || message.id === undefined) return;\n if (message.error) throw new CodexSecurityError(message.error.message);\n if (message.id === 1) {\n send({ method: \"initialized\" });\n send({\n id: 2,\n method: \"feedback/upload\",\n params: {\n classification: \"bug\",\n reason: options.reason,\n // Codex also collects this thread's descendants. Shared owners\n // belong only in the explicit attachment, not in that subtree.\n threadId:\n !includeLogs ||\n scan?.executionThreadIds?.includes(\n scan.continuationThreadId ?? \"\",\n )\n ? scan?.continuationThreadId\n : undefined,\n includeLogs,\n extraLogFiles,\n tags: {\n codex_security_version: VERSION,\n codex_security_plugin_version: BUNDLED_PLUGIN_VERSION,\n codex_security_codex_version: CODEX_EXECUTABLE_VERSION,\n codex_security_sdk_version: CODEX_SDK_VERSION,\n ...(scan === undefined\n ? {}\n : { codex_security_scan_id: scan.scanId }),\n },\n },\n });\n } else if (message.id === 2) {\n const feedbackId = message.result?.threadId;\n if (!feedbackId)\n throw new CodexSecurityError(\"Codex did not return a feedback ID.\");\n uploaded.resolve(feedbackId);\n }\n } catch (error) {\n uploaded.reject(error);\n }\n });\n try {\n try {\n send({\n id: 1,\n method: \"initialize\",\n params: { clientInfo: { name: \"codex-security\", version: VERSION } },\n });\n return {\n feedbackId: await uploaded.promise,\n scanId: scan?.scanId ?? null,\n includedLogs: includeLogs,\n };\n } finally {\n lines.close();\n child.stdin.end();\n child.kill();\n const timer = setTimeout(() => child.kill(\"SIGKILL\"), 1_000);\n try {\n await closed;\n } finally {\n clearTimeout(timer);\n options.signal?.removeEventListener(\"abort\", releaseCanceledPipes);\n child.removeListener(\"exit\", releaseCanceledPipes);\n }\n }\n } catch (error) {\n options.signal?.throwIfAborted();\n if (error === stdinError && stderr)\n throw new CodexSecurityError(stderr, { cause: error });\n throw error;\n }\n } finally {\n if (directory !== undefined)\n await rm(directory, { recursive: true, force: true });\n }\n}\n"]}
1
+ {"version":3,"file":"feedback.js","sourceRoot":"","sources":["../src/feedback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,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AI,EAAE,CAAC;gBACb,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,CAAC,CAAC;gBAC7D,IAAI,CAAC;oBACH,MAAM,MAAM,CAAC;gBACf,CAAC;wBAAS,CAAC;oBACT,YAAY,CAAC,KAAK,CAAC,CAAC;oBACpB,OAAO,CAAC,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,CAAC,CAAC;oBACnE,KAAK,CAAC,cAAc,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;gBACrD,CAAC;YACH,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC;YACjC,IAAI,KAAK,KAAK,UAAU,IAAI,MAAM;gBAChC,MAAM,IAAI,kBAAkB,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;YACzD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;YAAS,CAAC;QACT,IAAI,SAAS,KAAK,SAAS;YACzB,MAAM,EAAE,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1D,CAAC;AACH,CAAC","sourcesContent":["import { spawn } from \"node:child_process\";\nimport { mkdtemp, rm, writeFile } from \"node:fs/promises\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { createInterface } from \"node:readline\";\nimport { configuredCodexHome, readCodexHomeConfig } from \"./auth.js\";\nimport { CodexSecurityError } from \"./errors.js\";\nimport {\n codexSecurityCredentialHome,\n executablePathForSpawn,\n resolveCodexCommand,\n type StartCodex,\n} from \"./runtime.js\";\nimport { readSavedScanLogs, type ScanLogSource } from \"./scan-logs.js\";\nimport {\n BUNDLED_PLUGIN_VERSION,\n CODEX_EXECUTABLE_VERSION,\n CODEX_SDK_VERSION,\n VERSION,\n} from \"./version.js\";\n\ninterface FeedbackOptions {\n reason: string;\n includeLogs: boolean;\n scan?: ScanLogSource;\n environment: NodeJS.ProcessEnv;\n workingDirectory: string;\n signal?: AbortSignal;\n}\n\nexport async function sendFeedback(\n options: FeedbackOptions,\n startCodex: StartCodex = spawn,\n) {\n const { scan, environment, includeLogs } = options;\n options.signal?.throwIfAborted();\n const codexHome = codexSecurityCredentialHome(environment);\n const config = await readCodexHomeConfig(environment);\n const feedback = config[\"feedback\"] as { enabled?: boolean } | undefined;\n if (feedback?.enabled === false) {\n throw new CodexSecurityError(\n \"Sending feedback is disabled by configuration.\",\n );\n }\n\n let directory: string | undefined;\n try {\n const extraLogFiles: string[] = [];\n if (includeLogs && scan !== undefined) {\n try {\n const logs = await readSavedScanLogs(\n scan,\n [codexHome, configuredCodexHome(environment)],\n { allowMissingRoot: true },\n );\n if (logs.sessions.length > 0) {\n directory = await mkdtemp(join(tmpdir(), \"codex-security-feedback-\"));\n const path = join(directory, \"scan-logs.json\");\n await writeFile(path, JSON.stringify(logs), { mode: 0o600 });\n extraLogFiles.push(path);\n }\n } catch {\n options.signal?.throwIfAborted();\n console.warn(\n \"Codex Security could not attach saved scan logs; sending feedback with available Codex logs.\",\n );\n }\n }\n\n options.signal?.throwIfAborted();\n const command = resolveCodexCommand(environment);\n const child = startCodex(\n executablePathForSpawn(command.command),\n [\"app-server\", \"--stdio\"],\n {\n cwd: options.workingDirectory,\n env: { ...environment, CODEX_HOME: codexHome },\n stdio: [\"pipe\", \"pipe\", \"pipe\"],\n windowsHide: true,\n signal: options.signal,\n },\n );\n const uploaded = Promise.withResolvers<string>();\n let stderr = \"\";\n let stdinError: Error | undefined;\n const closed = new Promise<void>((resolve) => {\n child.once(\"close\", () => {\n uploaded.reject(\n new CodexSecurityError(\n stderr || \"Codex exited before feedback was uploaded.\",\n ),\n );\n resolve();\n });\n });\n child.once(\"error\", uploaded.reject);\n child.stdin.on(\"error\", (error: Error) => {\n stdinError ??= error;\n uploaded.reject(error);\n });\n child.stderr.setEncoding(\"utf8\").on(\"data\", (chunk: string) => {\n stderr += chunk;\n });\n const send = (message: object) =>\n child.stdin.write(`${JSON.stringify(message)}\\n`);\n const lines = createInterface({ input: child.stdout, crlfDelay: Infinity });\n const releaseCanceledPipes = () => {\n if (!options.signal?.aborted) return;\n uploaded.reject(options.signal.reason);\n if (child.exitCode === null && child.signalCode === null) return;\n lines.close();\n child.stdin.destroy();\n child.stdout.destroy();\n child.stderr.destroy();\n };\n options.signal?.addEventListener(\"abort\", releaseCanceledPipes, {\n once: true,\n });\n child.once(\"exit\", releaseCanceledPipes);\n lines.on(\"line\", (line) => {\n try {\n const message = JSON.parse(line) as {\n id?: number;\n method?: string;\n error?: { message: string };\n result?: { threadId?: string };\n };\n if (message.method !== undefined || message.id === undefined) return;\n if (message.error) throw new CodexSecurityError(message.error.message);\n if (message.id === 1) {\n send({ method: \"initialized\" });\n send({\n id: 2,\n method: \"feedback/upload\",\n params: {\n classification: \"bug\",\n reason: options.reason,\n // Codex also collects this thread's descendants. Shared owners\n // belong only in the explicit attachment, not in that subtree.\n threadId:\n !includeLogs ||\n scan?.executionThreadIds?.includes(\n scan.continuationThreadId ?? \"\",\n )\n ? scan?.continuationThreadId\n : undefined,\n includeLogs,\n extraLogFiles,\n tags: {\n codex_security_version: VERSION,\n codex_security_plugin_version: BUNDLED_PLUGIN_VERSION,\n codex_security_codex_version: CODEX_EXECUTABLE_VERSION,\n codex_security_sdk_version: CODEX_SDK_VERSION,\n ...(scan === undefined\n ? {}\n : { codex_security_scan_id: scan.scanId }),\n },\n },\n });\n } else if (message.id === 2) {\n const feedbackId = message.result?.threadId;\n if (!feedbackId)\n throw new CodexSecurityError(\"Codex did not return a feedback ID.\");\n uploaded.resolve(feedbackId);\n }\n } catch (error) {\n uploaded.reject(error);\n }\n });\n try {\n try {\n send({\n id: 1,\n method: \"initialize\",\n params: { clientInfo: { name: \"codex-security\", version: VERSION } },\n });\n return {\n feedbackId: await uploaded.promise,\n scanId: scan?.scanId ?? null,\n includedLogs: includeLogs,\n };\n } finally {\n lines.close();\n child.stdin.end();\n child.kill();\n const timer = setTimeout(() => child.kill(\"SIGKILL\"), 1_000);\n try {\n await closed;\n } finally {\n clearTimeout(timer);\n options.signal?.removeEventListener(\"abort\", releaseCanceledPipes);\n child.removeListener(\"exit\", releaseCanceledPipes);\n }\n }\n } catch (error) {\n options.signal?.throwIfAborted();\n if (error === stdinError && stderr)\n throw new CodexSecurityError(stderr, { cause: error });\n throw error;\n }\n } finally {\n if (directory !== undefined)\n await rm(directory, { recursive: true, force: true });\n }\n}\n"]}
@@ -0,0 +1,19 @@
1
+ import { type Readable } from "node:stream";
2
+ type Output = Pick<NodeJS.WriteStream, "write"> & {
3
+ on?(event: "error", listener: (error: Error) => void): unknown;
4
+ off?(event: "error", listener: (error: Error) => void): unknown;
5
+ };
6
+ type Execute = (id: string, request: unknown, onProgress?: (event: unknown) => void) => Promise<unknown>;
7
+ /** One bidirectional run, shared with dedupe. This transport never replays. */
8
+ export declare function runHostProtocol(input: Readable, output: Output, operation: {
9
+ label: string;
10
+ requestMethod: string;
11
+ /** Scan cancellation must retain the host's eventual receipt and usage. */
12
+ awaitCancellationReceipt?: boolean;
13
+ errorData?: (error: unknown) => object | undefined;
14
+ run(params: unknown, execute: Execute, signal: AbortSignal, onProgress: (event: unknown) => void): Promise<{
15
+ status: string;
16
+ }>;
17
+ }, signal?: AbortSignal): Promise<number>;
18
+ export {};
19
+ //# sourceMappingURL=host-protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host-protocol.d.ts","sourceRoot":"","sources":["../src/host-protocol.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,QAAQ,EAAY,MAAM,aAAa,CAAC;AA6BtD,KAAK,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,GAAG;IAChD,EAAE,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,GAAG,OAAO,CAAC;IAC/D,GAAG,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,GAAG,OAAO,CAAC;CACjE,CAAC;AACF,KAAK,OAAO,GAAG,CACb,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,OAAO,EAChB,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,KAClC,OAAO,CAAC,OAAO,CAAC,CAAC;AAEtB,+EAA+E;AAC/E,wBAAsB,eAAe,CACnC,KAAK,EAAE,QAAQ,EACf,MAAM,EAAE,MAAM,EACd,SAAS,EAAE;IACT,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,2EAA2E;IAC3E,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,GAAG,SAAS,CAAC;IACnD,GAAG,CACD,MAAM,EAAE,OAAO,EACf,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,WAAW,EACnB,UAAU,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GACnC,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAChC,EACD,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,MAAM,CAAC,CA8PjB"}
@@ -0,0 +1,270 @@
1
+ import { createInterface } from "node:readline";
2
+ import { Writable } from "node:stream";
3
+ import { z } from "incur";
4
+ const rpcId = z.union([z.string(), z.number().int()]);
5
+ const envelope = z.strictObject({ jsonrpc: z.literal("2.0") });
6
+ const request = envelope.extend({
7
+ id: rpcId,
8
+ method: z.literal("run"),
9
+ params: z.unknown(),
10
+ });
11
+ const cancellation = envelope.extend({
12
+ method: z.literal("cancel"),
13
+ params: z.strictObject({ id: rpcId }),
14
+ });
15
+ const progress = envelope.extend({
16
+ method: z.literal("execution.progress"),
17
+ params: z.strictObject({ requestId: z.string(), event: z.unknown() }),
18
+ });
19
+ const response = z.union([
20
+ envelope.extend({ id: rpcId, result: z.unknown() }),
21
+ envelope.extend({
22
+ id: rpcId,
23
+ error: z.strictObject({
24
+ code: z.number().int(),
25
+ message: z.string(),
26
+ data: z.unknown().optional(),
27
+ }),
28
+ }),
29
+ ]);
30
+ /** One bidirectional run, shared with dedupe. This transport never replays. */
31
+ export async function runHostProtocol(input, output, operation, signal) {
32
+ const controller = new AbortController();
33
+ let runId;
34
+ let terminalCode;
35
+ let completed = false;
36
+ let pending;
37
+ const { promise: completion, resolve: resolveCompletion } = Promise.withResolvers();
38
+ const complete = (code) => {
39
+ if (completed)
40
+ return;
41
+ completed = true;
42
+ resolveCompletion(code);
43
+ };
44
+ const stopOutput = (code) => {
45
+ if (completed)
46
+ return;
47
+ complete(code);
48
+ if (output instanceof Writable) {
49
+ // Native stdout can emit close repeatedly when destroy() is called from
50
+ // its close listener. Detach before destroying, even before cleanup runs.
51
+ output.off("close", outputClosed);
52
+ output.destroy();
53
+ }
54
+ };
55
+ const lines = createInterface({
56
+ input,
57
+ crlfDelay: Infinity,
58
+ terminal: false,
59
+ });
60
+ const send = async (message, onFlushed) => {
61
+ const line = `${JSON.stringify(message)}\n`;
62
+ if (output instanceof Writable) {
63
+ if (output.destroyed)
64
+ throw new Error("Host output is closed.");
65
+ await new Promise((resolve, reject) => {
66
+ let settled = false;
67
+ const settle = (error) => {
68
+ if (settled)
69
+ return;
70
+ settled = true;
71
+ output.off("close", closed);
72
+ // Node can emit error/close before the rejected Promise is observed.
73
+ // Record the failed write now, so the selected result cannot win.
74
+ if (error)
75
+ outputError(error);
76
+ else
77
+ onFlushed?.();
78
+ error ? reject(error) : resolve();
79
+ };
80
+ const closed = () => settle(new Error("Host output closed during write."));
81
+ output.once("close", closed);
82
+ output.write(line, settle);
83
+ });
84
+ }
85
+ else {
86
+ output.write(line);
87
+ onFlushed?.();
88
+ }
89
+ };
90
+ const fail = (code, message, canWrite = true, data) => {
91
+ if (completed)
92
+ return;
93
+ if (terminalCode !== undefined) {
94
+ if (!canWrite)
95
+ stopOutput(2);
96
+ return;
97
+ }
98
+ terminalCode = 2;
99
+ controller.abort(new Error(message));
100
+ pending?.reject(new Error(message));
101
+ pending = undefined;
102
+ // A peer that stopped reading cannot receive an error. Unblock both the
103
+ // request write and completion instead of waiting for a write callback.
104
+ if (!canWrite ||
105
+ (output instanceof Writable &&
106
+ (output.writableLength > 0 || output.writableNeedDrain))) {
107
+ stopOutput(2);
108
+ return;
109
+ }
110
+ void send({
111
+ jsonrpc: "2.0",
112
+ id: runId ?? null,
113
+ error: { code, message, ...(data === undefined ? {} : { data }) },
114
+ })
115
+ .catch(() => undefined)
116
+ .then(() => complete(2));
117
+ };
118
+ const disconnected = () => {
119
+ // Stdin EOF does not close stdout. If a terminal response is already being
120
+ // written, its callback decides whether delivery succeeded.
121
+ if (terminalCode === undefined)
122
+ fail(-32000, "Host disconnected before the run completed.");
123
+ };
124
+ const inputError = (error) => fail(-32000, error.message);
125
+ const outputError = (error) => fail(-32000, error.message, false);
126
+ const outputClosed = () => outputError(new Error("Host output is closed."));
127
+ const interrupted = () => {
128
+ if (terminalCode !== undefined)
129
+ stopOutput(2);
130
+ else
131
+ fail(-32800, `${operation.label} canceled.`);
132
+ };
133
+ const canceled = () => {
134
+ if (!operation.awaitCancellationReceipt ||
135
+ terminalCode !== undefined ||
136
+ (output instanceof Writable &&
137
+ (output.writableLength > 0 || output.writableNeedDrain))) {
138
+ interrupted();
139
+ return;
140
+ }
141
+ if (controller.signal.aborted)
142
+ return;
143
+ controller.abort(new Error(`${operation.label} canceled.`));
144
+ if (pending)
145
+ void send({
146
+ jsonrpc: "2.0",
147
+ method: "execution.cancel",
148
+ params: { requestId: pending.id },
149
+ }).catch(outputError);
150
+ };
151
+ input.on("error", inputError);
152
+ input.on("close", disconnected);
153
+ if (output instanceof Writable)
154
+ output.on("close", outputClosed);
155
+ lines.on("close", disconnected);
156
+ lines.on("error", inputError);
157
+ output.on?.("error", outputError);
158
+ signal?.addEventListener("abort", interrupted, { once: true });
159
+ lines.on("line", (line) => {
160
+ let message;
161
+ try {
162
+ message = JSON.parse(line);
163
+ }
164
+ catch {
165
+ fail(-32700, "Invalid JSON.");
166
+ return;
167
+ }
168
+ const cancel = cancellation.safeParse(message);
169
+ if (cancel.success) {
170
+ if (runId === undefined || cancel.data.params.id !== runId)
171
+ fail(-32600, "Cancellation does not match the active run.");
172
+ else
173
+ canceled();
174
+ return;
175
+ }
176
+ if (terminalCode !== undefined)
177
+ return;
178
+ const run = request.safeParse(message);
179
+ if (run.success) {
180
+ if (runId !== undefined) {
181
+ fail(-32600, "Only one run request is allowed.");
182
+ return;
183
+ }
184
+ runId = run.data.id;
185
+ void operation
186
+ .run(run.data.params, (id, params, onProgress) => {
187
+ if (terminalCode !== undefined || controller.signal.aborted)
188
+ return Promise.reject(controller.signal.reason);
189
+ if (pending)
190
+ return Promise.reject(new Error("Execution is already pending."));
191
+ return new Promise((resolve, reject) => {
192
+ pending = { id, resolve, reject, onProgress };
193
+ void send({
194
+ jsonrpc: "2.0",
195
+ id,
196
+ method: operation.requestMethod,
197
+ params,
198
+ }).catch(outputError);
199
+ });
200
+ }, controller.signal, (event) => {
201
+ if (terminalCode === undefined)
202
+ void send({
203
+ jsonrpc: "2.0",
204
+ method: "scan.progress",
205
+ params: { id: runId, event },
206
+ }).catch(outputError);
207
+ })
208
+ .then(async (result) => {
209
+ if (terminalCode !== undefined)
210
+ return;
211
+ const code = result.status === "completed" ? 0 : 1;
212
+ terminalCode = code;
213
+ try {
214
+ await send({ jsonrpc: "2.0", id: runId, result }, () => complete(code));
215
+ }
216
+ catch {
217
+ complete(2);
218
+ }
219
+ }, (error) => fail(-32602, error instanceof Error
220
+ ? error.message
221
+ : "Invalid run parameters.", true, operation.errorData?.(error)));
222
+ return;
223
+ }
224
+ const event = progress.safeParse(message);
225
+ if (event.success &&
226
+ operation.awaitCancellationReceipt &&
227
+ pending &&
228
+ event.data.params.requestId === pending.id) {
229
+ // Optional progress must never interrupt execution, including bad events
230
+ // or host observer exceptions. Correlation still rejects stale messages.
231
+ try {
232
+ pending.onProgress?.(event.data.params.event);
233
+ }
234
+ catch { }
235
+ return;
236
+ }
237
+ const reply = response.safeParse(message);
238
+ if (!reply.success || !pending || reply.data.id !== pending.id) {
239
+ fail(-32600, `Malformed, unexpected, or mismatched ${operation.requestMethod === "review.run" ? "review" : "execution"} response.`);
240
+ return;
241
+ }
242
+ const execution = pending;
243
+ pending = undefined;
244
+ if ("error" in reply.data)
245
+ execution.reject(new Error(reply.data.error.message));
246
+ else
247
+ execution.resolve(reply.data.result);
248
+ });
249
+ if (signal?.aborted)
250
+ interrupted();
251
+ if (input.readableEnded || input.destroyed)
252
+ disconnected();
253
+ try {
254
+ return await completion;
255
+ }
256
+ finally {
257
+ lines.removeAllListeners("line");
258
+ lines.removeListener("close", disconnected);
259
+ lines.removeListener("error", inputError);
260
+ lines.close();
261
+ input.pause();
262
+ input.removeListener("error", inputError);
263
+ input.removeListener("close", disconnected);
264
+ if (output instanceof Writable)
265
+ output.removeListener("close", outputClosed);
266
+ output.off?.("error", outputError);
267
+ signal?.removeEventListener("abort", interrupted);
268
+ }
269
+ }
270
+ //# sourceMappingURL=host-protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host-protocol.js","sourceRoot":"","sources":["../src/host-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAiB,QAAQ,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,CAAC,EAAE,MAAM,OAAO,CAAC;AAE1B,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;AACtD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IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;;YACnD,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;IACH,IAAI,MAAM,EAAE,OAAO;QAAE,WAAW,EAAE,CAAC;IACnC,IAAI,KAAK,CAAC,aAAa,IAAI,KAAK,CAAC,SAAS;QAAE,YAAY,EAAE,CAAC;IAC3D,IAAI,CAAC;QACH,OAAO,MAAM,UAAU,CAAC;IAC1B,CAAC;YAAS,CAAC;QACT,KAAK,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;QACjC,KAAK,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;QAC5C,KAAK,CAAC,cAAc,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QAC1C,KAAK,CAAC,KAAK,EAAE,CAAC;QACd,KAAK,CAAC,KAAK,EAAE,CAAC;QACd,KAAK,CAAC,cAAc,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QAC1C,KAAK,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;QAC5C,IAAI,MAAM,YAAY,QAAQ;YAC5B,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;QAC/C,MAAM,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QACnC,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IACpD,CAAC;AACH,CAAC","sourcesContent":["import { createInterface } from \"node:readline\";\nimport { type Readable, Writable } from \"node:stream\";\nimport { z } from \"incur\";\n\nconst rpcId = z.union([z.string(), z.number().int()]);\nconst envelope = z.strictObject({ jsonrpc: z.literal(\"2.0\") });\nconst request = envelope.extend({\n id: rpcId,\n method: z.literal(\"run\"),\n params: z.unknown(),\n});\nconst cancellation = envelope.extend({\n method: z.literal(\"cancel\"),\n params: z.strictObject({ id: rpcId }),\n});\nconst progress = envelope.extend({\n method: z.literal(\"execution.progress\"),\n params: z.strictObject({ requestId: z.string(), event: z.unknown() }),\n});\nconst response = z.union([\n envelope.extend({ id: rpcId, result: z.unknown() }),\n envelope.extend({\n id: rpcId,\n error: z.strictObject({\n code: z.number().int(),\n message: z.string(),\n data: z.unknown().optional(),\n }),\n }),\n]);\ntype Output = Pick<NodeJS.WriteStream, \"write\"> & {\n on?(event: \"error\", listener: (error: Error) => void): unknown;\n off?(event: \"error\", listener: (error: Error) => void): unknown;\n};\ntype Execute = (\n id: string,\n request: unknown,\n onProgress?: (event: unknown) => void,\n) => Promise<unknown>;\n\n/** One bidirectional run, shared with dedupe. This transport never replays. */\nexport async function runHostProtocol(\n input: Readable,\n output: Output,\n operation: {\n label: string;\n requestMethod: string;\n /** Scan cancellation must retain the host's eventual receipt and usage. */\n awaitCancellationReceipt?: boolean;\n errorData?: (error: unknown) => object | undefined;\n run(\n params: unknown,\n execute: Execute,\n signal: AbortSignal,\n onProgress: (event: unknown) => void,\n ): Promise<{ status: string }>;\n },\n signal?: AbortSignal,\n): Promise<number> {\n const controller = new AbortController();\n let runId: string | number | undefined;\n let terminalCode: number | undefined;\n let completed = false;\n let pending:\n | {\n id: string;\n resolve(value: unknown): void;\n reject(error: Error): void;\n onProgress?: (event: unknown) => void;\n }\n | undefined;\n const { promise: completion, resolve: resolveCompletion } =\n Promise.withResolvers<number>();\n const complete = (code: number) => {\n if (completed) return;\n completed = true;\n resolveCompletion(code);\n };\n const stopOutput = (code: number) => {\n if (completed) return;\n complete(code);\n if (output instanceof Writable) {\n // Native stdout can emit close repeatedly when destroy() is called from\n // its close listener. Detach before destroying, even before cleanup runs.\n output.off(\"close\", outputClosed);\n output.destroy();\n }\n };\n const lines = createInterface({\n input,\n crlfDelay: Infinity,\n terminal: false,\n });\n const send = async (message: object, onFlushed?: () => void) => {\n const line = `${JSON.stringify(message)}\\n`;\n if (output instanceof Writable) {\n if (output.destroyed) throw new Error(\"Host output is closed.\");\n await new Promise<void>((resolve, reject) => {\n let settled = false;\n const settle = (error?: Error | null) => {\n if (settled) return;\n settled = true;\n output.off(\"close\", closed);\n // Node can emit error/close before the rejected Promise is observed.\n // Record the failed write now, so the selected result cannot win.\n if (error) outputError(error);\n else onFlushed?.();\n error ? reject(error) : resolve();\n };\n const closed = () =>\n settle(new Error(\"Host output closed during write.\"));\n output.once(\"close\", closed);\n output.write(line, settle);\n });\n } else {\n output.write(line);\n onFlushed?.();\n }\n };\n const fail = (\n code: number,\n message: string,\n canWrite = true,\n data?: object,\n ) => {\n if (completed) return;\n if (terminalCode !== undefined) {\n if (!canWrite) stopOutput(2);\n return;\n }\n terminalCode = 2;\n controller.abort(new Error(message));\n pending?.reject(new Error(message));\n pending = undefined;\n // A peer that stopped reading cannot receive an error. Unblock both the\n // request write and completion instead of waiting for a write callback.\n if (\n !canWrite ||\n (output instanceof Writable &&\n (output.writableLength > 0 || output.writableNeedDrain))\n ) {\n stopOutput(2);\n return;\n }\n void send({\n jsonrpc: \"2.0\",\n id: runId ?? null,\n error: { code, message, ...(data === undefined ? {} : { data }) },\n })\n .catch(() => undefined)\n .then(() => complete(2));\n };\n const disconnected = () => {\n // Stdin EOF does not close stdout. If a terminal response is already being\n // written, its callback decides whether delivery succeeded.\n if (terminalCode === undefined)\n fail(-32000, \"Host disconnected before the run completed.\");\n };\n const inputError = (error: Error) => fail(-32000, error.message);\n const outputError = (error: Error) => fail(-32000, error.message, false);\n const outputClosed = () => outputError(new Error(\"Host output is closed.\"));\n const interrupted = () => {\n if (terminalCode !== undefined) stopOutput(2);\n else fail(-32800, `${operation.label} canceled.`);\n };\n const canceled = () => {\n if (\n !operation.awaitCancellationReceipt ||\n terminalCode !== undefined ||\n (output instanceof Writable &&\n (output.writableLength > 0 || output.writableNeedDrain))\n ) {\n interrupted();\n return;\n }\n if (controller.signal.aborted) return;\n controller.abort(new Error(`${operation.label} canceled.`));\n if (pending)\n void send({\n jsonrpc: \"2.0\",\n method: \"execution.cancel\",\n params: { requestId: pending.id },\n }).catch(outputError);\n };\n input.on(\"error\", inputError);\n input.on(\"close\", disconnected);\n if (output instanceof Writable) output.on(\"close\", outputClosed);\n lines.on(\"close\", disconnected);\n lines.on(\"error\", inputError);\n output.on?.(\"error\", outputError);\n signal?.addEventListener(\"abort\", interrupted, { once: true });\n lines.on(\"line\", (line) => {\n let message: unknown;\n try {\n message = JSON.parse(line);\n } catch {\n fail(-32700, \"Invalid JSON.\");\n return;\n }\n const cancel = cancellation.safeParse(message);\n if (cancel.success) {\n if (runId === undefined || cancel.data.params.id !== runId)\n fail(-32600, \"Cancellation does not match the active run.\");\n else canceled();\n return;\n }\n if (terminalCode !== undefined) return;\n const run = request.safeParse(message);\n if (run.success) {\n if (runId !== undefined) {\n fail(-32600, \"Only one run request is allowed.\");\n return;\n }\n runId = run.data.id;\n void operation\n .run(\n run.data.params,\n (id, params, onProgress) => {\n if (terminalCode !== undefined || controller.signal.aborted)\n return Promise.reject(controller.signal.reason);\n if (pending)\n return Promise.reject(new Error(\"Execution is already pending.\"));\n return new Promise((resolve, reject) => {\n pending = { id, resolve, reject, onProgress };\n void send({\n jsonrpc: \"2.0\",\n id,\n method: operation.requestMethod,\n params,\n }).catch(outputError);\n });\n },\n controller.signal,\n (event) => {\n if (terminalCode === undefined)\n void send({\n jsonrpc: \"2.0\",\n method: \"scan.progress\",\n params: { id: runId, event },\n }).catch(outputError);\n },\n )\n .then(\n async (result) => {\n if (terminalCode !== undefined) return;\n const code = result.status === \"completed\" ? 0 : 1;\n terminalCode = code;\n try {\n await send({ jsonrpc: \"2.0\", id: runId, result }, () =>\n complete(code),\n );\n } catch {\n complete(2);\n }\n },\n (error: unknown) =>\n fail(\n -32602,\n error instanceof Error\n ? error.message\n : \"Invalid run parameters.\",\n true,\n operation.errorData?.(error),\n ),\n );\n return;\n }\n const event = progress.safeParse(message);\n if (\n event.success &&\n operation.awaitCancellationReceipt &&\n pending &&\n event.data.params.requestId === pending.id\n ) {\n // Optional progress must never interrupt execution, including bad events\n // or host observer exceptions. Correlation still rejects stale messages.\n try {\n pending.onProgress?.(event.data.params.event);\n } catch {}\n return;\n }\n const reply = response.safeParse(message);\n if (!reply.success || !pending || reply.data.id !== pending.id) {\n fail(\n -32600,\n `Malformed, unexpected, or mismatched ${operation.requestMethod === \"review.run\" ? \"review\" : \"execution\"} response.`,\n );\n return;\n }\n const execution = pending;\n pending = undefined;\n if (\"error\" in reply.data)\n execution.reject(new Error(reply.data.error.message));\n else execution.resolve(reply.data.result);\n });\n if (signal?.aborted) interrupted();\n if (input.readableEnded || input.destroyed) disconnected();\n try {\n return await completion;\n } finally {\n lines.removeAllListeners(\"line\");\n lines.removeListener(\"close\", disconnected);\n lines.removeListener(\"error\", inputError);\n lines.close();\n input.pause();\n input.removeListener(\"error\", inputError);\n input.removeListener(\"close\", disconnected);\n if (output instanceof Writable)\n output.removeListener(\"close\", outputClosed);\n output.off?.(\"error\", outputError);\n signal?.removeEventListener(\"abort\", interrupted);\n }\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { Readable } from "node:stream";
2
+ import { runHostProtocol } from "./host-protocol.js";
3
+ export declare function runHostedScanProtocol(input: Readable, output: Parameters<typeof runHostProtocol>[1], signal?: AbortSignal): Promise<number>;
4
+ //# sourceMappingURL=hosted-scan-protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hosted-scan-protocol.d.ts","sourceRoot":"","sources":["../src/hosted-scan-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAWrD,wBAAsB,qBAAqB,CACzC,KAAK,EAAE,QAAQ,EACf,MAAM,EAAE,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC,CAAC,CAAC,EAC7C,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,MAAM,CAAC,CA6BjB"}
@@ -0,0 +1,25 @@
1
+ import { runHostProtocol } from "./host-protocol.js";
2
+ import { HostedScanPreparationError, runHostedScan, } from "./hosted-scan.js";
3
+ import { ScanExecutionEventSchema, ScanExecutionResultSchema, } from "./scan-executor.js";
4
+ export async function runHostedScanProtocol(input, output, signal) {
5
+ return await runHostProtocol(input, output, {
6
+ label: "Scan",
7
+ requestMethod: "execution.run",
8
+ awaitCancellationReceipt: true,
9
+ errorData: (error) => error instanceof HostedScanPreparationError
10
+ ? { reason: error.reason }
11
+ : undefined,
12
+ run: async (params, execute, signal, onEvent) => await runHostedScan(params, {
13
+ signal,
14
+ onEvent,
15
+ executor: {
16
+ run: async (request, options) => ScanExecutionResultSchema.parse(await execute(request.requestId, request, (event) => {
17
+ const parsed = ScanExecutionEventSchema.safeParse(event);
18
+ if (parsed.success)
19
+ options.onEvent?.(parsed.data);
20
+ })),
21
+ },
22
+ }),
23
+ }, signal);
24
+ }
25
+ //# sourceMappingURL=hosted-scan-protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hosted-scan-protocol.js","sourceRoot":"","sources":["../src/hosted-scan-protocol.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAEL,0BAA0B,EAC1B,aAAa,GACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,wBAAwB,EACxB,yBAAyB,GAC1B,MAAM,oBAAoB,CAAC;AAE5B,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,KAAe,EACf,MAA6C,EAC7C,MAAoB;IAEpB,OAAO,MAAM,eAAe,CAC1B,KAAK,EACL,MAAM,EACN;QACE,KAAK,EAAE,MAAM;QACb,aAAa,EAAE,eAAe;QAC9B,wBAAwB,EAAE,IAAI;QAC9B,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE,CACnB,KAAK,YAAY,0BAA0B;YACzC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE;YAC1B,CAAC,CAAC,SAAS;QACf,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,CAC9C,MAAM,aAAa,CAAC,MAAyB,EAAE;YAC7C,MAAM;YACN,OAAO;YACP,QAAQ,EAAE;gBACR,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CAC9B,yBAAyB,CAAC,KAAK,CAC7B,MAAM,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;oBAClD,MAAM,MAAM,GAAG,wBAAwB,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;oBACzD,IAAI,MAAM,CAAC,OAAO;wBAAE,OAAO,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;gBACrD,CAAC,CAAC,CACH;aACJ;SACF,CAAC;KACL,EACD,MAAM,CACP,CAAC;AACJ,CAAC","sourcesContent":["import type { Readable } from \"node:stream\";\nimport { runHostProtocol } from \"./host-protocol.js\";\nimport {\n type HostedScanInput,\n HostedScanPreparationError,\n runHostedScan,\n} from \"./hosted-scan.js\";\nimport {\n ScanExecutionEventSchema,\n ScanExecutionResultSchema,\n} from \"./scan-executor.js\";\n\nexport async function runHostedScanProtocol(\n input: Readable,\n output: Parameters<typeof runHostProtocol>[1],\n signal?: AbortSignal,\n): Promise<number> {\n return await runHostProtocol(\n input,\n output,\n {\n label: \"Scan\",\n requestMethod: \"execution.run\",\n awaitCancellationReceipt: true,\n errorData: (error) =>\n error instanceof HostedScanPreparationError\n ? { reason: error.reason }\n : undefined,\n run: async (params, execute, signal, onEvent) =>\n await runHostedScan(params as HostedScanInput, {\n signal,\n onEvent,\n executor: {\n run: async (request, options) =>\n ScanExecutionResultSchema.parse(\n await execute(request.requestId, request, (event) => {\n const parsed = ScanExecutionEventSchema.safeParse(event);\n if (parsed.success) options.onEvent?.(parsed.data);\n }),\n ),\n },\n }),\n },\n signal,\n );\n}\n"]}