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,116 @@
1
+ import * as z from "zod";
2
+ import { dirname } from "node:path";
3
+ import { defineOperation } from "./define-operation.js";
4
+ import { SysProMDocument } from "../schema.js";
5
+ import { parseSpecKitFeature } from "../speckit/parse.js";
6
+ import { generateSpecKitProject } from "../speckit/generate.js";
7
+ import { detectSpecKitProject } from "../speckit/project.js";
8
+ function compareDocuments(oldDoc, newDoc) {
9
+ const oldNodes = new Map(oldDoc.nodes.map((n) => [n.id, n]));
10
+ const newNodes = new Map(newDoc.nodes.map((n) => [n.id, n]));
11
+ const added = [];
12
+ const modified = [];
13
+ const removed = [];
14
+ // Find added and modified
15
+ for (const [id, newNode] of newNodes) {
16
+ const oldNode = oldNodes.get(id);
17
+ if (!oldNode) {
18
+ added.push(newNode);
19
+ }
20
+ else if (JSON.stringify(oldNode) !== JSON.stringify(newNode)) {
21
+ modified.push({ old: oldNode, new: newNode });
22
+ }
23
+ }
24
+ // Find removed
25
+ for (const [id, oldNode] of oldNodes) {
26
+ if (!newNodes.has(id)) {
27
+ removed.push(oldNode);
28
+ }
29
+ }
30
+ return { added, modified, removed };
31
+ }
32
+ export const SyncResult = z.object({
33
+ doc: SysProMDocument,
34
+ added: z.number(),
35
+ modified: z.number(),
36
+ removed: z.number(),
37
+ });
38
+ export const speckitSyncOp = defineOperation({
39
+ name: "speckitSync",
40
+ description: "Synchronise a SysProM document with a Spec-Kit directory",
41
+ input: z.object({
42
+ doc: SysProMDocument,
43
+ speckitDir: z.string().describe("Path to Spec-Kit directory"),
44
+ prefix: z
45
+ .string()
46
+ .optional()
47
+ .describe("ID prefix (defaults to directory name)"),
48
+ }),
49
+ output: SyncResult,
50
+ fn: ({ doc: syspromDoc, speckitDir, prefix }) => {
51
+ // Determine the prefix: use flag if provided, otherwise use directory name
52
+ const idPrefix = prefix ?? speckitDir.split("/").pop() ?? "FEAT";
53
+ // Find constitution file
54
+ let constitutionPath;
55
+ let searchDir = dirname(speckitDir);
56
+ for (let i = 0; i < 5; i++) {
57
+ const project = detectSpecKitProject(searchDir);
58
+ if (project.constitutionPath) {
59
+ constitutionPath = project.constitutionPath;
60
+ break;
61
+ }
62
+ const parent = dirname(searchDir);
63
+ if (parent === searchDir)
64
+ break;
65
+ searchDir = parent;
66
+ }
67
+ // Parse Spec-Kit feature
68
+ const specKitDoc = parseSpecKitFeature(speckitDir, idPrefix, constitutionPath);
69
+ // Compare documents
70
+ const diff = compareDocuments(syspromDoc, specKitDoc);
71
+ // Merge: Spec-Kit wins for content (description, status), SysProM wins for structure
72
+ const mergedNodes = new Map(syspromDoc.nodes.map((n) => [n.id, n]));
73
+ const specKitNodes = new Map(specKitDoc.nodes.map((n) => [n.id, n]));
74
+ for (const [id, specKitNode] of specKitNodes) {
75
+ const syspromNode = mergedNodes.get(id);
76
+ if (syspromNode) {
77
+ // Merge: Spec-Kit content wins, SysProM structure wins
78
+ const merged = {
79
+ ...syspromNode,
80
+ description: specKitNode.description ?? syspromNode.description,
81
+ status: specKitNode.status ?? syspromNode.status,
82
+ context: specKitNode.context ?? syspromNode.context,
83
+ options: specKitNode.options ?? syspromNode.options,
84
+ selected: specKitNode.selected ?? syspromNode.selected,
85
+ rationale: specKitNode.rationale ?? syspromNode.rationale,
86
+ scope: specKitNode.scope ?? syspromNode.scope,
87
+ operations: specKitNode.operations ?? syspromNode.operations,
88
+ plan: specKitNode.plan ?? syspromNode.plan,
89
+ };
90
+ mergedNodes.set(id, merged);
91
+ }
92
+ else {
93
+ // Add new node from Spec-Kit
94
+ mergedNodes.set(id, specKitNode);
95
+ }
96
+ }
97
+ // Remove nodes that were deleted in Spec-Kit
98
+ for (const node of diff.removed) {
99
+ mergedNodes.delete(node.id);
100
+ }
101
+ // Update merged document
102
+ const mergedDoc = {
103
+ ...syspromDoc,
104
+ nodes: Array.from(mergedNodes.values()),
105
+ relationships: syspromDoc.relationships, // Keep original relationships
106
+ };
107
+ // Re-generate Spec-Kit files from merged document
108
+ generateSpecKitProject(mergedDoc, speckitDir, idPrefix);
109
+ return {
110
+ doc: mergedDoc,
111
+ added: diff.added.length,
112
+ modified: diff.modified.length,
113
+ removed: diff.removed.length,
114
+ };
115
+ },
116
+ });
@@ -0,0 +1,309 @@
1
+ import * as z from "zod";
2
+ export declare const NodeState: z.ZodObject<{
3
+ nodeId: z.ZodString;
4
+ nodeName: z.ZodString;
5
+ activeStates: z.ZodArray<z.ZodString>;
6
+ }, z.core.$strip>;
7
+ export type NodeState = z.infer<typeof NodeState>;
8
+ export declare const stateAtOp: import("./define-operation.js").DefinedOperation<z.ZodObject<{
9
+ doc: z.ZodObject<{
10
+ $schema: z.ZodOptional<z.ZodString>;
11
+ metadata: z.ZodOptional<z.ZodObject<{
12
+ title: z.ZodOptional<z.ZodString>;
13
+ doc_type: z.ZodOptional<z.ZodString>;
14
+ scope: z.ZodOptional<z.ZodString>;
15
+ status: z.ZodOptional<z.ZodString>;
16
+ version: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodInt]>>;
17
+ }, z.core.$loose> & {
18
+ is(value: unknown): value is {
19
+ [x: string]: unknown;
20
+ title?: string | undefined;
21
+ doc_type?: string | undefined;
22
+ scope?: string | undefined;
23
+ status?: string | undefined;
24
+ version?: string | number | undefined;
25
+ };
26
+ }>;
27
+ nodes: z.ZodArray<z.ZodObject<{
28
+ id: z.ZodString;
29
+ type: z.ZodEnum<{
30
+ intent: "intent";
31
+ concept: "concept";
32
+ capability: "capability";
33
+ element: "element";
34
+ realisation: "realisation";
35
+ invariant: "invariant";
36
+ principle: "principle";
37
+ policy: "policy";
38
+ protocol: "protocol";
39
+ stage: "stage";
40
+ role: "role";
41
+ gate: "gate";
42
+ mode: "mode";
43
+ artefact: "artefact";
44
+ artefact_flow: "artefact_flow";
45
+ decision: "decision";
46
+ change: "change";
47
+ view: "view";
48
+ milestone: "milestone";
49
+ version: "version";
50
+ }> & {
51
+ 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";
52
+ };
53
+ name: z.ZodString;
54
+ description: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]> & {
55
+ is(value: unknown): value is string | string[];
56
+ }>;
57
+ status: z.ZodOptional<z.ZodEnum<{
58
+ deprecated: "deprecated";
59
+ proposed: "proposed";
60
+ accepted: "accepted";
61
+ active: "active";
62
+ implemented: "implemented";
63
+ adopted: "adopted";
64
+ defined: "defined";
65
+ introduced: "introduced";
66
+ in_progress: "in_progress";
67
+ complete: "complete";
68
+ consolidated: "consolidated";
69
+ experimental: "experimental";
70
+ retired: "retired";
71
+ superseded: "superseded";
72
+ abandoned: "abandoned";
73
+ deferred: "deferred";
74
+ }> & {
75
+ is(value: unknown): value is "deprecated" | "proposed" | "accepted" | "active" | "implemented" | "adopted" | "defined" | "introduced" | "in_progress" | "complete" | "consolidated" | "experimental" | "retired" | "superseded" | "abandoned" | "deferred";
76
+ }>;
77
+ lifecycle: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodBoolean, z.ZodString]>>>;
78
+ context: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]> & {
79
+ is(value: unknown): value is string | string[];
80
+ }>;
81
+ options: z.ZodOptional<z.ZodArray<z.ZodObject<{
82
+ id: z.ZodString;
83
+ description: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]> & {
84
+ is(value: unknown): value is string | string[];
85
+ };
86
+ }, z.core.$loose> & {
87
+ is(value: unknown): value is {
88
+ [x: string]: unknown;
89
+ id: string;
90
+ description: string | string[];
91
+ };
92
+ }>>;
93
+ selected: z.ZodOptional<z.ZodString>;
94
+ rationale: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]> & {
95
+ is(value: unknown): value is string | string[];
96
+ }>;
97
+ scope: z.ZodOptional<z.ZodArray<z.ZodString>>;
98
+ operations: z.ZodOptional<z.ZodArray<z.ZodObject<{
99
+ type: z.ZodEnum<{
100
+ link: "link";
101
+ add: "add";
102
+ update: "update";
103
+ remove: "remove";
104
+ }>;
105
+ target: z.ZodOptional<z.ZodString>;
106
+ description: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]> & {
107
+ is(value: unknown): value is string | string[];
108
+ }>;
109
+ }, z.core.$loose> & {
110
+ is(value: unknown): value is {
111
+ [x: string]: unknown;
112
+ type: "link" | "add" | "update" | "remove";
113
+ target?: string | undefined;
114
+ description?: string | string[] | undefined;
115
+ };
116
+ }>>;
117
+ plan: z.ZodOptional<z.ZodArray<z.ZodObject<{
118
+ description: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]> & {
119
+ is(value: unknown): value is string | string[];
120
+ };
121
+ done: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
122
+ }, z.core.$loose> & {
123
+ is(value: unknown): value is {
124
+ [x: string]: unknown;
125
+ description: string | string[];
126
+ done?: boolean | undefined;
127
+ };
128
+ }>>;
129
+ propagation: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodBoolean>>;
130
+ includes: z.ZodOptional<z.ZodArray<z.ZodString>>;
131
+ input: z.ZodOptional<z.ZodString>;
132
+ output: z.ZodOptional<z.ZodString>;
133
+ external_references: z.ZodOptional<z.ZodArray<z.ZodObject<{
134
+ role: z.ZodEnum<{
135
+ output: "output";
136
+ input: "input";
137
+ context: "context";
138
+ evidence: "evidence";
139
+ source: "source";
140
+ standard: "standard";
141
+ prior_art: "prior_art";
142
+ }> & {
143
+ is(value: unknown): value is "output" | "input" | "context" | "evidence" | "source" | "standard" | "prior_art";
144
+ };
145
+ identifier: z.ZodString;
146
+ description: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]> & {
147
+ is(value: unknown): value is string | string[];
148
+ }>;
149
+ node_id: z.ZodOptional<z.ZodString>;
150
+ internalised: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]> & {
151
+ is(value: unknown): value is string | string[];
152
+ }>;
153
+ }, z.core.$strip> & {
154
+ is(value: unknown): value is {
155
+ role: "output" | "input" | "context" | "evidence" | "source" | "standard" | "prior_art";
156
+ identifier: string;
157
+ description?: string | string[] | undefined;
158
+ node_id?: string | undefined;
159
+ internalised?: string | string[] | undefined;
160
+ };
161
+ }>>;
162
+ readonly subsystem: z.ZodOptional<z.ZodObject</*elided*/ any, z.core.$strip>>;
163
+ }, z.core.$loose>>;
164
+ relationships: z.ZodOptional<z.ZodArray<z.ZodObject<{
165
+ from: z.ZodString;
166
+ to: z.ZodString;
167
+ type: z.ZodEnum<{
168
+ refines: "refines";
169
+ realises: "realises";
170
+ implements: "implements";
171
+ depends_on: "depends_on";
172
+ constrained_by: "constrained_by";
173
+ affects: "affects";
174
+ supersedes: "supersedes";
175
+ must_preserve: "must_preserve";
176
+ performs: "performs";
177
+ part_of: "part_of";
178
+ precedes: "precedes";
179
+ must_follow: "must_follow";
180
+ blocks: "blocks";
181
+ routes_to: "routes_to";
182
+ governed_by: "governed_by";
183
+ modifies: "modifies";
184
+ triggered_by: "triggered_by";
185
+ applies_to: "applies_to";
186
+ produces: "produces";
187
+ consumes: "consumes";
188
+ transforms_into: "transforms_into";
189
+ selects: "selects";
190
+ requires: "requires";
191
+ disables: "disables";
192
+ }> & {
193
+ 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";
194
+ };
195
+ description: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]> & {
196
+ is(value: unknown): value is string | string[];
197
+ }>;
198
+ }, z.core.$loose> & {
199
+ is(value: unknown): value is {
200
+ [x: string]: unknown;
201
+ from: string;
202
+ to: string;
203
+ 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";
204
+ description?: string | string[] | undefined;
205
+ };
206
+ }>>;
207
+ external_references: z.ZodOptional<z.ZodArray<z.ZodObject<{
208
+ role: z.ZodEnum<{
209
+ output: "output";
210
+ input: "input";
211
+ context: "context";
212
+ evidence: "evidence";
213
+ source: "source";
214
+ standard: "standard";
215
+ prior_art: "prior_art";
216
+ }> & {
217
+ is(value: unknown): value is "output" | "input" | "context" | "evidence" | "source" | "standard" | "prior_art";
218
+ };
219
+ identifier: z.ZodString;
220
+ description: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]> & {
221
+ is(value: unknown): value is string | string[];
222
+ }>;
223
+ node_id: z.ZodOptional<z.ZodString>;
224
+ internalised: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]> & {
225
+ is(value: unknown): value is string | string[];
226
+ }>;
227
+ }, z.core.$strip> & {
228
+ is(value: unknown): value is {
229
+ role: "output" | "input" | "context" | "evidence" | "source" | "standard" | "prior_art";
230
+ identifier: string;
231
+ description?: string | string[] | undefined;
232
+ node_id?: string | undefined;
233
+ internalised?: string | string[] | undefined;
234
+ };
235
+ }>>;
236
+ }, z.core.$strip> & {
237
+ is(value: unknown): value is {
238
+ nodes: {
239
+ [x: string]: unknown;
240
+ id: string;
241
+ type: "intent" | "concept" | "capability" | "element" | "realisation" | "invariant" | "principle" | "policy" | "protocol" | "stage" | "role" | "gate" | "mode" | "artefact" | "artefact_flow" | "decision" | "change" | "view" | "milestone" | "version";
242
+ name: string;
243
+ description?: string | string[] | undefined;
244
+ status?: "deprecated" | "proposed" | "accepted" | "active" | "implemented" | "adopted" | "defined" | "introduced" | "in_progress" | "complete" | "consolidated" | "experimental" | "retired" | "superseded" | "abandoned" | "deferred" | undefined;
245
+ lifecycle?: Record<string, string | boolean> | undefined;
246
+ context?: string | string[] | undefined;
247
+ options?: {
248
+ [x: string]: unknown;
249
+ id: string;
250
+ description: string | string[];
251
+ }[] | undefined;
252
+ selected?: string | undefined;
253
+ rationale?: string | string[] | undefined;
254
+ scope?: string[] | undefined;
255
+ operations?: {
256
+ [x: string]: unknown;
257
+ type: "link" | "add" | "update" | "remove";
258
+ target?: string | undefined;
259
+ description?: string | string[] | undefined;
260
+ }[] | undefined;
261
+ plan?: {
262
+ [x: string]: unknown;
263
+ description: string | string[];
264
+ done?: boolean | undefined;
265
+ }[] | undefined;
266
+ propagation?: Record<string, boolean> | undefined;
267
+ includes?: string[] | undefined;
268
+ input?: string | undefined;
269
+ output?: string | undefined;
270
+ external_references?: {
271
+ role: "output" | "input" | "context" | "evidence" | "source" | "standard" | "prior_art";
272
+ identifier: string;
273
+ description?: string | string[] | undefined;
274
+ node_id?: string | undefined;
275
+ internalised?: string | string[] | undefined;
276
+ }[] | undefined;
277
+ subsystem?: /*elided*/ any | undefined;
278
+ }[];
279
+ $schema?: string | undefined;
280
+ metadata?: {
281
+ [x: string]: unknown;
282
+ title?: string | undefined;
283
+ doc_type?: string | undefined;
284
+ scope?: string | undefined;
285
+ status?: string | undefined;
286
+ version?: string | number | undefined;
287
+ } | undefined;
288
+ relationships?: {
289
+ [x: string]: unknown;
290
+ from: string;
291
+ to: string;
292
+ 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";
293
+ description?: string | string[] | undefined;
294
+ }[] | undefined;
295
+ external_references?: {
296
+ role: "output" | "input" | "context" | "evidence" | "source" | "standard" | "prior_art";
297
+ identifier: string;
298
+ description?: string | string[] | undefined;
299
+ node_id?: string | undefined;
300
+ internalised?: string | string[] | undefined;
301
+ }[] | undefined;
302
+ };
303
+ };
304
+ timestamp: z.ZodString;
305
+ }, z.core.$strip>, z.ZodArray<z.ZodObject<{
306
+ nodeId: z.ZodString;
307
+ nodeName: z.ZodString;
308
+ activeStates: z.ZodArray<z.ZodString>;
309
+ }, z.core.$strip>>>;
@@ -0,0 +1,53 @@
1
+ import * as z from "zod";
2
+ import { defineOperation } from "./define-operation.js";
3
+ import { SysProMDocument } from "../schema.js";
4
+ export const NodeState = z.object({
5
+ nodeId: z.string(),
6
+ nodeName: z.string(),
7
+ activeStates: z.array(z.string()),
8
+ });
9
+ export const stateAtOp = defineOperation({
10
+ name: "state-at",
11
+ description: "Determine the active states of all nodes at a specific point in time",
12
+ input: z.object({
13
+ doc: SysProMDocument,
14
+ timestamp: z.string(),
15
+ }),
16
+ output: z.array(NodeState),
17
+ fn: (input) => {
18
+ const nodeStates = new Map();
19
+ function processNode(node) {
20
+ if (node.lifecycle) {
21
+ const activeStates = [];
22
+ for (const [state, value] of Object.entries(node.lifecycle)) {
23
+ if (typeof value === "boolean") {
24
+ if (value) {
25
+ activeStates.push(state);
26
+ }
27
+ }
28
+ else if (typeof value === "string") {
29
+ if (value.localeCompare(input.timestamp) <= 0) {
30
+ activeStates.push(state);
31
+ }
32
+ }
33
+ }
34
+ if (activeStates.length > 0) {
35
+ nodeStates.set(node.id, {
36
+ nodeId: node.id,
37
+ nodeName: node.name,
38
+ activeStates: activeStates.sort(),
39
+ });
40
+ }
41
+ }
42
+ if (node.subsystem) {
43
+ for (const subNode of node.subsystem.nodes) {
44
+ processNode(subNode);
45
+ }
46
+ }
47
+ }
48
+ for (const node of input.doc.nodes) {
49
+ processNode(node);
50
+ }
51
+ return Array.from(nodeStates.values()).sort((a, b) => a.nodeId.localeCompare(b.nodeId));
52
+ },
53
+ });