evOo-local/packages/core/src/self-update.ts
cynarAI a55ed44394
One product: evOo updates and name, phone actions, German on mobile, working account deletion, consistent settings (#168)
* Pull updates from evOo instead of the upstream Rakazo repository

The in-app server updater, the image-based compose files and the desktop
auto-updater still pointed at elie222/rakazo, so updating an evOo install
would have pulled Rakazo. They now follow cynarAI/evOo-local, where the
publish workflow already pushes the images. The disabled Rakazo production
deploy job is gone from CI; evo deploys itself.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tgvrj34NMnaqvtgvruYQZZ

* Call the product evOo everywhere people see its name

The desktop setup window and menu, account emails, the iOS app name and
permission prompts, sign-in headings, messages bots post into connected chat
apps, the web fetch user agent, issue templates and the marketing site still
said Rakazo, or EvOo. They now say evOo. The marketing site no longer calls
evOo an alternative to itself.

Internal identifiers (package scopes, env vars, bundle ids, the desktop
productName that keys its data folder and keychain entry) stay as they are.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tgvrj34NMnaqvtgvruYQZZ

* Open conversation actions by holding a row on a phone

Pin, move to folder, mark unread, duplicate, archive and delete only opened
on right-click, which iOS Safari never fires. Holding a conversation or a
folder header now dispatches the same contextmenu event, so the existing menu
opens under the finger; Android's own long-press event is not doubled and the
lift does not also open the conversation.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tgvrj34NMnaqvtgvruYQZZ

* Give small chrome icons a 44px touch area on phones

The browser and computer toggles, the activity bell, the create button and the
section plus buttons were 18 to 36 px targets. On touch screens each now gets
an invisible 44px hit area without changing how it looks; the create button
uses the same plus icon as the rest of the sidebar instead of a text glyph,
and the computer toggle gets an accessible name.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tgvrj34NMnaqvtgvruYQZZ

* Add German to the mobile app

German speakers saw the phone app in English because the mobile UI only
knew English, Simplified Chinese, and Russian. The app now ships a German
catalog covering every mobile chrome string, follows a German device
language (de, de-DE, de-AT, de-CH, ...), and offers Deutsch in the Account
language picker.

Strings that also exist in the web German catalog reuse its wording so
web and phone say the same thing; the rest follow the same terms and the
informal "du".

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tgvrj34NMnaqvtgvruYQZZ

* Use the evOo sign-in strings in the German phone catalog

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tgvrj34NMnaqvtgvruYQZZ

* Make account deletion work and give settings one section style

Deleting an account posted to the auth endpoint without a JSON content
type, so the server refused it and the button did nothing. The privacy
page now deletes through the auth client and returns to sign-in. It also
drops the claims it could not verify, the export button that only showed
an alert, and its own padding, and shows where the data and the computer
live. Notifications and media settings use the same SettingsSection.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tgvrj34NMnaqvtgvruYQZZ

* Use status tokens, the shared switch and one German glossary

Voice stage dots, the onboarding progress bar and the Voice First button
used raw emerald, violet, cyan and rose; they now use foreground, success
and destructive like the rest of the app. The routine editor's hand-built
switch is the shared Switch. German says Unterhaltung for threads and
Space consistently on web and phone.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tgvrj34NMnaqvtgvruYQZZ

* Expect the evOo setup copy in the desktop e2e specs

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tgvrj34NMnaqvtgvruYQZZ

* Translate the voice preview label in the German phone catalog

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tgvrj34NMnaqvtgvruYQZZ

* Wait for the main thread URL without waiting for every resource

openMainBotThread already navigated with domcontentloaded; its URL check
then waited for the full load event, which can exceed 20 s on a busy
runner. The composer check that follows covers readiness.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tgvrj34NMnaqvtgvruYQZZ

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-06 00:38:31 +02:00

299 lines
11 KiB
TypeScript

/** The repository a stock evOo deployment tracks. */
export const OFFICIAL_REPO_URL = "https://github.com/cynarAI/evOo-local";
export const DEFAULT_UPDATE_BRANCH = "main";
export const DEFAULT_UPDATE_REMOTE = "origin";
const SCP_LIKE = /^(?<user>[A-Za-z0-9._-]+)@(?<host>[A-Za-z0-9._-]+):(?<path>[^:]+)$/;
const SAFE_PATH_SEGMENT = /^[A-Za-z0-9._-]+$/;
const BRANCH_REJECT = /[\s~^:?*[\\]/;
const COMMIT = /^[0-9a-f]{40}(?:[0-9a-f]{24})?$/i;
/** Whitespace and control bytes are how a second argument gets smuggled into a command. */
function hasUnsafeCharacter(value: string): boolean {
for (const character of value) {
const code = character.codePointAt(0) ?? 0;
if (code <= 0x20 || code === 0x7f) return true;
}
return false;
}
export type RepoUrlResult = { url: string } | { error: string };
export type BranchResult = { branch: string } | { error: string };
/**
* A custom repository is arbitrary code the server will run, so the only shapes accepted are
* unambiguous https and ssh git remotes. Anything that could be read as a git option, a local
* path, or a plaintext transport is refused rather than normalized into something plausible.
*/
export function normalizeRepoUrl(input: string): RepoUrlResult {
const trimmed = input.trim();
if (trimmed === "") return { error: "A repository URL is required." };
if (trimmed.length > 400) return { error: "That repository URL is too long." };
if (hasUnsafeCharacter(trimmed)) {
return { error: "A repository URL cannot contain spaces or control characters." };
}
if (trimmed.startsWith("-")) return { error: "A repository URL cannot start with a dash." };
const scp = SCP_LIKE.exec(trimmed);
if (scp?.groups) {
const path = normalizeRepoPath(scp.groups.path ?? "");
if (path === null) return { error: "That does not look like a git repository path." };
return { url: `${scp.groups.user}@${scp.groups.host}:${path}` };
}
let url: URL;
try {
url = new URL(trimmed);
} catch {
return { error: "Enter an https:// or ssh:// git URL." };
}
if (url.protocol !== "https:" && url.protocol !== "ssh:") {
return { error: "Only https:// and ssh:// git remotes are allowed." };
}
if (url.hostname === "") return { error: "That URL has no host." };
if (url.password !== "" || (url.protocol === "https:" && url.username !== "")) {
return { error: "Do not put credentials in the repository URL." };
}
if (url.protocol === "ssh:" && url.username !== "" && !SAFE_PATH_SEGMENT.test(url.username)) {
return { error: "That SSH username has unsupported characters." };
}
if (url.search !== "" || url.hash !== "") {
return { error: "A repository URL cannot carry a query string or fragment." };
}
const path = normalizeRepoPath(url.pathname);
if (path === null) return { error: "That does not look like a git repository path." };
const credentials = url.username === "" ? "" : `${url.username}@`;
const port = url.port === "" ? "" : `:${url.port}`;
return { url: `${url.protocol}//${credentials}${url.hostname}${port}/${path}` };
}
function normalizeRepoPath(raw: string): string | null {
const segments = raw.split("/").filter((segment) => segment !== "");
if (segments.length < 2) return null;
if (
segments.some(
(segment) => !SAFE_PATH_SEGMENT.test(segment) || segment === "." || segment === "..",
)
)
return null;
return segments.join("/");
}
/** `github.com/cynarai/evoo-local` for every spelling of the same remote, for comparison only. */
export function repoIdentity(url: string): string | null {
const normalized = normalizeRepoUrl(url);
if ("error" in normalized) return null;
const scp = SCP_LIKE.exec(normalized.url);
const host = scp?.groups?.host ?? safeHost(normalized.url);
const path = scp?.groups?.path ?? safePath(normalized.url);
if (host === null || path === null) return null;
return `${host}/${path.replace(/\.git$/, "")}`.toLowerCase();
}
function safeHost(url: string): string | null {
try {
return new URL(url).hostname;
} catch {
return null;
}
}
function safePath(url: string): string | null {
try {
return new URL(url).pathname.replace(/^\/+/, "");
} catch {
return null;
}
}
export function isOfficialRepoUrl(url: string): boolean {
const identity = repoIdentity(url);
return identity !== null && identity === repoIdentity(OFFICIAL_REPO_URL);
}
export function normalizeUpdateBranch(input: string): BranchResult {
const branch = input.trim();
if (branch === "") return { error: "A branch name is required." };
if (branch.length > 200) return { error: "That branch name is too long." };
if (hasUnsafeCharacter(branch) || BRANCH_REJECT.test(branch)) {
return { error: "That branch name has characters git rejects." };
}
if (branch.startsWith("-")) return { error: "A branch name cannot start with a dash." };
if (branch.includes("..") || branch.includes("@{")) {
return { error: "That branch name has characters git rejects." };
}
if (
branch === "@" ||
branch.endsWith(".") ||
branch.startsWith("/") ||
branch.endsWith("/") ||
branch.includes("//") ||
branch.split("/").some((component) => component.startsWith(".")) ||
branch.split("/").some((component) => component.endsWith(".lock"))
) {
return { error: "That branch name has characters git rejects." };
}
return { branch };
}
export function isGitCommit(value: string): boolean {
return COMMIT.test(value.trim());
}
export interface PorcelainStatus {
clean: boolean;
changed: string[];
}
/** Reads `git status --porcelain --untracked-files=no`; build output must not look like drift. */
export function parseGitStatusPorcelain(stdout: string): PorcelainStatus {
const changed = stdout
.split("\n")
.map((line) => line.trimEnd())
.filter((line) => line.trim() !== "")
.map((line) => line.slice(3).trim())
.filter((path) => path !== "");
return { clean: changed.length === 0, changed };
}
export interface UpdateStep {
id: string;
label: string;
command: string;
args: string[];
}
export interface UpdatePlanInput {
remote?: string;
remoteUrl: string;
branch: string;
/** Immutable commit selected by preflight; a later branch movement must not change the update. */
targetCommit: string;
/** Set when the checkout currently points at a different remote and has to be re-pointed. */
repointRemote?: boolean;
}
/**
* Ordered work to get from "new commits on the remote" to "new code on disk". The migration runs
* last so the window where the old process sees the new schema is as short as the restart itself,
* and the merge is fast-forward only so local commits fail the update instead of being discarded.
*/
export function updateSteps(input: UpdatePlanInput): UpdateStep[] {
if (!isGitCommit(input.targetCommit)) throw new Error("An update needs a full commit digest.");
const remote = input.remote ?? DEFAULT_UPDATE_REMOTE;
const steps: UpdateStep[] = [];
if (input.repointRemote === true) {
steps.push({
id: "remote",
label: "Point the checkout at the chosen repository",
command: "git",
args: ["remote", "set-url", remote, input.remoteUrl],
});
}
steps.push(
{
id: "fetch",
label: "Fetch the selected branch",
command: "git",
args: ["fetch", "--no-tags", "--prune", remote, input.branch],
},
{
id: "merge",
label: "Fast-forward to the checked commit",
command: "git",
args: ["merge", "--ff-only", input.targetCommit],
},
{
id: "install",
label: "Install dependencies",
command: "pnpm",
args: ["install", "--frozen-lockfile"],
},
{
id: "generate",
label: "Regenerate the database client",
command: "pnpm",
args: ["--filter", "@rakazo/db", "run", "generate"],
},
{
id: "build",
label: "Build the web app",
command: "pnpm",
args: ["--filter", "@rakazo/web", "run", "build"],
},
{
id: "migrate",
label: "Apply database migrations",
command: "pnpm",
args: ["--filter", "@rakazo/db", "run", "migrate"],
},
);
return steps;
}
export type RestartSupervisor =
| { kind: "systemd" | "pm2" | "declared"; label: string }
| { kind: "none"; label: null };
export const RESTART_SUPERVISOR_ENV = "RAKAZO_UPDATE_RESTART_SUPERVISOR";
/**
* Whether something outside this process will start it again after it exits. Docker restart
* policies are invisible from inside the container, so that case has to be declared by the
* operator; exiting without a supervisor would take the deployment down for good.
*/
export function detectRestartSupervisor(
env: Record<string, string | undefined>,
): RestartSupervisor {
const declared = env[RESTART_SUPERVISOR_ENV]?.trim();
if (declared) return { kind: "declared", label: declared };
if (env.INVOCATION_ID?.trim()) return { kind: "systemd", label: "systemd" };
if (env.pm_id?.trim() || env.PM2_HOME?.trim()) return { kind: "pm2", label: "pm2" };
return { kind: "none", label: null };
}
export function restartSupervisorAdvice(supervisor: RestartSupervisor): string {
if (supervisor.kind !== "none") {
return `evOo will exit after updating and ${supervisor.label} will start it on the new code.`;
}
return `No process supervisor was detected, so evOo will not exit on its own. Restart the API, worker, and web processes yourself, or set ${RESTART_SUPERVISOR_ENV} to the supervisor that restarts them (for example "docker" with restart: unless-stopped, or run under systemd with Restart=always).`;
}
export type UpdateAvailability =
| { status: "unavailable"; reason: string }
| { status: "dirty"; changed: string[] }
| { status: "up-to-date"; commit: string }
| { status: "available"; commit: string; targetCommit: string; behindBy: number };
export interface UpdateCheckInput {
checkoutReason?: string;
commit?: string;
targetCommit?: string;
behindBy?: number;
status?: PorcelainStatus;
}
/** One place decides whether an update may proceed, so the API and the tests agree. */
export function decideUpdateAvailability(input: UpdateCheckInput): UpdateAvailability {
if (input.checkoutReason) return { status: "unavailable", reason: input.checkoutReason };
if (!input.commit || !input.targetCommit) {
return { status: "unavailable", reason: "Could not read the current commit." };
}
if (input.status && !input.status.clean) {
return { status: "dirty", changed: input.status.changed };
}
if (input.commit === input.targetCommit) return { status: "up-to-date", commit: input.commit };
return {
status: "available",
commit: input.commit,
targetCommit: input.targetCommit,
behindBy: input.behindBy ?? 0,
};
}
export function shortCommit(commit: string | null | undefined): string {
return commit ? commit.trim().slice(0, 7) : "unknown";
}