@sigloch/contracts 0.7.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 (44) hide show
  1. package/LICENSE +21 -0
  2. package/dist/harness/index.d.ts +185 -0
  3. package/dist/harness/index.js +185 -0
  4. package/dist/index.d.ts +13 -0
  5. package/dist/index.js +14 -0
  6. package/dist/se/ao-rules.d.ts +59 -0
  7. package/dist/se/ao-rules.js +341 -0
  8. package/dist/se/conformance-rules.d.ts +64 -0
  9. package/dist/se/conformance-rules.js +364 -0
  10. package/dist/se/cr-quality-rules.d.ts +8 -0
  11. package/dist/se/cr-quality-rules.js +141 -0
  12. package/dist/se/evaluate-all.d.ts +17 -0
  13. package/dist/se/evaluate-all.js +50 -0
  14. package/dist/se/fchain-quality-rules.d.ts +10 -0
  15. package/dist/se/fchain-quality-rules.js +105 -0
  16. package/dist/se/fmea-rules.d.ts +17 -0
  17. package/dist/se/fmea-rules.js +137 -0
  18. package/dist/se/format-e-parser.d.ts +28 -0
  19. package/dist/se/format-e-parser.js +217 -0
  20. package/dist/se/index.d.ts +28 -0
  21. package/dist/se/index.js +28 -0
  22. package/dist/se/meta-model.d.ts +26 -0
  23. package/dist/se/meta-model.js +60 -0
  24. package/dist/se/metric-rules.d.ts +45 -0
  25. package/dist/se/metric-rules.js +208 -0
  26. package/dist/se/near-duplicate-rules.d.ts +44 -0
  27. package/dist/se/near-duplicate-rules.js +106 -0
  28. package/dist/se/ontology.d.ts +327 -0
  29. package/dist/se/ontology.js +216 -0
  30. package/dist/se/quality-rules.d.ts +28 -0
  31. package/dist/se/quality-rules.js +206 -0
  32. package/dist/se/readiness.d.ts +62 -0
  33. package/dist/se/readiness.js +79 -0
  34. package/dist/se/rules.d.ts +159 -0
  35. package/dist/se/rules.js +854 -0
  36. package/dist/se/schema-quality-rules.d.ts +11 -0
  37. package/dist/se/schema-quality-rules.js +73 -0
  38. package/dist/se/semantic-id.d.ts +30 -0
  39. package/dist/se/semantic-id.js +90 -0
  40. package/dist/se/uc-quality-rules.d.ts +13 -0
  41. package/dist/se/uc-quality-rules.js +123 -0
  42. package/dist/se/view-rules.d.ts +11 -0
  43. package/dist/se/view-rules.js +56 -0
  44. package/package.json +51 -0
@@ -0,0 +1,327 @@
1
+ /**
2
+ * SE Ontology as Zod (version: see ONTOLOGY_VERSION in ./index.ts).
3
+ * Element + Trace types per INCOSE/SysML 2.0.
4
+ * @sigloch/contracts/se — single source of truth for SE ontology schemas.
5
+ */
6
+ import { z } from 'zod/v4';
7
+ /**
8
+ * Element (Node) types — matches GraphEngine ontology.
9
+ * SYS=System, UC=UseCase, ACTOR=Actor, FCHAIN=FunctionChain,
10
+ * FUNC=Function, FLOW=DataFlow, REQ=Requirement, TEST=TestCase,
11
+ * MOD=Module, SCHEMA=Contract/Interface (Zod schemas).
12
+ */
13
+ export declare const ElementType: z.ZodEnum<{
14
+ SYS: "SYS";
15
+ UC: "UC";
16
+ ACTOR: "ACTOR";
17
+ FCHAIN: "FCHAIN";
18
+ FUNC: "FUNC";
19
+ FLOW: "FLOW";
20
+ REQ: "REQ";
21
+ TEST: "TEST";
22
+ MOD: "MOD";
23
+ SCHEMA: "SCHEMA";
24
+ SESSION: "SESSION";
25
+ CR: "CR";
26
+ MS: "MS";
27
+ }>;
28
+ export type ElementType = z.infer<typeof ElementType>;
29
+ /**
30
+ * Trace (Edge) types — matches GraphEngine ontology.
31
+ * compose=parent-child, io=data flow, satisfy=REQ satisfaction,
32
+ * verify=test coverage, allocate=function-to-module, relation=generic link.
33
+ */
34
+ export declare const TraceType: z.ZodEnum<{
35
+ compose: "compose";
36
+ io: "io";
37
+ satisfy: "satisfy";
38
+ verify: "verify";
39
+ allocate: "allocate";
40
+ relation: "relation";
41
+ produces: "produces";
42
+ }>;
43
+ export type TraceType = z.infer<typeof TraceType>;
44
+ /** REQ kind — 7 values aligned with SysML 2.0 + FMEA (CR-180). */
45
+ export declare const ReqKind: z.ZodEnum<{
46
+ functional: "functional";
47
+ "non-functional": "non-functional";
48
+ risk: "risk";
49
+ negative: "negative";
50
+ mitigation: "mitigation";
51
+ precondition: "precondition";
52
+ postcondition: "postcondition";
53
+ }>;
54
+ export type ReqKind = z.infer<typeof ReqKind>;
55
+ export declare const AsilLevel: z.ZodEnum<{
56
+ QM: "QM";
57
+ A: "A";
58
+ B: "B";
59
+ C: "C";
60
+ D: "D";
61
+ }>;
62
+ export type AsilLevel = z.infer<typeof AsilLevel>;
63
+ /** INCOSE TIAD verification method (only relevant for type=TEST). */
64
+ export declare const VerificationMethod: z.ZodEnum<{
65
+ test: "test";
66
+ inspection: "inspection";
67
+ analysis: "analysis";
68
+ demonstration: "demonstration";
69
+ }>;
70
+ export type VerificationMethod = z.infer<typeof VerificationMethod>;
71
+ /** Test execution result (only relevant for type=TEST). */
72
+ export declare const TestResult: z.ZodEnum<{
73
+ passed: "passed";
74
+ failed: "failed";
75
+ skipped: "skipped";
76
+ pending: "pending";
77
+ }>;
78
+ export type TestResult = z.infer<typeof TestResult>;
79
+ /**
80
+ * A repo-relative source path (CR-GC-255, ontology bump 3.8.0) — the path format every
81
+ * `*Ref.file` binding must use, so a graph-supplied path can never resolve outside the
82
+ * repo root a consumer joins it onto.
83
+ *
84
+ * Pure Zod, deliberately NO `node:path`/`node:fs`: contracts stays I/O-free and
85
+ * browser-bundlable (CR-GC-253 §2). Rejected:
86
+ * - absolute POSIX (`/x`), home-relative (`~/x`), Windows drive (`C:/x`) and UNC (`\\srv`)
87
+ * - any `..` path segment (traversal)
88
+ * - backslashes (a `..\` escape must not slip past a POSIX-only segment check)
89
+ * - the empty string
90
+ * Accepted: `tests/foo.test.ts`, `src/a/b.ts`, `a..b/c.ts` (`..` only as a full segment).
91
+ */
92
+ export declare const RepoRelativePathSchema: z.ZodString;
93
+ export type RepoRelativePath = z.infer<typeof RepoRelativePathSchema>;
94
+ /**
95
+ * Runnable binding for a TEST element (CR-GC-134, ontology bump 3.4.0).
96
+ * Resolves a TEST node to the concrete artefact a runner can execute, enabling
97
+ * bottom-up selective test deduction (`graph_tests`): change → impacted TESTs →
98
+ * `testRef` → minimal selective run command.
99
+ * - `file` : test file path, e.g. `tests/foo.test.ts` (the runner target).
100
+ * - `case` : optional named case/`describe`/`it` block within the file.
101
+ * - `tool` : the runner, e.g. `vitest`, `playwright`, `pytest`.
102
+ * - `level` : optional level, e.g. `unit`, `integration`, `validation`.
103
+ * Stored under `OntologyElement.attributes.testRef` (additive, opt-in validation).
104
+ */
105
+ export declare const TestRefSchema: z.ZodObject<{
106
+ file: z.ZodString;
107
+ case: z.ZodOptional<z.ZodString>;
108
+ tool: z.ZodString;
109
+ level: z.ZodOptional<z.ZodString>;
110
+ }, z.core.$strip>;
111
+ export type TestRef = z.infer<typeof TestRefSchema>;
112
+ /**
113
+ * Code binding for a FUNC element (CR-GC-205 Item 5, ontology bump 3.6.0).
114
+ * Resolves a FUNC node to the concrete code symbol that realizes it, enabling
115
+ * graph<->code conformance: every non-concept/non-external FUNC must resolve to a
116
+ * real symbol in its allocated MOD's file, and (via the consumer's LSP-backed
117
+ * check) every cross-module-called symbol must itself be a FUNC node.
118
+ * - `file` : implementation file path, e.g. `src/harness.ts` (the symbol's home).
119
+ * - `symbol` : the exported symbol (function/method/class) name realizing the FUNC.
120
+ * - `lang` : optional language id (default `ts`) — selects the LSP/engine the
121
+ * conformance check drives, so the binding is language-agnostic.
122
+ * Stored under `OntologyElement.attributes.codeRef` (additive, opt-in validation).
123
+ */
124
+ export declare const CodeRefSchema: z.ZodObject<{
125
+ file: z.ZodString;
126
+ symbol: z.ZodString;
127
+ lang: z.ZodOptional<z.ZodString>;
128
+ }, z.core.$strip>;
129
+ export type CodeRef = z.infer<typeof CodeRefSchema>;
130
+ /**
131
+ * Binding of a SCHEMA node to the Zod schema that defines it (CR-211), analogous
132
+ * to CodeRefSchema for FUNC:
133
+ * - `file` : the source file declaring the Zod schema, e.g. `src/se/ontology.ts`.
134
+ * - `symbol` : the exported schema symbol, e.g. `CodeRefSchema`.
135
+ * - `lang` : optional language id (default `ts`).
136
+ * Stored under `OntologyElement.attributes.schemaRef`. The free-text `contract`
137
+ * attribute stays as a human description but is no longer the conformance basis:
138
+ * RC-03 resolves this binding to a declared export, RC-04 checks it is parsed at
139
+ * the modelled interface.
140
+ */
141
+ export declare const SchemaRefSchema: z.ZodObject<{
142
+ file: z.ZodString;
143
+ symbol: z.ZodString;
144
+ lang: z.ZodOptional<z.ZodString>;
145
+ }, z.core.$strip>;
146
+ export type SchemaRef = z.infer<typeof SchemaRefSchema>;
147
+ /**
148
+ * An element (node) in the SE ontology graph.
149
+ * `attributes` holds type-specific properties (e.g. FUNC.safety_relevant).
150
+ */
151
+ export declare const OntologyElement: z.ZodObject<{
152
+ id: z.ZodString;
153
+ type: z.ZodEnum<{
154
+ SYS: "SYS";
155
+ UC: "UC";
156
+ ACTOR: "ACTOR";
157
+ FCHAIN: "FCHAIN";
158
+ FUNC: "FUNC";
159
+ FLOW: "FLOW";
160
+ REQ: "REQ";
161
+ TEST: "TEST";
162
+ MOD: "MOD";
163
+ SCHEMA: "SCHEMA";
164
+ SESSION: "SESSION";
165
+ CR: "CR";
166
+ MS: "MS";
167
+ }>;
168
+ name: z.ZodString;
169
+ description: z.ZodString;
170
+ asil: z.ZodOptional<z.ZodEnum<{
171
+ QM: "QM";
172
+ A: "A";
173
+ B: "B";
174
+ C: "C";
175
+ D: "D";
176
+ }>>;
177
+ method: z.ZodOptional<z.ZodEnum<{
178
+ test: "test";
179
+ inspection: "inspection";
180
+ analysis: "analysis";
181
+ demonstration: "demonstration";
182
+ }>>;
183
+ kinds: z.ZodOptional<z.ZodArray<z.ZodEnum<{
184
+ functional: "functional";
185
+ "non-functional": "non-functional";
186
+ risk: "risk";
187
+ negative: "negative";
188
+ mitigation: "mitigation";
189
+ precondition: "precondition";
190
+ postcondition: "postcondition";
191
+ }>>>;
192
+ attributes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
193
+ status: z.ZodDefault<z.ZodEnum<{
194
+ draft: "draft";
195
+ reviewed: "reviewed";
196
+ open: "open";
197
+ done: "done";
198
+ }>>;
199
+ created_at: z.ZodString;
200
+ updated_at: z.ZodOptional<z.ZodString>;
201
+ }, z.core.$strip>;
202
+ export type OntologyElement = z.infer<typeof OntologyElement>;
203
+ /**
204
+ * A trace (edge) in the SE ontology graph.
205
+ * `label` provides semantic context for 'relation' edges (e.g. 'derives', 'depends-on').
206
+ */
207
+ /** Trace category: modeling traces are user-visible, audit traces are internal. */
208
+ export declare const TraceCategory: z.ZodEnum<{
209
+ modeling: "modeling";
210
+ audit: "audit";
211
+ }>;
212
+ export type TraceCategory = z.infer<typeof TraceCategory>;
213
+ export declare const Trace: z.ZodObject<{
214
+ source: z.ZodString;
215
+ target: z.ZodString;
216
+ type: z.ZodEnum<{
217
+ compose: "compose";
218
+ io: "io";
219
+ satisfy: "satisfy";
220
+ verify: "verify";
221
+ allocate: "allocate";
222
+ relation: "relation";
223
+ produces: "produces";
224
+ }>;
225
+ category: z.ZodOptional<z.ZodEnum<{
226
+ modeling: "modeling";
227
+ audit: "audit";
228
+ }>>;
229
+ label: z.ZodOptional<z.ZodString>;
230
+ weight: z.ZodDefault<z.ZodNumber>;
231
+ attributes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
232
+ created_at: z.ZodString;
233
+ verified_at: z.ZodOptional<z.ZodString>;
234
+ }, z.core.$strip>;
235
+ export type Trace = z.infer<typeof Trace>;
236
+ export declare const OntologyGraph: z.ZodObject<{
237
+ elements: z.ZodArray<z.ZodObject<{
238
+ id: z.ZodString;
239
+ type: z.ZodEnum<{
240
+ SYS: "SYS";
241
+ UC: "UC";
242
+ ACTOR: "ACTOR";
243
+ FCHAIN: "FCHAIN";
244
+ FUNC: "FUNC";
245
+ FLOW: "FLOW";
246
+ REQ: "REQ";
247
+ TEST: "TEST";
248
+ MOD: "MOD";
249
+ SCHEMA: "SCHEMA";
250
+ SESSION: "SESSION";
251
+ CR: "CR";
252
+ MS: "MS";
253
+ }>;
254
+ name: z.ZodString;
255
+ description: z.ZodString;
256
+ asil: z.ZodOptional<z.ZodEnum<{
257
+ QM: "QM";
258
+ A: "A";
259
+ B: "B";
260
+ C: "C";
261
+ D: "D";
262
+ }>>;
263
+ method: z.ZodOptional<z.ZodEnum<{
264
+ test: "test";
265
+ inspection: "inspection";
266
+ analysis: "analysis";
267
+ demonstration: "demonstration";
268
+ }>>;
269
+ kinds: z.ZodOptional<z.ZodArray<z.ZodEnum<{
270
+ functional: "functional";
271
+ "non-functional": "non-functional";
272
+ risk: "risk";
273
+ negative: "negative";
274
+ mitigation: "mitigation";
275
+ precondition: "precondition";
276
+ postcondition: "postcondition";
277
+ }>>>;
278
+ attributes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
279
+ status: z.ZodDefault<z.ZodEnum<{
280
+ draft: "draft";
281
+ reviewed: "reviewed";
282
+ open: "open";
283
+ done: "done";
284
+ }>>;
285
+ created_at: z.ZodString;
286
+ updated_at: z.ZodOptional<z.ZodString>;
287
+ }, z.core.$strip>>;
288
+ traces: z.ZodArray<z.ZodObject<{
289
+ source: z.ZodString;
290
+ target: z.ZodString;
291
+ type: z.ZodEnum<{
292
+ compose: "compose";
293
+ io: "io";
294
+ satisfy: "satisfy";
295
+ verify: "verify";
296
+ allocate: "allocate";
297
+ relation: "relation";
298
+ produces: "produces";
299
+ }>;
300
+ category: z.ZodOptional<z.ZodEnum<{
301
+ modeling: "modeling";
302
+ audit: "audit";
303
+ }>>;
304
+ label: z.ZodOptional<z.ZodString>;
305
+ weight: z.ZodDefault<z.ZodNumber>;
306
+ attributes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
307
+ created_at: z.ZodString;
308
+ verified_at: z.ZodOptional<z.ZodString>;
309
+ }, z.core.$strip>>;
310
+ }, z.core.$strip>;
311
+ export type OntologyGraph = z.infer<typeof OntologyGraph>;
312
+ /** Human-readable descriptions for each ElementType. */
313
+ export declare const ELEMENT_DESCRIPTIONS: Record<ElementType, string>;
314
+ /** Element types used in modeling (user-visible). Excludes audit types (SESSION, CR). */
315
+ export declare const MODELING_ELEMENT_TYPES: ElementType[];
316
+ export interface AttributeSpec {
317
+ key: string;
318
+ type: 'string' | 'number' | 'boolean' | 'enum' | 'object';
319
+ enumValues?: readonly string[];
320
+ description: string;
321
+ }
322
+ /**
323
+ * Documented attributes per ElementType.
324
+ * `attributes` is Record<string,unknown> on the schema level, but these are
325
+ * the prescribed keys that rules, views, and extractors rely on.
326
+ */
327
+ export declare const ELEMENT_ATTRIBUTES: Partial<Record<ElementType, AttributeSpec[]>>;
@@ -0,0 +1,216 @@
1
+ /**
2
+ * SE Ontology as Zod (version: see ONTOLOGY_VERSION in ./index.ts).
3
+ * Element + Trace types per INCOSE/SysML 2.0.
4
+ * @sigloch/contracts/se — single source of truth for SE ontology schemas.
5
+ */
6
+ import { z } from 'zod/v4';
7
+ /**
8
+ * Element (Node) types — matches GraphEngine ontology.
9
+ * SYS=System, UC=UseCase, ACTOR=Actor, FCHAIN=FunctionChain,
10
+ * FUNC=Function, FLOW=DataFlow, REQ=Requirement, TEST=TestCase,
11
+ * MOD=Module, SCHEMA=Contract/Interface (Zod schemas).
12
+ */
13
+ export const ElementType = z.enum([
14
+ 'SYS', 'UC', 'ACTOR', 'FCHAIN',
15
+ 'FUNC', 'FLOW', 'REQ', 'TEST',
16
+ 'MOD', 'SCHEMA', 'SESSION', 'CR',
17
+ 'MS',
18
+ ]);
19
+ /**
20
+ * Trace (Edge) types — matches GraphEngine ontology.
21
+ * compose=parent-child, io=data flow, satisfy=REQ satisfaction,
22
+ * verify=test coverage, allocate=function-to-module, relation=generic link.
23
+ */
24
+ export const TraceType = z.enum([
25
+ 'compose', 'io', 'satisfy', 'verify', 'allocate', 'relation', 'produces',
26
+ ]);
27
+ /** REQ kind — 7 values aligned with SysML 2.0 + FMEA (CR-180). */
28
+ export const ReqKind = z.enum([
29
+ 'functional', 'non-functional', 'risk', 'negative',
30
+ 'mitigation', 'precondition', 'postcondition',
31
+ ]);
32
+ export const AsilLevel = z.enum(['QM', 'A', 'B', 'C', 'D']);
33
+ /** INCOSE TIAD verification method (only relevant for type=TEST). */
34
+ export const VerificationMethod = z.enum(['test', 'inspection', 'analysis', 'demonstration']);
35
+ /** Test execution result (only relevant for type=TEST). */
36
+ export const TestResult = z.enum(['passed', 'failed', 'skipped', 'pending']);
37
+ /**
38
+ * A repo-relative source path (CR-GC-255, ontology bump 3.8.0) — the path format every
39
+ * `*Ref.file` binding must use, so a graph-supplied path can never resolve outside the
40
+ * repo root a consumer joins it onto.
41
+ *
42
+ * Pure Zod, deliberately NO `node:path`/`node:fs`: contracts stays I/O-free and
43
+ * browser-bundlable (CR-GC-253 §2). Rejected:
44
+ * - absolute POSIX (`/x`), home-relative (`~/x`), Windows drive (`C:/x`) and UNC (`\\srv`)
45
+ * - any `..` path segment (traversal)
46
+ * - backslashes (a `..\` escape must not slip past a POSIX-only segment check)
47
+ * - the empty string
48
+ * Accepted: `tests/foo.test.ts`, `src/a/b.ts`, `a..b/c.ts` (`..` only as a full segment).
49
+ */
50
+ export const RepoRelativePathSchema = z
51
+ .string()
52
+ .min(1, 'path must not be empty')
53
+ .refine((p) => !p.includes('\\'), { message: 'path must not contain backslashes (use POSIX separators)' })
54
+ .refine((p) => !p.startsWith('/') && !p.startsWith('~'), { message: 'path must be repo-relative, not absolute' })
55
+ .refine((p) => !/^[A-Za-z]:/.test(p), { message: 'path must be repo-relative, not a Windows drive path' })
56
+ .refine((p) => !p.split('/').includes('..'), { message: "path must not contain a '..' segment" });
57
+ /**
58
+ * Runnable binding for a TEST element (CR-GC-134, ontology bump 3.4.0).
59
+ * Resolves a TEST node to the concrete artefact a runner can execute, enabling
60
+ * bottom-up selective test deduction (`graph_tests`): change → impacted TESTs →
61
+ * `testRef` → minimal selective run command.
62
+ * - `file` : test file path, e.g. `tests/foo.test.ts` (the runner target).
63
+ * - `case` : optional named case/`describe`/`it` block within the file.
64
+ * - `tool` : the runner, e.g. `vitest`, `playwright`, `pytest`.
65
+ * - `level` : optional level, e.g. `unit`, `integration`, `validation`.
66
+ * Stored under `OntologyElement.attributes.testRef` (additive, opt-in validation).
67
+ */
68
+ export const TestRefSchema = z.object({
69
+ file: RepoRelativePathSchema,
70
+ case: z.string().optional(),
71
+ tool: z.string(),
72
+ level: z.string().optional(),
73
+ });
74
+ /**
75
+ * Code binding for a FUNC element (CR-GC-205 Item 5, ontology bump 3.6.0).
76
+ * Resolves a FUNC node to the concrete code symbol that realizes it, enabling
77
+ * graph<->code conformance: every non-concept/non-external FUNC must resolve to a
78
+ * real symbol in its allocated MOD's file, and (via the consumer's LSP-backed
79
+ * check) every cross-module-called symbol must itself be a FUNC node.
80
+ * - `file` : implementation file path, e.g. `src/harness.ts` (the symbol's home).
81
+ * - `symbol` : the exported symbol (function/method/class) name realizing the FUNC.
82
+ * - `lang` : optional language id (default `ts`) — selects the LSP/engine the
83
+ * conformance check drives, so the binding is language-agnostic.
84
+ * Stored under `OntologyElement.attributes.codeRef` (additive, opt-in validation).
85
+ */
86
+ export const CodeRefSchema = z.object({
87
+ file: RepoRelativePathSchema,
88
+ symbol: z.string(),
89
+ lang: z.string().optional(),
90
+ });
91
+ /**
92
+ * Binding of a SCHEMA node to the Zod schema that defines it (CR-211), analogous
93
+ * to CodeRefSchema for FUNC:
94
+ * - `file` : the source file declaring the Zod schema, e.g. `src/se/ontology.ts`.
95
+ * - `symbol` : the exported schema symbol, e.g. `CodeRefSchema`.
96
+ * - `lang` : optional language id (default `ts`).
97
+ * Stored under `OntologyElement.attributes.schemaRef`. The free-text `contract`
98
+ * attribute stays as a human description but is no longer the conformance basis:
99
+ * RC-03 resolves this binding to a declared export, RC-04 checks it is parsed at
100
+ * the modelled interface.
101
+ */
102
+ export const SchemaRefSchema = z.object({
103
+ file: RepoRelativePathSchema,
104
+ symbol: z.string(),
105
+ lang: z.string().optional(),
106
+ });
107
+ /**
108
+ * An element (node) in the SE ontology graph.
109
+ * `attributes` holds type-specific properties (e.g. FUNC.safety_relevant).
110
+ */
111
+ export const OntologyElement = z.object({
112
+ id: z.string(),
113
+ type: ElementType,
114
+ name: z.string(),
115
+ description: z.string(),
116
+ asil: AsilLevel.optional(),
117
+ /** INCOSE TIAD verification method — only for TEST elements (CR-057). */
118
+ method: VerificationMethod.optional(),
119
+ /** REQ kinds: multi-valued classification (CR-180). Only for REQ elements. */
120
+ kinds: z.array(ReqKind).optional(),
121
+ attributes: z.record(z.string(), z.unknown()).optional(),
122
+ status: z.enum(['draft', 'reviewed', 'open', 'done']).default('draft'),
123
+ created_at: z.string(),
124
+ updated_at: z.string().optional(),
125
+ });
126
+ /**
127
+ * A trace (edge) in the SE ontology graph.
128
+ * `label` provides semantic context for 'relation' edges (e.g. 'derives', 'depends-on').
129
+ */
130
+ /** Trace category: modeling traces are user-visible, audit traces are internal. */
131
+ export const TraceCategory = z.enum(['modeling', 'audit']);
132
+ export const Trace = z.object({
133
+ source: z.string(),
134
+ target: z.string(),
135
+ type: TraceType,
136
+ /** 'modeling' (default, user-visible) or 'audit' (internal, e.g. produces traces). Absent = modeling. */
137
+ category: TraceCategory.optional(),
138
+ label: z.string().optional(),
139
+ weight: z.number().default(1),
140
+ attributes: z.record(z.string(), z.unknown()).optional(),
141
+ created_at: z.string(),
142
+ verified_at: z.string().optional(),
143
+ });
144
+ export const OntologyGraph = z.object({
145
+ elements: z.array(OntologyElement),
146
+ traces: z.array(Trace),
147
+ });
148
+ // ---------------------------------------------------------------------------
149
+ // Ontology metadata — single source of truth for plugin generators (CR-190)
150
+ // ---------------------------------------------------------------------------
151
+ /** Human-readable descriptions for each ElementType. */
152
+ export const ELEMENT_DESCRIPTIONS = {
153
+ SYS: 'System (Wurzel)',
154
+ UC: 'Use Case',
155
+ ACTOR: 'Akteur (Mensch, System, Geraet)',
156
+ FCHAIN: 'Funktionskette (UC->FN Verknuepfung)',
157
+ FUNC: 'Funktion (implementierbare Einheit)',
158
+ FLOW: 'Datenfluss / Zustandsuebergang',
159
+ REQ: 'Requirement (funktional oder nicht-funktional)',
160
+ TEST: 'Testfall',
161
+ MOD: 'Modul (SW-Paket oder HW-Baugruppe)',
162
+ SCHEMA: 'Datenschema (Zod)',
163
+ SESSION: 'Audit-Session',
164
+ CR: 'Change Request',
165
+ MS: 'Meilenstein',
166
+ };
167
+ /** Element types used in modeling (user-visible). Excludes audit types (SESSION, CR). */
168
+ export const MODELING_ELEMENT_TYPES = ElementType.options.filter(t => t !== 'SESSION' && t !== 'CR');
169
+ /**
170
+ * Documented attributes per ElementType.
171
+ * `attributes` is Record<string,unknown> on the schema level, but these are
172
+ * the prescribed keys that rules, views, and extractors rely on.
173
+ */
174
+ export const ELEMENT_ATTRIBUTES = {
175
+ TEST: [
176
+ { key: 'testResult', type: 'enum', enumValues: TestResult.options, description: 'Test execution outcome' },
177
+ { key: 'sourceFile', type: 'string', description: 'Test file path (e.g. tests/foo.test.ts)' },
178
+ { key: 'testRef', type: 'object', description: 'Runnable binding {file, case?, tool, level?} — see TestRefSchema (CR-GC-134)' },
179
+ { key: 'concept', type: 'boolean', description: 'Concept-only TEST: no run artifact yet; exempt from the R-19 testRef-binding requirement (CR-GC-205)' },
180
+ ],
181
+ REQ: [
182
+ { key: 'severity', type: 'number', description: 'FMEA severity (1-10)' },
183
+ { key: 'occurrence', type: 'number', description: 'FMEA occurrence (1-10)' },
184
+ { key: 'detection', type: 'number', description: 'FMEA detection (1-10)' },
185
+ ],
186
+ FUNC: [
187
+ { key: 'safety_relevant', type: 'boolean', description: 'Function is safety-relevant' },
188
+ { key: 'timingBudgetMs', type: 'number', description: 'NFR timing budget in ms' },
189
+ { key: 'measuredMs', type: 'number', description: 'Measured execution time in ms' },
190
+ { key: 'sourceFile', type: 'string', description: 'Implementation source file' },
191
+ { key: 'codeRef', type: 'object', description: 'Code binding {file, symbol, lang?} — the symbol that realizes this FUNC; see CodeRefSchema (CR-GC-205)' },
192
+ { key: 'external', type: 'boolean', description: 'Externally-realized FUNC (e.g. a renderer in another package): exempt from the R-20 codeRef-binding requirement (CR-GC-205)' },
193
+ { key: 'concept', type: 'boolean', description: 'Concept-only FUNC: specified, no implementation yet; exempt from R-20 (CR-GC-205)' },
194
+ ],
195
+ UC: [
196
+ { key: 'operatingMode', type: 'string', description: 'ConOps operating mode' },
197
+ ],
198
+ CR: [
199
+ { key: 'status', type: 'enum', enumValues: ['open', 'done'], description: 'CR completion status' },
200
+ { key: 'rationale', type: 'string', description: 'Reason for the change' },
201
+ { key: 'spike', type: 'boolean', description: 'CR is a spike/exploration' },
202
+ ],
203
+ FLOW: [
204
+ { key: 'protocol', type: 'string', description: 'ICD protocol (e.g. REST, gRPC)' },
205
+ { key: 'qos', type: 'string', description: 'Quality of Service level' },
206
+ ],
207
+ MOD: [
208
+ { key: 'path', type: 'string', description: 'Source file or glob the module owns, e.g. src/harness.ts — anchors the MOD<->file mapping for graph<->code conformance (CR-GC-205)' },
209
+ ],
210
+ SCHEMA: [
211
+ { key: 'contract', type: 'string', description: 'Free-text contract description, e.g. "@sigloch/contracts LiveUpdateEventSchema" — human hint only, not the conformance basis (CR-211)' },
212
+ { key: 'schemaRef', type: 'object', description: 'Schema binding {file, symbol, lang?} — the Zod export defining this SCHEMA; see SchemaRefSchema (CR-211)' },
213
+ { key: 'external', type: 'boolean', description: 'Externally-defined SCHEMA (e.g. a foreign-API contract): exempt from the schemaRef-presence requirement (CR-211)' },
214
+ { key: 'concept', type: 'boolean', description: 'Concept-only SCHEMA: modelled, no Zod export yet; exempt from the schemaRef-presence requirement (CR-211)' },
215
+ ],
216
+ };
@@ -0,0 +1,28 @@
1
+ /**
2
+ * BQ-01 through BQ-07 — Base Quality rules for artefact descriptions.
3
+ * Complement the structural V3 rules (R-01..R-12) with content-level checks
4
+ * on REQ element descriptions (weasel words, verifiability, atomicity, etc.).
5
+ */
6
+ import type { OntologyGraph } from './ontology.js';
7
+ import type { RuleDefinition, RuleViolation } from './rules.js';
8
+ export declare function bq01Unambiguous(graph: OntologyGraph): RuleViolation[];
9
+ export declare function bq02Verifiable(graph: OntologyGraph): RuleViolation[];
10
+ /**
11
+ * Inject a pre-computed similarity matrix for BQ-04.
12
+ * Call this before evaluateBQRules() when embeddings are available.
13
+ * Pass null to clear.
14
+ */
15
+ export declare function setBQ04SimilarityMatrix(data: {
16
+ reqIds: string[];
17
+ matrix: number[][];
18
+ } | null): void;
19
+ /**
20
+ * BQ-04 checks for duplicate / near-duplicate requirements using
21
+ * pre-computed embedding similarity. Returns [] when no matrix is set.
22
+ */
23
+ export declare function bq04Necessary(graph: OntologyGraph): RuleViolation[];
24
+ export declare function bq06Conforming(graph: OntologyGraph): RuleViolation[];
25
+ export declare function bq07Complete(graph: OntologyGraph): RuleViolation[];
26
+ export declare const BQ_RULES: RuleDefinition[];
27
+ /** Run all BQ rules against a graph, returning combined violations. */
28
+ export declare function evaluateBQRules(graph: OntologyGraph): RuleViolation[];