@openai/codex-security 0.1.18 → 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.
- package/README.md +133 -9
- package/_bundled_plugin/.codex-plugin/plugin.json +1 -1
- package/_bundled_plugin/scripts/workbench_cli.py +5 -1
- package/_bundled_plugin/scripts/workbench_db.py +53 -0
- package/dist/bulk-scan-discovery.d.ts +8 -0
- package/dist/bulk-scan-discovery.d.ts.map +1 -1
- package/dist/bulk-scan-discovery.js +15 -1
- package/dist/bulk-scan-discovery.js.map +1 -1
- package/dist/cli.d.ts +5 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +364 -71
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.d.ts +16 -0
- package/dist/cloud-publish.d.ts.map +1 -0
- package/dist/cloud-publish.js +142 -0
- package/dist/cloud-publish.js.map +1 -0
- package/dist/contract.d.ts +1 -0
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +4 -0
- package/dist/contract.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/linear.d.ts +5 -0
- package/dist/linear.d.ts.map +1 -1
- package/dist/linear.js +25 -9
- package/dist/linear.js.map +1 -1
- package/dist/publication-events.d.ts +40 -13
- package/dist/publication-events.d.ts.map +1 -1
- package/dist/publication-events.js +218 -104
- package/dist/publication-events.js.map +1 -1
- package/dist/publication-store.d.ts +1 -0
- package/dist/publication-store.d.ts.map +1 -1
- package/dist/publication-store.js +73 -26
- package/dist/publication-store.js.map +1 -1
- package/dist/publication.d.ts +6 -0
- package/dist/publication.d.ts.map +1 -1
- package/dist/publication.js +13 -0
- package/dist/publication.js.map +1 -1
- package/dist/publish.d.ts +41 -1
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +611 -251
- package/dist/publish.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +2 -2
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;
|
|
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
|
package/dist/linear.d.ts.map
CHANGED
|
@@ -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,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AC,YAAY,EAAE,MAAM,CAAC,CAG5B;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,QAAQ,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,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
|
@@ -57,12 +57,23 @@ export async function importLinearIssues(options) {
|
|
|
57
57
|
issues.push(issue);
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
const imports = [];
|
|
61
|
+
for (const issue of issues) {
|
|
62
|
+
const comments = await issue.comments({ first: 50 });
|
|
63
|
+
while (comments.pageInfo.hasNextPage)
|
|
64
|
+
await comments.fetchNext();
|
|
65
|
+
imports.push({
|
|
66
|
+
source: "linear",
|
|
67
|
+
id: issue.identifier,
|
|
68
|
+
url: issue.url,
|
|
69
|
+
text: [
|
|
70
|
+
`Title: ${issue.title}`,
|
|
71
|
+
`<description>\n${issue.description ?? ""}\n</description>`,
|
|
72
|
+
...comments.nodes.map(({ url, body }) => `<comment>\nURL: ${url}\n\n${body}\n</comment>`),
|
|
73
|
+
].join("\n\n"),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return imports;
|
|
66
77
|
}
|
|
67
78
|
catch (error) {
|
|
68
79
|
if (error instanceof CodexSecurityError)
|
|
@@ -93,12 +104,17 @@ function linearIssueFilter(input) {
|
|
|
93
104
|
}
|
|
94
105
|
throw new CodexSecurityError("--linear-filter must be a JSON Linear issue filter.");
|
|
95
106
|
}
|
|
96
|
-
function
|
|
107
|
+
export function isLinearIssueIdentifier(input) {
|
|
108
|
+
return /^[A-Za-z][A-Za-z0-9_-]*-\d+$/u.test(input);
|
|
109
|
+
}
|
|
110
|
+
export function linearIssueReference(input) {
|
|
97
111
|
if (!/^https?:\/\//iu.test(input))
|
|
98
112
|
return { id: input };
|
|
99
113
|
const url = new URL(input);
|
|
100
|
-
const match = /^\/([^/]+)\/issue\/([
|
|
101
|
-
if (url.hostname !== "linear.app" ||
|
|
114
|
+
const match = /^\/([^/]+)\/issue\/([^/]+)(?:\/|$)/iu.exec(url.pathname);
|
|
115
|
+
if (url.hostname !== "linear.app" ||
|
|
116
|
+
match === null ||
|
|
117
|
+
!isLinearIssueIdentifier(match[2])) {
|
|
102
118
|
throw new CodexSecurityError("Linear issue URL is invalid.");
|
|
103
119
|
}
|
|
104
120
|
return { id: match[2], workspace: match[1].toLowerCase() };
|
package/dist/linear.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linear.js","sourceRoot":"","sources":["../src/linear.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,oBAAoB,EACpB,YAAY,EACZ,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAQnE,MAAM,UAAU,mBAAmB,CACjC,WAA8B,EAC9B,QAAiB;IAEjB,OAAO,CACL,QAAQ,EAAE,IAAI,E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BAAiB,CAAC,KAAyB;IAClD,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,EAAE,CAAC;IACnC,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC7B,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,GAAG,IAAI,CAAC;IAChB,CAAC;IACD,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5E,OAAO,MAAoB,CAAC;IAC9B,CAAC;IACD,MAAM,IAAI,kBAAkB,CAC1B,qDAAqD,CACtD,CAAC;AACJ,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 return issues.map(({ identifier, title, url, description }) => ({\n source: \"linear\",\n id: identifier,\n url,\n text: `Title: ${title}\\n\\n${description ?? \"\"}`,\n }));\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,EACZ,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAQnE,MAAM,UAAU,mBAAmB,CACjC,WAA8B,EAC9B,QAAiB;IAEjB,OAAO,CACL,QAAQ,EAAE,IAAI,EAAE;QAChB,WAAW,CAAC,+BAA+B,CAAC,EAAE,IAAI,EAAE;QACpD,SAAS,CACV,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,OAAsD,EACtD,OAAqC;IAErC,MAAM,aAAa,GAAG,EAAE,GAAG,OAAO,EAAE,QAAQ,EAAE,OAAgB,EAAE,CAAC;IACjE,OAAO,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,IAAI,YAAY,CAAC,aAAa,CAAC,CAAC;AAC5E,CAAC;AASD,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,OAOxC;IACC,MAAM,MAAM,GACV,mBAAmB,CAAC,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,MAAM,CAAC;QACxD,OAAO,CAAC,WAAW,CAAC,gBAAgB,CAAC,EAAE,IAAI,EAAE,CAAC;IAChD,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,qBAAqB,CAAC,EAAE,IAAI,EAAE,CAAC;IACvE,MAAM,UAAU,GAAG,MAAM,IAAI,WAAW,CAAC;IACzC,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,kBAAkB,CAC1B,+FAA+F,CAChG,CAAC;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AAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5E,OAAO,MAAoB,CAAC;IAC9B,CAAC;IACD,MAAM,IAAI,kBAAkB,CAC1B,qDAAqD,CACtD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,KAAa;IACnD,OAAO,+BAA+B,CAAC,IAAI,CAAC,KAAK,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
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
|
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":"
|
|
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;IAAE,KAAK,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,gBAAgB,EAAE,CAAA;CAAE,GA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AM,EAAE,SAAS,gBAAgB,EAAE,GAClC,eAAe,CA6DjB;AAgID,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,gBAAgB,GACtB,gBAAgB,EAAE,CAMpB"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import { isLinearIssueIdentifier, linearIssueReference } from "./linear.js";
|
|
2
|
+
import { linearPublicationArguments, } from "./publication.js";
|
|
3
|
+
export const MISSING_PUBLICATION_IDENTIFIER_ERROR = "The connected Linear app did not return a created issue identifier.";
|
|
1
4
|
export function collectPublicationEvents(output, publication, failureMessage) {
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
for (const line of output.split(/\r?\n/)) {
|
|
6
|
-
if (line.trim().length === 0)
|
|
5
|
+
const evidence = [];
|
|
6
|
+
for (const rawLine of output.split(/\r?\n/)) {
|
|
7
|
+
if (rawLine.trim().length === 0)
|
|
7
8
|
continue;
|
|
8
9
|
let event;
|
|
9
10
|
try {
|
|
10
|
-
event = JSON.parse(
|
|
11
|
+
event = JSON.parse(rawLine);
|
|
11
12
|
}
|
|
12
13
|
catch {
|
|
13
14
|
continue;
|
|
@@ -15,125 +16,238 @@ export function collectPublicationEvents(output, publication, failureMessage) {
|
|
|
15
16
|
if (!isRecord(event) || event["type"] !== "item.completed")
|
|
16
17
|
continue;
|
|
17
18
|
const item = event["item"];
|
|
18
|
-
if (!
|
|
19
|
-
item["type"] !== "mcp_tool_call" ||
|
|
20
|
-
item["server"] !== "codex_apps" ||
|
|
21
|
-
(item["tool"] !== "linear.save_issue" &&
|
|
22
|
-
item["tool"] !== "linear_save_issue")) {
|
|
19
|
+
if (!isLinearCreateCall(item))
|
|
23
20
|
continue;
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
? matchPublicationIssue(publication, args)
|
|
21
|
+
const arguments_ = item["arguments"];
|
|
22
|
+
const owner = isRecord(arguments_)
|
|
23
|
+
? matchPublicationIssue(publication, arguments_)
|
|
28
24
|
: undefined;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
25
|
+
const argumentsValid = owner !== undefined &&
|
|
26
|
+
hasExpectedPublicationArguments(publication, owner, arguments_);
|
|
27
|
+
if (item["status"] === "completed") {
|
|
28
|
+
evidence.push({
|
|
29
|
+
source: "event",
|
|
30
|
+
status: "completed",
|
|
31
|
+
rawLine,
|
|
32
|
+
...(owner === undefined ? {} : { ownerFindingId: owner.findingId }),
|
|
33
|
+
argumentsValid,
|
|
34
|
+
resolution: resolvePublicationClaims(item["result"]),
|
|
35
|
+
});
|
|
35
36
|
continue;
|
|
36
37
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
const error = item["error"];
|
|
39
|
+
evidence.push({
|
|
40
|
+
source: "event",
|
|
41
|
+
status: "failed",
|
|
42
|
+
rawLine,
|
|
43
|
+
...(owner === undefined ? {} : { ownerFindingId: owner.findingId }),
|
|
44
|
+
argumentsValid,
|
|
45
|
+
resolution: resolvePublicationClaims(item["result"]),
|
|
46
|
+
error: isRecord(error) && typeof error["message"] === "string"
|
|
40
47
|
? error["message"]
|
|
41
|
-
: failureMessage
|
|
42
|
-
continue;
|
|
43
|
-
}
|
|
44
|
-
const saved = savedIssue(item["result"]);
|
|
45
|
-
if (saved === undefined) {
|
|
46
|
-
failed.set(issue.findingId, "The connected Linear app did not return a created issue identifier.");
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
created.set(issue.findingId, {
|
|
50
|
-
findingId: issue.findingId,
|
|
51
|
-
occurrenceId: issue.occurrenceId,
|
|
52
|
-
issueIdentifier: saved.issueIdentifier,
|
|
53
|
-
...(saved.url === undefined ? {} : { url: saved.url }),
|
|
48
|
+
: failureMessage,
|
|
54
49
|
});
|
|
55
50
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return [];
|
|
65
|
-
const result = created.get(issue.findingId);
|
|
66
|
-
return result === undefined ? [] : [result];
|
|
67
|
-
}),
|
|
68
|
-
failed: publication.issues.flatMap((issue) => {
|
|
69
|
-
const error = failed.get(issue.findingId);
|
|
70
|
-
if (error !== undefined)
|
|
71
|
-
return [{ findingId: issue.findingId, error }];
|
|
72
|
-
return created.has(issue.findingId)
|
|
73
|
-
? []
|
|
74
|
-
: [{ findingId: issue.findingId, error: failureMessage }];
|
|
75
|
-
}),
|
|
76
|
-
};
|
|
51
|
+
return evidence;
|
|
52
|
+
}
|
|
53
|
+
export function hasExpectedPublicationArguments(publication, issue, actual) {
|
|
54
|
+
if (!isRecord(actual))
|
|
55
|
+
return false;
|
|
56
|
+
const expected = linearPublicationArguments(publication.destination, issue);
|
|
57
|
+
return (Object.keys(actual).length === Object.keys(expected).length &&
|
|
58
|
+
Object.entries(expected).every(([key, value]) => Object.hasOwn(actual, key) && Object.is(actual[key], value)));
|
|
77
59
|
}
|
|
78
60
|
export function matchPublicationIssue(publication, arguments_) {
|
|
61
|
+
const exactMatches = publication.issues.filter((issue) => hasExpectedPublicationArguments(publication, issue, arguments_));
|
|
62
|
+
if (exactMatches.length === 1)
|
|
63
|
+
return exactMatches[0];
|
|
79
64
|
const description = arguments_["description"];
|
|
80
|
-
if (typeof description !== "string")
|
|
65
|
+
if (typeof description !== "string")
|
|
81
66
|
return undefined;
|
|
82
|
-
|
|
83
|
-
const matches = publication.issues.filter((issue) => descriptionIdentifiesIssue(description, issue));
|
|
84
|
-
return matches.length === 1 ? matches[0] : undefined;
|
|
85
|
-
}
|
|
86
|
-
function descriptionIdentifiesIssue(description, issue) {
|
|
87
|
-
return (containsIdentifier(description, issue.findingId) &&
|
|
67
|
+
const matches = publication.issues.filter((issue) => containsIdentifier(description, issue.findingId) &&
|
|
88
68
|
containsIdentifier(description, issue.occurrenceId));
|
|
69
|
+
return matches.length === 1 ? matches[0] : undefined;
|
|
89
70
|
}
|
|
90
|
-
function
|
|
91
|
-
const
|
|
92
|
-
|
|
71
|
+
export function resolvePublicationClaims(value) {
|
|
72
|
+
const claims = [];
|
|
73
|
+
collectPublicationClaims(value, claims);
|
|
74
|
+
return resolveClaims(claims);
|
|
93
75
|
}
|
|
94
|
-
function
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
76
|
+
export function resolveClaims(claims) {
|
|
77
|
+
const seen = new Set();
|
|
78
|
+
const normalized = claims.flatMap((claim) => {
|
|
79
|
+
const trimmed = claim.value.trim();
|
|
80
|
+
if (trimmed.length === 0)
|
|
81
|
+
return [];
|
|
82
|
+
const value = isCanonicalUuid(trimmed) ? trimmed.toLowerCase() : trimmed;
|
|
83
|
+
return [{ kind: claim.kind, value }];
|
|
84
|
+
});
|
|
85
|
+
const retained = normalized
|
|
86
|
+
.filter((claim) => {
|
|
87
|
+
const key = `${claim.kind}\0${claim.value}`;
|
|
88
|
+
if (seen.has(key))
|
|
89
|
+
return false;
|
|
90
|
+
seen.add(key);
|
|
91
|
+
return true;
|
|
92
|
+
})
|
|
93
|
+
.sort(compareClaims);
|
|
94
|
+
const identifiers = new Set(retained
|
|
95
|
+
.filter((claim) => claim.kind === "identifier")
|
|
96
|
+
.map((claim) => claim.value));
|
|
97
|
+
const entityIds = new Set(retained
|
|
98
|
+
.filter((claim) => claim.kind === "entityId")
|
|
99
|
+
.map((claim) => claim.value));
|
|
100
|
+
const urls = new Set(retained
|
|
101
|
+
.filter((claim) => claim.kind === "url")
|
|
102
|
+
.map((claim) => claim.value));
|
|
103
|
+
const canonicalUrls = new Set([...urls].map(canonicalPublicationUrlClaim));
|
|
104
|
+
const urlContradictsIdentifier = identifiers.size > 0 &&
|
|
105
|
+
[...urls]
|
|
106
|
+
.map(linearIssueReferenceFromUrl)
|
|
107
|
+
.some((reference) => reference !== undefined && !identifiers.has(reference.id));
|
|
108
|
+
const overlappingIdentity = [...identifiers].some((identifier) => entityIds.has(identifier));
|
|
109
|
+
if (identifiers.size > 1 ||
|
|
110
|
+
entityIds.size > 1 ||
|
|
111
|
+
canonicalUrls.size > 1 ||
|
|
112
|
+
urlContradictsIdentifier ||
|
|
113
|
+
overlappingIdentity) {
|
|
114
|
+
return { state: "conflicting", claims: retained };
|
|
115
|
+
}
|
|
116
|
+
if (identifiers.size === 0) {
|
|
117
|
+
return { state: "absent", claims: retained };
|
|
112
118
|
}
|
|
113
|
-
|
|
114
|
-
|
|
119
|
+
return {
|
|
120
|
+
state: "resolved",
|
|
121
|
+
claims: retained,
|
|
122
|
+
issueIdentifier: identifiers.values().next().value,
|
|
123
|
+
...(urls.size === 0 ? {} : { url: urls.values().next().value }),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function isLinearCreateCall(item) {
|
|
127
|
+
return (isRecord(item) &&
|
|
128
|
+
item["type"] === "mcp_tool_call" &&
|
|
129
|
+
item["server"] === "codex_apps" &&
|
|
130
|
+
(item["tool"] === "linear.save_issue" ||
|
|
131
|
+
item["tool"] === "linear_save_issue"));
|
|
132
|
+
}
|
|
133
|
+
function collectPublicationClaims(value, claims) {
|
|
134
|
+
const visited = new Set();
|
|
135
|
+
const pending = [value];
|
|
136
|
+
while (pending.length > 0) {
|
|
137
|
+
const candidate = pending.pop();
|
|
138
|
+
if (!isRecord(candidate) || visited.has(candidate))
|
|
115
139
|
continue;
|
|
116
|
-
|
|
140
|
+
visited.add(candidate);
|
|
141
|
+
collectDirectClaims(candidate, claims);
|
|
117
142
|
const data = candidate["data"];
|
|
118
|
-
|
|
119
|
-
candidate,
|
|
120
|
-
|
|
143
|
+
const nested = [
|
|
144
|
+
candidate["structured_content"],
|
|
145
|
+
candidate["structuredContent"],
|
|
146
|
+
candidate["issue"],
|
|
121
147
|
isRecord(data) ? data["issue"] : undefined,
|
|
122
|
-
]
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
148
|
+
];
|
|
149
|
+
if (Array.isArray(candidate["content"])) {
|
|
150
|
+
for (const content of candidate["content"]) {
|
|
151
|
+
if (!isRecord(content) || typeof content["text"] !== "string") {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
try {
|
|
155
|
+
nested.push(JSON.parse(content["text"]));
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
128
160
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
};
|
|
161
|
+
}
|
|
162
|
+
for (let index = nested.length - 1; index >= 0; index -= 1) {
|
|
163
|
+
if (isRecord(nested[index]))
|
|
164
|
+
pending.push(nested[index]);
|
|
134
165
|
}
|
|
135
166
|
}
|
|
136
|
-
|
|
167
|
+
}
|
|
168
|
+
function collectDirectClaims(candidate, claims) {
|
|
169
|
+
for (const field of ["identifier", "issueIdentifier", "key", "id"]) {
|
|
170
|
+
const claim = classifyIdentityClaim(field, candidate[field]);
|
|
171
|
+
if (claim !== undefined)
|
|
172
|
+
claims.push(claim);
|
|
173
|
+
}
|
|
174
|
+
const url = candidate["url"];
|
|
175
|
+
const normalizedUrl = normalizeNonemptyString(url);
|
|
176
|
+
if (normalizedUrl !== undefined) {
|
|
177
|
+
claims.push({ kind: "url", value: normalizedUrl });
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
function classifyIdentityClaim(field, value) {
|
|
181
|
+
const normalized = normalizeNonemptyString(value);
|
|
182
|
+
if (normalized === undefined)
|
|
183
|
+
return undefined;
|
|
184
|
+
if (isCanonicalUuid(normalized)) {
|
|
185
|
+
return { kind: "entityId", value: normalized };
|
|
186
|
+
}
|
|
187
|
+
if (field === "identifier" || field === "issueIdentifier") {
|
|
188
|
+
return { kind: "identifier", value: normalized };
|
|
189
|
+
}
|
|
190
|
+
if (isLinearIssueIdentifier(normalized)) {
|
|
191
|
+
return { kind: "identifier", value: normalized };
|
|
192
|
+
}
|
|
193
|
+
return field === "id" ? { kind: "entityId", value: normalized } : undefined;
|
|
194
|
+
}
|
|
195
|
+
function compareClaims(left, right) {
|
|
196
|
+
const order = { identifier: 0, entityId: 1, url: 2 };
|
|
197
|
+
const kindOrder = order[left.kind] - order[right.kind];
|
|
198
|
+
if (kindOrder !== 0)
|
|
199
|
+
return kindOrder;
|
|
200
|
+
if (left.value === right.value)
|
|
201
|
+
return 0;
|
|
202
|
+
return left.value < right.value ? -1 : 1;
|
|
203
|
+
}
|
|
204
|
+
function isCanonicalUuid(value) {
|
|
205
|
+
return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/iu.test(value);
|
|
206
|
+
}
|
|
207
|
+
function linearIssueReferenceFromUrl(value) {
|
|
208
|
+
let url;
|
|
209
|
+
try {
|
|
210
|
+
url = new URL(value);
|
|
211
|
+
}
|
|
212
|
+
catch {
|
|
213
|
+
return undefined;
|
|
214
|
+
}
|
|
215
|
+
if (url.protocol !== "https:" || url.hostname !== "linear.app") {
|
|
216
|
+
return undefined;
|
|
217
|
+
}
|
|
218
|
+
try {
|
|
219
|
+
const reference = linearIssueReference(value);
|
|
220
|
+
return reference.workspace === undefined
|
|
221
|
+
? undefined
|
|
222
|
+
: { id: reference.id, workspace: reference.workspace };
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
|
+
return undefined;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
function canonicalPublicationUrlClaim(value) {
|
|
229
|
+
const reference = linearIssueReferenceFromUrl(value);
|
|
230
|
+
return reference === undefined
|
|
231
|
+
? `raw:\0${value}`
|
|
232
|
+
: `linear:\0${reference.workspace}\0${reference.id}`;
|
|
233
|
+
}
|
|
234
|
+
export function publicationClaimAliases(claim) {
|
|
235
|
+
if (claim.kind !== "url")
|
|
236
|
+
return [claim];
|
|
237
|
+
const reference = linearIssueReferenceFromUrl(claim.value);
|
|
238
|
+
return reference === undefined
|
|
239
|
+
? [claim]
|
|
240
|
+
: [claim, { kind: "identifier", value: reference.id }];
|
|
241
|
+
}
|
|
242
|
+
function normalizeNonemptyString(value) {
|
|
243
|
+
if (typeof value !== "string")
|
|
244
|
+
return undefined;
|
|
245
|
+
const normalized = value.trim();
|
|
246
|
+
return normalized.length === 0 ? undefined : normalized;
|
|
247
|
+
}
|
|
248
|
+
function containsIdentifier(value, identifier) {
|
|
249
|
+
const escaped = identifier.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
250
|
+
return new RegExp(`(?<![\\w-])${escaped}(?![\\w-])`, "u").test(value);
|
|
137
251
|
}
|
|
138
252
|
function isRecord(value) {
|
|
139
253
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|