@venizia/vulcan 0.4.8 → 0.4.9-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.
Files changed (126) hide show
  1. package/base/hooks/antigravity-guards.ts +2 -1
  2. package/base/hooks/codex-guards.ts +2 -1
  3. package/base/hooks/guard-manifest.ts +2 -1
  4. package/base/hooks/guard-package.ts +2 -1
  5. package/base/hooks/guard-remote-hosts.ts +9 -3
  6. package/base/hooks/guard-scripting.ts +2 -1
  7. package/base/hooks/guard-writes.ts +14 -4
  8. package/base/hooks/post-tool.ts +2 -1
  9. package/base/hooks/prompt-submit.ts +2 -1
  10. package/base/hooks/session-start.ts +3 -1
  11. package/base/hooks/stop.ts +2 -1
  12. package/base/make/vulcan.mk +1 -4
  13. package/base/skills/build-a-feature/SKILL.md +1 -1
  14. package/base/skills/docs-update/SKILL.md +11 -5
  15. package/base/skills/docs-update/evals/evals.json +1 -1
  16. package/base/skills/docs-writing/SKILL.md +1 -1
  17. package/base/skills/plan-a-change/references/spec-card.md +1 -1
  18. package/base/skills/ship/SKILL.md +1 -1
  19. package/base/skills/visualize-work/SKILL.md +20 -6
  20. package/base/skills/visualize-work/references/spec.md +16 -5
  21. package/package.json +5 -6
  22. package/src/agents/codex-hooks.ts +11 -10
  23. package/src/agents/common/types.ts +1 -1
  24. package/src/agents/exclude.ts +1 -1
  25. package/src/agents/hooks-json.ts +4 -8
  26. package/src/agents/prompt.ts +2 -2
  27. package/src/agents/render.ts +8 -12
  28. package/src/cli.ts +3 -1
  29. package/src/commands/doctor.command.ts +3 -1
  30. package/src/commands/help.command.ts +11 -9
  31. package/src/commands/init.command.ts +3 -1
  32. package/src/commands/profile.command.ts +1 -1
  33. package/src/commands/upgrade.command.ts +5 -3
  34. package/src/commands/visualize.command.ts +23 -2
  35. package/src/common/index.ts +2 -0
  36. package/src/common/layout-folder.ts +2 -20
  37. package/src/common/record.ts +7 -0
  38. package/src/common/text.ts +7 -0
  39. package/src/config/common/constants.ts +13 -1
  40. package/src/config/common/types.ts +8 -1
  41. package/src/config/loader.ts +4 -2
  42. package/src/config/packages.ts +4 -1
  43. package/src/config/schema.ts +51 -4
  44. package/src/create/add-app.ts +170 -69
  45. package/src/create/add-lib.ts +41 -31
  46. package/src/create/common/constants.ts +1 -0
  47. package/src/create/common/failure.ts +10 -0
  48. package/src/create/common/index.ts +2 -0
  49. package/src/create/common/preset-path.ts +11 -0
  50. package/src/create/common/types.ts +7 -2
  51. package/src/create/init-monorepo.ts +5 -2
  52. package/src/create/lib-preset.ts +22 -17
  53. package/src/create/names.ts +1 -1
  54. package/src/create/next.ts +1 -1
  55. package/src/create/preset-diff.ts +232 -55
  56. package/src/create/preset-menu.ts +3 -3
  57. package/src/create/preset.ts +18 -10
  58. package/src/create/process.ts +4 -2
  59. package/src/create/scratch.ts +3 -1
  60. package/src/create/workspace.ts +37 -20
  61. package/src/doctor/checks.ts +74 -16
  62. package/src/doctor/runner.ts +2 -0
  63. package/src/doctor/tags.ts +2 -4
  64. package/src/hooks/codex-patch.ts +2 -2
  65. package/src/hooks/common/constants.ts +0 -3
  66. package/src/hooks/common/types.ts +15 -1
  67. package/src/hooks/decision.ts +1 -5
  68. package/src/hooks/guard-git.ts +1 -1
  69. package/src/hooks/guard-outside.ts +28 -9
  70. package/src/hooks/guard-package.ts +13 -7
  71. package/src/hooks/guard-scripting.ts +1 -1
  72. package/src/hooks/guard-writes.ts +73 -20
  73. package/src/hooks/owner-reply.ts +1 -1
  74. package/src/hooks/project-guards.ts +39 -4
  75. package/src/hooks/remote-hosts.ts +5 -20
  76. package/src/hooks/session-digest.ts +7 -0
  77. package/src/hooks/shell.ts +13 -4
  78. package/src/hooks/trusted-scripts.ts +80 -4
  79. package/src/init/common/types.ts +1 -1
  80. package/src/init/scaffold.ts +2 -2
  81. package/src/local/clean.ts +1 -1
  82. package/src/local/scan.ts +2 -2
  83. package/src/manifest/render.ts +20 -11
  84. package/src/owner/profile.ts +1 -3
  85. package/src/owner/shape.ts +1 -1
  86. package/src/owner/survey.ts +27 -18
  87. package/src/router.ts +4 -1
  88. package/src/rules/common/types.ts +1 -1
  89. package/src/signals/state.ts +1 -4
  90. package/src/sync/agent-removal.ts +7 -10
  91. package/src/sync/claude-launch.ts +36 -1
  92. package/src/sync/common/constants.ts +4 -0
  93. package/src/sync/common/index.ts +1 -0
  94. package/src/sync/common/symlink.ts +9 -0
  95. package/src/sync/common/types.ts +2 -2
  96. package/src/sync/planner.ts +10 -12
  97. package/src/sync/settings.ts +1 -1
  98. package/src/ui/keyboard.ts +3 -1
  99. package/src/ui/prompt.ts +4 -2
  100. package/src/visualize/assets.ts +370 -195
  101. package/src/visualize/charts.ts +11 -2
  102. package/src/visualize/compare-css.ts +30 -0
  103. package/src/visualize/compare-render.ts +194 -0
  104. package/src/visualize/compare-schema.ts +81 -0
  105. package/src/visualize/compare-validate.ts +126 -0
  106. package/src/visualize/constants.ts +29 -3
  107. package/src/visualize/diagrams.ts +1 -1
  108. package/src/visualize/gate.ts +136 -0
  109. package/src/visualize/icons.ts +5 -2
  110. package/src/visualize/index.ts +2 -0
  111. package/src/visualize/kinds-css.ts +54 -0
  112. package/src/visualize/kinds-render.ts +693 -0
  113. package/src/visualize/kinds-schema.ts +148 -0
  114. package/src/visualize/kinds-validate.ts +184 -0
  115. package/src/visualize/labels-vi.ts +109 -0
  116. package/src/visualize/labels.ts +49 -0
  117. package/src/visualize/layout.ts +10 -5
  118. package/src/visualize/page.ts +99 -61
  119. package/src/visualize/render.ts +48 -7
  120. package/src/visualize/schema.ts +21 -1
  121. package/src/visualize/sections.ts +115 -34
  122. package/src/visualize/sources.ts +270 -0
  123. package/src/visualize/theme.ts +472 -0
  124. package/src/visualize/validate.ts +6 -0
  125. package/src/wiki/anchors.ts +1 -1
  126. package/src/wiki/source-links.ts +3 -5
@@ -0,0 +1,148 @@
1
+ import { z } from 'zod';
2
+ import { NodeStates, VisualizeLimits } from './constants.ts';
3
+
4
+ /** How a message in a sequence is drawn: a call, the reply to it, or a call that does not wait. */
5
+ export class MessageKinds {
6
+ static readonly CALL = 'call';
7
+ static readonly REPLY = 'reply';
8
+ static readonly ASYNC = 'async';
9
+ static readonly SCHEME_SET = new Set<string>([this.CALL, this.REPLY, this.ASYNC]);
10
+
11
+ static isValid(value: string): boolean {
12
+ return this.SCHEME_SET.has(value);
13
+ }
14
+ }
15
+
16
+ /** What a state is in a lifecycle: where it begins, a state in between, or where it ends. */
17
+ export class LifecycleKinds {
18
+ static readonly START = 'start';
19
+ static readonly NORMAL = 'normal';
20
+ static readonly END = 'end';
21
+ static readonly SCHEME_SET = new Set<string>([this.START, this.NORMAL, this.END]);
22
+
23
+ static isValid(value: string): boolean {
24
+ return this.SCHEME_SET.has(value);
25
+ }
26
+ }
27
+
28
+ /** The limits of the three kinds; the shared ones come from `VisualizeLimits`. */
29
+ export class NewKindLimits {
30
+ static readonly MIN_PARTICIPANTS = 2;
31
+ static readonly MAX_PARTICIPANTS = 6;
32
+ static readonly MAX_MESSAGES = 20;
33
+ static readonly MIN_STATES = 2;
34
+ static readonly MAX_STATES = 10;
35
+ static readonly MAX_TRANSITIONS = 20;
36
+ /** Levels below the root. */
37
+ static readonly MAX_TREE_DEPTH = 4;
38
+ static readonly MAX_TREE_NODES = VisualizeLimits.MAX_NODES;
39
+ }
40
+
41
+ /** One line of plain text: no markup is interpreted anywhere, it is all escaped. */
42
+ const text = (max: number) =>
43
+ z
44
+ .string()
45
+ .max(max)
46
+ .regex(/^(?=.*\S)[^\p{Cc}‪-‮⁦-⁩]+$/u, 'one line of text, not blank');
47
+ /** A closed set as a pattern, so the printed JSON Schema says the same as the renderer. */
48
+ const choice = (opts: { set: Set<string> }) =>
49
+ z
50
+ .string()
51
+ .regex(new RegExp(`^(${[...opts.set].join('|')})$`), `one of: ${[...opts.set].join(', ')}`);
52
+ const ID = z
53
+ .string()
54
+ .regex(/^[a-z][a-z0-9-]{0,31}$/, 'lowercase letters, digits and -, at most 32');
55
+
56
+ /** Who talks to whom over time: lanes for the participants, one arrow per message, in order. */
57
+ export const SEQUENCE_SCHEMA = z.strictObject({
58
+ participants: z
59
+ .array(
60
+ z.strictObject({
61
+ id: ID,
62
+ label: text(VisualizeLimits.MAX_LABEL),
63
+ sublabel: text(VisualizeLimits.MAX_LABEL).optional(),
64
+ }),
65
+ )
66
+ .min(NewKindLimits.MIN_PARTICIPANTS)
67
+ .max(NewKindLimits.MAX_PARTICIPANTS),
68
+ messages: z
69
+ .array(
70
+ z.strictObject({
71
+ from: ID,
72
+ to: ID,
73
+ /** A verb phrase: what the sender does. */
74
+ label: text(VisualizeLimits.MAX_EDGE_LABEL),
75
+ kind: choice({ set: MessageKinds.SCHEME_SET }).optional(),
76
+ note: text(VisualizeLimits.MAX_LABEL).optional(),
77
+ }),
78
+ )
79
+ .min(1)
80
+ .max(NewKindLimits.MAX_MESSAGES),
81
+ /** The sentence under the figure; absent, the page counts the parts itself. */
82
+ caption: text(VisualizeLimits.MAX_SENTENCE).optional(),
83
+ });
84
+
85
+ /** States and what moves a thing from one to the next: one start, at least one end. */
86
+ export const LIFECYCLE_SCHEMA = z.strictObject({
87
+ states: z
88
+ .array(
89
+ z.strictObject({
90
+ id: ID,
91
+ label: text(VisualizeLimits.MAX_LABEL),
92
+ sublabel: text(VisualizeLimits.MAX_LABEL).optional(),
93
+ kind: choice({ set: LifecycleKinds.SCHEME_SET }).optional(),
94
+ }),
95
+ )
96
+ .min(NewKindLimits.MIN_STATES)
97
+ .max(NewKindLimits.MAX_STATES),
98
+ transitions: z
99
+ .array(
100
+ z.strictObject({
101
+ from: ID,
102
+ to: ID,
103
+ /** The trigger: what makes the state change. */
104
+ label: text(VisualizeLimits.MAX_EDGE_LABEL),
105
+ }),
106
+ )
107
+ .max(NewKindLimits.MAX_TRANSITIONS)
108
+ .default([]),
109
+ caption: text(VisualizeLimits.MAX_SENTENCE).optional(),
110
+ });
111
+
112
+ /** One node of the tree and what hangs under it. */
113
+ export interface ITreeNode {
114
+ id: string;
115
+ label: string;
116
+ sublabel?: string | undefined;
117
+ state?: string | undefined;
118
+ children?: ITreeNode[] | undefined;
119
+ }
120
+
121
+ const treeNode = (opts: { level: number }): z.ZodType<ITreeNode> =>
122
+ z.strictObject({
123
+ id: ID,
124
+ label: text(VisualizeLimits.MAX_LABEL),
125
+ sublabel: text(VisualizeLimits.MAX_LABEL).optional(),
126
+ state: choice({ set: NodeStates.SCHEME_SET }).optional(),
127
+ children:
128
+ opts.level >= NewKindLimits.MAX_TREE_DEPTH
129
+ ? z
130
+ .array(z.never())
131
+ .max(0, `the tree goes at most ${NewKindLimits.MAX_TREE_DEPTH} levels below the root`)
132
+ .optional()
133
+ : z
134
+ .array(treeNode({ level: opts.level + 1 }))
135
+ .min(1)
136
+ .max(NewKindLimits.MAX_TREE_NODES - 1)
137
+ .optional(),
138
+ });
139
+
140
+ /** A hierarchy: a root, children nested up to four levels, at most 25 nodes in all. */
141
+ export const TREE_SCHEMA = z.strictObject({
142
+ root: treeNode({ level: 0 }),
143
+ caption: text(VisualizeLimits.MAX_SENTENCE).optional(),
144
+ });
145
+
146
+ export type TSequence = z.output<typeof SEQUENCE_SCHEMA>;
147
+ export type TLifecycle = z.output<typeof LIFECYCLE_SCHEMA>;
148
+ export type TTree = z.output<typeof TREE_SCHEMA>;
@@ -0,0 +1,184 @@
1
+ import { LifecycleKinds, NewKindLimits } from './kinds-schema.ts';
2
+ import type { ITreeNode, TLifecycle, TSequence, TTree } from './kinds-schema.ts';
3
+
4
+ /** The part of a page spec the three kinds live in; the full spec fits it once the kinds are registered. */
5
+ export interface INewKindsSpec {
6
+ sequence?: TSequence | undefined;
7
+ lifecycle?: TLifecycle | undefined;
8
+ tree?: TTree | undefined;
9
+ }
10
+
11
+ const checkSequence = (opts: { sequence: TSequence }): string[] => {
12
+ const problems: string[] = [];
13
+ const ids = new Set<string>();
14
+
15
+ for (const participant of opts.sequence.participants) {
16
+ if (ids.has(participant.id)) {
17
+ problems.push(`sequence.participants: id '${participant.id}' is used twice`);
18
+ }
19
+
20
+ ids.add(participant.id);
21
+ }
22
+
23
+ for (const [index, message] of opts.sequence.messages.entries()) {
24
+ const name = `${message.from}>${message.to}`;
25
+
26
+ for (const end of [message.from, message.to]) {
27
+ if (!ids.has(end)) {
28
+ problems.push(
29
+ `sequence.messages[${index}]: '${name}' names '${end}', which is not a participant`,
30
+ );
31
+ }
32
+ }
33
+
34
+ if (message.from === message.to) {
35
+ problems.push(
36
+ `sequence.messages[${index}]: '${name}' goes from a participant to itself - send it to another participant`,
37
+ );
38
+ }
39
+ }
40
+
41
+ return problems;
42
+ };
43
+
44
+ /** The ids reachable from `start` along the transitions. */
45
+ const reachableFrom = (opts: { lifecycle: TLifecycle; start: string }): Set<string> => {
46
+ const seen = new Set<string>([opts.start]);
47
+ const queue = [opts.start];
48
+
49
+ while (queue.length > 0) {
50
+ const at = queue.shift();
51
+
52
+ for (const transition of opts.lifecycle.transitions) {
53
+ if (transition.from === at && !seen.has(transition.to)) {
54
+ seen.add(transition.to);
55
+ queue.push(transition.to);
56
+ }
57
+ }
58
+ }
59
+
60
+ return seen;
61
+ };
62
+
63
+ const checkLifecycle = (opts: { lifecycle: TLifecycle }): string[] => {
64
+ const { lifecycle } = opts;
65
+ const problems: string[] = [];
66
+ const ids = new Set<string>();
67
+
68
+ for (const state of lifecycle.states) {
69
+ if (ids.has(state.id)) {
70
+ problems.push(`lifecycle.states: id '${state.id}' is used twice`);
71
+ }
72
+
73
+ ids.add(state.id);
74
+ }
75
+
76
+ const starts = lifecycle.states.filter((state) => state.kind === LifecycleKinds.START);
77
+ const ends = lifecycle.states.filter((state) => state.kind === LifecycleKinds.END);
78
+
79
+ if (starts.length !== 1) {
80
+ problems.push(
81
+ starts.length === 0
82
+ ? "lifecycle.states: there is no state of kind 'start' - exactly one is needed"
83
+ : `lifecycle.states: ${starts.length} states are of kind 'start' (${starts.map((state) => `'${state.id}'`).join(', ')}) - exactly one is needed`,
84
+ );
85
+ }
86
+
87
+ if (ends.length === 0) {
88
+ problems.push("lifecycle.states: there is no state of kind 'end' - at least one is needed");
89
+ }
90
+
91
+ const names = new Set<string>();
92
+
93
+ for (const transition of lifecycle.transitions) {
94
+ const name = `${transition.from}>${transition.to}`;
95
+
96
+ for (const end of [transition.from, transition.to]) {
97
+ if (!ids.has(end)) {
98
+ problems.push(`lifecycle.transitions: '${name}' names '${end}', which is not a state`);
99
+ }
100
+ }
101
+
102
+ if (transition.from === transition.to) {
103
+ problems.push(`lifecycle.transitions: '${name}' loops to itself - name the state it goes to`);
104
+ }
105
+
106
+ if (names.has(name)) {
107
+ problems.push(
108
+ `lifecycle.transitions: '${name}' is listed twice - put both triggers in one label`,
109
+ );
110
+ }
111
+
112
+ names.add(name);
113
+
114
+ if (ends.some((state) => state.id === transition.from)) {
115
+ problems.push(
116
+ `lifecycle.transitions: '${name}' leaves the end state '${transition.from}' - an end has nothing after it`,
117
+ );
118
+ }
119
+ }
120
+
121
+ const [start] = starts;
122
+
123
+ if (starts.length === 1 && start !== undefined) {
124
+ const reached = reachableFrom({ lifecycle, start: start.id });
125
+
126
+ for (const state of lifecycle.states) {
127
+ if (!reached.has(state.id)) {
128
+ problems.push(
129
+ `lifecycle.states: '${state.id}' cannot be reached from the start '${start.id}'`,
130
+ );
131
+ }
132
+ }
133
+ }
134
+
135
+ return problems;
136
+ };
137
+
138
+ const checkTree = (opts: { tree: TTree }): string[] => {
139
+ const problems: string[] = [];
140
+ const ids = new Set<string>();
141
+ let count = 0;
142
+ let deepest = 0;
143
+ const walk = (node: ITreeNode, depth: number): void => {
144
+ count += 1;
145
+ deepest = Math.max(deepest, depth);
146
+
147
+ if (ids.has(node.id)) {
148
+ problems.push(`tree: id '${node.id}' is used twice`);
149
+ }
150
+
151
+ ids.add(node.id);
152
+
153
+ for (const child of node.children ?? []) {
154
+ walk(child, depth + 1);
155
+ }
156
+ };
157
+
158
+ walk(opts.tree.root, 0);
159
+
160
+ if (count > NewKindLimits.MAX_TREE_NODES) {
161
+ problems.push(
162
+ `tree: ${count} nodes, at most ${NewKindLimits.MAX_TREE_NODES} - split it into two trees`,
163
+ );
164
+ }
165
+
166
+ if (deepest > NewKindLimits.MAX_TREE_DEPTH) {
167
+ problems.push(
168
+ `tree: ${deepest} levels below the root, at most ${NewKindLimits.MAX_TREE_DEPTH}`,
169
+ );
170
+ }
171
+
172
+ return problems;
173
+ };
174
+
175
+ /** What a schema cannot say about the sequence, the lifecycle and the tree: ids, ends of arrows, reach, limits. */
176
+ export const checkNewKinds = (opts: { spec: INewKindsSpec }): string[] => {
177
+ const { sequence, lifecycle, tree } = opts.spec;
178
+
179
+ return [
180
+ ...(sequence === undefined ? [] : checkSequence({ sequence })),
181
+ ...(lifecycle === undefined ? [] : checkLifecycle({ lifecycle })),
182
+ ...(tree === undefined ? [] : checkTree({ tree })),
183
+ ];
184
+ };
@@ -0,0 +1,109 @@
1
+ import type { TChrome } from './constants.ts';
2
+
3
+ /**
4
+ * The page's own words in Vietnamese: every key of the English set. They address the reader
5
+ * neutrally (no anh, no em): the owner pages the agent writes carry the personal register.
6
+ */
7
+ export const VI_CHROME: TChrome = {
8
+ asOf: 'Cập nhật',
9
+ scope: 'Phạm vi',
10
+ status: 'Trạng thái',
11
+ statusStates: {
12
+ ok: 'Đúng tiến độ',
13
+ warn: 'Cần chú ý',
14
+ blocked: 'Đang bị chặn',
15
+ info: 'Để biết',
16
+ },
17
+ healthy: 'Ổn không?',
18
+ blockedBy: 'Bị chặn bởi',
19
+ changed: 'Đã đổi gì',
20
+ next: 'Việc cần làm',
21
+ minimap: 'Tình hình hiện tại',
22
+ task: 'Việc',
23
+ minimapStates: {
24
+ done: 'xong',
25
+ 'in-progress': 'đang làm',
26
+ waiting: 'đang chờ',
27
+ 'not-started': 'chưa làm',
28
+ blocked: 'bị chặn',
29
+ dropped: 'bỏ',
30
+ info: 'để biết',
31
+ },
32
+ actions: 'Làm lần lượt',
33
+ footer: 'Trang tĩnh do vulcan visualize tạo; không tải gì từ mạng.',
34
+ flow: 'Luồng đi',
35
+ legend: 'Chú giải',
36
+ play: 'Chạy',
37
+ pause: 'Dừng',
38
+ previous: 'Trước',
39
+ following: 'Tiếp',
40
+ step: 'Bước',
41
+ allSteps: 'Tất cả bước',
42
+ detail: 'Chi tiết',
43
+ detailHint: 'Rê chuột hoặc chọn một ô để xem chi tiết.',
44
+ before: 'Trước đó',
45
+ after: 'Sau đó',
46
+ added: 'thêm',
47
+ removed: 'bỏ',
48
+ decisions: 'Cần quyết định',
49
+ recommended: 'Đề xuất',
50
+ changesClaim: 'Thay đổi',
51
+ evidence: 'Bằng chứng',
52
+ claim: 'Nhận định',
53
+ probe: 'Cách kiểm',
54
+ result: 'Kết quả',
55
+ label: 'Căn cứ',
56
+ evidenceLabels: { verified: 'đã kiểm', inferred: 'suy ra', guess: 'đoán' },
57
+ risks: 'Rủi ro',
58
+ risk: 'Rủi ro',
59
+ impact: 'Ảnh hưởng',
60
+ fallback: 'Đường lui',
61
+ log: 'Nhật ký',
62
+ links: 'Liên kết',
63
+ theme: 'Giao diện',
64
+ present: 'Trình chiếu',
65
+ exitPresent: 'Thoát',
66
+ slide: 'Trang chiếu',
67
+ slideOf: 'trên',
68
+ comparison: 'So sánh',
69
+ total: 'Tổng điểm',
70
+ outOf: 'trên',
71
+ pros: 'Ưu điểm',
72
+ cons: 'Nhược điểm',
73
+ ideaMap: 'Sơ đồ ý tưởng',
74
+ explainer: 'Cách hoạt động',
75
+ architecture: 'Kiến trúc',
76
+ timeline: 'Dòng thời gian',
77
+ findings: 'Điều tìm được',
78
+ decisionRecord: 'Biên bản quyết định',
79
+ context: 'Bối cảnh',
80
+ optionsConsidered: 'Các cách đã cân nhắc',
81
+ decision: 'Quyết định',
82
+ chosen: 'Đã chọn',
83
+ consequences: 'Hệ quả',
84
+ tableView: 'Dạng bảng',
85
+ value: 'Giá trị',
86
+ uses: 'dùng',
87
+ themeToLight: 'Chuyển sang giao diện sáng',
88
+ themeToDark: 'Chuyển sang giao diện tối',
89
+ navLabel: 'Trên trang này',
90
+ sequence: 'Trình tự',
91
+ lifecycle: 'Vòng đời',
92
+ tree: 'Cấu trúc',
93
+ compareView: 'Điểm khác nhau',
94
+ inBoth: 'ở cả hai',
95
+ sources: 'Nguồn',
96
+ terms: 'Các từ trong trang',
97
+ onlyHere: 'chỉ ở đây',
98
+ addedEdge: 'thêm',
99
+ removedEdge: 'bỏ',
100
+ kindCall: 'gọi',
101
+ kindReply: 'trả lời',
102
+ kindAsync: 'không chờ',
103
+ stateStart: 'bắt đầu',
104
+ stateEnd: 'kết thúc',
105
+ countMessages: 'thông điệp',
106
+ countStates: 'trạng thái',
107
+ countTransitions: 'lần chuyển',
108
+ countItems: 'mục',
109
+ };
@@ -0,0 +1,49 @@
1
+ import { DEFAULT_CHROME } from './constants.ts';
2
+ import type { TChrome } from './constants.ts';
3
+ import { VI_CHROME } from './labels-vi.ts';
4
+ import type { TVisualizeSpec } from './schema.ts';
5
+
6
+ /** The word sets that ship with the page, by the primary subtag of the language; English is the default. */
7
+ export const BUNDLED_LANGUAGES: Readonly<Record<string, TChrome>> = {
8
+ en: DEFAULT_CHROME,
9
+ vi: VI_CHROME,
10
+ };
11
+
12
+ const definedOnly = (opts: {
13
+ value: Record<string, string | undefined> | undefined;
14
+ }): Record<string, string> =>
15
+ Object.fromEntries(
16
+ Object.entries(opts.value ?? {}).filter(
17
+ (entry): entry is [string, string] => entry[1] !== undefined,
18
+ ),
19
+ );
20
+
21
+ /** The bundled words of a language: `vi`, `vi-VN` and `VI` are Vietnamese; no bundled set is English. */
22
+ const bundledOf = (opts: { language?: string }): TChrome => {
23
+ const primary = (opts.language ?? 'en').trim().split(/[-_]/)[0]?.toLowerCase() ?? 'en';
24
+
25
+ return Object.hasOwn(BUNDLED_LANGUAGES, primary)
26
+ ? (BUNDLED_LANGUAGES[primary] ?? DEFAULT_CHROME)
27
+ : DEFAULT_CHROME;
28
+ };
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 };
35
+
36
+ for (const [key, value] of Object.entries(given)) {
37
+ if (typeof value === 'string') {
38
+ merged[key] = value;
39
+ }
40
+ }
41
+
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
+ };
@@ -102,8 +102,11 @@ export const renderFigure = (opts: { flow: NonNullable<TVisualizeSpec['flow']> }
102
102
 
103
103
  const route = routeOf({ from: centreOf(from), to: centreOf(to) });
104
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';
105
108
 
106
- return `<g class="edge ${escaped(edge.variant ?? 'main')}" data-edge="${escaped(name)}"><title>${escaped(edge.label)}</title><path d="${route.path}" marker-end="url(#${edge.variant === 'error' ? 'e' : 'a'})"/><text x="${route.label.x}" y="${route.label.y}" text-anchor="middle">${escaped(edge.label)}</text></g>`;
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>`;
107
110
  })
108
111
  .join('');
109
112
  const nodes = flow.nodes
@@ -111,19 +114,21 @@ export const renderFigure = (opts: { flow: NonNullable<TVisualizeSpec['flow']> }
111
114
  const centre = centreOf(node);
112
115
  const lines = node.sublabel === undefined ? 1 : 2;
113
116
  const tone = node.state === undefined ? '' : ` c-${NodeStates.toneOf(node.state)}`;
117
+ const gate = node.state === 'waiting';
114
118
  const left = centre.x - BOX_WIDTH / 2;
115
119
  const anchor = node.state === undefined ? 'middle' : 'start';
116
- const textX = node.state === undefined ? centre.x : left + 40;
120
+ const textX =
121
+ node.state === undefined ? centre.x : left + (node.state === 'waiting' ? 48 : 40);
117
122
  const mark =
118
123
  node.state === undefined
119
124
  ? ''
120
- : `<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>`;
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>`;
121
126
 
122
- return `<g class="node ${escaped(node.kind ?? 'step')}${tone}" 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>`;
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>`;
123
128
  })
124
129
  .join('');
125
130
 
126
- 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="7" markerHeight="7" orient="auto"><path d="M0 0L10 5L0 10z" fill="currentColor"/></marker><marker id="e" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto"><path class="bad" d="M0 0L10 5L0 10z"/></marker></defs>${edges}${nodes}</svg>`;
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>`;
127
132
  };
128
133
 
129
134
  /**