@clue-ai/cli 0.0.3

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.
@@ -0,0 +1,784 @@
1
+ "use strict";
2
+ const zod_1 = require("zod");
3
+
4
+ const toolingSchemas = (() => {
5
+ const nonEmptyStringSchema = zod_1.z.string().trim().min(1);
6
+ const clueInitToolTargetSchema = zod_1.z.enum(["codex", "claude_code"]);
7
+ const clueInitToolFrameworkSchema = nonEmptyStringSchema;
8
+ const clueInitToolRequiredSecretSchema = zod_1.z.enum([
9
+ "CLUE_API_KEY",
10
+ "AI_PROVIDER_API_KEY",
11
+ ]);
12
+ const clueInitToolRequiredSecretsSchema = zod_1.z
13
+ .array(clueInitToolRequiredSecretSchema)
14
+ .superRefine((value, context) => {
15
+ for (const secret of clueInitToolRequiredSecretSchema.options) {
16
+ if (!value.includes(secret)) {
17
+ context.addIssue({
18
+ code: zod_1.z.ZodIssueCode.custom,
19
+ message: `${secret} is required`,
20
+ });
21
+ }
22
+ }
23
+ })
24
+ .transform((value) => Array.from(new Set(value)));
25
+ const clueInitToolRequestSchema = zod_1.z.object({
26
+ target_tool: clueInitToolTargetSchema,
27
+ project_key: nonEmptyStringSchema,
28
+ environment: nonEmptyStringSchema,
29
+ service_key: nonEmptyStringSchema,
30
+ framework: clueInitToolFrameworkSchema.default("fastapi"),
31
+ allowed_source_paths: zod_1.z.array(nonEmptyStringSchema).min(1),
32
+ excluded_source_paths: zod_1.z.array(nonEmptyStringSchema).default([]),
33
+ ci_workflow_path: nonEmptyStringSchema.default(".github/workflows/clue-semantic-snapshot.yml"),
34
+ });
35
+ const clueInitToolLifecycleInsertionSchema = zod_1.z.object({
36
+ api_name: zod_1.z.enum([
37
+ "ClueInit",
38
+ "ClueIdentify",
39
+ "ClueSetAccount",
40
+ "ClueLogout",
41
+ ]),
42
+ file_path: nonEmptyStringSchema,
43
+ confidence: zod_1.z.number().min(0).max(1),
44
+ reason: nonEmptyStringSchema,
45
+ });
46
+ const clueInitToolReportSchema = zod_1.z.object({
47
+ target_tool: clueInitToolTargetSchema,
48
+ ci_workflow_path: nonEmptyStringSchema,
49
+ ci_workflow_added: zod_1.z.literal(true),
50
+ required_secrets: clueInitToolRequiredSecretsSchema,
51
+ lifecycle_insertions: zod_1.z.array(clueInitToolLifecycleInsertionSchema),
52
+ semantic_generation_timing: zod_1.z.literal("after_merge_ci"),
53
+ semantic_preview_generated: zod_1.z.literal(false),
54
+ client_repo_generated_files_committed: zod_1.z.literal(false),
55
+ clue_track_inserted: zod_1.z.literal(false),
56
+ clue_dom_tag_inserted: zod_1.z.literal(false),
57
+ allowed_source_paths: zod_1.z.array(nonEmptyStringSchema),
58
+ excluded_source_paths: zod_1.z.array(nonEmptyStringSchema),
59
+ warnings: zod_1.z.array(nonEmptyStringSchema).default([]),
60
+ });
61
+
62
+ return {
63
+ clueInitToolRequestSchema,
64
+ clueInitToolReportSchema,
65
+ };
66
+ })();
67
+
68
+ const semanticSchemas = (() => {
69
+ const nonEmptyStringSchema = zod_1.z.string().trim().min(1);
70
+ const nullableNonEmptyStringSchema = nonEmptyStringSchema.nullable();
71
+ const confidenceSchema = zod_1.z.number().min(0).max(1);
72
+ const snakeSegmentPattern = /^[a-z][a-z0-9]*(?:_[a-z0-9]+)*$/;
73
+ const effectKeyPattern = /^[a-z][a-z0-9]*(?:_[a-z0-9]+)*\.[a-z][a-z0-9]*(?:_[a-z0-9]+)*$/;
74
+ const semanticFieldPathPattern = /^(target_object_profiles|target_object_catalog|target_object_mappings|routes)\[[a-zA-Z0-9_./:{}-]+\](?:\.[a-z][a-z0-9_]*(?:\[[a-zA-Z0-9_./:{}-]+\])?)+$/;
75
+ const sha256HashPattern = /^sha256:[a-f0-9]{64}$/;
76
+ const actualOutcomeActions = new Set([
77
+ "completed",
78
+ "failed",
79
+ "validation_error",
80
+ "blocked",
81
+ "abandoned",
82
+ ]);
83
+ const jsonPrimitiveSchema = zod_1.z.union([
84
+ zod_1.z.string(),
85
+ zod_1.z.number(),
86
+ zod_1.z.boolean(),
87
+ zod_1.z.null(),
88
+ ]);
89
+ const semanticSnapshotEffectKindValues = [
90
+ "data_create",
91
+ "data_update",
92
+ "data_delete",
93
+ "data_upsert",
94
+ "data_read",
95
+ "data_query",
96
+ "data_import",
97
+ "data_export",
98
+ "state_transition",
99
+ "validation_check",
100
+ "access_check",
101
+ "communication_send",
102
+ "audit_record",
103
+ "event_emit",
104
+ "background_task_schedule",
105
+ "external_service_call",
106
+ "payment_operation",
107
+ "ai_inference",
108
+ "file_process",
109
+ "cache_change",
110
+ "system_config_change",
111
+ "unknown",
112
+ ];
113
+ const semanticSnapshotResolutionBasisValues = [
114
+ "route_contract",
115
+ "direct_data_mutation",
116
+ "repository_call",
117
+ "orm_model_call",
118
+ "sql_statement",
119
+ "read_query",
120
+ "external_sdk_call",
121
+ "message_publish",
122
+ "job_enqueue",
123
+ "file_operation",
124
+ "validation_logic",
125
+ "access_control_logic",
126
+ "ai_inferred_code_behavior",
127
+ "explicit_semantic_config",
128
+ "unknown",
129
+ ];
130
+ const semanticSnapshotEvidenceStrengthValues = [
131
+ "weak",
132
+ "medium",
133
+ "strong",
134
+ "unknown",
135
+ ];
136
+ const semanticSnapshotSelectedSourceValues = [
137
+ "deterministic",
138
+ "ai",
139
+ ];
140
+ const targetObjectKeySchema = nonEmptyStringSchema.regex(snakeSegmentPattern, {
141
+ message: "must be a lowercase snake_case key",
142
+ });
143
+ const operationEffectKeySchema = nonEmptyStringSchema
144
+ .regex(effectKeyPattern, {
145
+ message: "must use <target_object_key>.<effect_action> with lowercase snake_case segments",
146
+ })
147
+ .refine((value) => !value.startsWith("unknown."), {
148
+ message: "must not fabricate unknown.* operation effect keys",
149
+ })
150
+ .refine((value) => !actualOutcomeActions.has(value.split(".")[1] ?? ""), {
151
+ message: "must not use runtime actual outcome terms as effect actions",
152
+ });
153
+ const semanticFieldPathSchema = nonEmptyStringSchema
154
+ .regex(semanticFieldPathPattern, {
155
+ message: "must be a mechanically generated semantic snapshot field path",
156
+ })
157
+ .refine((value) => !value.includes("sha256:"), {
158
+ message: "must not contain hashes",
159
+ })
160
+ .refine((value) => !/\.(py|ts|tsx|js|mjs)\b/i.test(value), {
161
+ message: "must not contain raw source file paths",
162
+ });
163
+ const semanticSnapshotHashSchema = nonEmptyStringSchema.regex(sha256HashPattern, {
164
+ message: "must be a sha256 hash",
165
+ });
166
+ const semanticSnapshotRepositorySchema = zod_1.z
167
+ .object({
168
+ provider: nonEmptyStringSchema,
169
+ repository_id: nonEmptyStringSchema,
170
+ owner: nonEmptyStringSchema.optional(),
171
+ name: nonEmptyStringSchema.optional(),
172
+ default_branch: nonEmptyStringSchema.optional(),
173
+ merge_commit: nonEmptyStringSchema,
174
+ merged_at: zod_1.z.string().datetime({ offset: true }).optional(),
175
+ pull_request_number: zod_1.z.number().int().positive().nullable().optional(),
176
+ workflow_run_id: nonEmptyStringSchema.optional(),
177
+ })
178
+ .strict();
179
+ const semanticSnapshotServiceSchema = zod_1.z
180
+ .object({
181
+ service_key: nonEmptyStringSchema,
182
+ root_path: nullableNonEmptyStringSchema.optional(),
183
+ framework: nullableNonEmptyStringSchema.optional(),
184
+ language: nullableNonEmptyStringSchema.optional(),
185
+ })
186
+ .strict();
187
+ const semanticSnapshotAnalysisSummarySchema = zod_1.z
188
+ .object({
189
+ total_routes_scanned: zod_1.z.number().int().nonnegative(),
190
+ routes_generated: zod_1.z.number().int().nonnegative(),
191
+ uncertain_routes: zod_1.z.number().int().nonnegative(),
192
+ failed_routes: zod_1.z.number().int().nonnegative(),
193
+ })
194
+ .strict();
195
+ const semanticCandidateSchema = zod_1.z
196
+ .object({
197
+ label: nonEmptyStringSchema,
198
+ subject_type: nullableNonEmptyStringSchema.optional(),
199
+ action_category: nullableNonEmptyStringSchema.optional(),
200
+ outcome_kind: nullableNonEmptyStringSchema.optional(),
201
+ value_kind: nullableNonEmptyStringSchema.optional(),
202
+ confidence: confidenceSchema,
203
+ })
204
+ .strict();
205
+ const layerEvidenceSchema = zod_1.z
206
+ .object({
207
+ data_effects: zod_1.z
208
+ .array(zod_1.z
209
+ .object({
210
+ entity_label: nonEmptyStringSchema,
211
+ mutation_kind: zod_1.z
212
+ .enum(["create", "update", "delete", "upsert", "read", "unknown"])
213
+ .optional(),
214
+ confidence: confidenceSchema.optional(),
215
+ })
216
+ .strict())
217
+ .default([]),
218
+ side_effects: zod_1.z
219
+ .array(zod_1.z
220
+ .object({
221
+ side_effect_kind: nonEmptyStringSchema,
222
+ confidence: confidenceSchema.optional(),
223
+ })
224
+ .strict())
225
+ .default([]),
226
+ failure_surfaces: zod_1.z.array(nonEmptyStringSchema).default([]),
227
+ validation_field_paths: zod_1.z.array(nonEmptyStringSchema).default([]),
228
+ permission_scopes: zod_1.z.array(nonEmptyStringSchema).default([]),
229
+ component_fingerprints: zod_1.z.array(semanticSnapshotHashSchema).default([]),
230
+ })
231
+ .strict();
232
+ const defaultLayerEvidence = {
233
+ data_effects: [],
234
+ side_effects: [],
235
+ failure_surfaces: [],
236
+ validation_field_paths: [],
237
+ permission_scopes: [],
238
+ component_fingerprints: [],
239
+ };
240
+ const semanticSnapshotSourceEvidenceRefSchema = zod_1.z
241
+ .object({
242
+ id: nonEmptyStringSchema,
243
+ kind: nonEmptyStringSchema,
244
+ summary: nonEmptyStringSchema,
245
+ evidence_strength: zod_1.z.enum(semanticSnapshotEvidenceStrengthValues),
246
+ source_ref_hash: semanticSnapshotHashSchema,
247
+ location_hash: semanticSnapshotHashSchema,
248
+ metadata: zod_1.z.record(zod_1.z.string(), jsonPrimitiveSchema).default({}),
249
+ })
250
+ .strict();
251
+ const semanticSnapshotAiInferenceEvidenceSchema = zod_1.z
252
+ .object({
253
+ id: nonEmptyStringSchema,
254
+ task: nonEmptyStringSchema,
255
+ input_source_evidence_refs: zod_1.z.array(nonEmptyStringSchema).default([]),
256
+ output_field_paths: zod_1.z.array(semanticFieldPathSchema).default([]),
257
+ reasoning_summary: nonEmptyStringSchema,
258
+ missing_context: zod_1.z.array(nonEmptyStringSchema).default([]),
259
+ })
260
+ .strict();
261
+ const semanticSnapshotTargetObjectProfileSchema = zod_1.z
262
+ .object({
263
+ id: nonEmptyStringSchema,
264
+ operation_source_key: nonEmptyStringSchema,
265
+ operation_effect_key: operationEffectKeySchema,
266
+ raw_target_object_text: nonEmptyStringSchema,
267
+ concept: nonEmptyStringSchema,
268
+ business_role: nonEmptyStringSchema,
269
+ evidence_refs: zod_1.z.array(nonEmptyStringSchema).default([]),
270
+ source_evidence_refs: zod_1.z.array(nonEmptyStringSchema).default([]),
271
+ missing_context: zod_1.z.array(nonEmptyStringSchema).default([]),
272
+ })
273
+ .strict();
274
+ const semanticSnapshotTargetObjectCatalogEntrySchema = zod_1.z
275
+ .object({
276
+ target_object_key: targetObjectKeySchema,
277
+ display_name: nonEmptyStringSchema,
278
+ concept: nonEmptyStringSchema,
279
+ business_role: nonEmptyStringSchema,
280
+ aliases: zod_1.z.array(nonEmptyStringSchema).default([]),
281
+ raw_target_object_profile_refs: zod_1.z.array(nonEmptyStringSchema).default([]),
282
+ grouping_evidence_refs: zod_1.z.array(nonEmptyStringSchema).default([]),
283
+ missing_context: zod_1.z.array(nonEmptyStringSchema).default([]),
284
+ })
285
+ .strict();
286
+ const semanticSnapshotTargetObjectMappingSchema = zod_1.z
287
+ .object({
288
+ id: nonEmptyStringSchema,
289
+ operation_source_key: nonEmptyStringSchema,
290
+ operation_effect_key: operationEffectKeySchema,
291
+ raw_target_object_profile_ref: nonEmptyStringSchema,
292
+ target_object_key: targetObjectKeySchema,
293
+ grouping_evidence_ref: nonEmptyStringSchema,
294
+ mapping_reason: nonEmptyStringSchema,
295
+ missing_context: zod_1.z.array(nonEmptyStringSchema).default([]),
296
+ })
297
+ .strict();
298
+ const semanticSnapshotOperationEffectSchema = zod_1.z
299
+ .object({
300
+ operation_effect_key: operationEffectKeySchema,
301
+ effect_kind: zod_1.z.enum(semanticSnapshotEffectKindValues),
302
+ expected_domain_effect: operationEffectKeySchema,
303
+ target_object_key: targetObjectKeySchema,
304
+ target_object_profile_ref: nonEmptyStringSchema,
305
+ target_object_mapping_ref: nonEmptyStringSchema,
306
+ resolution: zod_1.z
307
+ .object({
308
+ basis: zod_1.z.enum(semanticSnapshotResolutionBasisValues),
309
+ reason: nonEmptyStringSchema,
310
+ })
311
+ .strict(),
312
+ source_evidence_refs: zod_1.z.array(nonEmptyStringSchema).default([]),
313
+ missing_context: zod_1.z.array(nonEmptyStringSchema).default([]),
314
+ })
315
+ .strict()
316
+ .superRefine((effect, ctx) => {
317
+ const effectPrefix = effect.operation_effect_key.split(".")[0];
318
+ const expectedPrefix = effect.expected_domain_effect.split(".")[0];
319
+ if (effectPrefix !== effect.target_object_key) {
320
+ ctx.addIssue({
321
+ code: "custom",
322
+ path: ["operation_effect_key"],
323
+ message: "prefix must equal target_object_key",
324
+ });
325
+ }
326
+ if (expectedPrefix !== effect.target_object_key) {
327
+ ctx.addIssue({
328
+ code: "custom",
329
+ path: ["expected_domain_effect"],
330
+ message: "prefix must equal target_object_key",
331
+ });
332
+ }
333
+ });
334
+ const semanticSnapshotUnresolvedOperationEffectSchema = zod_1.z
335
+ .object({
336
+ id: nonEmptyStringSchema,
337
+ operation_source_key: nonEmptyStringSchema,
338
+ reason: nonEmptyStringSchema,
339
+ source_evidence_refs: zod_1.z.array(nonEmptyStringSchema).default([]),
340
+ missing_context: zod_1.z.array(nonEmptyStringSchema).default([]),
341
+ })
342
+ .strict();
343
+ const semanticMeaningCandidateValueSchema = zod_1.z.union([
344
+ nonEmptyStringSchema,
345
+ zod_1.z.number(),
346
+ zod_1.z.boolean(),
347
+ zod_1.z.null(),
348
+ ]);
349
+ const semanticSnapshotSemanticMeaningCandidateSchema = zod_1.z
350
+ .object({
351
+ id: nonEmptyStringSchema,
352
+ field_path: semanticFieldPathSchema,
353
+ parameter_name: nonEmptyStringSchema,
354
+ deterministic_candidate: zod_1.z
355
+ .object({
356
+ value: semanticMeaningCandidateValueSchema,
357
+ source_evidence_refs: zod_1.z.array(nonEmptyStringSchema).default([]),
358
+ missing_context: zod_1.z.array(nonEmptyStringSchema).default([]),
359
+ })
360
+ .strict(),
361
+ ai_candidate: zod_1.z
362
+ .object({
363
+ value: semanticMeaningCandidateValueSchema,
364
+ source_evidence_refs: zod_1.z.array(nonEmptyStringSchema).default([]),
365
+ ai_inference_evidence_ref: nonEmptyStringSchema,
366
+ missing_context: zod_1.z.array(nonEmptyStringSchema).default([]),
367
+ })
368
+ .strict(),
369
+ selected_source: zod_1.z.enum(semanticSnapshotSelectedSourceValues),
370
+ selection_reason: nonEmptyStringSchema,
371
+ selection_ai_inference_evidence_ref: nonEmptyStringSchema,
372
+ })
373
+ .strict();
374
+ const routeSemanticSnapshotEntrySchema = zod_1.z
375
+ .object({
376
+ operation_source_key: nonEmptyStringSchema,
377
+ semantic_snapshot_version: nonEmptyStringSchema.optional(),
378
+ method: nonEmptyStringSchema.optional(),
379
+ path_template: nonEmptyStringSchema.optional(),
380
+ semantics: zod_1.z
381
+ .object({
382
+ route_summary: nonEmptyStringSchema,
383
+ action_candidates: zod_1.z.array(semanticCandidateSchema).default([]),
384
+ outcome_candidates: zod_1.z.array(semanticCandidateSchema).default([]),
385
+ value_event_candidates: zod_1.z.array(semanticCandidateSchema).default([]),
386
+ route_confidence: confidenceSchema,
387
+ })
388
+ .strict(),
389
+ layer_evidence: layerEvidenceSchema.default(defaultLayerEvidence),
390
+ operation_effects: zod_1.z
391
+ .array(semanticSnapshotOperationEffectSchema)
392
+ .default([]),
393
+ unresolved_operation_effects: zod_1.z
394
+ .array(semanticSnapshotUnresolvedOperationEffectSchema)
395
+ .default([]),
396
+ source_evidence_refs: zod_1.z.array(nonEmptyStringSchema).default([]),
397
+ confidence_reason: nonEmptyStringSchema,
398
+ })
399
+ .strict();
400
+ const addDuplicateIssues = (ctx, values, path, label) => {
401
+ const seen = new Set();
402
+ values.forEach((value, index) => {
403
+ if (seen.has(value)) {
404
+ ctx.addIssue({
405
+ code: "custom",
406
+ path: [...path, index],
407
+ message: `${label} must be unique within one semantic snapshot`,
408
+ });
409
+ }
410
+ seen.add(value);
411
+ });
412
+ };
413
+ const addMissingRefIssue = (ctx, ref, validRefs, path, label) => {
414
+ if (!validRefs.has(ref)) {
415
+ ctx.addIssue({
416
+ code: "custom",
417
+ path,
418
+ message: `${label} must reference an existing snapshot-local id`,
419
+ });
420
+ }
421
+ };
422
+ const addMissingFieldPathIssue = (ctx, fieldPath, validFieldPaths, path, label) => {
423
+ if (!validFieldPaths.has(fieldPath)) {
424
+ ctx.addIssue({
425
+ code: "custom",
426
+ path,
427
+ message: `${label} must reference an existing semantic snapshot field`,
428
+ });
429
+ }
430
+ };
431
+ const semanticSnapshotRequestSchema = zod_1.z
432
+ .object({
433
+ project_key: nonEmptyStringSchema,
434
+ idempotency_key: nonEmptyStringSchema,
435
+ schema_version: zod_1.z.number().int().positive().default(1),
436
+ semantic_snapshot_version: nonEmptyStringSchema.optional(),
437
+ generated_at: zod_1.z.string().datetime({ offset: true }),
438
+ repository: semanticSnapshotRepositorySchema,
439
+ service: semanticSnapshotServiceSchema,
440
+ analysis_summary: semanticSnapshotAnalysisSummarySchema,
441
+ routes: zod_1.z.array(routeSemanticSnapshotEntrySchema).min(1),
442
+ target_object_profiles: zod_1.z
443
+ .array(semanticSnapshotTargetObjectProfileSchema)
444
+ .default([]),
445
+ target_object_catalog: zod_1.z
446
+ .array(semanticSnapshotTargetObjectCatalogEntrySchema)
447
+ .default([]),
448
+ target_object_mappings: zod_1.z
449
+ .array(semanticSnapshotTargetObjectMappingSchema)
450
+ .default([]),
451
+ source_evidence_refs: zod_1.z
452
+ .array(semanticSnapshotSourceEvidenceRefSchema)
453
+ .default([]),
454
+ ai_inference_evidence: zod_1.z
455
+ .array(semanticSnapshotAiInferenceEvidenceSchema)
456
+ .default([]),
457
+ semantic_meaning_candidates: zod_1.z
458
+ .array(semanticSnapshotSemanticMeaningCandidateSchema)
459
+ .default([]),
460
+ })
461
+ .strict()
462
+ .superRefine((snapshot, ctx) => {
463
+ if (snapshot.schema_version >= 2 && !snapshot.semantic_snapshot_version) {
464
+ ctx.addIssue({
465
+ code: "custom",
466
+ path: ["semantic_snapshot_version"],
467
+ message: "semantic_snapshot_version is required for schema_version >= 2",
468
+ });
469
+ }
470
+ addDuplicateIssues(ctx, snapshot.target_object_profiles.map((profile) => profile.id), ["target_object_profiles"], "target_object_profiles[].id");
471
+ addDuplicateIssues(ctx, snapshot.target_object_mappings.map((mapping) => mapping.id), ["target_object_mappings"], "target_object_mappings[].id");
472
+ addDuplicateIssues(ctx, snapshot.target_object_catalog.map((entry) => entry.target_object_key), ["target_object_catalog"], "target_object_catalog[].target_object_key");
473
+ addDuplicateIssues(ctx, snapshot.source_evidence_refs.map((entry) => entry.id), ["source_evidence_refs"], "source_evidence_refs[].id");
474
+ addDuplicateIssues(ctx, snapshot.ai_inference_evidence.map((entry) => entry.id), ["ai_inference_evidence"], "ai_inference_evidence[].id");
475
+ addDuplicateIssues(ctx, snapshot.semantic_meaning_candidates.map((entry) => entry.id), ["semantic_meaning_candidates"], "semantic_meaning_candidates[].id");
476
+ const profileRefs = new Set(snapshot.target_object_profiles.map((profile) => profile.id));
477
+ const profileById = new Map(snapshot.target_object_profiles.map((profile) => [profile.id, profile]));
478
+ const mappingRefs = new Set(snapshot.target_object_mappings.map((mapping) => mapping.id));
479
+ const mappingById = new Map(snapshot.target_object_mappings.map((mapping) => [mapping.id, mapping]));
480
+ const catalogKeys = new Set(snapshot.target_object_catalog.map((entry) => entry.target_object_key));
481
+ const catalogByKey = new Map(snapshot.target_object_catalog.map((entry) => [
482
+ entry.target_object_key,
483
+ entry,
484
+ ]));
485
+ const sourceEvidenceRefs = new Set(snapshot.source_evidence_refs.map((entry) => entry.id));
486
+ const aiInferenceRefs = new Set(snapshot.ai_inference_evidence.map((entry) => entry.id));
487
+ const validFieldPaths = new Set();
488
+ snapshot.target_object_profiles.forEach((profile) => {
489
+ const prefix = `target_object_profiles[${profile.id}]`;
490
+ for (const field of [
491
+ "raw_target_object_text",
492
+ "concept",
493
+ "business_role",
494
+ "operation_effect_key",
495
+ ]) {
496
+ validFieldPaths.add(`${prefix}.${field}`);
497
+ }
498
+ });
499
+ snapshot.target_object_catalog.forEach((entry) => {
500
+ const prefix = `target_object_catalog[${entry.target_object_key}]`;
501
+ for (const field of [
502
+ "display_name",
503
+ "concept",
504
+ "business_role",
505
+ "aliases",
506
+ "grouping_evidence_refs",
507
+ ]) {
508
+ validFieldPaths.add(`${prefix}.${field}`);
509
+ }
510
+ });
511
+ snapshot.target_object_mappings.forEach((mapping) => {
512
+ const prefix = `target_object_mappings[${mapping.id}]`;
513
+ for (const field of [
514
+ "target_object_key",
515
+ "mapping_reason",
516
+ "grouping_evidence_ref",
517
+ ]) {
518
+ validFieldPaths.add(`${prefix}.${field}`);
519
+ }
520
+ });
521
+ snapshot.routes.forEach((route) => {
522
+ for (const effect of route.operation_effects) {
523
+ const prefix = `routes[${route.operation_source_key}].operation_effects[${effect.operation_effect_key}]`;
524
+ for (const field of [
525
+ "effect_kind",
526
+ "expected_domain_effect",
527
+ "target_object_key",
528
+ "target_object_profile_ref",
529
+ "target_object_mapping_ref",
530
+ "resolution.basis",
531
+ "resolution.reason",
532
+ ]) {
533
+ validFieldPaths.add(`${prefix}.${field}`);
534
+ }
535
+ }
536
+ });
537
+ snapshot.routes.forEach((route, routeIndex) => {
538
+ if (snapshot.schema_version >= 2 && !route.semantic_snapshot_version) {
539
+ ctx.addIssue({
540
+ code: "custom",
541
+ path: ["routes", routeIndex, "semantic_snapshot_version"],
542
+ message: "routes[].semantic_snapshot_version is required for schema_version >= 2",
543
+ });
544
+ }
545
+ if (snapshot.schema_version >= 2 &&
546
+ route.semantics.value_event_candidates.length > 0) {
547
+ ctx.addIssue({
548
+ code: "custom",
549
+ path: ["routes", routeIndex, "semantics", "value_event_candidates"],
550
+ message: "value_event_candidates is legacy compatibility only and must be empty for schema_version >= 2",
551
+ });
552
+ }
553
+ route.source_evidence_refs.forEach((ref, refIndex) => {
554
+ addMissingRefIssue(ctx, ref, sourceEvidenceRefs, ["routes", routeIndex, "source_evidence_refs", refIndex], "routes[].source_evidence_refs[]");
555
+ });
556
+ route.operation_effects.forEach((effect, effectIndex) => {
557
+ if (effect.expected_domain_effect !== effect.operation_effect_key) {
558
+ ctx.addIssue({
559
+ code: "custom",
560
+ path: [
561
+ "routes",
562
+ routeIndex,
563
+ "operation_effects",
564
+ effectIndex,
565
+ "expected_domain_effect",
566
+ ],
567
+ message: "operation_effects[].expected_domain_effect must match operation_effect_key for canonical clue_tools snapshots",
568
+ });
569
+ }
570
+ addMissingRefIssue(ctx, effect.target_object_profile_ref, profileRefs, [
571
+ "routes",
572
+ routeIndex,
573
+ "operation_effects",
574
+ effectIndex,
575
+ "target_object_profile_ref",
576
+ ], "operation_effects[].target_object_profile_ref");
577
+ addMissingRefIssue(ctx, effect.target_object_mapping_ref, mappingRefs, [
578
+ "routes",
579
+ routeIndex,
580
+ "operation_effects",
581
+ effectIndex,
582
+ "target_object_mapping_ref",
583
+ ], "operation_effects[].target_object_mapping_ref");
584
+ addMissingRefIssue(ctx, effect.target_object_key, catalogKeys, [
585
+ "routes",
586
+ routeIndex,
587
+ "operation_effects",
588
+ effectIndex,
589
+ "target_object_key",
590
+ ], "operation_effects[].target_object_key");
591
+ const profile = profileById.get(effect.target_object_profile_ref);
592
+ if (profile &&
593
+ (profile.operation_source_key !== route.operation_source_key ||
594
+ profile.operation_effect_key !== effect.operation_effect_key)) {
595
+ ctx.addIssue({
596
+ code: "custom",
597
+ path: [
598
+ "routes",
599
+ routeIndex,
600
+ "operation_effects",
601
+ effectIndex,
602
+ "target_object_profile_ref",
603
+ ],
604
+ message: "operation_effects[].target_object_profile_ref must reference a profile for the same operation source and effect key",
605
+ });
606
+ }
607
+ const mapping = mappingById.get(effect.target_object_mapping_ref);
608
+ if (mapping &&
609
+ (mapping.operation_source_key !== route.operation_source_key ||
610
+ mapping.operation_effect_key !== effect.operation_effect_key ||
611
+ mapping.raw_target_object_profile_ref !==
612
+ effect.target_object_profile_ref ||
613
+ mapping.target_object_key !== effect.target_object_key)) {
614
+ ctx.addIssue({
615
+ code: "custom",
616
+ path: [
617
+ "routes",
618
+ routeIndex,
619
+ "operation_effects",
620
+ effectIndex,
621
+ "target_object_mapping_ref",
622
+ ],
623
+ message: "operation_effects[].target_object_mapping_ref must reference a mapping for the same source, effect, profile, and target object",
624
+ });
625
+ }
626
+ const catalogEntry = catalogByKey.get(effect.target_object_key);
627
+ if (catalogEntry &&
628
+ profile &&
629
+ !catalogEntry.raw_target_object_profile_refs.includes(profile.id)) {
630
+ ctx.addIssue({
631
+ code: "custom",
632
+ path: [
633
+ "routes",
634
+ routeIndex,
635
+ "operation_effects",
636
+ effectIndex,
637
+ "target_object_key",
638
+ ],
639
+ message: "operation_effects[].target_object_key must reference a catalog entry that includes the effect profile",
640
+ });
641
+ }
642
+ effect.source_evidence_refs.forEach((ref, refIndex) => {
643
+ addMissingRefIssue(ctx, ref, sourceEvidenceRefs, [
644
+ "routes",
645
+ routeIndex,
646
+ "operation_effects",
647
+ effectIndex,
648
+ "source_evidence_refs",
649
+ refIndex,
650
+ ], "operation_effects[].source_evidence_refs[]");
651
+ });
652
+ });
653
+ route.unresolved_operation_effects.forEach((effect, effectIndex) => {
654
+ effect.source_evidence_refs.forEach((ref, refIndex) => {
655
+ addMissingRefIssue(ctx, ref, sourceEvidenceRefs, [
656
+ "routes",
657
+ routeIndex,
658
+ "unresolved_operation_effects",
659
+ effectIndex,
660
+ "source_evidence_refs",
661
+ refIndex,
662
+ ], "unresolved_operation_effects[].source_evidence_refs[]");
663
+ });
664
+ });
665
+ });
666
+ snapshot.target_object_profiles.forEach((profile, profileIndex) => {
667
+ profile.evidence_refs.forEach((ref, refIndex) => {
668
+ addMissingRefIssue(ctx, ref, sourceEvidenceRefs, ["target_object_profiles", profileIndex, "evidence_refs", refIndex], "target_object_profiles[].evidence_refs[]");
669
+ });
670
+ profile.source_evidence_refs.forEach((ref, refIndex) => {
671
+ addMissingRefIssue(ctx, ref, sourceEvidenceRefs, [
672
+ "target_object_profiles",
673
+ profileIndex,
674
+ "source_evidence_refs",
675
+ refIndex,
676
+ ], "target_object_profiles[].source_evidence_refs[]");
677
+ });
678
+ });
679
+ snapshot.target_object_catalog.forEach((entry, entryIndex) => {
680
+ entry.raw_target_object_profile_refs.forEach((ref, refIndex) => {
681
+ addMissingRefIssue(ctx, ref, profileRefs, [
682
+ "target_object_catalog",
683
+ entryIndex,
684
+ "raw_target_object_profile_refs",
685
+ refIndex,
686
+ ], "target_object_catalog[].raw_target_object_profile_refs[]");
687
+ });
688
+ entry.grouping_evidence_refs.forEach((ref, refIndex) => {
689
+ addMissingRefIssue(ctx, ref, sourceEvidenceRefs, [
690
+ "target_object_catalog",
691
+ entryIndex,
692
+ "grouping_evidence_refs",
693
+ refIndex,
694
+ ], "target_object_catalog[].grouping_evidence_refs[]");
695
+ });
696
+ });
697
+ snapshot.target_object_mappings.forEach((mapping, mappingIndex) => {
698
+ addMissingRefIssue(ctx, mapping.raw_target_object_profile_ref, profileRefs, [
699
+ "target_object_mappings",
700
+ mappingIndex,
701
+ "raw_target_object_profile_ref",
702
+ ], "target_object_mappings[].raw_target_object_profile_ref");
703
+ addMissingRefIssue(ctx, mapping.target_object_key, catalogKeys, ["target_object_mappings", mappingIndex, "target_object_key"], "target_object_mappings[].target_object_key");
704
+ addMissingRefIssue(ctx, mapping.grouping_evidence_ref, sourceEvidenceRefs, ["target_object_mappings", mappingIndex, "grouping_evidence_ref"], "target_object_mappings[].grouping_evidence_ref");
705
+ const profile = profileById.get(mapping.raw_target_object_profile_ref);
706
+ if (profile &&
707
+ (profile.operation_source_key !== mapping.operation_source_key ||
708
+ profile.operation_effect_key !== mapping.operation_effect_key)) {
709
+ ctx.addIssue({
710
+ code: "custom",
711
+ path: [
712
+ "target_object_mappings",
713
+ mappingIndex,
714
+ "raw_target_object_profile_ref",
715
+ ],
716
+ message: "target_object_mappings[].raw_target_object_profile_ref must reference a profile for the same operation source and effect key",
717
+ });
718
+ }
719
+ });
720
+ snapshot.ai_inference_evidence.forEach((entry, entryIndex) => {
721
+ entry.input_source_evidence_refs.forEach((ref, refIndex) => {
722
+ addMissingRefIssue(ctx, ref, sourceEvidenceRefs, [
723
+ "ai_inference_evidence",
724
+ entryIndex,
725
+ "input_source_evidence_refs",
726
+ refIndex,
727
+ ], "ai_inference_evidence[].input_source_evidence_refs[]");
728
+ });
729
+ entry.output_field_paths.forEach((fieldPath, fieldPathIndex) => {
730
+ addMissingFieldPathIssue(ctx, fieldPath, validFieldPaths, [
731
+ "ai_inference_evidence",
732
+ entryIndex,
733
+ "output_field_paths",
734
+ fieldPathIndex,
735
+ ], "ai_inference_evidence[].output_field_paths[]");
736
+ });
737
+ });
738
+ snapshot.semantic_meaning_candidates.forEach((candidate, candidateIndex) => {
739
+ addMissingFieldPathIssue(ctx, candidate.field_path, validFieldPaths, ["semantic_meaning_candidates", candidateIndex, "field_path"], "semantic_meaning_candidates[].field_path");
740
+ candidate.deterministic_candidate.source_evidence_refs.forEach((ref, refIndex) => {
741
+ addMissingRefIssue(ctx, ref, sourceEvidenceRefs, [
742
+ "semantic_meaning_candidates",
743
+ candidateIndex,
744
+ "deterministic_candidate",
745
+ "source_evidence_refs",
746
+ refIndex,
747
+ ], "semantic_meaning_candidates[].deterministic_candidate.source_evidence_refs[]");
748
+ });
749
+ candidate.ai_candidate.source_evidence_refs.forEach((ref, refIndex) => {
750
+ addMissingRefIssue(ctx, ref, sourceEvidenceRefs, [
751
+ "semantic_meaning_candidates",
752
+ candidateIndex,
753
+ "ai_candidate",
754
+ "source_evidence_refs",
755
+ refIndex,
756
+ ], "semantic_meaning_candidates[].ai_candidate.source_evidence_refs[]");
757
+ });
758
+ addMissingRefIssue(ctx, candidate.ai_candidate.ai_inference_evidence_ref, aiInferenceRefs, [
759
+ "semantic_meaning_candidates",
760
+ candidateIndex,
761
+ "ai_candidate",
762
+ "ai_inference_evidence_ref",
763
+ ], "semantic_meaning_candidates[].ai_candidate.ai_inference_evidence_ref");
764
+ addMissingRefIssue(ctx, candidate.selection_ai_inference_evidence_ref, aiInferenceRefs, [
765
+ "semantic_meaning_candidates",
766
+ candidateIndex,
767
+ "selection_ai_inference_evidence_ref",
768
+ ], "semantic_meaning_candidates[].selection_ai_inference_evidence_ref");
769
+ });
770
+ });
771
+
772
+ return {
773
+ semanticSnapshotRequestSchema,
774
+ };
775
+ })();
776
+
777
+ const schemaPackage = {
778
+ clueInitToolRequestSchema: toolingSchemas.clueInitToolRequestSchema,
779
+ clueInitToolReportSchema: toolingSchemas.clueInitToolReportSchema,
780
+ semanticSnapshotRequestSchema: semanticSchemas.semanticSnapshotRequestSchema,
781
+ };
782
+
783
+ module.exports = schemaPackage;
784
+ module.exports.default = schemaPackage;