@openai/codex-security 0.1.19 → 0.1.20

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 (42) hide show
  1. package/README.md +52 -7
  2. package/_bundled_plugin/.codex-plugin/plugin.json +1 -1
  3. package/_bundled_plugin/scripts/workbench_cli.py +5 -1
  4. package/_bundled_plugin/scripts/workbench_db.py +53 -0
  5. package/dist/bulk-scan-discovery.d.ts +8 -0
  6. package/dist/bulk-scan-discovery.d.ts.map +1 -1
  7. package/dist/bulk-scan-discovery.js +15 -1
  8. package/dist/bulk-scan-discovery.js.map +1 -1
  9. package/dist/cli.d.ts +3 -2
  10. package/dist/cli.d.ts.map +1 -1
  11. package/dist/cli.js +166 -82
  12. package/dist/cli.js.map +1 -1
  13. package/dist/cloud-publish.js +16 -12
  14. package/dist/cloud-publish.js.map +1 -1
  15. package/dist/index.d.ts +2 -2
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +1 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/linear.d.ts +5 -0
  20. package/dist/linear.d.ts.map +1 -1
  21. package/dist/linear.js +8 -3
  22. package/dist/linear.js.map +1 -1
  23. package/dist/publication-events.d.ts +40 -13
  24. package/dist/publication-events.d.ts.map +1 -1
  25. package/dist/publication-events.js +218 -104
  26. package/dist/publication-events.js.map +1 -1
  27. package/dist/publication-store.d.ts +1 -0
  28. package/dist/publication-store.d.ts.map +1 -1
  29. package/dist/publication-store.js +73 -26
  30. package/dist/publication-store.js.map +1 -1
  31. package/dist/publication.d.ts +5 -0
  32. package/dist/publication.d.ts.map +1 -1
  33. package/dist/publication.js +12 -0
  34. package/dist/publication.js.map +1 -1
  35. package/dist/publish.d.ts +40 -1
  36. package/dist/publish.d.ts.map +1 -1
  37. package/dist/publish.js +611 -251
  38. package/dist/publish.js.map +1 -1
  39. package/dist/version.d.ts +1 -1
  40. package/dist/version.js +1 -1
  41. package/dist/version.js.map +1 -1
  42. package/package.json +2 -2
@@ -7,7 +7,7 @@ import { loadContract } from "./contract.js";
7
7
  import { AuthenticationRequiredError, CodexSecurityError } from "./errors.js";
8
8
  import { bundledPluginRoot, codexSecurityCredentialAllowsAmbientImport, codexSecurityCredentialHome, codexSecurityHasStoredFileCredentials, expandHome, } from "./runtime.js";
9
9
  const CLOUD_PUBLISH_URL = "https://chatgpt.com/backend-api/aardvark/cli/findings";
10
- const CHATGPT_LOGIN_REQUIRED = 'Cloud publication requires ChatGPT credentials stored with cli_auth_credentials_store = "file". Automatic and keyring storage are not read because a stale auth.json may belong to another account. Configure file storage, sign in with ChatGPT again, then retry.';
10
+ const CHATGPT_LOGIN_REQUIRED = "Cloud publication requires a ChatGPT login already available to Codex Security. Run a scan or sign in with ChatGPT using Codex file credential storage, then retry.";
11
11
  const credentialsSchema = z.object({
12
12
  auth_mode: z.literal("chatgpt").optional(),
13
13
  OPENAI_API_KEY: z.null().optional(),
@@ -100,6 +100,7 @@ export async function publishScanToCloud(scanDirectory, dependencies = {}) {
100
100
  }
101
101
  async function readCloudCredentials(environment) {
102
102
  let home = expandHome(environment["CODEX_HOME"]?.trim() || "~/.codex", environment);
103
+ let requireFileStorage = true;
103
104
  const dedicatedHome = codexSecurityCredentialHome(environment);
104
105
  if (existsSync(dedicatedHome)) {
105
106
  if (!(await codexSecurityCredentialAllowsAmbientImport(dedicatedHome))) {
@@ -107,23 +108,26 @@ async function readCloudCredentials(environment) {
107
108
  }
108
109
  if (await codexSecurityHasStoredFileCredentials(dedicatedHome)) {
109
110
  home = dedicatedHome;
111
+ requireFileStorage = false;
110
112
  }
111
113
  else if (existsSync(join(dedicatedHome, "config.toml"))) {
112
114
  // Do not silently switch accounts when the dedicated login may be in a keyring.
113
115
  throw new AuthenticationRequiredError(CHATGPT_LOGIN_REQUIRED);
114
116
  }
115
117
  }
116
- let credentialStorage;
117
- try {
118
- credentialStorage = parseToml(await readFile(join(home, "config.toml"), "utf8"))["cli_auth_credentials_store"];
119
- }
120
- catch {
121
- throw new AuthenticationRequiredError(CHATGPT_LOGIN_REQUIRED);
122
- }
123
- // File presence is not proof that it is the active login: automatic or
124
- // keyring storage can leave an auth.json from a different account.
125
- if (credentialStorage !== "file") {
126
- throw new AuthenticationRequiredError(CHATGPT_LOGIN_REQUIRED);
118
+ if (requireFileStorage) {
119
+ let credentialStorage;
120
+ try {
121
+ credentialStorage = parseToml(await readFile(join(home, "config.toml"), "utf8"))["cli_auth_credentials_store"];
122
+ }
123
+ catch {
124
+ throw new AuthenticationRequiredError(CHATGPT_LOGIN_REQUIRED);
125
+ }
126
+ // File presence is not proof that it is the active ambient login:
127
+ // automatic or keyring storage can leave auth.json for another account.
128
+ if (credentialStorage !== "file") {
129
+ throw new AuthenticationRequiredError(CHATGPT_LOGIN_REQUIRED);
130
+ }
127
131
  }
128
132
  try {
129
133
  const credentials = credentialsSchema.safeParse(JSON.parse(await readFile(join(home, "auth.json"), "utf8")));
@@ -1 +1 @@
1
- {"version":3,"file":"cloud-publish.js","sourceRoot":"","sources":["../src/cloud-publish.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,CAAC,EAAE,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,2BAA2B,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAE9E,OAAO,EACL,iBAAiB,EACjB,0CAA0C,EAC1C,2BAA2B,EAC3B,qCAAqC,EACrC,UAAU,GACX,MAAM,cAAc,CAAC;AAEtB,MAAM,iBAAiB,GACrB,uDAAuD,CAAC;AAC1D,MAAM,sBAAsB,GAC1B,qQAAqQ,CAAC;AAExQ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M,EAAE,CAAC;QACjC,MAAM,IAAI,2BAA2B,CAAC,sBAAsB,CAAC,CAAC;IAChE,CAAC;IACD,IAAI,CAAC;QACH,MAAM,WAAW,GAAG,iBAAiB,CAAC,SAAS,CAC7C,IAAI,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,EAAE,MAAM,CAAC,CAAC,CAC5D,CAAC;QACF,IAAI,WAAW,CAAC,OAAO;YAAE,OAAO,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC;IAC1D,CAAC;IAAC,MAAM,CAAC;QACP,2EAA2E;IAC7E,CAAC;IACD,MAAM,IAAI,2BAA2B,CAAC,sBAAsB,CAAC,CAAC;AAChE,CAAC","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { z } from \"incur\";\nimport { parse as parseToml } from \"smol-toml\";\nimport { loadContract } from \"./contract.js\";\nimport { AuthenticationRequiredError, CodexSecurityError } from \"./errors.js\";\nimport type { Finding } from \"./models.js\";\nimport {\n bundledPluginRoot,\n codexSecurityCredentialAllowsAmbientImport,\n codexSecurityCredentialHome,\n codexSecurityHasStoredFileCredentials,\n expandHome,\n} from \"./runtime.js\";\n\nconst CLOUD_PUBLISH_URL =\n \"https://chatgpt.com/backend-api/aardvark/cli/findings\";\nconst CHATGPT_LOGIN_REQUIRED =\n 'Cloud publication requires ChatGPT credentials stored with cli_auth_credentials_store = \"file\". Automatic and keyring storage are not read because a stale auth.json may belong to another account. Configure file storage, sign in with ChatGPT again, then retry.';\n\nconst credentialsSchema = z.object({\n auth_mode: z.literal(\"chatgpt\").optional(),\n OPENAI_API_KEY: z.null().optional(),\n tokens: z.object({\n access_token: z.string().trim().min(1),\n account_id: z.string().trim().min(1),\n }),\n});\n\nconst receiptSchema = z.object({\n status: z.literal(\"accepted\"),\n finding_ids: z.array(z.string().min(1)),\n finding_count: z.number().int().positive(),\n});\n\nexport interface CloudPublicationResult {\n scanId: string;\n findingIds: string[];\n findingCount: number;\n dryRun?: true;\n findings?: Finding[];\n}\n\nexport async function publishScanToCloud(\n scanDirectory: string,\n dependencies: {\n environment?: NodeJS.ProcessEnv;\n fetch?: (url: string, options: RequestInit) => Promise<Response>;\n signal?: AbortSignal;\n dryRun?: boolean;\n expectedScanId?: string;\n } = {},\n): Promise<CloudPublicationResult> {\n const { manifest, findings } = await loadContract(scanDirectory, {\n pluginRoot: await bundledPluginRoot(),\n signal: dependencies.signal,\n expectedScanId: dependencies.expectedScanId,\n });\n if (findings.findings.length === 0) {\n throw new CodexSecurityError(\n \"The completed scan has no findings to publish.\",\n );\n }\n dependencies.signal?.throwIfAborted();\n if (dependencies.dryRun) {\n return {\n scanId: manifest.scan.id,\n findingIds: [],\n findingCount: findings.findings.length,\n dryRun: true,\n findings: findings.findings,\n };\n }\n const credentials = await readCloudCredentials(\n dependencies.environment ?? process.env,\n );\n const publishUrl =\n dependencies.environment?.[\"CODEX_SECURITY_CLOUD_PUBLISH_URL\"]?.trim() ||\n CLOUD_PUBLISH_URL;\n const timeout = AbortSignal.timeout(30_000);\n const signal = dependencies.signal\n ? AbortSignal.any([dependencies.signal, timeout])\n : timeout;\n let response: Response;\n try {\n response = await (dependencies.fetch ?? globalThis.fetch)(publishUrl, {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${credentials.access_token}`,\n \"ChatGPT-Account-ID\": credentials.account_id,\n \"Content-Type\": \"application/json\",\n Accept: \"application/json\",\n },\n body: JSON.stringify({\n schemaVersion: \"1.0\",\n scan: manifest.scan,\n findings: findings.findings,\n }),\n redirect: \"error\",\n signal,\n });\n } catch {\n // A lost response does not establish whether the server accepted the POST.\n throw new CodexSecurityError(\n \"Cloud publication was not confirmed. The request was not retried; check whether it was accepted before submitting again.\",\n );\n }\n if (!response.ok) {\n await response.body?.cancel().catch(() => undefined);\n const detail =\n response.status === 401\n ? \"Sign in with ChatGPT again before retrying.\"\n : response.status === 403\n ? \"The signed-in account is not authorized to publish to Cloud.\"\n : response.status === 404\n ? \"Cloud publication is not available for this account or deployment.\"\n : \"The request was not retried.\";\n throw new CodexSecurityError(\n `Cloud publication failed (HTTP ${response.status}). ${detail}`,\n );\n }\n const receipt = receiptSchema.safeParse(\n await response.json().catch(() => undefined),\n );\n // Cloud assigns opaque IDs in request order, so they cannot be compared to\n // local finding IDs. The authenticated response must still preserve the\n // submitted count and return one distinct observation for each finding.\n if (\n (response.status !== 200 && response.status !== 201) ||\n !receipt.success ||\n receipt.data.finding_count !== findings.findings.length ||\n receipt.data.finding_ids.length !== findings.findings.length ||\n new Set(receipt.data.finding_ids).size !== receipt.data.finding_ids.length\n ) {\n throw new CodexSecurityError(\n \"Cloud publication returned an invalid acceptance receipt. Check whether the request was accepted before submitting again.\",\n );\n }\n return {\n scanId: manifest.scan.id,\n findingIds: receipt.data.finding_ids,\n findingCount: receipt.data.finding_count,\n };\n}\n\nasync function readCloudCredentials(environment: NodeJS.ProcessEnv) {\n let home = expandHome(\n environment[\"CODEX_HOME\"]?.trim() || \"~/.codex\",\n environment,\n );\n const dedicatedHome = codexSecurityCredentialHome(environment);\n if (existsSync(dedicatedHome)) {\n if (!(await codexSecurityCredentialAllowsAmbientImport(dedicatedHome))) {\n throw new AuthenticationRequiredError(CHATGPT_LOGIN_REQUIRED);\n }\n if (await codexSecurityHasStoredFileCredentials(dedicatedHome)) {\n home = dedicatedHome;\n } else if (existsSync(join(dedicatedHome, \"config.toml\"))) {\n // Do not silently switch accounts when the dedicated login may be in a keyring.\n throw new AuthenticationRequiredError(CHATGPT_LOGIN_REQUIRED);\n }\n }\n let credentialStorage: unknown;\n try {\n credentialStorage = parseToml(\n await readFile(join(home, \"config.toml\"), \"utf8\"),\n )[\"cli_auth_credentials_store\"];\n } catch {\n throw new AuthenticationRequiredError(CHATGPT_LOGIN_REQUIRED);\n }\n // File presence is not proof that it is the active login: automatic or\n // keyring storage can leave an auth.json from a different account.\n if (credentialStorage !== \"file\") {\n throw new AuthenticationRequiredError(CHATGPT_LOGIN_REQUIRED);\n }\n try {\n const credentials = credentialsSchema.safeParse(\n JSON.parse(await readFile(join(home, \"auth.json\"), \"utf8\")),\n );\n if (credentials.success) return credentials.data.tokens;\n } catch {\n // Parsing and filesystem diagnostics must not reflect credential contents.\n }\n throw new AuthenticationRequiredError(CHATGPT_LOGIN_REQUIRED);\n}\n"]}
1
+ {"version":3,"file":"cloud-publish.js","sourceRoot":"","sources":["../src/cloud-publish.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,CAAC,EAAE,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,2BAA2B,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAE9E,OAAO,EACL,iBAAiB,EACjB,0CAA0C,EAC1C,2BAA2B,EAC3B,qCAAqC,EACrC,UAAU,GACX,MAAM,cAAc,CAAC;AAEtB,MAAM,iBAAiB,GACrB,uDAAuD,CAAC;AAC1D,MAAM,sBAAsB,GAC1B,qKAAqK,CAAC;AAExK,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE;IAC1C,cAAc,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE;IACnC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC;QACf,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QACtC,UAAU,EAAE,CAAC,CAAC,MAAM,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AAM,CAAC,CAAC,CAC5D,CAAC;QACF,IAAI,WAAW,CAAC,OAAO;YAAE,OAAO,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC;IAC1D,CAAC;IAAC,MAAM,CAAC;QACP,2EAA2E;IAC7E,CAAC;IACD,MAAM,IAAI,2BAA2B,CAAC,sBAAsB,CAAC,CAAC;AAChE,CAAC","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { z } from \"incur\";\nimport { parse as parseToml } from \"smol-toml\";\nimport { loadContract } from \"./contract.js\";\nimport { AuthenticationRequiredError, CodexSecurityError } from \"./errors.js\";\nimport type { Finding } from \"./models.js\";\nimport {\n bundledPluginRoot,\n codexSecurityCredentialAllowsAmbientImport,\n codexSecurityCredentialHome,\n codexSecurityHasStoredFileCredentials,\n expandHome,\n} from \"./runtime.js\";\n\nconst CLOUD_PUBLISH_URL =\n \"https://chatgpt.com/backend-api/aardvark/cli/findings\";\nconst CHATGPT_LOGIN_REQUIRED =\n \"Cloud publication requires a ChatGPT login already available to Codex Security. Run a scan or sign in with ChatGPT using Codex file credential storage, then retry.\";\n\nconst credentialsSchema = z.object({\n auth_mode: z.literal(\"chatgpt\").optional(),\n OPENAI_API_KEY: z.null().optional(),\n tokens: z.object({\n access_token: z.string().trim().min(1),\n account_id: z.string().trim().min(1),\n }),\n});\n\nconst receiptSchema = z.object({\n status: z.literal(\"accepted\"),\n finding_ids: z.array(z.string().min(1)),\n finding_count: z.number().int().positive(),\n});\n\nexport interface CloudPublicationResult {\n scanId: string;\n findingIds: string[];\n findingCount: number;\n dryRun?: true;\n findings?: Finding[];\n}\n\nexport async function publishScanToCloud(\n scanDirectory: string,\n dependencies: {\n environment?: NodeJS.ProcessEnv;\n fetch?: (url: string, options: RequestInit) => Promise<Response>;\n signal?: AbortSignal;\n dryRun?: boolean;\n expectedScanId?: string;\n } = {},\n): Promise<CloudPublicationResult> {\n const { manifest, findings } = await loadContract(scanDirectory, {\n pluginRoot: await bundledPluginRoot(),\n signal: dependencies.signal,\n expectedScanId: dependencies.expectedScanId,\n });\n if (findings.findings.length === 0) {\n throw new CodexSecurityError(\n \"The completed scan has no findings to publish.\",\n );\n }\n dependencies.signal?.throwIfAborted();\n if (dependencies.dryRun) {\n return {\n scanId: manifest.scan.id,\n findingIds: [],\n findingCount: findings.findings.length,\n dryRun: true,\n findings: findings.findings,\n };\n }\n const credentials = await readCloudCredentials(\n dependencies.environment ?? process.env,\n );\n const publishUrl =\n dependencies.environment?.[\"CODEX_SECURITY_CLOUD_PUBLISH_URL\"]?.trim() ||\n CLOUD_PUBLISH_URL;\n const timeout = AbortSignal.timeout(30_000);\n const signal = dependencies.signal\n ? AbortSignal.any([dependencies.signal, timeout])\n : timeout;\n let response: Response;\n try {\n response = await (dependencies.fetch ?? globalThis.fetch)(publishUrl, {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${credentials.access_token}`,\n \"ChatGPT-Account-ID\": credentials.account_id,\n \"Content-Type\": \"application/json\",\n Accept: \"application/json\",\n },\n body: JSON.stringify({\n schemaVersion: \"1.0\",\n scan: manifest.scan,\n findings: findings.findings,\n }),\n redirect: \"error\",\n signal,\n });\n } catch {\n // A lost response does not establish whether the server accepted the POST.\n throw new CodexSecurityError(\n \"Cloud publication was not confirmed. The request was not retried; check whether it was accepted before submitting again.\",\n );\n }\n if (!response.ok) {\n await response.body?.cancel().catch(() => undefined);\n const detail =\n response.status === 401\n ? \"Sign in with ChatGPT again before retrying.\"\n : response.status === 403\n ? \"The signed-in account is not authorized to publish to Cloud.\"\n : response.status === 404\n ? \"Cloud publication is not available for this account or deployment.\"\n : \"The request was not retried.\";\n throw new CodexSecurityError(\n `Cloud publication failed (HTTP ${response.status}). ${detail}`,\n );\n }\n const receipt = receiptSchema.safeParse(\n await response.json().catch(() => undefined),\n );\n // Cloud assigns opaque IDs in request order, so they cannot be compared to\n // local finding IDs. The authenticated response must still preserve the\n // submitted count and return one distinct observation for each finding.\n if (\n (response.status !== 200 && response.status !== 201) ||\n !receipt.success ||\n receipt.data.finding_count !== findings.findings.length ||\n receipt.data.finding_ids.length !== findings.findings.length ||\n new Set(receipt.data.finding_ids).size !== receipt.data.finding_ids.length\n ) {\n throw new CodexSecurityError(\n \"Cloud publication returned an invalid acceptance receipt. Check whether the request was accepted before submitting again.\",\n );\n }\n return {\n scanId: manifest.scan.id,\n findingIds: receipt.data.finding_ids,\n findingCount: receipt.data.finding_count,\n };\n}\n\nasync function readCloudCredentials(environment: NodeJS.ProcessEnv) {\n let home = expandHome(\n environment[\"CODEX_HOME\"]?.trim() || \"~/.codex\",\n environment,\n );\n let requireFileStorage = true;\n const dedicatedHome = codexSecurityCredentialHome(environment);\n if (existsSync(dedicatedHome)) {\n if (!(await codexSecurityCredentialAllowsAmbientImport(dedicatedHome))) {\n throw new AuthenticationRequiredError(CHATGPT_LOGIN_REQUIRED);\n }\n if (await codexSecurityHasStoredFileCredentials(dedicatedHome)) {\n home = dedicatedHome;\n requireFileStorage = false;\n } else if (existsSync(join(dedicatedHome, \"config.toml\"))) {\n // Do not silently switch accounts when the dedicated login may be in a keyring.\n throw new AuthenticationRequiredError(CHATGPT_LOGIN_REQUIRED);\n }\n }\n if (requireFileStorage) {\n let credentialStorage: unknown;\n try {\n credentialStorage = parseToml(\n await readFile(join(home, \"config.toml\"), \"utf8\"),\n )[\"cli_auth_credentials_store\"];\n } catch {\n throw new AuthenticationRequiredError(CHATGPT_LOGIN_REQUIRED);\n }\n // File presence is not proof that it is the active ambient login:\n // automatic or keyring storage can leave auth.json for another account.\n if (credentialStorage !== \"file\") {\n throw new AuthenticationRequiredError(CHATGPT_LOGIN_REQUIRED);\n }\n }\n try {\n const credentials = credentialsSchema.safeParse(\n JSON.parse(await readFile(join(home, \"auth.json\"), \"utf8\")),\n );\n if (credentials.success) return credentials.data.tokens;\n } catch {\n // Parsing and filesystem diagnostics must not reflect credential contents.\n }\n throw new AuthenticationRequiredError(CHATGPT_LOGIN_REQUIRED);\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -18,8 +18,8 @@ export type { CodexSecurityConfig, JsonObject, JsonValue } from "./config.js";
18
18
  export { loadContract, requireScanFile } from "./contract.js";
19
19
  export type { LoadedContract, ScanExpectation } from "./contract.js";
20
20
  export type * from "./models.js";
21
- export { publishScan } from "./publish.js";
22
- export type { PublishScanOptions, PublishScanProgress, PublishScanResult, } from "./publish.js";
21
+ export { checkScanPublication, publishScan } from "./publish.js";
22
+ export type { CheckScanPublicationOptions, CheckScanPublicationResult, PublishScanOptions, PublishScanProgress, PublishScanResult, } from "./publish.js";
23
23
  export { ScanResult } from "./result.js";
24
24
  export type { RepositoryFinding, ScanResultOptions, TurnResultMetadata, } from "./result.js";
25
25
  export { bootstrapPlugin, bundledPluginRoot, cleanupSdkDirectory, createIsolatedHome, createMarketplace, extractPluginZip, importAmbientAuth, MARKETPLACE_NAME, pluginExecutionEnvironment, pluginMetadata, PLUGIN_NAME, prepareOutputDir, resolveCodexCommand, resolvePluginPath, resolvePluginPython, validateOutputDir, } from "./runtime.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,YAAY,EACV,6BAA6B,EAC7B,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC7E,YAAY,EACV,aAAa,EACb,wBAAwB,GACzB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,YAAY,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC5D,YAAY,EAAE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AO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,YAAY,EACV,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,0BAA0B,EAC1B,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,cAAc,CAAC;AACtB,YAAY,EACV,YAAY,EACZ,aAAa,EACb,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,UAAU,EACV,mBAAmB,EACnB,eAAe,EACf,kBAAkB,EAClB,YAAY,GACb,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,gBAAgB,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,sBAAsB,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ export { CodexLoginHandle } from "./auth.js";
6
6
  export { AuthenticationRequiredError, CodexSecurityError, ConfigurationError, ContractValidationError, IncompleteScanError, InvalidTargetError, OutputDirectoryError, OutputDirectoryNotEmptyError, OutputInsideProtectedRootError, PluginBootstrapError, PluginPythonUnavailableError, ScanCostLimitExceededError, ScanInterruptedError, } from "./errors.js";
7
7
  export { DEFAULT_CODEX_CONFIG, mergedCodexConfig, writeCodexConfig, } from "./config.js";
8
8
  export { loadContract, requireScanFile } from "./contract.js";
9
- export { publishScan } from "./publish.js";
9
+ export { checkScanPublication, publishScan } from "./publish.js";
10
10
  export { ScanResult } from "./result.js";
11
11
  export { bootstrapPlugin, bundledPluginRoot, cleanupSdkDirectory, createIsolatedHome, createMarketplace, extractPluginZip, importAmbientAuth, MARKETPLACE_NAME, pluginExecutionEnvironment, pluginMetadata, PLUGIN_NAME, prepareOutputDir, resolveCodexCommand, resolvePluginPath, resolvePluginPython, validateOutputDir, } from "./runtime.js";
12
12
  export { DiffTarget, normalizeRepository, normalizeTarget, repositoryRevision, validateMode, } from "./targets.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAQxD,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAK7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAuB7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAG7C,OAAO,EACL,2BAA2B,EAC3B,kBAAkB,EAClB,kBAAkB,EAClB,uBAAuB,EACvB,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,4BAA4B,EAC5B,8BAA8B,EAC9B,oBAAoB,EACpB,4BAA4B,EAC5B,0BAA0B,EAC1B,oBAAoB,GACrB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAG9D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAM3C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAMzC,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,0BAA0B,EAC1B,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,cAAc,CAAC;AAOtB,OAAO,EACL,UAAU,EACV,mBAAmB,EACnB,eAAe,EACf,kBAAkB,EAClB,YAAY,GACb,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,sBAAsB,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC","sourcesContent":["export { CodexSecurity, createSecurity } from \"./api.js\";\nexport { runComponentScans } from \"./component-scan.js\";\nexport type {\n ComponentDeduplicationSummary,\n ComponentReceipt,\n ComponentScanOptions,\n ComponentScanEvent,\n ComponentScanResult,\n} from \"./component-scan.js\";\nexport { normalizeComponentPlan, planComponents } from \"./component-plan.js\";\nexport type {\n ComponentPlan,\n ComponentPlanningOptions,\n} from \"./component-plan.js\";\nexport { estimateScanCost } from \"./cost.js\";\nexport type { ScanCost, ScanSessionEvent } from \"./cost.js\";\nexport type { CustomValidationResult } from \"./custom-validation.js\";\nexport type { ScanActivity, ScanActivityStatus } from \"./scan-activity.js\";\nexport type {\n CodexSecurityMetadata,\n DeepScanOptions,\n ScanAuthMode,\n ScanAuthentication,\n ScanOptions,\n ScanPreflight,\n ScanReconnectDetails,\n ScanTrustedAccessStatus,\n ScanWarningDetails,\n ValidationOptions,\n ValidationResult,\n} from \"./api.js\";\nexport type {\n ScanPhase,\n ScanProgress,\n ScanWorkerPhase,\n ScanWorkerStatus,\n} from \"./worker-progress.js\";\nexport { CodexLoginHandle } from \"./auth.js\";\nexport type { AccountStatus, LoginResult } from \"./auth.js\";\n\nexport {\n AuthenticationRequiredError,\n CodexSecurityError,\n ConfigurationError,\n ContractValidationError,\n IncompleteScanError,\n InvalidTargetError,\n OutputDirectoryError,\n OutputDirectoryNotEmptyError,\n OutputInsideProtectedRootError,\n PluginBootstrapError,\n PluginPythonUnavailableError,\n ScanCostLimitExceededError,\n ScanInterruptedError,\n} from \"./errors.js\";\nexport type { ProtectedScanPathKind } from \"./errors.js\";\nexport {\n DEFAULT_CODEX_CONFIG,\n mergedCodexConfig,\n writeCodexConfig,\n} from \"./config.js\";\nexport type { CodexSecurityConfig, JsonObject, JsonValue } from \"./config.js\";\nexport { loadContract, requireScanFile } from \"./contract.js\";\nexport type { LoadedContract, ScanExpectation } from \"./contract.js\";\nexport type * from \"./models.js\";\nexport { publishScan } from \"./publish.js\";\nexport type {\n PublishScanOptions,\n PublishScanProgress,\n PublishScanResult,\n} from \"./publish.js\";\nexport { ScanResult } from \"./result.js\";\nexport type {\n RepositoryFinding,\n ScanResultOptions,\n TurnResultMetadata,\n} from \"./result.js\";\nexport {\n bootstrapPlugin,\n bundledPluginRoot,\n cleanupSdkDirectory,\n createIsolatedHome,\n createMarketplace,\n extractPluginZip,\n importAmbientAuth,\n MARKETPLACE_NAME,\n pluginExecutionEnvironment,\n pluginMetadata,\n PLUGIN_NAME,\n prepareOutputDir,\n resolveCodexCommand,\n resolvePluginPath,\n resolvePluginPython,\n validateOutputDir,\n} from \"./runtime.js\";\nexport type {\n CodexCommand,\n PluginInstall,\n PluginPythonOptions,\n ProcessEnvironment,\n} from \"./runtime.js\";\nexport {\n DiffTarget,\n normalizeRepository,\n normalizeTarget,\n repositoryRevision,\n validateMode,\n} from \"./targets.js\";\nexport type { NormalizedTarget, ScanMode, ScanTarget } from \"./targets.js\";\nexport { BUNDLED_PLUGIN_VERSION, VERSION } from \"./version.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAQxD,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAK7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAuB7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAG7C,OAAO,EACL,2BAA2B,EAC3B,kBAAkB,EAClB,kBAAkB,EAClB,uBAAuB,EACvB,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,4BAA4B,EAC5B,8BAA8B,EAC9B,oBAAoB,EACpB,4BAA4B,EAC5B,0BAA0B,EAC1B,oBAAoB,GACrB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAG9D,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAQjE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAMzC,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,0BAA0B,EAC1B,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,cAAc,CAAC;AAOtB,OAAO,EACL,UAAU,EACV,mBAAmB,EACnB,eAAe,EACf,kBAAkB,EAClB,YAAY,GACb,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,sBAAsB,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC","sourcesContent":["export { CodexSecurity, createSecurity } from \"./api.js\";\nexport { runComponentScans } from \"./component-scan.js\";\nexport type {\n ComponentDeduplicationSummary,\n ComponentReceipt,\n ComponentScanOptions,\n ComponentScanEvent,\n ComponentScanResult,\n} from \"./component-scan.js\";\nexport { normalizeComponentPlan, planComponents } from \"./component-plan.js\";\nexport type {\n ComponentPlan,\n ComponentPlanningOptions,\n} from \"./component-plan.js\";\nexport { estimateScanCost } from \"./cost.js\";\nexport type { ScanCost, ScanSessionEvent } from \"./cost.js\";\nexport type { CustomValidationResult } from \"./custom-validation.js\";\nexport type { ScanActivity, ScanActivityStatus } from \"./scan-activity.js\";\nexport type {\n CodexSecurityMetadata,\n DeepScanOptions,\n ScanAuthMode,\n ScanAuthentication,\n ScanOptions,\n ScanPreflight,\n ScanReconnectDetails,\n ScanTrustedAccessStatus,\n ScanWarningDetails,\n ValidationOptions,\n ValidationResult,\n} from \"./api.js\";\nexport type {\n ScanPhase,\n ScanProgress,\n ScanWorkerPhase,\n ScanWorkerStatus,\n} from \"./worker-progress.js\";\nexport { CodexLoginHandle } from \"./auth.js\";\nexport type { AccountStatus, LoginResult } from \"./auth.js\";\n\nexport {\n AuthenticationRequiredError,\n CodexSecurityError,\n ConfigurationError,\n ContractValidationError,\n IncompleteScanError,\n InvalidTargetError,\n OutputDirectoryError,\n OutputDirectoryNotEmptyError,\n OutputInsideProtectedRootError,\n PluginBootstrapError,\n PluginPythonUnavailableError,\n ScanCostLimitExceededError,\n ScanInterruptedError,\n} from \"./errors.js\";\nexport type { ProtectedScanPathKind } from \"./errors.js\";\nexport {\n DEFAULT_CODEX_CONFIG,\n mergedCodexConfig,\n writeCodexConfig,\n} from \"./config.js\";\nexport type { CodexSecurityConfig, JsonObject, JsonValue } from \"./config.js\";\nexport { loadContract, requireScanFile } from \"./contract.js\";\nexport type { LoadedContract, ScanExpectation } from \"./contract.js\";\nexport type * from \"./models.js\";\nexport { checkScanPublication, publishScan } from \"./publish.js\";\nexport type {\n CheckScanPublicationOptions,\n CheckScanPublicationResult,\n PublishScanOptions,\n PublishScanProgress,\n PublishScanResult,\n} from \"./publish.js\";\nexport { ScanResult } from \"./result.js\";\nexport type {\n RepositoryFinding,\n ScanResultOptions,\n TurnResultMetadata,\n} from \"./result.js\";\nexport {\n bootstrapPlugin,\n bundledPluginRoot,\n cleanupSdkDirectory,\n createIsolatedHome,\n createMarketplace,\n extractPluginZip,\n importAmbientAuth,\n MARKETPLACE_NAME,\n pluginExecutionEnvironment,\n pluginMetadata,\n PLUGIN_NAME,\n prepareOutputDir,\n resolveCodexCommand,\n resolvePluginPath,\n resolvePluginPython,\n validateOutputDir,\n} from \"./runtime.js\";\nexport type {\n CodexCommand,\n PluginInstall,\n PluginPythonOptions,\n ProcessEnvironment,\n} from \"./runtime.js\";\nexport {\n DiffTarget,\n normalizeRepository,\n normalizeTarget,\n repositoryRevision,\n validateMode,\n} from \"./targets.js\";\nexport type { NormalizedTarget, ScanMode, ScanTarget } from \"./targets.js\";\nexport { BUNDLED_PLUGIN_VERSION, VERSION } from \"./version.js\";\n"]}
package/dist/linear.d.ts CHANGED
@@ -16,4 +16,9 @@ export declare function importLinearIssues(options: {
16
16
  environment: NodeJS.ProcessEnv;
17
17
  linearClient?: LinearClientFactory;
18
18
  }): Promise<ImportedIssue[]>;
19
+ export declare function isLinearIssueIdentifier(input: string): boolean;
20
+ export declare function linearIssueReference(input: string): {
21
+ id: string;
22
+ workspace?: string;
23
+ };
19
24
  //# sourceMappingURL=linear.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"linear.d.ts","sourceRoot":"","sources":["../src/linear.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,YAAY,EAEb,MAAM,aAAa,CAAC;AAIrB,MAAM,MAAM,mBAAmB,CAC7B,MAAM,SAAS,MAAM,YAAY,GAAG,OAAO,GAAG,UAAU,IACtD,CACF,OAAO,EAAE,qBAAqB,CAAC,OAAO,YAAY,CAAC,CAAC,CAAC,CAAC,KACnD,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;AAEhC,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,MAAM,CAAC,UAAU,EAC9B,QAAQ,CAAC,EAAE,MAAM,GAChB,MAAM,GAAG,SAAS,CAMpB;AAED,wBAAgB,kBAAkB,CAAC,MAAM,SAAS,MAAM,YAAY,EAClE,OAAO,EAAE,qBAAqB,CAAC,OAAO,YAAY,CAAC,CAAC,CAAC,CAAC,EACtD,OAAO,CAAC,EAAE,mBAAmB,CAAC,MAAM,CAAC,GACpC,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,CAG5B;AAED,MAAM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MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CACd;AAED,wBAAsB,kBAAkB,CAAC,OAAO,EAAE;IAChD,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC,UAAU,CAAC;IAC/B,YAAY,CAAC,EAAE,mBAAmB,CAAC;CACpC,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAsG3B;AAkBD,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE9D;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG;IACnD,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAYA"}
package/dist/linear.js CHANGED
@@ -104,12 +104,17 @@ function linearIssueFilter(input) {
104
104
  }
105
105
  throw new CodexSecurityError("--linear-filter must be a JSON Linear issue filter.");
106
106
  }
107
- function linearIssueReference(input) {
107
+ export function isLinearIssueIdentifier(input) {
108
+ return /^[A-Za-z][A-Za-z0-9_-]*-\d+$/u.test(input);
109
+ }
110
+ export function linearIssueReference(input) {
108
111
  if (!/^https?:\/\//iu.test(input))
109
112
  return { id: input };
110
113
  const url = new URL(input);
111
- const match = /^\/([^/]+)\/issue\/([A-Z][A-Z0-9]*-\d+)(?:\/|$)/iu.exec(url.pathname);
112
- if (url.hostname !== "linear.app" || match === null) {
114
+ const match = /^\/([^/]+)\/issue\/([^/]+)(?:\/|$)/iu.exec(url.pathname);
115
+ if (url.hostname !== "linear.app" ||
116
+ match === null ||
117
+ !isLinearIssueIdentifier(match[2])) {
113
118
  throw new CodexSecurityError("Linear issue URL is invalid.");
114
119
  }
115
120
  return { id: match[2], workspace: match[1].toLowerCase() };
@@ -1 +1 @@
1
- {"version":3,"file":"linear.js","sour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J,CAAC;AAED,SAAS,oBAAoB,CAAC,KAAa;IAIzC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC;IACxD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;IAC3B,MAAM,KAAK,GAAG,mDAAmD,CAAC,IAAI,CACpE,GAAG,CAAC,QAAQ,CACb,CAAC;IACF,IAAI,GAAG,CAAC,QAAQ,KAAK,YAAY,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACpD,MAAM,IAAI,kBAAkB,CAAC,8BAA8B,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC,CAAE,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,CAAE,CAAC,WAAW,EAAE,EAAE,CAAC;AAC/D,CAAC","sourcesContent":["import {\n AuthenticationLinearError,\n ForbiddenLinearError,\n LinearClient,\n RatelimitedLinearError,\n} from \"@linear/sdk\";\nimport type { JsonObject } from \"./config.js\";\nimport { CodexSecurityError, safeErrorMessage } from \"./errors.js\";\n\nexport type LinearClientFactory<\n Method extends keyof LinearClient = \"issue\" | \"projects\",\n> = (\n options: ConstructorParameters<typeof LinearClient>[0],\n) => Pick<LinearClient, Method>;\n\nexport function resolveLinearApiKey(\n environment: NodeJS.ProcessEnv,\n explicit?: string,\n): string | undefined {\n return (\n explicit?.trim() ||\n environment[\"CODEX_SECURITY_LINEAR_API_KEY\"]?.trim() ||\n undefined\n );\n}\n\nexport function createLinearClient<Method extends keyof LinearClient>(\n options: ConstructorParameters<typeof LinearClient>[0],\n factory?: LinearClientFactory<Method>,\n): Pick<LinearClient, Method> {\n const configuration = { ...options, redirect: \"error\" as const };\n return factory ? factory(configuration) : new LinearClient(configuration);\n}\n\nexport interface ImportedIssue {\n source: \"linear\";\n id: string;\n url: string;\n text: string;\n}\n\nexport async function importLinearIssues(options: {\n issues: readonly string[];\n project?: string;\n filter?: string;\n apiKey?: string;\n environment: NodeJS.ProcessEnv;\n linearClient?: LinearClientFactory;\n}): Promise<ImportedIssue[]> {\n const apiKey =\n resolveLinearApiKey(options.environment, options.apiKey) ||\n options.environment[\"LINEAR_API_KEY\"]?.trim();\n const accessToken = options.environment[\"LINEAR_ACCESS_TOKEN\"]?.trim();\n const credential = apiKey || accessToken;\n if (!credential) {\n throw new CodexSecurityError(\n \"Linear access requires CODEX_SECURITY_LINEAR_API_KEY, LINEAR_API_KEY, or LINEAR_ACCESS_TOKEN.\",\n );\n }\n\n const client = createLinearClient(\n apiKey ? { apiKey } : { accessToken },\n options.linearClient,\n );\n\n try {\n const issues: Awaited<ReturnType<LinearClient[\"issue\"]>>[] = [];\n if (options.project !== undefined) {\n const suppliedFilter = linearIssueFilter(options.filter);\n const filter = Object.hasOwn(suppliedFilter, \"state\")\n ? suppliedFilter\n : {\n state: { type: { nin: [\"completed\", \"canceled\"] } },\n ...suppliedFilter,\n };\n const projects = await client.projects({\n filter: { name: { eqIgnoreCase: options.project } },\n first: 2,\n });\n if (projects.nodes.length !== 1) {\n throw new CodexSecurityError(\n `Linear project \"${options.project}\" ${projects.nodes.length === 0 ? \"was not found or is not accessible\" : \"is ambiguous\"}.`,\n );\n }\n\n const page = await projects.nodes[0]!.issues({ first: 50, filter });\n while (page.pageInfo.hasNextPage) await page.fetchNext();\n issues.push(...page.nodes);\n if (issues.length === 0) {\n throw new CodexSecurityError(\n `No open Linear issues matched project \"${options.project}\" and its filter.`,\n );\n }\n } else {\n for (const input of options.issues) {\n const { id, workspace } = linearIssueReference(input);\n const issue = await client.issue(id);\n if (!issue) {\n throw new CodexSecurityError(\n `Linear issue \"${id}\" was not found or is not accessible.`,\n );\n }\n if (\n workspace !== undefined &&\n linearIssueReference(issue.url).workspace !== workspace\n ) {\n throw new CodexSecurityError(\n \"Fetched Linear issue does not match the workspace in the selected URL.\",\n );\n }\n issues.push(issue);\n }\n }\n\n const imports: ImportedIssue[] = [];\n for (const issue of issues) {\n const comments = await issue.comments({ first: 50 });\n while (comments.pageInfo.hasNextPage) await comments.fetchNext();\n imports.push({\n source: \"linear\",\n id: issue.identifier,\n url: issue.url,\n text: [\n `Title: ${issue.title}`,\n `<description>\\n${issue.description ?? \"\"}\\n</description>`,\n ...comments.nodes.map(\n ({ url, body }) => `<comment>\\nURL: ${url}\\n\\n${body}\\n</comment>`,\n ),\n ].join(\"\\n\\n\"),\n });\n }\n return imports;\n } catch (error) {\n if (error instanceof CodexSecurityError) throw error;\n if (\n error instanceof AuthenticationLinearError ||\n error instanceof ForbiddenLinearError\n ) {\n throw new CodexSecurityError(\"Linear authentication failed.\");\n }\n if (error instanceof RatelimitedLinearError) {\n throw new CodexSecurityError(\n \"Linear request was rate limited. Wait and retry.\",\n );\n }\n const message = safeErrorMessage(error);\n throw new CodexSecurityError(\n `Linear request failed: ${message.includes(credential) ? \"[redacted]\" : message}`,\n );\n }\n}\n\nfunction linearIssueFilter(input: string | undefined): JsonObject {\n if (input === undefined) return {};\n let filter: unknown;\n try {\n filter = JSON.parse(input);\n } catch {\n filter = null;\n }\n if (typeof filter === \"object\" && filter !== null && !Array.isArray(filter)) {\n return filter as JsonObject;\n }\n throw new CodexSecurityError(\n \"--linear-filter must be a JSON Linear issue filter.\",\n );\n}\n\nfunction linearIssueReference(input: string): {\n id: string;\n workspace?: string;\n} {\n if (!/^https?:\\/\\//iu.test(input)) return { id: input };\n const url = new URL(input);\n const match = /^\\/([^/]+)\\/issue\\/([A-Z][A-Z0-9]*-\\d+)(?:\\/|$)/iu.exec(\n url.pathname,\n );\n if (url.hostname !== \"linear.app\" || match === null) {\n throw new CodexSecurityError(\"Linear issue URL is invalid.\");\n }\n return { id: match[2]!, workspace: match[1]!.toLowerCase() };\n}\n"]}
1
+ {"version":3,"file":"linear.js","sourceRoot":"","sources":["../src/linear.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,oBAAoB,EACpB,YAAY,E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CAAC,CAAC;AACrD,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,KAAa;IAIhD,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC;IACxD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;IAC3B,MAAM,KAAK,GAAG,sCAAsC,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACxE,IACE,GAAG,CAAC,QAAQ,KAAK,YAAY;QAC7B,KAAK,KAAK,IAAI;QACd,CAAC,uBAAuB,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC,EACnC,CAAC;QACD,MAAM,IAAI,kBAAkB,CAAC,8BAA8B,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC,CAAE,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,CAAE,CAAC,WAAW,EAAE,EAAE,CAAC;AAC/D,CAAC","sourcesContent":["import {\n AuthenticationLinearError,\n ForbiddenLinearError,\n LinearClient,\n RatelimitedLinearError,\n} from \"@linear/sdk\";\nimport type { JsonObject } from \"./config.js\";\nimport { CodexSecurityError, safeErrorMessage } from \"./errors.js\";\n\nexport type LinearClientFactory<\n Method extends keyof LinearClient = \"issue\" | \"projects\",\n> = (\n options: ConstructorParameters<typeof LinearClient>[0],\n) => Pick<LinearClient, Method>;\n\nexport function resolveLinearApiKey(\n environment: NodeJS.ProcessEnv,\n explicit?: string,\n): string | undefined {\n return (\n explicit?.trim() ||\n environment[\"CODEX_SECURITY_LINEAR_API_KEY\"]?.trim() ||\n undefined\n );\n}\n\nexport function createLinearClient<Method extends keyof LinearClient>(\n options: ConstructorParameters<typeof LinearClient>[0],\n factory?: LinearClientFactory<Method>,\n): Pick<LinearClient, Method> {\n const configuration = { ...options, redirect: \"error\" as const };\n return factory ? factory(configuration) : new LinearClient(configuration);\n}\n\nexport interface ImportedIssue {\n source: \"linear\";\n id: string;\n url: string;\n text: string;\n}\n\nexport async function importLinearIssues(options: {\n issues: readonly string[];\n project?: string;\n filter?: string;\n apiKey?: string;\n environment: NodeJS.ProcessEnv;\n linearClient?: LinearClientFactory;\n}): Promise<ImportedIssue[]> {\n const apiKey =\n resolveLinearApiKey(options.environment, options.apiKey) ||\n options.environment[\"LINEAR_API_KEY\"]?.trim();\n const accessToken = options.environment[\"LINEAR_ACCESS_TOKEN\"]?.trim();\n const credential = apiKey || accessToken;\n if (!credential) {\n throw new CodexSecurityError(\n \"Linear access requires CODEX_SECURITY_LINEAR_API_KEY, LINEAR_API_KEY, or LINEAR_ACCESS_TOKEN.\",\n );\n }\n\n const client = createLinearClient(\n apiKey ? { apiKey } : { accessToken },\n options.linearClient,\n );\n\n try {\n const issues: Awaited<ReturnType<LinearClient[\"issue\"]>>[] = [];\n if (options.project !== undefined) {\n const suppliedFilter = linearIssueFilter(options.filter);\n const filter = Object.hasOwn(suppliedFilter, \"state\")\n ? suppliedFilter\n : {\n state: { type: { nin: [\"completed\", \"canceled\"] } },\n ...suppliedFilter,\n };\n const projects = await client.projects({\n filter: { name: { eqIgnoreCase: options.project } },\n first: 2,\n });\n if (projects.nodes.length !== 1) {\n throw new CodexSecurityError(\n `Linear project \"${options.project}\" ${projects.nodes.length === 0 ? \"was not found or is not accessible\" : \"is ambiguous\"}.`,\n );\n }\n\n const page = await projects.nodes[0]!.issues({ first: 50, filter });\n while (page.pageInfo.hasNextPage) await page.fetchNext();\n issues.push(...page.nodes);\n if (issues.length === 0) {\n throw new CodexSecurityError(\n `No open Linear issues matched project \"${options.project}\" and its filter.`,\n );\n }\n } else {\n for (const input of options.issues) {\n const { id, workspace } = linearIssueReference(input);\n const issue = await client.issue(id);\n if (!issue) {\n throw new CodexSecurityError(\n `Linear issue \"${id}\" was not found or is not accessible.`,\n );\n }\n if (\n workspace !== undefined &&\n linearIssueReference(issue.url).workspace !== workspace\n ) {\n throw new CodexSecurityError(\n \"Fetched Linear issue does not match the workspace in the selected URL.\",\n );\n }\n issues.push(issue);\n }\n }\n\n const imports: ImportedIssue[] = [];\n for (const issue of issues) {\n const comments = await issue.comments({ first: 50 });\n while (comments.pageInfo.hasNextPage) await comments.fetchNext();\n imports.push({\n source: \"linear\",\n id: issue.identifier,\n url: issue.url,\n text: [\n `Title: ${issue.title}`,\n `<description>\\n${issue.description ?? \"\"}\\n</description>`,\n ...comments.nodes.map(\n ({ url, body }) => `<comment>\\nURL: ${url}\\n\\n${body}\\n</comment>`,\n ),\n ].join(\"\\n\\n\"),\n });\n }\n return imports;\n } catch (error) {\n if (error instanceof CodexSecurityError) throw error;\n if (\n error instanceof AuthenticationLinearError ||\n error instanceof ForbiddenLinearError\n ) {\n throw new CodexSecurityError(\"Linear authentication failed.\");\n }\n if (error instanceof RatelimitedLinearError) {\n throw new CodexSecurityError(\n \"Linear request was rate limited. Wait and retry.\",\n );\n }\n const message = safeErrorMessage(error);\n throw new CodexSecurityError(\n `Linear request failed: ${message.includes(credential) ? \"[redacted]\" : message}`,\n );\n }\n}\n\nfunction linearIssueFilter(input: string | undefined): JsonObject {\n if (input === undefined) return {};\n let filter: unknown;\n try {\n filter = JSON.parse(input);\n } catch {\n filter = null;\n }\n if (typeof filter === \"object\" && filter !== null && !Array.isArray(filter)) {\n return filter as JsonObject;\n }\n throw new CodexSecurityError(\n \"--linear-filter must be a JSON Linear issue filter.\",\n );\n}\n\nexport function isLinearIssueIdentifier(input: string): boolean {\n return /^[A-Za-z][A-Za-z0-9_-]*-\\d+$/u.test(input);\n}\n\nexport function linearIssueReference(input: string): {\n id: string;\n workspace?: string;\n} {\n if (!/^https?:\\/\\//iu.test(input)) return { id: input };\n const url = new URL(input);\n const match = /^\\/([^/]+)\\/issue\\/([^/]+)(?:\\/|$)/iu.exec(url.pathname);\n if (\n url.hostname !== \"linear.app\" ||\n match === null ||\n !isLinearIssueIdentifier(match[2]!)\n ) {\n throw new CodexSecurityError(\"Linear issue URL is invalid.\");\n }\n return { id: match[2]!, workspace: match[1]!.toLowerCase() };\n}\n"]}
@@ -1,16 +1,43 @@
1
- import type { PreparedPublicationIssue, PreparedScanPublication } from "./publication.js";
2
- export interface CollectedPublicationEvents {
3
- created: Array<{
4
- findingId: string;
5
- occurrenceId: string;
6
- issueIdentifier: string;
7
- url?: string;
8
- }>;
9
- failed: Array<{
10
- findingId: string;
11
- error: string;
12
- }>;
1
+ import { type PreparedPublicationIssue, type PreparedScanPublication } from "./publication.js";
2
+ export declare const MISSING_PUBLICATION_IDENTIFIER_ERROR = "The connected Linear app did not return a created issue identifier.";
3
+ export interface PublicationClaim {
4
+ kind: "identifier" | "entityId" | "url";
5
+ value: string;
13
6
  }
14
- export declare function collectPublicationEvents(output: string, publication: PreparedScanPublication, failureMessage: string): CollectedPublicationEvents;
7
+ export type ClaimResolution = {
8
+ state: "absent";
9
+ claims: PublicationClaim[];
10
+ } | {
11
+ state: "conflicting";
12
+ claims: PublicationClaim[];
13
+ } | {
14
+ state: "resolved";
15
+ claims: PublicationClaim[];
16
+ issueIdentifier: string;
17
+ url?: string;
18
+ };
19
+ export interface CompletedCreateEvidence {
20
+ source: "event";
21
+ status: "completed";
22
+ rawLine: string;
23
+ ownerFindingId?: string;
24
+ argumentsValid: boolean;
25
+ resolution: ClaimResolution;
26
+ }
27
+ export interface FailedCreateEvidence {
28
+ source: "event";
29
+ status: "failed";
30
+ rawLine: string;
31
+ ownerFindingId?: string;
32
+ argumentsValid: boolean;
33
+ resolution: ClaimResolution;
34
+ error: string;
35
+ }
36
+ export type PublicationEventEvidence = CompletedCreateEvidence | FailedCreateEvidence;
37
+ export declare function collectPublicationEvents(output: string, publication: PreparedScanPublication, failureMessage: string): PublicationEventEvidence[];
38
+ export declare function hasExpectedPublicationArguments(publication: PreparedScanPublication, issue: PreparedPublicationIssue, actual: unknown): boolean;
15
39
  export declare function matchPublicationIssue(publication: PreparedScanPublication, arguments_: Record<string, unknown>): PreparedPublicationIssue | undefined;
40
+ export declare function resolvePublicationClaims(value: unknown): ClaimResolution;
41
+ export declare function resolveClaims(claims: readonly PublicationClaim[]): ClaimResolution;
42
+ export declare function publicationClaimAliases(claim: PublicationClaim): PublicationClaim[];
16
43
  //# sourceMappingURL=publication-events.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"publication-events.d.ts","sourceRoot":"","sources":["../src/publication-events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,uBAAuB,EACxB,MAAM,kBAAkB,CAAC;AAE1B,MAAM,WAAW,0BAA0B;IACzC,OAAO,EAAE,KAAK,CAAC;QACb,SAAS,EAAE,MAAM,CAAC;QAClB,YAAY,EAAE,MAAM,CAAC;QACrB,eAAe,EAAE,MAAM,CAAC;QACxB,GAAG,CAAC,EAAE,MAAM,CAAC;KACd,CAAC,CAAC;IACH,MAAM,EAAE,KAAK,CAAC;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACrD;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,uBAAuB,EACpC,cAAc,EAAE,MAAM,GACrB,0BAA0B,CA2F5B;AAED,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,uBAAuB,EACpC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAClC,wBAAwB,GAAG,SAAS,CAUtC"}
1
+ {"version":3,"file":"publication-events.d.ts","sourceRoot":"","sources":["../src/publication-events.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC7B,MAAM,kBAAkB,CAAC;AAE1B,eAAO,MAAM,oCAAoC,wEACsB,CAAC;AAExE,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,YAAY,GAAG,UAAU,GAAG,KAAK,CAAC;IACxC,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,eAAe,GACvB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