sysprom 1.14.0 → 1.15.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.
@@ -0,0 +1,375 @@
1
+ import * as z from "zod";
2
+ /**
3
+ * A derived relationship inferred from transitive closure or composition.
4
+ */
5
+ declare const DerivedRelationship: z.ZodObject<{
6
+ from: z.ZodString;
7
+ to: z.ZodString;
8
+ type: z.ZodString;
9
+ derivedFrom: z.ZodArray<z.ZodObject<{
10
+ from: z.ZodString;
11
+ to: z.ZodString;
12
+ type: z.ZodString;
13
+ }, z.core.$strip>>;
14
+ derivationType: z.ZodEnum<{
15
+ transitive: "transitive";
16
+ composite: "composite";
17
+ inverse: "inverse";
18
+ }>;
19
+ }, z.core.$strip>;
20
+ /** A derived relationship inferred from the graph. */
21
+ export type DerivedRelationship = z.infer<typeof DerivedRelationship>;
22
+ /**
23
+ * Output schema for inferDerivedOp.
24
+ */
25
+ declare const DerivedOutput: z.ZodObject<{
26
+ derivedRelationships: z.ZodArray<z.ZodObject<{
27
+ from: z.ZodString;
28
+ to: z.ZodString;
29
+ type: z.ZodString;
30
+ derivedFrom: z.ZodArray<z.ZodObject<{
31
+ from: z.ZodString;
32
+ to: z.ZodString;
33
+ type: z.ZodString;
34
+ }, z.core.$strip>>;
35
+ derivationType: z.ZodEnum<{
36
+ transitive: "transitive";
37
+ composite: "composite";
38
+ inverse: "inverse";
39
+ }>;
40
+ }, z.core.$strip>>;
41
+ summary: z.ZodObject<{
42
+ transitive: z.ZodNumber;
43
+ composite: z.ZodNumber;
44
+ inverse: z.ZodNumber;
45
+ total: z.ZodNumber;
46
+ }, z.core.$strip>;
47
+ }, z.core.$strip>;
48
+ /** Output of derived relationships inference operation. */
49
+ export type DerivedOutput = z.infer<typeof DerivedOutput>;
50
+ /**
51
+ * Infer derived relationships from the graph structure.
52
+ *
53
+ * Computes transitive closure for hierarchical relationships, derives
54
+ * inverse relationships, and identifies composite patterns.
55
+ */
56
+ export declare const inferDerivedOp: import("./define-operation.js").DefinedOperation<z.ZodObject<{
57
+ doc: z.ZodObject<{
58
+ $schema: z.ZodOptional<z.ZodString>;
59
+ metadata: z.ZodOptional<z.ZodObject<{
60
+ title: z.ZodOptional<z.ZodString>;
61
+ doc_type: z.ZodOptional<z.ZodString>;
62
+ scope: z.ZodOptional<z.ZodString>;
63
+ status: z.ZodOptional<z.ZodString>;
64
+ version: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodInt]>>;
65
+ }, z.core.$loose> & {
66
+ is(value: unknown): value is {
67
+ [x: string]: unknown;
68
+ title?: string | undefined;
69
+ doc_type?: string | undefined;
70
+ scope?: string | undefined;
71
+ status?: string | undefined;
72
+ version?: string | number | undefined;
73
+ };
74
+ }>;
75
+ nodes: z.ZodArray<z.ZodObject<{
76
+ id: z.ZodString;
77
+ type: z.ZodEnum<{
78
+ intent: "intent";
79
+ concept: "concept";
80
+ capability: "capability";
81
+ element: "element";
82
+ realisation: "realisation";
83
+ invariant: "invariant";
84
+ principle: "principle";
85
+ policy: "policy";
86
+ protocol: "protocol";
87
+ stage: "stage";
88
+ role: "role";
89
+ gate: "gate";
90
+ mode: "mode";
91
+ artefact: "artefact";
92
+ artefact_flow: "artefact_flow";
93
+ decision: "decision";
94
+ change: "change";
95
+ view: "view";
96
+ milestone: "milestone";
97
+ version: "version";
98
+ }> & {
99
+ is(value: unknown): value is "intent" | "concept" | "capability" | "element" | "realisation" | "invariant" | "principle" | "policy" | "protocol" | "stage" | "role" | "gate" | "mode" | "artefact" | "artefact_flow" | "decision" | "change" | "view" | "milestone" | "version";
100
+ };
101
+ name: z.ZodString;
102
+ description: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]> & {
103
+ is(value: unknown): value is string | string[];
104
+ }>;
105
+ status: z.ZodOptional<z.ZodEnum<{
106
+ deprecated: "deprecated";
107
+ proposed: "proposed";
108
+ accepted: "accepted";
109
+ active: "active";
110
+ implemented: "implemented";
111
+ adopted: "adopted";
112
+ defined: "defined";
113
+ introduced: "introduced";
114
+ in_progress: "in_progress";
115
+ complete: "complete";
116
+ consolidated: "consolidated";
117
+ experimental: "experimental";
118
+ retired: "retired";
119
+ superseded: "superseded";
120
+ abandoned: "abandoned";
121
+ deferred: "deferred";
122
+ }> & {
123
+ is(value: unknown): value is "deprecated" | "proposed" | "accepted" | "active" | "implemented" | "adopted" | "defined" | "introduced" | "in_progress" | "complete" | "consolidated" | "experimental" | "retired" | "superseded" | "abandoned" | "deferred";
124
+ }>;
125
+ lifecycle: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodBoolean, z.ZodString]>>>;
126
+ context: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]> & {
127
+ is(value: unknown): value is string | string[];
128
+ }>;
129
+ options: z.ZodOptional<z.ZodArray<z.ZodObject<{
130
+ id: z.ZodString;
131
+ description: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]> & {
132
+ is(value: unknown): value is string | string[];
133
+ };
134
+ }, z.core.$loose> & {
135
+ is(value: unknown): value is {
136
+ [x: string]: unknown;
137
+ id: string;
138
+ description: string | string[];
139
+ };
140
+ }>>;
141
+ selected: z.ZodOptional<z.ZodString>;
142
+ rationale: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]> & {
143
+ is(value: unknown): value is string | string[];
144
+ }>;
145
+ scope: z.ZodOptional<z.ZodArray<z.ZodString>>;
146
+ operations: z.ZodOptional<z.ZodArray<z.ZodObject<{
147
+ type: z.ZodEnum<{
148
+ link: "link";
149
+ add: "add";
150
+ update: "update";
151
+ remove: "remove";
152
+ }>;
153
+ target: z.ZodOptional<z.ZodString>;
154
+ description: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]> & {
155
+ is(value: unknown): value is string | string[];
156
+ }>;
157
+ }, z.core.$loose> & {
158
+ is(value: unknown): value is {
159
+ [x: string]: unknown;
160
+ type: "link" | "add" | "update" | "remove";
161
+ target?: string | undefined;
162
+ description?: string | string[] | undefined;
163
+ };
164
+ }>>;
165
+ plan: z.ZodOptional<z.ZodArray<z.ZodObject<{
166
+ description: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]> & {
167
+ is(value: unknown): value is string | string[];
168
+ };
169
+ done: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
170
+ }, z.core.$loose> & {
171
+ is(value: unknown): value is {
172
+ [x: string]: unknown;
173
+ description: string | string[];
174
+ done?: boolean | undefined;
175
+ };
176
+ }>>;
177
+ propagation: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodBoolean>>;
178
+ includes: z.ZodOptional<z.ZodArray<z.ZodString>>;
179
+ input: z.ZodOptional<z.ZodString>;
180
+ output: z.ZodOptional<z.ZodString>;
181
+ external_references: z.ZodOptional<z.ZodArray<z.ZodObject<{
182
+ role: z.ZodEnum<{
183
+ output: "output";
184
+ input: "input";
185
+ context: "context";
186
+ evidence: "evidence";
187
+ source: "source";
188
+ standard: "standard";
189
+ prior_art: "prior_art";
190
+ }> & {
191
+ is(value: unknown): value is "output" | "input" | "context" | "evidence" | "source" | "standard" | "prior_art";
192
+ };
193
+ identifier: z.ZodString;
194
+ description: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]> & {
195
+ is(value: unknown): value is string | string[];
196
+ }>;
197
+ node_id: z.ZodOptional<z.ZodString>;
198
+ internalised: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]> & {
199
+ is(value: unknown): value is string | string[];
200
+ }>;
201
+ }, z.core.$strip> & {
202
+ is(value: unknown): value is {
203
+ role: "output" | "input" | "context" | "evidence" | "source" | "standard" | "prior_art";
204
+ identifier: string;
205
+ description?: string | string[] | undefined;
206
+ node_id?: string | undefined;
207
+ internalised?: string | string[] | undefined;
208
+ };
209
+ }>>;
210
+ readonly subsystem: z.ZodOptional<z.ZodObject</*elided*/ any, z.core.$strip>>;
211
+ }, z.core.$loose>>;
212
+ relationships: z.ZodOptional<z.ZodArray<z.ZodObject<{
213
+ from: z.ZodString;
214
+ to: z.ZodString;
215
+ type: z.ZodEnum<{
216
+ refines: "refines";
217
+ realises: "realises";
218
+ implements: "implements";
219
+ depends_on: "depends_on";
220
+ constrained_by: "constrained_by";
221
+ affects: "affects";
222
+ supersedes: "supersedes";
223
+ must_preserve: "must_preserve";
224
+ performs: "performs";
225
+ part_of: "part_of";
226
+ precedes: "precedes";
227
+ must_follow: "must_follow";
228
+ blocks: "blocks";
229
+ routes_to: "routes_to";
230
+ governed_by: "governed_by";
231
+ modifies: "modifies";
232
+ triggered_by: "triggered_by";
233
+ applies_to: "applies_to";
234
+ produces: "produces";
235
+ consumes: "consumes";
236
+ transforms_into: "transforms_into";
237
+ selects: "selects";
238
+ requires: "requires";
239
+ disables: "disables";
240
+ }> & {
241
+ is(value: unknown): value is "refines" | "realises" | "implements" | "depends_on" | "constrained_by" | "affects" | "supersedes" | "must_preserve" | "performs" | "part_of" | "precedes" | "must_follow" | "blocks" | "routes_to" | "governed_by" | "modifies" | "triggered_by" | "applies_to" | "produces" | "consumes" | "transforms_into" | "selects" | "requires" | "disables";
242
+ };
243
+ description: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]> & {
244
+ is(value: unknown): value is string | string[];
245
+ }>;
246
+ }, z.core.$loose> & {
247
+ is(value: unknown): value is {
248
+ [x: string]: unknown;
249
+ from: string;
250
+ to: string;
251
+ type: "refines" | "realises" | "implements" | "depends_on" | "constrained_by" | "affects" | "supersedes" | "must_preserve" | "performs" | "part_of" | "precedes" | "must_follow" | "blocks" | "routes_to" | "governed_by" | "modifies" | "triggered_by" | "applies_to" | "produces" | "consumes" | "transforms_into" | "selects" | "requires" | "disables";
252
+ description?: string | string[] | undefined;
253
+ };
254
+ }>>;
255
+ external_references: z.ZodOptional<z.ZodArray<z.ZodObject<{
256
+ role: z.ZodEnum<{
257
+ output: "output";
258
+ input: "input";
259
+ context: "context";
260
+ evidence: "evidence";
261
+ source: "source";
262
+ standard: "standard";
263
+ prior_art: "prior_art";
264
+ }> & {
265
+ is(value: unknown): value is "output" | "input" | "context" | "evidence" | "source" | "standard" | "prior_art";
266
+ };
267
+ identifier: z.ZodString;
268
+ description: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]> & {
269
+ is(value: unknown): value is string | string[];
270
+ }>;
271
+ node_id: z.ZodOptional<z.ZodString>;
272
+ internalised: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]> & {
273
+ is(value: unknown): value is string | string[];
274
+ }>;
275
+ }, z.core.$strip> & {
276
+ is(value: unknown): value is {
277
+ role: "output" | "input" | "context" | "evidence" | "source" | "standard" | "prior_art";
278
+ identifier: string;
279
+ description?: string | string[] | undefined;
280
+ node_id?: string | undefined;
281
+ internalised?: string | string[] | undefined;
282
+ };
283
+ }>>;
284
+ }, z.core.$strip> & {
285
+ is(value: unknown): value is {
286
+ nodes: {
287
+ [x: string]: unknown;
288
+ id: string;
289
+ type: "intent" | "concept" | "capability" | "element" | "realisation" | "invariant" | "principle" | "policy" | "protocol" | "stage" | "role" | "gate" | "mode" | "artefact" | "artefact_flow" | "decision" | "change" | "view" | "milestone" | "version";
290
+ name: string;
291
+ description?: string | string[] | undefined;
292
+ status?: "deprecated" | "proposed" | "accepted" | "active" | "implemented" | "adopted" | "defined" | "introduced" | "in_progress" | "complete" | "consolidated" | "experimental" | "retired" | "superseded" | "abandoned" | "deferred" | undefined;
293
+ lifecycle?: Record<string, string | boolean> | undefined;
294
+ context?: string | string[] | undefined;
295
+ options?: {
296
+ [x: string]: unknown;
297
+ id: string;
298
+ description: string | string[];
299
+ }[] | undefined;
300
+ selected?: string | undefined;
301
+ rationale?: string | string[] | undefined;
302
+ scope?: string[] | undefined;
303
+ operations?: {
304
+ [x: string]: unknown;
305
+ type: "link" | "add" | "update" | "remove";
306
+ target?: string | undefined;
307
+ description?: string | string[] | undefined;
308
+ }[] | undefined;
309
+ plan?: {
310
+ [x: string]: unknown;
311
+ description: string | string[];
312
+ done?: boolean | undefined;
313
+ }[] | undefined;
314
+ propagation?: Record<string, boolean> | undefined;
315
+ includes?: string[] | undefined;
316
+ input?: string | undefined;
317
+ output?: string | undefined;
318
+ external_references?: {
319
+ role: "output" | "input" | "context" | "evidence" | "source" | "standard" | "prior_art";
320
+ identifier: string;
321
+ description?: string | string[] | undefined;
322
+ node_id?: string | undefined;
323
+ internalised?: string | string[] | undefined;
324
+ }[] | undefined;
325
+ subsystem?: /*elided*/ any | undefined;
326
+ }[];
327
+ $schema?: string | undefined;
328
+ metadata?: {
329
+ [x: string]: unknown;
330
+ title?: string | undefined;
331
+ doc_type?: string | undefined;
332
+ scope?: string | undefined;
333
+ status?: string | undefined;
334
+ version?: string | number | undefined;
335
+ } | undefined;
336
+ relationships?: {
337
+ [x: string]: unknown;
338
+ from: string;
339
+ to: string;
340
+ type: "refines" | "realises" | "implements" | "depends_on" | "constrained_by" | "affects" | "supersedes" | "must_preserve" | "performs" | "part_of" | "precedes" | "must_follow" | "blocks" | "routes_to" | "governed_by" | "modifies" | "triggered_by" | "applies_to" | "produces" | "consumes" | "transforms_into" | "selects" | "requires" | "disables";
341
+ description?: string | string[] | undefined;
342
+ }[] | undefined;
343
+ external_references?: {
344
+ role: "output" | "input" | "context" | "evidence" | "source" | "standard" | "prior_art";
345
+ identifier: string;
346
+ description?: string | string[] | undefined;
347
+ node_id?: string | undefined;
348
+ internalised?: string | string[] | undefined;
349
+ }[] | undefined;
350
+ };
351
+ };
352
+ }, z.core.$strip>, z.ZodObject<{
353
+ derivedRelationships: z.ZodArray<z.ZodObject<{
354
+ from: z.ZodString;
355
+ to: z.ZodString;
356
+ type: z.ZodString;
357
+ derivedFrom: z.ZodArray<z.ZodObject<{
358
+ from: z.ZodString;
359
+ to: z.ZodString;
360
+ type: z.ZodString;
361
+ }, z.core.$strip>>;
362
+ derivationType: z.ZodEnum<{
363
+ transitive: "transitive";
364
+ composite: "composite";
365
+ inverse: "inverse";
366
+ }>;
367
+ }, z.core.$strip>>;
368
+ summary: z.ZodObject<{
369
+ transitive: z.ZodNumber;
370
+ composite: z.ZodNumber;
371
+ inverse: z.ZodNumber;
372
+ total: z.ZodNumber;
373
+ }, z.core.$strip>;
374
+ }, z.core.$strip>>;
375
+ export {};
@@ -0,0 +1,158 @@
1
+ import * as z from "zod";
2
+ import { defineOperation } from "./define-operation.js";
3
+ import { SysProMDocument } from "../schema.js";
4
+ /**
5
+ * A derived relationship inferred from transitive closure or composition.
6
+ */
7
+ const DerivedRelationship = z.object({
8
+ from: z.string(),
9
+ to: z.string(),
10
+ type: z.string(),
11
+ derivedFrom: z.array(z.object({
12
+ from: z.string(),
13
+ to: z.string(),
14
+ type: z.string(),
15
+ })),
16
+ derivationType: z.enum(["transitive", "composite", "inverse"]),
17
+ });
18
+ /**
19
+ * Output schema for inferDerivedOp.
20
+ */
21
+ const DerivedOutput = z.object({
22
+ derivedRelationships: z.array(DerivedRelationship),
23
+ summary: z.object({
24
+ transitive: z.number(),
25
+ composite: z.number(),
26
+ inverse: z.number(),
27
+ total: z.number(),
28
+ }),
29
+ });
30
+ /**
31
+ * Relationship types that support transitive derivation.
32
+ */
33
+ const TRANSITIVE_RELATIONSHIPS = {
34
+ depends_on: "depends_on",
35
+ refines: "refines",
36
+ part_of: "part_of",
37
+ precedes: "precedes",
38
+ };
39
+ /**
40
+ * Relationship types that have inverse relationships.
41
+ */
42
+ const INVERSE_RELATIONSHIPS = {
43
+ depends_on: "enables",
44
+ precedes: "follows",
45
+ refines: "refined_by",
46
+ realises: "realised_by",
47
+ implements: "implemented_by",
48
+ };
49
+ /**
50
+ * Infer derived relationships from the graph structure.
51
+ *
52
+ * Computes transitive closure for hierarchical relationships, derives
53
+ * inverse relationships, and identifies composite patterns.
54
+ */
55
+ export const inferDerivedOp = defineOperation({
56
+ name: "infer-derived",
57
+ description: "Infer derived relationships from transitive closure, inverses, and composites",
58
+ input: z.object({
59
+ doc: SysProMDocument,
60
+ }),
61
+ output: DerivedOutput,
62
+ fn: (input) => {
63
+ const derived = [];
64
+ const existingKeys = new Set((input.doc.relationships ?? []).map((r) => `${r.from}:${r.type}:${r.to}`));
65
+ const derivedKeys = new Set();
66
+ // Helper to add derived relationship if not already existing
67
+ const addDerived = (from, to, type, derivedFrom, derivationType) => {
68
+ const key = `${from}:${type}:${to}`;
69
+ if (existingKeys.has(key) || derivedKeys.has(key))
70
+ return;
71
+ derivedKeys.add(key);
72
+ derived.push({ from, to, type, derivedFrom, derivationType });
73
+ };
74
+ // 1. Transitive relationships - compute full transitive closure with path tracking
75
+ for (const [relType, derivedType] of Object.entries(TRANSITIVE_RELATIONSHIPS)) {
76
+ const rels = (input.doc.relationships ?? []).filter((r) => r.type === relType);
77
+ // Build adjacency list
78
+ const adj = new Map();
79
+ for (const r of rels) {
80
+ const targets = adj.get(r.from) ?? [];
81
+ targets.push(r.to);
82
+ adj.set(r.from, targets);
83
+ }
84
+ // For each source, find all transitively reachable targets with paths
85
+ for (const source of adj.keys()) {
86
+ // BFS to find all reachable nodes and their paths
87
+ const visited = new Map();
88
+ const queue = (adj.get(source) ?? []).map((target) => ({
89
+ node: target,
90
+ path: [{ from: source, to: target, type: relType }],
91
+ }));
92
+ while (queue.length > 0) {
93
+ const item = queue.shift();
94
+ if (!item)
95
+ break;
96
+ const { node: current, path } = item;
97
+ // Skip if already visited (keep first/shortest path)
98
+ if (visited.has(current))
99
+ continue;
100
+ visited.set(current, path);
101
+ // Explore neighbours
102
+ const neighbours = adj.get(current) ?? [];
103
+ for (const neighbour of neighbours) {
104
+ if (!visited.has(neighbour)) {
105
+ queue.push({
106
+ node: neighbour,
107
+ path: [
108
+ ...path,
109
+ { from: current, to: neighbour, type: relType },
110
+ ],
111
+ });
112
+ }
113
+ }
114
+ }
115
+ // Add derived relationships from transitive closure
116
+ for (const [target, path] of visited) {
117
+ // Only add if there's no direct relationship (path length > 1 means transitive)
118
+ if (path.length > 1) {
119
+ addDerived(source, target, derivedType, path, "transitive");
120
+ }
121
+ }
122
+ }
123
+ }
124
+ // 2. Inverse relationships
125
+ for (const [relType, inverseType] of Object.entries(INVERSE_RELATIONSHIPS)) {
126
+ const rels = (input.doc.relationships ?? []).filter((r) => r.type === relType);
127
+ for (const r of rels) {
128
+ addDerived(r.to, r.from, inverseType, [{ from: r.from, to: r.to, type: r.type }], "inverse");
129
+ }
130
+ }
131
+ // 3. Composite patterns (A affects B, B depends_on C => A potentially_affects C)
132
+ const affectsRels = (input.doc.relationships ?? []).filter((r) => r.type === "affects");
133
+ const dependsRels = (input.doc.relationships ?? []).filter((r) => r.type === "depends_on");
134
+ const dependsMap = new Map();
135
+ for (const r of dependsRels) {
136
+ const deps = dependsMap.get(r.from) ?? [];
137
+ deps.push(r.to);
138
+ dependsMap.set(r.from, deps);
139
+ }
140
+ for (const affect of affectsRels) {
141
+ const deps = dependsMap.get(affect.to) ?? [];
142
+ for (const dep of deps) {
143
+ addDerived(affect.from, dep, "potentially_affects", [
144
+ { from: affect.from, to: affect.to, type: "affects" },
145
+ { from: affect.to, to: dep, type: "depends_on" },
146
+ ], "composite");
147
+ }
148
+ }
149
+ const summary = {
150
+ transitive: derived.filter((d) => d.derivationType === "transitive")
151
+ .length,
152
+ composite: derived.filter((d) => d.derivationType === "composite").length,
153
+ inverse: derived.filter((d) => d.derivationType === "inverse").length,
154
+ total: derived.length,
155
+ };
156
+ return { derivedRelationships: derived, summary };
157
+ },
158
+ });