@venizia/vulcan 0.4.10-2 → 0.4.10-21
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 +30 -23
- package/base/checks/wiki-source-links.ts +17 -1
- package/base/claude/events.json +1 -11
- package/base/claude/settings.json +5 -76
- package/base/extensions/vulcan-guards.ts +81 -18
- package/base/hooks/guard-git.ts +95 -19
- package/base/hooks/guard-outside.ts +163 -43
- package/base/hooks/guard-writes.ts +15 -36
- package/base/hooks/session-start.ts +1 -1
- package/base/make/vulcan.mk +8 -5
- package/base/packs/venizia.md +16 -0
- package/base/references/delegation-brief.md +3 -5
- package/base/references/testing.md +1 -9
- package/base/rules.md +33 -38
- package/base/skills/build-a-feature/SKILL.md +4 -4
- package/base/skills/docs-update/SKILL.md +19 -8
- package/base/skills/fix-a-bug/SKILL.md +4 -2
- package/base/skills/plan-a-change/SKILL.md +1 -1
- package/base/skills/research/SKILL.md +1 -1
- package/base/skills/retro/SKILL.md +2 -2
- package/base/skills/review-a-change/SKILL.md +1 -1
- package/base/skills/visualize-work/SKILL.md +3 -3
- package/base/skills/visualize-work/references/spec.md +6 -3
- package/base/templates/AGENTS.md +9 -7
- package/base/templates/board.html +10 -110
- package/package.json +3 -3
- package/src/agents/atlas-block.ts +8 -31
- package/src/agents/codex-hooks.ts +1 -1
- package/src/agents/generated-block.ts +52 -0
- package/src/agents/hooks-json.ts +22 -3
- package/src/agents/index.ts +2 -0
- package/src/agents/render.ts +15 -2
- package/src/agents/resolve.ts +1 -0
- package/src/agents/rules-block.ts +92 -0
- package/src/board/command.ts +92 -30
- package/src/board/common/constants.ts +26 -0
- package/src/board/common/types.ts +10 -3
- package/src/board/fold.ts +1 -1
- package/src/board/github.ts +1 -2
- package/src/board/gitlab.ts +436 -0
- package/src/board/index.ts +1 -0
- package/src/board/logo.ts +49 -0
- package/src/board/open-file.ts +110 -0
- package/src/board/page.ts +57 -5
- package/src/board/schema.ts +4 -1
- package/src/board/server.ts +87 -3
- package/src/board/settings.ts +21 -24
- package/src/commands/changelog.command.ts +40 -0
- package/src/commands/clean.command.ts +6 -1
- package/src/commands/help.command.ts +2 -63
- package/src/commands/index.ts +6 -1
- package/src/commands/migrate.command.ts +71 -0
- package/src/commands/profile.command.ts +1 -1
- package/src/commands/runners.command.ts +43 -0
- package/src/commands/sync.command.ts +8 -4
- package/src/commands/table.ts +362 -0
- package/src/commit/check.ts +1 -0
- package/src/commit/common/constants.ts +4 -0
- package/src/commit/hook.ts +112 -8
- package/src/common/constants.ts +11 -9
- package/src/common/env-variables.ts +41 -0
- package/src/common/index.ts +1 -0
- package/src/common/layout-folder.ts +3 -4
- package/src/common/record.ts +5 -0
- package/src/config/common/constants.ts +28 -22
- package/src/config/loader.ts +22 -0
- package/src/config/schema.ts +330 -146
- package/src/create/add-app.ts +7 -2
- package/src/create/add-lib.ts +2 -4
- package/src/create/common/constants.ts +5 -3
- package/src/create/preset.ts +1 -0
- package/src/create/scratch.ts +2 -1
- package/src/doctor/checks.ts +277 -448
- package/src/doctor/common/constants.ts +27 -19
- package/src/doctor/private-values.ts +4 -1
- package/src/doctor/runner.ts +5 -12
- package/src/doctor/schema.ts +4 -0
- package/src/events/common/actor-names.ts +12 -0
- package/src/events/common/constants.ts +65 -38
- package/src/events/common/index.ts +1 -0
- package/src/events/hook.ts +5 -56
- package/src/events/text.ts +41 -6
- package/src/hooks/command-view.ts +80 -19
- package/src/hooks/common/constants.ts +26 -17
- package/src/hooks/common/types.ts +13 -24
- package/src/hooks/decision.ts +30 -12
- package/src/hooks/git-queries.ts +113 -0
- package/src/hooks/guard-git.ts +76 -24
- package/src/hooks/guard-outside.ts +334 -311
- package/src/hooks/guard-runner.ts +206 -0
- package/src/hooks/guard-writes.ts +87 -184
- package/src/hooks/hook-input.ts +57 -0
- package/src/hooks/index.ts +3 -6
- package/src/hooks/link-makers.ts +315 -0
- package/src/hooks/package-runners.ts +268 -0
- package/src/hooks/project-guards.ts +81 -44
- package/src/hooks/project-tmp.ts +39 -4
- package/src/hooks/runner-scan.ts +257 -0
- package/src/hooks/script-runners.ts +400 -0
- package/src/hooks/session-digest.ts +27 -117
- package/src/hooks/shell-folders.ts +760 -0
- package/src/hooks/shell-writes.ts +646 -0
- package/src/hooks/shell.ts +1421 -194
- package/src/hooks/subagent-card.ts +2 -2
- package/src/hooks/write-commands.ts +898 -0
- package/src/init/scaffold.ts +2 -3
- package/src/local/auto-clean.ts +2 -1
- package/src/local/browser-socket.ts +33 -0
- package/src/local/clean.ts +37 -6
- package/src/local/constants.ts +15 -1
- package/src/local/index.ts +1 -0
- package/src/local/scan.ts +41 -10
- package/src/manifest/render.ts +84 -30
- package/src/owner/constants.ts +4 -5
- package/src/owner/index.ts +0 -2
- package/src/owner/profile.ts +1 -0
- package/src/owner/schema.ts +51 -27
- package/src/owner/survey.ts +0 -3
- package/src/owner/view.ts +0 -9
- package/src/router.ts +8 -132
- package/src/rules/base.ts +12 -7
- package/src/rules/index.ts +1 -0
- package/src/rules/packs.ts +44 -0
- package/src/runners/check.ts +130 -0
- package/src/skills/frontmatter.ts +1 -0
- package/src/sync/agents-block.ts +104 -0
- package/src/sync/base-rules.ts +3 -3
- package/src/sync/claude-launch.ts +12 -12
- package/src/sync/common/constants.ts +0 -2
- package/src/sync/index.ts +1 -1
- package/src/sync/local-choice.ts +32 -3
- package/src/sync/planner.ts +2 -15
- package/src/sync/settings.ts +0 -17
- package/src/theme/index.ts +1 -0
- package/src/theme/tokens.ts +410 -0
- package/src/ui/prompt.ts +1 -0
- package/src/visualize/architecture.ts +504 -0
- package/src/visualize/assets.ts +41 -30
- package/src/visualize/compare-render.ts +22 -24
- package/src/visualize/constants.ts +27 -0
- package/src/visualize/diagrams.ts +13 -121
- package/src/visualize/kinds-render.ts +2 -2
- package/src/visualize/kinds-schema.ts +49 -0
- package/src/visualize/labels-vi.ts +25 -0
- package/src/visualize/labels.ts +2 -0
- package/src/visualize/layout.ts +415 -66
- package/src/visualize/page.ts +82 -15
- package/src/visualize/render.ts +2 -1
- package/src/visualize/schema.ts +29 -1
- package/src/visualize/sections.ts +78 -9
- package/src/visualize/theme.ts +49 -18
- package/src/wiki/anchors.ts +1 -0
- package/src/wiki/command.ts +10 -3
- package/src/wiki/source-links.ts +57 -18
- package/base/ci-global.json +0 -13
- package/base/claude/remote-hosts.json +0 -15
- package/base/hooks/guard-manifest.ts +0 -27
- package/base/hooks/guard-package.ts +0 -30
- package/base/hooks/guard-remote-hosts.ts +0 -70
- package/base/hooks/guard-scripting.ts +0 -32
- package/base/hooks/post-tool.ts +0 -37
- package/base/hooks/prompt-submit.ts +0 -54
- package/base/hooks/stop.ts +0 -40
- package/base/skills/build-a-feature/evals/evals.json +0 -29
- package/base/skills/docs-update/evals/evals.json +0 -23
- package/base/skills/docs-writing/evals/evals.json +0 -17
- package/base/skills/fix-a-bug/evals/evals.json +0 -17
- package/base/skills/knowledge-sync/SKILL.md +0 -81
- package/base/skills/knowledge-sync/knowledge-sync.workflow.js +0 -291
- package/base/skills/knowledge-sync/references/workflow.md +0 -44
- package/base/skills/plan-a-change/evals/evals.json +0 -47
- package/base/skills/report-back/evals/evals.json +0 -23
- package/base/skills/research/evals/evals.json +0 -17
- package/base/skills/retro/evals/evals.json +0 -17
- package/base/skills/review-a-change/evals/evals.json +0 -17
- package/base/skills/ship/evals/evals.json +0 -23
- package/base/skills/visualize-work/evals/evals.json +0 -17
- package/base/templates/ci/github-actions.yml +0 -75
- package/base/templates/ci/gitlab-ci.yml +0 -52
- package/base/templates/trusted-hosts.local.example +0 -11
- package/src/ci/affected.ts +0 -176
- package/src/ci/command.ts +0 -166
- package/src/ci/common/constants.ts +0 -76
- package/src/ci/common/index.ts +0 -2
- package/src/ci/common/types.ts +0 -37
- package/src/ci/git.ts +0 -72
- package/src/ci/global.ts +0 -48
- package/src/ci/graph.ts +0 -43
- package/src/ci/index.ts +0 -7
- package/src/ci/workspace.ts +0 -119
- package/src/commands/ci.command.ts +0 -4
- package/src/hooks/guard-manifest.ts +0 -109
- package/src/hooks/guard-package.ts +0 -226
- package/src/hooks/guard-scripting.ts +0 -36
- package/src/hooks/host-pattern.ts +0 -17
- package/src/hooks/owner-reply.ts +0 -162
- package/src/hooks/post-tool.ts +0 -138
- package/src/hooks/remote-hosts.ts +0 -1013
- package/src/hooks/trusted-scripts.ts +0 -212
- package/src/owner/shape.ts +0 -496
- package/src/owner/violations.ts +0 -332
- package/src/signals/claims.ts +0 -73
- package/src/signals/classify.ts +0 -137
- package/src/signals/constants.ts +0 -88
- package/src/signals/index.ts +0 -5
- package/src/signals/loop.ts +0 -48
- package/src/signals/state.ts +0 -271
- package/src/sync/atlas-block.ts +0 -56
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
import { ProjectTheme, Theme } from '../visualize/theme.ts';
|
|
2
|
+
import type { IThemeInput } from '../visualize/theme.ts';
|
|
3
|
+
|
|
4
|
+
/** One mode of the token set: token name to colour (`#rrggbb`, or `#rrggbbaa` for a line or a muted text). */
|
|
5
|
+
export type TTokenMode = Record<string, string>;
|
|
6
|
+
|
|
7
|
+
/** What the project writes under `theme`: a preset, an accent, per-token overrides and the type and corner settings. */
|
|
8
|
+
export interface IThemeConfig extends Partial<IThemeInput> {
|
|
9
|
+
preset?: string;
|
|
10
|
+
/** A colour for both modes, or one per mode. */
|
|
11
|
+
tokens?: Record<string, string | { light?: string; dark?: string }>;
|
|
12
|
+
font?: string;
|
|
13
|
+
mono?: string;
|
|
14
|
+
radius?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** The resolved set every consumer reads: both modes and the three settings, with the preset it started from. */
|
|
18
|
+
export interface IThemeTokens {
|
|
19
|
+
preset: string;
|
|
20
|
+
light: TTokenMode;
|
|
21
|
+
dark: TTokenMode;
|
|
22
|
+
font: string;
|
|
23
|
+
mono: string;
|
|
24
|
+
radius: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type TTokensResult = { ok: true; tokens: IThemeTokens } | { ok: false; problems: string[] };
|
|
28
|
+
|
|
29
|
+
interface IPreset {
|
|
30
|
+
/** The accent the preset is known by; a project that gives the same seed gets the preset as written. */
|
|
31
|
+
seed: IThemeInput;
|
|
32
|
+
light: TTokenMode;
|
|
33
|
+
dark: TTokenMode;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The neutral part shared by the presets: grounds, text, lines and the states. Board and wiki agree on these values. */
|
|
37
|
+
const NEUTRAL_LIGHT: TTokenMode = {
|
|
38
|
+
ground: '#f6f6f7',
|
|
39
|
+
bg: '#ffffff',
|
|
40
|
+
line: '#e2e2e3',
|
|
41
|
+
'line-strong': '#101010',
|
|
42
|
+
ink: '#000000',
|
|
43
|
+
body: '#4b4b4b',
|
|
44
|
+
muted: '#6b6b6b',
|
|
45
|
+
ok: '#067647',
|
|
46
|
+
'ok-soft': '#e7f5ee',
|
|
47
|
+
wait: '#8a4b00',
|
|
48
|
+
'wait-soft': '#fdf1dc',
|
|
49
|
+
fail: '#b42318',
|
|
50
|
+
'fail-soft': '#fdecea',
|
|
51
|
+
info: '#175cd3',
|
|
52
|
+
'info-soft': '#eff8ff',
|
|
53
|
+
};
|
|
54
|
+
const NEUTRAL_DARK: TTokenMode = {
|
|
55
|
+
ground: '#1b1b1f',
|
|
56
|
+
bg: '#202127',
|
|
57
|
+
line: '#2e2e32',
|
|
58
|
+
'line-strong': '#ffffff4d',
|
|
59
|
+
ink: '#ffffff',
|
|
60
|
+
body: '#ffffffb3',
|
|
61
|
+
muted: '#ffffff8c',
|
|
62
|
+
ok: '#47cd89',
|
|
63
|
+
'ok-soft': '#14291f',
|
|
64
|
+
wait: '#fdb022',
|
|
65
|
+
'wait-soft': '#33270f',
|
|
66
|
+
fail: '#f97066',
|
|
67
|
+
'fail-soft': '#3a1d1a',
|
|
68
|
+
info: '#84caff',
|
|
69
|
+
'info-soft': '#102a43',
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/** The text pairs checked at 4.5:1 and the marks at 3:1, per mode; `on` names the token the first sits on. */
|
|
73
|
+
const TEXT_PAIRS: [string, string][] = [
|
|
74
|
+
['ink', 'bg'],
|
|
75
|
+
['body', 'bg'],
|
|
76
|
+
['muted', 'bg'],
|
|
77
|
+
['ink', 'ground'],
|
|
78
|
+
['body', 'ground'],
|
|
79
|
+
['muted', 'ground'],
|
|
80
|
+
['accent-text', 'bg'],
|
|
81
|
+
['accent-text', 'ground'],
|
|
82
|
+
['accent-text', 'accent-soft'],
|
|
83
|
+
['ink', 'accent-soft'],
|
|
84
|
+
['body', 'accent-soft'],
|
|
85
|
+
['muted', 'accent-soft'],
|
|
86
|
+
['accent-ink', 'accent'],
|
|
87
|
+
['ok', 'ok-soft'],
|
|
88
|
+
['wait', 'wait-soft'],
|
|
89
|
+
['fail', 'fail-soft'],
|
|
90
|
+
['info', 'info-soft'],
|
|
91
|
+
];
|
|
92
|
+
const MARK_PAIRS: [string, string][] = [
|
|
93
|
+
['accent', 'bg'],
|
|
94
|
+
['accent', 'ground'],
|
|
95
|
+
['ok', 'bg'],
|
|
96
|
+
['wait', 'bg'],
|
|
97
|
+
['fail', 'bg'],
|
|
98
|
+
['info', 'bg'],
|
|
99
|
+
];
|
|
100
|
+
const TEXT_RATIO = 4.5;
|
|
101
|
+
const MARK_RATIO = 3;
|
|
102
|
+
/** The text tokens a surface of the board carries; each is checked on each surface of the mode. */
|
|
103
|
+
const SURFACE_TEXT = ['ink', 'body', 'muted', 'accent-text'];
|
|
104
|
+
const SURFACE_NAMES = ['head', 'soft', 'sunk'];
|
|
105
|
+
const SURFACE_PAIRS: [string, string][] = SURFACE_TEXT.flatMap((text) =>
|
|
106
|
+
SURFACE_NAMES.map((surface): [string, string] => [text, surface]),
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
/** The design tokens: fixed semantic names, values from a preset and the project, checked against WCAG AA. */
|
|
110
|
+
export class ThemeTokens {
|
|
111
|
+
static readonly DEFAULT_PRESET = 'venizia';
|
|
112
|
+
|
|
113
|
+
/** A colour of a token: six hex digits, or eight with an alpha channel (a line, a soft text). */
|
|
114
|
+
static readonly COLOUR = /^#[0-9a-fA-F]{6}(?:[0-9a-fA-F]{2})?$/;
|
|
115
|
+
|
|
116
|
+
static readonly PRESETS: Record<string, IPreset> = {
|
|
117
|
+
venizia: {
|
|
118
|
+
seed: ProjectTheme.DEFAULT,
|
|
119
|
+
light: {
|
|
120
|
+
...NEUTRAL_LIGHT,
|
|
121
|
+
accent: '#8a5a20',
|
|
122
|
+
'accent-ink': '#ffffff',
|
|
123
|
+
'accent-soft': '#f5ecdf',
|
|
124
|
+
'accent-text': '#8a5a20',
|
|
125
|
+
},
|
|
126
|
+
dark: {
|
|
127
|
+
...NEUTRAL_DARK,
|
|
128
|
+
accent: '#dead6a',
|
|
129
|
+
'accent-ink': '#1a1200',
|
|
130
|
+
'accent-soft': '#33281a',
|
|
131
|
+
'accent-text': '#dead6a',
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
slate: {
|
|
135
|
+
seed: { accent: '#3f5266', accentDark: '#9fb4cc' },
|
|
136
|
+
// The tint the derivation gives this accent (#e8eaed) leaves muted at 4.42:1 on it; this one is 4.63:1.
|
|
137
|
+
light: { ...NEUTRAL_LIGHT, 'accent-soft': '#edeff2' },
|
|
138
|
+
dark: NEUTRAL_DARK,
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
static readonly FONT = "'Inter Display', system-ui, -apple-system, 'Segoe UI', sans-serif";
|
|
143
|
+
static readonly MONO =
|
|
144
|
+
"'JetBrains Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace";
|
|
145
|
+
static readonly RADIUS = '4px';
|
|
146
|
+
/** A corner radius: a bare `0` or a length, so nothing else (a brace, a tag) can reach a style element. */
|
|
147
|
+
static readonly RADIUS_PATTERN = /^(?:0|\d+(?:\.\d+)?(?:px|rem|em))$/;
|
|
148
|
+
|
|
149
|
+
/** The greys of the board's own panes, the same in every project; the text tokens are checked on them. */
|
|
150
|
+
static readonly SURFACES: Record<'light' | 'dark', Record<string, string>> = {
|
|
151
|
+
light: { head: '#fafafa', soft: '#f2f2f2', sunk: '#f7f7f7' },
|
|
152
|
+
dark: { head: '#202024', soft: '#26262b', sunk: '#232327' },
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
/** The `--property:value` pairs of one mode; `names` maps a token to the custom property a consumer calls it. */
|
|
156
|
+
static declarations(opts: { mode: TTokenMode; names: Record<string, string> }): string {
|
|
157
|
+
return Object.entries(opts.names)
|
|
158
|
+
.map(([token, property]) => `--${property}:${opts.mode[token]}`)
|
|
159
|
+
.join(';');
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* The resolved tokens that `vulcan sync` wrote to the manifest of `root`, or the default preset when the manifest has
|
|
164
|
+
* none or holds a block this version cannot read (then with a warning to print). Nothing is requested and no config
|
|
165
|
+
* is loaded.
|
|
166
|
+
*/
|
|
167
|
+
static read(opts: { root: string }): { tokens: IThemeTokens; warning?: string } {
|
|
168
|
+
const { block, warning } = ProjectTheme.readManifestBlock({ root: opts.root });
|
|
169
|
+
const stored = block === undefined ? undefined : ThemeTokens.storedIn({ block });
|
|
170
|
+
|
|
171
|
+
if (block !== undefined && stored === undefined) {
|
|
172
|
+
return {
|
|
173
|
+
tokens: ThemeTokens.defaults(),
|
|
174
|
+
warning:
|
|
175
|
+
'the manifest theme is not readable by this version, so the default preset is used',
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return {
|
|
180
|
+
tokens: stored ?? ThemeTokens.defaults(),
|
|
181
|
+
...(warning === undefined ? {} : { warning }),
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** The tokens of a project with no `theme`: the default preset as written. */
|
|
186
|
+
static defaults(): IThemeTokens {
|
|
187
|
+
const resolved = ThemeTokens.resolve({});
|
|
188
|
+
|
|
189
|
+
if (!resolved.ok) {
|
|
190
|
+
throw new Error('the default theme preset fails its own contrast check');
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return resolved.tokens;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** The tokens of a manifest `theme` block when every token of both modes and the three settings are there. */
|
|
197
|
+
private static storedIn(opts: { block: object }): IThemeTokens | undefined {
|
|
198
|
+
const tokens: unknown = Reflect.get(opts.block, 'tokens');
|
|
199
|
+
const modes = ['light', 'dark'].map((mode): TTokenMode | undefined => {
|
|
200
|
+
const value: unknown =
|
|
201
|
+
typeof tokens === 'object' && tokens !== null ? Reflect.get(tokens, mode) : undefined;
|
|
202
|
+
|
|
203
|
+
return typeof value === 'object' &&
|
|
204
|
+
value !== null &&
|
|
205
|
+
ThemeTokens.names().every((name) => {
|
|
206
|
+
const color: unknown = Reflect.get(value, name);
|
|
207
|
+
|
|
208
|
+
return typeof color === 'string' && ThemeTokens.COLOUR.test(color);
|
|
209
|
+
})
|
|
210
|
+
? Object.fromEntries(Object.entries(value))
|
|
211
|
+
: undefined;
|
|
212
|
+
});
|
|
213
|
+
const [light, dark] = modes;
|
|
214
|
+
const [font, mono, radius, preset]: unknown[] = ['font', 'mono', 'radius', 'preset'].map(
|
|
215
|
+
(key) => Reflect.get(opts.block, key),
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
return light !== undefined &&
|
|
219
|
+
dark !== undefined &&
|
|
220
|
+
typeof font === 'string' &&
|
|
221
|
+
typeof mono === 'string' &&
|
|
222
|
+
typeof radius === 'string' &&
|
|
223
|
+
ThemeTokens.RADIUS_PATTERN.test(radius) &&
|
|
224
|
+
typeof preset === 'string'
|
|
225
|
+
? { preset, light, dark, font, mono, radius }
|
|
226
|
+
: undefined;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** The names a project may override: the keys of a preset. */
|
|
230
|
+
static names(): string[] {
|
|
231
|
+
return Object.keys(ThemeTokens.PRESETS.venizia.light);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** A colour with an alpha channel laid over `ground`, as the six-digit colour the eye sees. */
|
|
235
|
+
private static opaque(opts: { color: string; ground: string }): string {
|
|
236
|
+
if (opts.color.length !== 9) {
|
|
237
|
+
return opts.color;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const alpha = Number.parseInt(opts.color.slice(7), 16) / 255;
|
|
241
|
+
const channel = (from: number): number =>
|
|
242
|
+
Math.round(
|
|
243
|
+
Number.parseInt(opts.color.slice(from, from + 2), 16) * alpha +
|
|
244
|
+
Number.parseInt(opts.ground.slice(from, from + 2), 16) * (1 - alpha),
|
|
245
|
+
);
|
|
246
|
+
|
|
247
|
+
return `#${[1, 3, 5].map((from) => channel(from).toString(16).padStart(2, '0')).join('')}`;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
private static ratio(opts: { mode: TTokenMode; text: string; on: string }): number {
|
|
251
|
+
const ground = ThemeTokens.opaque({ color: opts.mode[opts.on], ground: opts.mode.bg });
|
|
252
|
+
|
|
253
|
+
return Theme.contrastOf({
|
|
254
|
+
foreground: ThemeTokens.opaque({ color: opts.mode[opts.text], ground }),
|
|
255
|
+
background: ground,
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** Every pair of a mode below AA, each as a sentence that names the pair, the colours and the ratio. */
|
|
260
|
+
private static contrastProblems(opts: { name: 'light' | 'dark'; mode: TTokenMode }): string[] {
|
|
261
|
+
const problems: string[] = [];
|
|
262
|
+
// The greys of the board's panes sit beside the tokens, so a pair on one of them is read the same way.
|
|
263
|
+
const mode = { ...opts.mode, ...ThemeTokens.SURFACES[opts.name] };
|
|
264
|
+
|
|
265
|
+
for (const [pairs, needed, role] of [
|
|
266
|
+
[[...TEXT_PAIRS, ...SURFACE_PAIRS], TEXT_RATIO, 'text'],
|
|
267
|
+
[MARK_PAIRS, MARK_RATIO, 'a mark'],
|
|
268
|
+
] as const) {
|
|
269
|
+
for (const [text, on] of pairs) {
|
|
270
|
+
const ratio = ThemeTokens.ratio({ mode, text, on });
|
|
271
|
+
|
|
272
|
+
if (ratio < needed) {
|
|
273
|
+
problems.push(
|
|
274
|
+
`${opts.name}: ${text} ${mode[text]} as ${role} on ${on} ${mode[on]} is ${ratio.toFixed(2)}:1; it needs ${needed}:1`,
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return problems;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* The token set of a project's `theme` (or of the default preset when it has none): the preset as written, the
|
|
285
|
+
* accent family derived when the project gives its own accent, then its per-token overrides. Every pair is checked
|
|
286
|
+
* for each mode and a pair below AA refuses the whole theme; nothing is swapped for another colour.
|
|
287
|
+
*/
|
|
288
|
+
static resolve(opts: { theme?: IThemeConfig }): TTokensResult {
|
|
289
|
+
const theme = opts.theme ?? {};
|
|
290
|
+
const presetName = theme.preset ?? ThemeTokens.DEFAULT_PRESET;
|
|
291
|
+
const preset = Object.hasOwn(ThemeTokens.PRESETS, presetName)
|
|
292
|
+
? ThemeTokens.PRESETS[presetName]
|
|
293
|
+
: undefined;
|
|
294
|
+
|
|
295
|
+
if (preset === undefined) {
|
|
296
|
+
return {
|
|
297
|
+
ok: false,
|
|
298
|
+
problems: [
|
|
299
|
+
`theme preset '${presetName}' is unknown; use one of ${Object.keys(ThemeTokens.PRESETS).join(', ')}`,
|
|
300
|
+
],
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
if (
|
|
305
|
+
theme.accent === undefined &&
|
|
306
|
+
(theme.accentDark !== undefined || theme.accentText !== undefined)
|
|
307
|
+
) {
|
|
308
|
+
return {
|
|
309
|
+
ok: false,
|
|
310
|
+
problems: ['theme accentDark and accentText belong to an accent: give accent too'],
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (theme.radius !== undefined && !ThemeTokens.RADIUS_PATTERN.test(theme.radius)) {
|
|
315
|
+
return {
|
|
316
|
+
ok: false,
|
|
317
|
+
problems: [
|
|
318
|
+
`theme radius '${theme.radius}' is not 0 or a length such as 4px, 0.25rem or 0.5em`,
|
|
319
|
+
],
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const light: TTokenMode = { ...preset.light };
|
|
324
|
+
const dark: TTokenMode = { ...preset.dark };
|
|
325
|
+
const seed: IThemeInput =
|
|
326
|
+
theme.accent === undefined
|
|
327
|
+
? preset.seed
|
|
328
|
+
: { accent: theme.accent, accentDark: theme.accentDark, accentText: theme.accentText };
|
|
329
|
+
const own =
|
|
330
|
+
seed.accent === preset.seed.accent &&
|
|
331
|
+
seed.accentDark === preset.seed.accentDark &&
|
|
332
|
+
seed.accentText === undefined;
|
|
333
|
+
|
|
334
|
+
// Venizia carries its accent family as written; any other seed is derived by the page resolver, which refuses a bad one.
|
|
335
|
+
if (!own || presetName !== 'venizia') {
|
|
336
|
+
const derived = ProjectTheme.resolve({ project: seed });
|
|
337
|
+
|
|
338
|
+
if (!derived.ok) {
|
|
339
|
+
return { ok: false, problems: derived.problems };
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
for (const [mode, palette, presetTint] of [
|
|
343
|
+
[light, derived.theme.light, preset.light['accent-soft']],
|
|
344
|
+
[dark, derived.theme.dark, preset.dark['accent-soft']],
|
|
345
|
+
] as const) {
|
|
346
|
+
mode.accent = palette.accent;
|
|
347
|
+
mode['accent-ink'] = palette.accentInk;
|
|
348
|
+
// A preset's own tint stays for its own accent; a project's accent gets the derived one.
|
|
349
|
+
mode['accent-soft'] =
|
|
350
|
+
theme.accent === undefined && presetTint !== undefined ? presetTint : palette.accentSoft;
|
|
351
|
+
mode['accent-text'] = palette.accent;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// On the light ground the page resolver's accent is the text colour; the mark and the fill are the seed itself.
|
|
355
|
+
light.accent = seed.accent;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
const problems: string[] = [];
|
|
359
|
+
|
|
360
|
+
for (const [name, value] of Object.entries(theme.tokens ?? {})) {
|
|
361
|
+
if (!Object.hasOwn(light, name)) {
|
|
362
|
+
problems.push(
|
|
363
|
+
`theme token '${name}' is unknown; use one of ${ThemeTokens.names().join(', ')}`,
|
|
364
|
+
);
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
const given = typeof value === 'string' ? { light: value, dark: value } : value;
|
|
369
|
+
|
|
370
|
+
for (const [mode, key] of [
|
|
371
|
+
[light, 'light'],
|
|
372
|
+
[dark, 'dark'],
|
|
373
|
+
] as const) {
|
|
374
|
+
const color = given[key];
|
|
375
|
+
|
|
376
|
+
if (color === undefined) {
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
if (!ThemeTokens.COLOUR.test(color)) {
|
|
381
|
+
problems.push(`theme token '${name}' ${key} '${color}' is not a hex colour like #8a5a20`);
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
mode[name] = color.toLowerCase();
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
problems.push(
|
|
390
|
+
...ThemeTokens.contrastProblems({ name: 'light', mode: light }),
|
|
391
|
+
...ThemeTokens.contrastProblems({ name: 'dark', mode: dark }),
|
|
392
|
+
);
|
|
393
|
+
|
|
394
|
+
if (problems.length > 0) {
|
|
395
|
+
return { ok: false, problems };
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
return {
|
|
399
|
+
ok: true,
|
|
400
|
+
tokens: {
|
|
401
|
+
preset: presetName,
|
|
402
|
+
light,
|
|
403
|
+
dark,
|
|
404
|
+
font: theme.font ?? ThemeTokens.FONT,
|
|
405
|
+
mono: theme.mono ?? ThemeTokens.MONO,
|
|
406
|
+
radius: theme.radius ?? ThemeTokens.RADIUS,
|
|
407
|
+
},
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
}
|
package/src/ui/prompt.ts
CHANGED
|
@@ -8,6 +8,7 @@ interface IChoice {
|
|
|
8
8
|
hint?: string;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
/** Terminal prompts (text, select, multiselect, confirm, plan) for the interactive commands such as `vulcan init`, `vulcan add` and `vulcan profile`. */
|
|
11
12
|
export class TerminalPrompt {
|
|
12
13
|
/**
|
|
13
14
|
* Free text, only where there is nothing to pick from (a new name). A default, when there is one, is
|