@transitrix/diagrams 1.5.0 → 1.7.6

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/dist/capability-map/CapabilityCardNode.d.ts +19 -0
  2. package/dist/capability-map/CapabilityCardNode.js +66 -0
  3. package/dist/capability-map/CapabilityMapView.d.ts +59 -0
  4. package/dist/capability-map/CapabilityMapView.js +204 -0
  5. package/dist/capability-map/CapabilityRootNode.d.ts +12 -0
  6. package/dist/capability-map/CapabilityRootNode.js +23 -0
  7. package/dist/capability-map/__tests__/CapabilityMapView.test.d.ts +1 -0
  8. package/dist/capability-map/__tests__/CapabilityMapView.test.js +217 -0
  9. package/dist/capability-map/__tests__/address.test.d.ts +1 -0
  10. package/dist/capability-map/__tests__/address.test.js +49 -0
  11. package/dist/capability-map/__tests__/dsm-layout.test.d.ts +1 -0
  12. package/dist/capability-map/__tests__/dsm-layout.test.js +46 -0
  13. package/dist/capability-map/__tests__/dsm-mutations.test.d.ts +1 -0
  14. package/dist/capability-map/__tests__/dsm-mutations.test.js +125 -0
  15. package/dist/capability-map/__tests__/dsm-validate.test.d.ts +1 -0
  16. package/dist/capability-map/__tests__/dsm-validate.test.js +56 -0
  17. package/dist/capability-map/address.d.ts +12 -0
  18. package/dist/capability-map/address.js +48 -0
  19. package/dist/capability-map/dsm-layout.d.ts +9 -0
  20. package/dist/capability-map/dsm-layout.js +125 -0
  21. package/dist/capability-map/dsm-mutations.d.ts +28 -0
  22. package/dist/capability-map/dsm-mutations.js +196 -0
  23. package/dist/capability-map/dsm-schema.d.ts +71 -0
  24. package/dist/capability-map/dsm-schema.js +14 -0
  25. package/dist/capability-map/dsm-theme.d.ts +20 -0
  26. package/dist/capability-map/dsm-theme.js +36 -0
  27. package/dist/capability-map/dsm-validate.d.ts +2 -0
  28. package/dist/capability-map/dsm-validate.js +93 -0
  29. package/dist/capability-map/index.d.ts +9 -0
  30. package/dist/capability-map/index.js +6 -0
  31. package/dist/codex/__tests__/example.test.d.ts +1 -0
  32. package/dist/codex/__tests__/example.test.js +33 -0
  33. package/dist/codex/__tests__/validate.test.d.ts +1 -0
  34. package/dist/codex/__tests__/validate.test.js +68 -0
  35. package/dist/codex/index.d.ts +4 -0
  36. package/dist/codex/index.js +2 -0
  37. package/dist/codex/types.d.ts +7 -0
  38. package/dist/codex/types.js +8 -0
  39. package/dist/codex/validate.d.ts +11 -0
  40. package/dist/codex/validate.js +103 -0
  41. package/dist/compliance/__tests__/canon-catalog.test.d.ts +1 -0
  42. package/dist/compliance/__tests__/canon-catalog.test.js +60 -0
  43. package/dist/compliance/__tests__/trace.test.d.ts +1 -0
  44. package/dist/compliance/__tests__/trace.test.js +144 -0
  45. package/dist/compliance/__tests__/view-resolution.test.d.ts +1 -0
  46. package/dist/compliance/__tests__/view-resolution.test.js +59 -0
  47. package/dist/compliance/canon-catalog.d.ts +19 -0
  48. package/dist/compliance/canon-catalog.js +59 -0
  49. package/dist/compliance/classify.js +7 -1
  50. package/dist/compliance/coverage-metric.d.ts +12 -0
  51. package/dist/compliance/coverage-metric.js +35 -0
  52. package/dist/compliance/impact.d.ts +7 -1
  53. package/dist/compliance/impact.js +53 -0
  54. package/dist/compliance/index.d.ts +8 -5
  55. package/dist/compliance/index.js +4 -2
  56. package/dist/compliance/reverse-index.js +4 -1
  57. package/dist/compliance/trace.d.ts +26 -0
  58. package/dist/compliance/trace.js +89 -0
  59. package/dist/compliance/types.d.ts +94 -1
  60. package/dist/constraint/__tests__/example.test.d.ts +1 -0
  61. package/dist/constraint/__tests__/example.test.js +14 -0
  62. package/dist/constraint/__tests__/validate.test.d.ts +1 -0
  63. package/dist/constraint/__tests__/validate.test.js +58 -0
  64. package/dist/constraint/index.d.ts +4 -0
  65. package/dist/constraint/index.js +2 -0
  66. package/dist/constraint/types.d.ts +4 -0
  67. package/dist/constraint/types.js +2 -0
  68. package/dist/constraint/validate.d.ts +7 -0
  69. package/dist/constraint/validate.js +115 -0
  70. package/dist/fgca/__tests__/parse-canonical.test.js +31 -0
  71. package/dist/fgca/parse-canonical.d.ts +1 -1
  72. package/dist/fgca/parse-canonical.js +18 -4
  73. package/dist/goals/GoalNode.d.ts +19 -0
  74. package/dist/goals/GoalNode.js +96 -0
  75. package/dist/goals/GoalTreeView.d.ts +59 -0
  76. package/dist/goals/GoalTreeView.js +245 -0
  77. package/dist/goals/__tests__/GoalTreeView.test.d.ts +1 -0
  78. package/dist/goals/__tests__/GoalTreeView.test.js +337 -0
  79. package/dist/goals/__tests__/mutations.test.js +39 -0
  80. package/dist/goals/__tests__/parse-canonical.test.js +2 -0
  81. package/dist/goals/index.d.ts +3 -0
  82. package/dist/goals/index.js +1 -0
  83. package/dist/goals/layout.js +2 -1
  84. package/dist/goals/mutations.js +6 -6
  85. package/dist/goals/parse-canonical.d.ts +5 -0
  86. package/dist/goals/parse-canonical.js +5 -0
  87. package/dist/goals/theme.d.ts +22 -0
  88. package/dist/goals/theme.js +32 -0
  89. package/dist/goals/types.d.ts +2 -0
  90. package/dist/index.d.ts +2 -1
  91. package/dist/index.js +1 -1
  92. package/dist/repo-validate/types.js +2 -3
  93. package/dist/webview/__tests__/render-goals.test.js +17 -3
  94. package/dist/webview/render-goals.js +2 -1
  95. package/package.json +4 -1
  96. package/src/capability-map/CapabilityCardNode.tsx +146 -0
  97. package/src/capability-map/CapabilityMapView.tsx +331 -0
  98. package/src/capability-map/CapabilityRootNode.tsx +38 -0
  99. package/src/capability-map/__tests__/CapabilityMapView.test.tsx +232 -0
  100. package/src/capability-map/__tests__/address.test.ts +59 -0
  101. package/src/capability-map/__tests__/dsm-layout.test.ts +52 -0
  102. package/src/capability-map/__tests__/dsm-mutations.test.ts +141 -0
  103. package/src/capability-map/__tests__/dsm-validate.test.ts +65 -0
  104. package/src/capability-map/address.ts +48 -0
  105. package/src/capability-map/dsm-layout.ts +142 -0
  106. package/src/capability-map/dsm-mutations.ts +208 -0
  107. package/src/capability-map/dsm-schema.ts +80 -0
  108. package/src/capability-map/dsm-theme.ts +53 -0
  109. package/src/capability-map/dsm-validate.ts +103 -0
  110. package/src/capability-map/index.ts +35 -0
  111. package/src/codex/__tests__/example.test.ts +40 -0
  112. package/src/codex/__tests__/validate.test.ts +84 -0
  113. package/src/codex/index.ts +4 -0
  114. package/src/codex/types.ts +13 -0
  115. package/src/codex/validate.ts +125 -0
  116. package/src/compliance/__tests__/canon-catalog.test.ts +68 -0
  117. package/src/compliance/__tests__/trace.test.ts +157 -0
  118. package/src/compliance/__tests__/view-resolution.test.ts +80 -0
  119. package/src/compliance/canon-catalog.ts +76 -0
  120. package/src/compliance/classify.ts +7 -1
  121. package/src/compliance/coverage-metric.ts +50 -0
  122. package/src/compliance/impact.ts +67 -1
  123. package/src/compliance/index.ts +16 -1
  124. package/src/compliance/reverse-index.ts +3 -1
  125. package/src/compliance/trace.ts +118 -0
  126. package/src/compliance/types.ts +101 -1
  127. package/src/constraint/__tests__/example.test.ts +19 -0
  128. package/src/constraint/__tests__/validate.test.ts +68 -0
  129. package/src/constraint/index.ts +4 -0
  130. package/src/constraint/types.ts +5 -0
  131. package/src/constraint/validate.ts +131 -0
  132. package/src/fgca/__tests__/parse-canonical.test.ts +34 -0
  133. package/src/fgca/parse-canonical.ts +17 -4
  134. package/src/goals/GoalNode.tsx +219 -0
  135. package/src/goals/GoalTreeView.tsx +384 -0
  136. package/src/goals/__tests__/GoalTreeView.test.tsx +361 -0
  137. package/src/goals/__tests__/mutations.test.ts +42 -0
  138. package/src/goals/__tests__/parse-canonical.test.ts +2 -0
  139. package/src/goals/index.ts +4 -0
  140. package/src/goals/layout.ts +2 -1
  141. package/src/goals/mutations.ts +6 -6
  142. package/src/goals/parse-canonical.ts +6 -0
  143. package/src/goals/theme.ts +54 -0
  144. package/src/goals/types.ts +2 -0
  145. package/src/index.ts +29 -1
  146. package/src/repo-validate/types.ts +2 -3
  147. package/src/webview/__tests__/render-goals.test.ts +17 -3
  148. package/src/webview/render-goals.ts +2 -1
@@ -1,5 +1,6 @@
1
1
  import type { AssertionStatus } from '../assertion/types.js';
2
- /** Projection of a REQUIREMENT the compliance views need. */
2
+ import type { ComplianceCodexDoc } from './classify.js';
3
+ /** Projection of a REQUIREMENT (or CONSTRAINT) the compliance views need. */
3
4
  export interface IndexRequirement {
4
5
  id: string;
5
6
  name: string;
@@ -14,6 +15,38 @@ export interface IndexRequirement {
14
15
  * past or imminent, CV-3 renders an urgent decoration on the cell.
15
16
  */
16
17
  deadline?: string;
18
+ /**
19
+ * Origin taxonomy (15-requirement.md §2.1): `legislative`, `process-product`,
20
+ * or `project-product`. Distinguishes the context from which the obligation
21
+ * was derived. Undefined for existing pre-taxonomy admissions (treated as
22
+ * `legislative` by tooling that supports origin-based filtering).
23
+ */
24
+ origin?: 'legislative' | 'process-product' | 'project-product';
25
+ /**
26
+ * Same-TYPE `parent` reference: the higher-scale obligation this one
27
+ * decomposes from (15-requirement.md §2.4; ELEMENT_PRIMITIVES.md §7.13 for
28
+ * CONSTRAINT). Origin-agnostic, structure-only. Enables the hierarchy half
29
+ * of the requirement traceability view.
30
+ */
31
+ parent?: string;
32
+ /**
33
+ * Motivation-layer element kind. `requirement` = positive obligation
34
+ * (15-requirement.md); `constraint` = restriction / prohibition
35
+ * (ELEMENT_PRIMITIVES.md §7.13). ASSERTION coverage applies to `requirement`
36
+ * only (16-assertion.md §1); the hierarchy half applies to both.
37
+ */
38
+ element_kind?: 'requirement' | 'constraint';
39
+ /**
40
+ * Longer-form description of the obligation (15-requirement.md §2). Optional;
41
+ * used by the requirement traceability view to show the requirement body
42
+ * inline. Not used by matrix / list views.
43
+ */
44
+ description?: string;
45
+ /**
46
+ * `next_review_at` review-checkpoint date (15-requirement.md §2.3; ISO 8601).
47
+ * Present when the author has scheduled a review; drives `REQ-STALE-001`.
48
+ */
49
+ next_review_at?: string;
17
50
  }
18
51
  /**
19
52
  * Temporal status of a requirement deadline relative to today.
@@ -93,6 +126,11 @@ export interface ComplianceIndex {
93
126
  assertionsByRequirement: Map<string, IndexAssertion[]>;
94
127
  /** Subject id (product / process / capability) → assertions about it. */
95
128
  assertionsBySubject: Map<string, IndexAssertion[]>;
129
+ /**
130
+ * Parent id → the requirements/constraints that name it in `parent`
131
+ * (15-requirement.md §2.4). Enables the requirement-hierarchy view.
132
+ */
133
+ requirementsByParent: Map<string, IndexRequirement[]>;
96
134
  }
97
135
  export interface LawTreeRequirement {
98
136
  requirement: IndexRequirement;
@@ -115,3 +153,58 @@ export interface ProductView {
115
153
  /** Requirements bound to the product via an assertion, requirement-id-sorted. */
116
154
  requirements: ProductRequirementStatus[];
117
155
  }
156
+ /** A codex artefact resolved from a requirement's `derived_from` reference. */
157
+ export interface TraceSourceRef {
158
+ /** Verbatim id from `derived_from`. Always present. */
159
+ id: string;
160
+ /** The codex artefact, when resolved by the scan. Absent for dangling refs. */
161
+ codex?: ComplianceCodexDoc;
162
+ }
163
+ /** A named element (subject or realising element) resolved by the trace. */
164
+ export interface TraceElementRef {
165
+ id: string;
166
+ /** Element name when resolved by the scan; absent for dangling refs. */
167
+ name?: string;
168
+ }
169
+ /** One ASSERTION targeting the traced requirement, with subject + realising elements. */
170
+ export interface TraceAssertionRow {
171
+ assertion: IndexAssertion;
172
+ subject: TraceElementRef;
173
+ /** Elements named in the assertion's `realised_via` list (may be empty). */
174
+ realisedVia: TraceElementRef[];
175
+ }
176
+ /**
177
+ * Requirement traceability + hierarchy view.
178
+ *
179
+ * Two halves, both origin-agnostic (15-requirement.md §2.1):
180
+ * 1. Trace chain — `derived_from` source(s) → the element itself → any
181
+ * ASSERTION targeting it (`about`) → the asserted `subject` + `realised_via`
182
+ * elements. Origin-agnostic per 15-requirement.md §2.1; assertion coverage
183
+ * applies to REQUIREMENT only (16-assertion.md §1) — CONSTRAINT trace shows
184
+ * only the source chain + hierarchy.
185
+ * 2. Hierarchy — `parent` chain (ancestors, root last of the array) + children
186
+ * (any element whose `parent` names this one), sorted by id.
187
+ */
188
+ export interface RequirementTrace {
189
+ /** The element being traced (REQUIREMENT or CONSTRAINT). Falls back to a
190
+ * stub carrying the id as its name when the element is missing from the
191
+ * scan (a dangling `parent` or a repository being edited). */
192
+ requirement: IndexRequirement;
193
+ /** Backward-trace: `derived_from` codex artefacts, verbatim order. */
194
+ sources: TraceSourceRef[];
195
+ /** Forward-trace via ASSERTION. Empty for CONSTRAINT elements (16-assertion.md §1) or for a REQUIREMENT with no filed assertion. */
196
+ assertions: TraceAssertionRow[];
197
+ /** Parent chain: immediate parent first, root last. Empty when the element has no `parent`. */
198
+ ancestors: IndexRequirement[];
199
+ /** Direct children: elements naming this one as their `parent`, id-sorted. */
200
+ children: IndexRequirement[];
201
+ }
202
+ /**
203
+ * The complementary data the trace builder needs to name subjects and realising
204
+ * elements. Names are resolved by looking up the id in this map; unresolved ids
205
+ * surface as the id alone (a dangling reference).
206
+ */
207
+ export interface TraceElementCatalog {
208
+ /** id → human-readable name (or the id itself when unnamed). */
209
+ nameById: Map<string, string>;
210
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { readFileSync } from 'node:fs';
3
+ import { fileURLToPath } from 'node:url';
4
+ import path from 'node:path';
5
+ import yaml from 'js-yaml';
6
+ import { validateConstraint } from '../validate.js';
7
+ const dir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../../../../tests/fixtures/notation-corpus/constraint');
8
+ describe('constraint worked example (notation-corpus)', () => {
9
+ it('validates CONSTRAINT-GDPR-RESIDENCY-1.yaml without error', () => {
10
+ const data = yaml.load(readFileSync(path.join(dir, 'CONSTRAINT-GDPR-RESIDENCY-1.yaml'), 'utf-8'));
11
+ const v = validateConstraint(data);
12
+ expect(v.valid, JSON.stringify(v.errors)).toBe(true);
13
+ });
14
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,58 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { validateConstraint } from '../validate.js';
3
+ function valid() {
4
+ return {
5
+ notation: 'constraint',
6
+ id: 'CONSTRAINT-GDPR-RESIDENCY-1',
7
+ name: 'EU customer personal data must be stored within EU/EEA jurisdictions',
8
+ statement: 'Personal data of EU customers MUST NOT be persisted outside EU / EEA jurisdictions.',
9
+ status: 'active',
10
+ zone: 'canon',
11
+ admitted_at: '2026-05-29',
12
+ admitted_by: 'v.korobeinikov',
13
+ gate_checks: { uniqueness: 'pass', consistency: 'pass', completeness: 'pass' },
14
+ valid_from: '2018-05-25',
15
+ valid_to: null,
16
+ severity: 'mandatory',
17
+ owner_role: 'ROLE-DPO-1',
18
+ applies_to: ['APPLICATION-CRM-1'],
19
+ };
20
+ }
21
+ const codes = (input, opts) => validateConstraint(input, opts).errors.map((e) => e.code);
22
+ describe('validateConstraint — positive', () => {
23
+ it('accepts a well-formed constraint', () => {
24
+ const r = validateConstraint(valid());
25
+ expect(r.valid, JSON.stringify(r.errors)).toBe(true);
26
+ });
27
+ });
28
+ describe('validateConstraint — CONST-001', () => {
29
+ it('flags missing required fields and wrong notation', () => {
30
+ const r = valid();
31
+ delete r.statement;
32
+ expect(codes(r)).toContain('CONST-001');
33
+ expect(codes({ ...valid(), notation: 'requirement' })).toContain('CONST-001');
34
+ expect(codes({ ...valid(), id: 'CONSTRAINT-001' })).toContain('CONST-001');
35
+ });
36
+ });
37
+ describe('validateConstraint — CONST-002/003', () => {
38
+ it('flags invalid status and severity', () => {
39
+ expect(codes({ ...valid(), status: 'enabled' })).toContain('CONST-002');
40
+ expect(codes({ ...valid(), severity: 'critical' })).toContain('CONST-003');
41
+ });
42
+ });
43
+ describe('validateConstraint — CONST-004/005 (catalog)', () => {
44
+ it('flags unresolved applies_to and owner_role with catalog', () => {
45
+ const catalog = { typeOf: () => undefined };
46
+ expect(codes(valid(), { catalog })).toContain('CONST-004');
47
+ expect(codes(valid(), { catalog })).toContain('CONST-005');
48
+ });
49
+ it('does not flag CONST-004 without catalog for well-formed applies_to', () => {
50
+ expect(codes(valid())).not.toContain('CONST-004');
51
+ });
52
+ it('resolves applies_to when catalogue admits the target', () => {
53
+ const catalog = {
54
+ typeOf: (id) => (id === 'APPLICATION-CRM-1' ? 'APPLICATION' : id === 'ROLE-DPO-1' ? 'ROLE' : undefined),
55
+ };
56
+ expect(validateConstraint(valid(), { catalog }).valid).toBe(true);
57
+ });
58
+ });
@@ -0,0 +1,4 @@
1
+ export { CONSTRAINT_STATUSES, CONSTRAINT_SEVERITIES } from './types.js';
2
+ export type { ConstraintStatus, ConstraintSeverity } from './types.js';
3
+ export { validateConstraint } from './validate.js';
4
+ export type { ConstraintValidateOptions } from './validate.js';
@@ -0,0 +1,2 @@
1
+ export { CONSTRAINT_STATUSES, CONSTRAINT_SEVERITIES } from './types.js';
2
+ export { validateConstraint } from './validate.js';
@@ -0,0 +1,4 @@
1
+ export declare const CONSTRAINT_STATUSES: readonly ["active", "proposed", "deprecated", "retired"];
2
+ export type ConstraintStatus = (typeof CONSTRAINT_STATUSES)[number];
3
+ export declare const CONSTRAINT_SEVERITIES: readonly ["mandatory", "recommended", "advisory"];
4
+ export type ConstraintSeverity = (typeof CONSTRAINT_SEVERITIES)[number];
@@ -0,0 +1,2 @@
1
+ export const CONSTRAINT_STATUSES = ['active', 'proposed', 'deprecated', 'retired'];
2
+ export const CONSTRAINT_SEVERITIES = ['mandatory', 'recommended', 'advisory'];
@@ -0,0 +1,7 @@
1
+ import type { ValidationResult } from '../validation-types.js';
2
+ import { type CanonCatalog } from '../typed-id.js';
3
+ export interface ConstraintValidateOptions {
4
+ /** When provided, CONST-004/005 enforce artefact existence for cross-refs. */
5
+ catalog?: CanonCatalog;
6
+ }
7
+ export declare function validateConstraint(input: unknown, options?: ConstraintValidateOptions): ValidationResult;
@@ -0,0 +1,115 @@
1
+ // CONSTRAINT validator — methodology ELEMENT_PRIMITIVES.md §7.13 (sibling to
2
+ // 15-requirement.md). Implements CONST-001..005 for the compliance suite (#518 C4).
3
+ import { typeOfId, isCanonicalIdOfType } from '../typed-id.js';
4
+ import { CONSTRAINT_STATUSES, CONSTRAINT_SEVERITIES } from './types.js';
5
+ const REQUIRED_FIELDS = [
6
+ 'notation',
7
+ 'name',
8
+ 'statement',
9
+ 'status',
10
+ 'zone',
11
+ 'admitted_at',
12
+ 'admitted_by',
13
+ 'gate_checks',
14
+ 'valid_from',
15
+ ];
16
+ export function validateConstraint(input, options = {}) {
17
+ const errors = [];
18
+ const warnings = [];
19
+ if (input === null || typeof input !== 'object' || Array.isArray(input)) {
20
+ errors.push({ code: 'CONST-001', message: 'Constraint must be a YAML mapping.' });
21
+ return { valid: false, errors, warnings };
22
+ }
23
+ const c = input;
24
+ if (!isCanonicalIdOfType(c.id, 'CONSTRAINT')) {
25
+ errors.push({
26
+ code: 'CONST-001',
27
+ message: `id "${String(c.id)}" must match CONSTRAINT-[<middle>-]<INTEGER>.`,
28
+ path: 'id',
29
+ });
30
+ }
31
+ if (c.notation !== 'constraint') {
32
+ errors.push({ code: 'CONST-001', message: 'notation must be the fixed value "constraint".', path: 'notation' });
33
+ }
34
+ for (const f of REQUIRED_FIELDS) {
35
+ if (f === 'notation')
36
+ continue;
37
+ if (f === 'gate_checks') {
38
+ if (c.gate_checks === null || typeof c.gate_checks !== 'object') {
39
+ errors.push({ code: 'CONST-001', message: 'gate_checks is required and must be a mapping.', path: 'gate_checks' });
40
+ }
41
+ continue;
42
+ }
43
+ const v = c[f];
44
+ if (typeof v !== 'string' || v.trim() === '') {
45
+ errors.push({ code: 'CONST-001', message: `${f} is required.`, path: f });
46
+ }
47
+ }
48
+ if (c.zone !== 'canon') {
49
+ errors.push({ code: 'CONST-001', message: 'zone must be "canon" for a CONSTRAINT.', path: 'zone' });
50
+ }
51
+ if (!('valid_to' in c) || !(typeof c.valid_to === 'string' || c.valid_to === null)) {
52
+ errors.push({ code: 'CONST-001', message: 'valid_to is required (an ISO date string or null).', path: 'valid_to' });
53
+ }
54
+ const status = typeof c.status === 'string' ? c.status.trim() : '';
55
+ if (status && !CONSTRAINT_STATUSES.includes(status)) {
56
+ errors.push({
57
+ code: 'CONST-002',
58
+ message: `status must be one of ${CONSTRAINT_STATUSES.join(', ')}.`,
59
+ path: 'status',
60
+ });
61
+ }
62
+ if (c.severity !== undefined) {
63
+ const severity = typeof c.severity === 'string' ? c.severity.trim() : '';
64
+ if (!severity || !CONSTRAINT_SEVERITIES.includes(severity)) {
65
+ errors.push({
66
+ code: 'CONST-003',
67
+ message: `severity must be one of ${CONSTRAINT_SEVERITIES.join(', ')}.`,
68
+ path: 'severity',
69
+ });
70
+ }
71
+ }
72
+ if (c.applies_to !== undefined) {
73
+ if (!Array.isArray(c.applies_to)) {
74
+ errors.push({ code: 'CONST-001', message: 'applies_to must be a list of typed IDs.', path: 'applies_to' });
75
+ }
76
+ else {
77
+ c.applies_to.forEach((ref, i) => {
78
+ const type = typeOfId(ref);
79
+ if (!type) {
80
+ errors.push({
81
+ code: 'CONST-004',
82
+ message: `applies_to[${i}] "${String(ref)}" is not a resolvable typed ID.`,
83
+ path: `applies_to[${i}]`,
84
+ });
85
+ return;
86
+ }
87
+ if (options.catalog && options.catalog.typeOf(ref) === undefined) {
88
+ errors.push({
89
+ code: 'CONST-004',
90
+ message: `applies_to[${i}] "${String(ref)}" does not resolve to an admitted artefact.`,
91
+ path: `applies_to[${i}]`,
92
+ });
93
+ }
94
+ });
95
+ }
96
+ }
97
+ if (c.owner_role !== undefined) {
98
+ const role = c.owner_role;
99
+ if (typeof role !== 'string' || !isCanonicalIdOfType(role, 'ROLE')) {
100
+ errors.push({
101
+ code: 'CONST-005',
102
+ message: `owner_role "${String(role)}" must be a typed ROLE id.`,
103
+ path: 'owner_role',
104
+ });
105
+ }
106
+ else if (options.catalog && options.catalog.typeOf(role) === undefined) {
107
+ errors.push({
108
+ code: 'CONST-005',
109
+ message: `owner_role "${role}" does not resolve to an admitted artefact.`,
110
+ path: 'owner_role',
111
+ });
112
+ }
113
+ }
114
+ return { valid: errors.length === 0, errors, warnings };
115
+ }
@@ -32,6 +32,29 @@ describe('parseCanonicalFGCA', () => {
32
32
  expect(r.parsed?.changes).toHaveLength(1);
33
33
  expect(r.parsed?.activities).toHaveLength(1);
34
34
  });
35
+ it('accepts ACTION-* ids (methodology 1.0) alongside legacy ACTIVITY-*', () => {
36
+ const r = parseCanonicalFGCA({
37
+ ...VALID,
38
+ actions: [
39
+ { id: 'ACTION-CRM-EU-1', name: 'CRM rollout', changes: ['CHANGE-1'] },
40
+ { id: 'ACTIVITY-2', name: 'Legacy workstream', changes: ['CHANGE-1'] },
41
+ ],
42
+ });
43
+ expect(r.valid, JSON.stringify(r.errors)).toBe(true);
44
+ expect(r.parsed?.activities.map((a) => a.id)).toEqual(['ACTION-CRM-EU-1', 'ACTIVITY-2']);
45
+ });
46
+ it('defaults changes to [] when view_config.layers.changes is off (DGA-in-dgca)', () => {
47
+ const r = parseCanonicalFGCA({
48
+ ...VALID,
49
+ changes: undefined,
50
+ view_config: { layers: { changes: 'off' } },
51
+ actions: [
52
+ { id: 'ACTION-DISCOVERY-1', name: 'Gap assessment', goals: ['GOAL-1'] },
53
+ ],
54
+ });
55
+ expect(r.valid, JSON.stringify(r.errors)).toBe(true);
56
+ expect(r.parsed?.changes).toEqual([]);
57
+ });
35
58
  it('FGCA-001: rejects non-object input', () => {
36
59
  expect(parseCanonicalFGCA(null).errors[0].code).toBe('FGCA-001');
37
60
  expect(parseCanonicalFGCA('string').errors[0].code).toBe('FGCA-001');
@@ -178,6 +201,14 @@ describe('parseCanonicalFGA', () => {
178
201
  expect(r.parsed?.goals).toHaveLength(1);
179
202
  expect(r.parsed?.activities).toHaveLength(1);
180
203
  });
204
+ it('accepts ACTION-* ids in FGA mode', () => {
205
+ const r = parseCanonicalFGA({
206
+ ...VALID_FGA,
207
+ actions: [{ id: 'ACTION-GDPR-DSR-WORKFLOW-1', name: 'DSR workflow', goals: ['GOAL-1'] }],
208
+ });
209
+ expect(r.valid, JSON.stringify(r.errors)).toBe(true);
210
+ expect(r.parsed?.activities[0].id).toBe('ACTION-GDPR-DSR-WORKFLOW-1');
211
+ });
181
212
  it('populates activity.goal_id from activity.goals[] (the FGA edge-driving field)', () => {
182
213
  // The "FGA nodes render, no edges" bug: activities had no resolvable
183
214
  // goal_id, so the renderer drew no goal → activity edges.
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * - Flat top-level arrays, no `fgca:` wrapper.
8
8
  * - Typed string IDs per `IDS_AND_REFERENCES.md` (`FACTOR-1`,
9
- * `GOAL-RET-1`, `CHANGE-1`, `ACTIVITY-ONBOARD-1`).
9
+ * `GOAL-RET-1`, `CHANGE-1`, `ACTION-ONBOARD-1` (legacy `ACTIVITY-*` accepted).
10
10
  * - Plural canonical-direction cross-references: `goal.factors`,
11
11
  * `change.goals`, `activity.changes`, `activity.goals`.
12
12
  * - Per-notation validation codes `FGCA-001 … FGCA-015`.
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * - Flat top-level arrays, no `fgca:` wrapper.
8
8
  * - Typed string IDs per `IDS_AND_REFERENCES.md` (`FACTOR-1`,
9
- * `GOAL-RET-1`, `CHANGE-1`, `ACTIVITY-ONBOARD-1`).
9
+ * `GOAL-RET-1`, `CHANGE-1`, `ACTION-ONBOARD-1` (legacy `ACTIVITY-*` accepted).
10
10
  * - Plural canonical-direction cross-references: `goal.factors`,
11
11
  * `change.goals`, `activity.changes`, `activity.goals`.
12
12
  * - Per-notation validation codes `FGCA-001 … FGCA-015`.
@@ -31,7 +31,8 @@ const DRIVER_ID_RE = /^DRIVER(-[A-Z0-9][A-Z0-9_]*)*-\d+$/;
31
31
  const FACTOR_OR_DRIVER_ID_RE = /^(FACTOR|DRIVER)(-[A-Z0-9][A-Z0-9_]*)*-\d+$/;
32
32
  const GOAL_ID_RE = /^GOAL(-[A-Z0-9][A-Z0-9_]*)*-\d+$/;
33
33
  const CHANGE_ID_RE = /^CHANGE(-[A-Z0-9][A-Z0-9_]*)*-\d+$/;
34
- const ACTIVITY_ID_RE = /^ACTIVITY(-[A-Z0-9][A-Z0-9_]*)*-\d+$/;
34
+ // ACTION is canonical since methodology 1.0; ACTIVITY accepted for legacy docs.
35
+ const ACTION_OR_ACTIVITY_ID_RE = /^(ACTION|ACTIVITY)(-[A-Z0-9][A-Z0-9_]*)*-\d+$/;
35
36
  const FGCA_DOC_ID_RE = /^(FGCA|DGCA)(-[A-Z0-9][A-Z0-9_]*)*-\d+$/;
36
37
  const CONSTRAINT_ID_RE = /^CONSTRAINT(-[A-Z0-9][A-Z0-9_]*)*-\d+$/;
37
38
  function isNonEmptyString(v) {
@@ -42,6 +43,16 @@ function asObjectArray(v) {
42
43
  return null;
43
44
  return v.map((el) => (el && typeof el === 'object' ? el : null));
44
45
  }
46
+ /** DGA mode (`view_config.layers.changes: off`) may omit the changes layer. */
47
+ function isChangesLayerOff(raw) {
48
+ const vc = raw['view_config'];
49
+ if (!vc || typeof vc !== 'object')
50
+ return false;
51
+ const layers = vc['layers'];
52
+ if (!layers || typeof layers !== 'object')
53
+ return false;
54
+ return layers['changes'] === 'off';
55
+ }
45
56
  /**
46
57
  * Validate canonical FGCA YAML and, on success, return an internal-form
47
58
  * `FGCADoc` ready for `buildFGCALayout`.
@@ -87,7 +98,10 @@ export function parseCanonicalFGCA(input) {
87
98
  }
88
99
  const factorsRaw = asObjectArray(raw['factors']);
89
100
  const goalsRaw = asObjectArray(raw['goals']);
90
- const changesRaw = asObjectArray(raw['changes']);
101
+ let changesRaw = asObjectArray(raw['changes']);
102
+ if (changesRaw === null && raw['changes'] === undefined && isChangesLayerOff(raw)) {
103
+ changesRaw = [];
104
+ }
91
105
  const activitiesRaw = asObjectArray(raw['actions']);
92
106
  if (activitiesRaw === null && 'activities' in raw) {
93
107
  errors.push({ code: 'FGCA-004', message: '"activities" key is not accepted — rename to "actions"', path: 'actions' });
@@ -145,7 +159,7 @@ export function parseCanonicalFGCA(input) {
145
159
  factors.forEach((el, i) => checkLayerElement(el, `factors[${i}]`, FACTOR_OR_DRIVER_ID_RE, factorIds));
146
160
  goals.forEach((el, i) => checkLayerElement(el, `goals[${i}]`, GOAL_ID_RE, goalIds));
147
161
  changes.forEach((el, i) => checkLayerElement(el, `changes[${i}]`, CHANGE_ID_RE, changeIds));
148
- activities.forEach((el, i) => checkLayerElement(el, `activities[${i}]`, ACTIVITY_ID_RE, activityIds));
162
+ activities.forEach((el, i) => checkLayerElement(el, `activities[${i}]`, ACTION_OR_ACTIVITY_ID_RE, activityIds));
149
163
  if (errors.length > 0)
150
164
  return { valid: false, errors, warnings };
151
165
  // Cross-refs.
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import type { Factor, Goal } from './types.js';
3
+ import type { ThemeTokens } from './theme.js';
4
+ export interface GoalNodeData {
5
+ goal: Goal;
6
+ theme: Required<ThemeTokens>;
7
+ readOnly: boolean;
8
+ isDropTarget: boolean;
9
+ hasHiddenChildren: boolean;
10
+ isCollapsed: boolean;
11
+ onAddChild: (parentId: number, parentLevel: number) => void;
12
+ onDelete: (id: number) => void;
13
+ onToggleCollapse: (id: number) => void;
14
+ onFactorClick?: (factor: Factor) => void;
15
+ }
16
+ declare const GoalNode: React.MemoExoticComponent<({ data }: {
17
+ data: GoalNodeData;
18
+ }) => import("react/jsx-runtime").JSX.Element>;
19
+ export default GoalNode;
@@ -0,0 +1,96 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { memo, useState } from 'react';
3
+ import { Handle, Position } from 'reactflow';
4
+ import { displayGoalId } from './parse-canonical.js';
5
+ const NODE_WIDTH = 250;
6
+ const NODE_HEIGHT = 80;
7
+ function impactSign(f) {
8
+ const t = f.impact_type;
9
+ if (t === 'mixed')
10
+ return 'both';
11
+ if (t === 'opportunity' || t === 'positive')
12
+ return 'positive';
13
+ return 'negative';
14
+ }
15
+ const GoalNode = memo(({ data }) => {
16
+ const { goal, theme, readOnly, isDropTarget, hasHiddenChildren, isCollapsed } = data;
17
+ const [openPanel, setOpenPanel] = useState(null);
18
+ const positive = (goal.factors ?? []).filter((f) => impactSign(f) !== 'negative');
19
+ const negative = (goal.factors ?? []).filter((f) => impactSign(f) !== 'positive');
20
+ const bg = theme.goalLevelColors[goal.level] ?? theme.goalLevelColors[0];
21
+ return (_jsxs("div", { className: "tx-goal-node", style: {
22
+ position: 'relative',
23
+ width: NODE_WIDTH,
24
+ height: NODE_HEIGHT,
25
+ background: bg,
26
+ borderRadius: 12,
27
+ borderStyle: 'solid',
28
+ borderWidth: isDropTarget ? 2 : theme.cardBorderWidth,
29
+ borderColor: isDropTarget ? theme.dropTargetBorderColor : theme.cardBorderColor,
30
+ boxShadow: '0 1px 4px rgba(0,0,0,0.12)',
31
+ padding: '6px 8px',
32
+ fontSize: 12,
33
+ display: 'flex',
34
+ alignItems: 'stretch',
35
+ justifyContent: 'center',
36
+ }, children: [_jsx(Handle, { type: "target", position: Position.Left, style: { opacity: 0 } }), _jsx(Handle, { type: "source", position: Position.Right, style: { opacity: 0 } }), _jsx("div", { style: { flexShrink: 0, display: 'flex', alignItems: 'center', width: 16 }, children: positive.length > 0 && (_jsxs("span", { role: "button", "aria-label": `${positive.length} positive factor${positive.length > 1 ? 's' : ''}`, title: `${positive.length} positive factor${positive.length > 1 ? 's' : ''}`, onClick: (e) => {
37
+ e.stopPropagation();
38
+ setOpenPanel(openPanel === 'positive' ? null : 'positive');
39
+ }, style: { cursor: 'pointer', color: '#16a34a', fontSize: 14, lineHeight: 1, userSelect: 'none' }, children: ["\u25B2", positive.length > 1 && _jsx("span", { style: { fontSize: 9, fontWeight: 700, marginLeft: 2 }, children: positive.length })] })) }), _jsxs("div", { style: { flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', justifyContent: 'center', textAlign: 'center', padding: '0 4px' }, children: [_jsx("div", { title: goal.name, style: {
40
+ fontWeight: 600,
41
+ color: theme.cardTextColor,
42
+ lineHeight: 1.2,
43
+ overflow: 'hidden',
44
+ display: '-webkit-box',
45
+ WebkitLineClamp: 2,
46
+ WebkitBoxOrient: 'vertical',
47
+ wordBreak: 'break-word',
48
+ }, children: goal.name }), _jsxs("div", { style: { fontSize: 10, color: theme.cardMetaColor, marginTop: 2 }, children: ["ID: ", displayGoalId(goal), " | Lvl: ", goal.level, goal.tag ? ` | #${goal.tag}` : ''] })] }), _jsx("div", { style: { flexShrink: 0, display: 'flex', alignItems: 'center', width: 16, justifyContent: 'flex-end' }, children: negative.length > 0 && (_jsxs("span", { role: "button", "aria-label": `${negative.length} negative factor${negative.length > 1 ? 's' : ''}`, title: `${negative.length} negative factor${negative.length > 1 ? 's' : ''}`, onClick: (e) => {
49
+ e.stopPropagation();
50
+ setOpenPanel(openPanel === 'negative' ? null : 'negative');
51
+ }, style: { cursor: 'pointer', color: '#dc2626', fontSize: 14, lineHeight: 1, userSelect: 'none' }, children: ["\u25BC", negative.length > 1 && _jsx("span", { style: { fontSize: 9, fontWeight: 700, marginLeft: 2 }, children: negative.length })] })) }), openPanel && (_jsx("div", { style: {
52
+ position: 'absolute',
53
+ left: 0,
54
+ width: '100%',
55
+ zIndex: 20,
56
+ display: 'flex',
57
+ flexDirection: 'column',
58
+ gap: 4,
59
+ ...(openPanel === 'positive' ? { bottom: 'calc(100% + 8px)' } : { top: 'calc(100% + 8px)' }),
60
+ }, children: (openPanel === 'positive' ? positive : negative).map((f) => (_jsxs("div", { onClick: (e) => {
61
+ e.stopPropagation();
62
+ data.onFactorClick?.(f);
63
+ }, style: {
64
+ background: openPanel === 'positive' ? '#f0fdf4' : '#fef2f2',
65
+ border: `1px solid ${openPanel === 'positive' ? '#bbf7d0' : '#fecaca'}`,
66
+ color: openPanel === 'positive' ? '#166534' : '#991b1b',
67
+ borderRadius: 4,
68
+ padding: '4px 6px',
69
+ fontSize: 10,
70
+ textAlign: 'left',
71
+ cursor: data.onFactorClick ? 'pointer' : 'default',
72
+ }, children: [_jsx("div", { style: { fontWeight: 700 }, children: f.name }), f.description && _jsx("div", { style: { opacity: 0.85 }, children: f.description })] }, f.id))) })), !readOnly && (_jsx("button", { type: "button", "aria-label": "Add child goal", title: "Add child goal", onClick: (e) => {
73
+ e.stopPropagation();
74
+ data.onAddChild(goal.id, goal.level);
75
+ }, style: {
76
+ position: 'absolute', top: -8, right: -8, width: 16, height: 16,
77
+ borderRadius: '50%', border: '1px solid #86efac', background: '#ffffff',
78
+ color: '#16a34a', fontSize: 11, lineHeight: '14px', padding: 0, cursor: 'pointer',
79
+ }, children: "+" })), !readOnly && (_jsx("button", { type: "button", "aria-label": "Delete goal", title: "Delete goal and descendants", onClick: (e) => {
80
+ e.stopPropagation();
81
+ data.onDelete(goal.id);
82
+ }, style: {
83
+ position: 'absolute', bottom: -8, right: -8, width: 16, height: 16,
84
+ borderRadius: '50%', border: '1px solid #fca5a5', background: '#ffffff',
85
+ color: '#dc2626', fontSize: 11, lineHeight: '14px', padding: 0, cursor: 'pointer',
86
+ }, children: "\u00D7" })), hasHiddenChildren && (_jsx("button", { type: "button", "aria-label": isCollapsed ? 'Expand branch' : 'Collapse branch', title: isCollapsed ? 'Expand branch' : 'Collapse branch', onClick: (e) => {
87
+ e.stopPropagation();
88
+ data.onToggleCollapse(goal.id);
89
+ }, style: {
90
+ position: 'absolute', top: '50%', right: -8, transform: 'translateY(-50%)',
91
+ width: 16, height: 16, borderRadius: '50%', border: `1px solid ${theme.cardBorderColor}`,
92
+ background: '#ffffff', color: theme.cardBorderColor, fontSize: 11, lineHeight: '14px', padding: 0, cursor: 'pointer',
93
+ }, children: isCollapsed ? '+' : '−' }))] }));
94
+ });
95
+ GoalNode.displayName = 'GoalNode';
96
+ export default GoalNode;
@@ -0,0 +1,59 @@
1
+ import React from 'react';
2
+ import 'reactflow/dist/style.css';
3
+ import type { Factor, Goal, GoalTree, GoalTreeLayout, LayoutOptions } from './types.js';
4
+ import type { ThemeTokens } from './theme.js';
5
+ export type { ThemeTokens } from './theme.js';
6
+ export interface GoalTreeViewProps {
7
+ tree: GoalTree;
8
+ layout?: GoalTreeLayout;
9
+ layoutOptions?: LayoutOptions;
10
+ theme?: ThemeTokens;
11
+ readOnly?: boolean;
12
+ showBacklog?: boolean;
13
+ defaultBacklogOpen?: boolean;
14
+ showMiniMap?: boolean;
15
+ onChange?: (event: GoalTreeChange) => void;
16
+ onEditRequest?: (goal: Goal) => void;
17
+ onFactorClick?: (factor: Factor) => void;
18
+ }
19
+ export type GoalTreeChange = {
20
+ kind: 'reparent';
21
+ sourceId: number;
22
+ targetId: number;
23
+ result: GoalTree;
24
+ } | {
25
+ kind: 'addChild';
26
+ parentId: number;
27
+ newGoal: Goal;
28
+ result: GoalTree;
29
+ } | {
30
+ kind: 'delete';
31
+ id: number;
32
+ result: GoalTree;
33
+ } | {
34
+ kind: 'moveToBacklog';
35
+ id: number;
36
+ result: GoalTree;
37
+ } | {
38
+ kind: 'restoreFromBacklog';
39
+ id: number;
40
+ newParentId: number;
41
+ result: GoalTree;
42
+ };
43
+ /** Where a card was dropped, as classified from the pointer position at drag-stop. */
44
+ export type DropTarget = {
45
+ kind: 'node';
46
+ id: number;
47
+ } | {
48
+ kind: 'backlog';
49
+ } | null;
50
+ /**
51
+ * Pure decision: given where a dragged card was dropped, compute the mutation
52
+ * and the GoalTreeChange to report (or null for a no-op drop). Kept separate
53
+ * from the DOM/pointer-event glue in onNodeDragStop so the mutation-selection
54
+ * logic — which card wins reparent vs moveToBacklog vs a refused mutation —
55
+ * is unit-testable without needing a real drag gesture through reactflow's
56
+ * internal, DOM-measurement-gated dragging.
57
+ */
58
+ export declare function computeDragOutcome(tree: GoalTree, sourceId: number, dropTarget: DropTarget): GoalTreeChange | null;
59
+ export declare function GoalTreeView(props: GoalTreeViewProps): React.ReactElement;