sysprom 1.0.0 → 1.0.5

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 (148) hide show
  1. package/README.md +207 -0
  2. package/dist/schema.json +510 -0
  3. package/dist/src/canonical-json.d.ts +23 -0
  4. package/dist/src/canonical-json.js +120 -0
  5. package/dist/src/cli/commands/add.d.ts +22 -0
  6. package/dist/src/cli/commands/add.js +95 -0
  7. package/dist/src/cli/commands/check.d.ts +10 -0
  8. package/dist/src/cli/commands/check.js +33 -0
  9. package/dist/src/cli/commands/graph.d.ts +15 -0
  10. package/dist/src/cli/commands/graph.js +32 -0
  11. package/dist/src/cli/commands/init.d.ts +2 -0
  12. package/dist/src/cli/commands/init.js +44 -0
  13. package/dist/src/cli/commands/json2md.d.ts +2 -0
  14. package/dist/src/cli/commands/json2md.js +60 -0
  15. package/dist/src/cli/commands/md2json.d.ts +2 -0
  16. package/dist/src/cli/commands/md2json.js +29 -0
  17. package/dist/src/cli/commands/plan.d.ts +2 -0
  18. package/dist/src/cli/commands/plan.js +227 -0
  19. package/dist/src/cli/commands/query.d.ts +2 -0
  20. package/dist/src/cli/commands/query.js +275 -0
  21. package/dist/src/cli/commands/remove.d.ts +13 -0
  22. package/dist/src/cli/commands/remove.js +50 -0
  23. package/dist/src/cli/commands/rename.d.ts +14 -0
  24. package/dist/src/cli/commands/rename.js +34 -0
  25. package/dist/src/cli/commands/search.d.ts +11 -0
  26. package/dist/src/cli/commands/search.js +37 -0
  27. package/dist/src/cli/commands/speckit.d.ts +2 -0
  28. package/dist/src/cli/commands/speckit.js +318 -0
  29. package/dist/src/cli/commands/stats.d.ts +10 -0
  30. package/dist/src/cli/commands/stats.js +51 -0
  31. package/dist/src/cli/commands/task.d.ts +2 -0
  32. package/dist/src/cli/commands/task.js +162 -0
  33. package/dist/src/cli/commands/update.d.ts +2 -0
  34. package/dist/src/cli/commands/update.js +219 -0
  35. package/dist/src/cli/commands/validate.d.ts +10 -0
  36. package/dist/src/cli/commands/validate.js +30 -0
  37. package/dist/src/cli/define-command.d.ts +34 -0
  38. package/dist/src/cli/define-command.js +237 -0
  39. package/dist/src/cli/index.d.ts +2 -0
  40. package/dist/src/cli/index.js +3 -0
  41. package/dist/src/cli/program.d.ts +4 -0
  42. package/dist/src/cli/program.js +46 -0
  43. package/dist/src/cli/shared.d.ts +26 -0
  44. package/dist/src/cli/shared.js +41 -0
  45. package/dist/src/generate-schema.d.ts +1 -0
  46. package/dist/src/generate-schema.js +9 -0
  47. package/dist/src/index.d.ts +48 -0
  48. package/dist/src/index.js +99 -0
  49. package/dist/src/io.d.ts +22 -0
  50. package/dist/src/io.js +66 -0
  51. package/dist/src/json-to-md.d.ts +26 -0
  52. package/dist/src/json-to-md.js +498 -0
  53. package/dist/src/md-to-json.d.ts +22 -0
  54. package/dist/src/md-to-json.js +548 -0
  55. package/dist/src/operations/add-node.d.ts +887 -0
  56. package/dist/src/operations/add-node.js +21 -0
  57. package/dist/src/operations/add-plan-task.d.ts +594 -0
  58. package/dist/src/operations/add-plan-task.js +25 -0
  59. package/dist/src/operations/add-relationship.d.ts +635 -0
  60. package/dist/src/operations/add-relationship.js +25 -0
  61. package/dist/src/operations/check.d.ts +301 -0
  62. package/dist/src/operations/check.js +66 -0
  63. package/dist/src/operations/define-operation.d.ts +14 -0
  64. package/dist/src/operations/define-operation.js +21 -0
  65. package/dist/src/operations/graph.d.ts +303 -0
  66. package/dist/src/operations/graph.js +71 -0
  67. package/dist/src/operations/index.d.ts +38 -0
  68. package/dist/src/operations/index.js +45 -0
  69. package/dist/src/operations/init-document.d.ts +299 -0
  70. package/dist/src/operations/init-document.js +26 -0
  71. package/dist/src/operations/json-to-markdown.d.ts +298 -0
  72. package/dist/src/operations/json-to-markdown.js +13 -0
  73. package/dist/src/operations/mark-task-done.d.ts +594 -0
  74. package/dist/src/operations/mark-task-done.js +26 -0
  75. package/dist/src/operations/mark-task-undone.d.ts +594 -0
  76. package/dist/src/operations/mark-task-undone.js +26 -0
  77. package/dist/src/operations/markdown-to-json.d.ts +298 -0
  78. package/dist/src/operations/markdown-to-json.js +13 -0
  79. package/dist/src/operations/next-id.d.ts +322 -0
  80. package/dist/src/operations/next-id.js +29 -0
  81. package/dist/src/operations/node-history.d.ts +313 -0
  82. package/dist/src/operations/node-history.js +55 -0
  83. package/dist/src/operations/plan-add-task.d.ts +595 -0
  84. package/dist/src/operations/plan-add-task.js +18 -0
  85. package/dist/src/operations/plan-gate.d.ts +351 -0
  86. package/dist/src/operations/plan-gate.js +41 -0
  87. package/dist/src/operations/plan-init.d.ts +299 -0
  88. package/dist/src/operations/plan-init.js +17 -0
  89. package/dist/src/operations/plan-progress.d.ts +313 -0
  90. package/dist/src/operations/plan-progress.js +23 -0
  91. package/dist/src/operations/plan-status.d.ts +349 -0
  92. package/dist/src/operations/plan-status.js +41 -0
  93. package/dist/src/operations/query-node.d.ts +1065 -0
  94. package/dist/src/operations/query-node.js +27 -0
  95. package/dist/src/operations/query-nodes.d.ts +594 -0
  96. package/dist/src/operations/query-nodes.js +23 -0
  97. package/dist/src/operations/query-relationships.d.ts +343 -0
  98. package/dist/src/operations/query-relationships.js +27 -0
  99. package/dist/src/operations/remove-node.d.ts +895 -0
  100. package/dist/src/operations/remove-node.js +58 -0
  101. package/dist/src/operations/remove-relationship.d.ts +622 -0
  102. package/dist/src/operations/remove-relationship.js +26 -0
  103. package/dist/src/operations/rename.d.ts +594 -0
  104. package/dist/src/operations/rename.js +113 -0
  105. package/dist/src/operations/search.d.ts +593 -0
  106. package/dist/src/operations/search.js +39 -0
  107. package/dist/src/operations/speckit-diff.d.ts +330 -0
  108. package/dist/src/operations/speckit-diff.js +89 -0
  109. package/dist/src/operations/speckit-export.d.ts +300 -0
  110. package/dist/src/operations/speckit-export.js +17 -0
  111. package/dist/src/operations/speckit-import.d.ts +299 -0
  112. package/dist/src/operations/speckit-import.js +39 -0
  113. package/dist/src/operations/speckit-sync.d.ts +900 -0
  114. package/dist/src/operations/speckit-sync.js +116 -0
  115. package/dist/src/operations/state-at.d.ts +309 -0
  116. package/dist/src/operations/state-at.js +53 -0
  117. package/dist/src/operations/stats.d.ts +324 -0
  118. package/dist/src/operations/stats.js +85 -0
  119. package/dist/src/operations/task-list.d.ts +305 -0
  120. package/dist/src/operations/task-list.js +44 -0
  121. package/dist/src/operations/timeline.d.ts +312 -0
  122. package/dist/src/operations/timeline.js +46 -0
  123. package/dist/src/operations/trace-from-node.d.ts +1197 -0
  124. package/dist/src/operations/trace-from-node.js +36 -0
  125. package/dist/src/operations/update-metadata.d.ts +593 -0
  126. package/dist/src/operations/update-metadata.js +18 -0
  127. package/dist/src/operations/update-node.d.ts +957 -0
  128. package/dist/src/operations/update-node.js +24 -0
  129. package/dist/src/operations/update-plan-task.d.ts +595 -0
  130. package/dist/src/operations/update-plan-task.js +31 -0
  131. package/dist/src/operations/validate.d.ts +310 -0
  132. package/dist/src/operations/validate.js +82 -0
  133. package/dist/src/schema.d.ts +891 -0
  134. package/dist/src/schema.js +356 -0
  135. package/dist/src/speckit/generate.d.ts +7 -0
  136. package/dist/src/speckit/generate.js +546 -0
  137. package/dist/src/speckit/index.d.ts +4 -0
  138. package/dist/src/speckit/index.js +4 -0
  139. package/dist/src/speckit/parse.d.ts +11 -0
  140. package/dist/src/speckit/parse.js +712 -0
  141. package/dist/src/speckit/plan.d.ts +125 -0
  142. package/dist/src/speckit/plan.js +636 -0
  143. package/dist/src/speckit/project.d.ts +39 -0
  144. package/dist/src/speckit/project.js +141 -0
  145. package/dist/src/text.d.ts +23 -0
  146. package/dist/src/text.js +32 -0
  147. package/package.json +86 -8
  148. package/schema.json +510 -0
@@ -0,0 +1,310 @@
1
+ import * as z from "zod";
2
+ export declare const ValidationResult: z.ZodObject<{
3
+ valid: z.ZodBoolean;
4
+ issues: z.ZodArray<z.ZodString>;
5
+ nodeCount: z.ZodNumber;
6
+ relationshipCount: z.ZodNumber;
7
+ }, z.core.$strip>;
8
+ export type ValidationResult = z.infer<typeof ValidationResult>;
9
+ export declare const validateOp: import("./define-operation.js").DefinedOperation<z.ZodObject<{
10
+ doc: z.ZodObject<{
11
+ $schema: z.ZodOptional<z.ZodString>;
12
+ metadata: z.ZodOptional<z.ZodObject<{
13
+ title: z.ZodOptional<z.ZodString>;
14
+ doc_type: z.ZodOptional<z.ZodString>;
15
+ scope: z.ZodOptional<z.ZodString>;
16
+ status: z.ZodOptional<z.ZodString>;
17
+ version: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodInt]>>;
18
+ }, z.core.$loose> & {
19
+ is(value: unknown): value is {
20
+ [x: string]: unknown;
21
+ title?: string | undefined;
22
+ doc_type?: string | undefined;
23
+ scope?: string | undefined;
24
+ status?: string | undefined;
25
+ version?: string | number | undefined;
26
+ };
27
+ }>;
28
+ nodes: z.ZodArray<z.ZodObject<{
29
+ id: z.ZodString;
30
+ type: z.ZodEnum<{
31
+ intent: "intent";
32
+ concept: "concept";
33
+ capability: "capability";
34
+ element: "element";
35
+ realisation: "realisation";
36
+ invariant: "invariant";
37
+ principle: "principle";
38
+ policy: "policy";
39
+ protocol: "protocol";
40
+ stage: "stage";
41
+ role: "role";
42
+ gate: "gate";
43
+ mode: "mode";
44
+ artefact: "artefact";
45
+ artefact_flow: "artefact_flow";
46
+ decision: "decision";
47
+ change: "change";
48
+ view: "view";
49
+ milestone: "milestone";
50
+ version: "version";
51
+ }> & {
52
+ 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";
53
+ };
54
+ name: z.ZodString;
55
+ description: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]> & {
56
+ is(value: unknown): value is string | string[];
57
+ }>;
58
+ status: z.ZodOptional<z.ZodEnum<{
59
+ deprecated: "deprecated";
60
+ proposed: "proposed";
61
+ accepted: "accepted";
62
+ active: "active";
63
+ implemented: "implemented";
64
+ adopted: "adopted";
65
+ defined: "defined";
66
+ introduced: "introduced";
67
+ in_progress: "in_progress";
68
+ complete: "complete";
69
+ consolidated: "consolidated";
70
+ experimental: "experimental";
71
+ retired: "retired";
72
+ superseded: "superseded";
73
+ abandoned: "abandoned";
74
+ deferred: "deferred";
75
+ }> & {
76
+ is(value: unknown): value is "deprecated" | "proposed" | "accepted" | "active" | "implemented" | "adopted" | "defined" | "introduced" | "in_progress" | "complete" | "consolidated" | "experimental" | "retired" | "superseded" | "abandoned" | "deferred";
77
+ }>;
78
+ lifecycle: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodBoolean, z.ZodString]>>>;
79
+ context: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]> & {
80
+ is(value: unknown): value is string | string[];
81
+ }>;
82
+ options: z.ZodOptional<z.ZodArray<z.ZodObject<{
83
+ id: z.ZodString;
84
+ description: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]> & {
85
+ is(value: unknown): value is string | string[];
86
+ };
87
+ }, z.core.$loose> & {
88
+ is(value: unknown): value is {
89
+ [x: string]: unknown;
90
+ id: string;
91
+ description: string | string[];
92
+ };
93
+ }>>;
94
+ selected: z.ZodOptional<z.ZodString>;
95
+ rationale: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]> & {
96
+ is(value: unknown): value is string | string[];
97
+ }>;
98
+ scope: z.ZodOptional<z.ZodArray<z.ZodString>>;
99
+ operations: z.ZodOptional<z.ZodArray<z.ZodObject<{
100
+ type: z.ZodEnum<{
101
+ link: "link";
102
+ add: "add";
103
+ update: "update";
104
+ remove: "remove";
105
+ }>;
106
+ target: z.ZodOptional<z.ZodString>;
107
+ description: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]> & {
108
+ is(value: unknown): value is string | string[];
109
+ }>;
110
+ }, z.core.$loose> & {
111
+ is(value: unknown): value is {
112
+ [x: string]: unknown;
113
+ type: "link" | "add" | "update" | "remove";
114
+ target?: string | undefined;
115
+ description?: string | string[] | undefined;
116
+ };
117
+ }>>;
118
+ plan: z.ZodOptional<z.ZodArray<z.ZodObject<{
119
+ description: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]> & {
120
+ is(value: unknown): value is string | string[];
121
+ };
122
+ done: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
123
+ }, z.core.$loose> & {
124
+ is(value: unknown): value is {
125
+ [x: string]: unknown;
126
+ description: string | string[];
127
+ done?: boolean | undefined;
128
+ };
129
+ }>>;
130
+ propagation: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodBoolean>>;
131
+ includes: z.ZodOptional<z.ZodArray<z.ZodString>>;
132
+ input: z.ZodOptional<z.ZodString>;
133
+ output: z.ZodOptional<z.ZodString>;
134
+ external_references: z.ZodOptional<z.ZodArray<z.ZodObject<{
135
+ role: z.ZodEnum<{
136
+ output: "output";
137
+ input: "input";
138
+ context: "context";
139
+ evidence: "evidence";
140
+ source: "source";
141
+ standard: "standard";
142
+ prior_art: "prior_art";
143
+ }> & {
144
+ is(value: unknown): value is "output" | "input" | "context" | "evidence" | "source" | "standard" | "prior_art";
145
+ };
146
+ identifier: z.ZodString;
147
+ description: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]> & {
148
+ is(value: unknown): value is string | string[];
149
+ }>;
150
+ node_id: z.ZodOptional<z.ZodString>;
151
+ internalised: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]> & {
152
+ is(value: unknown): value is string | string[];
153
+ }>;
154
+ }, z.core.$strip> & {
155
+ is(value: unknown): value is {
156
+ role: "output" | "input" | "context" | "evidence" | "source" | "standard" | "prior_art";
157
+ identifier: string;
158
+ description?: string | string[] | undefined;
159
+ node_id?: string | undefined;
160
+ internalised?: string | string[] | undefined;
161
+ };
162
+ }>>;
163
+ readonly subsystem: z.ZodOptional<z.ZodObject</*elided*/ any, z.core.$strip>>;
164
+ }, z.core.$loose>>;
165
+ relationships: z.ZodOptional<z.ZodArray<z.ZodObject<{
166
+ from: z.ZodString;
167
+ to: z.ZodString;
168
+ type: z.ZodEnum<{
169
+ refines: "refines";
170
+ realises: "realises";
171
+ implements: "implements";
172
+ depends_on: "depends_on";
173
+ constrained_by: "constrained_by";
174
+ affects: "affects";
175
+ supersedes: "supersedes";
176
+ must_preserve: "must_preserve";
177
+ performs: "performs";
178
+ part_of: "part_of";
179
+ precedes: "precedes";
180
+ must_follow: "must_follow";
181
+ blocks: "blocks";
182
+ routes_to: "routes_to";
183
+ governed_by: "governed_by";
184
+ modifies: "modifies";
185
+ triggered_by: "triggered_by";
186
+ applies_to: "applies_to";
187
+ produces: "produces";
188
+ consumes: "consumes";
189
+ transforms_into: "transforms_into";
190
+ selects: "selects";
191
+ requires: "requires";
192
+ disables: "disables";
193
+ }> & {
194
+ 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";
195
+ };
196
+ description: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]> & {
197
+ is(value: unknown): value is string | string[];
198
+ }>;
199
+ }, z.core.$loose> & {
200
+ is(value: unknown): value is {
201
+ [x: string]: unknown;
202
+ from: string;
203
+ to: string;
204
+ 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";
205
+ description?: string | string[] | undefined;
206
+ };
207
+ }>>;
208
+ external_references: z.ZodOptional<z.ZodArray<z.ZodObject<{
209
+ role: z.ZodEnum<{
210
+ output: "output";
211
+ input: "input";
212
+ context: "context";
213
+ evidence: "evidence";
214
+ source: "source";
215
+ standard: "standard";
216
+ prior_art: "prior_art";
217
+ }> & {
218
+ is(value: unknown): value is "output" | "input" | "context" | "evidence" | "source" | "standard" | "prior_art";
219
+ };
220
+ identifier: z.ZodString;
221
+ description: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]> & {
222
+ is(value: unknown): value is string | string[];
223
+ }>;
224
+ node_id: z.ZodOptional<z.ZodString>;
225
+ internalised: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]> & {
226
+ is(value: unknown): value is string | string[];
227
+ }>;
228
+ }, z.core.$strip> & {
229
+ is(value: unknown): value is {
230
+ role: "output" | "input" | "context" | "evidence" | "source" | "standard" | "prior_art";
231
+ identifier: string;
232
+ description?: string | string[] | undefined;
233
+ node_id?: string | undefined;
234
+ internalised?: string | string[] | undefined;
235
+ };
236
+ }>>;
237
+ }, z.core.$strip> & {
238
+ is(value: unknown): value is {
239
+ nodes: {
240
+ [x: string]: unknown;
241
+ id: string;
242
+ type: "intent" | "concept" | "capability" | "element" | "realisation" | "invariant" | "principle" | "policy" | "protocol" | "stage" | "role" | "gate" | "mode" | "artefact" | "artefact_flow" | "decision" | "change" | "view" | "milestone" | "version";
243
+ name: string;
244
+ description?: string | string[] | undefined;
245
+ status?: "deprecated" | "proposed" | "accepted" | "active" | "implemented" | "adopted" | "defined" | "introduced" | "in_progress" | "complete" | "consolidated" | "experimental" | "retired" | "superseded" | "abandoned" | "deferred" | undefined;
246
+ lifecycle?: Record<string, string | boolean> | undefined;
247
+ context?: string | string[] | undefined;
248
+ options?: {
249
+ [x: string]: unknown;
250
+ id: string;
251
+ description: string | string[];
252
+ }[] | undefined;
253
+ selected?: string | undefined;
254
+ rationale?: string | string[] | undefined;
255
+ scope?: string[] | undefined;
256
+ operations?: {
257
+ [x: string]: unknown;
258
+ type: "link" | "add" | "update" | "remove";
259
+ target?: string | undefined;
260
+ description?: string | string[] | undefined;
261
+ }[] | undefined;
262
+ plan?: {
263
+ [x: string]: unknown;
264
+ description: string | string[];
265
+ done?: boolean | undefined;
266
+ }[] | undefined;
267
+ propagation?: Record<string, boolean> | undefined;
268
+ includes?: string[] | undefined;
269
+ input?: string | undefined;
270
+ output?: string | undefined;
271
+ external_references?: {
272
+ role: "output" | "input" | "context" | "evidence" | "source" | "standard" | "prior_art";
273
+ identifier: string;
274
+ description?: string | string[] | undefined;
275
+ node_id?: string | undefined;
276
+ internalised?: string | string[] | undefined;
277
+ }[] | undefined;
278
+ subsystem?: /*elided*/ any | undefined;
279
+ }[];
280
+ $schema?: string | undefined;
281
+ metadata?: {
282
+ [x: string]: unknown;
283
+ title?: string | undefined;
284
+ doc_type?: string | undefined;
285
+ scope?: string | undefined;
286
+ status?: string | undefined;
287
+ version?: string | number | undefined;
288
+ } | undefined;
289
+ relationships?: {
290
+ [x: string]: unknown;
291
+ from: string;
292
+ to: string;
293
+ 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";
294
+ description?: string | string[] | undefined;
295
+ }[] | undefined;
296
+ external_references?: {
297
+ role: "output" | "input" | "context" | "evidence" | "source" | "standard" | "prior_art";
298
+ identifier: string;
299
+ description?: string | string[] | undefined;
300
+ node_id?: string | undefined;
301
+ internalised?: string | string[] | undefined;
302
+ }[] | undefined;
303
+ };
304
+ };
305
+ }, z.core.$strip>, z.ZodObject<{
306
+ valid: z.ZodBoolean;
307
+ issues: z.ZodArray<z.ZodString>;
308
+ nodeCount: z.ZodNumber;
309
+ relationshipCount: z.ZodNumber;
310
+ }, z.core.$strip>>;
@@ -0,0 +1,82 @@
1
+ import * as z from "zod";
2
+ import { defineOperation } from "./define-operation.js";
3
+ import { SysProMDocument } from "../schema.js";
4
+ export const ValidationResult = z.object({
5
+ valid: z.boolean(),
6
+ issues: z.array(z.string()),
7
+ nodeCount: z.number(),
8
+ relationshipCount: z.number(),
9
+ });
10
+ const DOMAIN_TYPES = new Set([
11
+ "intent",
12
+ "concept",
13
+ "capability",
14
+ "element",
15
+ "invariant",
16
+ ]);
17
+ export const validateOp = defineOperation({
18
+ name: "validate",
19
+ description: "Validate a SysProM document for structural and semantic correctness",
20
+ input: z.object({
21
+ doc: SysProMDocument,
22
+ }),
23
+ output: ValidationResult,
24
+ fn: (input) => {
25
+ const issues = [];
26
+ // Unique node IDs
27
+ const ids = new Set();
28
+ for (const n of input.doc.nodes) {
29
+ if (ids.has(n.id)) {
30
+ issues.push(`Duplicate node ID: ${n.id}`);
31
+ }
32
+ ids.add(n.id);
33
+ }
34
+ // Relationship endpoint references
35
+ for (const r of input.doc.relationships ?? []) {
36
+ if (!ids.has(r.from)) {
37
+ issues.push(`Relationship references unknown source: ${r.from}`);
38
+ }
39
+ if (!ids.has(r.to)) {
40
+ issues.push(`Relationship references unknown target: ${r.to}`);
41
+ }
42
+ }
43
+ // INV2: Changes must reference at least one decision
44
+ const decisionIds = new Set(input.doc.nodes.filter((n) => n.type === "decision").map((n) => n.id));
45
+ for (const n of input.doc.nodes.filter((n) => n.type === "change")) {
46
+ const targets = (input.doc.relationships ?? [])
47
+ .filter((r) => r.from === n.id)
48
+ .map((r) => r.to);
49
+ const linksToDecision = targets.some((t) => decisionIds.has(t));
50
+ if (!linksToDecision) {
51
+ issues.push(`${n.id} (${n.name}): change does not reference any decision`);
52
+ }
53
+ }
54
+ // INV3: Decisions affecting domain nodes must have must_preserve
55
+ const nodeTypes = new Map(input.doc.nodes.map((n) => [n.id, n.type]));
56
+ for (const n of input.doc.nodes.filter((n) => n.type === "decision")) {
57
+ const affects = (input.doc.relationships ?? []).filter((r) => r.from === n.id && r.type === "affects");
58
+ const affectsDomain = affects.some((r) => DOMAIN_TYPES.has(nodeTypes.get(r.to) ?? ""));
59
+ if (!affectsDomain)
60
+ continue;
61
+ const preserves = (input.doc.relationships ?? []).filter((r) => r.from === n.id && r.type === "must_preserve");
62
+ if (preserves.length === 0) {
63
+ issues.push(`${n.id} (${n.name}): affects domain nodes but has no must_preserve relationship`);
64
+ }
65
+ }
66
+ // INV13: Decisions must have options and selected
67
+ for (const n of input.doc.nodes.filter((n) => n.type === "decision")) {
68
+ if (!n.options || n.options.length === 0) {
69
+ issues.push(`${n.id} (${n.name}): decision has no options`);
70
+ }
71
+ if (!n.selected) {
72
+ issues.push(`${n.id} (${n.name}): decision has no selected option`);
73
+ }
74
+ }
75
+ return {
76
+ valid: issues.length === 0,
77
+ issues,
78
+ nodeCount: input.doc.nodes.length,
79
+ relationshipCount: (input.doc.relationships ?? []).length,
80
+ };
81
+ },
82
+ });