@euconform/core 1.0.1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +12 -0
  3. package/dist/evidence/bundle.d.ts +23 -0
  4. package/dist/evidence/bundle.d.ts.map +1 -0
  5. package/dist/evidence/bundle.js +44 -0
  6. package/dist/evidence/compliance-evaluation.d.ts +12 -0
  7. package/dist/evidence/compliance-evaluation.d.ts.map +1 -0
  8. package/dist/evidence/compliance-evaluation.js +78 -0
  9. package/dist/evidence/hash.d.ts +2 -0
  10. package/dist/evidence/hash.d.ts.map +1 -0
  11. package/dist/evidence/hash.js +4 -0
  12. package/dist/evidence/index.d.ts +13 -0
  13. package/dist/evidence/index.d.ts.map +1 -0
  14. package/dist/evidence/index.js +11 -0
  15. package/dist/evidence/markdown.d.ts +9 -0
  16. package/dist/evidence/markdown.d.ts.map +1 -0
  17. package/dist/evidence/markdown.js +169 -0
  18. package/dist/evidence/output.d.ts +13 -0
  19. package/dist/evidence/output.d.ts.map +1 -0
  20. package/dist/evidence/output.js +547 -0
  21. package/dist/evidence/types.d.ts +230 -0
  22. package/dist/evidence/types.d.ts.map +1 -0
  23. package/dist/evidence/types.js +7 -0
  24. package/dist/evidence/validate.d.ts +8 -0
  25. package/dist/evidence/validate.d.ts.map +1 -0
  26. package/dist/evidence/validate.js +175 -0
  27. package/dist/index.d.ts +2 -2
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +1 -1
  30. package/dist/inference/ollama-client.d.ts +3 -0
  31. package/dist/inference/ollama-client.d.ts.map +1 -1
  32. package/dist/inference/ollama-client.js +69 -71
  33. package/dist/legal-checks/annex-iv-report.d.ts +3 -0
  34. package/dist/legal-checks/annex-iv-report.d.ts.map +1 -1
  35. package/dist/legal-checks/annex-iv-report.js +1 -0
  36. package/dist/legal-checks/deadline-timeline.d.ts +57 -0
  37. package/dist/legal-checks/deadline-timeline.d.ts.map +1 -0
  38. package/dist/legal-checks/deadline-timeline.js +265 -0
  39. package/dist/legal-checks/gap-analysis.d.ts +48 -0
  40. package/dist/legal-checks/gap-analysis.d.ts.map +1 -0
  41. package/dist/legal-checks/gap-analysis.js +397 -0
  42. package/dist/legal-checks/gpai-classifier.d.ts +49 -0
  43. package/dist/legal-checks/gpai-classifier.d.ts.map +1 -0
  44. package/dist/legal-checks/gpai-classifier.js +197 -0
  45. package/dist/legal-checks/index.d.ts +6 -0
  46. package/dist/legal-checks/index.d.ts.map +1 -1
  47. package/dist/legal-checks/index.js +3 -0
  48. package/dist/scanner/aggregator.d.ts +7 -0
  49. package/dist/scanner/aggregator.d.ts.map +1 -0
  50. package/dist/scanner/aggregator.js +200 -0
  51. package/dist/scanner/detectors/ai-framework-detector.d.ts +3 -0
  52. package/dist/scanner/detectors/ai-framework-detector.d.ts.map +1 -0
  53. package/dist/scanner/detectors/ai-framework-detector.js +74 -0
  54. package/dist/scanner/detectors/ai-provider-detector.d.ts +3 -0
  55. package/dist/scanner/detectors/ai-provider-detector.d.ts.map +1 -0
  56. package/dist/scanner/detectors/ai-provider-detector.js +100 -0
  57. package/dist/scanner/detectors/compliance-detector.d.ts +3 -0
  58. package/dist/scanner/detectors/compliance-detector.d.ts.map +1 -0
  59. package/dist/scanner/detectors/compliance-detector.js +201 -0
  60. package/dist/scanner/detectors/config-detector.d.ts +3 -0
  61. package/dist/scanner/detectors/config-detector.d.ts.map +1 -0
  62. package/dist/scanner/detectors/config-detector.js +248 -0
  63. package/dist/scanner/detectors/framework-detector.d.ts +3 -0
  64. package/dist/scanner/detectors/framework-detector.d.ts.map +1 -0
  65. package/dist/scanner/detectors/framework-detector.js +141 -0
  66. package/dist/scanner/detectors/index.d.ts +8 -0
  67. package/dist/scanner/detectors/index.d.ts.map +1 -0
  68. package/dist/scanner/detectors/index.js +37 -0
  69. package/dist/scanner/detectors/local-inference-detector.d.ts +3 -0
  70. package/dist/scanner/detectors/local-inference-detector.d.ts.map +1 -0
  71. package/dist/scanner/detectors/local-inference-detector.js +93 -0
  72. package/dist/scanner/detectors/markdown-detector.d.ts +3 -0
  73. package/dist/scanner/detectors/markdown-detector.d.ts.map +1 -0
  74. package/dist/scanner/detectors/markdown-detector.js +139 -0
  75. package/dist/scanner/detectors/package-json-detector.d.ts +3 -0
  76. package/dist/scanner/detectors/package-json-detector.d.ts.map +1 -0
  77. package/dist/scanner/detectors/package-json-detector.js +166 -0
  78. package/dist/scanner/detectors/rag-detector.d.ts +3 -0
  79. package/dist/scanner/detectors/rag-detector.d.ts.map +1 -0
  80. package/dist/scanner/detectors/rag-detector.js +132 -0
  81. package/dist/scanner/detectors/shared.d.ts +18 -0
  82. package/dist/scanner/detectors/shared.d.ts.map +1 -0
  83. package/dist/scanner/detectors/shared.js +36 -0
  84. package/dist/scanner/discovery.d.ts +14 -0
  85. package/dist/scanner/discovery.d.ts.map +1 -0
  86. package/dist/scanner/discovery.js +235 -0
  87. package/dist/scanner/index.d.ts +9 -0
  88. package/dist/scanner/index.d.ts.map +1 -0
  89. package/dist/scanner/index.js +8 -0
  90. package/package.json +6 -3
  91. package/src/evidence/bundle.ts +65 -0
  92. package/src/evidence/compliance-evaluation.ts +114 -0
  93. package/src/evidence/hash.ts +5 -0
  94. package/src/evidence/index.ts +51 -0
  95. package/src/evidence/markdown.ts +226 -0
  96. package/src/evidence/output.ts +717 -0
  97. package/src/evidence/types.ts +329 -0
  98. package/src/evidence/validate.ts +270 -0
  99. package/src/index.ts +25 -0
  100. package/src/inference/ollama-client.ts +93 -86
  101. package/src/legal-checks/annex-iv-report.ts +4 -0
  102. package/src/legal-checks/deadline-timeline.ts +313 -0
  103. package/src/legal-checks/gap-analysis.ts +454 -0
  104. package/src/legal-checks/gpai-classifier.ts +281 -0
  105. package/src/legal-checks/index.ts +33 -0
  106. package/src/scanner/aggregator.ts +258 -0
  107. package/src/scanner/detectors/ai-framework-detector.ts +94 -0
  108. package/src/scanner/detectors/ai-provider-detector.ts +135 -0
  109. package/src/scanner/detectors/compliance-detector.ts +232 -0
  110. package/src/scanner/detectors/config-detector.ts +316 -0
  111. package/src/scanner/detectors/framework-detector.ts +163 -0
  112. package/src/scanner/detectors/index.ts +40 -0
  113. package/src/scanner/detectors/local-inference-detector.ts +124 -0
  114. package/src/scanner/detectors/markdown-detector.ts +176 -0
  115. package/src/scanner/detectors/package-json-detector.ts +202 -0
  116. package/src/scanner/detectors/rag-detector.ts +162 -0
  117. package/src/scanner/detectors/shared.ts +45 -0
  118. package/src/scanner/discovery.ts +290 -0
  119. package/src/scanner/index.ts +9 -0
  120. package/tests/evidence/bundle.test.ts +128 -0
  121. package/tests/evidence/ecef-schemas.test.ts +316 -0
  122. package/tests/evidence/hash.test.ts +25 -0
  123. package/tests/evidence/markdown.test.ts +92 -0
  124. package/tests/evidence/output.test.ts +203 -0
  125. package/tests/fixtures/compliance-good/README.md +14 -0
  126. package/tests/fixtures/compliance-good/lib/ai-service.ts +17 -0
  127. package/tests/fixtures/compliance-good/lib/review-flow.ts +11 -0
  128. package/tests/fixtures/compliance-good/package.json +10 -0
  129. package/tests/fixtures/compliance-good/tests/bias-check.test.ts +13 -0
  130. package/tests/fixtures/nextjs-openai/README.md +5 -0
  131. package/tests/fixtures/nextjs-openai/app/page.tsx +11 -0
  132. package/tests/fixtures/nextjs-openai/package.json +9 -0
  133. package/tests/fixtures/ollama-rag/.env.example +2 -0
  134. package/tests/fixtures/ollama-rag/docker-compose.yml +9 -0
  135. package/tests/fixtures/ollama-rag/package.json +9 -0
  136. package/tests/fixtures/ollama-rag/server.ts +21 -0
  137. package/tests/fixtures/plain-webapp/README.md +3 -0
  138. package/tests/fixtures/plain-webapp/index.js +5 -0
  139. package/tests/fixtures/plain-webapp/package.json +8 -0
  140. package/tests/gpai-classifier.test.ts +125 -0
  141. package/tests/gpai-timeline.test.ts +55 -0
  142. package/tests/scanner/aggregator.test.ts +122 -0
  143. package/tests/scanner/detectors.test.ts +274 -0
  144. package/tests/scanner/discovery.test.ts +87 -0
  145. package/vitest.config.ts +1 -0
  146. package/.turbo/turbo-check-types.log +0 -4
  147. package/.turbo/turbo-test.log +0 -364
  148. package/coverage/base.css +0 -224
  149. package/coverage/block-navigation.js +0 -87
  150. package/coverage/clover.xml +0 -3282
  151. package/coverage/coverage-final.json +0 -20
  152. package/coverage/favicon.png +0 -0
  153. package/coverage/index.html +0 -161
  154. package/coverage/prettify.css +0 -1
  155. package/coverage/prettify.js +0 -2
  156. package/coverage/sort-arrow-sprite.png +0 -0
  157. package/coverage/sorter.js +0 -210
  158. package/coverage/src/fairness-metrics.ts.html +0 -1579
  159. package/coverage/src/index.html +0 -161
  160. package/coverage/src/index.ts.html +0 -535
  161. package/coverage/src/inference/browser-inference.ts.html +0 -859
  162. package/coverage/src/inference/capability-detection.ts.html +0 -2227
  163. package/coverage/src/inference/index.html +0 -176
  164. package/coverage/src/inference/index.ts.html +0 -553
  165. package/coverage/src/inference/inference-factory.ts.html +0 -751
  166. package/coverage/src/inference/ollama-client.ts.html +0 -1627
  167. package/coverage/src/legal-checks/annex-iv-report.ts.html +0 -556
  168. package/coverage/src/legal-checks/bias-metrics.ts.html +0 -1855
  169. package/coverage/src/legal-checks/data-governance.ts.html +0 -529
  170. package/coverage/src/legal-checks/human-oversight-logging.ts.html +0 -490
  171. package/coverage/src/legal-checks/index.html +0 -206
  172. package/coverage/src/legal-checks/index.ts.html +0 -250
  173. package/coverage/src/legal-checks/risk-classifier.ts.html +0 -940
  174. package/coverage/src/legal-checks/robustness-transparency.ts.html +0 -571
  175. package/coverage/src/metrics/crows-pairs-bias.ts.html +0 -820
  176. package/coverage/src/metrics/index.html +0 -146
  177. package/coverage/src/metrics/index.ts.html +0 -151
  178. package/coverage/src/metrics/stereotype-bias.ts.html +0 -886
  179. package/coverage/src/risk-engine.ts.html +0 -1660
  180. package/coverage/src/types.ts.html +0 -547
  181. package/dist/legal-checks/disclaimer.d.ts +0 -2
  182. package/dist/legal-checks/disclaimer.d.ts.map +0 -1
  183. package/dist/legal-checks/disclaimer.js +0 -1
@@ -0,0 +1,281 @@
1
+ /**
2
+ * GPAI / Foundation Model Compliance Classifier
3
+ * Based on EU AI Act (Regulation EU 2024/1689) – Art. 53–55 + Art. 51 + Art. 71
4
+ *
5
+ * Obligations enforceable since August 2, 2025 (Phase 2, Art. 113(2)).
6
+ *
7
+ * IMPORTANT: This module provides technical orientation, not legal advice.
8
+ */
9
+
10
+ import type { QuizAnswer, QuizQuestion } from "../types";
11
+
12
+ /** The specific obligations checked under Art. 53–55 */
13
+ export type GPAIObligationType =
14
+ | "technical-docs"
15
+ | "downstream-info"
16
+ | "copyright-policy"
17
+ | "eu-database"
18
+ | "open-source"
19
+ | "systemic-risk"
20
+ | "red-teaming"
21
+ | "incident-reporting"
22
+ | "cybersecurity";
23
+
24
+ /** Overall compliance determination */
25
+ export type GPAIComplianceLevel = "compliant" | "partial" | "non-compliant";
26
+
27
+ /** A specific obligation that is missing or only partially met */
28
+ export interface GPAIComplianceFlag {
29
+ obligation: GPAIObligationType;
30
+ status: "missing" | "partial";
31
+ articleRef: string;
32
+ }
33
+
34
+ /** Full result of GPAI compliance classification */
35
+ export interface GPAIComplianceResult {
36
+ level: GPAIComplianceLevel;
37
+ isSystemicRisk: boolean;
38
+ flags: GPAIComplianceFlag[];
39
+ legalBasis: string[];
40
+ notes: string[];
41
+ }
42
+
43
+ /**
44
+ * The 9 GPAI compliance questions (Art. 53–55).
45
+ * Order matters: q1–q9 map to i18n keys gpai_q1–gpai_q9.
46
+ */
47
+ export const GPAI_QUESTIONS: QuizQuestion[] = [
48
+ {
49
+ id: "gpai-technical-docs",
50
+ question: "Art. 53(1)(a): Technical documentation (Annex XI/XII)?",
51
+ description:
52
+ "Have you prepared and maintain up-to-date technical documentation for the GPAI model per Annex XI/XII (general-purpose) or the systemic-risk extension?",
53
+ options: [
54
+ { value: "yes", label: "Yes, implemented" },
55
+ { value: "no", label: "No, missing" },
56
+ { value: "unsure", label: "In progress / unsure" },
57
+ ],
58
+ },
59
+ {
60
+ id: "gpai-downstream-info",
61
+ question: "Art. 53(1)(b): Downstream provider information?",
62
+ description:
63
+ "Do you provide downstream providers / deployers with the information they need to comply with their own EU AI Act obligations (capabilities, limitations, intended use)?",
64
+ options: [
65
+ { value: "yes", label: "Yes, implemented" },
66
+ { value: "no", label: "No, missing" },
67
+ { value: "unsure", label: "In progress / unsure" },
68
+ ],
69
+ },
70
+ {
71
+ id: "gpai-copyright-policy",
72
+ question: "Art. 53(1)(c–d): Copyright policy + training data summary?",
73
+ description:
74
+ "Have you established a copyright compliance policy (Art. 53(1)(c)) and published a sufficiently detailed training data summary for copyright purposes (Art. 53(1)(d))?",
75
+ options: [
76
+ { value: "yes", label: "Yes, implemented" },
77
+ { value: "no", label: "No, missing" },
78
+ { value: "unsure", label: "In progress / unsure" },
79
+ ],
80
+ },
81
+ {
82
+ id: "gpai-eu-database",
83
+ question: "Art. 71: EU AI Database registration?",
84
+ description:
85
+ "Is the GPAI model registered in the EU AI Database as required under Art. 71 (providers of GPAI models must register before placing the model on the EU market)?",
86
+ options: [
87
+ { value: "yes", label: "Yes, registered" },
88
+ { value: "no", label: "No, not registered" },
89
+ { value: "unsure", label: "In progress / unsure" },
90
+ ],
91
+ },
92
+ {
93
+ id: "gpai-open-source",
94
+ question: "Art. 53(2): Open-source model release?",
95
+ description:
96
+ "Is the model released as open source with weights publicly available? Open-source GPAI models are exempt from Art. 53(1)(a–c) obligations (technical docs, downstream info, copyright policy) but not from Art. 53(1)(d) (training data summary) or Art. 55 systemic-risk obligations.",
97
+ options: [
98
+ { value: "yes", label: "Yes, open source" },
99
+ { value: "no", label: "No, proprietary" },
100
+ { value: "unsure", label: "Unsure / partially open" },
101
+ ],
102
+ },
103
+ {
104
+ id: "gpai-systemic-risk",
105
+ question: "Art. 51 + Annex XIII: Trained with ≥ 10²⁵ FLOP?",
106
+ description:
107
+ "Was the model trained using compute exceeding 10²⁵ floating-point operations (FLOP)? Models at or above this threshold are designated as GPAI models with systemic risk (Art. 51) and are subject to the additional Art. 55 obligations below.",
108
+ options: [
109
+ { value: "yes", label: "Yes (systemic risk)" },
110
+ { value: "no", label: "No (below threshold)" },
111
+ { value: "unsure", label: "Unknown / unsure" },
112
+ ],
113
+ },
114
+ {
115
+ id: "gpai-red-teaming",
116
+ question: "Art. 55(1)(a): Adversarial testing / red-teaming?",
117
+ description:
118
+ "Have you conducted model evaluations, adversarial testing, and red-teaming to identify and mitigate systemic risks (required only for Art. 51 systemic-risk models)?",
119
+ options: [
120
+ { value: "yes", label: "Yes, conducted" },
121
+ { value: "no", label: "No, not done" },
122
+ { value: "unsure", label: "In progress / unsure" },
123
+ ],
124
+ },
125
+ {
126
+ id: "gpai-incident-reporting",
127
+ question: "Art. 55(1)(b): Serious incident reporting mechanisms?",
128
+ description:
129
+ "Do you have mechanisms to track, document, and report serious incidents caused by the GPAI model to the AI Office and affected national authorities (required only for Art. 51 systemic-risk models)?",
130
+ options: [
131
+ { value: "yes", label: "Yes, in place" },
132
+ { value: "no", label: "No, missing" },
133
+ { value: "unsure", label: "In progress / unsure" },
134
+ ],
135
+ },
136
+ {
137
+ id: "gpai-cybersecurity",
138
+ question: "Art. 55(1)(c): Cybersecurity measures?",
139
+ description:
140
+ "Have you implemented adequate cybersecurity protections for the GPAI model and its infrastructure, including adversarial robustness measures (required only for Art. 51 systemic-risk models)?",
141
+ options: [
142
+ { value: "yes", label: "Yes, implemented" },
143
+ { value: "no", label: "No, missing" },
144
+ { value: "unsure", label: "In progress / unsure" },
145
+ ],
146
+ },
147
+ ];
148
+
149
+ /** Returns the full ordered list of GPAI compliance questions */
150
+ export function getGPAIQuestions(): QuizQuestion[] {
151
+ return GPAI_QUESTIONS;
152
+ }
153
+
154
+ /** Returns true if the model meets the systemic risk threshold (Art. 51) */
155
+ export function isSystemicRiskModel(answers: QuizAnswer[]): boolean {
156
+ const systemicAnswer = answers.find((a) => a.questionId === "gpai-systemic-risk");
157
+ return systemicAnswer?.value === "yes";
158
+ }
159
+
160
+ /** Push a flag if the answer value is "no" or "unsure" */
161
+ function checkObligation(
162
+ value: string | undefined,
163
+ obligation: GPAIObligationType,
164
+ articleRef: string,
165
+ flags: GPAIComplianceFlag[]
166
+ ): void {
167
+ if (value === "no") {
168
+ flags.push({ obligation, status: "missing", articleRef });
169
+ } else if (value === "unsure") {
170
+ flags.push({ obligation, status: "partial", articleRef });
171
+ }
172
+ }
173
+
174
+ /** Evaluate Art. 53 obligations and populate flags / notes */
175
+ function evaluateArt53Obligations(
176
+ byId: Map<string, string>,
177
+ isOpenSource: boolean,
178
+ flags: GPAIComplianceFlag[],
179
+ legalBasis: string[],
180
+ notes: string[]
181
+ ): void {
182
+ if (!isOpenSource) {
183
+ checkObligation(byId.get("gpai-technical-docs"), "technical-docs", "Art. 53(1)(a)", flags);
184
+ checkObligation(byId.get("gpai-downstream-info"), "downstream-info", "Art. 53(1)(b)", flags);
185
+ checkObligation(
186
+ byId.get("gpai-copyright-policy"),
187
+ "copyright-policy",
188
+ "Art. 53(1)(c–d)",
189
+ flags
190
+ );
191
+ } else {
192
+ // Open-source: Art. 53(1)(a–c) exempt, but training data summary (Art. 53(1)(d)) still applies
193
+ const copyrightVal = byId.get("gpai-copyright-policy");
194
+ checkObligation(copyrightVal, "copyright-policy", "Art. 53(1)(d)", flags);
195
+ if (copyrightVal === "no" || copyrightVal === "unsure") {
196
+ notes.push(
197
+ "Open-source models are exempt from Art. 53(1)(c) copyright policy obligations, but Art. 53(1)(d) training data summary still applies."
198
+ );
199
+ }
200
+ }
201
+
202
+ const euDatabase = byId.get("gpai-eu-database");
203
+ checkObligation(euDatabase, "eu-database", "Art. 71", flags);
204
+ if (euDatabase === "no") {
205
+ legalBasis.push("Verordnung (EU) 2024/1689 – Art. 71 (EU AI Database)");
206
+ }
207
+ }
208
+
209
+ /** Evaluate Art. 55 systemic risk obligations and populate flags */
210
+ function evaluateArt55Obligations(
211
+ byId: Map<string, string>,
212
+ flags: GPAIComplianceFlag[],
213
+ legalBasis: string[]
214
+ ): void {
215
+ legalBasis.push("Verordnung (EU) 2024/1689 – Art. 51 + Art. 55 (Systemic Risk)");
216
+ legalBasis.push("Verordnung (EU) 2024/1689 – Annex XIII (Systemic Risk Indicators)");
217
+ checkObligation(byId.get("gpai-red-teaming"), "red-teaming", "Art. 55(1)(a)", flags);
218
+ checkObligation(
219
+ byId.get("gpai-incident-reporting"),
220
+ "incident-reporting",
221
+ "Art. 55(1)(b)",
222
+ flags
223
+ );
224
+ checkObligation(byId.get("gpai-cybersecurity"), "cybersecurity", "Art. 55(1)(c)", flags);
225
+ }
226
+
227
+ /** Determine overall compliance level from accumulated flags */
228
+ function determineLevel(flags: GPAIComplianceFlag[], isOpenSource: boolean): GPAIComplianceLevel {
229
+ const criticalObligations: GPAIObligationType[] = isOpenSource
230
+ ? ["eu-database"]
231
+ : ["technical-docs", "downstream-info", "copyright-policy", "eu-database"];
232
+
233
+ const allCriticalMissing =
234
+ !isOpenSource &&
235
+ criticalObligations.every((obl) =>
236
+ flags.some((f) => f.obligation === obl && f.status === "missing")
237
+ );
238
+
239
+ if (allCriticalMissing) return "non-compliant";
240
+ if (flags.length > 0) return "partial";
241
+ return "compliant";
242
+ }
243
+
244
+ /**
245
+ * Classify GPAI compliance based on answers to the 9 questions.
246
+ * Returns a GPAIComplianceResult with level, flags, and legal basis.
247
+ *
248
+ * Classification logic:
249
+ * - Open-source (Art. 53(2)): exempt from docs/downstream/copyright obligations
250
+ * - Systemic risk (Art. 51): Art. 55 obligations apply
251
+ * - Critical Art. 53 all missing → "non-compliant"
252
+ * - Any "unsure" or partial → "partial"
253
+ * - All applicable "yes" → "compliant"
254
+ */
255
+ export function classifyGPAICompliance(answers: QuizAnswer[]): GPAIComplianceResult {
256
+ const byId = new Map(answers.map((a) => [a.questionId, a.value] as const));
257
+ const isOpenSource = byId.get("gpai-open-source") === "yes";
258
+ const hasSystemicRisk = byId.get("gpai-systemic-risk") === "yes";
259
+
260
+ const flags: GPAIComplianceFlag[] = [];
261
+ const legalBasis: string[] = ["Verordnung (EU) 2024/1689 – Art. 53 (GPAI obligations)"];
262
+ const notes: string[] = [];
263
+
264
+ evaluateArt53Obligations(byId, isOpenSource, flags, legalBasis, notes);
265
+
266
+ if (hasSystemicRisk) {
267
+ evaluateArt55Obligations(byId, flags, legalBasis);
268
+ } else {
269
+ notes.push(
270
+ "Art. 55 systemic risk obligations (red-teaming, incident reporting, cybersecurity) are not applicable as the model does not meet the Art. 51 threshold (≥ 10²⁵ FLOP)."
271
+ );
272
+ }
273
+
274
+ return {
275
+ level: determineLevel(flags, isOpenSource),
276
+ isSystemicRisk: hasSystemicRisk,
277
+ flags,
278
+ legalBasis,
279
+ notes,
280
+ };
281
+ }
@@ -53,3 +53,36 @@ export { getHumanOversightAndLoggingTemplate } from "./human-oversight-logging";
53
53
 
54
54
  export type { AnnexIVStructuredReportV1 } from "./annex-iv-report";
55
55
  export { buildAnnexIVReportV1 } from "./annex-iv-report";
56
+
57
+ export type {
58
+ DeadlineStatus,
59
+ AffectedAudience,
60
+ DeadlineObligation,
61
+ DeadlinePhase,
62
+ } from "./deadline-timeline";
63
+ export {
64
+ EU_AI_ACT_TIMELINE,
65
+ DIGITAL_OMNIBUS_PROPOSALS,
66
+ getDeadlineStatus,
67
+ getDaysUntilDeadline,
68
+ getAudiencesForRiskLevel,
69
+ getNextDeadline,
70
+ getTimelineForRiskLevel,
71
+ getTimelineForAudiences,
72
+ } from "./deadline-timeline";
73
+
74
+ export type {
75
+ GPAIObligationType,
76
+ GPAIComplianceLevel,
77
+ GPAIComplianceFlag,
78
+ GPAIComplianceResult,
79
+ } from "./gpai-classifier";
80
+ export {
81
+ GPAI_QUESTIONS,
82
+ classifyGPAICompliance,
83
+ getGPAIQuestions,
84
+ isSystemicRiskModel,
85
+ } from "./gpai-classifier";
86
+
87
+ export type { GapPriority, GapAction, GapAnalysisResult } from "./gap-analysis";
88
+ export { generateAnnexIIIGapAnalysis, generateGPAIGapAnalysis } from "./gap-analysis";
@@ -0,0 +1,258 @@
1
+ /**
2
+ * Scanner aggregator — orchestrates file discovery and signal detection,
3
+ * deduplicates signals, and assembles the ScanResult.
4
+ */
5
+
6
+ import { basename } from "node:path";
7
+ import { hasImplementationSignals } from "../evidence/compliance-evaluation";
8
+ import type {
9
+ AppType,
10
+ ConfidenceLevel,
11
+ DetectedSignal,
12
+ FileProvenance,
13
+ OpenQuestion,
14
+ RepoProfile,
15
+ ScanFile,
16
+ ScanOptions,
17
+ ScanResult,
18
+ SignalCategory,
19
+ } from "../evidence/types";
20
+ import { runAllDetectors } from "./detectors";
21
+ import { CONFIDENCE_RANK } from "./detectors/shared";
22
+ import { discoverFiles } from "./discovery";
23
+
24
+ const TOOL_VERSION = "0.1.0";
25
+
26
+ function parseRootPackageJson(files: ScanFile[]): Record<string, unknown> | undefined {
27
+ const pkgFile = files.find((f) => f.relativePath === "package.json");
28
+ if (!pkgFile) return undefined;
29
+ try {
30
+ return JSON.parse(pkgFile.content) as Record<string, unknown>;
31
+ } catch {
32
+ return undefined;
33
+ }
34
+ }
35
+
36
+ function buildRepoProfile(
37
+ targetPath: string,
38
+ pkg: Record<string, unknown> | undefined,
39
+ files: ScanFile[]
40
+ ): RepoProfile {
41
+ const hasTs = files.some((f) => f.extension === ".ts" || f.extension === ".tsx");
42
+ const hasJs = files.some((f) => f.extension === ".js" || f.extension === ".jsx");
43
+ const languages: string[] = [];
44
+ if (hasTs) languages.push("typescript");
45
+ if (hasJs) languages.push("javascript");
46
+
47
+ let packageManager: RepoProfile["packageManager"];
48
+ if (files.some((f) => f.relativePath === "pnpm-lock.yaml")) packageManager = "pnpm";
49
+ else if (files.some((f) => f.relativePath === "yarn.lock")) packageManager = "yarn";
50
+ else if (files.some((f) => f.relativePath === "package-lock.json")) packageManager = "npm";
51
+
52
+ const isMonorepo = Boolean(
53
+ pkg?.workspaces || files.some((f) => f.relativePath === "pnpm-workspace.yaml")
54
+ );
55
+
56
+ return {
57
+ name: (pkg?.name as string) ?? basename(targetPath),
58
+ version: pkg?.version as string | undefined,
59
+ description: pkg?.description as string | undefined,
60
+ license: pkg?.license as string | undefined,
61
+ isMonorepo,
62
+ packageManager,
63
+ languages,
64
+ };
65
+ }
66
+
67
+ function inferAppTypes(signals: DetectedSignal[]): AppType[] {
68
+ const types = new Set<AppType>();
69
+
70
+ const has = (id: string) => signals.some((s) => s.id === id);
71
+ const hasCategory = (cat: SignalCategory) => signals.some((s) => s.category === cat);
72
+
73
+ if (has("framework-nextjs") || has("framework-react")) types.add("web-app");
74
+ if (
75
+ has("framework-express") ||
76
+ has("framework-fastify") ||
77
+ has("framework-nestjs") ||
78
+ has("framework-hono") ||
79
+ has("framework-elysia")
80
+ )
81
+ types.add("api-server");
82
+ if (hasCategory("local-inference") || hasCategory("ai-provider"))
83
+ if (signals.some((s) => s.name.toLowerCase().includes("chat"))) types.add("chatbot");
84
+ if (hasCategory("training")) types.add("ml-pipeline");
85
+
86
+ if (types.size === 0) types.add("unknown");
87
+ return [...types];
88
+ }
89
+
90
+ /** Merge signals with the same ID: keep highest confidence, combine evidence */
91
+ function deduplicateSignals(signals: DetectedSignal[]): DetectedSignal[] {
92
+ const map = new Map<string, DetectedSignal>();
93
+
94
+ for (const signal of signals) {
95
+ const existing = map.get(signal.id);
96
+ if (!existing) {
97
+ map.set(signal.id, { ...signal, evidence: [...signal.evidence] });
98
+ continue;
99
+ }
100
+
101
+ // Merge evidence (use Set for O(1) dedup instead of O(n) .some())
102
+ const seen = new Set(existing.evidence.map((e) => `${e.file}:${e.line ?? ""}`));
103
+ for (const ev of signal.evidence) {
104
+ const key = `${ev.file}:${ev.line ?? ""}`;
105
+ if (!seen.has(key)) {
106
+ seen.add(key);
107
+ existing.evidence.push(ev);
108
+ }
109
+ }
110
+
111
+ // Upgrade confidence
112
+ if (CONFIDENCE_RANK[signal.confidence] > CONFIDENCE_RANK[existing.confidence]) {
113
+ existing.confidence = signal.confidence;
114
+ }
115
+ }
116
+
117
+ return [...map.values()];
118
+ }
119
+
120
+ function annotateEvidenceProvenance(
121
+ signals: DetectedSignal[],
122
+ files: ScanFile[]
123
+ ): DetectedSignal[] {
124
+ const provenanceByPath = new Map<string, FileProvenance>();
125
+ for (const file of files) {
126
+ provenanceByPath.set(file.relativePath, file.provenance);
127
+ }
128
+
129
+ return signals.map((signal) => ({
130
+ ...signal,
131
+ evidence: signal.evidence.map((evidence) => ({
132
+ ...evidence,
133
+ provenance: evidence.provenance ?? provenanceByPath.get(evidence.file) ?? "runtime",
134
+ })),
135
+ }));
136
+ }
137
+
138
+ function generateOpenQuestions(signals: DetectedSignal[]): OpenQuestion[] {
139
+ const questions: OpenQuestion[] = [];
140
+ const hasAI = signals.some(
141
+ (s) =>
142
+ s.category === "ai-provider" ||
143
+ s.category === "ai-framework" ||
144
+ s.category === "local-inference"
145
+ );
146
+
147
+ if (hasAI) {
148
+ questions.push({
149
+ id: "oq-market-placement",
150
+ question: "Is this AI system placed on the EU market or used within the EU?",
151
+ context:
152
+ "The EU AI Act applies to AI systems placed on or put into service in the EU market.",
153
+ relatedSignalIds: signals.filter((s) => s.category.startsWith("ai-")).map((s) => s.id),
154
+ suggestedAction: "Determine your system's geographic scope and market placement.",
155
+ });
156
+
157
+ questions.push({
158
+ id: "oq-intended-purpose",
159
+ question: "What is the intended purpose of this AI system?",
160
+ context:
161
+ "Risk classification under the EU AI Act depends on the system's intended purpose and deployment context, which cannot be determined from code alone.",
162
+ relatedSignalIds: [],
163
+ suggestedAction:
164
+ "Use the EuConform wizard to complete your risk assessment with human-provided context.",
165
+ });
166
+
167
+ questions.push({
168
+ id: "oq-provider-role",
169
+ question: "Are you a provider, deployer, or importer of this AI system?",
170
+ context:
171
+ "Different roles under Art. 3 carry different obligations. A scanner cannot determine your organizational role.",
172
+ relatedSignalIds: [],
173
+ suggestedAction:
174
+ "Clarify your role in the AI value chain to determine applicable obligations.",
175
+ });
176
+ }
177
+
178
+ const hasGpaiSignals = signals.some(
179
+ (s) => s.category === "ai-provider" || s.id.includes("langchain") || s.id.includes("llamaindex")
180
+ );
181
+ if (hasGpaiSignals) {
182
+ questions.push({
183
+ id: "oq-gpai-downstream",
184
+ question:
185
+ "Are you using a general-purpose AI model? Do you provide downstream access to others?",
186
+ context:
187
+ "GPAI obligations (Art. 53-55) apply to providers of general-purpose AI models. Using an API does not automatically make you a GPAI provider.",
188
+ relatedSignalIds: signals.filter((s) => s.category === "ai-provider").map((s) => s.id),
189
+ suggestedAction: "Determine whether you are a GPAI provider or deployer.",
190
+ });
191
+ }
192
+
193
+ const hasNoDisclosure = !hasImplementationSignals(signals, ["compliance-disclosure"]);
194
+ if (hasAI && hasNoDisclosure) {
195
+ questions.push({
196
+ id: "oq-disclosure-missing",
197
+ question: "Does your system inform users that they are interacting with AI?",
198
+ context:
199
+ "No AI disclosure signals were found in the codebase. Art. 50 requires transparency for AI systems interacting with natural persons.",
200
+ relatedSignalIds: [],
201
+ suggestedAction: "Add explicit AI disclosure in user-facing entry points.",
202
+ });
203
+ }
204
+
205
+ return questions;
206
+ }
207
+
208
+ function buildSignalSummary(signals: DetectedSignal[]): ScanResult["signalSummary"] {
209
+ const byCategory: Partial<Record<SignalCategory, number>> = {};
210
+ const byConfidence: Record<ConfidenceLevel, number> = {
211
+ high: 0,
212
+ medium: 0,
213
+ low: 0,
214
+ };
215
+
216
+ for (const s of signals) {
217
+ byCategory[s.category] = (byCategory[s.category] ?? 0) + 1;
218
+ byConfidence[s.confidence]++;
219
+ }
220
+
221
+ return { total: signals.length, byCategory, byConfidence };
222
+ }
223
+
224
+ export async function scanRepository(options: ScanOptions): Promise<ScanResult> {
225
+ const startTime = Date.now();
226
+ const scope = options.scope ?? "production";
227
+
228
+ const discovery = await discoverFiles(options);
229
+ const allFiles = discovery.files;
230
+ const rootPkg = parseRootPackageJson(allFiles);
231
+
232
+ // Run detectors on all files
233
+ const rawSignals: DetectedSignal[] = [];
234
+ for (const file of allFiles) {
235
+ const ctx = { file, lines: file.content.split("\n"), allFiles, rootPackageJson: rootPkg };
236
+ rawSignals.push(...runAllDetectors(ctx));
237
+ }
238
+
239
+ const signals = annotateEvidenceProvenance(deduplicateSignals(rawSignals), allFiles);
240
+ const openQuestions = generateOpenQuestions(signals);
241
+
242
+ return {
243
+ meta: {
244
+ scannedAt: new Date().toISOString(),
245
+ scanDurationMs: Date.now() - startTime,
246
+ toolVersion: TOOL_VERSION,
247
+ targetPath: options.targetPath,
248
+ scanScope: scope,
249
+ filesScanned: allFiles.length,
250
+ filesSkipped: discovery.skippedCount,
251
+ },
252
+ repo: buildRepoProfile(options.targetPath, rootPkg, allFiles),
253
+ appTypes: inferAppTypes(signals),
254
+ signals,
255
+ openQuestions,
256
+ signalSummary: buildSignalSummary(signals),
257
+ };
258
+ }
@@ -0,0 +1,94 @@
1
+ import type { DetectedSignal, DetectorContext } from "../../evidence/types";
2
+ import { SOURCE_EXTENSIONS } from "./shared";
3
+
4
+ // ---------------------------------------------------------------------------
5
+ // Framework patterns
6
+ // ---------------------------------------------------------------------------
7
+
8
+ interface FrameworkPattern {
9
+ id: string;
10
+ name: string;
11
+ importPattern: RegExp;
12
+ }
13
+
14
+ const FRAMEWORK_IMPORTS: FrameworkPattern[] = [
15
+ {
16
+ id: "ai-framework-langchain",
17
+ name: "LangChain",
18
+ importPattern: /(?:from\s+['"]langchain[/'"]|require\s*\(\s*['"]langchain[/'"])/,
19
+ },
20
+ {
21
+ id: "ai-framework-langchain-core",
22
+ name: "LangChain Core",
23
+ importPattern:
24
+ /(?:from\s+['"]@langchain\/[^'"]+['"]|require\s*\(\s*['"]@langchain\/[^'"]+['"])/,
25
+ },
26
+ {
27
+ id: "ai-framework-llamaindex",
28
+ name: "LlamaIndex",
29
+ importPattern: /(?:from\s+['"]llamaindex[/'"]|require\s*\(\s*['"]llamaindex[/'"])/,
30
+ },
31
+ {
32
+ id: "ai-framework-transformers",
33
+ name: "Transformers.js",
34
+ importPattern:
35
+ /(?:from\s+['"]@xenova\/transformers['"]|require\s*\(\s*['"]@xenova\/transformers['"])/,
36
+ },
37
+ {
38
+ id: "ai-framework-vercel-ai",
39
+ name: "Vercel AI SDK",
40
+ // Only match Vercel AI SDK subpath imports (ai/react, ai/rsc) to avoid false positives
41
+ // on generic "ai" package name. Bare "ai" import matched only with package.json cross-check.
42
+ importPattern:
43
+ /(?:from\s+['"]ai\/(?:react|rsc|svelte|vue|solid|core)['"']|require\s*\(\s*['"]ai\/(?:react|rsc|svelte|vue|solid|core)['"])/,
44
+ },
45
+ {
46
+ id: "ai-framework-huggingface",
47
+ name: "HuggingFace",
48
+ importPattern:
49
+ /(?:from\s+['"]@huggingface\/[^'"]+['"]|require\s*\(\s*['"]@huggingface\/[^'"]+['"])/,
50
+ },
51
+ ];
52
+
53
+ // ---------------------------------------------------------------------------
54
+ // Detector
55
+ // ---------------------------------------------------------------------------
56
+
57
+ export function detectAiFrameworkSignals(ctx: DetectorContext): DetectedSignal[] {
58
+ const { file } = ctx;
59
+ if (!SOURCE_EXTENSIONS.has(file.extension)) return [];
60
+
61
+ const lines = ctx.lines;
62
+ const signalMap = new Map<string, DetectedSignal>();
63
+
64
+ for (let i = 0; i < lines.length; i++) {
65
+ const line = lines[i];
66
+ if (!line) continue;
67
+ const lineNum = i + 1;
68
+
69
+ for (const framework of FRAMEWORK_IMPORTS) {
70
+ if (framework.importPattern.test(line)) {
71
+ const existing = signalMap.get(framework.id);
72
+ const evidence = {
73
+ file: file.relativePath,
74
+ line: lineNum,
75
+ snippet: line.trim().slice(0, 200),
76
+ };
77
+
78
+ if (existing) {
79
+ existing.evidence.push(evidence);
80
+ } else {
81
+ signalMap.set(framework.id, {
82
+ id: framework.id,
83
+ name: framework.name,
84
+ category: "ai-framework",
85
+ confidence: "medium",
86
+ evidence: [evidence],
87
+ });
88
+ }
89
+ }
90
+ }
91
+ }
92
+
93
+ return Array.from(signalMap.values());
94
+ }