diff --git a/.gitattributes b/.gitattributes index 3f67d46f31..4aeb1e48e6 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3,3 +3,15 @@ tests/fixtures/seal_view/** -text packages/seal-view/test/fixtures/** -text # Exact upload bytes; Cloud pins this file's SHA-256. packages/flow/tests/fixtures/public_seal/golden_vectors.json -text + +# Preserve the exact upstream license bytes, including prose whitespace. +packages/desktop/src/styles/vendor/semantic-theme/fonts/OFL-*.txt whitespace=-blank-at-eol +packages/desktop/openadapt_desktop/portal/shell/fonts/OFL-*.txt whitespace=-blank-at-eol + +# Hash-bound exports must not change when a checkout enables CRLF conversion. +packages/desktop/src/styles/vendor/** -text +packages/desktop/openadapt_desktop/portal/shell/fonts/** -text +# The plain-file theme generator checks these outputs with stable LF endings. +packages/desktop/openadapt_desktop/portal/shell/styles.css text eol=lf +packages/desktop/openadapt_desktop/portal/shell/index.html text eol=lf +packages/desktop/openadapt_desktop/portal/shell/manifest.webmanifest text eol=lf diff --git a/packages/desktop/CHANGELOG.md b/packages/desktop/CHANGELOG.md index 263ad3403b..6f02ed78db 100644 --- a/packages/desktop/CHANGELOG.md +++ b/packages/desktop/CHANGELOG.md @@ -1,6 +1,18 @@ # CHANGELOG +## v0.32.0 (2026-11-22) + +### Features + +- **design**: share Desktop overlay and phone theme roles + +### Bug Fixes + +- **desktop**: preserve pinned theme bytes on checkout + + + ## v0.31.3 (2026-11-22) ### Bug Fixes diff --git a/packages/desktop/openadapt_desktop/__init__.py b/packages/desktop/openadapt_desktop/__init__.py index da9fba3b4f..bd5e0a3fdf 100644 --- a/packages/desktop/openadapt_desktop/__init__.py +++ b/packages/desktop/openadapt_desktop/__init__.py @@ -21,4 +21,4 @@ +-- backends/ Storage backend plugins """ -__version__ = "0.31.3" +__version__ = "0.32.0" diff --git a/packages/desktop/openadapt_desktop/portal/server.py b/packages/desktop/openadapt_desktop/portal/server.py index e8831d3a42..4f67eb9fbb 100644 --- a/packages/desktop/openadapt_desktop/portal/server.py +++ b/packages/desktop/openadapt_desktop/portal/server.py @@ -46,6 +46,8 @@ SHELL_ASSETS: dict[str, tuple[str, str]] = { "/app.js": ("shell/app.js", "application/javascript; charset=utf-8"), "/styles.css": ("shell/styles.css", "text/css; charset=utf-8"), + "/fonts/PublicSans-Variable.woff2": ("shell/fonts/PublicSans-Variable.woff2", "font/woff2"), + "/fonts/OFL-PublicSans.txt": ("shell/fonts/OFL-PublicSans.txt", "text/plain; charset=utf-8"), "/manifest.webmanifest": ( "shell/manifest.webmanifest", "application/manifest+json; charset=utf-8", diff --git a/packages/desktop/openadapt_desktop/portal/shell/fonts/OFL-PublicSans.txt b/packages/desktop/openadapt_desktop/portal/shell/fonts/OFL-PublicSans.txt new file mode 100644 index 0000000000..9eef1e9900 --- /dev/null +++ b/packages/desktop/openadapt_desktop/portal/shell/fonts/OFL-PublicSans.txt @@ -0,0 +1,93 @@ +Copyright 2015 The Public Sans Project Authors (https://github.com/uswds/public-sans) + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +https://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/packages/desktop/openadapt_desktop/portal/shell/fonts/PublicSans-Variable.woff2 b/packages/desktop/openadapt_desktop/portal/shell/fonts/PublicSans-Variable.woff2 new file mode 100644 index 0000000000..15b5f3da4d Binary files /dev/null and b/packages/desktop/openadapt_desktop/portal/shell/fonts/PublicSans-Variable.woff2 differ diff --git a/packages/desktop/openadapt_desktop/portal/shell/index.html b/packages/desktop/openadapt_desktop/portal/shell/index.html index e976bc24c0..39577e3650 100644 --- a/packages/desktop/openadapt_desktop/portal/shell/index.html +++ b/packages/desktop/openadapt_desktop/portal/shell/index.html @@ -6,8 +6,8 @@ - - + + OpenAdapt decisions diff --git a/packages/desktop/openadapt_desktop/portal/shell/manifest.webmanifest b/packages/desktop/openadapt_desktop/portal/shell/manifest.webmanifest index e45242ca5f..c2e23f0076 100644 --- a/packages/desktop/openadapt_desktop/portal/shell/manifest.webmanifest +++ b/packages/desktop/openadapt_desktop/portal/shell/manifest.webmanifest @@ -6,6 +6,6 @@ "scope": "/", "display": "standalone", "orientation": "portrait", - "background_color": "#0B1220", - "theme_color": "#0B1220" + "background_color": "#05080d", + "theme_color": "#05080d" } diff --git a/packages/desktop/openadapt_desktop/portal/shell/styles.css b/packages/desktop/openadapt_desktop/portal/shell/styles.css index 9190c0ce9b..80fe9f2f6c 100644 --- a/packages/desktop/openadapt_desktop/portal/shell/styles.css +++ b/packages/desktop/openadapt_desktop/portal/shell/styles.css @@ -1,59 +1,54 @@ -/* The phone shell: one decision card in the reading zone, two answers in the - thumb zone. Dark first, with a light theme from the system setting. - - The shell is served by the engine as plain files with no bundler, so it - cannot import the vendored token stylesheet. Every literal colour below is - copied from the canonical design tokens in - src/styles/vendor/openadapt-web/tokens.json: the dark theme from the inset - set, the light theme from the page set. A dark value the canonical set does - not have is mixed from canonical values, never picked. - tests/test_portal/test_shell_palette.py fails if a copy stops matching. */ +/* Generated by scripts/build-phone-theme.mjs from the pinned semantic theme. +Public Sans is SIL OFL 1.1; its license is /fonts/OFL-PublicSans.txt. */ +@font-face { font-family: "Public Sans"; src: url("/fonts/PublicSans-Variable.woff2") format("woff2"); font-weight: 100 900; font-display: swap; } :root { color-scheme: dark; - --bg: #0B1220; /* --inset-bg */ - --panel: #131C2C; /* --inset-raised */ - --line: #1E293B; /* --inset-border */ - --text: #E2E8F0; /* --inset-text */ - --accent: #34D399; /* --inset-ok */ - --warn: #FBBF24; /* --inset-warn */ - --success: #34D399; /* --inset-ok */ - --panel-2: color-mix(in srgb, var(--panel) 90%, var(--text)); - --muted: color-mix(in srgb, var(--text) 68%, var(--bg)); - --faint: color-mix(in srgb, var(--text) 46%, var(--bg)); - --accent-ink: var(--bg); - --danger: color-mix(in srgb, #B3261E 55%, #FFFFFF); /* --accent-danger, lifted */ - --teach: color-mix(in srgb, #574FB0 50%, #FFFFFF); /* --link-visited, lifted */ - --focus: color-mix(in srgb, #2563EB 70%, #FFFFFF); /* --focus-ring, lifted */ + --bg: #05080d; + --panel: #0a0f17; + --panel-2: #0d141f; + --line: #1a2432; + --text: #edf1f7; + --muted: #9ba7b7; + --faint: #9ba7b7; + --accent: #79adff; + --accent-ink: #04101f; + --warn: #f5b640; + --success: #3ad69f; + --danger: #ff8f86; + --teach: #79adff; + --focus: #a2c6ff; + --action: #edf1f7; + --on-action: #05080d; + --font-body: "Public Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; + --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; --accent-glow: color-mix(in srgb, var(--accent) 26%, transparent); --danger-glow: color-mix(in srgb, var(--danger) 24%, transparent); --warn-soft: color-mix(in srgb, var(--warn) 13%, transparent); - --scrim: rgba(4, 7, 13, 0.72); - --shadow: 0 24px 60px -34px rgba(0, 0, 0, 0.7); - --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif; - --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace; + --scrim: color-mix(in srgb, var(--bg) 72%, transparent); + --shadow: 0 24px 60px -34px color-mix(in srgb, var(--text) 20%, transparent); } - @media (prefers-color-scheme: light) { :root { color-scheme: light; - --bg: #F5F7FA; /* --surface */ - --panel: #FFFFFF; /* --surface-raised */ - --panel-2: #EDF1F6; /* --surface-sunken */ - --line: #DEE4EC; /* --hairline */ - --text: #0B1220; /* --ink */ - --muted: #414E63; /* --text-secondary */ - --faint: #5A697F; /* --text-tertiary */ - --accent: #0B7A5A; /* --accent-verified */ - --accent-ink: #FFFFFF; - --warn: #9A5B0A; /* --accent-halt */ - --success: #0B7A5A; /* --accent-verified */ - --danger: #B3261E; /* --accent-danger */ - --teach: #574FB0; /* --link-visited */ - --focus: #2563EB; /* --focus-ring */ - --scrim: rgba(11, 18, 32, 0.4); - --shadow: 0 24px 60px -36px rgba(11, 18, 32, 0.35); + --bg: #ffffff; + --panel: #f5f7fa; + --panel-2: #edf2f5; + --line: #dde3e9; + --text: #0f1722; + --muted: #4f5a67; + --faint: #4f5a67; + --accent: #1f4fbf; + --accent-ink: #ffffff; + --warn: #9a5b0a; + --success: #0b7a5a; + --danger: #b3261e; + --teach: #1f4fbf; + --focus: #1f4fbf; + --action: #0f1722; + --on-action: #ffffff; } } +/* END GENERATED PHONE THEME */ * { box-sizing: border-box; } [hidden] { display: none !important; } @@ -93,7 +88,7 @@ button { font: inherit; color: inherit; } .mark::after { content: ""; position: absolute; inset: 5px; border-radius: 2px; background: var(--bg); } .status { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); min-width: 0; } .device { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } -.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 22%, transparent); flex: none; } +.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); flex: none; } body.offline .dot { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-glow); } .offline-bar { margin: 10px 0 0; padding: 9px 12px; border-radius: 12px; background: var(--danger-glow); color: var(--danger); font-size: 13px; flex: none; } @@ -212,7 +207,7 @@ body.offline .dot { background: var(--danger); box-shadow: 0 0 0 3px var(--dange .ans:active { transform: scale(0.97); } .ans svg { width: 20px; height: 20px; flex: none; } .ans.no { color: var(--danger); } -.ans.yes.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); } +.ans.yes.primary { background: var(--action); color: var(--on-action); border-color: var(--action); } .ans[disabled] { opacity: 0.38; cursor: not-allowed; } .ans.slot { visibility: hidden; } .more { width: 48px; height: 48px; border-radius: 16px; border: 1px solid var(--line); background: none; display: grid; place-items: center; cursor: pointer; color: var(--muted); } diff --git a/packages/desktop/openadapt_desktop/portal/shell/sw.js b/packages/desktop/openadapt_desktop/portal/shell/sw.js index d7a384bbd6..60993f5781 100644 --- a/packages/desktop/openadapt_desktop/portal/shell/sw.js +++ b/packages/desktop/openadapt_desktop/portal/shell/sw.js @@ -32,6 +32,8 @@ const SHELL_ASSETS = Object.freeze([ "/", "/app.js", "/styles.css", + "/fonts/PublicSans-Variable.woff2", + "/fonts/OFL-PublicSans.txt", "/manifest.webmanifest", ]); diff --git a/packages/desktop/package-lock.json b/packages/desktop/package-lock.json index 6f92410924..40b09c9271 100644 --- a/packages/desktop/package-lock.json +++ b/packages/desktop/package-lock.json @@ -1,12 +1,12 @@ { "name": "openadapt-desktop", - "version": "0.31.3", + "version": "0.32.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "openadapt-desktop", - "version": "0.31.3", + "version": "0.32.0", "dependencies": { "@tauri-apps/api": "^2", "@tauri-apps/plugin-notification": "^2", diff --git a/packages/desktop/package.json b/packages/desktop/package.json index 83c98dc872..758f41e268 100644 --- a/packages/desktop/package.json +++ b/packages/desktop/package.json @@ -1,6 +1,6 @@ { "name": "openadapt-desktop", - "version": "0.31.3", + "version": "0.32.0", "description": "Installed companion for OpenAdapt authoring, teaching, and local pairing", "private": true, "type": "module", @@ -11,7 +11,9 @@ "tokens:check": "node scripts/vendor-design-tokens.mjs --check", "capture:cockpit": "node scripts/capture-cockpit-previews.mjs", "preview": "vite preview", - "tauri": "tauri" + "tauri": "tauri", + "theme:check": "node scripts/check-semantic-theme.mjs src/styles/vendor/semantic-theme", + "prebuild": "npm run theme:check && node scripts/build-phone-theme.mjs --check" }, "devDependencies": { "@tauri-apps/cli": "^2", diff --git a/packages/desktop/pyproject.toml b/packages/desktop/pyproject.toml index 7b180de383..b954f795e4 100644 --- a/packages/desktop/pyproject.toml +++ b/packages/desktop/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "openadapt-desktop" -version = "0.31.3" +version = "0.32.0" description = "The OpenAdapt desktop app and local engine: record a data-entry task, run it on a list, and check each saved record" readme = "README.md" requires-python = ">=3.11" diff --git a/packages/desktop/scripts/build-phone-theme.mjs b/packages/desktop/scripts/build-phone-theme.mjs new file mode 100644 index 0000000000..541a3c92f7 --- /dev/null +++ b/packages/desktop/scripts/build-phone-theme.mjs @@ -0,0 +1,34 @@ +// Generate the plain-file phone shell from the same pinned theme as Desktop. +// The font uses the existing exact static-asset map; the CSP stays unchanged. +import fs from 'node:fs'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; +const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); +const vendor = path.join(root, 'src/styles/vendor/semantic-theme'); +const shell = path.join(root, 'openadapt_desktop/portal/shell'); +const theme = JSON.parse(fs.readFileSync(path.join(vendor, 'semantic-theme.json'), 'utf8')); +const roles = { '--bg':'--oa-canvas', '--panel':'--oa-surface', '--panel-2':'--oa-surface-sunken', '--line':'--oa-border', '--text':'--oa-text', '--muted':'--oa-text-muted', '--faint':'--oa-text-muted', '--accent':'--oa-link', '--accent-ink':'--oa-on-link', '--warn':'--oa-stopped', '--success':'--oa-verified', '--danger':'--oa-reconcile', '--teach':'--oa-link', '--focus':'--oa-focus', '--action':'--oa-text', '--on-action':'--oa-canvas' }; +const declaration = (colors) => Object.entries(roles).map(([name, source]) => ` ${name}: ${colors[source]};`).join('\n'); +fs.mkdirSync(path.join(shell, 'fonts'), { recursive: true }); +for (const name of ['PublicSans-Variable.woff2', 'OFL-PublicSans.txt']) { + const source = fs.readFileSync(path.join(vendor, 'fonts', name)); + const destination = path.join(shell, 'fonts', name); + if (process.argv.includes('--check')) { if (!fs.existsSync(destination) || !fs.readFileSync(destination).equals(source)) throw new Error(`Phone font drift: ${name}`); } + else fs.writeFileSync(destination, source); +} +const marker = '/* END GENERATED PHONE THEME */'; +const prefix = `/* Generated by scripts/build-phone-theme.mjs from the pinned semantic theme.\nPublic Sans is SIL OFL 1.1; its license is /fonts/OFL-PublicSans.txt. */\n@font-face { font-family: "Public Sans"; src: url("/fonts/PublicSans-Variable.woff2") format("woff2"); font-weight: 100 900; font-display: swap; }\n:root {\n color-scheme: dark;\n${declaration(theme.themes.dark)}\n --font-body: ${theme.common['--oa-font-body']};\n --font-mono: ${theme.common['--oa-font-mono']};\n --accent-glow: color-mix(in srgb, var(--accent) 26%, transparent);\n --danger-glow: color-mix(in srgb, var(--danger) 24%, transparent);\n --warn-soft: color-mix(in srgb, var(--warn) 13%, transparent);\n --scrim: color-mix(in srgb, var(--bg) 72%, transparent);\n --shadow: 0 24px 60px -34px color-mix(in srgb, var(--text) 20%, transparent);\n}\n@media (prefers-color-scheme: light) {\n :root {\n color-scheme: light;\n${declaration(theme.themes.light)}\n }\n}\n${marker}`; +const stylesheet = path.join(shell, 'styles.css'); +const existing = fs.readFileSync(stylesheet, 'utf8'); +const tail = existing.includes(marker) ? existing.slice(existing.indexOf(marker) + marker.length) : '\n\n' + existing.slice(existing.indexOf('* { box-sizing')); +const css = prefix + tail; +const htmlPath = path.join(shell, 'index.html'); +const html = fs.readFileSync(htmlPath, 'utf8').replace(/(name="theme-color" media="\(prefers-color-scheme: )(dark|light)(\)" content=")[^"]+("\s*>)/g, (_, a, mode, b, c) => a + mode + b + theme.themes[mode]['--oa-canvas'] + c); +const manifestPath = path.join(shell, 'manifest.webmanifest'); +const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8')); +manifest.background_color = theme.themes.dark['--oa-canvas']; +manifest.theme_color = theme.themes.dark['--oa-canvas']; +for (const [file, result] of [[stylesheet, css], [htmlPath, html], [manifestPath, JSON.stringify(manifest, null, 2) + '\n']]) { + if (process.argv.includes('--check')) { if (fs.readFileSync(file, 'utf8') !== result) throw new Error(`Phone theme drift: ${path.basename(file)}. Run node scripts/build-phone-theme.mjs.`); } + else fs.writeFileSync(file, result); +} diff --git a/packages/desktop/scripts/check-semantic-theme.mjs b/packages/desktop/scripts/check-semantic-theme.mjs new file mode 100644 index 0000000000..ce1e6ab47a --- /dev/null +++ b/packages/desktop/scripts/check-semantic-theme.mjs @@ -0,0 +1,24 @@ +// Check an immutable vendored snapshot. This does not claim it is the live theme. +import crypto from 'node:crypto'; +import fs from 'node:fs'; +import path from 'node:path'; +const root = process.argv[2]; +if (!root) throw new Error('Usage: node check-semantic-theme.mjs '); +const provenance = JSON.parse(fs.readFileSync(path.join(root, 'provenance.json'), 'utf8')); +if (provenance.version !== 2 || provenance.source !== 'OpenAdaptAI/openadapt-web' || !/^[a-f0-9]{40}$/.test(provenance.commit)) throw new Error('Invalid semantic theme provenance.'); +for (const [name, entry] of Object.entries(provenance.files)) { + if (path.isAbsolute(name) || name.split(/[\\/]/).includes('..')) throw new Error('Invalid theme path.'); + const hash = crypto.createHash('sha256').update(fs.readFileSync(path.join(root, name))).digest('hex'); + if (hash !== entry.sha256) throw new Error(`Semantic theme drift: ${name}`); +} +for (const required of ['semantic-theme.css', 'semantic-theme.json', 'fonts.css', 'fonts/OFL-PublicSans.txt', 'fonts/OFL-InterTight.txt']) { + if (!provenance.files[required]) throw new Error(`Missing semantic theme member: ${required}`); +} +const licenses = process.argv.indexOf('--licenses'); +if (licenses !== -1) { + const destination = process.argv[licenses + 1]; + if (!destination) throw new Error('--licenses requires a destination.'); + fs.mkdirSync(destination, { recursive: true }); + for (const name of ['OFL-PublicSans.txt', 'OFL-InterTight.txt']) fs.copyFileSync(path.join(root, 'fonts', name), path.join(destination, name)); +} +console.log(`Semantic theme v2 matches pinned ${provenance.commit}: ${Object.keys(provenance.files).length} files.`); diff --git a/packages/desktop/scripts/themeCheckout.test.ts b/packages/desktop/scripts/themeCheckout.test.ts new file mode 100644 index 0000000000..77b6fd0be8 --- /dev/null +++ b/packages/desktop/scripts/themeCheckout.test.ts @@ -0,0 +1,39 @@ +// Pin-bound exports and generated phone files must survive Git's checkout +// conversions. Exercise the real filters, not the spelling of .gitattributes. +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; +import { spawnSync } from "node:child_process"; +import { fileURLToPath } from "node:url"; +import { expect, it } from "vitest"; + +const desktop = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); +const repository = path.resolve(desktop, "../.."); +const shell = "packages/desktop/openadapt_desktop/portal/shell/"; +const selected = spawnSync("git", [ + "ls-files", "-z", "--", "packages/desktop/src/styles/vendor/", + `${shell}styles.css`, `${shell}index.html`, `${shell}manifest.webmanifest`, `${shell}fonts/`, +], { cwd: repository, encoding: "utf8" }); +expect(selected.status, selected.stderr).toBe(0); +const files = selected.stdout.split("\0").filter(Boolean); +expect(files).toContain("packages/desktop/src/styles/vendor/openadapt-web/tokens.css"); +expect(files).toContain("packages/desktop/src/styles/vendor/semantic-theme/semantic-theme.css"); +expect(files).toContain(`${shell}styles.css`); + +it.each([false, true])("preserves every pinned/generated byte with core.autocrlf=%s", (autocrlf) => { + const temporary = fs.mkdtempSync(path.join(os.tmpdir(), "openadapt-theme-checkout-")); + try { + const destination = path.join(temporary, "checkout"); + const prefix = destination.split(path.sep).join("/") + "/"; + const checked = spawnSync("git", [ + "-c", `core.autocrlf=${autocrlf}`, "checkout-index", `--prefix=${prefix}`, "-z", "--stdin", + ], { cwd: repository, input: files.join("\0") + "\0", encoding: "utf8" }); + expect(checked.status, checked.stderr).toBe(0); + for (const file of files) { + expect(fs.readFileSync(path.join(destination, file)), file) + .toEqual(fs.readFileSync(path.join(repository, file))); + } + } finally { + fs.rmSync(temporary, { recursive: true, force: true }); + } +}); diff --git a/packages/desktop/src-tauri/Cargo.lock b/packages/desktop/src-tauri/Cargo.lock index 4ebe931bb7..9828037e31 100644 --- a/packages/desktop/src-tauri/Cargo.lock +++ b/packages/desktop/src-tauri/Cargo.lock @@ -2513,7 +2513,7 @@ dependencies = [ [[package]] name = "openadapt-desktop" -version = "0.31.3" +version = "0.32.0" dependencies = [ "hex", "reqwest", diff --git a/packages/desktop/src-tauri/Cargo.toml b/packages/desktop/src-tauri/Cargo.toml index a46e5607d4..1e8e1dc3d6 100644 --- a/packages/desktop/src-tauri/Cargo.toml +++ b/packages/desktop/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "openadapt-desktop" -version = "0.31.3" +version = "0.32.0" description = "Installed companion for OpenAdapt authoring, teaching, and local pairing" authors = ["OpenAdapt AI"] license = "MIT" diff --git a/packages/desktop/src-tauri/tauri.conf.json b/packages/desktop/src-tauri/tauri.conf.json index 11b8c27846..82b9fd8b3c 100644 --- a/packages/desktop/src-tauri/tauri.conf.json +++ b/packages/desktop/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "https://raw.githubusercontent.com/nicoverbruggen/tauri-v2-schema/main/schema.json", "productName": "OpenAdapt Desktop", - "version": "0.31.3", + "version": "0.32.0", "identifier": "ai.openadapt.desktop", "build": { "frontendDist": "../dist", diff --git a/packages/desktop/src/main.tsx b/packages/desktop/src/main.tsx index 21afb9332d..2bf3074762 100644 --- a/packages/desktop/src/main.tsx +++ b/packages/desktop/src/main.tsx @@ -5,6 +5,7 @@ import { ControlOverlay } from "./overlay/ControlOverlay"; import { ProgramWorkbenchPreview } from "./ui/ProgramWorkbenchPreview"; import "@openadapt/program-graph/styles.css"; import "./styles/app.css"; +import "./styles/semantic-theme.css"; const surface = new URLSearchParams(window.location.search).get("surface"); const root = surface === "control-overlay" diff --git a/packages/desktop/src/overlay/ControlOverlay.tsx b/packages/desktop/src/overlay/ControlOverlay.tsx index 0897ea4b8a..31fc07743a 100644 --- a/packages/desktop/src/overlay/ControlOverlay.tsx +++ b/packages/desktop/src/overlay/ControlOverlay.tsx @@ -312,7 +312,7 @@ export function ControlOverlay() { : "Pause"; return ( -
+
{target && (
None: with pytest.raises(FlowConsoleUnavailable) as refused: client.request("save_approval_detail", request_id="../session") assert refused.value.reason == "bad_identifier" + + +def test_the_pinned_interface_font_is_served_same_origin_with_the_existing_csp() -> None: + from pathlib import Path + + app, _ = build(FakeFlow()) + status, headers, body = app.handle("GET", "/fonts/PublicSans-Variable.woff2", {}, b"") + assert status == 200 + assert headers["Content-Type"] == "font/woff2" + vendor = Path(__file__).resolve().parents[2] / "src/styles/vendor/semantic-theme/fonts" + assert body == (vendor / "PublicSans-Variable.woff2").read_bytes() + policy = headers["Content-Security-Policy"] + assert "default-src 'self'" in policy + assert "font-src" not in policy + assert app.handle("GET", "/fonts/../server.py", {}, b"")[0] == 404 diff --git a/packages/desktop/tests/test_portal/test_shell_palette.py b/packages/desktop/tests/test_portal/test_shell_palette.py index 70e0b9c79d..aca95a4e03 100644 --- a/packages/desktop/tests/test_portal/test_shell_palette.py +++ b/packages/desktop/tests/test_portal/test_shell_palette.py @@ -1,13 +1,7 @@ -"""The phone shell's palette must stay the canonical one. +"""The plain-file phone shell is generated from the pinned shared theme. -The shell is served by the engine as plain files with no bundler, so it cannot -import the vendored token stylesheet the way the React cockpit does. Its -palette is therefore a literal copy, and a copy drifts unless something fails. - -This is what fails. It reads the vendored canonical tokens -(src/styles/vendor/openadapt-web/tokens.json, itself hash-pinned by -scripts/designTokens.test.ts and scripts/vendor-design-tokens.mjs) and -checks the shell against them. +The same guard compares every phone role in dark and light mode, rejects +unowned literal colors, and checks the installed browser chrome colors. """ from __future__ import annotations @@ -20,7 +14,7 @@ ROOT = Path(__file__).resolve().parents[2] SHELL = ROOT / "openadapt_desktop" / "portal" / "shell" -CANONICAL = ROOT / "src" / "styles" / "vendor" / "openadapt-web" / "tokens.json" +CANONICAL = ROOT / "src" / "styles" / "vendor" / "semantic-theme" / "semantic-theme.json" # The shell is dark first. Each shell token and the canonical token it copies, # per theme: the dark theme from the inset set, the light theme from the page @@ -28,38 +22,33 @@ # values and is not listed here; test_every_literal_colour_is_canonical covers # what it may be mixed from. DARK_TO_CANONICAL = { - "--bg": "--inset-bg", - "--panel": "--inset-raised", - "--line": "--inset-border", - "--text": "--inset-text", - "--accent": "--inset-ok", - "--warn": "--inset-warn", - "--success": "--inset-ok", -} - -LIGHT_TO_CANONICAL = { - "--bg": "--surface", - "--panel": "--surface-raised", - "--panel-2": "--surface-sunken", - "--line": "--hairline", - "--text": "--ink", - "--muted": "--text-secondary", - "--faint": "--text-tertiary", - "--accent": "--accent-verified", - "--warn": "--accent-halt", - "--success": "--accent-verified", - "--danger": "--accent-danger", - "--teach": "--link-visited", - "--focus": "--focus-ring", + "--bg": "--oa-canvas", + "--panel": "--oa-surface", + "--panel-2": "--oa-surface-sunken", + "--line": "--oa-border", + "--text": "--oa-text", + "--muted": "--oa-text-muted", + "--faint": "--oa-text-muted", + "--accent": "--oa-link", + "--warn": "--oa-stopped", + "--success": "--oa-verified", + "--danger": "--oa-reconcile", + "--teach": "--oa-link", + "--focus": "--oa-focus", + "--action": "--oa-text", + "--on-action": "--oa-canvas", } +LIGHT_TO_CANONICAL = DARK_TO_CANONICAL CSS = (SHELL / "styles.css").read_text(encoding="utf-8") -def _canonical_colors() -> dict[str, str]: +def _canonical_colors(theme: str = "dark") -> dict[str, str]: return { name: value.upper() - for name, value in json.loads(CANONICAL.read_text(encoding="utf-8"))["color"].items() + for name, value in json.loads(CANONICAL.read_text(encoding="utf-8"))["themes"][ + theme + ].items() } @@ -93,7 +82,7 @@ def test_dark_token_matches_canonical(shell_token: str, canonical_token: str) -> @pytest.mark.parametrize(("shell_token", "canonical_token"), LIGHT_TO_CANONICAL.items()) def test_light_token_matches_canonical(shell_token: str, canonical_token: str) -> None: - canonical = _canonical_colors() + canonical = _canonical_colors("light") assert canonical_token in canonical, f"{canonical_token} is not a canonical token" assert _light_root()[shell_token] == canonical[canonical_token], ( f"light {shell_token} in openadapt_desktop/portal/shell/styles.css drifted from " @@ -103,14 +92,15 @@ def test_light_token_matches_canonical(shell_token: str, canonical_token: str) - def test_every_literal_colour_is_canonical() -> None: """A dark value without a canonical twin is mixed, never picked.""" - canonical = set(_canonical_colors().values()) + canonical = set(_canonical_colors().values()) | set(_canonical_colors("light").values()) for value in re.findall(r"#[0-9A-Fa-f]{6}\b", CSS): assert value.upper() in canonical, f"{value} in styles.css is not a canonical colour" def test_shell_theme_colour_matches_the_ground() -> None: colors = _canonical_colors() - dark, light = colors["--inset-bg"], colors["--surface"] + dark = colors["--oa-canvas"] + light = _canonical_colors("light")["--oa-canvas"] manifest = json.loads((SHELL / "manifest.webmanifest").read_text(encoding="utf-8")) # The installed app opens dark first, matching the shell's default. assert manifest["background_color"].upper() == dark @@ -148,3 +138,19 @@ def test_shell_carries_no_retired_warm_value() -> None: text = (SHELL / name).read_text(encoding="utf-8").lower() found = sorted(value for value in retired if value in text) assert not found, f"{name} still carries retired warm-palette values: {found}" + + +def test_the_self_hosted_interface_font_and_its_license_are_the_pinned_bytes() -> None: + import hashlib + + vendor = CANONICAL.parent + assert 'url("/fonts/PublicSans-Variable.woff2")' in CSS + assert ( + hashlib.sha256((SHELL / "fonts/PublicSans-Variable.woff2").read_bytes()).digest() + == hashlib.sha256((vendor / "fonts/PublicSans-Variable.woff2").read_bytes()).digest() + ) + assert (vendor / "fonts/OFL-PublicSans.txt").read_bytes() == ( + SHELL / "fonts/OFL-PublicSans.txt" + ).read_bytes() + assert "/fonts/OFL-PublicSans.txt" in CSS + assert ".ans.yes.primary { background: var(--action);" in CSS diff --git a/packages/desktop/uv.lock b/packages/desktop/uv.lock index bdb61ef816..e2060a0bb5 100644 --- a/packages/desktop/uv.lock +++ b/packages/desktop/uv.lock @@ -1172,7 +1172,7 @@ wheels = [ [[package]] name = "openadapt-desktop" -version = "0.31.3" +version = "0.32.0" source = { editable = "." } dependencies = [ { name = "cryptography" }, diff --git a/packages/desktop/vite.config.ts b/packages/desktop/vite.config.ts index a971ee8497..aebf406433 100644 --- a/packages/desktop/vite.config.ts +++ b/packages/desktop/vite.config.ts @@ -3,21 +3,25 @@ import { fileURLToPath } from "node:url"; import { defineConfig, type Plugin } from "vite"; import react from "@vitejs/plugin-react"; -// The app bundles two SIL OFL 1.1 fonts (src/styles/fonts/SOURCES.md). The +// The app bundles SIL OFL 1.1 fonts from its local and shared theme sources. The // licence has to travel with every copy of a font, so the built frontend -// carries both licence files next to the fonts it ships. -const FONT_LICENCES = ["OFL-PublicSans.txt", "OFL-SourceSerif4.txt"]; +// carries each licence next to the fonts it ships. +const FONT_LICENCES = [ + ["OFL-PublicSans.txt", "./src/styles/fonts/OFL-PublicSans.txt"], + ["OFL-SourceSerif4.txt", "./src/styles/fonts/OFL-SourceSerif4.txt"], + ["OFL-InterTight.txt", "./src/styles/vendor/semantic-theme/fonts/OFL-InterTight.txt"], +]; function fontLicences(): Plugin { return { name: "openadapt-font-licences", apply: "build", generateBundle() { - for (const name of FONT_LICENCES) { + for (const [name, source] of FONT_LICENCES) { this.emitFile({ type: "asset", fileName: `licenses/${name}`, - source: readFileSync(new URL(`./src/styles/fonts/${name}`, import.meta.url), "utf8"), + source: readFileSync(new URL(source, import.meta.url), "utf8"), }); } },