Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/chromatic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Chromatic

# The desktop app's stories (desktop/src/*.stories.tsx), published to Chromatic for visual review.
# Without the CHROMATIC_PROJECT_TOKEN secret (a fork, or a repository not set up for it) the job
# says so and passes.

on:
pull_request:
push:
branches: [next]

permissions:
contents: read

jobs:
chromatic:
runs-on: ubuntu-latest
env:
CHROMATIC_PROJECT_TOKEN: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
steps:
- name: Skip without a project token
if: env.CHROMATIC_PROJECT_TOKEN == ''
run: echo "CHROMATIC_PROJECT_TOKEN is not set; Chromatic is skipped."
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
if: env.CHROMATIC_PROJECT_TOKEN != ''
with:
fetch-depth: 0 # Chromatic compares with the builds of earlier commits
persist-credentials: false
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
if: env.CHROMATIC_PROJECT_TOKEN != ''
with:
node-version: 24
package-manager-cache: false
- run: npm ci
if: env.CHROMATIC_PROJECT_TOKEN != ''
working-directory: desktop
- uses: chromaui/action@latest
if: env.CHROMATIC_PROJECT_TOKEN != ''
with:
workingDir: desktop
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
onlyChanged: true
exitZeroOnChanges: true
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ to change the code.
| `node src/cli.ts <command>` | The CLI without installing it. |
| `npm run desktop` | The desktop app (`desktop/`, Electron), built and opened. It has its own `package.json` and `node_modules`: `npm install` in `desktop/` once. `npm run dev` there reloads the page as you edit. |
| `npm run desktop:test` | The desktop app from end to end: the real app, through its real window, on a pine home of its own with the scripted model server. About thirty seconds; needs a screen. Run it when you change `desktop/`, the control API the app uses (`src/http.ts`, `src/owner.ts`) or `pine service`. `npm run check` in `desktop/` is its type check. |
| `npm run storybook` (in `desktop/`) | Storybook for the parts of the app's page (`desktop/src/*.stories.tsx`), at port 6006; `npm run build-storybook` builds it. Chromatic publishes the stories on every pull request (`.github/workflows/chromatic.yml`, secret `CHROMATIC_PROJECT_TOKEN`). Add or update a story when you change `desktop/src/ui.tsx`. |
| `npm run desktop:pack` | `desktop/release/mac-arm64/Pine.app` (`mac/` on Intel), with the package of `npm run build` and its dependencies, the Node it runs on, pine's helpers built (`scripts/helpers.mjs`) and `pine` for a terminal inside, signed with the hardened runtime. `node desktop/scripts/smoke.mjs` starts that app from a folder of its own and checks that it runs on the pine and the Node it carries. Run both when you change `desktop/scripts/`, a helper's build function, `src/prebuilt.ts` or `desktop/electron/service.ts`. |

There is no build step. Node runs the TypeScript directly (the compiled parts, pine's Swift
Expand Down
1 change: 1 addition & 0 deletions desktop/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ dist-electron/
release/
release-*/
.stage/
storybook-static/
10 changes: 10 additions & 0 deletions desktop/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { StorybookConfig } from "@storybook/react-vite";

const config: StorybookConfig = {
framework: "@storybook/react-vite",
stories: ["../src/**/*.stories.tsx"],
addons: ["@storybook/addon-docs"],
core: { disableTelemetry: true },
};

export default config;
66 changes: 66 additions & 0 deletions desktop/.storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import type { Decorator, Preview } from "@storybook/react-vite";
import { useLayoutEffect } from "react";
import "../src/styles.css";

// The app has no theme switch of its own: styles.css follows the system with
// `@media (prefers-color-scheme: dark)`. To show either theme whatever the system says, the
// toolbar rewrites those rules' media: "all" forces dark, "not all" forces light, and "system"
// puts the original query back.
const DARK = /prefers-color-scheme:\s*dark/;
const original = new WeakMap<CSSMediaRule, string>();

function darkRules(): CSSMediaRule[] {
const found: CSSMediaRule[] = [];
for (const sheet of Array.from(document.styleSheets)) {
let rules: CSSRuleList;
try {
rules = sheet.cssRules;
} catch {
continue; // another origin's sheet
}
for (const rule of Array.from(rules)) {
if (!(rule instanceof CSSMediaRule)) continue;
const media = original.get(rule) ?? rule.media.mediaText;
if (DARK.test(media)) found.push(rule);
}
}
return found;
}

function applyTheme(theme: string) {
for (const rule of darkRules()) {
if (!original.has(rule)) original.set(rule, rule.media.mediaText);
rule.media.mediaText = theme === "dark" ? "all" : theme === "light" ? "not all" : original.get(rule)!;
}
document.documentElement.style.colorScheme = theme === "system" ? "" : theme;
}

const withTheme: Decorator = (Story, context) => {
const theme = context.globals.theme ?? "system";
useLayoutEffect(() => applyTheme(theme), [theme]);
return <Story />;
};

const preview: Preview = {
globalTypes: {
theme: {
description: "Light or dark, as the system would choose it",
toolbar: {
title: "Theme",
icon: "mirror",
items: [
{ value: "system", title: "System" },
{ value: "light", title: "Light" },
{ value: "dark", title: "Dark" },
],
dynamicTitle: true,
},
},
},
initialGlobals: { theme: "light" },
decorators: [withTheme],
parameters: { layout: "centered" },
tags: ["autodocs"],
};

export default preview;
Loading
Loading