@principal-ai/subsystems-react 0.51.0 → 0.51.2

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 (88) hide show
  1. package/dist/index.d.ts +6 -6
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +6 -4
  4. package/dist/index.js.map +1 -1
  5. package/dist/pierre/PierreTrailCodeView.d.ts +1 -1
  6. package/dist/pierre/PierreTrailCodeView.d.ts.map +1 -1
  7. package/dist/pierre/PierreTrailCodeView.js +44 -21
  8. package/dist/pierre/PierreTrailCodeView.js.map +1 -1
  9. package/dist/stories/Subsystem/C4Graph/c4ProposedElements.fixture.d.ts +493 -0
  10. package/dist/stories/Subsystem/C4Graph/c4ProposedElements.fixture.d.ts.map +1 -0
  11. package/dist/stories/Subsystem/C4Graph/c4ProposedElements.fixture.js +329 -0
  12. package/dist/stories/Subsystem/C4Graph/c4ProposedElements.fixture.js.map +1 -0
  13. package/dist/subsystem/C4Graph.d.ts +2 -2
  14. package/dist/subsystem/C4Graph.d.ts.map +1 -1
  15. package/dist/subsystem/C4Graph.js +25 -16
  16. package/dist/subsystem/C4Graph.js.map +1 -1
  17. package/dist/subsystem/C4NodeCard.d.ts +85 -35
  18. package/dist/subsystem/C4NodeCard.d.ts.map +1 -1
  19. package/dist/subsystem/C4NodeCard.js +112 -83
  20. package/dist/subsystem/C4NodeCard.js.map +1 -1
  21. package/dist/subsystem/FileDrawer.d.ts.map +1 -1
  22. package/dist/subsystem/FileDrawer.js +20 -21
  23. package/dist/subsystem/FileDrawer.js.map +1 -1
  24. package/dist/subsystem/IssueList.d.ts.map +1 -1
  25. package/dist/subsystem/IssueList.js +12 -3
  26. package/dist/subsystem/IssueList.js.map +1 -1
  27. package/dist/subsystem/SubsystemComponentGraph.d.ts.map +1 -1
  28. package/dist/subsystem/SubsystemComponentGraph.js +85 -7
  29. package/dist/subsystem/SubsystemComponentGraph.js.map +1 -1
  30. package/dist/subsystem/c4.d.ts +273 -0
  31. package/dist/subsystem/c4.d.ts.map +1 -0
  32. package/dist/subsystem/c4.js +322 -0
  33. package/dist/subsystem/c4.js.map +1 -0
  34. package/dist/subsystem/c4Evidence.d.ts +143 -0
  35. package/dist/subsystem/c4Evidence.d.ts.map +1 -0
  36. package/dist/subsystem/c4Evidence.js +240 -0
  37. package/dist/subsystem/c4Evidence.js.map +1 -0
  38. package/dist/subsystem/model.d.ts +2 -6
  39. package/dist/subsystem/model.d.ts.map +1 -1
  40. package/dist/subsystem/model.js.map +1 -1
  41. package/package.json +5 -4
  42. package/src/index.ts +26 -28
  43. package/src/pierre/PierreTrailCodeView.tsx +49 -21
  44. package/src/stories/Subsystem/C4Graph/C4NodeGallery.stories.tsx +171 -80
  45. package/src/stories/Subsystem/C4Graph/ProposedElements.stories.tsx +293 -0
  46. package/src/stories/Subsystem/C4Graph/c4ProposedElements.fixture.ts +366 -0
  47. package/src/stories/Subsystem/ComponentGraph/IssueOverlay.stories.tsx +1 -1
  48. package/src/stories/Subsystem/ComponentGraph/Issues.stories.tsx +169 -3
  49. package/src/subsystem/C4Graph.tsx +39 -24
  50. package/src/subsystem/C4NodeCard.test.ts +204 -62
  51. package/src/subsystem/C4NodeCard.tsx +146 -101
  52. package/src/subsystem/FileDrawer.tsx +32 -34
  53. package/src/subsystem/IssueList.tsx +13 -2
  54. package/src/subsystem/SubsystemComponentGraph.tsx +98 -7
  55. package/src/subsystem/c4.test.ts +573 -0
  56. package/src/subsystem/c4.ts +559 -0
  57. package/src/subsystem/c4Evidence.test.ts +386 -0
  58. package/src/subsystem/c4Evidence.ts +329 -0
  59. package/src/subsystem/model.ts +2 -6
  60. package/dist/stories/Subsystem/C4Graph/c4Associations.fixture.d.ts +0 -95
  61. package/dist/stories/Subsystem/C4Graph/c4Associations.fixture.d.ts.map +0 -1
  62. package/dist/stories/Subsystem/C4Graph/c4Associations.fixture.js +0 -340
  63. package/dist/stories/Subsystem/C4Graph/c4Associations.fixture.js.map +0 -1
  64. package/dist/stories/Subsystem/C4Graph/c4Fixture.d.ts +0 -7
  65. package/dist/stories/Subsystem/C4Graph/c4Fixture.d.ts.map +0 -1
  66. package/dist/stories/Subsystem/C4Graph/c4Fixture.js +0 -7335
  67. package/dist/stories/Subsystem/C4Graph/c4Fixture.js.map +0 -1
  68. package/dist/stories/Subsystem/C4Graph/generateFixture.d.ts +0 -2
  69. package/dist/stories/Subsystem/C4Graph/generateFixture.d.ts.map +0 -1
  70. package/dist/stories/Subsystem/C4Graph/generateFixture.js +0 -145
  71. package/dist/stories/Subsystem/C4Graph/generateFixture.js.map +0 -1
  72. package/dist/subsystem/c4Associations.d.ts +0 -186
  73. package/dist/subsystem/c4Associations.d.ts.map +0 -1
  74. package/dist/subsystem/c4Associations.js +0 -284
  75. package/dist/subsystem/c4Associations.js.map +0 -1
  76. package/dist/subsystem/toC4.d.ts +0 -214
  77. package/dist/subsystem/toC4.d.ts.map +0 -1
  78. package/dist/subsystem/toC4.js +0 -282
  79. package/dist/subsystem/toC4.js.map +0 -1
  80. package/src/stories/Subsystem/C4Graph/C4Associations.stories.tsx +0 -273
  81. package/src/stories/Subsystem/C4Graph/C4Container.stories.tsx +0 -101
  82. package/src/stories/Subsystem/C4Graph/c4Associations.fixture.ts +0 -344
  83. package/src/stories/Subsystem/C4Graph/c4Fixture.ts +0 -7339
  84. package/src/stories/Subsystem/C4Graph/generateFixture.ts +0 -161
  85. package/src/subsystem/c4Associations.test.ts +0 -484
  86. package/src/subsystem/c4Associations.ts +0 -398
  87. package/src/subsystem/toC4.test.ts +0 -114
  88. package/src/subsystem/toC4.ts +0 -478
@@ -0,0 +1,273 @@
1
+ /**
2
+ * C4 elements — the authored boxes on a diagram.
3
+ *
4
+ * A C4 diagram says something a code model cannot: *these* runs of code are
5
+ * one deployable unit, *this* component has no home, *this* external system is
6
+ * outside our boundary. That is an architectural judgement, and no amount of
7
+ * reading `process` strings will produce it — `process` answers "where does
8
+ * this run", which is a different question.
9
+ *
10
+ * So the element list is authored. An agent proposes it, a person confirms it,
11
+ * and `buildC4Model` does the only mechanical job left: draw the boxes the
12
+ * author named, and use the trails to draw the lines between them.
13
+ *
14
+ * ## Why a union and not one type with two axes
15
+ *
16
+ * C4's vocabulary is closed: software system, container, component, code —
17
+ * plus person outside the boundary. An earlier shape here carried a `level`
18
+ * (where it sits) and a `type` (what it is) as independent fields, which let
19
+ * combinations that mean nothing (`external` + `data-store`) and invented one
20
+ * that contradicts C4 (`library`, which is "typically not" an element at all).
21
+ *
22
+ * Four types carry only the fields the [C4 notation] requires for them:
23
+ *
24
+ * - technology is required on containers and components, optional on an
25
+ * external system, absent on a person
26
+ * - a component names its container, because a C4 component belongs to
27
+ * exactly one container
28
+ * - there is no `library` type; a package that is not a deployable unit is
29
+ * recorded as a review comment, not a new element kind
30
+ *
31
+ * [C4 notation]: https://c4model.com/diagrams/notation
32
+ */
33
+ import type { SubsystemComponent, SubsystemModelDocument } from './model';
34
+ /**
35
+ * Has anyone signed off on this element yet?
36
+ *
37
+ * `proposed` is what an agent writes and a human has not looked at. `accepted`
38
+ * is a human decision. `rejected` means the proposal was wrong and the box
39
+ * should not be drawn at all.
40
+ */
41
+ export type C4ElementState = 'proposed' | 'accepted' | 'rejected';
42
+ /** Fields every element carries, whatever its kind. */
43
+ interface C4ElementBase {
44
+ /**
45
+ * Stable identity: `container:studio-host`. Survives member churn, so a
46
+ * reviewer's accept/reject keeps pointing at the same box next week.
47
+ */
48
+ id: string;
49
+ /** Display name. */
50
+ label: string;
51
+ /**
52
+ * The component aliases that live directly inside this element.
53
+ *
54
+ * Named explicitly rather than derived from a `process` value, because two
55
+ * runs of code being one container is a judgement, not a lookup. This is also
56
+ * the dedup mechanism: two elements that should be one simply end up as one
57
+ * element holding both member sets.
58
+ *
59
+ * Each alias belongs to exactly one element. A container does *not* repeat
60
+ * the aliases its components already claim — `buildC4Model` rolls those up.
61
+ */
62
+ members: string[];
63
+ /**
64
+ * The `process` values this element consolidated, when it came from more than
65
+ * one. Purely provenance — it lets the confirm UI show "this box absorbed
66
+ * principal-studio/host". Never used to infer membership.
67
+ */
68
+ derivedFrom?: string[];
69
+ /** C4 asks every element to carry a one-line responsibility. */
70
+ description?: string;
71
+ state: C4ElementState;
72
+ /** Why this element is proposed as it is — shown in the confirm UI. */
73
+ rationale?: string;
74
+ /** Who or what authored it. */
75
+ author?: string;
76
+ /** When the state last changed (ISO). */
77
+ decidedAt?: string;
78
+ }
79
+ /**
80
+ * What kind of thing a container is.
81
+ *
82
+ * C4 recognises exactly two: an `application` (a deployable program) or a
83
+ * `data-store` (something the system reads or writes). There is deliberately
84
+ * no `queue` kind — c4model is explicit that an individual queue or topic *is*
85
+ * a data store, and that the message bus itself is not a container at all, so
86
+ * a queue is a `data-store` whose technology/label say "queue".
87
+ */
88
+ export type C4ContainerKind = 'application' | 'data-store';
89
+ /** A deployable unit or a store — the C4 level 2 box. */
90
+ export interface C4Container extends C4ElementBase {
91
+ kind: 'container';
92
+ /** What sort of container this is. */
93
+ containerKind: C4ContainerKind;
94
+ /** C4 requires a technology on every container. */
95
+ technology: string;
96
+ }
97
+ /**
98
+ * A functional grouping inside a container — the C4 level 3 box.
99
+ *
100
+ * `container` is required, not inferred. C4 says all components inside a
101
+ * container share one process space, so a component has exactly one parent;
102
+ * inferring it from member overlap gets that wrong whenever one concept is
103
+ * split across containers (an RPC bridge with a renderer half and a host half),
104
+ * which is precisely the case worth being able to state.
105
+ */
106
+ export interface C4Component extends C4ElementBase {
107
+ kind: 'component';
108
+ /** The id of the container this component sits inside. */
109
+ container: string;
110
+ /** C4 requires a technology on every component. */
111
+ technology: string;
112
+ }
113
+ /** A software system outside the boundary we are drawing. */
114
+ export interface C4ExternalSystem extends C4ElementBase {
115
+ kind: 'external-system';
116
+ /** Often unknown for a third-party system, so optional here. */
117
+ technology?: string;
118
+ }
119
+ /** A person. Outside the boundary, and never has technology. */
120
+ export interface C4Person extends C4ElementBase {
121
+ kind: 'person';
122
+ }
123
+ /** One element. Four kinds, no fifth. */
124
+ export type C4Element = C4Container | C4Component | C4ExternalSystem | C4Person;
125
+ /** A whole authored element list, for one repo or composed graph. */
126
+ export interface C4ElementSet {
127
+ /** Repo key this set describes, e.g. `pkg:github/owner/name`. */
128
+ repoKey: string;
129
+ /** ISO timestamp of the last change. */
130
+ updatedAt?: string;
131
+ elements: C4Element[];
132
+ }
133
+ /** Which level to draw. Determines which frames are drawn. */
134
+ export type C4View = 'container' | 'component';
135
+ /**
136
+ * A flattened element, as the renderer reads it.
137
+ *
138
+ * The union above is what an author writes; this is the one shape every box
139
+ * draws with, so the card does not branch on kind to find a label.
140
+ */
141
+ export interface C4Node {
142
+ id: string;
143
+ kind: C4Element['kind'];
144
+ /**
145
+ * Nesting parent: a component's container, a container or external system's
146
+ * frame, and nothing for a person — C4 puts people outside every system.
147
+ */
148
+ parentId?: string;
149
+ label: string;
150
+ technology?: string;
151
+ description?: string;
152
+ state: C4ElementState;
153
+ /** `application` / `data-store`. Set on containers only. */
154
+ containerKind?: C4ContainerKind;
155
+ /** Provenance, when the element consolidated several derived keys. */
156
+ derivedFrom?: string[];
157
+ /** Resolved members, when a document was supplied. A container's list includes its components'. */
158
+ members: string[];
159
+ /** Distinct constructs among resolved members. */
160
+ constructs: string[];
161
+ /** Present at component level when the document resolved it. */
162
+ component?: SubsystemComponent;
163
+ /** Source model ids that contributed members, when attribution is supplied. */
164
+ models?: string[];
165
+ }
166
+ /** A compound frame: the system, or a container holding its components. */
167
+ export interface C4Group {
168
+ id: string;
169
+ kind: 'system' | 'container';
170
+ label: string;
171
+ parentId?: string;
172
+ memberIds: string[];
173
+ }
174
+ /** A line between two elements, rolled up from a trail step. */
175
+ export interface C4Edge {
176
+ id: string;
177
+ source: string;
178
+ target: string;
179
+ label: string;
180
+ mechanisms: string[];
181
+ /** Trail steps that produced this line. */
182
+ count: number;
183
+ }
184
+ /** A drawable C4 projection. */
185
+ export interface C4Model {
186
+ view: C4View;
187
+ system: {
188
+ id: string;
189
+ label: string;
190
+ repoKey?: string;
191
+ };
192
+ nodes: C4Node[];
193
+ groups: C4Group[];
194
+ edges: C4Edge[];
195
+ }
196
+ /** Something an author should fix before this set is trusted. */
197
+ export type C4ProblemKind =
198
+ /** a member is claimed by two elements */
199
+ 'conflicting_member'
200
+ /** a member is not in the supplied document */
201
+ | 'unknown_member'
202
+ /** two elements share an id */
203
+ | 'duplicate_id'
204
+ /** an element that should have contents has none */
205
+ | 'empty_element'
206
+ /** a component names a container that is missing, or is not a container */
207
+ | 'unknown_container';
208
+ export interface C4Problem {
209
+ kind: C4ProblemKind;
210
+ message: string;
211
+ /** Alias for member problems, element id for the rest. */
212
+ subject: string;
213
+ }
214
+ export interface C4BuildResult {
215
+ model: C4Model;
216
+ /** Authoring mistakes. An empty array means the set is self-consistent. */
217
+ problems: C4Problem[];
218
+ /** Component aliases in the document that no element claims. */
219
+ unmapped: string[];
220
+ }
221
+ export interface C4BuildOptions {
222
+ /** The elements. The source of truth — nothing is invented. */
223
+ elements: readonly C4Element[];
224
+ /** Supply to resolve members and draw lines from trails. */
225
+ document?: SubsystemModelDocument;
226
+ view?: C4View;
227
+ /** Name of the system the elements sit in. */
228
+ systemLabel?: string;
229
+ /** Override the repo key (defaults to the first member's purl). */
230
+ repoKey?: string;
231
+ /** Model-id attribution per component alias. */
232
+ modelsByAlias?: Record<string, string[]>;
233
+ }
234
+ /** True when this element kind is drawn inside the system frame. */
235
+ export declare function isInBoundary(e: C4Element): boolean;
236
+ /** `owner/name` from a purl, trimmed of scheme and fragment. */
237
+ export declare function labelFromPurl(purl: string): string;
238
+ /**
239
+ * Build the drawable projection from authored elements.
240
+ *
241
+ * A plain join with no architectural judgement:
242
+ *
243
+ * boxes ← one per element, named and placed by the author
244
+ * lines ← trail steps, with each endpoint mapped to its owning element
245
+ *
246
+ * Trail steps whose endpoints are not claimed by any element are skipped:
247
+ * drawing them would assert a relationship the author did not describe.
248
+ */
249
+ export declare function buildC4Model(options: C4BuildOptions): C4BuildResult;
250
+ /**
251
+ * Tally for the confirm UI: how much is proposed vs accepted, and how much is
252
+ * still missing what the C4 notation requires.
253
+ *
254
+ * Counts the authored set, not the projection — a rejected element is still a
255
+ * decision that was made, so it is reported rather than forgotten.
256
+ */
257
+ export declare function summarizeElements(elements: readonly C4Element[]): {
258
+ containers: number;
259
+ components: number;
260
+ externals: number;
261
+ people: number;
262
+ accepted: number;
263
+ proposed: number;
264
+ rejected: number;
265
+ /** Containers missing the technology C4 requires. */
266
+ missingTechnology: number;
267
+ /** Elements missing a description. */
268
+ missingDescription: number;
269
+ /** Elements whose state is not yet `accepted`. */
270
+ needsDecision: number;
271
+ };
272
+ export {};
273
+ //# sourceMappingURL=c4.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"c4.d.ts","sourceRoot":"","sources":["../../src/subsystem/c4.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAE1E;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,UAAU,GAAG,UAAU,CAAC;AAElE,uDAAuD;AACvD,UAAU,aAAa;IACrB;;;OAGG;IACH,EAAE,EAAE,MAAM,CAAC;IACX,oBAAoB;IACpB,KAAK,EAAE,MAAM,CAAC;IACd;;;;;;;;;;OAUG;IACH,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,gEAAgE;IAChE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,cAAc,CAAC;IACtB,uEAAuE;IACvE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+BAA+B;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,yCAAyC;IACzC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,eAAe,GA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,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,qDAAqD;IACrD,iBAAiB,EAAE,MAAM,CAAC;IAC1B,sCAAsC;IACtC,kBAAkB,EAAE,MAAM,CAAC;IAC3B,kDAAkD;IAClD,aAAa,EAAE,MAAM,CAAC;CACvB,CAgBA"}
@@ -0,0 +1,322 @@
1
+ /**
2
+ * C4 elements — the authored boxes on a diagram.
3
+ *
4
+ * A C4 diagram says something a code model cannot: *these* runs of code are
5
+ * one deployable unit, *this* component has no home, *this* external system is
6
+ * outside our boundary. That is an architectural judgement, and no amount of
7
+ * reading `process` strings will produce it — `process` answers "where does
8
+ * this run", which is a different question.
9
+ *
10
+ * So the element list is authored. An agent proposes it, a person confirms it,
11
+ * and `buildC4Model` does the only mechanical job left: draw the boxes the
12
+ * author named, and use the trails to draw the lines between them.
13
+ *
14
+ * ## Why a union and not one type with two axes
15
+ *
16
+ * C4's vocabulary is closed: software system, container, component, code —
17
+ * plus person outside the boundary. An earlier shape here carried a `level`
18
+ * (where it sits) and a `type` (what it is) as independent fields, which let
19
+ * combinations that mean nothing (`external` + `data-store`) and invented one
20
+ * that contradicts C4 (`library`, which is "typically not" an element at all).
21
+ *
22
+ * Four types carry only the fields the [C4 notation] requires for them:
23
+ *
24
+ * - technology is required on containers and components, optional on an
25
+ * external system, absent on a person
26
+ * - a component names its container, because a C4 component belongs to
27
+ * exactly one container
28
+ * - there is no `library` type; a package that is not a deployable unit is
29
+ * recorded as a review comment, not a new element kind
30
+ *
31
+ * [C4 notation]: https://c4model.com/diagrams/notation
32
+ */
33
+ /**
34
+ * Element kinds drawn inside the system boundary.
35
+ *
36
+ * A C4 container diagram puts external systems *inside* the boundary: they are
37
+ * things this system depends on, drawn as containers we do not own. People go
38
+ * outside it, because a person is never part of any system.
39
+ */
40
+ const IN_BOUNDARY = new Set(['container', 'external-system']);
41
+ /** True when this element kind is drawn inside the system frame. */
42
+ export function isInBoundary(e) {
43
+ return IN_BOUNDARY.has(e.kind);
44
+ }
45
+ function purlRepoKey(purl) {
46
+ const p = (purl ?? '').split('#')[0]?.trim();
47
+ if (!p || p === 'external' || p.startsWith('external:'))
48
+ return undefined;
49
+ return p;
50
+ }
51
+ /** `owner/name` from a purl, trimmed of scheme and fragment. */
52
+ export function labelFromPurl(purl) {
53
+ const base = purl.replace(/^external:/, '').split('#')[0]?.trim() ?? '';
54
+ const parts = base.split('/').filter(Boolean);
55
+ return parts.slice(-2).join('/') || base || purl;
56
+ }
57
+ /**
58
+ * Build the drawable projection from authored elements.
59
+ *
60
+ * A plain join with no architectural judgement:
61
+ *
62
+ * boxes ← one per element, named and placed by the author
63
+ * lines ← trail steps, with each endpoint mapped to its owning element
64
+ *
65
+ * Trail steps whose endpoints are not claimed by any element are skipped:
66
+ * drawing them would assert a relationship the author did not describe.
67
+ */
68
+ export function buildC4Model(options) {
69
+ const view = options.view ?? 'container';
70
+ const doc = options.document;
71
+ const problems = [];
72
+ const byAlias = new Map(doc?.components.map((c) => [c.alias, c]) ?? []);
73
+ /**
74
+ * Alias → owning element, innermost home wins. One owner per alias: this is
75
+ * what makes `conflicting_member` mean "two boxes disagree" rather than
76
+ * "a container and its components both mention the same code".
77
+ */
78
+ const membersOf = new Map();
79
+ // --- accept each element once, and resolve membership --------------------
80
+ const seenIds = new Set();
81
+ /** alias → element id. One owner per alias; conflicts are reported. */
82
+ const ownerOf = new Map();
83
+ /** Ids in authored order, duplicates dropped. */
84
+ const accepted = [];
85
+ const elementById = new Map();
86
+ for (const e of options.elements) {
87
+ if (seenIds.has(e.id)) {
88
+ problems.push({
89
+ kind: 'duplicate_id',
90
+ subject: e.id,
91
+ message: `two elements share the id ${e.id}`,
92
+ });
93
+ continue;
94
+ }
95
+ seenIds.add(e.id);
96
+ accepted.push(e.id);
97
+ elementById.set(e.id, e);
98
+ // A rejected element is not drawn, so its members are inside nothing.
99
+ // Leaving them claimed would hide them from `unmapped` and quietly hide
100
+ // the fact that rejecting an element orphans whatever was in it.
101
+ if (e.state === 'rejected')
102
+ continue;
103
+ for (const alias of e.members) {
104
+ if (doc && !byAlias.has(alias)) {
105
+ problems.push({
106
+ kind: 'unknown_member',
107
+ subject: alias,
108
+ message: `element "${e.id}" claims "${alias}", which is not in the supplied document`,
109
+ });
110
+ continue;
111
+ }
112
+ const existing = ownerOf.get(alias);
113
+ if (existing && existing !== e.id) {
114
+ problems.push({
115
+ kind: 'conflicting_member',
116
+ subject: alias,
117
+ message: `"${alias}" is claimed by both ${existing} and ${e.id}; it is drawn inside ${existing}`,
118
+ });
119
+ continue;
120
+ }
121
+ ownerOf.set(alias, e.id);
122
+ const list = membersOf.get(e.id) ?? [];
123
+ list.push(alias);
124
+ membersOf.set(e.id, list);
125
+ }
126
+ }
127
+ // --- the system boundary -------------------------------------------------
128
+ const repoKey = options.repoKey ??
129
+ options.elements
130
+ .flatMap((e) => e.members)
131
+ .map((alias) => purlRepoKey(byAlias.get(alias)?.purl))
132
+ .find(Boolean);
133
+ const systemId = `system:${repoKey ?? 'unspecified'}`;
134
+ const systemLabel = options.systemLabel ?? (repoKey ? labelFromPurl(repoKey) : 'Software System');
135
+ // --- draw the boxes ------------------------------------------------------
136
+ const nodes = [];
137
+ /**
138
+ * The aliases an element claimed itself, before any rollup. A component's
139
+ * own members and its container's own members are disjoint by construction,
140
+ * which is what lets the two be added together below.
141
+ */
142
+ const ownMembers = new Map();
143
+ for (const id of accepted) {
144
+ const e = elementById.get(id);
145
+ if (e.state === 'rejected')
146
+ continue;
147
+ const own = membersOf.get(id) ?? [];
148
+ // A component's parent is stated, not inferred. Check it resolves: a
149
+ // dangling parent would silently drop the component out of every frame.
150
+ let parentId;
151
+ if (e.kind === 'component') {
152
+ const parent = elementById.get(e.container);
153
+ if (!parent || parent.state === 'rejected') {
154
+ problems.push({
155
+ kind: 'unknown_container',
156
+ subject: id,
157
+ message: `component "${id}" names container "${e.container}", which is not in this set`,
158
+ });
159
+ }
160
+ else if (parent.kind !== 'container') {
161
+ problems.push({
162
+ kind: 'unknown_container',
163
+ subject: id,
164
+ message: `component "${id}" names container "${e.container}", which is a ${parent.kind}, not a container`,
165
+ });
166
+ }
167
+ else {
168
+ parentId = parent.id;
169
+ }
170
+ }
171
+ else if (isInBoundary(e)) {
172
+ parentId = systemId;
173
+ }
174
+ ownMembers.set(id, own);
175
+ nodes.push({
176
+ id: e.id,
177
+ kind: e.kind,
178
+ label: e.label,
179
+ ...(parentId ? { parentId } : {}),
180
+ technology: 'technology' in e ? e.technology : undefined,
181
+ description: e.description,
182
+ state: e.state,
183
+ ...(e.kind === 'container' ? { containerKind: e.containerKind } : {}),
184
+ ...(e.derivedFrom && e.derivedFrom.length > 1 ? { derivedFrom: e.derivedFrom } : {}),
185
+ members: own,
186
+ constructs: [],
187
+ });
188
+ }
189
+ // --- roll components up into their container ------------------------------
190
+ //
191
+ // A C4 container diagram draws the container as a whole, so a container
192
+ // holds everything inside its components. Membership is still authored
193
+ // exactly once: an alias belongs to one element, so a container must not
194
+ // repeat what its components already claim — that repetition would read as
195
+ // a `conflicting_member` and hide the real question, which is how many
196
+ // components a container has.
197
+ for (const n of nodes) {
198
+ if (n.kind !== 'component' || !n.parentId)
199
+ continue;
200
+ const list = membersOf.get(n.parentId) ?? [];
201
+ list.push(...(ownMembers.get(n.id) ?? []));
202
+ membersOf.set(n.parentId, list);
203
+ }
204
+ for (const n of nodes) {
205
+ n.members = membersOf.get(n.id) ?? [];
206
+ if (n.members.length === 0) {
207
+ problems.push({
208
+ kind: 'empty_element',
209
+ subject: n.id,
210
+ message: `element "${n.id}" (${n.kind}) claims no members, and nothing is inside it either, so there is nothing to draw`,
211
+ });
212
+ }
213
+ const resolved = n.members.map((m) => byAlias.get(m)).filter((c) => !!c);
214
+ const constructs = [];
215
+ for (const c of resolved)
216
+ if (!constructs.includes(c.construct))
217
+ constructs.push(c.construct);
218
+ n.constructs = constructs;
219
+ if (n.kind === 'component' && resolved[0])
220
+ n.component = resolved[0];
221
+ const models = [...new Set(n.members.flatMap((m) => options.modelsByAlias?.[m] ?? []))];
222
+ if (models.length > 0)
223
+ n.models = models;
224
+ }
225
+ // --- compound frames -----------------------------------------------------
226
+ const groups = [];
227
+ if (view === 'container') {
228
+ const containerIds = nodes.filter((n) => n.kind === 'container').map((n) => n.id);
229
+ if (containerIds.length > 0) {
230
+ groups.push({ id: systemId, kind: 'system', label: systemLabel, memberIds: containerIds });
231
+ }
232
+ }
233
+ else {
234
+ const byContainer = new Map();
235
+ for (const n of nodes) {
236
+ if (n.kind !== 'component' || !n.parentId)
237
+ continue;
238
+ const list = byContainer.get(n.parentId) ?? [];
239
+ list.push(n.id);
240
+ byContainer.set(n.parentId, list);
241
+ }
242
+ const framed = [];
243
+ for (const [id, memberIds] of byContainer) {
244
+ const label = nodes.find((n) => n.id === id)?.label ?? id;
245
+ groups.push({ id, kind: 'container', label, parentId: systemId, memberIds });
246
+ framed.push(id);
247
+ }
248
+ if (framed.length > 0) {
249
+ groups.push({ id: systemId, kind: 'system', label: systemLabel, memberIds: framed });
250
+ }
251
+ }
252
+ // --- lines, from the trails ---------------------------------------------
253
+ const drawn = new Set(nodes.map((n) => n.id));
254
+ const edges = new Map();
255
+ for (const trail of doc?.trails ?? []) {
256
+ for (const step of trail.steps ?? []) {
257
+ const source = ownerOf.get(step.from);
258
+ const target = ownerOf.get(step.to);
259
+ // An endpoint no element claims has no box, so there is no line to draw.
260
+ if (!source || !target || source === target)
261
+ continue;
262
+ if (!drawn.has(source) || !drawn.has(target))
263
+ continue;
264
+ const key = `${source}\0${target}`;
265
+ const edge = edges.get(key);
266
+ if (edge) {
267
+ edge.count += 1;
268
+ if (!edge.mechanisms.includes(step.mechanism))
269
+ edge.mechanisms.push(step.mechanism);
270
+ }
271
+ else {
272
+ edges.set(key, {
273
+ id: `flow:${key}`,
274
+ source,
275
+ target,
276
+ label: step.mechanism,
277
+ mechanisms: [step.mechanism],
278
+ count: 1,
279
+ });
280
+ }
281
+ }
282
+ }
283
+ for (const e of edges.values())
284
+ e.label = [...e.mechanisms].sort().join(' + ');
285
+ const unmapped = (doc?.components ?? []).filter((c) => !ownerOf.has(c.alias)).map((c) => c.alias);
286
+ return {
287
+ model: {
288
+ view,
289
+ system: { id: systemId, label: systemLabel, repoKey },
290
+ nodes,
291
+ groups,
292
+ edges: [...edges.values()],
293
+ },
294
+ problems,
295
+ unmapped,
296
+ };
297
+ }
298
+ /**
299
+ * Tally for the confirm UI: how much is proposed vs accepted, and how much is
300
+ * still missing what the C4 notation requires.
301
+ *
302
+ * Counts the authored set, not the projection — a rejected element is still a
303
+ * decision that was made, so it is reported rather than forgotten.
304
+ */
305
+ export function summarizeElements(elements) {
306
+ const live = elements.filter((e) => e.state !== 'rejected');
307
+ return {
308
+ containers: live.filter((e) => e.kind === 'container').length,
309
+ components: live.filter((e) => e.kind === 'component').length,
310
+ externals: live.filter((e) => e.kind === 'external-system').length,
311
+ people: live.filter((e) => e.kind === 'person').length,
312
+ accepted: live.filter((e) => e.state === 'accepted').length,
313
+ proposed: live.filter((e) => e.state === 'proposed').length,
314
+ rejected: elements.filter((e) => e.state === 'rejected').length,
315
+ // `technology` is required by the type on containers and components, so a
316
+ // missing one can only mean an empty string — still worth reporting.
317
+ missingTechnology: live.filter((e) => 'technology' in e && !e.technology).length,
318
+ missingDescription: live.filter((e) => !e.description).length,
319
+ needsDecision: live.filter((e) => e.state !== 'accepted').length,
320
+ };
321
+ }
322
+ //# sourceMappingURL=c4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"c4.js","sourceRoot":"","sources":["../../src/subsystem/c4.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AA0NH;;;;;;GAMG;AACH,MAAM,WAAW,GAAG,IAAI,GAAG,CAAoB,CAAC,WAAW,EAAE,iBAAiB,CAAC,CAAC,CAAC;AAEjF,oEAAoE;AACpE,MAAM,UAAU,YAAY,CAAC,CAAY;IACvC,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,IA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