dsh-archify-projects 0.0.0-stage → 0.1.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/README.md +204 -2
- package/cordis.patch.yml +99 -0
- package/dist/client.js +2261 -0
- package/dist/client.js.map +1 -0
- package/docs/CONTAINER.md +197 -0
- package/docs/DESIGN.md +905 -0
- package/docs/HANDOVER.md +391 -0
- package/docs/PUBLISH.md +107 -0
- package/icon.svg +12 -0
- package/lib/host/archify-skill.js +116 -0
- package/lib/host/archify-skill.js.map +1 -0
- package/lib/host/config.js +95 -0
- package/lib/host/config.js.map +1 -0
- package/lib/host/context.js +28 -0
- package/lib/host/context.js.map +1 -0
- package/lib/host/git.js +185 -0
- package/lib/host/git.js.map +1 -0
- package/lib/host/http.js +184 -0
- package/lib/host/http.js.map +1 -0
- package/lib/host/index.js +90 -0
- package/lib/host/index.js.map +1 -0
- package/lib/host/policy.js +124 -0
- package/lib/host/policy.js.map +1 -0
- package/lib/host/routes.js +667 -0
- package/lib/host/routes.js.map +1 -0
- package/lib/host/runner.js +913 -0
- package/lib/host/runner.js.map +1 -0
- package/lib/host/store.js +370 -0
- package/lib/host/store.js.map +1 -0
- package/lib/host/workspace.js +65 -0
- package/lib/host/workspace.js.map +1 -0
- package/lib/shared/format.js +138 -0
- package/lib/shared/format.js.map +1 -0
- package/lib/shared/prompt.js +257 -0
- package/lib/shared/prompt.js.map +1 -0
- package/lib/shared/protocol.js +31 -0
- package/lib/shared/protocol.js.map +1 -0
- package/lib/shared/types.js +173 -0
- package/lib/shared/types.js.map +1 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +98 -4
- package/skills/archify/LICENSE +22 -0
- package/skills/archify/SKILL.md +109 -0
- package/skills/archify/THIRD_PARTY_NOTICES.md +69 -0
- package/skills/archify/assets/JetBrainsMono-OFL.txt +93 -0
- package/skills/archify/assets/template.html +13709 -0
- package/skills/archify/bin/archify.mjs +6936 -0
- package/skills/archify/bin/delivery-update.mjs +91 -0
- package/skills/archify/bin/finalize.mjs +895 -0
- package/skills/archify/bin/open-artifact.mjs +146 -0
- package/skills/archify/bin/preview.mjs +969 -0
- package/skills/archify/bin/recover-output.mjs +41 -0
- package/skills/archify/bin/visual-check.mjs +2667 -0
- package/skills/archify/brand-marks/README.md +31 -0
- package/skills/archify/brand-marks/catalog.json +131 -0
- package/skills/archify/delta/architecture-delta.mjs +1313 -0
- package/skills/archify/examples/agent-run.lifecycle.json +55 -0
- package/skills/archify/examples/agent-tool-call.workflow.json +74 -0
- package/skills/archify/examples/async-job-roundtrip.sequence.json +56 -0
- package/skills/archify/examples/brand-aware-delivery.architecture.json +34 -0
- package/skills/archify/examples/cache-miss-request.sequence.json +77 -0
- package/skills/archify/examples/checkout-platform.base.architecture.json +32 -0
- package/skills/archify/examples/checkout-platform.head.architecture.json +32 -0
- package/skills/archify/examples/dataflow-product-analytics.html +13820 -0
- package/skills/archify/examples/deployment-release.lifecycle.json +48 -0
- package/skills/archify/examples/event-stream.dataflow.json +52 -0
- package/skills/archify/examples/holiday-planning.workflow.json +143 -0
- package/skills/archify/examples/incident-response.workflow.json +59 -0
- package/skills/archify/examples/lifecycle-agent-run.html +13765 -0
- package/skills/archify/examples/locales/de.json +425 -0
- package/skills/archify/examples/locales/es.json +440 -0
- package/skills/archify/examples/locales/fr.json +425 -0
- package/skills/archify/examples/locales/fr.partial.json +22 -0
- package/skills/archify/examples/locales/it.json +425 -0
- package/skills/archify/examples/locales/ja.json +425 -0
- package/skills/archify/examples/locales/ko.json +440 -0
- package/skills/archify/examples/locales/pt.json +425 -0
- package/skills/archify/examples/locales/ru.json +425 -0
- package/skills/archify/examples/product-analytics.dataflow.json +71 -0
- package/skills/archify/examples/production-deployment.architecture.json +51 -0
- package/skills/archify/examples/release-delivery.workflow.json +57 -0
- package/skills/archify/examples/sequence-cache-miss-request.html +13835 -0
- package/skills/archify/examples/web-app-rendered.html +13808 -0
- package/skills/archify/examples/web-app.architecture.json +41 -0
- package/skills/archify/examples/workflow-agent-tool-call-rendered.html +13826 -0
- package/skills/archify/migrations/workflow-v2.mjs +280 -0
- package/skills/archify/package.json +17 -0
- package/skills/archify/recipes/scenarios.mjs +430 -0
- package/skills/archify/references/architecture-layout-repair.md +18 -0
- package/skills/archify/references/authoring-contract.md +419 -0
- package/skills/archify/references/authoring-defaults.md +41 -0
- package/skills/archify/references/brand-marks.md +82 -0
- package/skills/archify/references/delivery-contract.md +588 -0
- package/skills/archify/references/repository-authoring.md +105 -0
- package/skills/archify/references/update-awareness.md +12 -0
- package/skills/archify/references/viewer-runtime.md +35 -0
- package/skills/archify/renderers/architecture/grid.mjs +62 -0
- package/skills/archify/renderers/architecture/labels.mjs +215 -0
- package/skills/archify/renderers/architecture/render-architecture.mjs +1001 -0
- package/skills/archify/renderers/architecture/routing.mjs +1157 -0
- package/skills/archify/renderers/dataflow/README.md +105 -0
- package/skills/archify/renderers/dataflow/render-dataflow.mjs +544 -0
- package/skills/archify/renderers/lifecycle/README.md +171 -0
- package/skills/archify/renderers/lifecycle/grid-routing.mjs +429 -0
- package/skills/archify/renderers/lifecycle/render-lifecycle.mjs +938 -0
- package/skills/archify/renderers/sequence/README.md +129 -0
- package/skills/archify/renderers/sequence/render-sequence.mjs +526 -0
- package/skills/archify/renderers/shared/atomic-output.mjs +1982 -0
- package/skills/archify/renderers/shared/brand-marks.mjs +670 -0
- package/skills/archify/renderers/shared/cli.mjs +451 -0
- package/skills/archify/renderers/shared/desktop-readability.mjs +132 -0
- package/skills/archify/renderers/shared/diagnostics.mjs +173 -0
- package/skills/archify/renderers/shared/engineering-profiles.mjs +157 -0
- package/skills/archify/renderers/shared/generated-brand-marks.mjs +2003 -0
- package/skills/archify/renderers/shared/generated-validators.mjs +134 -0
- package/skills/archify/renderers/shared/geometry.mjs +1941 -0
- package/skills/archify/renderers/shared/i18n.mjs +603 -0
- package/skills/archify/renderers/shared/layout-report.mjs +42 -0
- package/skills/archify/renderers/shared/legend.mjs +217 -0
- package/skills/archify/renderers/shared/output-path.mjs +440 -0
- package/skills/archify/renderers/shared/path-semantics.mjs +1017 -0
- package/skills/archify/renderers/shared/portable-path.mjs +408 -0
- package/skills/archify/renderers/shared/repository-evidence.mjs +352 -0
- package/skills/archify/renderers/shared/repository-location.mjs +59 -0
- package/skills/archify/renderers/shared/route-quality.mjs +614 -0
- package/skills/archify/renderers/shared/sidecar-path.mjs +38 -0
- package/skills/archify/renderers/shared/spatial-grid.mjs +66 -0
- package/skills/archify/renderers/shared/text-fit.mjs +105 -0
- package/skills/archify/renderers/shared/utils.mjs +254 -0
- package/skills/archify/renderers/shared/validator.mjs +86 -0
- package/skills/archify/renderers/workflow/README.md +301 -0
- package/skills/archify/renderers/workflow/render-workflow.mjs +37 -0
- package/skills/archify/renderers/workflow/workflow-compiler.mjs +4913 -0
- package/skills/archify/renderers/workflow/workflow-migration-geometry.mjs +144 -0
- package/skills/archify/schemas/README.md +256 -0
- package/skills/archify/schemas/architecture.schema.json +152 -0
- package/skills/archify/schemas/common.schema.json +181 -0
- package/skills/archify/schemas/dataflow.schema.json +254 -0
- package/skills/archify/schemas/lifecycle.schema.json +280 -0
- package/skills/archify/schemas/sequence.schema.json +234 -0
- package/skills/archify/schemas/workflow.schema.json +439 -0
- package/skills/archify/scripts/check-render-output.mjs +1388 -0
- package/skills/archify/scripts/check-update.mjs +1710 -0
- package/skills/archify/scripts/delivery-update-child.mjs +23 -0
- package/skills/archify/scripts/render-examples.mjs +26 -0
- package/skills/archify/scripts/update-contract.mjs +182 -0
- package/skills/archify/skill-release.json +10 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** Uniform spatial grid for "which items can this box reach" queries (#8). */
|
|
2
|
+
|
|
3
|
+
// A cell box wider than this is not worth walking: the query returns every
|
|
4
|
+
// inserted item instead, which stays a superset of what the box reaches.
|
|
5
|
+
const DEFAULT_MAX_CELLS = 4096;
|
|
6
|
+
|
|
7
|
+
export function createSpatialGrid(cellSize, { maxCells = DEFAULT_MAX_CELLS } = {}) {
|
|
8
|
+
const buckets = new Map();
|
|
9
|
+
const items = [];
|
|
10
|
+
// Items whose own box cannot be walked are candidates for every query.
|
|
11
|
+
const overflow = [];
|
|
12
|
+
const keyOf = (x, y) => x + ':' + y;
|
|
13
|
+
const rangeOf = (box) => ({
|
|
14
|
+
x0: Math.floor(box.minX / cellSize), x1: Math.floor(box.maxX / cellSize),
|
|
15
|
+
y0: Math.floor(box.minY / cellSize), y1: Math.floor(box.maxY / cellSize),
|
|
16
|
+
});
|
|
17
|
+
// Finite coordinates can still land outside the safe-integer range, where
|
|
18
|
+
// incrementing an index no longer advances it; and a legal coordinate can
|
|
19
|
+
// name more cells than the grid is worth. Both cases stay out of the buckets
|
|
20
|
+
// and are answered by the item list, so they never hang or allocate.
|
|
21
|
+
const walkable = (range) => Number.isSafeInteger(range.x0) && Number.isSafeInteger(range.x1)
|
|
22
|
+
&& Number.isSafeInteger(range.y0) && Number.isSafeInteger(range.y1)
|
|
23
|
+
&& (range.x1 - range.x0 + 1) * (range.y1 - range.y0 + 1) <= maxCells;
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
insert(box, item) {
|
|
27
|
+
items.push(item);
|
|
28
|
+
const range = rangeOf(box);
|
|
29
|
+
if (!walkable(range)) {
|
|
30
|
+
overflow.push(item);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
for (let x = range.x0; x <= range.x1; x += 1) {
|
|
34
|
+
for (let y = range.y0; y <= range.y1; y += 1) {
|
|
35
|
+
const key = keyOf(x, y);
|
|
36
|
+
let bucket = buckets.get(key);
|
|
37
|
+
if (!bucket) { bucket = []; buckets.set(key, bucket); }
|
|
38
|
+
bucket.push(item);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
query(box) {
|
|
43
|
+
const range = rangeOf(box);
|
|
44
|
+
if (!walkable(range)) return items.slice();
|
|
45
|
+
const seen = new Set();
|
|
46
|
+
const found = [];
|
|
47
|
+
for (let x = range.x0; x <= range.x1; x += 1) {
|
|
48
|
+
for (let y = range.y0; y <= range.y1; y += 1) {
|
|
49
|
+
const bucket = buckets.get(keyOf(x, y));
|
|
50
|
+
if (!bucket) continue;
|
|
51
|
+
for (const item of bucket) {
|
|
52
|
+
if (seen.has(item)) continue;
|
|
53
|
+
seen.add(item);
|
|
54
|
+
found.push(item);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
for (const item of overflow) {
|
|
59
|
+
if (seen.has(item)) continue;
|
|
60
|
+
seen.add(item);
|
|
61
|
+
found.push(item);
|
|
62
|
+
}
|
|
63
|
+
return found;
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// Single-line node text fitting, shared by every renderer.
|
|
2
|
+
//
|
|
3
|
+
// Node text (`label`, `sublabel`, `tag`) renders as one <text> element with
|
|
4
|
+
// text-anchor="middle" and is never wrapped. Left unmeasured, an over-long
|
|
5
|
+
// value silently spills across its neighbours while validation still reports
|
|
6
|
+
// a clean receipt — the failure mode this module exists to close.
|
|
7
|
+
//
|
|
8
|
+
// Two halves, always used together:
|
|
9
|
+
// - fittedNodeFontSize shrinks the text toward a legible minimum at render
|
|
10
|
+
// time, so ordinary overruns simply get smaller instead of overlapping.
|
|
11
|
+
// - minimumNodeTextWidth reports the width the text still needs once it has
|
|
12
|
+
// shrunk as far as it may, so validation can reject what shrinking cannot
|
|
13
|
+
// save.
|
|
14
|
+
//
|
|
15
|
+
// The geometry constants below are shared; the per-field `preferred` and
|
|
16
|
+
// `minimum` font sizes are not, because renderers set node text at different
|
|
17
|
+
// sizes (architecture sublabels are 9px, the rest are 7px).
|
|
18
|
+
|
|
19
|
+
import { textUnits, SEMANTIC_SIGIL_INSET, SEMANTIC_SIGIL_SIZE, SEMANTIC_SIGIL_FOOTPRINT, SOURCE_BADGE_FOOTPRINT } from './utils.mjs';
|
|
20
|
+
|
|
21
|
+
// widthFactor: px of advance width per text unit, per px of font size.
|
|
22
|
+
// horizontalPadding: total px reserved inside the box so text never touches
|
|
23
|
+
// the border.
|
|
24
|
+
export const nodeTextFit = {
|
|
25
|
+
widthFactor: 0.6,
|
|
26
|
+
horizontalPadding: 8,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// Largest font size at or below `preferred` that fits `text` inside `width`,
|
|
30
|
+
// floored at `minimum` — below that the text is no longer legible and the
|
|
31
|
+
// caller should be reporting a problem instead.
|
|
32
|
+
export function fittedNodeFontSize(text, width, preferred, minimum) {
|
|
33
|
+
const units = Math.max(1, textUnits(text));
|
|
34
|
+
const available = Math.max(1, width - nodeTextFit.horizontalPadding);
|
|
35
|
+
const fitted = Math.min(preferred, available / (units * nodeTextFit.widthFactor));
|
|
36
|
+
return Math.max(minimum, Math.floor(fitted * 10) / 10);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Width `text` occupies at its legible minimum. Compare against
|
|
40
|
+
// `width - nodeTextFit.horizontalPadding` to decide whether shrink-to-fit can
|
|
41
|
+
// rescue it.
|
|
42
|
+
export function minimumNodeTextWidth(text, minimum) {
|
|
43
|
+
return textUnits(text) * minimum * nodeTextFit.widthFactor;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Available text width inside a box of `width`.
|
|
47
|
+
export function availableNodeTextWidth(width) {
|
|
48
|
+
return width - nodeTextFit.horizontalPadding;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Adapted from Souptik Chakraborty's #220: shift only labels which reach a
|
|
52
|
+
// corner icon. Unlike the original hard gate, a narrow valid node uses a
|
|
53
|
+
// separate text row; its authored bounds and acceptance remain unchanged.
|
|
54
|
+
export function nodeLabelLayout({ width, height, rows, side = 'left', brand = false, source = false, step = '' }) {
|
|
55
|
+
const result = { x: width / 2, ys: rows.map(row => row.y), sigilY: SEMANTIC_SIGIL_INSET, sigilSize: SEMANTIC_SIGIL_SIZE };
|
|
56
|
+
const labelWidth = minimumNodeTextWidth(rows[0].text, rows[0].font);
|
|
57
|
+
const stepEnd = step ? (side === 'left' ? 23 : 10) + minimumNodeTextWidth(step, 8) + 3 : 0;
|
|
58
|
+
const left = Math.max(side === 'left' ? SEMANTIC_SIGIL_FOOTPRINT + 2 : 4, stepEnd);
|
|
59
|
+
const right = width - (brand ? 26 : side === 'right' ? SEMANTIC_SIGIL_FOOTPRINT + 2 : 4)
|
|
60
|
+
- (source ? SOURCE_BADGE_FOOTPRINT : 0);
|
|
61
|
+
if (result.x - labelWidth / 2 >= left && result.x + labelWidth / 2 <= right) return result;
|
|
62
|
+
if (labelWidth <= right - left) {
|
|
63
|
+
// Round away from the icon, retaining the node centre whenever possible.
|
|
64
|
+
result.x = Math.min(Math.floor((right - labelWidth / 2) * 10) / 10,
|
|
65
|
+
Math.max(result.x, Math.ceil((left + labelWidth / 2) * 10) / 10));
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
// Keep the existing font sizes and put the text below the decoration rail.
|
|
69
|
+
// Conservative ascent/descent bounds also protect CJK and fallback fonts.
|
|
70
|
+
let bottom = Math.max(brand ? 22 : SEMANTIC_SIGIL_FOOTPRINT, source ? 19 : 0);
|
|
71
|
+
const ys = rows.map(row => {
|
|
72
|
+
const y = Math.max(row.y, Math.ceil((bottom + 2 + row.font * 1.2) * 10) / 10);
|
|
73
|
+
bottom = y + row.font * 0.3;
|
|
74
|
+
return y;
|
|
75
|
+
});
|
|
76
|
+
if (bottom <= height - 2) {
|
|
77
|
+
result.ys = ys;
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
if (source) {
|
|
81
|
+
// A source badge adds a second decoration on the right. On short boxes,
|
|
82
|
+
// restoring the original rows would put the title back under that badge.
|
|
83
|
+
// Try compact leading before giving up the dedicated text rail. Retain
|
|
84
|
+
// every font size and the authored box; only this crowded fallback packs
|
|
85
|
+
// the rows, with a full em above each baseline and 0.3 em below it.
|
|
86
|
+
let compactBottom = Math.max(brand ? 22 : SEMANTIC_SIGIL_FOOTPRINT, 19) + 1;
|
|
87
|
+
const compactYs = rows.map(row => {
|
|
88
|
+
const y = Math.ceil((compactBottom + 1 + row.font) * 10) / 10;
|
|
89
|
+
compactBottom = y + row.font * 0.3;
|
|
90
|
+
return y;
|
|
91
|
+
});
|
|
92
|
+
// The compact fallback may also use the otherwise reserved bottom
|
|
93
|
+
// padding; the entire descent still stays inside the fixed box.
|
|
94
|
+
if (compactBottom <= height - 0.5) {
|
|
95
|
+
result.ys = compactYs;
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// A deliberately short fixed box may have no spare row. Preserve its text
|
|
100
|
+
// and geometry, and fit only the decorative sigil in the space above it.
|
|
101
|
+
result.sigilY = 1;
|
|
102
|
+
result.sigilSize = Math.max(1, Math.min(SEMANTIC_SIGIL_SIZE,
|
|
103
|
+
Math.floor(rows[0].y - rows[0].font * 1.2 - 3)));
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import {
|
|
2
|
+
escapeHtml as esc,
|
|
3
|
+
localizeTemplate,
|
|
4
|
+
resolveLocale,
|
|
5
|
+
translateMessage,
|
|
6
|
+
viewerCatalog,
|
|
7
|
+
} from './i18n.mjs';
|
|
8
|
+
|
|
9
|
+
export { esc };
|
|
10
|
+
|
|
11
|
+
export function renderDefinitions() {
|
|
12
|
+
return ` <!-- Definitions -->
|
|
13
|
+
<defs>
|
|
14
|
+
<marker id="arrowhead" markerWidth="10" markerHeight="7" refX="9" refY="3.5" orient="auto">
|
|
15
|
+
<polygon points="0 0, 10 3.5, 0 7" class="m-default" />
|
|
16
|
+
</marker>
|
|
17
|
+
<marker id="arrowhead-emphasis" markerWidth="10" markerHeight="7" refX="9" refY="3.5" orient="auto">
|
|
18
|
+
<polygon points="0 0, 10 3.5, 0 7" class="m-emphasis" />
|
|
19
|
+
</marker>
|
|
20
|
+
<marker id="arrowhead-security" markerWidth="10" markerHeight="7" refX="9" refY="3.5" orient="auto">
|
|
21
|
+
<polygon points="0 0, 10 3.5, 0 7" class="m-security" />
|
|
22
|
+
</marker>
|
|
23
|
+
<marker id="arrowhead-dashed" markerWidth="10" markerHeight="7" refX="9" refY="3.5" orient="auto">
|
|
24
|
+
<polygon points="0 0, 10 3.5, 0 7" class="m-dashed" />
|
|
25
|
+
</marker>
|
|
26
|
+
<pattern id="grid" width="40" height="40" patternUnits="userSpaceOnUse">
|
|
27
|
+
<path d="M 40 0 L 0 0 0 40" class="c-grid" stroke-width="0.5"/>
|
|
28
|
+
</pattern>
|
|
29
|
+
</defs>`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const SIGIL_TONE = {
|
|
33
|
+
frontend: 'frontend',
|
|
34
|
+
start: 'frontend',
|
|
35
|
+
backend: 'backend',
|
|
36
|
+
active: 'frontend',
|
|
37
|
+
database: 'database',
|
|
38
|
+
success: 'backend',
|
|
39
|
+
cloud: 'cloud',
|
|
40
|
+
waiting: 'cloud',
|
|
41
|
+
security: 'security',
|
|
42
|
+
decision: 'database',
|
|
43
|
+
failure: 'security',
|
|
44
|
+
messagebus: 'messagebus',
|
|
45
|
+
external: 'external',
|
|
46
|
+
neutral: 'external',
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const SIGIL_SHAPE = {
|
|
50
|
+
calendar: `<rect x="2" y="3.5" width="12" height="10.5" rx="2"/><path d="M5 2v3M11 2v3M2 7h12M5 10h2M9 10h2"/>`,
|
|
51
|
+
clock: `<circle cx="8" cy="8" r="6"/><path d="M8 4v4l3 2"/>`,
|
|
52
|
+
person: `<circle cx="8" cy="4.5" r="2.5"/><path d="M3 14v-2a5 5 0 0 1 10 0v2"/>`,
|
|
53
|
+
briefcase: `<rect x="2" y="5" width="12" height="9" rx="2"/><path d="M5 5V2h6v3M2 9h12M7 9v2h2V9"/>`,
|
|
54
|
+
flag: `<path d="M3 14V2h10l-2 3 2 3H3"/>`,
|
|
55
|
+
moon: `<path d="M13.5 10A6 6 0 0 1 6 2.5 6 6 0 1 0 13.5 10Z"/>`,
|
|
56
|
+
frontend: `<rect x="2" y="3" width="12" height="10" rx="2"/>
|
|
57
|
+
<path d="M2 6.5h12"/>
|
|
58
|
+
<circle cx="4.1" cy="4.8" r=".7" class="sigil-fill"/>
|
|
59
|
+
<circle cx="6.3" cy="4.8" r=".7" class="sigil-fill"/>`,
|
|
60
|
+
backend: `<path d="M6 3 3 8l3 5M10 3l3 5-3 5"/>`,
|
|
61
|
+
database: `<ellipse cx="8" cy="4" rx="5" ry="2"/>
|
|
62
|
+
<path d="M3 4v8c0 1.1 2.2 2 5 2s5-.9 5-2V4M3 8c0 1.1 2.2 2 5 2s5-.9 5-2"/>`,
|
|
63
|
+
cloud: `<path d="M4.3 12.5h7.3a2.4 2.4 0 0 0 .2-4.8 4 4 0 0 0-7.5-1.3A3.1 3.1 0 0 0 4.3 12.5Z"/>`,
|
|
64
|
+
security: `<path d="M8 2.2 13 4v3.5c0 3.1-1.8 5.4-5 6.5-3.2-1.1-5-3.4-5-6.5V4Z"/>
|
|
65
|
+
<path d="m5.8 8 1.5 1.5 3-3"/>`,
|
|
66
|
+
messagebus: `<path d="M2.5 4.5h11M2.5 8h11M2.5 11.5h11"/>
|
|
67
|
+
<circle cx="5" cy="4.5" r="1" class="sigil-fill"/>
|
|
68
|
+
<circle cx="10.5" cy="8" r="1" class="sigil-fill"/>
|
|
69
|
+
<circle cx="7" cy="11.5" r="1" class="sigil-fill"/>`,
|
|
70
|
+
external: `<rect x="2.5" y="5" width="8.5" height="8" rx="1.5"/>
|
|
71
|
+
<path d="M8 2.5h5.5V8M13.5 2.5 7.5 8.5"/>`,
|
|
72
|
+
start: `<circle cx="8" cy="8" r="5"/>
|
|
73
|
+
<path d="m7 5.4 3.6 2.6L7 10.6Z" class="sigil-fill"/>`,
|
|
74
|
+
active: `<path d="M2 8h3l1.5-3.5L9 12l1.6-4H14"/>`,
|
|
75
|
+
waiting: `<path d="M4 2.5h8M4 13.5h8M5 3c0 2.8 2 3.2 3 5-1 1.8-3 2.2-3 5M11 3c0 2.8-2 3.2-3 5 1 1.8 3 2.2 3 5"/>`,
|
|
76
|
+
success: `<circle cx="8" cy="8" r="5.3"/>
|
|
77
|
+
<path d="m5.2 8 1.8 1.8 3.8-4"/>`,
|
|
78
|
+
failure: `<circle cx="8" cy="8" r="5.3"/>
|
|
79
|
+
<path d="m5.7 5.7 4.6 4.6m0-4.6-4.6 4.6"/>`,
|
|
80
|
+
neutral: `<rect x="3" y="3" width="10" height="10" rx="2"/>
|
|
81
|
+
<circle cx="8" cy="8" r="1.2" class="sigil-fill"/>`,
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// A quiet, renderer-owned corner symbol (type default or authored icon). It is
|
|
85
|
+
// SVG content rather than a
|
|
86
|
+
// viewer overlay, so it survives canonical export while adding no focus target,
|
|
87
|
+
// accessible name, layout box, or interaction state of its own.
|
|
88
|
+
// Shared with label clearance so the reserved rail matches the actual icon.
|
|
89
|
+
export const SEMANTIC_SIGIL_INSET = 6;
|
|
90
|
+
export const SEMANTIC_SIGIL_SIZE = 11;
|
|
91
|
+
export const SEMANTIC_SIGIL_FOOTPRINT = SEMANTIC_SIGIL_INSET + SEMANTIC_SIGIL_SIZE;
|
|
92
|
+
// The viewer installs a runtime "sources" beacon on the node's top-right
|
|
93
|
+
// rail, just left of the brand mark. Layout must reserve the same footprint
|
|
94
|
+
// so labels never sit under the badge.
|
|
95
|
+
export const SOURCE_BADGE_FOOTPRINT = 38;
|
|
96
|
+
|
|
97
|
+
export function renderSemanticSigil(kind, { x, y, size = SEMANTIC_SIGIL_SIZE, icon } = {}) {
|
|
98
|
+
if (icon === 'none') return '';
|
|
99
|
+
const selected = icon ?? kind;
|
|
100
|
+
const normalized = Object.hasOwn(SIGIL_SHAPE, selected) ? selected : 'neutral';
|
|
101
|
+
const tone = SIGIL_TONE[kind] || 'external';
|
|
102
|
+
const scale = size / 16;
|
|
103
|
+
return `<g aria-hidden="true" data-semantic-sigil="${esc(normalized)}" class="semantic-sigil s-${tone}" transform="translate(${x} ${y}) scale(${scale})">
|
|
104
|
+
${SIGIL_SHAPE[normalized]}
|
|
105
|
+
</g>`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function renderCards(cards) {
|
|
109
|
+
const list = Array.isArray(cards) ? cards : [];
|
|
110
|
+
return ` <!-- Info Cards -->
|
|
111
|
+
<div class="cards">
|
|
112
|
+
${list.map((card) => ` <div class="card">
|
|
113
|
+
<div class="card-header">
|
|
114
|
+
<div class="card-dot ${esc(card.dot)}"></div>
|
|
115
|
+
<h3>${esc(card.title)}</h3>
|
|
116
|
+
</div>
|
|
117
|
+
<ul>
|
|
118
|
+
${card.items.map((item) => ` <li>${esc(item)}</li>`).join('\n')}
|
|
119
|
+
</ul>
|
|
120
|
+
</div>`).join('\n\n')}
|
|
121
|
+
</div>`;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const SVG_SLOT_RE = / <!-- ARCHIFY:SVG_SLOT_START -->[\s\S]*? <!-- ARCHIFY:SVG_SLOT_END -->/;
|
|
125
|
+
const CARDS_SLOT_RE = / <!-- ARCHIFY:CARDS_SLOT_START -->[\s\S]*? <!-- ARCHIFY:CARDS_SLOT_END -->/;
|
|
126
|
+
const SUBTITLE_SLOT_RE = /^([ \t]*)<p class="subtitle">\[Subtitle description\]<\/p>[ \t]*(\r?\n)?/m;
|
|
127
|
+
const SOURCE_EVIDENCE_PLACEHOLDER = ' <!-- ARCHIFY:SOURCE_EVIDENCE_DATA -->';
|
|
128
|
+
const I18N_PLACEHOLDER = ' <!-- ARCHIFY:I18N_DATA -->';
|
|
129
|
+
|
|
130
|
+
function serializeScriptJson(value) {
|
|
131
|
+
return JSON.stringify(value)
|
|
132
|
+
.replaceAll('<', '\\u003c')
|
|
133
|
+
.replaceAll('>', '\\u003e')
|
|
134
|
+
.replaceAll('&', '\\u0026');
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const TEMPLATE_PLACEHOLDERS = [
|
|
138
|
+
'<html lang="en" data-theme="dark" data-preset="[VISUAL PRESET]">',
|
|
139
|
+
'<title>[PROJECT NAME] Architecture Diagram</title>',
|
|
140
|
+
'<h1>[PROJECT NAME] Architecture</h1>',
|
|
141
|
+
I18N_PLACEHOLDER,
|
|
142
|
+
];
|
|
143
|
+
|
|
144
|
+
export function applyTemplate(template, {
|
|
145
|
+
title,
|
|
146
|
+
subtitle,
|
|
147
|
+
svg,
|
|
148
|
+
cards,
|
|
149
|
+
locale,
|
|
150
|
+
visualPreset = 'classic',
|
|
151
|
+
sourceEvidence = null,
|
|
152
|
+
}) {
|
|
153
|
+
if (!SVG_SLOT_RE.test(template)) {
|
|
154
|
+
throw new Error('applyTemplate: template missing ARCHIFY:SVG_SLOT sentinel');
|
|
155
|
+
}
|
|
156
|
+
if (!CARDS_SLOT_RE.test(template)) {
|
|
157
|
+
throw new Error('applyTemplate: template missing ARCHIFY:CARDS_SLOT sentinel');
|
|
158
|
+
}
|
|
159
|
+
if (!SUBTITLE_SLOT_RE.test(template)) {
|
|
160
|
+
throw new Error('applyTemplate: template missing subtitle placeholder');
|
|
161
|
+
}
|
|
162
|
+
for (const ph of TEMPLATE_PLACEHOLDERS) {
|
|
163
|
+
if (!template.includes(ph)) {
|
|
164
|
+
throw new Error(`applyTemplate: template missing placeholder ${JSON.stringify(ph)}`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
// Keep existing custom templates compatible when evidence is not requested.
|
|
168
|
+
// Silently dropping verified evidence would be misleading, so the new slot
|
|
169
|
+
// becomes mandatory only for the opt-in evidence path.
|
|
170
|
+
if (sourceEvidence && !template.includes(SOURCE_EVIDENCE_PLACEHOLDER)) {
|
|
171
|
+
throw new Error(`applyTemplate: repository evidence requires placeholder ${JSON.stringify(SOURCE_EVIDENCE_PLACEHOLDER)}`);
|
|
172
|
+
}
|
|
173
|
+
// Function replacers: a literal `$&`, `$'`, `$\`` or `$$` in titles, labels,
|
|
174
|
+
// or rendered SVG must not be interpreted as a replacement pattern.
|
|
175
|
+
const sourceEvidenceJson = serializeScriptJson(sourceEvidence);
|
|
176
|
+
const resolvedLocale = resolveLocale(locale);
|
|
177
|
+
const i18nJson = serializeScriptJson({ locale: resolvedLocale, messages: viewerCatalog(resolvedLocale) });
|
|
178
|
+
const renderedSubtitle = typeof subtitle === 'string' && subtitle.trim()
|
|
179
|
+
? `<p class="subtitle">${esc(subtitle)}</p>`
|
|
180
|
+
: '';
|
|
181
|
+
const i18nData = ` <script id="archify-i18n-data" type="application/json">${i18nJson}</script>`;
|
|
182
|
+
return localizeTemplate(template, resolvedLocale)
|
|
183
|
+
.replace(I18N_PLACEHOLDER, () => i18nData)
|
|
184
|
+
.replace(TEMPLATE_PLACEHOLDERS[0], () => `<html lang="${esc(resolvedLocale)}" data-theme="dark" data-preset="${esc(visualPreset)}">`)
|
|
185
|
+
.replace(TEMPLATE_PLACEHOLDERS[1], () => `<title>${esc(translateMessage(resolvedLocale, 'page.title', { title }))}</title>`)
|
|
186
|
+
.replace(TEMPLATE_PLACEHOLDERS[2], () => `<h1>${esc(title)}</h1>`)
|
|
187
|
+
.replace(SUBTITLE_SLOT_RE, (_match, indent, newline = '') => renderedSubtitle
|
|
188
|
+
? `${indent}${renderedSubtitle}${newline}`
|
|
189
|
+
: '')
|
|
190
|
+
.replace(SVG_SLOT_RE, () => svg)
|
|
191
|
+
.replace(CARDS_SLOT_RE, () => cards)
|
|
192
|
+
.replace(SOURCE_EVIDENCE_PLACEHOLDER, () => sourceEvidence
|
|
193
|
+
? ` <script id="archify-source-evidence-data" type="application/json">${sourceEvidenceJson}</script>`
|
|
194
|
+
: '');
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// CJK and other wide/fullwidth glyphs render at roughly twice the advance
|
|
198
|
+
// width of ASCII in the monospace stacks the template uses. Keep halfwidth
|
|
199
|
+
// forms (notably U+FF61–U+FF9F Katakana) out of this set. The explicit ranges
|
|
200
|
+
// also cover vertical punctuation and supplementary East Asian scripts that
|
|
201
|
+
// literal glyph ranges made difficult to audit.
|
|
202
|
+
// Code points that take two columns of advance width: East Asian Wide and
|
|
203
|
+
// Fullwidth per UAX #11, tracking Unicode 17.0. That takes in the BMP symbols
|
|
204
|
+
// carrying emoji presentation (U+2705, U+2B50, U+26A1, U+231B, ...), which
|
|
205
|
+
// render at the same square advance as the supplementary-plane emoji already
|
|
206
|
+
// listed here, and Hangul Jamo Extended-A. Two boundary calls worth naming:
|
|
207
|
+
// Unicode 16.0 reclassified the trigrams (U+2630-U+2637) and the monogram /
|
|
208
|
+
// digram symbols (U+268A-U+268F) from Neutral to Wide, so both are in; and
|
|
209
|
+
// Hangul Jamo Extended-A stops at U+A97C, its last assigned jamo, because
|
|
210
|
+
// U+A97D-U+A97F are unassigned, and unassigned code points outside the CJK
|
|
211
|
+
// ranges UAX #11 names default to Neutral rather than Wide. Spelled out as
|
|
212
|
+
// ranges because V8 has no \p{East_Asian_Width=W} property escape.
|
|
213
|
+
const FULLWIDTH_RE = /[\u1100-\u115F\u231A-\u231B\u2329-\u232A\u23E9-\u23EC\u23F0\u23F3\u25FD-\u25FE\u2614-\u2615\u2630-\u2637\u2648-\u2653\u267F\u268A-\u268F\u2693\u26A1\u26AA-\u26AB\u26BD-\u26BE\u26C4-\u26C5\u26CE\u26D4\u26EA\u26F2-\u26F3\u26F5\u26FA\u26FD\u2705\u270A-\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B-\u2B1C\u2B50\u2B55\u2E80-\uA4CF\uA960-\uA97C\uAC00-\uD7A3\uF900-\uFAFF\uFE10-\uFE19\uFE30-\uFE6F\uFF01-\uFF60\uFFE0-\uFFE6\u{16FE0}-\u{18DFF}\u{1AFF0}-\u{1AFFF}\u{1B000}-\u{1B2FF}\u{1F000}-\u{1FAFF}\u{20000}-\u{3FFFD}]/u;
|
|
214
|
+
|
|
215
|
+
// Variation selectors contribute no separate unit. This is a conservative
|
|
216
|
+
// width estimate, not a measurement of the selected glyph: its actual advance
|
|
217
|
+
// depends on the font and presentation (Unicode UAX #11).
|
|
218
|
+
// VS16 requests emoji presentation, so reserve two units for the sequence.
|
|
219
|
+
// VS15 retains the base's width estimate; forcing every text-presentation
|
|
220
|
+
// sequence to one unit undercounts wide bases, including CJK characters whose
|
|
221
|
+
// font ignores that selector. Neutral bases remain one unit. Some selected
|
|
222
|
+
// text glyphs can be narrower than this estimate; prefer extra space to overflow.
|
|
223
|
+
const VARIATION_SELECTOR_FIRST = 0xfe00;
|
|
224
|
+
const VARIATION_SELECTOR_LAST = 0xfe0f;
|
|
225
|
+
const VARIATION_SELECTOR_EMOJI = 0xfe0f;
|
|
226
|
+
|
|
227
|
+
// Width measurement is pure and the same labels are measured many times per
|
|
228
|
+
// compile, so the unit count is memoized by its input string.
|
|
229
|
+
const TEXT_UNITS_CACHE = new Map();
|
|
230
|
+
const MAX_TEXT_UNITS_CACHE_ENTRIES = 4096;
|
|
231
|
+
const MAX_CACHED_TEXT_LENGTH = 1024;
|
|
232
|
+
|
|
233
|
+
export function textUnits(text) {
|
|
234
|
+
const cacheKey = String(text ?? '');
|
|
235
|
+
const cachedUnits = TEXT_UNITS_CACHE.get(cacheKey);
|
|
236
|
+
if (cachedUnits !== undefined) return cachedUnits;
|
|
237
|
+
const chars = Array.from(cacheKey);
|
|
238
|
+
let units = 0;
|
|
239
|
+
for (let i = 0; i < chars.length; i += 1) {
|
|
240
|
+
const codePoint = chars[i].codePointAt(0);
|
|
241
|
+
if (codePoint >= VARIATION_SELECTOR_FIRST && codePoint <= VARIATION_SELECTOR_LAST) continue;
|
|
242
|
+
const next = i + 1 < chars.length ? chars[i + 1].codePointAt(0) : -1;
|
|
243
|
+
if (next === VARIATION_SELECTOR_EMOJI) units += 2;
|
|
244
|
+
else units += FULLWIDTH_RE.test(chars[i]) ? 2 : 1;
|
|
245
|
+
}
|
|
246
|
+
// Keep repeated in-process compiles bounded, including unusually long labels.
|
|
247
|
+
if (cacheKey.length <= MAX_CACHED_TEXT_LENGTH) {
|
|
248
|
+
if (TEXT_UNITS_CACHE.size >= MAX_TEXT_UNITS_CACHE_ENTRIES) {
|
|
249
|
+
TEXT_UNITS_CACHE.delete(TEXT_UNITS_CACHE.keys().next().value);
|
|
250
|
+
}
|
|
251
|
+
TEXT_UNITS_CACHE.set(cacheKey, units);
|
|
252
|
+
}
|
|
253
|
+
return units;
|
|
254
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import * as validators from './generated-validators.mjs';
|
|
2
|
+
import { throwDiagnosticError } from './diagnostics.mjs';
|
|
3
|
+
|
|
4
|
+
// "/nodes/3/label" reads much better as "/nodes/3 (id: "router") /label" for the
|
|
5
|
+
// LLM fixing the JSON; resolve the nearest enclosing element's id or label.
|
|
6
|
+
function annotatedPath(instancePath, data) {
|
|
7
|
+
if (!instancePath) return { path: '/', identity: null };
|
|
8
|
+
let node = data;
|
|
9
|
+
let hint = null;
|
|
10
|
+
for (const seg of instancePath.split('/').slice(1)) {
|
|
11
|
+
if (node == null || typeof node !== 'object') break;
|
|
12
|
+
node = node[/^\d+$/.test(seg) ? Number(seg) : seg];
|
|
13
|
+
if (node && typeof node === 'object' && !Array.isArray(node)) {
|
|
14
|
+
const tag = node.id ?? node.label;
|
|
15
|
+
if (tag != null) hint = String(tag);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return { path: instancePath, identity: hint };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function annotatePath(instancePath, data) {
|
|
22
|
+
const annotated = annotatedPath(instancePath, data);
|
|
23
|
+
return annotated.identity != null
|
|
24
|
+
? `${annotated.path} (id/label: ${JSON.stringify(annotated.identity)})`
|
|
25
|
+
: annotated.path;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function formatErrors(errors, data) {
|
|
29
|
+
return errors.map((e) => {
|
|
30
|
+
const where = annotatePath(e.instancePath, data);
|
|
31
|
+
const detail = e.params && Object.keys(e.params).length
|
|
32
|
+
? ' ' + JSON.stringify(e.params)
|
|
33
|
+
: '';
|
|
34
|
+
return ` ${where} ${e.message}${detail}`;
|
|
35
|
+
}).join('\n');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function validateSchema(diagramType, data) {
|
|
39
|
+
const validate = validators[diagramType];
|
|
40
|
+
if (!validate) {
|
|
41
|
+
throw new Error(`validateSchema: unknown diagram type "${diagramType}"`);
|
|
42
|
+
}
|
|
43
|
+
if (!validate(data)) {
|
|
44
|
+
const diagnostics = validate.errors.map((error) => {
|
|
45
|
+
const annotated = annotatedPath(error.instancePath, data);
|
|
46
|
+
const subject = {
|
|
47
|
+
diagramType,
|
|
48
|
+
path: annotated.path,
|
|
49
|
+
...(annotated.identity != null ? { identity: String(annotated.identity) } : {}),
|
|
50
|
+
};
|
|
51
|
+
const evidence = {
|
|
52
|
+
keyword: error.keyword,
|
|
53
|
+
expected: error.schema,
|
|
54
|
+
...error.params,
|
|
55
|
+
};
|
|
56
|
+
const supportedFixes = {
|
|
57
|
+
additionalProperties: [`remove unsupported property ${JSON.stringify(error.params?.additionalProperty)}`],
|
|
58
|
+
required: [`add required property ${JSON.stringify(error.params?.missingProperty)}`],
|
|
59
|
+
type: [`use ${JSON.stringify(error.params?.type)} at ${annotated.path}`],
|
|
60
|
+
enum: [`choose one of ${JSON.stringify(error.params?.allowedValues || [])}`],
|
|
61
|
+
pattern: [`match the required pattern ${JSON.stringify(error.params?.pattern)}`],
|
|
62
|
+
minimum: [`use a value ${error.params?.comparison || '>='} ${error.params?.limit}`],
|
|
63
|
+
maximum: [`use a value ${error.params?.comparison || '<='} ${error.params?.limit}`],
|
|
64
|
+
minItems: [`provide at least ${error.params?.limit} item(s)`],
|
|
65
|
+
maxItems: [`provide at most ${error.params?.limit} item(s)`],
|
|
66
|
+
minLength: [`provide at least ${error.params?.limit} character(s)`],
|
|
67
|
+
maxLength: [`provide at most ${error.params?.limit} character(s)`],
|
|
68
|
+
}[error.keyword] || [];
|
|
69
|
+
const detail = error.params && Object.keys(error.params).length
|
|
70
|
+
? ` ${JSON.stringify(error.params)}`
|
|
71
|
+
: '';
|
|
72
|
+
return {
|
|
73
|
+
code: `schema/${error.keyword}`,
|
|
74
|
+
severity: 'error',
|
|
75
|
+
message: `${annotatePath(error.instancePath, data)} ${error.message}${detail}`,
|
|
76
|
+
subject,
|
|
77
|
+
evidence,
|
|
78
|
+
supportedFixes,
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
throwDiagnosticError(
|
|
82
|
+
`${diagramType} schema validation failed:\n${formatErrors(validate.errors, data)}`,
|
|
83
|
+
diagnostics,
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|