@principal-ai/subsystems-react 0.51.4 → 0.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/subsystem/C4Graph.d.ts +3 -7
- package/dist/subsystem/C4Graph.d.ts.map +1 -1
- package/dist/subsystem/C4Graph.js +159 -45
- package/dist/subsystem/C4Graph.js.map +1 -1
- package/dist/subsystem/C4NodeCard.d.ts +26 -26
- package/dist/subsystem/C4NodeCard.d.ts.map +1 -1
- package/dist/subsystem/C4NodeCard.js +56 -30
- package/dist/subsystem/C4NodeCard.js.map +1 -1
- package/dist/subsystem/IssueList.d.ts +1 -1
- package/dist/subsystem/IssueList.d.ts.map +1 -1
- package/dist/subsystem/IssueList.js +20 -1
- package/dist/subsystem/IssueList.js.map +1 -1
- package/dist/subsystem/SubsystemComponentGraph.d.ts.map +1 -1
- package/dist/subsystem/SubsystemComponentGraph.js +42 -19
- package/dist/subsystem/SubsystemComponentGraph.js.map +1 -1
- package/dist/subsystem/c4.d.ts +48 -49
- package/dist/subsystem/c4.d.ts.map +1 -1
- package/dist/subsystem/c4.js +50 -0
- package/dist/subsystem/c4.js.map +1 -1
- package/dist/subsystem/c4Evidence.d.ts +88 -84
- package/dist/subsystem/c4Evidence.d.ts.map +1 -1
- package/dist/subsystem/c4Evidence.js +113 -166
- package/dist/subsystem/c4Evidence.js.map +1 -1
- package/dist/subsystem/nodes.js +5 -5
- package/dist/subsystem/nodes.js.map +1 -1
- package/dist/subsystem/techIcons/index.d.ts +5 -0
- package/dist/subsystem/techIcons/index.d.ts.map +1 -1
- package/dist/subsystem/techIcons/index.js +3 -0
- package/dist/subsystem/techIcons/index.js.map +1 -1
- package/dist/utils/edgeLabel.d.ts +15 -1
- package/dist/utils/edgeLabel.d.ts.map +1 -1
- package/dist/utils/edgeLabel.js +25 -1
- package/dist/utils/edgeLabel.js.map +1 -1
- package/dist/utils/elkLayout.d.ts +47 -0
- package/dist/utils/elkLayout.d.ts.map +1 -1
- package/dist/utils/elkLayout.js +71 -7
- package/dist/utils/elkLayout.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +8 -6
- package/src/stories/Subsystem/C4Graph/C4Component.stories.tsx +198 -0
- package/src/stories/Subsystem/C4Graph/C4Container.stories.tsx +42 -6
- package/src/stories/Subsystem/C4Graph/C4NodeGallery.stories.tsx +9 -7
- package/src/stories/Subsystem/ComponentGraph/Issues.stories.tsx +686 -2
- package/src/subsystem/C4Graph.tsx +242 -82
- package/src/subsystem/C4NodeCard.test.ts +32 -22
- package/src/subsystem/C4NodeCard.tsx +67 -39
- package/src/subsystem/IssueList.tsx +23 -0
- package/src/subsystem/SubsystemComponentGraph.tsx +38 -16
- package/src/subsystem/c4.protocolColor.test.ts +26 -0
- package/src/subsystem/c4.ts +76 -52
- package/src/subsystem/c4Evidence.test.ts +177 -237
- package/src/subsystem/c4Evidence.ts +160 -235
- package/src/subsystem/nodes.group.test.tsx +15 -0
- package/src/subsystem/nodes.tsx +7 -7
- package/src/subsystem/techIcons/index.tsx +8 -0
- package/src/utils/edgeLabel.test.ts +21 -2
- package/src/utils/edgeLabel.ts +29 -1
- package/src/utils/elkLayout.test.ts +16 -0
- package/src/utils/elkLayout.ts +119 -7
- package/src/stories/Subsystem/ComponentGraph/IssueOverlay.stories.tsx +0 -602
|
@@ -16,7 +16,7 @@ import { useTheme } from '@principal-ade/industry-theme';
|
|
|
16
16
|
import { AppWindow, Database } from 'lucide-react';
|
|
17
17
|
import type { LucideIcon } from 'lucide-react';
|
|
18
18
|
import { TechMark, technologyBrand } from './techIcons';
|
|
19
|
-
import type {
|
|
19
|
+
import type { C4Element } from './c4';
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Card box for a container: a wide rectangle. A container carries four things
|
|
@@ -38,7 +38,7 @@ export const COMPONENT_SIZE = 140;
|
|
|
38
38
|
* Per-level box size. The graph lays out against these, so a square component
|
|
39
39
|
* and a rectangular container do not collide at a shared nominal width.
|
|
40
40
|
*/
|
|
41
|
-
export function nodeSize(node:
|
|
41
|
+
export function nodeSize(node: C4Element): { width: number; height: number } {
|
|
42
42
|
return node.kind === 'component'
|
|
43
43
|
? { width: COMPONENT_SIZE, height: COMPONENT_SIZE }
|
|
44
44
|
: { width: NODE_W, height: NODE_H };
|
|
@@ -59,35 +59,50 @@ export interface NodeStyle {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
|
-
* Border style for one node: colour
|
|
63
|
-
* and level.
|
|
62
|
+
* Border style for one node: colour from **technology**, dash and weight from
|
|
63
|
+
* **confirmation state** and level.
|
|
64
64
|
*
|
|
65
|
-
* One axis per channel, so nothing is said twice
|
|
65
|
+
* One axis per channel, so nothing is said twice:
|
|
66
66
|
*
|
|
67
|
-
* colour
|
|
67
|
+
* colour → technology (the brand hue; see `technologyBrand`)
|
|
68
|
+
* dash → confirmation state (solid accepted, dashed proposed)
|
|
68
69
|
* weight → C4 level, as a grayscale redundancy for the square
|
|
69
70
|
* shape + size → C4 kind (`nodeShape`, `nodeSize`)
|
|
70
71
|
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
* the border says who vouched for it.
|
|
72
|
+
* Colour moved from state to technology: on a container diagram the reader
|
|
73
|
+
* wants "is this Bun or React" at a glance, and the state already reads off the
|
|
74
|
+
* dash. A selected node overrides colour so a click target stands out.
|
|
75
75
|
*/
|
|
76
|
-
|
|
76
|
+
/** The technology string for an element, if its kind has one. */
|
|
77
|
+
export function nodeTechnology(node: C4Element): string | undefined {
|
|
78
|
+
switch (node.kind) {
|
|
79
|
+
case 'container':
|
|
80
|
+
case 'component':
|
|
81
|
+
return node.technology;
|
|
82
|
+
case 'external-system':
|
|
83
|
+
return node.technology;
|
|
84
|
+
case 'person':
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function nodeStyle(node: C4Element, theme: Theme, selected = false): NodeStyle {
|
|
77
90
|
const muted = theme.colors.border ?? '#555';
|
|
91
|
+
const techColor = technologyBrand(nodeTechnology(node))?.color;
|
|
78
92
|
if (selected) return { color: theme.colors.primary ?? '#5aa', dash: 'solid', width: 3 };
|
|
79
93
|
|
|
80
94
|
// Border weight carries the level, so a component stays a component even
|
|
81
95
|
// in grayscale or for a reader who cannot separate the hues.
|
|
82
96
|
const weight = node.kind === 'component' ? 1 : 2;
|
|
97
|
+
const color = techColor ?? muted;
|
|
83
98
|
|
|
84
99
|
switch (node.state) {
|
|
85
100
|
case 'accepted':
|
|
86
|
-
// Solid
|
|
87
|
-
return { color
|
|
101
|
+
// Solid — part of the architecture now.
|
|
102
|
+
return { color, dash: 'solid', width: weight };
|
|
88
103
|
case 'proposed':
|
|
89
104
|
// Dashed — an agent asked; a human has not answered.
|
|
90
|
-
return { color
|
|
105
|
+
return { color, dash: 'dashed', width: weight };
|
|
91
106
|
case 'rejected':
|
|
92
107
|
// Should never be drawn (a rejected element is not projected); belt-and-braces.
|
|
93
108
|
return { color: muted, dash: 'dotted', width: 1 };
|
|
@@ -99,7 +114,7 @@ export function nodeStyle(node: C4Node, theme: Theme, selected = false): NodeSty
|
|
|
99
114
|
* asks every element to carry. No fallback — when nothing is stated, the
|
|
100
115
|
* notation-gap row says so rather than the card inventing a summary.
|
|
101
116
|
*/
|
|
102
|
-
export function nodeSubtitle(node:
|
|
117
|
+
export function nodeSubtitle(node: C4Element): string {
|
|
103
118
|
return node.description ?? '';
|
|
104
119
|
}
|
|
105
120
|
|
|
@@ -109,7 +124,7 @@ export function nodeSubtitle(node: C4Node): string {
|
|
|
109
124
|
* Confirmation state is a separate axis carried by the border (see
|
|
110
125
|
* `nodeStyle`), not by a word on the card.
|
|
111
126
|
*/
|
|
112
|
-
export function nodeTag(node:
|
|
127
|
+
export function nodeTag(node: C4Element): string {
|
|
113
128
|
return node.kind;
|
|
114
129
|
}
|
|
115
130
|
|
|
@@ -119,11 +134,17 @@ export function nodeTag(node: C4Node): string {
|
|
|
119
134
|
* The C4 kind itself does not need a glyph — the box shape already carries it
|
|
120
135
|
* (square vs rectangle vs pill), and the row's one text slot is worth more
|
|
121
136
|
* spent on the technology. Only containers have a C4-recognised split, so the
|
|
122
|
-
* other
|
|
137
|
+
* other kinds return nothing.
|
|
123
138
|
*/
|
|
124
|
-
export function nodeKindIcon(node:
|
|
125
|
-
|
|
126
|
-
|
|
139
|
+
export function nodeKindIcon(node: C4Element): LucideIcon | undefined {
|
|
140
|
+
switch (node.kind) {
|
|
141
|
+
case 'container':
|
|
142
|
+
return node.containerKind === 'data-store' ? Database : AppWindow;
|
|
143
|
+
case 'component':
|
|
144
|
+
case 'external-system':
|
|
145
|
+
case 'person':
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
127
148
|
}
|
|
128
149
|
|
|
129
150
|
/**
|
|
@@ -131,9 +152,17 @@ export function nodeKindIcon(node: C4Node): LucideIcon | undefined {
|
|
|
131
152
|
* Postgres…). Falls back to the container kind / C4 kind when no technology is
|
|
132
153
|
* stated, so the row is never blank.
|
|
133
154
|
*/
|
|
134
|
-
export function nodeTopLabel(node:
|
|
135
|
-
|
|
136
|
-
|
|
155
|
+
export function nodeTopLabel(node: C4Element): string {
|
|
156
|
+
const technology = nodeTechnology(node);
|
|
157
|
+
if (technology) return technology;
|
|
158
|
+
switch (node.kind) {
|
|
159
|
+
case 'container':
|
|
160
|
+
return node.containerKind;
|
|
161
|
+
case 'component':
|
|
162
|
+
case 'external-system':
|
|
163
|
+
case 'person':
|
|
164
|
+
return node.kind;
|
|
165
|
+
}
|
|
137
166
|
}
|
|
138
167
|
|
|
139
168
|
/** How a box is drawn. Shape carries the C4 kind, independent of colour. */
|
|
@@ -151,26 +180,24 @@ export interface NodeShape {
|
|
|
151
180
|
*
|
|
152
181
|
* The convention:
|
|
153
182
|
*
|
|
154
|
-
* container wide rectangle,
|
|
183
|
+
* container wide rectangle, slight radius — a runtime boundary
|
|
155
184
|
* component square — a part inside one (see `nodeSize`)
|
|
156
|
-
* external system wide rectangle,
|
|
185
|
+
* external system wide rectangle, no radius — someone else's system
|
|
157
186
|
* person pill — not a box at all
|
|
158
187
|
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
* already spent on proposed-vs-accepted. The kind icon says it, and the frame
|
|
163
|
-
* position says it structurally.
|
|
188
|
+
* A container keeps a slight radius; an external system is drawn with none, so
|
|
189
|
+
* the two are distinguishable by corner treatment as well as by the kind icon
|
|
190
|
+
* and frame position. The border dash stays spent on proposed-vs-accepted.
|
|
164
191
|
*/
|
|
165
|
-
export function nodeShape(node:
|
|
192
|
+
export function nodeShape(node: C4Element): NodeShape {
|
|
166
193
|
switch (node.kind) {
|
|
167
194
|
case 'person':
|
|
168
195
|
return { kind: 'pill', radius: NODE_H / 2 };
|
|
169
196
|
case 'external-system':
|
|
170
|
-
return { kind: 'rect', radius:
|
|
197
|
+
return { kind: 'rect', radius: 0 };
|
|
171
198
|
case 'component':
|
|
172
199
|
return { kind: 'square', radius: 6 };
|
|
173
|
-
|
|
200
|
+
case 'container':
|
|
174
201
|
return { kind: 'rect', radius: 4 };
|
|
175
202
|
}
|
|
176
203
|
}
|
|
@@ -184,7 +211,7 @@ export function nodeShape(node: C4Node): NodeShape {
|
|
|
184
211
|
* component drawn without a parent already reports `unknown_container`, and
|
|
185
212
|
* that is the question worth asking first.
|
|
186
213
|
*/
|
|
187
|
-
export function nodeMissing(node:
|
|
214
|
+
export function nodeMissing(node: C4Element): string[] {
|
|
188
215
|
if (node.kind !== 'container') return [];
|
|
189
216
|
const missing: string[] = [];
|
|
190
217
|
if (!node.technology) missing.push('technology');
|
|
@@ -193,7 +220,7 @@ export function nodeMissing(node: C4Node): string[] {
|
|
|
193
220
|
}
|
|
194
221
|
|
|
195
222
|
export interface C4NodeCardProps {
|
|
196
|
-
node:
|
|
223
|
+
node: C4Element;
|
|
197
224
|
selected?: boolean;
|
|
198
225
|
/** Draw React Flow's edge handles. Off when rendering a bare gallery. */
|
|
199
226
|
handles?: React.ReactNode;
|
|
@@ -206,7 +233,7 @@ export function C4NodeCard({ node, selected = false, handles, onClick }: C4NodeC
|
|
|
206
233
|
const style = nodeStyle(node, theme, selected);
|
|
207
234
|
const shape = nodeShape(node);
|
|
208
235
|
const Icon = nodeKindIcon(node);
|
|
209
|
-
const brand = technologyBrand(node
|
|
236
|
+
const brand = technologyBrand(nodeTechnology(node));
|
|
210
237
|
const topLabel = nodeTopLabel(node);
|
|
211
238
|
const subtitle = nodeSubtitle(node);
|
|
212
239
|
|
|
@@ -232,7 +259,7 @@ export function C4NodeCard({ node, selected = false, handles, onClick }: C4NodeC
|
|
|
232
259
|
padding: centered ? '10px 30px' : '10px 12px',
|
|
233
260
|
borderRadius: shape.radius,
|
|
234
261
|
background: theme.colors.backgroundSecondary ?? theme.colors.background,
|
|
235
|
-
border: `${style.width} ${style.dash} ${style.color}`,
|
|
262
|
+
border: `${style.width}px ${style.dash} ${style.color}`,
|
|
236
263
|
boxShadow: '0 1px 4px rgba(0,0,0,0.25)',
|
|
237
264
|
cursor: onClick ? 'pointer' : 'default',
|
|
238
265
|
fontFamily: theme.fonts.body,
|
|
@@ -272,8 +299,8 @@ export function C4NodeCard({ node, selected = false, handles, onClick }: C4NodeC
|
|
|
272
299
|
</span>
|
|
273
300
|
{Icon && (
|
|
274
301
|
<span
|
|
275
|
-
title={node.containerKind
|
|
276
|
-
aria-label={node.containerKind
|
|
302
|
+
title={node.kind === 'container' ? node.containerKind : node.kind}
|
|
303
|
+
aria-label={node.kind === 'container' ? node.containerKind : node.kind}
|
|
277
304
|
style={{ display: 'inline-flex', flexShrink: 0, color: style.color }}
|
|
278
305
|
>
|
|
279
306
|
<Icon size={13} strokeWidth={2.25} />
|
|
@@ -286,6 +313,7 @@ export function C4NodeCard({ node, selected = false, handles, onClick }: C4NodeC
|
|
|
286
313
|
below sits at the same y on every card. */}
|
|
287
314
|
<span
|
|
288
315
|
style={{
|
|
316
|
+
fontFamily: theme.fonts.body,
|
|
289
317
|
fontWeight: 600,
|
|
290
318
|
fontSize: theme.fontSizes[2],
|
|
291
319
|
color: theme.colors.text,
|
|
@@ -17,7 +17,10 @@ import {
|
|
|
17
17
|
ChevronDown,
|
|
18
18
|
ChevronRight,
|
|
19
19
|
CircleCheck,
|
|
20
|
+
CircleDashed,
|
|
21
|
+
CircleEllipsis,
|
|
20
22
|
CircleHelp,
|
|
23
|
+
CircleX,
|
|
21
24
|
Component,
|
|
22
25
|
FileX,
|
|
23
26
|
FolderGit2,
|
|
@@ -41,6 +44,7 @@ export type SubsystemIssueSeverity = 'error' | 'info';
|
|
|
41
44
|
export type SubsystemIssueTargetKind =
|
|
42
45
|
| 'component'
|
|
43
46
|
| 'module'
|
|
47
|
+
| 'process'
|
|
44
48
|
| 'trail'
|
|
45
49
|
| 'step'
|
|
46
50
|
| 'repo'
|
|
@@ -105,6 +109,12 @@ const KIND_CATEGORY: Record<string, SubsystemIssueCategory> = {
|
|
|
105
109
|
graphify_unavailable: 'repo',
|
|
106
110
|
boundary_module_file_mismatch: 'static-topology',
|
|
107
111
|
boundary_process_nest_disagree: 'dynamic-topology',
|
|
112
|
+
// C4 process verification (verifyProcessBoundaries): a boundary whose
|
|
113
|
+
// container claim is not an accepted one. `verified` reports nothing —
|
|
114
|
+
// the audit reports absence only.
|
|
115
|
+
boundary_process_unassigned: 'dynamic-topology',
|
|
116
|
+
boundary_process_proposed: 'dynamic-topology',
|
|
117
|
+
boundary_process_rejected: 'dynamic-topology',
|
|
108
118
|
trail: 'trail',
|
|
109
119
|
step_unconfirmed: 'trail',
|
|
110
120
|
step_stale: 'trail',
|
|
@@ -168,6 +178,11 @@ export const ISSUE_KIND_ICON: Record<string, LucideIcon> = {
|
|
|
168
178
|
// One module, more than one claimed process parent — a containment that can't
|
|
169
179
|
// be drawn, which is why the region sits at the root instead of nested.
|
|
170
180
|
boundary_process_nest_disagree: Split,
|
|
181
|
+
// C4 process verification: unclaimed = no container at all, proposed = an
|
|
182
|
+
// agent scaffold awaits a decision, rejected = a container was declined.
|
|
183
|
+
boundary_process_unassigned: CircleEllipsis,
|
|
184
|
+
boundary_process_proposed: CircleDashed,
|
|
185
|
+
boundary_process_rejected: CircleX,
|
|
171
186
|
// Trail step verification: unconfirmed = no augmentation yet, stale = code changed
|
|
172
187
|
step_unconfirmed: CircleHelp,
|
|
173
188
|
step_stale: History,
|
|
@@ -250,6 +265,11 @@ const KIND_LABEL: Record<string, string> = {
|
|
|
250
265
|
graphify_unavailable: 'Graphify cache unavailable',
|
|
251
266
|
boundary_module_file_mismatch: 'Declaration file outside module',
|
|
252
267
|
boundary_process_nest_disagree: 'Module spans multiple process contexts',
|
|
268
|
+
// C4 process verification (labels read as boundary states, since the layer
|
|
269
|
+
// scopes them to process frames).
|
|
270
|
+
boundary_process_unassigned: 'Process boundary unclaimed',
|
|
271
|
+
boundary_process_proposed: 'Container awaiting decision',
|
|
272
|
+
boundary_process_rejected: 'Container rejected',
|
|
253
273
|
trail: 'Step issue',
|
|
254
274
|
step_unconfirmed: 'Call site not verified',
|
|
255
275
|
step_stale: 'Call site changed',
|
|
@@ -284,6 +304,9 @@ const KIND_ORDER: Record<string, number> = {
|
|
|
284
304
|
boundary_module_file_mismatch: 23,
|
|
285
305
|
// Runtime topology — process containment
|
|
286
306
|
boundary_process_nest_disagree: 30,
|
|
307
|
+
boundary_process_unassigned: 31,
|
|
308
|
+
boundary_process_proposed: 32,
|
|
309
|
+
boundary_process_rejected: 33,
|
|
287
310
|
// Trail — mechanical issues first, then step verification
|
|
288
311
|
trail: 40,
|
|
289
312
|
step_unconfirmed: 41,
|
|
@@ -39,6 +39,7 @@ import {
|
|
|
39
39
|
deriveGraphEdges,
|
|
40
40
|
isConstructsOnlyModel,
|
|
41
41
|
moduleGroupNodeId,
|
|
42
|
+
processGroupNodeId,
|
|
42
43
|
isTrailMechanism,
|
|
43
44
|
edgeColor,
|
|
44
45
|
MECHANISM_DESCRIPTIONS,
|
|
@@ -1099,16 +1100,24 @@ function Inner({ components, trails, graphifyRelations, orderByLine, initialTrai
|
|
|
1099
1100
|
[components],
|
|
1100
1101
|
);
|
|
1101
1102
|
|
|
1102
|
-
// A `module` issue target names a boundary frame, so focusing
|
|
1103
|
-
// that region on the canvas. Null when the target names no
|
|
1104
|
-
// dropped from the layout, or a region key nothing
|
|
1105
|
-
|
|
1103
|
+
// A `module` / `process` issue target names a boundary frame, so focusing
|
|
1104
|
+
// the card frames that region on the canvas. Null when the target names no
|
|
1105
|
+
// frame (a singleton dropped from the layout, or a region key nothing
|
|
1106
|
+
// declares).
|
|
1107
|
+
const issueFrameNodeId = useCallback(
|
|
1106
1108
|
(issue: SubsystemIssue): string | null => {
|
|
1107
1109
|
const target = issue.target;
|
|
1108
|
-
if (target?.kind
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1110
|
+
if (target?.kind === 'module') {
|
|
1111
|
+
const key = target.id ?? target.label;
|
|
1112
|
+
if (!components.some((c) => c.module?.trim() === key)) return null;
|
|
1113
|
+
return moduleGroupNodeId(key);
|
|
1114
|
+
}
|
|
1115
|
+
if (target?.kind === 'process') {
|
|
1116
|
+
const key = target.id ?? target.label;
|
|
1117
|
+
if (!components.some((c) => c.process === key)) return null;
|
|
1118
|
+
return processGroupNodeId(key);
|
|
1119
|
+
}
|
|
1120
|
+
return null;
|
|
1112
1121
|
},
|
|
1113
1122
|
[components],
|
|
1114
1123
|
);
|
|
@@ -1159,7 +1168,9 @@ function Inner({ components, trails, graphifyRelations, orderByLine, initialTrai
|
|
|
1159
1168
|
}, [issues, issueComponent]);
|
|
1160
1169
|
|
|
1161
1170
|
// Per-frame diagnostics badge: the same fold, but for findings about a
|
|
1162
|
-
// BOUNDARY rather than a construct. Keyed by the region's React Flow node
|
|
1171
|
+
// BOUNDARY rather than a construct. Keyed by the region's React Flow node
|
|
1172
|
+
// id — a `module` target names a module frame, a `process` target a process
|
|
1173
|
+
// frame (dynamic-topology findings, e.g. C4 process verification).
|
|
1163
1174
|
// Only kinds with a dedicated frame icon qualify (`ISSUE_KIND_ICON`) — a
|
|
1164
1175
|
// finding with no icon of its own has nothing to badge the frame with, and
|
|
1165
1176
|
// borrowing its layer's icon would imply the frame is at fault for it.
|
|
@@ -1168,8 +1179,12 @@ function Inner({ components, trails, graphifyRelations, orderByLine, initialTrai
|
|
|
1168
1179
|
if (!issues?.length) return map;
|
|
1169
1180
|
for (const issue of issues) {
|
|
1170
1181
|
const target = issue.target;
|
|
1171
|
-
if (target
|
|
1172
|
-
|
|
1182
|
+
if (!target || !ISSUE_KIND_ICON[issue.kind]) continue;
|
|
1183
|
+
if (target.kind !== 'module' && target.kind !== 'process') continue;
|
|
1184
|
+
const id =
|
|
1185
|
+
target.kind === 'module'
|
|
1186
|
+
? moduleGroupNodeId(target.id ?? target.label)
|
|
1187
|
+
: processGroupNodeId(target.id ?? target.label);
|
|
1173
1188
|
const prev = map.get(id);
|
|
1174
1189
|
map.set(id, {
|
|
1175
1190
|
severity:
|
|
@@ -1267,6 +1282,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, initialTrai
|
|
|
1267
1282
|
// target:
|
|
1268
1283
|
// component → that node
|
|
1269
1284
|
// module → every component in that module
|
|
1285
|
+
// process → every component with that `process` key
|
|
1270
1286
|
// trail → the flow's nodes + its step edges
|
|
1271
1287
|
// repo → every component of that repo
|
|
1272
1288
|
// graph → whole-graph finding; implicates nothing specific
|
|
@@ -1298,6 +1314,11 @@ function Inner({ components, trails, graphifyRelations, orderByLine, initialTrai
|
|
|
1298
1314
|
nodeIds.add(c.alias);
|
|
1299
1315
|
}
|
|
1300
1316
|
}
|
|
1317
|
+
} else if (t.kind === 'process') {
|
|
1318
|
+
const key = t.id ?? t.label;
|
|
1319
|
+
for (const c of components) {
|
|
1320
|
+
if (c.process === key) nodeIds.add(c.alias);
|
|
1321
|
+
}
|
|
1301
1322
|
} else if (t.kind === 'trail') {
|
|
1302
1323
|
const wt = (trails ?? []).find(
|
|
1303
1324
|
(w) => w.id === t.id || w.title === t.label,
|
|
@@ -1488,7 +1509,8 @@ function Inner({ components, trails, graphifyRelations, orderByLine, initialTrai
|
|
|
1488
1509
|
// Host override wins over the library's derived frame color.
|
|
1489
1510
|
const color = region?.key != null ? boundaryColors?.[region.key] : undefined;
|
|
1490
1511
|
// Boundary findings badge the FRAME, not a member — a region's shape is
|
|
1491
|
-
// the fault, so no leaf construct carries it.
|
|
1512
|
+
// the fault, so no leaf construct carries it. Process verification
|
|
1513
|
+
// findings ride the same path: their target kind is `process`.
|
|
1492
1514
|
const regionIssue = regionIssueByNodeId.get(n.id);
|
|
1493
1515
|
return {
|
|
1494
1516
|
...n,
|
|
@@ -2376,7 +2398,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, initialTrai
|
|
|
2376
2398
|
} else {
|
|
2377
2399
|
// Nothing selectable — but a module target names a boundary frame, so
|
|
2378
2400
|
// frame that region.
|
|
2379
|
-
const moduleNodeId =
|
|
2401
|
+
const moduleNodeId = issueFrameNodeId(issue);
|
|
2380
2402
|
if (moduleNodeId) {
|
|
2381
2403
|
setSelected(null);
|
|
2382
2404
|
setSelectedEdgeId(null);
|
|
@@ -2394,7 +2416,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, initialTrai
|
|
|
2394
2416
|
[
|
|
2395
2417
|
issueComponent,
|
|
2396
2418
|
issueStep,
|
|
2397
|
-
|
|
2419
|
+
issueFrameNodeId,
|
|
2398
2420
|
focusTrailStep,
|
|
2399
2421
|
onSelect,
|
|
2400
2422
|
onSelectIssue,
|
|
@@ -2418,7 +2440,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, initialTrai
|
|
|
2418
2440
|
setSelectedEdgeId(null);
|
|
2419
2441
|
} else {
|
|
2420
2442
|
const step = issueStep(issue);
|
|
2421
|
-
const moduleNodeId = step ? null :
|
|
2443
|
+
const moduleNodeId = step ? null : issueFrameNodeId(issue);
|
|
2422
2444
|
if (step) {
|
|
2423
2445
|
// Only unwind a step focus this card still owns. A dim-mode graph
|
|
2424
2446
|
// keeps its step focus in hover state instead (owned by the pointer,
|
|
@@ -2445,7 +2467,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, initialTrai
|
|
|
2445
2467
|
fitView({ padding: 0.1, duration: 300, minZoom: 0.05, maxZoom: 2 });
|
|
2446
2468
|
});
|
|
2447
2469
|
},
|
|
2448
|
-
[issueComponent, issueStep,
|
|
2470
|
+
[issueComponent, issueStep, issueFrameNodeId, fitView],
|
|
2449
2471
|
);
|
|
2450
2472
|
|
|
2451
2473
|
// Construct tokens inside a trail snippet. A step's line is an edge
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import { PROTOCOL_COLOR, PROTOCOL_COLOR_FALLBACK, protocolColor } from './c4';
|
|
3
|
+
|
|
4
|
+
describe('protocolColor', () => {
|
|
5
|
+
test('maps a known protocol to its hue', () => {
|
|
6
|
+
expect(protocolColor('HTTP')).toBe(PROTOCOL_COLOR.http);
|
|
7
|
+
expect(protocolColor('RPC')).toBe(PROTOCOL_COLOR.rpc);
|
|
8
|
+
expect(protocolColor('file I/O')).toBe(PROTOCOL_COLOR['file i/o']);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test('matches a token inside a longer protocol string', () => {
|
|
12
|
+
expect(protocolColor('Electrobun RPC')).toBe(PROTOCOL_COLOR.rpc);
|
|
13
|
+
expect(protocolColor('HTTPS')).toBe(PROTOCOL_COLOR.https);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('prefers the longest matching token', () => {
|
|
17
|
+
// `JSON-RPC` must find `json-rpc`, not the shorter `rpc`.
|
|
18
|
+
expect(protocolColor('JSON-RPC')).toBe(PROTOCOL_COLOR['json-rpc']);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test('falls back for an unknown or missing protocol', () => {
|
|
22
|
+
expect(protocolColor('carrier pigeon')).toBe(PROTOCOL_COLOR_FALLBACK);
|
|
23
|
+
expect(protocolColor(undefined)).toBe(PROTOCOL_COLOR_FALLBACK);
|
|
24
|
+
expect(protocolColor('')).toBe(PROTOCOL_COLOR_FALLBACK);
|
|
25
|
+
});
|
|
26
|
+
});
|
package/src/subsystem/c4.ts
CHANGED
|
@@ -12,6 +12,12 @@
|
|
|
12
12
|
* supplies the drawable model directly rather than having trails converted into
|
|
13
13
|
* lines.
|
|
14
14
|
*
|
|
15
|
+
* The element set is an umbrella over a model, not a standalone artifact: what
|
|
16
|
+
* sits inside a box resolves from the model document's `process` fields, folded
|
|
17
|
+
* to the claiming container's key by accepted consolidation records (see
|
|
18
|
+
* `c4Evidence`). Nothing here stores membership, so nothing here can drift from
|
|
19
|
+
* the model it organizes.
|
|
20
|
+
*
|
|
15
21
|
* ## Why a union and not one type with two axes
|
|
16
22
|
*
|
|
17
23
|
* C4's vocabulary is closed: software system, container, component, code —
|
|
@@ -32,8 +38,6 @@
|
|
|
32
38
|
* [C4 notation]: https://c4model.com/diagrams/notation
|
|
33
39
|
*/
|
|
34
40
|
|
|
35
|
-
import type { SubsystemComponent } from './model';
|
|
36
|
-
|
|
37
41
|
/**
|
|
38
42
|
* Has anyone signed off on this element yet?
|
|
39
43
|
*
|
|
@@ -53,27 +57,22 @@ interface C4ElementBase {
|
|
|
53
57
|
/** Display name. */
|
|
54
58
|
label: string;
|
|
55
59
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* runs of code being one container is a judgement, not a lookup.
|
|
60
|
-
*
|
|
61
|
-
* Each alias belongs to exactly one element.
|
|
60
|
+
* Nesting parent. A component's container, or a container's system frame.
|
|
61
|
+
* Absent on an external system or a person — both are outside the boundary:
|
|
62
|
+
* an external is someone else's system, a person is never part of one.
|
|
62
63
|
*/
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* The `process` values this element consolidated, when it came from more than
|
|
66
|
-
* one. Purely provenance — it lets the confirm UI show "this box absorbed
|
|
67
|
-
* principal-studio/host". Never used to infer membership.
|
|
68
|
-
*/
|
|
69
|
-
derivedFrom?: string[];
|
|
64
|
+
parentId?: string;
|
|
70
65
|
/** C4 asks every element to carry a one-line responsibility. */
|
|
71
66
|
description?: string;
|
|
72
67
|
state: C4ElementState;
|
|
73
68
|
/** Why this element is proposed as it is — shown in the confirm UI. */
|
|
74
69
|
rationale?: string;
|
|
75
|
-
/**
|
|
76
|
-
|
|
70
|
+
/** The component aliases this element groups. */
|
|
71
|
+
members?: string[];
|
|
72
|
+
/** Distinct constructs among the members, when resolved from a document. */
|
|
73
|
+
constructs?: string[];
|
|
74
|
+
/** Source model ids that contributed members, when attribution is supplied. */
|
|
75
|
+
models?: string[];
|
|
77
76
|
/** When the state last changed (ISO). */
|
|
78
77
|
decidedAt?: string;
|
|
79
78
|
}
|
|
@@ -96,6 +95,12 @@ export interface C4Container extends C4ElementBase {
|
|
|
96
95
|
containerKind: C4ContainerKind;
|
|
97
96
|
/** C4 requires a technology on every container. */
|
|
98
97
|
technology: string;
|
|
98
|
+
/**
|
|
99
|
+
* The `process` key this container claims — the boundary it verifies,
|
|
100
|
+
* matched exactly against the model document's keys. Not a member list:
|
|
101
|
+
* the components inside resolve from the model document.
|
|
102
|
+
*/
|
|
103
|
+
process?: string;
|
|
99
104
|
}
|
|
100
105
|
|
|
101
106
|
/**
|
|
@@ -114,7 +119,6 @@ export interface C4Component extends C4ElementBase {
|
|
|
114
119
|
/** C4 requires a technology on every component. */
|
|
115
120
|
technology: string;
|
|
116
121
|
}
|
|
117
|
-
|
|
118
122
|
/** A software system outside the boundary we are drawing. */
|
|
119
123
|
export interface C4ExternalSystem extends C4ElementBase {
|
|
120
124
|
kind: 'external-system';
|
|
@@ -130,7 +134,14 @@ export interface C4Person extends C4ElementBase {
|
|
|
130
134
|
/** One element. Four kinds, no fifth. */
|
|
131
135
|
export type C4Element = C4Container | C4Component | C4ExternalSystem | C4Person;
|
|
132
136
|
|
|
133
|
-
/**
|
|
137
|
+
/**
|
|
138
|
+
* A whole authored element list, for one repo or composed graph. This is the
|
|
139
|
+
* shape the durable element store persists (`~/.principal/c4-elements/<purl>.json`):
|
|
140
|
+
* **accepted elements only** — the set is the approved architecture, not a
|
|
141
|
+
* history. `proposed` exists only on in-memory proposal scaffolds and is never
|
|
142
|
+
* persisted; a rejected proposal stays remembered by the proposal store, which
|
|
143
|
+
* is where proposing agents consult prior rejections.
|
|
144
|
+
*/
|
|
134
145
|
export interface C4ElementSet {
|
|
135
146
|
/** Repo key this set describes, e.g. `pkg:github/owner/name`. */
|
|
136
147
|
repoKey: string;
|
|
@@ -142,38 +153,6 @@ export interface C4ElementSet {
|
|
|
142
153
|
/** Which level to draw. Determines which frames are drawn. */
|
|
143
154
|
export type C4View = 'container' | 'component';
|
|
144
155
|
|
|
145
|
-
/**
|
|
146
|
-
* A flattened element, as the renderer reads it.
|
|
147
|
-
*
|
|
148
|
-
* The union above is what an author writes; this is the one shape every box
|
|
149
|
-
* draws with, so the card does not branch on kind to find a label.
|
|
150
|
-
*/
|
|
151
|
-
export interface C4Node {
|
|
152
|
-
id: string;
|
|
153
|
-
kind: C4Element['kind'];
|
|
154
|
-
/**
|
|
155
|
-
* Nesting parent: a component's container, a container or external system's
|
|
156
|
-
* frame, and nothing for a person — C4 puts people outside every system.
|
|
157
|
-
*/
|
|
158
|
-
parentId?: string;
|
|
159
|
-
label: string;
|
|
160
|
-
technology?: string;
|
|
161
|
-
description?: string;
|
|
162
|
-
state: C4ElementState;
|
|
163
|
-
/** `application` / `data-store`. Set on containers only. */
|
|
164
|
-
containerKind?: C4ContainerKind;
|
|
165
|
-
/** Provenance, when the element consolidated several derived keys. */
|
|
166
|
-
derivedFrom?: string[];
|
|
167
|
-
/** Resolved members, when a document was supplied. A container's list includes its components'. */
|
|
168
|
-
members: string[];
|
|
169
|
-
/** Distinct constructs among resolved members. */
|
|
170
|
-
constructs: string[];
|
|
171
|
-
/** Present at component level when the document resolved it. */
|
|
172
|
-
component?: SubsystemComponent;
|
|
173
|
-
/** Source model ids that contributed members, when attribution is supplied. */
|
|
174
|
-
models?: string[];
|
|
175
|
-
}
|
|
176
|
-
|
|
177
156
|
/** A compound frame: the system, or a container holding its components. */
|
|
178
157
|
export interface C4Group {
|
|
179
158
|
id: string;
|
|
@@ -205,11 +184,56 @@ export interface C4Edge {
|
|
|
205
184
|
count: number;
|
|
206
185
|
}
|
|
207
186
|
|
|
187
|
+
/**
|
|
188
|
+
* Protocol hues, keyed by a canonical protocol token.
|
|
189
|
+
*
|
|
190
|
+
* C4's notation is colour-free, so this is a local choice — but on a container
|
|
191
|
+
* diagram the protocol is what a reader wants to distinguish at a glance
|
|
192
|
+
* (in-process RPC vs HTTP vs file I/O), more than the trail verb the line came
|
|
193
|
+
* from. Keys are lowercase, matched loosely (see `protocolColor`).
|
|
194
|
+
*/
|
|
195
|
+
export const PROTOCOL_COLOR: Record<string, string> = {
|
|
196
|
+
rpc: '#22c55e', // green — in-process call across a boundary
|
|
197
|
+
http: '#e8853a', // orange — network request
|
|
198
|
+
https: '#e8853a',
|
|
199
|
+
rest: '#e8853a',
|
|
200
|
+
graphql: '#e061a3', // pink
|
|
201
|
+
fs: '#0ea5e9', // sky — disk
|
|
202
|
+
'file i/o': '#0ea5e9',
|
|
203
|
+
sql: '#a78bfa', // violet — a database
|
|
204
|
+
sqlite: '#a78bfa',
|
|
205
|
+
postgres: '#a78bfa',
|
|
206
|
+
'json-rpc': '#22c55e',
|
|
207
|
+
ws: '#e3b341', // gold — stream/socket
|
|
208
|
+
websocket: '#e3b341',
|
|
209
|
+
mcp: '#4ec9b0', // teal — agent/tool transport
|
|
210
|
+
stdin: '#9ca3af', // gray — process boundary
|
|
211
|
+
stdout: '#9ca3af',
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
/** Fallback hue for an edge whose protocol we have no colour for (or none). */
|
|
215
|
+
export const PROTOCOL_COLOR_FALLBACK = '#9ca3af';
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Colour for an edge's protocol. Matches the longest known token contained in
|
|
219
|
+
* the (lowercased) protocol string, so `Electrobun RPC` finds `rpc` and
|
|
220
|
+
* `JSON-RPC` finds the `json-rpc` entry before `rpc`.
|
|
221
|
+
*/
|
|
222
|
+
export function protocolColor(protocol: string | undefined): string {
|
|
223
|
+
if (!protocol) return PROTOCOL_COLOR_FALLBACK;
|
|
224
|
+
const p = protocol.toLowerCase();
|
|
225
|
+
let best = '';
|
|
226
|
+
for (const key of Object.keys(PROTOCOL_COLOR)) {
|
|
227
|
+
if (key.length > best.length && p.includes(key)) best = key;
|
|
228
|
+
}
|
|
229
|
+
return best ? PROTOCOL_COLOR[best]! : PROTOCOL_COLOR_FALLBACK;
|
|
230
|
+
}
|
|
231
|
+
|
|
208
232
|
/** A drawable C4 projection. Authored, not derived. */
|
|
209
233
|
export interface C4Model {
|
|
210
234
|
view: C4View;
|
|
211
235
|
system: { id: string; label: string; repoKey?: string };
|
|
212
|
-
nodes:
|
|
236
|
+
nodes: C4Element[];
|
|
213
237
|
groups: C4Group[];
|
|
214
238
|
edges: C4Edge[];
|
|
215
239
|
}
|