@openai/codex-security 0.1.21 → 0.1.24

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 (183) hide show
  1. package/README.md +549 -1
  2. package/_bundled_plugin/.codex-plugin/plugin.json +1 -1
  3. package/_bundled_plugin/.mcp.json +1 -0
  4. package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
  5. package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
  6. package/_bundled_plugin/references/config-preflight.md +2 -30
  7. package/_bundled_plugin/references/core-scan.md +1 -1
  8. package/_bundled_plugin/references/final-report.md +1 -1
  9. package/_bundled_plugin/references/finding-detail-fields.md +5 -10
  10. package/_bundled_plugin/references/sarif-adapter.md +1 -1
  11. package/_bundled_plugin/references/scan-contract.md +10 -0
  12. package/_bundled_plugin/scripts/config_preflight.py +2 -8
  13. package/_bundled_plugin/scripts/deep_scan_workbench.py +6 -1
  14. package/_bundled_plugin/scripts/finalize_scan_contract.py +115 -76
  15. package/_bundled_plugin/scripts/finding_preview.py +22 -4
  16. package/_bundled_plugin/scripts/generate_in_scope_files.py +29 -9
  17. package/_bundled_plugin/scripts/generate_rank_input.py +1 -5
  18. package/_bundled_plugin/scripts/rank_preview.py +1 -0
  19. package/_bundled_plugin/scripts/report_projection.py +8 -14
  20. package/_bundled_plugin/scripts/validate_scan_contract.py +1 -3
  21. package/_bundled_plugin/scripts/windows_scan_local_files.py +90 -6
  22. package/_bundled_plugin/scripts/workbench_cli.py +27 -1
  23. package/_bundled_plugin/scripts/workbench_dashboard.py +138 -0
  24. package/_bundled_plugin/scripts/workbench_db.py +110 -539
  25. package/_bundled_plugin/scripts/workbench_finding_index.py +42 -24
  26. package/_bundled_plugin/scripts/workbench_finding_workflows.py +208 -0
  27. package/_bundled_plugin/scripts/workbench_findings.py +221 -0
  28. package/_bundled_plugin/scripts/workbench_native_indexes.py +1 -2
  29. package/_bundled_plugin/scripts/workbench_publication.py +520 -0
  30. package/_bundled_plugin/scripts/workbench_remediation.py +37 -0
  31. package/_bundled_plugin/scripts/workbench_saved_results.py +322 -89
  32. package/_bundled_plugin/scripts/workbench_scan_history.py +1 -2
  33. package/_bundled_plugin/scripts/workbench_scan_usage.py +9 -33
  34. package/_bundled_plugin/scripts/workbench_schema.py +276 -58
  35. package/_bundled_plugin/scripts/workbench_target.py +30 -6
  36. package/_bundled_plugin/scripts/workbench_validation.py +1 -5
  37. package/_bundled_plugin/skills/assess-patch-risk/SKILL.md +1 -5
  38. package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +6 -1
  39. package/_bundled_plugin/skills/track-findings/SKILL.md +2 -0
  40. package/dist/api.d.ts +5 -1
  41. package/dist/api.d.ts.map +1 -1
  42. package/dist/api.js +135 -27
  43. package/dist/api.js.map +1 -1
  44. package/dist/cli.d.ts +4 -0
  45. package/dist/cli.d.ts.map +1 -1
  46. package/dist/cli.js +158 -62
  47. package/dist/cli.js.map +1 -1
  48. package/dist/cloud-publish.js +5 -1
  49. package/dist/cloud-publish.js.map +1 -1
  50. package/dist/contract.d.ts +1 -0
  51. package/dist/contract.d.ts.map +1 -1
  52. package/dist/contract.js +9 -0
  53. package/dist/contract.js.map +1 -1
  54. package/dist/custom-publish.d.ts +22 -0
  55. package/dist/custom-publish.d.ts.map +1 -0
  56. package/dist/custom-publish.js +47 -0
  57. package/dist/custom-publish.js.map +1 -0
  58. package/dist/custom-validation-prompt.js +1 -1
  59. package/dist/custom-validation-prompt.js.map +1 -1
  60. package/dist/deduplication/checkpointed-review.d.ts +16 -0
  61. package/dist/deduplication/checkpointed-review.d.ts.map +1 -0
  62. package/dist/deduplication/checkpointed-review.js +76 -0
  63. package/dist/deduplication/checkpointed-review.js.map +1 -0
  64. package/dist/deduplication/codex-review.d.ts +21 -0
  65. package/dist/deduplication/codex-review.d.ts.map +1 -0
  66. package/dist/deduplication/codex-review.js +252 -0
  67. package/dist/deduplication/codex-review.js.map +1 -0
  68. package/dist/deduplication/deduplication-prompts.d.ts +8 -0
  69. package/dist/deduplication/deduplication-prompts.d.ts.map +1 -0
  70. package/dist/deduplication/deduplication-prompts.js +35 -0
  71. package/dist/deduplication/deduplication-prompts.js.map +1 -0
  72. package/dist/deduplication/deduplication-reviewer.d.ts +46 -0
  73. package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -0
  74. package/dist/deduplication/deduplication-reviewer.js +105 -0
  75. package/dist/deduplication/deduplication-reviewer.js.map +1 -0
  76. package/dist/deduplication/deduplication.d.ts +6 -0
  77. package/dist/deduplication/deduplication.d.ts.map +1 -0
  78. package/dist/deduplication/deduplication.js +85 -0
  79. package/dist/deduplication/deduplication.js.map +1 -0
  80. package/dist/deduplication/scan.d.ts +16 -0
  81. package/dist/deduplication/scan.d.ts.map +1 -0
  82. package/dist/deduplication/scan.js +101 -0
  83. package/dist/deduplication/scan.js.map +1 -0
  84. package/dist/deep-progress.d.ts +21 -0
  85. package/dist/deep-progress.d.ts.map +1 -0
  86. package/dist/deep-progress.js +108 -0
  87. package/dist/deep-progress.js.map +1 -0
  88. package/dist/finding-dedupe-groups.d.ts +7 -0
  89. package/dist/finding-dedupe-groups.d.ts.map +1 -0
  90. package/dist/finding-dedupe-groups.js +2 -0
  91. package/dist/finding-dedupe-groups.js.map +1 -0
  92. package/dist/finding-retrieval.d.ts +13 -0
  93. package/dist/finding-retrieval.d.ts.map +1 -0
  94. package/dist/finding-retrieval.js +2 -0
  95. package/dist/finding-retrieval.js.map +1 -0
  96. package/dist/finding-workflow.d.ts +53 -0
  97. package/dist/finding-workflow.d.ts.map +1 -0
  98. package/dist/finding-workflow.js +117 -0
  99. package/dist/finding-workflow.js.map +1 -0
  100. package/dist/findings-client.d.ts +15 -0
  101. package/dist/findings-client.d.ts.map +1 -0
  102. package/dist/findings-client.js +60 -0
  103. package/dist/findings-client.js.map +1 -0
  104. package/dist/index.d.ts +5 -0
  105. package/dist/index.d.ts.map +1 -1
  106. package/dist/index.js +2 -0
  107. package/dist/index.js.map +1 -1
  108. package/dist/publication.js +28 -40
  109. package/dist/publication.js.map +1 -1
  110. package/dist/runtime.d.ts +5 -1
  111. package/dist/runtime.d.ts.map +1 -1
  112. package/dist/runtime.js +119 -13
  113. package/dist/runtime.js.map +1 -1
  114. package/dist/saved-scan.d.ts +15 -0
  115. package/dist/saved-scan.d.ts.map +1 -0
  116. package/dist/saved-scan.js +68 -0
  117. package/dist/saved-scan.js.map +1 -0
  118. package/dist/scan-activity.d.ts.map +1 -1
  119. package/dist/scan-activity.js +12 -2
  120. package/dist/scan-activity.js.map +1 -1
  121. package/dist/scan-comparison.d.ts +3 -2
  122. package/dist/scan-comparison.d.ts.map +1 -1
  123. package/dist/scan-comparison.js +1 -1
  124. package/dist/scan-comparison.js.map +1 -1
  125. package/dist/server/dashboard/THIRD_PARTY_NOTICES.txt +276 -0
  126. package/dist/server/dashboard/app.css +2 -0
  127. package/dist/server/dashboard/app.js +66 -0
  128. package/dist/server/dashboard/index.html +18 -0
  129. package/dist/server/dashboard-types.d.ts +45 -0
  130. package/dist/server/dashboard-types.d.ts.map +1 -0
  131. package/dist/server/dashboard-types.js +2 -0
  132. package/dist/server/dashboard-types.js.map +1 -0
  133. package/dist/server/dashboard.d.ts +6 -0
  134. package/dist/server/dashboard.d.ts.map +1 -0
  135. package/dist/server/dashboard.js +45 -0
  136. package/dist/server/dashboard.js.map +1 -0
  137. package/dist/server/embeddings.d.ts +16 -0
  138. package/dist/server/embeddings.d.ts.map +1 -0
  139. package/dist/server/embeddings.js +114 -0
  140. package/dist/server/embeddings.js.map +1 -0
  141. package/dist/server/errors.d.ts +5 -0
  142. package/dist/server/errors.d.ts.map +1 -0
  143. package/dist/server/errors.js +8 -0
  144. package/dist/server/errors.js.map +1 -0
  145. package/dist/server/findings-service.d.ts +20 -0
  146. package/dist/server/findings-service.d.ts.map +1 -0
  147. package/dist/server/findings-service.js +31 -0
  148. package/dist/server/findings-service.js.map +1 -0
  149. package/dist/server/index.d.ts +2 -0
  150. package/dist/server/index.d.ts.map +1 -0
  151. package/dist/server/index.js +6 -0
  152. package/dist/server/index.js.map +1 -0
  153. package/dist/server/routes.d.ts +6 -0
  154. package/dist/server/routes.d.ts.map +1 -0
  155. package/dist/server/routes.js +86 -0
  156. package/dist/server/routes.js.map +1 -0
  157. package/dist/server/serve.d.ts +2 -0
  158. package/dist/server/serve.d.ts.map +1 -0
  159. package/dist/server/serve.js +28 -0
  160. package/dist/server/serve.js.map +1 -0
  161. package/dist/server/server.d.ts +10 -0
  162. package/dist/server/server.d.ts.map +1 -0
  163. package/dist/server/server.js +17 -0
  164. package/dist/server/server.js.map +1 -0
  165. package/dist/server/sqlite-store.d.ts +22 -0
  166. package/dist/server/sqlite-store.d.ts.map +1 -0
  167. package/dist/server/sqlite-store.js +82 -0
  168. package/dist/server/sqlite-store.js.map +1 -0
  169. package/dist/server/storage.d.ts +32 -0
  170. package/dist/server/storage.d.ts.map +1 -0
  171. package/dist/server/storage.js +2 -0
  172. package/dist/server/storage.js.map +1 -0
  173. package/dist/server/validation.d.ts +17 -0
  174. package/dist/server/validation.d.ts.map +1 -0
  175. package/dist/server/validation.js +53 -0
  176. package/dist/server/validation.js.map +1 -0
  177. package/dist/trusted-executable.d.ts.map +1 -1
  178. package/dist/trusted-executable.js +2 -1
  179. package/dist/trusted-executable.js.map +1 -1
  180. package/dist/version.d.ts +1 -1
  181. package/dist/version.js +1 -1
  182. package/dist/version.js.map +1 -1
  183. package/package.json +17 -5
@@ -0,0 +1,22 @@
1
+ import type { DashboardQuery, DashboardSnapshot } from "./dashboard-types.js";
2
+ import type { FindingDedupeGroup } from "../finding-dedupe-groups.js";
3
+ import type { FindingNeighborhood, FindingSearchScope } from "../finding-retrieval.js";
4
+ import type { EmbeddedFinding, FindingsPage, FindingsStore } from "./storage.js";
5
+ export declare class SqliteFindingsStore implements FindingsStore {
6
+ private readonly environment;
7
+ private options?;
8
+ constructor(environment?: NodeJS.ProcessEnv);
9
+ initialize(): Promise<void>;
10
+ dashboard(query: DashboardQuery): Promise<DashboardSnapshot>;
11
+ insert(entries: readonly EmbeddedFinding[], repositoryId?: string): Promise<string[]>;
12
+ list(page: {
13
+ limit: number;
14
+ offset: number;
15
+ }): Promise<FindingsPage>;
16
+ findPotentialDuplicates(findingId: string, scope: FindingSearchScope): Promise<FindingNeighborhood>;
17
+ storeDedupeGroups(groups: readonly string[][]): Promise<FindingDedupeGroup[]>;
18
+ listDedupeGroups(findingId: string): Promise<FindingDedupeGroup[]>;
19
+ private run;
20
+ private resolveOptions;
21
+ }
22
+ //# sourceMappingURL=sqlite-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite-store.d.ts","sourceRoot":"","sources":["../../src/server/sqlite-store.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,KAAK,EACV,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EACZ,aAAa,EACd,MAAM,cAAc,CAAC;AAEtB,qBAAa,mBAAoB,YAAW,aAAa;IAG3C,OAAO,CAAC,QAAQ,CAAC,WAAW;IAFxC,OAAO,CAAC,OAAO,CAAC,CAAmC;gBAEtB,WAAW,GAAE,MAAM,CAAC,UAAwB;IAEnE,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAO5D,MAAM,CACV,OAAO,EAAE,SAAS,eAAe,EAAE,EACnC,YAAY,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC,MAAM,EAAE,CAAC;IAcd,IAAI,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,YAAY,CAAC;IAUpE,uBAAuB,CAC3B,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,kBAAkB,GACxB,OAAO,CAAC,mBAAmB,CAAC;IAuBzB,iBAAiB,CACrB,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,GAC1B,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAc1B,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC;YAQ1D,GAAG;YAKH,cAAc;CAgB7B"}
@@ -0,0 +1,82 @@
1
+ import { bundledPluginRoot, codexSecurityStateDirectory, resolvePluginPython, runWorkbench, } from "../runtime.js";
2
+ import { FindingsError } from "./errors.js";
3
+ export class SqliteFindingsStore {
4
+ environment;
5
+ options;
6
+ constructor(environment = process.env) {
7
+ this.environment = environment;
8
+ }
9
+ async initialize() {
10
+ await this.run(["database-info"]);
11
+ }
12
+ async dashboard(query) {
13
+ return (await this.run(["dashboard"], JSON.stringify(query)));
14
+ }
15
+ async insert(entries, repositoryId) {
16
+ const result = await this.run(["store-findings"], JSON.stringify({ entries, repositoryId }));
17
+ if (result["error"] === "finding_conflict") {
18
+ throw new FindingsError("finding_conflict", "A finding identity conflicts with stored data.");
19
+ }
20
+ return result["findingIds"];
21
+ }
22
+ async list(page) {
23
+ return (await this.run([
24
+ "list-stored-findings",
25
+ "--limit",
26
+ String(page.limit),
27
+ "--offset",
28
+ String(page.offset),
29
+ ]));
30
+ }
31
+ async findPotentialDuplicates(findingId, scope) {
32
+ const result = await this.run([
33
+ "find-potential-duplicates",
34
+ `--finding-id=${findingId}`,
35
+ ...(scope.allRepositories === true
36
+ ? ["--all-repositories"]
37
+ : [`--repository-id=${scope.repositoryId}`]),
38
+ ]);
39
+ if (result["error"] === "finding_not_indexed") {
40
+ throw new FindingsError("finding_not_indexed", "The finding has no current embedding in the requested scope. Import it with the matching repositoryId through POST /v1/bulk/findings before requesting potential duplicates.");
41
+ }
42
+ if (result["error"] === "embedding_failed") {
43
+ throw new FindingsError("embedding_failed", "A stored embedding cannot be compared. Reimport the finding.");
44
+ }
45
+ return result;
46
+ }
47
+ async storeDedupeGroups(groups) {
48
+ const result = await this.run(["store-dedupe-groups"], JSON.stringify({ groups }));
49
+ if (result["error"] === "finding_conflict") {
50
+ throw new FindingsError("finding_conflict", "Every dedupe group member must already exist in the findings database.");
51
+ }
52
+ return result["groups"];
53
+ }
54
+ async listDedupeGroups(findingId) {
55
+ const result = await this.run([
56
+ "list-dedupe-groups",
57
+ `--finding-id=${findingId}`,
58
+ ]);
59
+ return result["groups"];
60
+ }
61
+ async run(args, input) {
62
+ const options = await (this.options ??= this.resolveOptions());
63
+ return await runWorkbench(options, args, input);
64
+ }
65
+ async resolveOptions() {
66
+ const environment = {
67
+ ...this.environment,
68
+ CODEX_SECURITY_STATE_DIR: codexSecurityStateDirectory(this.environment),
69
+ };
70
+ const [python, pluginRoot] = await Promise.all([
71
+ resolvePluginPython({ environment }),
72
+ bundledPluginRoot(),
73
+ ]);
74
+ return {
75
+ python,
76
+ pluginRoot,
77
+ environment,
78
+ failureMessage: "Could not access the findings database",
79
+ };
80
+ }
81
+ }
82
+ //# sourceMappingURL=sqlite-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite-store.js","sourceRoot":"","sources":["../../src/server/sqlite-store.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,2BAA2B,EAC3B,mBAAmB,EACnB,YAAY,GAEb,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAa5C,MAAM,OAAO,mBAAmB;IAGD;IAFrB,OAAO,CAAoC;IAEnD,YAA6B,cAAiC,OAAO,CAAC,GAAG;QAA5C,gBAAW,GAAX,WAAW,CAAiC;IAAG,CAAC;IAE7E,KAAK,CAAC,UAAU;QACd,MAAM,IAAI,CAAC,GAAG,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC;IACpC,CAAC;IAED,KAAK,CAAC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AAM,OAAO,CAAC,GAAG,CAAC;YAC7C,mBAAmB,CAAC,EAAE,WAAW,EAAE,CAAC;YACpC,iBAAiB,EAAE;SACpB,CAAC,CAAC;QACH,OAAO;YACL,MAAM;YACN,UAAU;YACV,WAAW;YACX,cAAc,EAAE,wCAAwC;SACzD,CAAC;IACJ,CAAC;CACF","sourcesContent":["import {\n bundledPluginRoot,\n codexSecurityStateDirectory,\n resolvePluginPython,\n runWorkbench,\n type WorkbenchCommandOptions,\n} from \"../runtime.js\";\nimport { FindingsError } from \"./errors.js\";\nimport type { DashboardQuery, DashboardSnapshot } from \"./dashboard-types.js\";\nimport type { FindingDedupeGroup } from \"../finding-dedupe-groups.js\";\nimport type {\n FindingNeighborhood,\n FindingSearchScope,\n} from \"../finding-retrieval.js\";\nimport type {\n EmbeddedFinding,\n FindingsPage,\n FindingsStore,\n} from \"./storage.js\";\n\nexport class SqliteFindingsStore implements FindingsStore {\n private options?: Promise<WorkbenchCommandOptions>;\n\n constructor(private readonly environment: NodeJS.ProcessEnv = process.env) {}\n\n async initialize(): Promise<void> {\n await this.run([\"database-info\"]);\n }\n\n async dashboard(query: DashboardQuery): Promise<DashboardSnapshot> {\n return (await this.run(\n [\"dashboard\"],\n JSON.stringify(query),\n )) as unknown as DashboardSnapshot;\n }\n\n async insert(\n entries: readonly EmbeddedFinding[],\n repositoryId?: string,\n ): Promise<string[]> {\n const result = await this.run(\n [\"store-findings\"],\n JSON.stringify({ entries, repositoryId }),\n );\n if (result[\"error\"] === \"finding_conflict\") {\n throw new FindingsError(\n \"finding_conflict\",\n \"A finding identity conflicts with stored data.\",\n );\n }\n return result[\"findingIds\"] as string[];\n }\n\n async list(page: { limit: number; offset: number }): Promise<FindingsPage> {\n return (await this.run([\n \"list-stored-findings\",\n \"--limit\",\n String(page.limit),\n \"--offset\",\n String(page.offset),\n ])) as unknown as FindingsPage;\n }\n\n async findPotentialDuplicates(\n findingId: string,\n scope: FindingSearchScope,\n ): Promise<FindingNeighborhood> {\n const result = await this.run([\n \"find-potential-duplicates\",\n `--finding-id=${findingId}`,\n ...(scope.allRepositories === true\n ? [\"--all-repositories\"]\n : [`--repository-id=${scope.repositoryId}`]),\n ]);\n if (result[\"error\"] === \"finding_not_indexed\") {\n throw new FindingsError(\n \"finding_not_indexed\",\n \"The finding has no current embedding in the requested scope. Import it with the matching repositoryId through POST /v1/bulk/findings before requesting potential duplicates.\",\n );\n }\n if (result[\"error\"] === \"embedding_failed\") {\n throw new FindingsError(\n \"embedding_failed\",\n \"A stored embedding cannot be compared. Reimport the finding.\",\n );\n }\n return result as unknown as FindingNeighborhood;\n }\n\n async storeDedupeGroups(\n groups: readonly string[][],\n ): Promise<FindingDedupeGroup[]> {\n const result = await this.run(\n [\"store-dedupe-groups\"],\n JSON.stringify({ groups }),\n );\n if (result[\"error\"] === \"finding_conflict\") {\n throw new FindingsError(\n \"finding_conflict\",\n \"Every dedupe group member must already exist in the findings database.\",\n );\n }\n return result[\"groups\"] as unknown as FindingDedupeGroup[];\n }\n\n async listDedupeGroups(findingId: string): Promise<FindingDedupeGroup[]> {\n const result = await this.run([\n \"list-dedupe-groups\",\n `--finding-id=${findingId}`,\n ]);\n return result[\"groups\"] as unknown as FindingDedupeGroup[];\n }\n\n private async run(args: string[], input?: string) {\n const options = await (this.options ??= this.resolveOptions());\n return await runWorkbench(options, args, input);\n }\n\n private async resolveOptions(): Promise<WorkbenchCommandOptions> {\n const environment = {\n ...this.environment,\n CODEX_SECURITY_STATE_DIR: codexSecurityStateDirectory(this.environment),\n };\n const [python, pluginRoot] = await Promise.all([\n resolvePluginPython({ environment }),\n bundledPluginRoot(),\n ]);\n return {\n python,\n pluginRoot,\n environment,\n failureMessage: \"Could not access the findings database\",\n };\n }\n}\n"]}
@@ -0,0 +1,32 @@
1
+ import type { Finding } from "../models.js";
2
+ import type { DashboardQuery, DashboardSnapshot } from "./dashboard-types.js";
3
+ import type { FindingDedupeGroup } from "../finding-dedupe-groups.js";
4
+ import type { FindingNeighborhood, FindingSearchScope } from "../finding-retrieval.js";
5
+ export interface FindingEmbedding {
6
+ model: string;
7
+ vector: number[];
8
+ }
9
+ export interface EmbeddedFinding {
10
+ finding: Finding;
11
+ embedding: FindingEmbedding;
12
+ }
13
+ export interface FindingsPage {
14
+ findings: Finding[];
15
+ limit: number;
16
+ offset: number;
17
+ total: number;
18
+ nextOffset: number | null;
19
+ }
20
+ export interface FindingsStore {
21
+ initialize(): Promise<void>;
22
+ dashboard(query: DashboardQuery): Promise<DashboardSnapshot>;
23
+ insert(entries: readonly EmbeddedFinding[], repositoryId?: string): Promise<string[]>;
24
+ list(page: {
25
+ limit: number;
26
+ offset: number;
27
+ }): Promise<FindingsPage>;
28
+ storeDedupeGroups(groups: readonly string[][]): Promise<FindingDedupeGroup[]>;
29
+ listDedupeGroups(findingId: string): Promise<FindingDedupeGroup[]>;
30
+ findPotentialDuplicates(findingId: string, scope: FindingSearchScope): Promise<FindingNeighborhood>;
31
+ }
32
+ //# sourceMappingURL=storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/server/storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,KAAK,EACV,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,yBAAyB,CAAC;AAEjC,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,gBAAgB,CAAC;CAC7B;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED,MAAM,WAAW,aAAa;IAC5B,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC7D,MAAM,CACJ,OAAO,EAAE,SAAS,eAAe,EAAE,EACnC,YAAY,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACrB,IAAI,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IACrE,iBAAiB,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC;IAC9E,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC;IACnE,uBAAuB,CACrB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,kBAAkB,GACxB,OAAO,CAAC,mBAAmB,CAAC,CAAC;CACjC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.js","sourceRoot":"","sources":["../../src/server/storage.ts"],"names":[],"mappings":"","sourcesContent":["import type { Finding } from \"../models.js\";\nimport type { DashboardQuery, DashboardSnapshot } from \"./dashboard-types.js\";\nimport type { FindingDedupeGroup } from \"../finding-dedupe-groups.js\";\nimport type {\n FindingNeighborhood,\n FindingSearchScope,\n} from \"../finding-retrieval.js\";\n\nexport interface FindingEmbedding {\n model: string;\n vector: number[];\n}\n\nexport interface EmbeddedFinding {\n finding: Finding;\n embedding: FindingEmbedding;\n}\n\nexport interface FindingsPage {\n findings: Finding[];\n limit: number;\n offset: number;\n total: number;\n nextOffset: number | null;\n}\n\nexport interface FindingsStore {\n initialize(): Promise<void>;\n dashboard(query: DashboardQuery): Promise<DashboardSnapshot>;\n insert(\n entries: readonly EmbeddedFinding[],\n repositoryId?: string,\n ): Promise<string[]>;\n list(page: { limit: number; offset: number }): Promise<FindingsPage>;\n storeDedupeGroups(groups: readonly string[][]): Promise<FindingDedupeGroup[]>;\n listDedupeGroups(findingId: string): Promise<FindingDedupeGroup[]>;\n findPotentialDuplicates(\n findingId: string,\n scope: FindingSearchScope,\n ): Promise<FindingNeighborhood>;\n}\n"]}
@@ -0,0 +1,17 @@
1
+ import { type ValidateFunction } from "ajv/dist/2020.js";
2
+ import type { Finding } from "../models.js";
3
+ import type { FindingSearchScope } from "../finding-retrieval.js";
4
+ export type FindingsRequest = {
5
+ findings: Finding[];
6
+ repositoryId?: string;
7
+ };
8
+ export declare const validateDedupeGroups: ValidateFunction<{
9
+ groups: string[][];
10
+ }>;
11
+ export declare function findingsRequestValidator(): Promise<ValidateFunction<FindingsRequest>>;
12
+ export declare function findingSearchScope(parameters: URLSearchParams): FindingSearchScope;
13
+ export declare function pagination(parameters: URLSearchParams): {
14
+ limit: number;
15
+ offset: number;
16
+ };
17
+ //# sourceMappingURL=validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/server/validation.ts"],"names":[],"mappings":"AAEA,OAAgB,EAAE,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAIlE,MAAM,MAAM,eAAe,GAAG;IAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE7E,eAAO,MAAM,oBAAoB;YACvB,MAAM,EAAE,EAAE;EAelB,CAAC;AAEH,wBAAsB,wBAAwB,IAAI,OAAO,CACvD,gBAAgB,CAAC,eAAe,CAAC,CAClC,CAaA;AAED,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,eAAe,GAC1B,kBAAkB,CAWpB;AAED,wBAAgB,UAAU,CAAC,UAAU,EAAE,eAAe,GAAG;IACvD,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAeA"}
@@ -0,0 +1,53 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import Ajv2020 from "ajv/dist/2020.js";
4
+ import { bundledPluginRoot } from "../runtime.js";
5
+ import { FindingsError } from "./errors.js";
6
+ export const validateDedupeGroups = new Ajv2020().compile({
7
+ type: "object",
8
+ required: ["groups"],
9
+ properties: {
10
+ groups: {
11
+ type: "array",
12
+ items: {
13
+ type: "array",
14
+ minItems: 2,
15
+ uniqueItems: true,
16
+ items: { type: "string", minLength: 1 },
17
+ },
18
+ },
19
+ },
20
+ });
21
+ export async function findingsRequestValidator() {
22
+ const root = await bundledPluginRoot();
23
+ const schema = JSON.parse(await readFile(join(root, "schemas", "findings.schema.json"), "utf8"));
24
+ return new Ajv2020({ strict: false }).compile({
25
+ type: "object",
26
+ required: ["findings"],
27
+ properties: {
28
+ findings: schema.properties.findings,
29
+ repositoryId: { type: "string", minLength: 1 },
30
+ },
31
+ });
32
+ }
33
+ export function findingSearchScope(parameters) {
34
+ const repositoryId = parameters.get("repositoryId");
35
+ const allRepositories = parameters.get("allRepositories");
36
+ if (allRepositories === "true" && repositoryId === null)
37
+ return { allRepositories: true };
38
+ if (repositoryId && (allRepositories === null || allRepositories === "false"))
39
+ return { repositoryId };
40
+ throw new FindingsError("invalid_request", "Specify repositoryId or allRepositories=true, not both.");
41
+ }
42
+ export function pagination(parameters) {
43
+ const limit = Number(parameters.get("limit") ?? 50);
44
+ const offset = Number(parameters.get("offset") ?? 0);
45
+ if (!Number.isSafeInteger(limit) ||
46
+ limit < 1 ||
47
+ !Number.isSafeInteger(offset) ||
48
+ offset < 0) {
49
+ throw new FindingsError("invalid_request", "limit must be a positive integer and offset must be a non-negative integer.");
50
+ }
51
+ return { limit, offset };
52
+ }
53
+ //# sourceMappingURL=validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/server/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,OAAkC,MAAM,kBAAkB,CAAC;AAGlE,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAI5C,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,OAAO,EAAE,CAAC,OAAO,CAEtD;IACD,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,CAAC,QAAQ,CAAC;IACpB,UAAU,EAAE;QACV,MAAM,EAAE;YACN,IAAI,EAAE,OAAO;YACb,KAAK,EAAE;gBACL,IAAI,EAAE,OAAO;gBACb,QAAQ,EAAE,CAAC;gBACX,WAAW,EAAE,IAAI;gBACjB,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,EAAE;aACxC;SACF;KACF;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,KAAK,UAAU,wBAAwB;IAG5C,MAAM,IAAI,GAAG,MAAM,iBAAiB,EAAE,CAAC;IACvC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CACvB,MAAM,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,sBAAsB,CAAC,EAAE,MAAM,CAAC,CACtE,CAAC;IACF,OAAO,IAAI,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,OAAO,CA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AAC3B,CAAC","sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport Ajv2020, { type ValidateFunction } from \"ajv/dist/2020.js\";\nimport type { Finding } from \"../models.js\";\nimport type { FindingSearchScope } from \"../finding-retrieval.js\";\nimport { bundledPluginRoot } from \"../runtime.js\";\nimport { FindingsError } from \"./errors.js\";\n\nexport type FindingsRequest = { findings: Finding[]; repositoryId?: string };\n\nexport const validateDedupeGroups = new Ajv2020().compile<{\n groups: string[][];\n}>({\n type: \"object\",\n required: [\"groups\"],\n properties: {\n groups: {\n type: \"array\",\n items: {\n type: \"array\",\n minItems: 2,\n uniqueItems: true,\n items: { type: \"string\", minLength: 1 },\n },\n },\n },\n});\n\nexport async function findingsRequestValidator(): Promise<\n ValidateFunction<FindingsRequest>\n> {\n const root = await bundledPluginRoot();\n const schema = JSON.parse(\n await readFile(join(root, \"schemas\", \"findings.schema.json\"), \"utf8\"),\n );\n return new Ajv2020({ strict: false }).compile<FindingsRequest>({\n type: \"object\",\n required: [\"findings\"],\n properties: {\n findings: schema.properties.findings,\n repositoryId: { type: \"string\", minLength: 1 },\n },\n });\n}\n\nexport function findingSearchScope(\n parameters: URLSearchParams,\n): FindingSearchScope {\n const repositoryId = parameters.get(\"repositoryId\");\n const allRepositories = parameters.get(\"allRepositories\");\n if (allRepositories === \"true\" && repositoryId === null)\n return { allRepositories: true };\n if (repositoryId && (allRepositories === null || allRepositories === \"false\"))\n return { repositoryId };\n throw new FindingsError(\n \"invalid_request\",\n \"Specify repositoryId or allRepositories=true, not both.\",\n );\n}\n\nexport function pagination(parameters: URLSearchParams): {\n limit: number;\n offset: number;\n} {\n const limit = Number(parameters.get(\"limit\") ?? 50);\n const offset = Number(parameters.get(\"offset\") ?? 0);\n if (\n !Number.isSafeInteger(limit) ||\n limit < 1 ||\n !Number.isSafeInteger(offset) ||\n offset < 0\n ) {\n throw new FindingsError(\n \"invalid_request\",\n \"limit must be a positive integer and offset must be a non-negative integer.\",\n );\n }\n return { limit, offset };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"trusted-executable.d.ts","sourceRoot":"","sources":["../src/trusted-executable.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;CACjD;AAED,wBAAsB,wBAAwB,CAC5C,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,EACzD,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAsFnC"}
1
+ {"version":3,"file":"trusted-executable.d.ts","sourceRoot":"","sources":["../src/trusted-executable.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;CACjD;AAED,wBAAsB,wBAAwB,CAC5C,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,EACzD,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAwFnC"}
@@ -3,7 +3,8 @@ import { access, realpath, stat } from "node:fs/promises";
3
3
  import { delimiter, extname, isAbsolute, join, relative, resolve, sep, } from "node:path";
4
4
  export async function resolveTrustedExecutable(candidate, environment, protectedRoot) {
5
5
  const root = await realpath(protectedRoot).catch(() => resolve(protectedRoot));
6
- const path = Object.entries(environment).find(([name]) => name.toUpperCase() === "PATH")?.[1];
6
+ const path = environment["PATH"] ??
7
+ Object.entries(environment).find(([name]) => name.toUpperCase() === "PATH")?.[1];
7
8
  const entries = [];
8
9
  for (let entry of path?.split(delimiter) ?? []) {
9
10
  if (process.platform === "win32" &&
@@ -1 +1 @@
1
- {"version":3,"file":"trusted-executable.js","sourceRoot":"","sources":["../src/trusted-executable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EACL,SAAS,EACT,OAAO,EACP,UAAU,EACV,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,GAAG,GACJ,MAAM,WAAW,CAAC;AAOnB,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,SAAiB,EACjB,WAAyD,EACzD,aAAqB;IAErB,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,aAAa,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CACpD,OAAO,CAAC,aAAa,CAAC,CACvB,CAAC;IACF,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,IAAI,CAC3C,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,MAAM,CAC1C,EAAE,CAAC,CAAC,CAAC,CAAC;IACP,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,KAAK,IAAI,KAAK,IAAI,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,CAAC;QAC/C,IACE,OAAO,CAAC,QAAQ,KAAK,OAAO;YAC5B,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC;YACrB,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,EACnB,CAAC;YACD,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC7B,CAAC;QACD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,SAAS;QACjC,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC,KAAK,CAAC,CAAC,K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\"node:fs/promises\";\nimport {\n delimiter,\n extname,\n isAbsolute,\n join,\n relative,\n resolve,\n sep,\n} from \"node:path\";\n\nexport interface TrustedExecutable {\n executable: string;\n environment: Record<string, string | undefined>;\n}\n\nexport async function resolveTrustedExecutable(\n candidate: string,\n environment: Readonly<Record<string, string | undefined>>,\n protectedRoot: string,\n): Promise<TrustedExecutable | null> {\n const root = await realpath(protectedRoot).catch(() =>\n resolve(protectedRoot),\n );\n const path = Object.entries(environment).find(\n ([name]) => name.toUpperCase() === \"PATH\",\n )?.[1];\n const entries: string[] = [];\n for (let entry of path?.split(delimiter) ?? []) {\n if (\n process.platform === \"win32\" &&\n entry.startsWith('\"') &&\n entry.endsWith('\"')\n ) {\n entry = entry.slice(1, -1);\n }\n if (entry.length === 0) continue;\n const canonical = await realpath(entry).catch(() => null);\n if (canonical === null || isWithin(root, canonical)) continue;\n if (!entries.includes(canonical)) entries.push(canonical);\n }\n\n const pathLike = candidate.includes(\"/\") || candidate.includes(\"\\\\\");\n // execFile cannot launch batch files, but their symlink targets still affect PATH trust.\n // CreateProcess appends .exe to an extensionless explicit path, so inspect the file that\n // will actually run instead of rejecting an otherwise valid Windows configuration.\n const extensions =\n process.platform === \"win32\"\n ? /\\.(?:exe|com)$/iu.test(candidate)\n ? [{ suffix: \"\", runnable: true }]\n : pathLike\n ? extname(candidate) === \"\"\n ? [{ suffix: \".exe\", runnable: true }]\n : [{ suffix: \"\", runnable: false }]\n : [\n { suffix: \".exe\", runnable: true },\n { suffix: \".com\", runnable: true },\n { suffix: \".bat\", runnable: false },\n { suffix: \".cmd\", runnable: false },\n { suffix: \"\", runnable: false },\n ]\n : [{ suffix: \"\", runnable: true }];\n const candidates = pathLike\n ? extensions.map((extension) => ({\n entry: null,\n path: resolve(`${candidate}${extension.suffix}`),\n runnable: extension.runnable,\n }))\n : entries.flatMap((entry) =>\n extensions.map((extension) => ({\n entry,\n path: join(entry, `${candidate}${extension.suffix}`),\n runnable: extension.runnable,\n })),\n );\n const unsafeEntries = new Set<string>();\n let executable: string | null = null;\n for (const current of candidates) {\n const canonical = await realpath(current.path).catch(() => null);\n if (canonical === null) continue;\n if (isWithin(root, canonical)) {\n if (current.entry !== null) unsafeEntries.add(current.entry);\n continue;\n }\n if (!current.runnable) continue;\n try {\n await access(\n canonical,\n process.platform === \"win32\" ? constants.F_OK : constants.X_OK,\n );\n if (!(await stat(canonical)).isFile()) continue;\n executable ??= pathLike ? canonical : current.path;\n } catch {\n continue;\n }\n }\n if (executable === null) return null;\n\n const sanitizedEnvironment = { ...environment };\n for (const name of Object.keys(sanitizedEnvironment)) {\n if (name.toUpperCase() === \"PATH\") delete sanitizedEnvironment[name];\n }\n sanitizedEnvironment[\"PATH\"] = entries\n .filter((entry) => !unsafeEntries.has(entry))\n .join(delimiter);\n return { executable, environment: sanitizedEnvironment };\n}\n\nfunction isWithin(root: string, candidate: string): boolean {\n const path = relative(root, candidate);\n return (\n path === \"\" ||\n (path !== \"..\" && !path.startsWith(`..${sep}`) && !isAbsolute(path))\n );\n}\n"]}
1
+ {"version":3,"file":"trusted-executable.js","sourceRoot":"","sources":["../src/trusted-executable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EACL,SAAS,EACT,OAAO,EACP,UAAU,EACV,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,GAAG,GACJ,MAAM,WAAW,CAAC;AAOnB,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,SAAiB,EACjB,WAAyD,EACzD,aAAqB;IAErB,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,aAAa,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CACpD,OAAO,CAAC,aAAa,CAAC,CACvB,CAAC;IACF,MAAM,IAAI,GACR,WAAW,CAAC,MAAM,CAAC;QACnB,MAAM,CAAC,O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C,IAAI,CAAC,CAAC;IACvE,CAAC;IACD,oBAAoB,CAAC,MAAM,CAAC,GAAG,OAAO;SACnC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;SAC5C,IAAI,CAAC,SAAS,CAAC,CAAC;IACnB,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,oBAAoB,EAAE,CAAC;AAC3D,CAAC;AAED,SAAS,QAAQ,CAAC,IAAY,EAAE,SAAiB;IAC/C,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IACvC,OAAO,CACL,IAAI,KAAK,EAAE;QACX,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,GAAG,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CACrE,CAAC;AACJ,CAAC","sourcesContent":["import { constants } from \"node:fs\";\nimport { access, realpath, stat } from \"node:fs/promises\";\nimport {\n delimiter,\n extname,\n isAbsolute,\n join,\n relative,\n resolve,\n sep,\n} from \"node:path\";\n\nexport interface TrustedExecutable {\n executable: string;\n environment: Record<string, string | undefined>;\n}\n\nexport async function resolveTrustedExecutable(\n candidate: string,\n environment: Readonly<Record<string, string | undefined>>,\n protectedRoot: string,\n): Promise<TrustedExecutable | null> {\n const root = await realpath(protectedRoot).catch(() =>\n resolve(protectedRoot),\n );\n const path =\n environment[\"PATH\"] ??\n Object.entries(environment).find(\n ([name]) => name.toUpperCase() === \"PATH\",\n )?.[1];\n const entries: string[] = [];\n for (let entry of path?.split(delimiter) ?? []) {\n if (\n process.platform === \"win32\" &&\n entry.startsWith('\"') &&\n entry.endsWith('\"')\n ) {\n entry = entry.slice(1, -1);\n }\n if (entry.length === 0) continue;\n const canonical = await realpath(entry).catch(() => null);\n if (canonical === null || isWithin(root, canonical)) continue;\n if (!entries.includes(canonical)) entries.push(canonical);\n }\n\n const pathLike = candidate.includes(\"/\") || candidate.includes(\"\\\\\");\n // execFile cannot launch batch files, but their symlink targets still affect PATH trust.\n // CreateProcess appends .exe to an extensionless explicit path, so inspect the file that\n // will actually run instead of rejecting an otherwise valid Windows configuration.\n const extensions =\n process.platform === \"win32\"\n ? /\\.(?:exe|com)$/iu.test(candidate)\n ? [{ suffix: \"\", runnable: true }]\n : pathLike\n ? extname(candidate) === \"\"\n ? [{ suffix: \".exe\", runnable: true }]\n : [{ suffix: \"\", runnable: false }]\n : [\n { suffix: \".exe\", runnable: true },\n { suffix: \".com\", runnable: true },\n { suffix: \".bat\", runnable: false },\n { suffix: \".cmd\", runnable: false },\n { suffix: \"\", runnable: false },\n ]\n : [{ suffix: \"\", runnable: true }];\n const candidates = pathLike\n ? extensions.map((extension) => ({\n entry: null,\n path: resolve(`${candidate}${extension.suffix}`),\n runnable: extension.runnable,\n }))\n : entries.flatMap((entry) =>\n extensions.map((extension) => ({\n entry,\n path: join(entry, `${candidate}${extension.suffix}`),\n runnable: extension.runnable,\n })),\n );\n const unsafeEntries = new Set<string>();\n let executable: string | null = null;\n for (const current of candidates) {\n const canonical = await realpath(current.path).catch(() => null);\n if (canonical === null) continue;\n if (isWithin(root, canonical)) {\n if (current.entry !== null) unsafeEntries.add(current.entry);\n continue;\n }\n if (!current.runnable) continue;\n try {\n await access(\n canonical,\n process.platform === \"win32\" ? constants.F_OK : constants.X_OK,\n );\n if (!(await stat(canonical)).isFile()) continue;\n executable ??= pathLike ? canonical : current.path;\n } catch {\n continue;\n }\n }\n if (executable === null) return null;\n\n const sanitizedEnvironment = { ...environment };\n for (const name of Object.keys(sanitizedEnvironment)) {\n if (name.toUpperCase() === \"PATH\") delete sanitizedEnvironment[name];\n }\n sanitizedEnvironment[\"PATH\"] = entries\n .filter((entry) => !unsafeEntries.has(entry))\n .join(delimiter);\n return { executable, environment: sanitizedEnvironment };\n}\n\nfunction isWithin(root: string, candidate: string): boolean {\n const path = relative(root, candidate);\n return (\n path === \"\" ||\n (path !== \"..\" && !path.startsWith(`..${sep}`) && !isAbsolute(path))\n );\n}\n"]}
package/dist/version.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export declare const VERSION: string;
2
2
  export declare const CODEX_SDK_VERSION: string;
3
3
  export declare const CODEX_EXECUTABLE_VERSION: string;
4
- export declare const BUNDLED_PLUGIN_VERSION: "0.1.60";
4
+ export declare const BUNDLED_PLUGIN_VERSION: "0.1.79";
5
5
  export interface UpdateNotice {
6
6
  readonly currentVersion: string;
7
7
  readonly latestVersion: string;
package/dist/version.js CHANGED
@@ -5,7 +5,7 @@ const PACKAGE_VERSIONS = packageVersions(new URL("../package.json", import.meta.
5
5
  export const VERSION = PACKAGE_VERSIONS.package;
6
6
  export const CODEX_SDK_VERSION = PACKAGE_VERSIONS.sdk;
7
7
  export const CODEX_EXECUTABLE_VERSION = PACKAGE_VERSIONS.executable;
8
- export const BUNDLED_PLUGIN_VERSION = "0.1.60";
8
+ export const BUNDLED_PLUGIN_VERSION = "0.1.79";
9
9
  const PACKAGE_NAME = "@openai/codex-security";
10
10
  export function updateNoticeEnabled(environment) {
11
11
  return (environment["CODEX_SECURITY_NO_UPDATE_NOTICE"] === undefined &&
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,QAAQ,MAAM,wBAAwB,CAAC;AAE9C,MAAM,gBAAgB,GAAG,eAAe,CACtC,IAAI,GAAG,CAAC,iBAAiB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAC5C,CAAC;AAEF,MAAM,CAAC,MAAM,OAAO,GAAG,gBAAgB,CAAC,OAAO,CAAC;AAChD,MAAM,CAAC,MAAM,iBAAiB,GAAG,gBAAgB,CAAC,GAAG,CAAC;AACtD,MAAM,CAAC,MAAM,w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AK,CAAC,gCAAgC,CAAC,CAAC;QACpD,CAAC;QACD,MAAM,GAAG,GACP,mBAAmB,IAAI,YAAY;YACjC,CAAC,CAAC,YAAY,CAAC,mBAAmB,CAAC;YACnC,CAAC,CAAC,SAAS,CAAC;QAChB,MAAM,UAAU,GACd,eAAe,IAAI,YAAY;YAC7B,CAAC,CAAC,YAAY,CAAC,eAAe,CAAC;YAC/B,CAAC,CAAC,SAAS,CAAC;QAChB,IACE,OAAO,GAAG,KAAK,QAAQ;YACvB,GAAG,CAAC,MAAM,KAAK,CAAC;YAChB,OAAO,UAAU,KAAK,QAAQ;YAC9B,UAAU,CAAC,MAAM,KAAK,CAAC,EACvB,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;QACrE,CAAC;QACD,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC;IACxD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,iDAAiD,EAAE;YACjE,KAAK,EAAE,KAAK;SACb,CAAC,CAAC;IACL,CAAC;AACH,CAAC","sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { fileURLToPath } from \"node:url\";\nimport semverGt from \"semver/functions/gt.js\";\n\nconst PACKAGE_VERSIONS = packageVersions(\n new URL(\"../package.json\", import.meta.url),\n);\n\nexport const VERSION = PACKAGE_VERSIONS.package;\nexport const CODEX_SDK_VERSION = PACKAGE_VERSIONS.sdk;\nexport const CODEX_EXECUTABLE_VERSION = PACKAGE_VERSIONS.executable;\nexport const BUNDLED_PLUGIN_VERSION = \"0.1.60\" as const;\n\nconst PACKAGE_NAME = \"@openai/codex-security\";\n\nexport interface UpdateNotice {\n readonly currentVersion: string;\n readonly latestVersion: string;\n readonly command: string;\n}\n\nexport function updateNoticeEnabled(environment: NodeJS.ProcessEnv): boolean {\n return (\n environment[\"CODEX_SECURITY_NO_UPDATE_NOTICE\"] === undefined &&\n environment[\"NO_UPDATE_NOTIFIER\"] === undefined &&\n environment[\"CI\"] === undefined\n );\n}\n\nexport function updateCommand(\n environment: NodeJS.ProcessEnv = process.env,\n entrypoint: string = fileURLToPath(import.meta.url),\n): string {\n const path = entrypoint.replaceAll(\"\\\\\", \"/\").toLowerCase();\n const agent = (environment[\"npm_config_user_agent\"] ?? \"\").toLowerCase();\n\n if (\n environment[\"npm_command\"] === \"exec\" ||\n environment[\"npm_lifecycle_event\"] === \"npx\" ||\n path.includes(\"/_npx/\")\n ) {\n return `npx ${PACKAGE_NAME}@latest`;\n }\n if (path.includes(\"/.install/node_modules/\")) {\n return \"download and extract the latest Codex Security release\";\n }\n\n const global =\n environment[\"npm_config_global\"] === \"true\" ||\n path.includes(\"/lib/node_modules/\") ||\n path.includes(\"/appdata/roaming/npm/node_modules/\") ||\n path.includes(\"/pnpm/global/\") ||\n path.includes(\"/.bun/install/global/\") ||\n path.includes(\"/.yarn/global/\") ||\n path.includes(\"/yarn/global/\");\n\n if (agent.startsWith(\"pnpm/\") || path.includes(\"/.pnpm/\")) {\n return `pnpm add${global ? \" -g\" : \"\"} ${PACKAGE_NAME}@latest`;\n }\n if (\n agent.startsWith(\"yarn/\") ||\n path.includes(\"/.yarn/\") ||\n path.includes(\"/yarn/global/\")\n ) {\n return `yarn${global ? \" global\" : \"\"} add ${PACKAGE_NAME}@latest`;\n }\n if (agent.startsWith(\"bun/\") || path.includes(\"/.bun/\")) {\n return `bun add${global ? \" -g\" : \"\"} ${PACKAGE_NAME}@latest`;\n }\n return agent.startsWith(\"npm/\") || path.includes(\"/node_modules/\")\n ? `npm install${global ? \" -g\" : \"\"} ${PACKAGE_NAME}@latest`\n : `npx ${PACKAGE_NAME}@latest`;\n}\n\nexport async function checkForUpdate({\n environment = process.env,\n entrypoint,\n currentVersion = VERSION,\n fetch: fetchLatest = fetch,\n signal,\n}: {\n environment?: NodeJS.ProcessEnv;\n entrypoint?: string;\n currentVersion?: string;\n fetch?: (\n input: Parameters<typeof fetch>[0],\n init?: Parameters<typeof fetch>[1],\n ) => ReturnType<typeof fetch>;\n signal?: AbortSignal;\n} = {}): Promise<UpdateNotice | undefined> {\n if (!updateNoticeEnabled(environment)) return undefined;\n\n try {\n const registry =\n environment[\"CODEX_SECURITY_NPM_REGISTRY\"] ??\n environment[\"npm_config_registry\"] ??\n environment[\"NPM_CONFIG_REGISTRY\"] ??\n \"https://registry.npmjs.org/\";\n const timeout = AbortSignal.timeout(3_000);\n const response = await fetchLatest(\n new URL(\n `${encodeURIComponent(PACKAGE_NAME)}/latest`,\n registry.endsWith(\"/\") ? registry : `${registry}/`,\n ),\n {\n signal:\n signal === undefined ? timeout : AbortSignal.any([signal, timeout]),\n },\n );\n if (!response.ok) return undefined;\n\n const manifest: unknown = await response.json();\n if (\n typeof manifest !== \"object\" ||\n manifest === null ||\n !(\"version\" in manifest) ||\n typeof manifest.version !== \"string\" ||\n !semverGt(manifest.version, currentVersion)\n ) {\n return undefined;\n }\n\n return {\n currentVersion,\n latestVersion: manifest.version,\n command: updateCommand(environment, entrypoint),\n };\n } catch {\n return undefined;\n }\n}\n\nexport function formatUpdateNotice(notice: UpdateNotice): string {\n const lines = [\n `Codex Security update available: ${notice.currentVersion} → ${notice.latestVersion}`,\n `Run: ${notice.command}`,\n ];\n const width = Math.max(...lines.map((line) => line.length));\n return [\n \"\",\n `╭${\"─\".repeat(width + 2)}╮`,\n ...lines.map((line) => `│ ${line.padEnd(width)} │`),\n `╰${\"─\".repeat(width + 2)}╯`,\n \"\",\n ].join(\"\\n\");\n}\n\nfunction packageVersions(url: URL): {\n package: string;\n sdk: string;\n executable: string;\n} {\n try {\n const manifest: unknown = JSON.parse(readFileSync(url, \"utf8\"));\n if (\n typeof manifest !== \"object\" ||\n manifest === null ||\n !(\"version\" in manifest) ||\n typeof manifest.version !== \"string\" ||\n manifest.version.length === 0\n ) {\n throw new Error(\"version must be a non-empty string\");\n }\n const dependencies =\n \"dependencies\" in manifest ? manifest.dependencies : undefined;\n if (typeof dependencies !== \"object\" || dependencies === null) {\n throw new Error(\"dependencies must be an object\");\n }\n const sdk =\n \"@openai/codex-sdk\" in dependencies\n ? dependencies[\"@openai/codex-sdk\"]\n : undefined;\n const executable =\n \"@openai/codex\" in dependencies\n ? dependencies[\"@openai/codex\"]\n : undefined;\n if (\n typeof sdk !== \"string\" ||\n sdk.length === 0 ||\n typeof executable !== \"string\" ||\n executable.length === 0\n ) {\n throw new Error(\"Codex dependencies must have non-empty versions\");\n }\n return { package: manifest.version, sdk, executable };\n } catch (error) {\n throw new Error(\"Unable to read Codex Security package versions.\", {\n cause: error,\n });\n }\n}\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,QAAQ,MAAM,wBAAwB,CAAC;AAE9C,MAAM,gBAAgB,GAAG,eAAe,CACtC,IAAI,GAAG,CAAC,iBAAiB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAC5C,CAAC;AAEF,MAAM,CAAC,MAAM,OAAO,GAAG,gBAAgB,CAAC,OAAO,CAAC;AAChD,MAAM,CAAC,MAAM,iBAAiB,GAAG,gBAAgB,CAAC,GAAG,CAAC;AACtD,MAAM,CAAC,MAAM,wBAAwB,GAAG,gBAAgB,CAAC,UAAU,CAAC;AACpE,MAAM,CAAC,MAAM,sBAAsB,GAAG,QAAiB,CAAC;AAExD,MAAM,YAAY,GAAG,wBAAwB,CAAC;AAQ9C,MAAM,UAAU,mBAAmB,CAAC,WAA8B;IAChE,OAAO,CACL,WAAW,CAAC,iCAAiC,CAAC,KAAK,SAAS;QAC5D,WAAW,CAAC,oBAAoB,CAAC,KAAK,SAAS;QAC/C,WAAW,CAAC,IAAI,CAAC,KAAK,SAAS,CAChC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,aA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AAU,KAAK,QAAQ;YAC9B,UAAU,CAAC,MAAM,KAAK,CAAC,EACvB,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;QACrE,CAAC;QACD,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC;IACxD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,iDAAiD,EAAE;YACjE,KAAK,EAAE,KAAK;SACb,CAAC,CAAC;IACL,CAAC;AACH,CAAC","sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { fileURLToPath } from \"node:url\";\nimport semverGt from \"semver/functions/gt.js\";\n\nconst PACKAGE_VERSIONS = packageVersions(\n new URL(\"../package.json\", import.meta.url),\n);\n\nexport const VERSION = PACKAGE_VERSIONS.package;\nexport const CODEX_SDK_VERSION = PACKAGE_VERSIONS.sdk;\nexport const CODEX_EXECUTABLE_VERSION = PACKAGE_VERSIONS.executable;\nexport const BUNDLED_PLUGIN_VERSION = \"0.1.79\" as const;\n\nconst PACKAGE_NAME = \"@openai/codex-security\";\n\nexport interface UpdateNotice {\n readonly currentVersion: string;\n readonly latestVersion: string;\n readonly command: string;\n}\n\nexport function updateNoticeEnabled(environment: NodeJS.ProcessEnv): boolean {\n return (\n environment[\"CODEX_SECURITY_NO_UPDATE_NOTICE\"] === undefined &&\n environment[\"NO_UPDATE_NOTIFIER\"] === undefined &&\n environment[\"CI\"] === undefined\n );\n}\n\nexport function updateCommand(\n environment: NodeJS.ProcessEnv = process.env,\n entrypoint: string = fileURLToPath(import.meta.url),\n): string {\n const path = entrypoint.replaceAll(\"\\\\\", \"/\").toLowerCase();\n const agent = (environment[\"npm_config_user_agent\"] ?? \"\").toLowerCase();\n\n if (\n environment[\"npm_command\"] === \"exec\" ||\n environment[\"npm_lifecycle_event\"] === \"npx\" ||\n path.includes(\"/_npx/\")\n ) {\n return `npx ${PACKAGE_NAME}@latest`;\n }\n if (path.includes(\"/.install/node_modules/\")) {\n return \"download and extract the latest Codex Security release\";\n }\n\n const global =\n environment[\"npm_config_global\"] === \"true\" ||\n path.includes(\"/lib/node_modules/\") ||\n path.includes(\"/appdata/roaming/npm/node_modules/\") ||\n path.includes(\"/pnpm/global/\") ||\n path.includes(\"/.bun/install/global/\") ||\n path.includes(\"/.yarn/global/\") ||\n path.includes(\"/yarn/global/\");\n\n if (agent.startsWith(\"pnpm/\") || path.includes(\"/.pnpm/\")) {\n return `pnpm add${global ? \" -g\" : \"\"} ${PACKAGE_NAME}@latest`;\n }\n if (\n agent.startsWith(\"yarn/\") ||\n path.includes(\"/.yarn/\") ||\n path.includes(\"/yarn/global/\")\n ) {\n return `yarn${global ? \" global\" : \"\"} add ${PACKAGE_NAME}@latest`;\n }\n if (agent.startsWith(\"bun/\") || path.includes(\"/.bun/\")) {\n return `bun add${global ? \" -g\" : \"\"} ${PACKAGE_NAME}@latest`;\n }\n return agent.startsWith(\"npm/\") || path.includes(\"/node_modules/\")\n ? `npm install${global ? \" -g\" : \"\"} ${PACKAGE_NAME}@latest`\n : `npx ${PACKAGE_NAME}@latest`;\n}\n\nexport async function checkForUpdate({\n environment = process.env,\n entrypoint,\n currentVersion = VERSION,\n fetch: fetchLatest = fetch,\n signal,\n}: {\n environment?: NodeJS.ProcessEnv;\n entrypoint?: string;\n currentVersion?: string;\n fetch?: (\n input: Parameters<typeof fetch>[0],\n init?: Parameters<typeof fetch>[1],\n ) => ReturnType<typeof fetch>;\n signal?: AbortSignal;\n} = {}): Promise<UpdateNotice | undefined> {\n if (!updateNoticeEnabled(environment)) return undefined;\n\n try {\n const registry =\n environment[\"CODEX_SECURITY_NPM_REGISTRY\"] ??\n environment[\"npm_config_registry\"] ??\n environment[\"NPM_CONFIG_REGISTRY\"] ??\n \"https://registry.npmjs.org/\";\n const timeout = AbortSignal.timeout(3_000);\n const response = await fetchLatest(\n new URL(\n `${encodeURIComponent(PACKAGE_NAME)}/latest`,\n registry.endsWith(\"/\") ? registry : `${registry}/`,\n ),\n {\n signal:\n signal === undefined ? timeout : AbortSignal.any([signal, timeout]),\n },\n );\n if (!response.ok) return undefined;\n\n const manifest: unknown = await response.json();\n if (\n typeof manifest !== \"object\" ||\n manifest === null ||\n !(\"version\" in manifest) ||\n typeof manifest.version !== \"string\" ||\n !semverGt(manifest.version, currentVersion)\n ) {\n return undefined;\n }\n\n return {\n currentVersion,\n latestVersion: manifest.version,\n command: updateCommand(environment, entrypoint),\n };\n } catch {\n return undefined;\n }\n}\n\nexport function formatUpdateNotice(notice: UpdateNotice): string {\n const lines = [\n `Codex Security update available: ${notice.currentVersion} → ${notice.latestVersion}`,\n `Run: ${notice.command}`,\n ];\n const width = Math.max(...lines.map((line) => line.length));\n return [\n \"\",\n `╭${\"─\".repeat(width + 2)}╮`,\n ...lines.map((line) => `│ ${line.padEnd(width)} │`),\n `╰${\"─\".repeat(width + 2)}╯`,\n \"\",\n ].join(\"\\n\");\n}\n\nfunction packageVersions(url: URL): {\n package: string;\n sdk: string;\n executable: string;\n} {\n try {\n const manifest: unknown = JSON.parse(readFileSync(url, \"utf8\"));\n if (\n typeof manifest !== \"object\" ||\n manifest === null ||\n !(\"version\" in manifest) ||\n typeof manifest.version !== \"string\" ||\n manifest.version.length === 0\n ) {\n throw new Error(\"version must be a non-empty string\");\n }\n const dependencies =\n \"dependencies\" in manifest ? manifest.dependencies : undefined;\n if (typeof dependencies !== \"object\" || dependencies === null) {\n throw new Error(\"dependencies must be an object\");\n }\n const sdk =\n \"@openai/codex-sdk\" in dependencies\n ? dependencies[\"@openai/codex-sdk\"]\n : undefined;\n const executable =\n \"@openai/codex\" in dependencies\n ? dependencies[\"@openai/codex\"]\n : undefined;\n if (\n typeof sdk !== \"string\" ||\n sdk.length === 0 ||\n typeof executable !== \"string\" ||\n executable.length === 0\n ) {\n throw new Error(\"Codex dependencies must have non-empty versions\");\n }\n return { package: manifest.version, sdk, executable };\n } catch (error) {\n throw new Error(\"Unable to read Codex Security package versions.\", {\n cause: error,\n });\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openai/codex-security",
3
- "version": "0.1.21",
3
+ "version": "0.1.24",
4
4
  "description": "TypeScript SDK and CLI for Codex Security",
5
5
  "license": "Apache-2.0",
6
6
  "author": "OpenAI",
@@ -52,6 +52,7 @@
52
52
  "fflate": "0.8.2",
53
53
  "incur": "0.4.13",
54
54
  "ink": "6.8.0",
55
+ "js-tiktoken": "1.0.21",
55
56
  "papaparse": "5.5.3",
56
57
  "pdfjs-dist": "6.2.108",
57
58
  "react": "19.2.4",
@@ -59,32 +60,43 @@
59
60
  "smol-toml": "1.6.1"
60
61
  },
61
62
  "devDependencies": {
63
+ "@openai/apps-sdk-ui": "0.2.2",
62
64
  "@stryker-mutator/core": "9.6.1",
65
+ "@tailwindcss/postcss": "4.3.3",
63
66
  "@types/bun": "1.3.13",
64
67
  "@types/node": "22.19.17",
65
68
  "@types/papaparse": "5.3.15",
66
69
  "@types/react": "19.2.14",
70
+ "@types/react-dom": "19.2.3",
67
71
  "@types/semver": "7.8.0",
72
+ "esbuild": "0.28.2",
68
73
  "fast-check": "4.9.0",
69
74
  "ink-testing-library": "4.0.0",
70
75
  "json-schema-to-typescript": "15.0.4",
76
+ "postcss": "8.5.23",
71
77
  "prettier": "3.2.5",
78
+ "react-dom": "19.2.4",
79
+ "tailwindcss": "4.3.3",
72
80
  "typescript": "5.7.3"
73
81
  },
74
- "gitHead": "fd98a9009b0a3a919b6cbce7c541b09d543dcaec",
82
+ "gitHead": "d4b7d29a87cb86c9072f7905ba867d02385d8fd3",
75
83
  "scripts": {
76
84
  "audit:prod": "pnpm audit --prod --audit-level high",
77
85
  "clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
78
- "build": "node --run clean && tsc -p tsconfig.build.json",
86
+ "build": "node --run clean && tsc -p tsconfig.build.json && node scripts/build-dashboard.mjs",
87
+ "build:plugin": "node scripts/build-plugin.mjs",
88
+ "check:plugin-source": "node scripts/check-plugin-source.mjs",
79
89
  "check:package": "node scripts/check-package.mjs",
80
90
  "format": "prettier --check --ignore-path .gitignore --ignore-path .prettierignore \"**/*.{cjs,mjs,js,ts,tsx,json,md}\"",
81
91
  "generate:models": "node scripts/generate-models.cjs",
82
92
  "generate:models:check": "node scripts/generate-models.cjs --check",
83
93
  "lint": "tsc --noEmit",
84
- "test": "bun test --timeout 30000 ./tests-ts",
94
+ "start:server": "node dist/server/index.js",
95
+ "test": "node --run build:plugin && bun test --timeout 30000 ./tests-ts",
85
96
  "test:ci": "node -e \"require('node:fs').mkdirSync('reports',{recursive:true})\" && pnpm run test --coverage --coverage-reporter=text --coverage-reporter=lcov --reporter=junit --reporter-outfile=reports/junit.xml",
97
+ "test:mcp": "node --run build:plugin && npm --prefix ../../plugins/codex-security/mcp-app run test:mcp",
86
98
  "test:mutation": "stryker run",
87
99
  "test:package": "node scripts/smoke-package.mjs",
88
- "types": "pnpm run generate:models:check && tsc --noEmit"
100
+ "types": "pnpm run generate:models:check && npm --prefix ../../plugins/codex-security/mcp-app run typecheck && tsc --noEmit"
89
101
  }
90
102
  }