@venizia/vulcan 0.4.9-0 → 0.4.9-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 (141) hide show
  1. package/base/extensions/vulcan-guards.ts +48 -41
  2. package/base/hooks/antigravity-guards.ts +2 -2
  3. package/base/hooks/codex-guards.ts +15 -5
  4. package/base/hooks/guard-git.ts +8 -8
  5. package/base/hooks/guard-manifest.ts +4 -5
  6. package/base/hooks/guard-outside.ts +8 -8
  7. package/base/hooks/guard-package.ts +5 -6
  8. package/base/hooks/guard-remote-hosts.ts +6 -7
  9. package/base/hooks/guard-scripting.ts +5 -6
  10. package/base/hooks/guard-writes.ts +8 -9
  11. package/base/hooks/post-tool.ts +2 -2
  12. package/base/hooks/prompt-submit.ts +2 -2
  13. package/base/hooks/session-start.ts +3 -3
  14. package/base/hooks/stop.ts +2 -2
  15. package/base/hooks/subagent-start.ts +2 -2
  16. package/base/skills/docs-update/SKILL.md +4 -2
  17. package/base/skills/visualize-work/SKILL.md +9 -0
  18. package/package.json +3 -3
  19. package/src/agents/atlas-block.ts +43 -43
  20. package/src/agents/codex-hooks.ts +45 -43
  21. package/src/agents/detect.ts +19 -16
  22. package/src/agents/exclude.ts +96 -97
  23. package/src/agents/hooks-json.ts +38 -36
  24. package/src/agents/local.ts +46 -43
  25. package/src/agents/prompt.ts +45 -42
  26. package/src/agents/render.ts +201 -195
  27. package/src/agents/resolve.ts +133 -134
  28. package/src/agents/table.ts +12 -8
  29. package/src/commands/add.command.ts +2 -2
  30. package/src/commands/agents.command.ts +11 -17
  31. package/src/commands/clean.command.ts +6 -6
  32. package/src/commands/doctor.command.ts +4 -4
  33. package/src/commands/init.command.ts +12 -8
  34. package/src/commands/preset.command.ts +2 -2
  35. package/src/commands/profile.command.ts +42 -49
  36. package/src/commands/sync.command.ts +109 -111
  37. package/src/commands/upgrade.command.ts +80 -75
  38. package/src/commands/visualize.command.ts +7 -13
  39. package/src/commands/x.command.ts +55 -50
  40. package/src/common/format.ts +23 -21
  41. package/src/common/json.ts +8 -5
  42. package/src/common/layout-folder.ts +94 -91
  43. package/src/common/paths.ts +14 -12
  44. package/src/config/loader.ts +52 -49
  45. package/src/config/packages.ts +14 -11
  46. package/src/config/schema.ts +3 -3
  47. package/src/create/add-app.ts +519 -509
  48. package/src/create/add-lib.ts +237 -240
  49. package/src/create/bunfig.ts +26 -23
  50. package/src/create/checks.ts +36 -34
  51. package/src/create/diff.ts +21 -23
  52. package/src/create/dockerignore.ts +26 -24
  53. package/src/create/files.ts +7 -5
  54. package/src/create/init-monorepo.ts +75 -80
  55. package/src/create/lib-preset.ts +59 -63
  56. package/src/create/manifest-json.ts +10 -4
  57. package/src/create/names.ts +217 -210
  58. package/src/create/next.ts +26 -23
  59. package/src/create/plan.ts +15 -12
  60. package/src/create/preset-diff.ts +301 -303
  61. package/src/create/preset-menu.ts +38 -32
  62. package/src/create/preset.ts +202 -197
  63. package/src/create/process.ts +79 -72
  64. package/src/create/scratch.ts +48 -49
  65. package/src/create/workspace.ts +404 -396
  66. package/src/doctor/checks.ts +1027 -1014
  67. package/src/doctor/makefile.ts +17 -13
  68. package/src/doctor/runner.ts +88 -118
  69. package/src/doctor/skills.ts +97 -95
  70. package/src/doctor/tags.ts +42 -37
  71. package/src/hooks/codex-patch.ts +25 -22
  72. package/src/hooks/command-view.ts +44 -39
  73. package/src/hooks/decision.ts +37 -37
  74. package/src/hooks/guard-git.ts +51 -49
  75. package/src/hooks/guard-manifest.ts +58 -55
  76. package/src/hooks/guard-outside.ts +93 -91
  77. package/src/hooks/guard-package.ts +82 -79
  78. package/src/hooks/guard-scripting.ts +19 -14
  79. package/src/hooks/guard-writes.ts +154 -149
  80. package/src/hooks/owner-reply.ts +127 -127
  81. package/src/hooks/post-tool.ts +94 -93
  82. package/src/hooks/project-guards.ts +65 -62
  83. package/src/hooks/project-tmp.ts +27 -24
  84. package/src/hooks/remote-hosts.ts +153 -130
  85. package/src/hooks/session-digest.ts +98 -101
  86. package/src/hooks/shell.ts +509 -499
  87. package/src/hooks/subagent-card.ts +11 -7
  88. package/src/hooks/trusted-scripts.ts +106 -104
  89. package/src/init/scaffold.ts +135 -132
  90. package/src/local/clean.ts +38 -36
  91. package/src/local/format.ts +21 -17
  92. package/src/local/scan.ts +144 -138
  93. package/src/manifest/render.ts +110 -104
  94. package/src/owner/card.ts +51 -46
  95. package/src/owner/profile.ts +99 -93
  96. package/src/owner/reply-switch.ts +9 -6
  97. package/src/owner/shape.ts +71 -69
  98. package/src/owner/survey.ts +173 -171
  99. package/src/owner/view.ts +62 -59
  100. package/src/owner/violations.ts +119 -123
  101. package/src/rules/base.ts +15 -11
  102. package/src/rules/parser.ts +39 -32
  103. package/src/rules/slots.ts +8 -6
  104. package/src/signals/claims.ts +30 -28
  105. package/src/signals/classify.ts +38 -33
  106. package/src/signals/loop.ts +39 -37
  107. package/src/signals/state.ts +79 -81
  108. package/src/skills/frontmatter.ts +28 -28
  109. package/src/sync/agent-files.ts +217 -199
  110. package/src/sync/agent-removal.ts +56 -59
  111. package/src/sync/atlas-block.ts +45 -43
  112. package/src/sync/base-rules.ts +32 -30
  113. package/src/sync/claude-launch.ts +36 -34
  114. package/src/sync/exclude.ts +77 -69
  115. package/src/sync/local-choice.ts +50 -47
  116. package/src/sync/planner.ts +59 -61
  117. package/src/sync/prune.ts +52 -48
  118. package/src/sync/settings.ts +166 -167
  119. package/src/ui/capability.ts +12 -7
  120. package/src/ui/keyboard.ts +38 -38
  121. package/src/ui/prompt.ts +79 -77
  122. package/src/visualize/assets.ts +33 -24
  123. package/src/visualize/charts.ts +179 -176
  124. package/src/visualize/compare-css.ts +3 -2
  125. package/src/visualize/compare-render.ts +9 -7
  126. package/src/visualize/diagrams.ts +189 -174
  127. package/src/visualize/grid-span.ts +34 -0
  128. package/src/visualize/icons.ts +7 -5
  129. package/src/visualize/kinds-render.ts +50 -45
  130. package/src/visualize/kinds-validate.ts +12 -10
  131. package/src/visualize/labels.ts +21 -17
  132. package/src/visualize/layout.ts +112 -97
  133. package/src/visualize/page.ts +92 -104
  134. package/src/visualize/render.ts +143 -140
  135. package/src/visualize/sections.ts +395 -384
  136. package/src/visualize/sources.ts +2 -2
  137. package/src/visualize/theme.ts +12 -10
  138. package/src/visualize/validate.ts +13 -9
  139. package/src/wiki/anchors.ts +38 -36
  140. package/src/wiki/command.ts +4 -4
  141. package/src/wiki/source-links.ts +46 -44
@@ -27,23 +27,27 @@ const bundledOf = (opts: { language?: string }): TChrome => {
27
27
  : DEFAULT_CHROME;
28
28
  };
29
29
 
30
- /** The strings of the page: the bundled words of the page's language, with whatever the spec replaces. */
31
- export const chromeOf = (opts: { spec: TVisualizeSpec; language?: string }): TChrome => {
32
- const given = opts.spec.chrome ?? {};
33
- const base = bundledOf({ language: opts.language });
34
- const merged: Record<string, unknown> = { ...base };
30
+ export class Labels {
31
+ /** The strings of the page: the bundled words of the page's language, with whatever the spec replaces. */
32
+ static chromeOf(opts: { spec: TVisualizeSpec; language?: string }): TChrome {
33
+ const given = opts.spec.chrome ?? {};
34
+ const base = bundledOf({ language: opts.language });
35
+ const merged: Record<string, unknown> = { ...base };
35
36
 
36
- for (const [key, value] of Object.entries(given)) {
37
- if (typeof value === 'string') {
38
- merged[key] = value;
37
+ for (const [key, value] of Object.entries(given)) {
38
+ if (typeof value === 'string') {
39
+ merged[key] = value;
40
+ }
39
41
  }
40
- }
41
42
 
42
- return {
43
- ...base,
44
- ...Object.fromEntries(Object.entries(merged).filter(([, value]) => typeof value === 'string')),
45
- statusStates: { ...base.statusStates, ...definedOnly({ value: given.statusStates }) },
46
- minimapStates: { ...base.minimapStates, ...definedOnly({ value: given.minimapStates }) },
47
- evidenceLabels: { ...base.evidenceLabels, ...definedOnly({ value: given.evidenceLabels }) },
48
- };
49
- };
43
+ return {
44
+ ...base,
45
+ ...Object.fromEntries(
46
+ Object.entries(merged).filter(([, value]) => typeof value === 'string'),
47
+ ),
48
+ statusStates: { ...base.statusStates, ...definedOnly({ value: given.statusStates }) },
49
+ minimapStates: { ...base.minimapStates, ...definedOnly({ value: given.minimapStates }) },
50
+ evidenceLabels: { ...base.evidenceLabels, ...definedOnly({ value: given.evidenceLabels }) },
51
+ };
52
+ }
53
+ }
@@ -1,44 +1,22 @@
1
1
  import { NodeStates } from './constants.ts';
2
- import { iconSvg } from './icons.ts';
2
+ import { IconSet } from './icons.ts';
3
3
  import type { TVisualizeSpec } from './schema.ts';
4
4
 
5
- /** Escapes text for HTML and for an attribute value: everything the spec says is data, never markup. */
6
- export const escapeText = (opts: { value: string }): string =>
7
- opts.value
8
- .replaceAll('&', '&amp;')
9
- .replaceAll('<', '&lt;')
10
- .replaceAll('>', '&gt;')
11
- .replaceAll('"', '&quot;')
12
- .replaceAll("'", '&#39;');
13
-
14
5
  const CELL_WIDTH = 290;
15
- const CELL_HEIGHT = 112;
16
- const BOX_WIDTH = 176;
17
- const BOX_HEIGHT = 60;
18
- const MARGIN = 24;
19
6
 
20
- /** Below this share of its natural width the figure is replaced by a list, so no text drops under 12 px. */
21
- export const FIGURE_FIT = 0.92;
7
+ const CELL_HEIGHT = 112;
22
8
 
23
- /** The natural width of a figure of `cols` columns, in pixels. */
24
- export const figureWidth = (opts: { cols: number }): number => MARGIN * 2 + opts.cols * CELL_WIDTH;
9
+ const BOX_WIDTH = 176;
25
10
 
26
- /** How many columns a flow spans. */
27
- export const columnsOf = (opts: { flow: NonNullable<TVisualizeSpec['flow']> }): number =>
28
- Math.max(...opts.flow.nodes.map((node) => node.col)) + 1;
11
+ const BOX_HEIGHT = 60;
29
12
 
30
- interface IPoint {
31
- x: number;
32
- y: number;
33
- }
13
+ const MARGIN = 24;
34
14
 
35
15
  const centreOf = (opts: { row: number; col: number }): IPoint => ({
36
16
  x: MARGIN + opts.col * CELL_WIDTH + CELL_WIDTH / 2,
37
17
  y: MARGIN + opts.row * CELL_HEIGHT + CELL_HEIGHT / 2,
38
18
  });
39
19
 
40
- const escaped = (value: string): string => escapeText({ value });
41
-
42
20
  /**
43
21
  * The route of an edge between two box centres: straight when they share a row or a column, else an
44
22
  * elbow - along the source's row, then along the target's column. The label sits on the longest run.
@@ -85,78 +63,115 @@ const routeOf = (opts: { from: IPoint; to: IPoint }): { path: string; label: IPo
85
63
  };
86
64
  };
87
65
 
88
- /** The figure: boxes on a grid, arrows between them. Every part carries a `data-` id the page script highlights. */
89
- export const renderFigure = (opts: { flow: NonNullable<TVisualizeSpec['flow']> }): string => {
90
- const { flow } = opts;
91
- const byId = new Map(flow.nodes.map((node) => [node.id, node]));
92
- const width = figureWidth({ cols: columnsOf({ flow }) });
93
- const height = MARGIN * 2 + (Math.max(...flow.nodes.map((node) => node.row)) + 1) * CELL_HEIGHT;
94
- const edges = flow.edges
95
- .map((edge) => {
96
- const from = byId.get(edge.from);
97
- const to = byId.get(edge.to);
98
-
99
- if (from === undefined || to === undefined) {
100
- return '';
101
- }
102
-
103
- const route = routeOf({ from: centreOf(from), to: centreOf(to) });
104
- const name = `${edge.from}>${edge.to}`;
105
- // What the owner starts is drawn in the hot colour; a failure keeps its own red.
106
- const hot = from.state === 'waiting' && edge.variant !== 'error';
107
- const head = edge.variant === 'error' ? 'e' : hot ? 'h' : 'a';
108
-
109
- return `<g class="edge ${escaped(edge.variant ?? 'main')}${hot ? ' hot' : ''}" data-edge="${escaped(name)}"><title>${escaped(edge.label)}</title><path d="${route.path}" marker-end="url(#${head})"/><text x="${route.label.x}" y="${route.label.y}" text-anchor="middle">${escaped(edge.label)}</text></g>`;
110
- })
111
- .join('');
112
- const nodes = flow.nodes
113
- .map((node) => {
114
- const centre = centreOf(node);
115
- const lines = node.sublabel === undefined ? 1 : 2;
116
- const tone = node.state === undefined ? '' : ` c-${NodeStates.toneOf(node.state)}`;
117
- const gate = node.state === 'waiting';
118
- const left = centre.x - BOX_WIDTH / 2;
119
- const anchor = node.state === undefined ? 'middle' : 'start';
120
- const textX =
121
- node.state === undefined ? centre.x : left + (node.state === 'waiting' ? 48 : 40);
66
+ export class FigureLayout {
67
+ private static escaped(value: string): string {
68
+ return FigureLayout.escapeText({ value });
69
+ }
70
+
71
+ /** Escapes text for HTML and for an attribute value: everything the spec says is data, never markup. */
72
+ static escapeText(opts: { value: string }): string {
73
+ return opts.value
74
+ .replaceAll('&', '&amp;')
75
+ .replaceAll('<', '&lt;')
76
+ .replaceAll('>', '&gt;')
77
+ .replaceAll('"', '&quot;')
78
+ .replaceAll("'", '&#39;');
79
+ }
80
+
81
+ /** The natural width of a figure of `cols` columns, in pixels. */
82
+ static figureWidth(opts: { cols: number }): number {
83
+ return MARGIN * 2 + opts.cols * CELL_WIDTH;
84
+ }
85
+
86
+ /** How many columns a flow spans. */
87
+ static columnsOf(opts: { flow: NonNullable<TVisualizeSpec['flow']> }): number {
88
+ return Math.max(...opts.flow.nodes.map((node) => node.col)) + 1;
89
+ }
90
+
91
+ /** The figure: boxes on a grid, arrows between them. Every part carries a `data-` id the page script highlights. */
92
+ static render(opts: { flow: NonNullable<TVisualizeSpec['flow']> }): string {
93
+ const { flow } = opts;
94
+ const byId = new Map(flow.nodes.map((node) => [node.id, node]));
95
+ const width = FigureLayout.figureWidth({ cols: FigureLayout.columnsOf({ flow }) });
96
+ const height = MARGIN * 2 + (Math.max(...flow.nodes.map((node) => node.row)) + 1) * CELL_HEIGHT;
97
+ const edges = flow.edges
98
+ .map((edge) => {
99
+ const from = byId.get(edge.from);
100
+ const to = byId.get(edge.to);
101
+
102
+ if (from === undefined || to === undefined) {
103
+ return '';
104
+ }
105
+
106
+ const route = routeOf({ from: centreOf(from), to: centreOf(to) });
107
+ const name = `${edge.from}>${edge.to}`;
108
+ // What the owner starts is drawn in the hot colour; a failure keeps its own red.
109
+ const hot = from.state === 'waiting' && edge.variant !== 'error';
110
+ const head = edge.variant === 'error' ? 'e' : hot ? 'h' : 'a';
111
+
112
+ return `<g class="edge ${FigureLayout.escaped(edge.variant ?? 'main')}${hot ? ' hot' : ''}" data-edge="${FigureLayout.escaped(name)}"><title>${FigureLayout.escaped(edge.label)}</title><path d="${route.path}" marker-end="url(#${head})"/><text x="${route.label.x}" y="${route.label.y}" text-anchor="middle">${FigureLayout.escaped(edge.label)}</text></g>`;
113
+ })
114
+ .join('');
115
+ const nodes = flow.nodes
116
+ .map((node) => {
117
+ const centre = centreOf(node);
118
+ const lines = node.sublabel === undefined ? 1 : 2;
119
+ const tone = node.state === undefined ? '' : ` c-${NodeStates.toneOf(node.state)}`;
120
+ const gate = node.state === 'waiting';
121
+ const left = centre.x - BOX_WIDTH / 2;
122
+ const anchor = node.state === undefined ? 'middle' : 'start';
123
+ const textX =
124
+ node.state === undefined ? centre.x : left + (node.state === 'waiting' ? 48 : 40);
125
+ const mark =
126
+ node.state === undefined
127
+ ? ''
128
+ : `${gate ? `<circle class="halo" cx="${left + 22}" cy="${centre.y}" r="20"/><circle class="core" cx="${left + 22}" cy="${centre.y}" r="13"/>` : ''}<g class="st" transform="translate(${left + 12} ${centre.y - 10})">${IconSet.iconSvg({ name: NodeStates.iconOf(node.state), size: 20 }).replace('<svg', '<svg x="0" y="0"')}</g>`;
129
+
130
+ return `<g class="node ${FigureLayout.escaped(node.kind ?? 'step')}${tone}${gate ? ' gate' : ''}" tabindex="0" role="img" aria-label="${FigureLayout.escaped(node.label)}${node.sublabel === undefined ? '' : `, ${FigureLayout.escaped(node.sublabel)}`}" data-node="${FigureLayout.escaped(node.id)}" data-detail="${FigureLayout.escaped(node.detail ?? node.sublabel ?? node.label)}"><title>${FigureLayout.escaped(node.label)}</title><rect x="${left}" y="${centre.y - BOX_HEIGHT / 2}" width="${BOX_WIDTH}" height="${BOX_HEIGHT}" rx="4"/>${mark}<text x="${textX}" y="${centre.y + (lines === 1 ? 5 : -4)}" text-anchor="${anchor}" class="t">${FigureLayout.escaped(node.label)}</text>${node.sublabel === undefined ? '' : `<text x="${textX}" y="${centre.y + 17}" text-anchor="${anchor}" class="s">${FigureLayout.escaped(node.sublabel)}</text>`}</g>`;
131
+ })
132
+ .join('');
133
+
134
+ return `<svg width="${width}" height="${height}" viewBox="0 0 ${width} ${height}" role="group" aria-label="flow"><defs><marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="13" markerHeight="13" markerUnits="userSpaceOnUse" orient="auto"><path class="ah" d="M0 0L10 5L0 10z"/></marker><marker id="e" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="13" markerHeight="13" markerUnits="userSpaceOnUse" orient="auto"><path class="bad" d="M0 0L10 5L0 10z"/></marker><marker id="h" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="15" markerHeight="15" markerUnits="userSpaceOnUse" orient="auto"><path class="hot" d="M0 0L10 5L0 10z"/></marker></defs>${edges}${nodes}</svg>`;
135
+ }
136
+
137
+ /**
138
+ * The same flow as a list, for a phone where the figure cannot be read: one row per arrow, then one per box that
139
+ * has a detail. Page CSS shows it only on a narrow screen.
140
+ */
141
+ static renderPathList(opts: { flow: NonNullable<TVisualizeSpec['flow']> }): string {
142
+ const { flow } = opts;
143
+ const byId = new Map(flow.nodes.map((node) => [node.id, node]));
144
+ const nameOf = (id: string): string => {
145
+ const node = byId.get(id);
122
146
  const mark =
123
- node.state === undefined
147
+ node?.state === undefined
124
148
  ? ''
125
- : `${gate ? `<circle class="halo" cx="${left + 22}" cy="${centre.y}" r="20"/><circle class="core" cx="${left + 22}" cy="${centre.y}" r="13"/>` : ''}<g class="st" transform="translate(${left + 12} ${centre.y - 10})">${iconSvg({ name: NodeStates.iconOf(node.state), size: 20 }).replace('<svg', '<svg x="0" y="0"')}</g>`;
149
+ : `<span class="inl c-${NodeStates.toneOf(node.state)}">${IconSet.iconSvg({ name: NodeStates.iconOf(node.state), size: 16 })}</span>`;
126
150
 
127
- return `<g class="node ${escaped(node.kind ?? 'step')}${tone}${gate ? ' gate' : ''}" tabindex="0" role="img" aria-label="${escaped(node.label)}${node.sublabel === undefined ? '' : `, ${escaped(node.sublabel)}`}" data-node="${escaped(node.id)}" data-detail="${escaped(node.detail ?? node.sublabel ?? node.label)}"><title>${escaped(node.label)}</title><rect x="${left}" y="${centre.y - BOX_HEIGHT / 2}" width="${BOX_WIDTH}" height="${BOX_HEIGHT}" rx="4"/>${mark}<text x="${textX}" y="${centre.y + (lines === 1 ? 5 : -4)}" text-anchor="${anchor}" class="t">${escaped(node.label)}</text>${node.sublabel === undefined ? '' : `<text x="${textX}" y="${centre.y + 17}" text-anchor="${anchor}" class="s">${escaped(node.sublabel)}</text>`}</g>`;
128
- })
129
- .join('');
151
+ return `${mark}${FigureLayout.escaped(node?.label ?? id)}`;
152
+ };
153
+ const arrows = flow.edges
154
+ .map(
155
+ (edge) =>
156
+ `<li><b>${nameOf(edge.from)}</b><span class="verb ${FigureLayout.escaped(edge.variant ?? 'main')}">${FigureLayout.escaped(edge.label)}</span><b>${nameOf(edge.to)}</b></li>`,
157
+ )
158
+ .join('');
159
+ const details = flow.nodes
160
+ .filter((node) => node.detail !== undefined)
161
+ .map(
162
+ (node) =>
163
+ `<li><b>${FigureLayout.escaped(node.label)}</b> ${FigureLayout.escaped(node.detail ?? '')}</li>`,
164
+ )
165
+ .join('');
166
+
167
+ return `<ol class="path">${arrows}</ol>${details === '' ? '' : `<ul class="path-detail">${details}</ul>`}`;
168
+ }
169
+ }
130
170
 
131
- return `<svg width="${width}" height="${height}" viewBox="0 0 ${width} ${height}" role="group" aria-label="flow"><defs><marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="13" markerHeight="13" markerUnits="userSpaceOnUse" orient="auto"><path class="ah" d="M0 0L10 5L0 10z"/></marker><marker id="e" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="13" markerHeight="13" markerUnits="userSpaceOnUse" orient="auto"><path class="bad" d="M0 0L10 5L0 10z"/></marker><marker id="h" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="15" markerHeight="15" markerUnits="userSpaceOnUse" orient="auto"><path class="hot" d="M0 0L10 5L0 10z"/></marker></defs>${edges}${nodes}</svg>`;
132
- };
171
+ /** Below this share of its natural width the figure is replaced by a list, so no text drops under 12 px. */
172
+ export const FIGURE_FIT = 0.92;
133
173
 
134
- /**
135
- * The same flow as a list, for a phone where the figure cannot be read: one row per arrow, then one per box that
136
- * has a detail. Page CSS shows it only on a narrow screen.
137
- */
138
- export const renderPathList = (opts: { flow: NonNullable<TVisualizeSpec['flow']> }): string => {
139
- const { flow } = opts;
140
- const byId = new Map(flow.nodes.map((node) => [node.id, node]));
141
- const nameOf = (id: string): string => {
142
- const node = byId.get(id);
143
- const mark =
144
- node?.state === undefined
145
- ? ''
146
- : `<span class="inl c-${NodeStates.toneOf(node.state)}">${iconSvg({ name: NodeStates.iconOf(node.state), size: 16 })}</span>`;
147
-
148
- return `${mark}${escaped(node?.label ?? id)}`;
149
- };
150
- const arrows = flow.edges
151
- .map(
152
- (edge) =>
153
- `<li><b>${nameOf(edge.from)}</b><span class="verb ${escaped(edge.variant ?? 'main')}">${escaped(edge.label)}</span><b>${nameOf(edge.to)}</b></li>`,
154
- )
155
- .join('');
156
- const details = flow.nodes
157
- .filter((node) => node.detail !== undefined)
158
- .map((node) => `<li><b>${escaped(node.label)}</b> ${escaped(node.detail ?? '')}</li>`)
159
- .join('');
160
-
161
- return `<ol class="path">${arrows}</ol>${details === '' ? '' : `<ul class="path-detail">${details}</ul>`}`;
162
- };
174
+ interface IPoint {
175
+ x: number;
176
+ y: number;
177
+ }
@@ -1,43 +1,24 @@
1
1
  import { createHash } from 'node:crypto';
2
- import { HEAD_JS, PAGE_JS, pageCss } from './assets.ts';
2
+ import { Assets, HEAD_JS, PAGE_JS } from './assets.ts';
3
3
  import { NodeStates } from './constants.ts';
4
4
  import type { TChrome } from './constants.ts';
5
- import { iconSvg } from './icons.ts';
6
- import { stateIcon } from './charts.ts';
5
+ import { IconSet } from './icons.ts';
6
+ import { SpecCharts } from './charts.ts';
7
7
  import { COMPARE_CSS } from './compare-css.ts';
8
8
  import { CompareView } from './compare-render.ts';
9
9
  import { NEW_KINDS_CSS } from './kinds-css.ts';
10
- import { lifecycleSection, sequenceSection, treeSection } from './kinds-render.ts';
11
- import { chromeOf } from './labels.ts';
12
- import { escapeText, FIGURE_FIT } from './layout.ts';
10
+ import { KindsRender } from './kinds-render.ts';
11
+ import { GridSpans } from './grid-span.ts';
12
+ import { Labels } from './labels.ts';
13
+ import { FIGURE_FIT, FigureLayout } from './layout.ts';
13
14
  import type { TVisualizeSpec } from './schema.ts';
14
15
  import { PageTerms, SourceRefs } from './sources.ts';
15
16
  import { ProjectTheme } from './theme.ts';
16
17
  import type { IResolvedTheme } from './theme.ts';
17
- import {
18
- architectureSection,
19
- beforeAfterSection,
20
- chip,
21
- comparisonSection,
22
- decisionRecordSection,
23
- decisionsSection,
24
- evidenceSection,
25
- explainerSection,
26
- findingsSection,
27
- flowSection,
28
- ideaMapSection,
29
- linksSection,
30
- logSection,
31
- risksSection,
32
- section,
33
- sectionLinks,
34
- stateWord,
35
- tilesHtml,
36
- timelineSection,
37
- } from './sections.ts';
18
+ import { SpecSections } from './sections.ts';
38
19
  import type { ISectionContext } from './sections.ts';
39
20
 
40
- const escaped = (value: string): string => escapeText({ value });
21
+ const escaped = (value: string): string => FigureLayout.escapeText({ value });
41
22
 
42
23
  /** The mark of the top bar: a diamond in the hot colour. */
43
24
  const MARK =
@@ -85,22 +66,22 @@ const countTiles = (opts: {
85
66
  return [
86
67
  {
87
68
  value: `${count('done')} / ${rows.length}`,
88
- label: stateWord({ chrome: opts.chrome, state: 'done' }),
69
+ label: SpecSections.stateWord({ chrome: opts.chrome, state: 'done' }),
89
70
  state: 'done',
90
71
  },
91
72
  {
92
73
  value: String(count('in progress')),
93
- label: stateWord({ chrome: opts.chrome, state: 'in progress' }),
74
+ label: SpecSections.stateWord({ chrome: opts.chrome, state: 'in progress' }),
94
75
  state: 'in progress',
95
76
  },
96
77
  {
97
78
  value: String(count('waiting')),
98
- label: stateWord({ chrome: opts.chrome, state: 'waiting' }),
79
+ label: SpecSections.stateWord({ chrome: opts.chrome, state: 'waiting' }),
99
80
  state: 'waiting',
100
81
  },
101
82
  {
102
83
  value: String(count('blocked')),
103
- label: stateWord({ chrome: opts.chrome, state: 'blocked' }),
84
+ label: SpecSections.stateWord({ chrome: opts.chrome, state: 'blocked' }),
104
85
  state: 'blocked',
105
86
  },
106
87
  ];
@@ -130,7 +111,7 @@ const heroHtml = (opts: { ctx: ISectionContext }): string => {
130
111
  spec.scope === undefined ? '' : `<span>${escaped(chrome.scope)}: ${escaped(spec.scope)}</span>`,
131
112
  ].join('');
132
113
 
133
- return `<div class="banner slab c-${tone}" data-slide data-hero><div class="wrap hero"><p class="state">${stateIcon({ state, size: 22 })}<span class="word">${escaped(word)}</span></p><h1>${escaped(spec.title)}</h1><p class="lede">${escaped(spec.verdict)}</p>${spec.caption === undefined ? '' : `<p class="cap">${escaped(spec.caption)}</p>`}${meta === '' ? '' : `<p class="meta">${meta}</p>`}${flowSection({ ctx: opts.ctx })}</div></div>`;
114
+ return `<div class="banner slab c-${tone}" data-slide data-hero><div class="wrap hero"><p class="state">${SpecCharts.stateIcon({ state, size: 22 })}<span class="word">${escaped(word)}</span></p><h1>${escaped(spec.title)}</h1><p class="lede">${escaped(spec.verdict)}</p>${spec.caption === undefined ? '' : `<p class="cap">${escaped(spec.caption)}</p>`}${meta === '' ? '' : `<p class="meta">${meta}</p>`}${SpecSections.flow({ ctx: opts.ctx })}</div></div>`;
134
115
  };
135
116
 
136
117
  /** The minimap as a track: a stripe, a shape and a word for every task. */
@@ -146,7 +127,7 @@ const stepperHtml = (opts: { spec: TVisualizeSpec; chrome: TChrome }): string =>
146
127
  return `<section class="part" id="minimap" data-slide><div class="wrap"><h2 class="sh">${escaped(chrome.minimap)}</h2><ol class="strip">${minimap
147
128
  .map(
148
129
  (row) =>
149
- `<li class="seg c-${NodeStates.toneOf(row.status)}"><span class="bar"></span><span class="nm">${chip({ chrome, state: row.status })}<span class="tn">${escaped(row.task)}</span></span>${row.note === undefined ? '' : `<span class="nt">${escaped(row.note)}</span>`}</li>`,
130
+ `<li class="seg c-${NodeStates.toneOf(row.status)}"><span class="bar"></span><span class="nm">${SpecSections.chip({ chrome, state: row.status })}<span class="tn">${escaped(row.task)}</span></span>${row.note === undefined ? '' : `<span class="nt">${escaped(row.note)}</span>`}</li>`,
150
131
  )
151
132
  .join('')}</ol></div></section>`;
152
133
  };
@@ -168,7 +149,7 @@ const ownerHtml = (opts: { spec: TVisualizeSpec; chrome: TChrome }): string => {
168
149
  ? ''
169
150
  : `<ol class="check">${spec.actions.map((action) => `<li>${escaped(action)}</li>`).join('')}</ol>`;
170
151
 
171
- return `<section class="two" id="next" data-slide><div class="wrap"><div class="own"><div class="nx"><p class="lab">${escaped(chrome.next)}</p><h2>${escaped(spec.strip.next)}</h2>${actions}${jump}</div><div class="stop"><p class="lab">${escaped(chrome.blockedBy)}</p><p>${escaped(spec.strip.blockedBy)}</p></div></div><div class="facts"><p class="fact">${iconSvg({ name: 'done', size: 18 })}<span><b>${escaped(chrome.healthy)}</b> ${escaped(spec.strip.healthy)}</span></p><p class="fact">${iconSvg({ name: 'info', size: 18 })}<span><b>${escaped(chrome.changed)}</b> ${escaped(spec.strip.changed)}</span></p></div></div></section>`;
152
+ return `<section class="two" id="next" data-slide><div class="wrap"><div class="own"><div class="nx"><p class="lab">${escaped(chrome.next)}</p><h2>${escaped(spec.strip.next)}</h2>${actions}${jump}</div><div class="stop"><p class="lab">${escaped(chrome.blockedBy)}</p><p>${escaped(spec.strip.blockedBy)}</p></div></div><div class="facts"><p class="fact">${IconSet.iconSvg({ name: 'done', size: 18 })}<span><b>${escaped(chrome.healthy)}</b> ${escaped(spec.strip.healthy)}</span></p><p class="fact">${IconSet.iconSvg({ name: 'info', size: 18 })}<span><b>${escaped(chrome.changed)}</b> ${escaped(spec.strip.changed)}</span></p></div></div></section>`;
172
153
  };
173
154
 
174
155
  /** The neutral theme of a page that is given none. */
@@ -184,72 +165,79 @@ const NEUTRAL = ((): IResolvedTheme => {
184
165
  return resolved.theme;
185
166
  })();
186
167
 
187
- /** The whole page: one file, no network, a content-security policy that allows only the page's own style and scripts by hash. */
188
- export const renderPage = (opts: {
189
- spec: TVisualizeSpec;
190
- /** The page's language: the spec's, else the owner's profile, else English. */
191
- language?: string;
192
- /** The checked colours of the page; the stylesheet takes its tokens from them. */
193
- theme?: IResolvedTheme;
194
- }): string => {
195
- const { spec } = opts;
196
- const language = opts.language ?? spec.language ?? 'en';
197
- const chrome = chromeOf({ spec, language });
198
- const ctx: ISectionContext = { spec, chrome, fits: new Set<number>() };
199
- const { state, tone, word } = stateOf({ spec, chrome });
200
- const sources = SourceRefs.entries({ spec, chrome });
201
- const tiles =
202
- spec.tiles ?? (spec.minimap === undefined ? undefined : countTiles({ spec, chrome }));
203
- const body = [
204
- heroHtml({ ctx }),
205
- tiles === undefined
206
- ? ''
207
- : `<div data-slide class="slide-tiles"><div class="wrap">${tilesHtml({ tiles, chrome })}</div></div>`,
208
- stepperHtml({ spec, chrome }),
209
- ownerHtml({ spec, chrome }),
210
- architectureSection({ ctx }),
211
- CompareView.section({ ctx }),
212
- sequenceSection({ ctx }),
213
- lifecycleSection({ ctx }),
214
- treeSection({ ctx }),
215
- comparisonSection({ ctx }),
216
- ideaMapSection({ ctx }),
217
- explainerSection({ ctx }),
218
- timelineSection({ ctx }),
219
- findingsSection({ ctx }),
220
- beforeAfterSection({ ctx }),
221
- decisionRecordSection({ ctx }),
222
- decisionsSection({ ctx }),
223
- evidenceSection({ ctx }),
224
- risksSection({ ctx }),
225
- logSection({ ctx }),
226
- spec.terms === undefined
227
- ? ''
228
- : section({
229
- id: 'terms',
230
- title: chrome.terms,
231
- body: PageTerms.listHtml({ terms: spec.terms }),
232
- }),
233
- sources.length === 0
234
- ? ''
235
- : section({
236
- id: 'sources',
237
- title: chrome.sources,
238
- body: SourceRefs.listHtml({ entries: sources }),
239
- }),
240
- linksSection({ ctx }),
241
- ].join('');
242
- const css = `${pageCss({ tokens: ProjectTheme.tokensCss({ theme: opts.theme ?? NEUTRAL }) })}\n${NEW_KINDS_CSS}\n${COMPARE_CSS}\n${figureFitCss({ widths: ctx.fits })}`;
243
- const policy = `default-src 'none'; style-src ${sha256({ text: css })}; script-src ${sha256({ text: HEAD_JS })} ${sha256({ text: PAGE_JS })}; base-uri 'none'; form-action 'none'`;
244
- const links = sectionLinks({ spec, chrome })
245
- .map((link) => `<a href="#${link.id}">${escaped(link.title)}</a>`)
246
- .join('');
247
- const stamp =
248
- spec.asOf === undefined
249
- ? ''
250
- : `<span class="sep" aria-hidden="true"></span><span class="stamp">${escaped(spec.asOf)}</span>`;
251
- const bar = `<header class="top slab c-${tone}"><div class="wrap">${MARK}<b class="ttl">${escaped(spec.title)}</b>${chip({ chrome, state, size: 18, label: word })}<nav aria-label="${escaped(chrome.navLabel)}"><span class="links">${links}</span>${stamp}<span class="sep" aria-hidden="true"></span><button class="btn js-only" id="present" type="button" data-on="${escaped(chrome.present)}" data-off="${escaped(chrome.exitPresent)}">${escaped(chrome.present)}</button><button class="theme" id="theme" type="button" aria-label="${escaped(chrome.themeToDark)}" data-to-light="${escaped(chrome.themeToLight)}" data-to-dark="${escaped(chrome.themeToDark)}">${iconSvg({ name: 'sun', size: 20, className: 'sun' })}${iconSvg({ name: 'moon', size: 20, className: 'moon' })}<span class="tip" aria-hidden="true"></span></button></nav></div></header>`;
252
- const deck = `<nav class="deck" aria-label="${escaped(chrome.slide)}"><button class="btn" id="slide-prev" type="button">${escaped(chrome.previous)}</button><span id="slide-count" aria-live="polite"></span><button class="btn" id="slide-next" type="button">${escaped(chrome.following)}</button></nav>`;
253
-
254
- return `<!doctype html><html lang="${escaped(language)}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover"><meta http-equiv="Content-Security-Policy" content="${escaped(policy)}"><meta name="generator" content="vulcan visualize"><title>${escaped(spec.title)}</title><script>${HEAD_JS}</script><style>${css}</style></head><body>${bar}<main>${body}</main><footer class="slab foot"><div class="wrap"><p>${escaped(chrome.footer)}</p></div></footer>${deck}<script>${PAGE_JS}</script></body></html>`;
255
- };
168
+ export class PageShell {
169
+ /** The whole page: one file, no network, a content-security policy that allows only the page's own style and scripts by hash. */
170
+ static render(opts: {
171
+ spec: TVisualizeSpec;
172
+ /** The page's language: the spec's, else the owner's profile, else English. */
173
+ language?: string;
174
+ /** The checked colours of the page; the stylesheet takes its tokens from them. */
175
+ theme?: IResolvedTheme;
176
+ }): string {
177
+ const { spec } = opts;
178
+ const language = opts.language ?? spec.language ?? 'en';
179
+ const chrome = Labels.chromeOf({ spec, language });
180
+ const ctx: ISectionContext = {
181
+ spec,
182
+ chrome,
183
+ fits: new Set<number>(),
184
+ spans: new Set<number>(),
185
+ };
186
+ const { state, tone, word } = stateOf({ spec, chrome });
187
+ const sources = SourceRefs.entries({ spec, chrome });
188
+ const tiles =
189
+ spec.tiles ?? (spec.minimap === undefined ? undefined : countTiles({ spec, chrome }));
190
+ const body = [
191
+ heroHtml({ ctx }),
192
+ tiles === undefined
193
+ ? ''
194
+ : `<div data-slide class="slide-tiles"><div class="wrap">${SpecSections.tilesHtml({ tiles, chrome })}</div></div>`,
195
+ stepperHtml({ spec, chrome }),
196
+ ownerHtml({ spec, chrome }),
197
+ SpecSections.architecture({ ctx }),
198
+ CompareView.section({ ctx }),
199
+ KindsRender.sequenceSection({ ctx }),
200
+ KindsRender.lifecycleSection({ ctx }),
201
+ KindsRender.treeSection({ ctx }),
202
+ SpecSections.comparison({ ctx }),
203
+ SpecSections.ideaMap({ ctx }),
204
+ SpecSections.explainer({ ctx }),
205
+ SpecSections.timeline({ ctx }),
206
+ SpecSections.findings({ ctx }),
207
+ SpecSections.beforeAfter({ ctx }),
208
+ SpecSections.decisionRecord({ ctx }),
209
+ SpecSections.decisions({ ctx }),
210
+ SpecSections.evidence({ ctx }),
211
+ SpecSections.risks({ ctx }),
212
+ SpecSections.log({ ctx }),
213
+ spec.terms === undefined
214
+ ? ''
215
+ : SpecSections.section({
216
+ id: 'terms',
217
+ title: chrome.terms,
218
+ body: PageTerms.listHtml({ terms: spec.terms }),
219
+ }),
220
+ sources.length === 0
221
+ ? ''
222
+ : SpecSections.section({
223
+ id: 'sources',
224
+ title: chrome.sources,
225
+ body: SourceRefs.listHtml({ entries: sources }),
226
+ }),
227
+ SpecSections.links({ ctx }),
228
+ ].join('');
229
+ const css = `${Assets.pageCss({ tokens: ProjectTheme.tokensCss({ theme: opts.theme ?? NEUTRAL }) })}\n${NEW_KINDS_CSS}\n${COMPARE_CSS}\n${GridSpans.css({ spans: ctx.spans })}\n${figureFitCss({ widths: ctx.fits })}`;
230
+ const policy = `default-src 'none'; style-src ${sha256({ text: css })}; script-src ${sha256({ text: HEAD_JS })} ${sha256({ text: PAGE_JS })}; base-uri 'none'; form-action 'none'`;
231
+ const links = SpecSections.sectionLinks({ spec, chrome })
232
+ .map((link) => `<a href="#${link.id}">${escaped(link.title)}</a>`)
233
+ .join('');
234
+ const stamp =
235
+ spec.asOf === undefined
236
+ ? ''
237
+ : `<span class="sep" aria-hidden="true"></span><span class="stamp">${escaped(spec.asOf)}</span>`;
238
+ const bar = `<header class="top slab c-${tone}"><div class="wrap">${MARK}<b class="ttl">${escaped(spec.title)}</b>${SpecSections.chip({ chrome, state, size: 18, label: word })}<nav aria-label="${escaped(chrome.navLabel)}"><span class="links">${links}</span>${stamp}<span class="sep" aria-hidden="true"></span><button class="btn js-only" id="present" type="button" data-on="${escaped(chrome.present)}" data-off="${escaped(chrome.exitPresent)}">${escaped(chrome.present)}</button><button class="theme" id="theme" type="button" aria-label="${escaped(chrome.themeToDark)}" data-to-light="${escaped(chrome.themeToLight)}" data-to-dark="${escaped(chrome.themeToDark)}">${IconSet.iconSvg({ name: 'sun', size: 20, className: 'sun' })}${IconSet.iconSvg({ name: 'moon', size: 20, className: 'moon' })}<span class="tip" aria-hidden="true"></span></button></nav></div></header>`;
239
+ const deck = `<nav class="deck" aria-label="${escaped(chrome.slide)}"><button class="btn" id="slide-prev" type="button">${escaped(chrome.previous)}</button><span id="slide-count" aria-live="polite"></span><button class="btn" id="slide-next" type="button">${escaped(chrome.following)}</button></nav>`;
240
+
241
+ return `<!doctype html><html lang="${escaped(language)}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover"><meta http-equiv="Content-Security-Policy" content="${escaped(policy)}"><meta name="generator" content="vulcan visualize"><title>${escaped(spec.title)}</title><script>${HEAD_JS}</script><style>${css}</style></head><body>${bar}<main>${body}</main><footer class="slab foot"><div class="wrap"><p>${escaped(chrome.footer)}</p></div></footer>${deck}<script>${PAGE_JS}</script></body></html>`;
242
+ }
243
+ }