diff --git a/docs/decisions.md b/docs/decisions.md index 2d811808b..4487af872 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -3577,3 +3577,94 @@ hashes, and the wording rule on the elements' text. The page was checked in Chrome against temporary fixture Folders, local and with a recorded entry, in both languages at 1440×900, 1470×956 and 390×844. These are no rendered-page CI gates (root decision 0178). + +**Addendum 2026-10-04, decided by Matěj with Anička (plan DEV-6639): the Organization +rail.** Built to the shell wireframe at `HumanAndMachine-ai/prototypes-lazurio` +1cbad15, its default navigation (`envNav = "org"`), and the design system's selection +rule at `design-system-lazurio` 5bbc1f7 (#54, variant A). Generic kind icons look the same +in every Organization and a wrong click was easy; an Organization's GitHub avatar is +recognised at a glance. So the rail switches Organizations and the head of the left +column picks the Environment. Root decision 0179 (the rail of Environments) is being +amended by the Operator to match. This supersedes, in F36 point 1, the rail's personal +Environments, Organization folders, "+N", the Environment fill in the Organization's +accent and the gear in the rail; in point 7, the three-section Apps (already two since +F32's final addendum), the column's module list and search, the status rows of tiles +and their new-tab arrows, and the Organization picker in the home's head. + +1. **Rail** (``): the Lazurio logo (the personal Dashboard), the + jump to any Environment (⌘⇧E), your personal space marked with your initials, a + divider, one GitHub avatar per Organization (the active one ringed in ink), "+" to + add an Organization in the Dashboard, and at the foot only the account, with your + GitHub photo where known. Labels show at once. A click on a space leads to the last + Environment this browser was in there, else its first, in the same app (Chat, Apps or + Automate); a space without one leads to its Dashboard. No Environment icons, folders + or colour fills, and no gear. +2. **Column head** (``): the Environment + picker (a glyph, the Environment's name, a line saying who it is for) with the gear + of this Environment's Settings right beside it, then the switch Chat · Apps · + Automate. The picker drops its list over the column: the Organization's head + (`lz-menu__head`) opening its Dashboard, then its Environments with the current one + checked as "tady jsi", and "Všechny Organizace" widening it to every space. The + panel under the head stays the app's own, which is what the forks need. +3. **Names.** A hosted Environment is never named by its machine's technical name. A + Team Environment is its Team's ("Team Sales", by the Team's display name in the + catalog), an Automated one its persona's Team, a work one "Pracovní", a personal one + "Osobní", and a workstation its computer, as the person named it (the host name + without its domain, "MacBook-Pro"; "Tento počítač" when it has none); the second line says who it is for (`@login` of a work + Environment's assigned person, "sdílený Teamem", "automatizace", "jen tvůj", + "tento počítač"). The machine's name stays the document's id and in Settings → This + Environment. +4. **Contract, changed in place.** The producer and the elements ship in one binary and + no fork consumes `lazurio.shell.v1` yet, so the shape changes without a compatibility + layer: an Environment's `label` is its own name or null, it gains `assignee`; an + Organization loses `accent` and gains `dashboard` + (`https://dashboard.lazurio.ai/orgs/`, the Dashboard's canonical + Organization slug); the operator gains `avatar`; the document gains + `addOrganization` (`https://dashboard.lazurio.ai/add-organization`). An + Organization's slug is its manifest's (any nonblank text, here at most 128 characters + without control characters), never held to the GitHub login's rule, which applies + only to `forgeLogin`. +5. **Apps column:** "Všechny moduly", "Soubory", the favourites ("Oblíbené"; a hint + while there are none) and, at the foot, "Marketplace" marked "již brzy", whose page + says it is coming. No search and no module list; a module's overview is reached from + its tile's menu. In Settings the column is their navigation with "Zpět". +6. **Apps home:** the Organization's name with, under it, the Environment you are in, + and "Guide" (the Lazurio documentation) top right. Two sections, Workspace and + Productionspace (repositories, counted as such), without subtitles. Clean tiles: + stone, name, short description, a small star when favourite. The "⋯" menu at a tile's + top right adds or removes the favourite and leads to "Informace o modulu" (the + module's overview) or, for a production repository, "Informace o repozitáři" (its + GitHub page). A click opens the module's app in a new tab as before; a module without + an app, one that cannot start and a repository only say so in a short message in the + wireframe's words. `infra` stays hidden (F32's final addendum, root #486). +7. **Favourites** belong to the person and the Organization. Until the Dashboard account + holds them they are kept in this browser's `localStorage`, one list per Organization + (`lazurio.favorites:`), never in the Folder, which a Team Environment shares + with its whole Team. They come first in their section in the column's order, and only + those this Environment's catalog has are shown. +8. **"+ Nový modul"** ends Workspace only where this Environment's GitHub identity is an + Owner of the Organization: GitHub's own, live answer (`gh api + user/memberships/orgs/`: active, role `admin`), read by the Launchpad + behind the same admission as every read (`GET /api/organizations//owner`), + bounded by a timeout, kept five minutes per login, failing closed. A Team + Environment (the Team's brokered identity) and an Organization without a bound + GitHub login get no tile, without a call. No local rule stands in for GitHub. Its + click copies the wireframe's prompt to the clipboard and opens this Environment's + Chat in a new tab, with a short message to paste it into a new chat; a workstation + has no Chat origin and only copies. Once the T3 Code fork takes a prompt draft by + link (Lazurio/t3code#35) Chat opens with it in the composer. + +**Not in this addendum, each an issue:** "Přístup k modulu" in the tile menu (the +Dashboard's `/orgs//application-access` sets a person's access level inside an +application, not which Teams reach a module's repository), remembering the last +Environment after sign-in (the Dashboard's), and Chat opening with the prompt already in +its composer (Lazurio/t3code#35). + +Verified by unit and HTTP tests: the contract and its parser, the producer's names (Team, +persona, kind, assigned person) and Dashboards, the rail's spaces and their targets in +each app, the picker's list (one space, all of them, filtered), the Apps sections without +subtitles, tile actions and the wireframe's messages, favourites first and their stored +list read defensively, the Owner answer (only an active admin, cached, a member, a +refusal and a timeout are no, no call on a Team Environment), and the admission of the +Owner route; and in Chrome against temporary fixture Folders, hosted and local, in both +languages. diff --git a/docs/launchpad-development.md b/docs/launchpad-development.md index 10c3039b2..2d4febfb2 100644 --- a/docs/launchpad-development.md +++ b/docs/launchpad-development.md @@ -169,35 +169,45 @@ was settled by F32's addenda: the read-only `repositories`; `infra` is not liste ## The shell as built (decision F36) -The first cut of the [target shell](#target-shell), DEV-6639; [decision +The [target shell](#target-shell) as built, DEV-6639: [decision F36](decisions.md#f36--the-lazurio-shell-one-library-in-the-platform-served-at-lazurioshelljs-with-lazurioshelljson-the-launchpad-is-its-first-consumer) -records what is functional and what is a facade until its source exists. +and its addendum of 2026-10-04, the Organization rail of the wireframe at +prototypes-lazurio 1cbad15. Where the target shell above still describes a rail of +Environments, folders and a gear in the rail, the addendum supersedes it. - **Library.** `src/shell/`: `contract.ts` (`lazurio.shell.v1` and its parser), - `view.ts` (the rail, the switch and the jump list as pure functions), `elements.ts` - (``, ``), `styles.ts` (the vendored tokens on - `:host`), `fonts.ts`, `index.ts` (the entry of `/.lazurio/shell.js`) and `vendor/` - (tokens, logo and fonts with their hashes). Tests: `tests/shell.test.ts`, - `tests/launchpad-shell-routes.test.ts`, `tests/apps-view.test.ts`. -- **Routes.** `/.lazurio/shell.js` and `/.lazurio/fonts/` beside the page's - routes (`src/launchpad/page.ts`); `/.lazurio/shell.json` in the server after - admission (`src/launchpad/server.ts`, producer `shell-document.ts`). -- **Page.** `index.html` is rail | column | main. The Apps column and home are - `catalog-panel.ts` over `apps-view.ts`, the frame is `shell.ts` and the switch's - pairing is in `ui.ts`. Settings, Tools, Recovery and Files keep their panels in the - new frame and look. A module's name, line and stone come from its default app's - declaration (title, description, `icon`, tags), carried by the catalog as display-only - `display`; the stone falls back by the root Launchpad's org-agnostic semantic key - (`src/shell/stones.ts`), and the Module's own manifest stays the authority. The - sections below that speak of the sidebar, its footer, the - top bar, T3 Code's colours or Chat and MausBot as sidebar links describe the build - before F36. + `view.ts` (the rail's spaces, the Environment picker's list, names and who lines, the + switch, as pure functions), `elements.ts` (``, ``), + `styles.ts` (the vendored tokens on `:host`, the design system's selection rule), + `stones.ts`, `fonts.ts`, `index.ts` (the entry of `/.lazurio/shell.js`) and `vendor/` + (tokens, logo, fonts and stones with their hashes). Tests: `tests/shell.test.ts`, + `tests/launchpad-shell-routes.test.ts`, `tests/apps-view.test.ts`, + `tests/organization-owner.test.ts`. +- **Routes.** `/.lazurio/shell.js`, `/.lazurio/fonts/` and + `/.lazurio/stones/` beside the page's routes (`src/launchpad/page.ts`); + `/.lazurio/shell.json` and `/api/organizations//owner` in the server after + admission (`src/launchpad/server.ts`, producer `shell-document.ts`, the Owner + answer `organization-owner.ts`). +- **Page.** `index.html` is rail | column | main. The Apps column (all modules, Files, + favourites, Marketplace) and home are `catalog-panel.ts` over `apps-view.ts` and + `favorites.ts`, the frame is `shell.ts`, and the switch's pairing and the new + module's hand-over to Chat are in `ui.ts`. A module's name, line and stone come from + its default app's declaration (title, description, `icon`, tags), carried by the + catalog as display-only `display`; the stone falls back by the root Launchpad's + org-agnostic semantic key, and the Module's own manifest stays the authority. + Favourites live in the browser per Organization. Settings, Tools, Recovery and Files + keep their panels. The sections below that speak of the sidebar, its footer, the top + bar, T3 Code's colours or Chat and MausBot as sidebar links describe the build before + F36. - **Preview.** A temporary fixture Folder, never a live one: `bun - scripts/preview-launchpad.ts local|hosted cs|en ` writes an Organization with root-level and workspace modules in Workspace, two production repositories in Productionspace and an `infra` that is not listed, a synthetic home for Files - and Tools, and with `hosted` a recorded entry plus a loopback proxy that adds the - gateway's Host and cookie. Screenshots come from Chrome through playwright-core. + scripts/preview-launchpad.ts local|hosted cs|en ` writes an Organization with + root-level and workspace modules in Workspace, two production repositories in + Productionspace and an `infra` that is not listed, a synthetic home for Files and + Tools whose `gh` answers the Owner question for the example Organization, and with + `hosted` a recorded entry plus a loopback proxy that adds the gateway's Host and + cookie. Screenshots come from Chrome through playwright-core. - **A fork's snippet** is in decision F36 point 5 and in the target shell's "The forks - and `/.lazurio/`". + and `/.lazurio/`": the rail, and the column head at the top of the fork's sidebar. ## Settings: structure, routes and the T3 Code pattern @@ -282,7 +292,7 @@ Escape does not leave Settings from a form field, so an unsaved note is not left behind by a stray key. T3 Code's settings search, `/` shortcut, resizable sidebar and per-row reset are not built: the page has three sections and no defaults to reset to. The General settings keep the explicit Preview → Apply of a Folder change instead of -T3 Code's immediate apply. Icons are Lucide (ISC), inlined as SVG symbols. +T3 Code's immediate apply. Icons are Iconoir (MIT), the design system's interface set, inlined as SVG symbols (Lucide before decision F36's addendum of 2026-10-04). ## Launchpad home: the catalog diff --git a/scripts/preview-launchpad.ts b/scripts/preview-launchpad.ts index e5ac77b89..9543b8380 100644 --- a/scripts/preview-launchpad.ts +++ b/scripts/preview-launchpad.ts @@ -2,9 +2,8 @@ // Folder, never a live one: `bun scripts/preview-launchpad.ts local|hosted // cs|en [port]`. One Organization with root-level and workspace modules in // Workspace, production repositories in Productionspace and an `infra` the -// Launchpad does not list (and a second Organization locally, for the -// picker), a -// synthetic home for Files and Tools. Prints one JSON line: `url` to open +// Launchpad does not list (and a second Organization locally, for the rail), +// a synthetic home for Files and Tools. Prints one JSON line: `url` to open // (local: with the fragment token) and, hosted, `proxy`: a loopback listener // that adds the gateway's Host and cookie, which a browser automation routes // the entry's origin through. Synthetic names only; stop it with Ctrl-C. @@ -25,6 +24,7 @@ import { executionOs } from "../src/folder/platform"; import { presetProfile } from "../src/folder/presets"; import { startLaunchpad } from "../src/launchpad/server"; import { toolsEnvironmentOf } from "../src/tools/overview"; +import { runTool } from "../src/tools/status"; import { writeModule, writeOrganization, @@ -134,6 +134,10 @@ if (mode === "local") // A synthetic home: the Files page shows its Documents, never the account's, // and the Tools page reads no real tool or sign-in. const home = join(parent, "home"); +await mkdir(join(home, "bin"), { recursive: true }); +await writeFile(join(home, "bin", "gh"), "#!/bin/sh\nexit 1\n", { + mode: 0o755, +}); await mkdir(join(home, "Documents", "Nabídky"), { recursive: true }); await mkdir(join(home, "Documents", "Smlouvy"), { recursive: true }); await writeFile( @@ -151,7 +155,22 @@ const app = await startLaunchpad( undefined, undefined, mode === "hosted" ? { fetcher: async () => new Response("ok") } : {}, - toolsEnvironmentOf({ PATH: "", HOME: home }, process.platform), + // The preview's GitHub identity answers the Owner question of the Apps + // home ("+ Nový modul") as an Owner of the example Organization; no real + // account is asked. + toolsEnvironmentOf( + { PATH: join(home, "bin"), HOME: home }, + process.platform, + async (command, timeoutMs, env) => + command[1] === "api" && + command[2]?.startsWith("user/memberships/orgs/example") + ? { + exitCode: 0, + stdout: JSON.stringify({ state: "active", role: "admin" }), + stderr: "", + } + : runTool(command, timeoutMs, env), + ), {}, undefined, undefined, diff --git a/src/launchpad/apps-view.ts b/src/launchpad/apps-view.ts index f67224591..b3c31e2e9 100644 --- a/src/launchpad/apps-view.ts +++ b/src/launchpad/apps-view.ts @@ -20,21 +20,27 @@ import { moduleRoute, } from "./catalog-view"; import type { PublicEntry } from "./chat"; +import { + favoritesFirst, + moduleFavorite, + repositoryFavorite, +} from "./favorites"; import { moduleOrigin } from "./hosted-entry"; import type { MessageKey } from "./messages"; import type { PageRoute } from "./routes"; type Copy = Readonly>; -// Pure presentation of the Apps home and its left column (decision F36, the -// target shell's "Apps home"): one Organization at a time, its name on top -// (a picker when the Folder holds several), its modules in the section -// Workspace and its production repositories, read-only, in the section -// Productionspace (decision F32's addendum of 2026-10-03, final), each a pill -// with a count over a grid of tiles. A tile opens the module's app in a new -// tab; a module that has no app or cannot start opens its overview; a -// production repository's tile is at most its GitHub page. The DOM lives in -// catalog-panel.ts. +// Pure presentation of the Apps home and its column (decision F36 and its +// addendum of 2026-10-04): one Organization at a time, its name on top and +// the Environment under it, its modules in the section Workspace and its +// production repositories in Productionspace (decision F32's final +// addendum), each a pill with a count over a grid of clean tiles: stone, +// name, a short description, a star when favourite. A module's tile opens its +// app in a new tab; one without an app, one that cannot start and a +// repository only say so in a short message. Its "⋯" menu stars it and leads +// to the module's overview (a repository's GitHub page). Favourites come +// first, in the column's order. The DOM lives in catalog-panel.ts. /** The groups the Apps home offers (Organizations, then the Personalspace * group), in the catalog's order. */ @@ -175,37 +181,48 @@ export function pluralKey( return keys.many; } +/** What a click on a tile does: open the module's app (hosted on its own + * origin, locally through the lifecycle), or say in a short message why + * there is nothing to open. */ +export type TileAction = + | Readonly<{ + kind: "open"; + target: Extract; + }> + | Readonly<{ kind: "say"; text: string }>; + export type AppsTile = | Readonly<{ kind: "module"; + /** Its favourite key (`m:`). */ + key: string; entry: CatalogModuleEntry; name: string; description: string; /** Its Lazurio stone (decision F36). */ stone: Readonly<{ key: StoneKey; src: string; accent: string }>; - /** The exception the tile reports, or null: status only by - * exception (the design system's `lz-status--plain`). */ - note: Readonly<{ tone: "warn"; text: string; title: string }> | null; - target: TileTarget; + action: TileAction; + /** The module's overview, from its menu ("Informace o modulu"). */ + info: string | null; + favorite: boolean; }> - /** A production repository: read-only, no status dot, no action, no - * page (F32 addendum of 2026-10-03). */ + /** A production repository: read-only, no app, no page of its own + * (decision F32's final addendum); its menu leads to its GitHub page. */ | Readonly<{ kind: "repository"; + key: string; repository: CatalogRepository; name: string; description: string; - /** "Not checked out" as plain text, or null when it is. */ - note: Readonly<{ tone: "muted"; text: string; title: string }> | null; - /** Its GitHub page, in a new tab, or null. */ - href: string | null; + action: TileAction; + info: string | null; + favorite: boolean; }>; export type AppsSection = Readonly<{ kind: CatalogSectionKind | "personal"; title: string; count: string; - subtitle: string | null; tiles: readonly AppsTile[]; }>; @@ -222,72 +239,149 @@ const countKeys = { }, } as const; -/** The sections of one group, in order, each with what it holds; empty +/** What a click on a module's tile does. */ +export function moduleAction( + target: TileTarget, + module: CatalogModule, + copy: Copy, +): TileAction { + if (target.kind === "hosted" || target.kind === "start") + return { kind: "open", target }; + return { + kind: "say", + text: (module.defaultApp === null + ? copy.appsSayNoApp + : copy.appsSayCannotStart + ).replace("{name}", moduleName(module)), + }; +} + +/** Every tile of one group, in the catalog's order: its modules, then its + * production repositories. */ +export function appsTiles( + catalog: Catalog, + group: CatalogGroupEntry, + copy: Copy, + entry: PublicEntry | null, + favorites: readonly string[], +): Readonly<{ + modules: readonly AppsTile[]; + repositories: readonly AppsTile[]; +}> { + const moduleTile = (item: CatalogModuleEntry): AppsTile => { + const target = tileTarget(catalog, group.organization, item.module, entry); + const key = moduleFavorite(item.module.module); + return { + kind: "module", + key, + entry: item, + name: moduleName(item.module), + description: moduleDescription(item.module, copy), + stone: moduleStone(item.module), + action: moduleAction(target, item.module, copy), + info: item.href, + favorite: favorites.includes(key), + }; + }; + const modules = + group.sections === null + ? group.modules + : group.sections.flatMap((section) => + section.kind === "workspace" ? section.modules : [], + ); + const repositories = + group.sections === null + ? [] + : group.sections.flatMap((section) => + section.kind === "productionspace" ? section.repositories : [], + ); + return { + modules: modules.map(moduleTile), + repositories: repositories.map(({ repository }): AppsTile => { + const key = repositoryFavorite(repository.slug); + return { + kind: "repository", + key, + repository, + name: repository.slug, + description: repository.path, + action: { + kind: "say", + text: copy.appsSayRepository.replace("{name}", repository.slug), + }, + info: repository.url, + favorite: favorites.includes(key), + }; + }), + }; +} + +/** The sections of one group, in order, favourites first in each; empty * sections are left out. The Personalspace group is one section. */ export function appsSections( catalog: Catalog, group: CatalogGroupEntry, copy: Copy, entry: PublicEntry | null, + favorites: readonly string[] = [], ): readonly AppsSection[] { - const moduleTile = (item: CatalogModuleEntry): AppsTile => ({ - kind: "module", - entry: item, - name: moduleName(item.module), - description: moduleDescription(item.module, copy), - stone: moduleStone(item.module), - // A module without an app is not one that cannot start: its tile says - // "No app" and nothing more. - note: - item.status.state === "blocked" && item.module.reason !== "no-app" - ? { tone: "warn", text: copy.appsCannotStart, title: item.status.text } - : null, - target: tileTarget(catalog, group.organization, item.module, entry), - }); - const count = (tiles: number, kind: keyof typeof countKeys) => - copy[pluralKey(tiles, countKeys[kind])].replace("{count}", String(tiles)); + const tiles = appsTiles(catalog, group, copy, entry, favorites); + const count = (length: number, kind: keyof typeof countKeys) => + copy[pluralKey(length, countKeys[kind])].replace("{count}", String(length)); if (group.sections === null) - return group.modules.length === 0 + return tiles.modules.length === 0 ? [] : [ { kind: "personal", title: copy.appsPersonal, - count: count(group.modules.length, "modules"), - subtitle: null, - tiles: group.modules.map(moduleTile), + count: count(tiles.modules.length, "modules"), + tiles: favoritesFirst(tiles.modules, favorites), }, ]; - return group.sections.map((section): AppsSection => { - if (section.kind === "workspace") - return { - kind: section.kind, - title: section.title, - count: count(section.modules.length, "modules"), - subtitle: copy.appsWorkspaceSubtitle.replace("{name}", group.name), - tiles: section.modules.map(moduleTile), - }; - return { - kind: section.kind, - title: section.title, - count: count(section.repositories.length, "repositories"), - subtitle: copy.appsProductionspaceSubtitle, - tiles: section.repositories.map( - ({ repository, checkout }): AppsTile => ({ - kind: "repository", - repository, - name: repository.slug, - description: repository.path, - note: repository.checkedOut - ? null - : { tone: "muted", text: checkout, title: checkout }, - href: repository.url, - }), - ), - }; - }); + return group.sections.map( + (section): AppsSection => + section.kind === "workspace" + ? { + kind: section.kind, + title: section.title, + count: count(tiles.modules.length, "modules"), + tiles: favoritesFirst(tiles.modules, favorites), + } + : { + kind: section.kind, + title: section.title, + count: count(tiles.repositories.length, "repositories"), + tiles: favoritesFirst(tiles.repositories, favorites), + }, + ); } -/** Whether a tile or column item matches the column's search. */ -export const appsMatch = (name: string, query: string): boolean => - name.toLocaleLowerCase().includes(query.trim().toLocaleLowerCase()); +/** The favourites of the Apps column, in their order, only those this + * Environment's catalog has. */ +export function favoriteTiles( + catalog: Catalog, + group: CatalogGroupEntry, + copy: Copy, + entry: PublicEntry | null, + favorites: readonly string[], +): readonly AppsTile[] { + const tiles = appsTiles(catalog, group, copy, entry, favorites); + return favoritesFirst( + [...tiles.modules, ...tiles.repositories], + favorites, + ).filter((tile) => tile.favorite); +} + +/** The prompt "+ Nový modul" hands to Chat (the wireframe's + * `newModulePrompt`): the agent first asks what the module is for, then + * founds it by the Lazurio Module Standard with the scaffold, never by + * hand, and hands it over as a pull request. */ +export const newModulePrompt = ( + name: string, + login: string, + copy: Copy, +): string => + copy.appsNewModulePrompt + .replaceAll("{name}", name) + .replaceAll("{login}", login); diff --git a/src/launchpad/catalog-panel.ts b/src/launchpad/catalog-panel.ts index 5b27d5201..5a3dc186f 100644 --- a/src/launchpad/catalog-panel.ts +++ b/src/launchpad/catalog-panel.ts @@ -9,13 +9,14 @@ import { initialsOf } from "../shell/view"; import { type AppsSection, type AppsTile, - appsMatch, appsScope, appsScopes, appsSections, + favoriteTiles, moduleDescription, moduleName, moduleStone, + newModulePrompt, type TileTarget, tileTarget, } from "./apps-view"; @@ -32,6 +33,7 @@ import { routeOrganization, } from "./catalog-view"; import type { PublicEntry } from "./chat"; +import { favoritesKey, parseFavorites, toggleFavorite } from "./favorites"; import type { MessageKey } from "./messages"; import { moduleLink, @@ -40,27 +42,36 @@ import { moduleStatusView, parseModuleResult, } from "./module-view"; +import { createOwnerAnswers } from "./owner-answer"; import type { PageRoute } from "./routes"; type Copy = Readonly>; -// The Apps home of the Lazurio shell (decision F36; the target shell's "Apps -// home"): the left column lists one Organization's modules under the section -// Workspace and its production repositories, read-only, under the section -// Productionspace (F32 addendum of 2026-10-03, final), with a search; the -// main view shows that -// Organization's name on top (a picker when the Folder holds several) and -// the same sections as pills with counts over grids of tiles. A tile opens -// the module's app in a new tab: hosted on the module's own origin, where the -// gateway starts it; locally through the lifecycle (start, then open the link -// it reports). A module with no app, or one that cannot start, opens its -// overview, and so does choosing it in the column. The overview carries the -// module lifecycle (slice P5): the status of its app with a dot, the one -// primary action (Start or Stop) and Open while the app reports a link, over -// `/api/modules///…`, the same core as `lazurio module`. A -// production repository has no dot, no action and no page: its tile is its -// GitHub page when known, else plain text. Teams are shown nowhere (decision -// F32). Every value from the server is drawn with textContent. +/** The current Environment as the Apps home names it under the + * Organization: its name by what it is for and its kind's icon. */ +export type HomeEnvironment = Readonly<{ + name: string; + icon: "laptop" | "user" | "users" | "bot"; +}>; + +// The Apps home of the Lazurio shell (decision F36 and its addendum of +// 2026-10-04): the left column holds "Všechny moduly", "Soubory", your +// favourite modules and, at its foot, the Marketplace; no module list and no +// search. The main view names the Organization and, under it, the +// Environment, then the sections Workspace (every module) and +// Productionspace (production repositories, read-only, decision F32's final +// addendum) as pills with counts over grids of clean tiles: stone, name, a +// short description, a star when favourite. A tile opens the module's app in +// a new tab: hosted on the module's own origin, where the gateway starts it; +// locally through the lifecycle (start, then open the link it reports). A +// module without an app, one that cannot start and a repository only say so +// in a short message. The "⋯" menu at a tile's top right stars it and leads +// to the module's overview (a repository's GitHub page), which carries the +// module lifecycle (slice P5) over `/api/modules///…`, the same +// core as `lazurio module`. Where this Environment's GitHub identity is an +// Owner of the Organization, Workspace ends with "+ Nový modul". Teams are +// shown nowhere (decision F32). Every value from the server is drawn with +// textContent. export function createCatalogPanel( options: Readonly<{ post: ( @@ -80,6 +91,15 @@ export function createCatalogPanel( entry: () => PublicEntry | null; /** The avatar of an Organization slug, as the shell document names it. */ avatar: (slug: string) => string | null; + /** The current Environment's name and icon, once the shell document is + * read. */ + environment: () => HomeEnvironment | null; + /** The Organization (or `personal`) the Apps home now shows: the shell + * marks it as the space you are in. */ + space: (space: string) => void; + /** "+ Nový modul": hands the prepared prompt to Chat; resolves to + * whether it reached the clipboard. */ + newModule: (prompt: string) => Promise; }>, ) { const find = (selector: string): T => { @@ -87,19 +107,23 @@ export function createCatalogPanel( if (!element) throw new Error("Missing catalog UI"); return element; }; - const tree = find("#catalog-tree"); const home = find("#catalog-home"); - const search = find("#catalog-search"); + const favoritesBox = find("#catalog-favorites"); const head = find("#catalog-head"); const headName = find("#catalog-head-name"); const body = find("#catalog-body"); const status = find("#catalog-status"); - const refreshButton = find("#catalog-refresh"); + const toastRegion = find("#toast"); let catalog: Catalog | null = null; let state: "loading" | "loaded" | "failed" = "loading"; // A sentence about the last tile opened on a workstation (starting, // failed), shown in the status line until the next move. let notice: string | null = null; + // Whether this Environment's GitHub identity is an Owner of an + // Organization, by its route key: read once per page, never assumed. + // The Owner answers this page holds (owner-answer.ts); a catalog read + // drops them all. + const owners = createOwnerAnswers(); // The lifecycle of the module the page shows: its last status, the // sentence after the last action, and whether a request is under way. // Nothing of it is kept beyond the page; the service manager is the truth. @@ -152,7 +176,7 @@ export function createCatalogPanel( return line; }; // An Organization's mark: its GitHub avatar, or its initials when there - // is none or it does not load. + // is none or it does not load; the Personalspace group's is round. const orgMark = (group: CatalogGroupEntry, className: string) => { const mark = element("span", className); const initials = () => mark.replaceChildren(initialsOf(group.name)); @@ -183,10 +207,14 @@ export function createCatalogPanel( image.setAttribute("aria-hidden", "true"); return image; }; - const tileMark = (stone: Readonly<{ src: string }> | null) => { - if (stone !== null) return stoneImage(stone.src, 48, "tile-stone"); - const mark = element("span", "tile-mark"); - mark.dataset.kind = "repository"; + const tileMark = (tile: AppsTile, size: number) => { + if (tile.kind === "module") + return stoneImage( + tile.stone.src, + size, + size > 24 ? "tile-stone" : "menu-stone", + ); + const mark = element("span", size > 24 ? "tile-mark" : "menu-mark"); mark.append(svg("folder")); mark.setAttribute("aria-hidden", "true"); return mark; @@ -195,6 +223,40 @@ export function createCatalogPanel( group === null || group === appsScopes(value, options.copy())[0] ? "/" : (organizationRoute(value, group.organization) ?? "/"); + // The favourites of one group live per Organization in this browser + // (favorites.ts): never in the Folder, which a Team Environment shares. + const scopeKey = (group: CatalogGroupEntry) => + group.sections === null + ? "personalspace" + : (group.organization.organization ?? group.organization.directory); + const favoritesOf = (group: CatalogGroupEntry): readonly string[] => { + try { + return parseFavorites( + localStorage.getItem(favoritesKey(scopeKey(group))), + ); + } catch { + return []; + } + }; + const toggle = (group: CatalogGroupEntry, key: string) => { + try { + localStorage.setItem( + favoritesKey(scopeKey(group)), + JSON.stringify(toggleFavorite(favoritesOf(group), key)), + ); + } catch {} + render(); + }; + + // --- A short message at the foot of the page (the wireframe's toast) -- + let toastTimer: ReturnType | undefined; + function say(text: string) { + clearTimeout(toastTimer); + const toast = element("div", "toast"); + toast.append(svg("info"), text); + toastRegion.replaceChildren(toast); + toastTimer = setTimeout(() => toastRegion.replaceChildren(), 3500); + } // --- Opening a module's app ------------------------------------------- @@ -245,19 +307,15 @@ export function createCatalogPanel( options.navigate(target.overview); } - // The tile's or the overview button's link for a target. - function targetLink( - target: TileTarget, + // A link that opens a module's app in a new tab: the module's own origin + // hosted; locally a plain click starts it first (without the script the + // link is the overview). + function openLink( + target: Extract, name: string, className: string, - ): HTMLElement { + ): HTMLAnchorElement { const copy = options.copy(); - if (target.kind === "none") return element("div", className); - if (target.kind === "overview") { - const link = routeLink(target.href, className); - link.title = copy.appsOverviewNamed.replace("{name}", name); - return link; - } const link = element("a", className); link.title = copy.appsOpenAppNamed.replace("{name}", name); if (target.kind === "hosted") { @@ -266,7 +324,6 @@ export function createCatalogPanel( link.rel = "noopener noreferrer"; return link; } - // Without the script it is the overview; with it, a plain click starts. link.href = target.overview; link.dataset.route = ""; link.addEventListener("click", (event) => { @@ -285,104 +342,290 @@ export function createCatalogPanel( return link; } - function tile(item: AppsTile): HTMLElement { + // What a tile, or a favourite in the column, is: a link that opens the + // app, or a button that says why there is nothing to open. + function actionNode(item: AppsTile, className: string): HTMLElement { + if (item.action.kind === "open") + return openLink(item.action.target, item.name, className); + const text = item.action.text; + const button = element("button", `${className} is-button`); + button.type = "button"; + button.addEventListener("click", () => say(text)); + return button; + } + + // --- The "⋯" menu of a tile ------------------------------------------- + + let openMenu: (() => void) | null = null; + document.addEventListener("click", (event) => { + if (openMenu === null) return; + const target = event.target; + if (target instanceof Element && target.closest(".tile-menu")) return; + openMenu(); + }); + document.addEventListener("keydown", (event) => { + if (event.key === "Escape" && openMenu !== null) { + event.preventDefault(); + openMenu(); + } + }); + + function tileMenu(item: AppsTile, group: CatalogGroupEntry): HTMLElement { const copy = options.copy(); - let node: HTMLElement; - if (item.kind === "module") - node = targetLink(item.target, item.name, "tile"); - else if (item.href !== null) { - const link = element("a", "tile"); - link.href = item.href; - link.target = "_blank"; - link.rel = "noopener noreferrer"; - link.title = copy.appsRepositoryNamed.replace("{name}", item.name); - node = link; - } else node = element("div", "tile"); - node.dataset.kind = item.kind; - const text = element("span", "tile-body"); - text.append( - element("span", "tile-name", item.name), - element("span", "tile-desc", item.description), + const box = element("div", "tile-menu"); + const button = element("button", "tile-menu-button"); + button.type = "button"; + button.setAttribute("aria-haspopup", "menu"); + button.setAttribute("aria-expanded", "false"); + button.setAttribute( + "aria-label", + copy.appsMore.replace("{name}", item.name), + ); + button.append(svg("more")); + const list = element("div", "tile-menu-list"); + list.setAttribute("role", "menu"); + list.hidden = true; + const close = () => { + list.hidden = true; + box.classList.remove("is-open"); + button.setAttribute("aria-expanded", "false"); + openMenu = null; + }; + const star = element("button", "tile-menu-item"); + star.type = "button"; + star.setAttribute("role", "menuitem"); + if (item.favorite) star.classList.add("is-favorite"); + star.append( + svg(item.favorite ? "star-filled" : "star"), + item.favorite ? copy.appsFavoriteRemove : copy.appsFavoriteAdd, ); - if (item.note !== null) { - const note = element("span", "tile-note", item.note.text); - note.dataset.tone = item.note.tone; - note.title = item.note.title; - // A status dot only on a module: a production repository has none. - if (item.kind === "module") note.prepend(dot("blocked-warn")); - text.append(note); + star.addEventListener("click", () => { + close(); + toggle(group, item.key); + }); + list.append(star); + if (item.info !== null) { + const info = + item.kind === "module" + ? routeLink(item.info, "tile-menu-item") + : element("a", "tile-menu-item"); + if (item.kind === "repository") { + info.href = item.info; + info.target = "_blank"; + info.rel = "noopener noreferrer"; + } + info.setAttribute("role", "menuitem"); + info.append( + svg("info"), + item.kind === "module" ? copy.appsInfoModule : copy.appsInfoRepository, + ); + info.addEventListener("click", close); + list.append(info); } - node.append(tileMark(item.kind === "module" ? item.stone : null), text); + button.addEventListener("click", (event) => { + event.stopPropagation(); + if (!list.hidden) { + close(); + return; + } + openMenu?.(); + list.hidden = false; + box.classList.add("is-open"); + button.setAttribute("aria-expanded", "true"); + openMenu = close; + list.querySelector(".tile-menu-item")?.focus(); + }); + box.append(button, list); + return box; + } + + function tile(item: AppsTile, group: CatalogGroupEntry): HTMLElement { + const copy = options.copy(); + const wrap = element("div", "tile-wrap"); + const node = actionNode(item, "tile"); + node.dataset.kind = item.kind; if (item.kind === "module") node.style.setProperty("--stone-accent", item.stone.accent); - const opensTab = - (item.kind === "module" && - (item.target.kind === "hosted" || item.target.kind === "start")) || - (item.kind === "repository" && item.href !== null); - if (opensTab) node.append(svg("external", "icon tile-open")); - return node; + const name = element("span", "tile-name", item.name); + if (item.favorite) { + const star = element("span", "tile-star"); + star.title = copy.appsFavoriteMark; + star.append( + svg("star-filled"), + element("span", "sr-only", copy.appsFavoriteMark), + ); + name.append(star); + } + const text = element("span", "tile-body"); + text.append(name, element("span", "tile-desc", item.description)); + node.append(tileMark(item, 48), text); + wrap.append(node, tileMenu(item, group)); + return wrap; } - function section(value: AppsSection): HTMLElement { + // "+ Nový modul" (2026-10-04): the last tile of Workspace, only where this + // Environment's GitHub identity is an Owner of the Organization. It hands + // the wireframe's prompt to Chat: until the T3 Code fork takes a prompt + // draft by link (Lazurio/t3code#35, issue #153) the prompt goes to the clipboard and + // Chat opens, where the person pastes it into a new chat. + function newModuleTile(group: CatalogGroupEntry): HTMLElement { + const copy = options.copy(); + const button = element("button", "tile tile--new is-button"); + button.type = "button"; + const mark = element("span", "tile-mark tile-mark--new"); + mark.append(svg("plus")); + const text = element("span", "tile-body"); + text.append( + element("span", "tile-name", copy.appsNewModule), + element("span", "tile-desc", copy.appsNewModuleSub), + ); + button.append(mark, text); + const login = group.organization.forgeLogin; + button.addEventListener("click", async () => { + if (login === undefined) return; + const copied = await options.newModule( + newModulePrompt(group.name, login, copy), + ); + say(copied ? copy.appsNewModuleCopied : copy.appsNewModuleCopyFailed); + }); + return button; + } + + // Whether this Environment may found modules in an Organization: GitHub's + // own answer through the Launchpad, fail closed, asked again once it is + // older than the server's cache or the bound login changed. + function ownerOf(value: Catalog, group: CatalogGroupEntry): boolean { + const login = group.organization.forgeLogin; + if (group.sections === null || login === undefined) return false; + const organization = catalogOrganizationKey(value, group.organization); + if (organization === null) return false; + const { owner, ask } = owners.read(organization, login); + if (ask !== null) + void options + .get(`/api/organizations/${encodeURIComponent(organization)}/owner`) + .then(({ value: answer, ok }) => + owners.settle( + organization, + login, + ask, + ok && + !!answer && + typeof answer === "object" && + (answer as { owner?: unknown }).owner === true, + ), + ) + .catch(() => owners.settle(organization, login, ask, false)) + .finally(() => { + wakeForOwners(); + render(); + }); + return owner; + } + + // Wakes the page when the earliest Owner answer expires, so that a shown + // "+ Nový modul" is asked again without any navigation. + let ownerWake: ReturnType | undefined; + function wakeForOwners() { + clearTimeout(ownerWake); + const next = owners.nextExpiry(); + if (next === null) return; + ownerWake = setTimeout( + () => { + render(); + wakeForOwners(); + }, + Math.max(1000, next - Date.now()), + ); + } + + function section( + value: AppsSection, + group: CatalogGroupEntry, + owner: boolean, + ): HTMLElement { const part = element("section", "apps-section"); part.dataset.section = value.kind; const top = element("div", "section-head"); const title = element("h2", "section-pill", value.title); top.append(title, element("span", "section-count", value.count)); - part.append(top); - if (value.subtitle !== null) - part.append(element("p", "section-subtitle", value.subtitle)); const grid = element("div", "tile-grid"); - grid.append(...value.tiles.map(tile)); - part.append(grid); + grid.append(...value.tiles.map((item) => tile(item, group))); + if (value.kind === "workspace" && owner) grid.append(newModuleTile(group)); + part.append(top, grid); return part; } - // --- The head: the Organization's name, or a picker ------------------- + // --- The column: favourites ------------------------------------------- - function drawHead(value: Catalog, group: CatalogGroupEntry | null) { + function drawFavorites(value: Catalog, group: CatalogGroupEntry | null) { const copy = options.copy(); - const groups = appsScopes(value, copy); if (group === null) { - const heading = element("h1", "apps-title", copy.homeTitle); - heading.tabIndex = -1; - heading.dataset.pageHeading = ""; - headName.replaceChildren(heading); + favoritesBox.replaceChildren(); return; } - const heading = element("h1", "apps-title", group.name); - heading.tabIndex = -1; - heading.dataset.pageHeading = ""; - if (groups.length < 2) { - headName.replaceChildren(orgMark(group, "org-mark"), heading); + const label = element("p", "column-label", copy.appsFavorites); + label.id = "column-favorites"; + const items = favoriteTiles( + value, + group, + copy, + options.entry(), + favoritesOf(group), + ); + if (items.length === 0) { + favoritesBox.replaceChildren( + label, + element("p", "column-hint", copy.appsFavoritesHint), + ); return; } - // Several Organizations in this Folder: the name opens a list of them. - const picker = element("details", "org-picker"); - const summary = element("summary"); - summary.setAttribute( - "aria-label", - `${group.name}, ${copy.appsOrganizationPick}`, - ); - summary.append(heading, svg("chevron-down", "icon org-picker-chevron")); - const list = element("ul", "org-picker-list"); + const list = element("ul", "menu"); + list.setAttribute("aria-labelledby", label.id); list.append( - ...groups.map((entry) => { - const item = element("li"); - const href = scopeRoute(value, entry); - const link = routeLink(href, "org-picker-item"); + ...items.map((item) => { + const entry = element("li"); + // A favourite opens the app straight away, like its tile. + const link = actionNode(item, "menu-item"); link.append( - orgMark(entry, "org-mark small"), - element("span", "", entry.name), + tileMark(item, 20), + element("span", "menu-name", item.name), ); - if (entry === group) link.setAttribute("aria-current", "true"); - link.addEventListener("click", () => picker.removeAttribute("open")); - item.append(link); - return item; + if (item.action.kind === "open") + link.append(svg("external", "icon menu-external")); + entry.append(link); + return entry; }), ); - picker.append(summary, list); - headName.replaceChildren(orgMark(group, "org-mark"), picker); + favoritesBox.replaceChildren(label, list); + } + + // --- The head: the Organization, and the Environment under it --------- + + function drawHead(group: CatalogGroupEntry | null) { + const copy = options.copy(); + const heading = element( + "h1", + "apps-title", + group === null + ? copy.homeTitle + : group.sections === null + ? copy.appsPersonal + : group.name, + ); + heading.tabIndex = -1; + heading.dataset.pageHeading = ""; + const where = element("div", "apps-where"); + where.append(heading); + const environment = options.environment(); + if (environment !== null) { + const line = element("span", "apps-environment"); + line.append(svg(environment.icon), environment.name); + where.append(line); + } + headName.replaceChildren( + ...(group === null ? [] : [orgMark(group, "org-mark")]), + where, + ); } // --- The main views ----------------------------------------------------- @@ -396,10 +639,17 @@ export function createCatalogPanel( group.organization.reason !== undefined ) parts.push(statusLine(group.status)); - const sections = appsSections(value, group, copy, options.entry()); + const sections = appsSections( + value, + group, + copy, + options.entry(), + favoritesOf(group), + ); + const owner = ownerOf(value, group); if (sections.length === 0 && group.organization.reason === undefined) parts.push(element("p", "intro", copy.catalogNoModules)); - parts.push(...sections.map(section)); + parts.push(...sections.map((part) => section(part, group, owner))); return parts; } @@ -480,7 +730,7 @@ export function createCatalogPanel( top.append(stoneImage(moduleStone(module).src, 64, "module-stone"), text); const target = tileTarget(value, organization, module, options.entry()); if (target.kind === "hosted" || target.kind === "start") { - const open = targetLink( + const open = openLink( target, moduleName(module), "button primary module-open", @@ -658,98 +908,10 @@ export function createCatalogPanel( // --- The left column ---------------------------------------------------- - // One Organization's modules and production repositories in the column, - // under the section labels Workspace and Productionspace, filtered by the - // search; the current module is marked. - function drawTree( - value: Catalog, - scope: CatalogGroupEntry | null, - route: PageRoute, - ) { - const copy = options.copy(); - const query = search.value; - const selection = catalogSelection(value, route); - if (scope === null) { - tree.replaceChildren(); - return; - } - tree.setAttribute( - "aria-label", - copy.appsColumn.replace("{name}", scope.name), - ); - const sections = appsSections(value, scope, copy, options.entry()); - const parts = sections.flatMap((part) => { - const items = part.tiles.filter((item) => appsMatch(item.name, query)); - if (items.length === 0) return []; - const box = element("div", "column-group"); - box.dataset.section = part.kind; - const label = element("p", "column-label", part.title); - label.id = `column-${part.kind}`; - const list = element("ul", "menu"); - list.setAttribute("aria-labelledby", label.id); - list.append( - ...items.map((item) => { - const entry = element("li"); - let link: HTMLElement; - if (item.kind === "module") { - link = - item.entry.href === null - ? element("span", "menu-item") - : routeLink(item.entry.href, "menu-item"); - if ( - selection.kind === "module" && - selection.module === item.entry.module - ) - link.setAttribute("aria-current", "page"); - } else if (item.href !== null) { - const anchor = element("a", "menu-item"); - anchor.href = item.href; - anchor.target = "_blank"; - anchor.rel = "noopener noreferrer"; - anchor.title = copy.appsRepositoryNamed.replace( - "{name}", - item.name, - ); - link = anchor; - } else link = element("span", "menu-item"); - let mark: HTMLElement; - if (item.kind === "module") - mark = stoneImage(item.stone.src, 20, "menu-stone"); - else { - mark = element("span", "menu-mark"); - mark.dataset.kind = "repository"; - mark.append(svg("folder")); - } - link.append(mark, element("span", "menu-name", item.name)); - if (item.note !== null) { - // A status dot only on a module: a production repository has - // none, its state is said in words. - if (item.kind === "module") { - const tail = dot("blocked-warn"); - tail.classList.add("menu-tail"); - link.append(tail); - } - link.append(element("span", "sr-only", `, ${item.note.text}`)); - } - entry.append(link); - return entry; - }), - ); - box.append(label, list); - return [box]; - }); - tree.replaceChildren( - ...(parts.length === 0 && query.trim() !== "" - ? [element("p", "column-empty", copy.appsNoMatch)] - : parts), - ); - } - /** Draws the route now shown from the catalog last read. */ function render(route: PageRoute = options.route()) { const copy = options.copy(); - search.placeholder = copy.appsSearch; - search.setAttribute("aria-label", copy.appsSearchLabel); + openMenu?.(); status.textContent = notice ?? (state === "loading" @@ -758,13 +920,20 @@ export function createCatalogPanel( ? copy.catalogLoadFailed : ""); if (catalog === null) { - tree.replaceChildren(); + favoritesBox.replaceChildren(); body.replaceChildren(); - drawHeadless(); + drawHead(null); + head.hidden = false; return; } const scope = appsScope(catalog, route, copy); const selection = catalogSelection(catalog, route); + if (scope !== null) + options.space( + scope.sections === null + ? "personal" + : (scope.organization.organization ?? "personal"), + ); home.href = scopeRoute(catalog, scope); if ( (route.view === "home" || route.view === "organization") && @@ -772,7 +941,7 @@ export function createCatalogPanel( ) home.setAttribute("aria-current", "page"); else home.removeAttribute("aria-current"); - drawTree(catalog, scope, route); + drawFavorites(catalog, scope); if ( route.view !== "home" && route.view !== "organization" && @@ -781,7 +950,7 @@ export function createCatalogPanel( return; if (selection.kind === "missing") { head.hidden = false; - drawHead(catalog, null); + drawHead(null); const missing = element("p", "callout"); missing.append( copy.catalogNotFound, @@ -798,7 +967,7 @@ export function createCatalogPanel( document.activeElement.dataset.moduleAction !== undefined; if (selection.kind !== "module") lifecycle = null; head.hidden = selection.kind === "module"; - if (selection.kind !== "module") drawHead(catalog, scope); + if (selection.kind !== "module") drawHead(scope); body.replaceChildren( ...(selection.kind === "ambiguous" ? ambiguousView(catalog, selection.candidates) @@ -815,18 +984,10 @@ export function createCatalogPanel( } } - // Before the catalog is read: the head names the Launchpad. - function drawHeadless() { - const heading = element("h1", "apps-title", options.copy().homeTitle); - heading.tabIndex = -1; - heading.dataset.pageHeading = ""; - headName.replaceChildren(heading); - head.hidden = false; - } - - /** Reads the catalog again (on load, Refresh and a language change). */ + /** Reads the catalog again (on load, on the way back to "Všechny moduly" + * and on a language change). */ async function refresh() { - refreshButton.disabled = true; + owners.clear(); state = catalog === null ? "loading" : state; render(); try { @@ -838,13 +999,10 @@ export function createCatalogPanel( } catch { state = "failed"; } finally { - refreshButton.disabled = false; render(); options.loaded(); } } - refreshButton.addEventListener("click", () => void refresh()); - search.addEventListener("input", () => render()); return { render(route?: PageRoute) { @@ -862,5 +1020,11 @@ export function createCatalogPanel( ? undefined : organizationName(organization); }, + /** The Organization a route shows, for the Marketplace's sentence. */ + scopeName(route: PageRoute): string | null { + if (catalog === null) return null; + const scope = appsScope(catalog, route, options.copy()); + return scope === null || scope.sections === null ? null : scope.name; + }, }; } diff --git a/src/launchpad/catalog-view.ts b/src/launchpad/catalog-view.ts index 800e6a687..149c88e9d 100644 --- a/src/launchpad/catalog-view.ts +++ b/src/launchpad/catalog-view.ts @@ -149,7 +149,8 @@ export function catalogSelection( if ( route.view === "home" || route.view === "settings" || - route.view === "files" + route.view === "files" || + route.view === "marketplace" ) return { kind: "overview" }; const selection = selectCatalogOrganization(catalog, route.organization); diff --git a/src/launchpad/favorites.ts b/src/launchpad/favorites.ts new file mode 100644 index 000000000..68605479d --- /dev/null +++ b/src/launchpad/favorites.ts @@ -0,0 +1,62 @@ +// Favourite modules and repositories (decision F36 addendum of 2026-10-04, +// Anička 2026-10-03): starred from a tile's "⋯" menu, listed in the Apps +// column under "Všechny moduly" and "Soubory" and first in their section of +// the Apps home, in the column's order. They belong to the person and the +// Organization; until the Dashboard account holds them they live in this +// browser's `localStorage`, one list per Organization. Never in the Folder: +// on a Team Environment that would share one person's favourites with the +// whole Team. An Environment shows only those its catalog has. Pure but for +// the storage passed in. + +/** A favourite: a module (`m:`) or a production repository + * (`r:`), so the two never collide. */ +export const moduleFavorite = (id: string): string => `m:${id}`; +export const repositoryFavorite = (slug: string): string => `r:${slug}`; + +/** The storage key of one Organization's list (the Personalspace group is + * `personalspace`); slugs are compared case-insensitively. */ +export const favoritesKey = (scope: string): string => + `lazurio.favorites:${scope.toLowerCase()}`; + +const entry = /^[mr]:[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/; + +/** A stored list, read defensively: anything that is not a list of + * favourites is none; duplicates keep their first place; at most 200. */ +export function parseFavorites(raw: string | null): readonly string[] { + if (raw === null) return []; + let value: unknown; + try { + value = JSON.parse(raw); + } catch { + return []; + } + if (!Array.isArray(value)) return []; + return [ + ...new Set( + value.filter( + (item): item is string => typeof item === "string" && entry.test(item), + ), + ), + ].slice(0, 200); +} + +/** The list with `favorite` added at its end, or removed. */ +export const toggleFavorite = ( + list: readonly string[], + favorite: string, +): readonly string[] => + list.includes(favorite) + ? list.filter((item) => item !== favorite) + : [...list, favorite]; + +/** Favourites first, in the list's order, then the rest in their own. */ +export function favoritesFirst>( + items: readonly T[], + list: readonly string[], +): readonly T[] { + const starred = list.flatMap((key) => { + const found = items.find((item) => item.key === key); + return found === undefined ? [] : [found]; + }); + return [...starred, ...items.filter((item) => !list.includes(item.key))]; +} diff --git a/src/launchpad/index.html b/src/launchpad/index.html index 62456bb90..c5c04ec48 100644 --- a/src/launchpad/index.html +++ b/src/launchpad/index.html @@ -3,16 +3,16 @@ Lazurio Launchpad - + - - + +
@@ -453,16 +483,24 @@

Product updat

-
-
+
Guide

Reading Organizations…

+ +
+

Marketplace

Coming soon

+

+
+
@@ -534,6 +572,7 @@

Product updat +

diff --git a/src/launchpad/messages.ts b/src/launchpad/messages.ts index 0473117c6..8f205a490 100644 --- a/src/launchpad/messages.ts +++ b/src/launchpad/messages.ts @@ -364,13 +364,9 @@ const en = { toolsMcpPromptHint: "Copy this prompt and paste it into a new chat in T3 Code in this Environment. The agent asks which app you want, sets the server up and lets you sign in in your browser. You never copy an API key.", // The Apps home and its left column (decision F36). + appsTitle: "Apps", appsAll: "All modules", - appsSearch: "Search", - appsSearchLabel: "Search modules", appsPersonal: "Personal", - appsWorkspaceSubtitle: "{name} Workspace", - appsProductionspaceSubtitle: - "The Organization's repositories with their own release, read-only", appsModulesOne: "{count} module", appsModulesFew: "{count} modules", appsModulesMany: "{count} modules", @@ -379,21 +375,13 @@ const en = { appsRepositoriesMany: "{count} repositories", appsOpenApp: "Open app", appsOpenAppNamed: "Open the app of {name} in a new tab", - appsOverviewNamed: "Overview of the module {name}", - appsCannotStart: "Cannot start", appsNoApp: "No app", - appsRunning: "running", - appsRepositoryNamed: "The repository {name} on GitHub, in a new tab", - appsOrganizationPick: "Choose an Organization", appsAbout: "About the module", - appsFolder: "Folder", appsLog: "App log", appsLogHint: "The Launchpad does not show the log yet. Its last lines are read on the command line of this Environment:", appsStarting: "Starting {name}…", appsStartFailed: "{name} could not be opened. Its overview says why.", - appsNoMatch: "No module matches.", - appsColumn: "Modules of {name}", // The org-agnostic description of a module by its stone's semantic key, // when its app declares none (decision F36; the root Launchpad's // `description.`). @@ -419,13 +407,38 @@ const en = { appsDescriptionSystem: "Operations tools and technical infrastructure.", appsDescriptionDefault: "An application for day-to-day work in the {module} module.", + // The Apps home and column of the Organization rail (decision F36 + // addendum of 2026-10-04): the wireframe's words. + appsSayNoApp: "The module {name} has no app yet.", + appsSayCannotStart: "The app of the module {name} cannot start right now.", + appsSayRepository: "The repository {name} has no app.", + appsMore: "More options for {name}", + appsFavorites: "Favourites", + appsFavoritesHint: "Star a module to pin it here.", + appsFavoriteAdd: "Add to favourites", + appsFavoriteRemove: "Remove from favourites", + appsFavoriteMark: "In favourites", + appsInfoModule: "Module information", + appsInfoRepository: "Repository information", + appsNewModule: "New module", + appsNewModuleSub: "You found it with an agent in Chat", + appsNewModuleCopied: + "The new module's brief is in your clipboard: paste it into a new chat.", + appsNewModuleCopyFailed: + "The brief could not be copied; open Chat and describe the new module to the agent.", + appsNewModulePrompt: + "I want to found a new module in the Organization {name} (GitHub {login}).\n\nBefore you create anything, ask me one question at a time:\n1. What the module is for and who will use it.\n2. What it should be called (a name and a short slug).\n3. Whether it should have an app and which (vite-react, astro, astro-starlight, bun-service, python-uv), or none.\n4. Which Teams should have access to it.\n\nThen follow the Lazurio Module Standard (skill lazurio-module-standard):\n- found the module with the scaffold `lazurio module create {login}/ --stack --teams ` from a task worktree of the Organization's root, never by hand, and first show me the plan with --dry-run;\n- check that the module's repository exists on GitHub in the Organization {login} and that the chosen Teams have access to it;\n- prepare the result as a pull request and ask me before Publication.", + appsGuide: "Guide", + appsMarketplace: "Marketplace", + appsSoon: "coming soon", + appsMarketplaceSoon: "Coming soon", + appsMarketplaceText: + "This is where you will add more modules to the Environment. We are preparing it.", + appsMarketplaceOrganization: + " Until then, modules are added in the Dashboard of the Organization {name}.", title: "Lazurio Launchpad", homeTitle: "Launchpad", - catalogNavigation: "Organizations", catalogBreadcrumb: "Where you are in the Launchpad", - catalogIntro: - "The Organizations and modules of this Folder, read from its organizations/ directory each time. A module's page starts, stops and opens its app.", - catalogRefresh: "Refresh", catalogLoading: "Reading Organizations…", catalogLoadFailed: "The Organizations could not be read. Try Refresh; if it keeps failing, run lazurio organization list in the CLI.", @@ -433,11 +446,8 @@ const en = { "No Organizations in this Folder. An Organization appears here once its repository is in organizations/.", catalogNotFound: "This Organization or module is not in this Folder. It may have been renamed or removed; see all Organizations.", - catalogAll: "All Organizations", chat: "Chat", - chatTitle: "Open T3 Code in this Environment", mausbot: "Lazurio MausBot", - mausbotTitle: "Open Lazurio MausBot in this Environment", catalogModules: "Modules", catalogNoModules: "This Organization declares no modules.", catalogSectionWorkspace: "Workspace", @@ -449,7 +459,6 @@ const en = { catalogState: "Resolution state", catalogIssues: "Issues", catalogApps: "Apps", - catalogDefaultApp: "Default app", catalogDefaultMark: "default", catalogPath: "Path", catalogStatus: "Can it run", @@ -1075,13 +1084,9 @@ const cs: Record = { toolsMcpPromptHint: "Zkopírujte tenhle prompt a vložte ho do nového chatu v T3 Code na tomhle Environmentu. Agent se zeptá, kterou aplikaci chcete, server nastaví a přihlášení necháte proběhnout ve svém prohlížeči. Žádný API klíč nikdy nekopírujete.", // The Apps home and its left column (decision F36). + appsTitle: "Apps", appsAll: "Všechny moduly", - appsSearch: "Hledat", - appsSearchLabel: "Hledat moduly", appsPersonal: "Osobní", - appsWorkspaceSubtitle: "{name} Workspace", - appsProductionspaceSubtitle: - "Repozitáře Organizace s vlastním releasem, jen pro čtení", appsModulesOne: "{count} modul", appsModulesFew: "{count} moduly", appsModulesMany: "{count} modulů", @@ -1090,21 +1095,13 @@ const cs: Record = { appsRepositoriesMany: "{count} repozitářů", appsOpenApp: "Otevřít aplikaci", appsOpenAppNamed: "Otevřít aplikaci modulu {name} v nové záložce", - appsOverviewNamed: "Přehled modulu {name}", - appsCannotStart: "Nelze spustit", appsNoApp: "Bez aplikace", - appsRunning: "běží", - appsRepositoryNamed: "Repozitář {name} na GitHubu v nové záložce", - appsOrganizationPick: "Vybrat Organizaci", appsAbout: "O modulu", - appsFolder: "Složka", appsLog: "Log aplikace", appsLogHint: "Launchpad log zatím neukazuje. Jeho poslední řádky přečteš v příkazové řádce tohoto Environmentu:", appsStarting: "Spouštím {name}…", appsStartFailed: "{name} se nepodařilo otevřít. Proč, říká přehled modulu.", - appsNoMatch: "Žádný modul neodpovídá.", - appsColumn: "Moduly {name}", // The org-agnostic description of a module by its stone's semantic key, // when its app declares none (decision F36; the root Launchpad's // `description.`). @@ -1129,13 +1126,38 @@ const cs: Record = { appsDescriptionApp: "Pracovní podklady a soubory tohoto modulu.", appsDescriptionSystem: "Provozní nástroje a technické zázemí.", appsDescriptionDefault: "Aplikace pro každodenní práci v modulu {module}.", + // The Apps home and column of the Organization rail (decision F36 + // addendum of 2026-10-04): the wireframe's words. + appsSayNoApp: "Modul {name} zatím nemá aplikaci.", + appsSayCannotStart: "Aplikace modulu {name} teď nejde spustit.", + appsSayRepository: "Repozitář {name} nemá aplikaci.", + appsMore: "Další volby pro {name}", + appsFavorites: "Oblíbené", + appsFavoritesHint: "Hvězdičkou u modulu si ho připneš sem.", + appsFavoriteAdd: "Přidat do oblíbených", + appsFavoriteRemove: "Odebrat z oblíbených", + appsFavoriteMark: "V oblíbených", + appsInfoModule: "Informace o modulu", + appsInfoRepository: "Informace o repozitáři", + appsNewModule: "Nový modul", + appsNewModuleSub: "Založíš ho s agentem v Chatu", + appsNewModuleCopied: + "Zadání nového modulu je ve schránce: vlož ho v Chatu do nového vlákna.", + appsNewModuleCopyFailed: + "Zadání se nepodařilo zkopírovat; otevři Chat a popiš agentovi nový modul.", + appsNewModulePrompt: + "Chci založit nový modul v Organizaci {name} (GitHub {login}).\n\nNež cokoli vytvoříš, zeptej se mě postupně, jednu otázku po druhé:\n1. K čemu modul je a kdo ho bude používat.\n2. Jak se má jmenovat (název a krátký slug).\n3. Jestli má mít aplikaci a jakou (vite-react, astro, astro-starlight, bun-service, python-uv), nebo žádnou.\n4. Které Teamy k němu mají mít přístup.\n\nPak postupuj podle Lazurio Module Standard (skill lazurio-module-standard):\n- modul založ scaffoldem `lazurio module create {login}/ --stack --teams ` z task worktree rootu Organizace, nikdy ručně, a nejdřív mi ukaž plán přes --dry-run;\n- ověř, že repozitář modulu existuje na GitHubu v Organizaci {login} a že k němu mají přístup vybrané Teamy;\n- výsledek připrav jako pull request a před Publikací se mě zeptej.", + appsGuide: "Guide", + appsMarketplace: "Marketplace", + appsSoon: "již brzy", + appsMarketplaceSoon: "Již brzy", + appsMarketplaceText: + "Tady si do Environmentu budeš přidávat další moduly. Připravujeme to.", + appsMarketplaceOrganization: + " Do té doby přibývají moduly v Dashboardu Organizace {name}.", title: "Lazurio Launchpad", homeTitle: "Launchpad", - catalogNavigation: "Organizace", catalogBreadcrumb: "Kde v Launchpadu jste", - catalogIntro: - "Organizace a moduly tohoto Folderu, pokaždé znovu načtené z jeho složky organizations/. Stránka modulu jeho aplikaci spouští, zastavuje a otevírá.", - catalogRefresh: "Načíst znovu", catalogLoading: "Načítám Organizace…", catalogLoadFailed: "Organizace nelze načíst. Zkuste Načíst znovu; když to nepomůže, spusťte v CLI lazurio organization list.", @@ -1143,11 +1165,8 @@ const cs: Record = { "V tomhle Folderu nejsou žádné Organizace. Organizace se tu objeví, jakmile je její repozitář v organizations/.", catalogNotFound: "Tahle Organizace nebo modul v tomhle Folderu není. Možná byl přejmenován nebo odstraněn; podívejte se na všechny Organizace.", - catalogAll: "Všechny Organizace", chat: "Chat", - chatTitle: "Otevřít T3 Code na tomto Environmentu", mausbot: "Lazurio MausBot", - mausbotTitle: "Otevřít Lazurio MausBot na tomto Environmentu", catalogModules: "Moduly", catalogNoModules: "Tahle Organizace nedeklaruje žádné moduly.", catalogSectionWorkspace: "Workspace", @@ -1159,7 +1178,6 @@ const cs: Record = { catalogState: "Stav rozlišení", catalogIssues: "Problémy", catalogApps: "Aplikace", - catalogDefaultApp: "Výchozí aplikace", catalogDefaultMark: "výchozí", catalogPath: "Cesta", catalogStatus: "Lze spustit", diff --git a/src/launchpad/organization-owner.ts b/src/launchpad/organization-owner.ts new file mode 100644 index 000000000..f519e508d --- /dev/null +++ b/src/launchpad/organization-owner.ts @@ -0,0 +1,88 @@ +import type { PresetName } from "../folder/presets"; +import type { ToolsEnvironment } from "../tools/overview"; +import { resolveOnPath } from "../tools/status"; +import { ownerAnswerMs } from "./owner-answer"; + +// Whether this Environment's GitHub identity is an Owner of an Organization +// (decision F36 addendum of 2026-10-04): GitHub's own, live answer, read +// with the Environment's `gh` (`gh api user/memberships/orgs/`: an +// active membership with the role `admin`). It decides only whether the +// Apps home offers "+ Nový modul"; it grants nothing, and no local rule +// stands in for it. A Team Environment acts under the Team's brokered +// identity and never founds modules for a person, and an Organization +// without a bound GitHub login has none to ask: both are no, without a +// call. Every failure is no (fail closed). An answer is kept a few +// minutes per login. + +export const ownerCheck = Object.freeze({ + timeoutMs: 10_000, + cacheMs: ownerAnswerMs, +}); + +const login = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/; + +/** Whether a membership answer of the GitHub API is an active Owner's. */ +export function isOwnerMembership(stdout: string): boolean { + try { + const value = JSON.parse(stdout) as { state?: unknown; role?: unknown }; + return value?.state === "active" && value?.role === "admin"; + } catch { + return false; + } +} + +export function createOwnerCheck( + environment: ToolsEnvironment, + now: () => number = Date.now, +) { + const answers = new Map< + string, + Readonly<{ owner: boolean; until: number }> + >(); + async function ask(organization: string): Promise { + const gh = await resolveOnPath( + "gh", + environment.path, + environment.platform, + ); + if (gh === undefined || !environment.home) return false; + const env: Record = { HOME: environment.home }; + if (environment.path) env.PATH = environment.path; + for (const [name, value] of Object.entries(environment.xdg ?? {})) + env[name] = value; + try { + const result = await environment.run( + [gh, "api", `user/memberships/orgs/${organization}`], + ownerCheck.timeoutMs, + env, + ); + return ( + result !== "timeout" && + result.exitCode === 0 && + isOwnerMembership(result.stdout) + ); + } catch { + return false; + } + } + return { + /** The answer for a bound GitHub login on this Folder's preset. */ + async owner( + organization: string | undefined, + preset: PresetName, + ): Promise { + if ( + organization === undefined || + !login.test(organization) || + preset === "hosted-organization-team" + ) + return false; + const key = organization.toLowerCase(); + const known = answers.get(key); + if (known !== undefined && known.until > now()) return known.owner; + const owner = await ask(organization); + answers.set(key, { owner, until: now() + ownerCheck.cacheMs }); + return owner; + }, + }; +} diff --git a/src/launchpad/owner-answer.ts b/src/launchpad/owner-answer.ts new file mode 100644 index 000000000..6291fa9c9 --- /dev/null +++ b/src/launchpad/owner-answer.ts @@ -0,0 +1,79 @@ +// How long an Owner answer stands, and the page's copy of the answers +// (decision F36 addendum of 2026-10-04). The Launchpad keeps GitHub's answer +// this long per login (organization-owner.ts); the page asks again once its +// own copy is this old (waking itself at that moment), when the bound login +// changes, and after a catalog read. Pure, shared by the server and the page. +export const ownerAnswerMs = 5 * 60_000; + +type Answer = Readonly<{ + owner: boolean; + until: number; + /** The question being asked now, or null: only its answer settles. */ + asking: number | null; +}>; + +export function createOwnerAnswers(now: () => number = Date.now) { + const answers = new Map(); + let questions = 0; + const key = (organization: string, login: string) => + `${organization}\n${login.toLowerCase()}`; + return { + /** What to show now for an Organization bound to a login, and, when the + * Launchpad must be asked, the question to settle (the last answer + * stands meanwhile, and nothing is asked twice at once). */ + read( + organization: string, + login: string, + ): Readonly<{ owner: boolean; ask: number | null }> { + const known = answers.get(key(organization, login)); + if (known !== undefined && (known.asking !== null || known.until > now())) + return { owner: known.owner, ask: null }; + questions += 1; + answers.set(key(organization, login), { + owner: known?.owner ?? false, + until: 0, + asking: questions, + }); + return { owner: known?.owner ?? false, ask: questions }; + }, + /** GitHub's answer to one question, as the Launchpad gave it (false on + * any failure); an answer to a question no longer asked (forgotten by a + * catalog read, or overtaken) changes nothing. */ + settle( + organization: string, + login: string, + question: number, + owner: boolean, + ) { + const known = answers.get(key(organization, login)); + if (known === undefined || known.asking !== question) return; + answers.set(key(organization, login), { + owner, + until: now() + ownerAnswerMs, + asking: null, + }); + }, + /** When the earliest settled answer that still stands expires, or + * null: the page wakes then, asks again for what it shows, and wakes + * again for the next one. An answer already expired (an Organization no + * longer shown) is asked again only when it is shown, so it never keeps + * the page waking. */ + nextExpiry(): number | null { + const at = now(); + let next: number | null = null; + for (const answer of answers.values()) + if ( + answer.asking === null && + answer.until > at && + (next === null || answer.until < next) + ) + next = answer.until; + return next; + }, + /** Forgets every answer and every question still out: the next read + * asks again. */ + clear() { + answers.clear(); + }, + }; +} diff --git a/src/launchpad/routes.ts b/src/launchpad/routes.ts index baa998378..03615eeb0 100644 --- a/src/launchpad/routes.ts +++ b/src/launchpad/routes.ts @@ -30,18 +30,23 @@ export type PageRoute = | Readonly<{ view: "settings"; section: SettingsSection }> /** A folder of the Documents folder (decision F35): `/files` is the * folder itself, `/files//` one below it. */ - | Readonly<{ view: "files"; path: readonly string[] }>; + | Readonly<{ view: "files"; path: readonly string[] }> + /** The Marketplace of the Environment, at the foot of the Apps column + * (decision F36 addendum of 2026-10-04): for now it says it is coming. */ + | Readonly<{ view: "marketplace" }>; -/** The three frames of the page: the catalog (home, Organization, module) - * with the Organizations in the sidebar, the Files page beside the same - * sidebar, and Settings with its navigation. */ -export type PageFrame = "catalog" | "files" | "settings"; +/** The frames of the page: the Apps home (home, Organization, module), the + * Files page and the Marketplace beside the same Apps column, and Settings + * with its navigation. */ +export type PageFrame = "catalog" | "files" | "marketplace" | "settings"; export const routeFrame = (route: PageRoute): PageFrame => route.view === "settings" ? "settings" : route.view === "files" ? "files" - : "catalog"; + : route.view === "marketplace" + ? "marketplace" + : "catalog"; /** Every path the server answers with the page. The two catalog patterns are * the server's route parameters; the page reads its segments itself. */ @@ -51,6 +56,7 @@ export const pagePaths: readonly string[] = [ "/o/:organization/:module", "/files", "/files/*", + "/marketplace", "/settings", ...settingsSections.map((section) => `/settings/${section}`), ]; @@ -91,6 +97,7 @@ export function pageRoute(pathname: string): PageRoute { return { view: "files", path: "segments" in parsed ? parsed.segments : [] }; } const path = pathname.length > 1 ? pathname.replace(/\/+$/, "") : pathname; + if (path === "/marketplace") return { view: "marketplace" }; if (path.startsWith("/o/")) { const parts = path.slice("/o/".length).split("/"); const organization = segment(parts[0]); @@ -120,6 +127,7 @@ export function routePath(route: PageRoute): string { if (route.view === "module") return modulePath(route.organization, route.module); if (route.view === "files") return filesUrlPath(route.path); + if (route.view === "marketplace") return "/marketplace"; return settingsPath(route.section); } @@ -153,6 +161,11 @@ export function routeTitle( document: `${route.module} · ${organization} — ${copy.title}`, }; } + if (route.view === "marketplace") + return { + heading: copy.appsMarketplace, + document: `${copy.appsMarketplace} — ${copy.title}`, + }; if (route.view === "files") { const folder = route.path.at(-1); return { diff --git a/src/launchpad/server.ts b/src/launchpad/server.ts index 0aec8fc9d..266191c2b 100644 --- a/src/launchpad/server.ts +++ b/src/launchpad/server.ts @@ -1,4 +1,5 @@ import { randomBytes } from "node:crypto"; +import { hostname } from "node:os"; import { join } from "node:path"; import { type DocumentsHost, processDocumentsHost } from "../files/documents"; import { inspectProfileChange } from "../folder/inspect-profile-change"; @@ -24,6 +25,7 @@ import { processModuleHost, } from "../modules/module-operations"; import { readFolderCatalog } from "../organizations/catalog"; +import { selectCatalogOrganization } from "../organizations/catalog-selection"; import { readOrganizationApplications } from "../organizations/read-applications"; import type { RecoveryResult } from "../recover/recover"; import { activatableTools, toolSelection } from "../tools/catalog"; @@ -51,6 +53,7 @@ import { serveHealthSocket } from "./health-socket"; import { type AuthFetcher, createHostedTrust } from "./hosted-trust"; import { BodyTooLarge, readJsonBody } from "./json-body"; import { issueMausbotLink } from "./mausbot"; +import { createOwnerCheck } from "./organization-owner"; import { admitLocal, pageRoutes, privatePage, serveShell } from "./page"; import { shellDocument } from "./shell-document"; import { @@ -78,6 +81,11 @@ export type HostedOptions = Readonly<{ /** The Lazurio shell's data document (decision F36). */ export const shellDocumentPath = "/.lazurio/shell.json"; +// Whether this Environment's GitHub identity is an Owner of an Organization +// (decision F36 addendum of 2026-10-04): `` names it as the catalog's +// routes do. +const ownerRoute = /^\/api\/organizations\/([^/]+)\/owner$/; + // The module lifecycle routes (launchpad-parity B3): `` and `` // are URL-encoded segments naming the module as `lazurio module` does. const moduleRoute = @@ -245,6 +253,7 @@ export async function startLaunchpad( githubLoginRefused(await folderPreset(folder), tool, action), }); const installing = new Set(); + const owners = createOwnerCheck(toolsEnvironment); let closing = false; const headers = { "Cache-Control": "no-store", @@ -338,12 +347,38 @@ export async function startLaunchpad( machine: current.preferences.machine, locale: current.preferences.profile.locale === "cs" ? "cs" : "en", catalog: await readFolderCatalog(folder), + computer: hostname(), }), ); } catch { return response({ error: "operation-failed" }, 500); } } + const ownerRequest = ownerRoute.exec(url.pathname); + if (ownerRequest !== null) { + // Read-only and behind the same admission as every read: GitHub's + // own answer, never a local rule (organization-owner.ts). + if (request.method !== "GET") + return response({ error: "method-not-allowed" }, 405); + if (closing) return response({ error: "closing" }, 503); + try { + const name = decodeURIComponent(ownerRequest[1] as string); + const selection = selectCatalogOrganization( + await readFolderCatalog(folder), + name, + ); + server.timeout(request, 30); + const owner = + selection.kind === "found" && + (await owners.owner( + selection.organization.forgeLogin, + await folderPreset(folder), + )); + return response({ kind: "organization-owner", owner }); + } catch { + return response({ kind: "organization-owner", owner: false }); + } + } if (url.pathname.startsWith("/api/files/")) { if (closing) return response({ error: "closing" }, 503); try { diff --git a/src/launchpad/shell-document.ts b/src/launchpad/shell-document.ts index 3cdc9c9cb..35c25adfb 100644 --- a/src/launchpad/shell-document.ts +++ b/src/launchpad/shell-document.ts @@ -2,6 +2,7 @@ import type { MachineBinding } from "../folder/machine-binding"; import type { PresetName } from "../folder/presets"; import type { Catalog } from "../organizations/catalog"; import { + isShellSlug, parseShell, type Shell, type ShellEnvironmentKind, @@ -10,16 +11,24 @@ import { } from "../shell/contract"; import { initialsOf } from "../shell/view"; -// The producer of `/.lazurio/shell.json` (decision F36): what this -// Environment knows about itself today, in the shape of `lazurio.shell.v1`. -// One Environment, its own; its Organizations from the catalog of this -// Folder; its apps from the recorded hosted entry. Nothing here is a grant: -// the document names places, and every place admits by its own rules. The +// The producer of `/.lazurio/shell.json` (decision F36 and its addendum of +// 2026-10-04): what this Environment knows about itself today, in the shape +// of `lazurio.shell.v1`. One Environment, its own, named by what it is for +// (its Team, its persona, or its kind) and never by the machine's name; its +// Organizations from the catalog of this Folder, each with its Dashboard; +// its apps from the recorded hosted entry. Nothing here is a grant: the +// document names places, and every place admits by its own rules. The // Dashboard fills the other Environments later through the Lazurio account. -/** The Lazurio Dashboard and its account settings (root decision 0179). */ +/** The Lazurio Dashboard: the personal one, the account settings, adding an + * Organization, and an Organization's page `/orgs/` (by the + * Organization's slug, the Dashboard's canonical `org_slug`). */ export const dashboardUrl = "https://dashboard.lazurio.ai/"; export const accountUrl = "https://dashboard.lazurio.ai/settings"; +export const addOrganizationUrl = + "https://dashboard.lazurio.ai/add-organization"; +export const organizationDashboardUrl = (slug: string): string => + `https://dashboard.lazurio.ai/orgs/${encodeURIComponent(slug)}`; /** The kind of Environment a preset sets up (decisions 0165, 0169). */ export const presetKinds: Readonly> = { @@ -61,7 +70,9 @@ export function shellOrganizations( organization.reason === "template-not-runtime" || organization.reason === "organization-duplicate" || seen.has(slug.toLowerCase()) || - !/^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/.test(slug) + // The slug by its own rule, never the GitHub login's: the two may + // differ, and only `forgeLogin` is a login. + !isShellSlug(slug) ) return []; seen.add(slug.toLowerCase()); @@ -69,7 +80,7 @@ export function shellOrganizations( Object.freeze({ slug, name: shellName(organization.displayName, slug), - accent: null, + dashboard: organizationDashboardUrl(slug), avatar: organization.forgeLogin === undefined ? null @@ -101,14 +112,68 @@ export function shellName(name: string | null, slug: string): string { } const origin = (value: string) => `${value}/`; +const githubPhoto = (login: string) => + `https://github.com/${encodeURIComponent(login)}.png?size=96`; -/** This Environment's shell document. */ +/** The name of a Team-bound Environment: a Team Environment is its Team's + * ("Team Sales"), an Automated Environment its persona's Team ("Steward"), + * by the Team's display name in the catalog of the Organization that owns + * the Environment. Null when the binding names no Team or the catalog does + * not know it: the elements then name it by its kind. */ +export function teamLabel( + machine: MachineBinding | null, + kind: ShellEnvironmentKind, + catalog: Catalog, +): string | null { + if (machine === null || machine.owner.kind !== "organization") return null; + const { organization, team } = machine.owner; + if (team === null || (kind !== "team" && kind !== "automated")) return null; + const same = (left: string | null | undefined, right: string) => + typeof left === "string" && left.toLowerCase() === right.toLowerCase(); + const owner = catalog.organizations.find( + (entry) => + same(entry.forgeLogin, organization) || + same(entry.organization, organization), + ); + const declared = owner?.teams.find((entry) => same(entry.slug, team)); + if (declared === undefined) return null; + const name = shellName(declared.displayName, declared.slug); + return kind === "team" && !/^team\b/i.test(name) + ? shellName(`Team ${name}`, declared.slug) + : name; +} + +/** The person a work Environment is assigned to, for its "who" line. */ +export function assigneeLogin( + machine: MachineBinding | null, + kind: ShellEnvironmentKind, +): string | null { + if (kind !== "work" || machine === null) return null; + if (machine.owner.kind !== "organization") return null; + const assignment = machine.owner.assignment; + return assignment !== undefined && assignment.kind === "operator" + ? assignment.githubLogin + : null; +} + +/** A workstation's name: the computer's host name without its domain + * (`MacBook-Pro.local` is `MacBook-Pro`), as the person named the computer; + * null when there is none. Only a workstation is named so: a hosted + * Environment is never named by its machine. */ +export function computerLabel(name: string | undefined): string | null { + const host = (name ?? "").split(".")[0]?.trim() ?? ""; + return /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,62})$/.test(host) ? host : null; +} + +/** This Environment's shell document. `computer` is the host name of the + * computer a workstation runs on. */ export function shellDocument( input: Readonly<{ preset: PresetName; machine: MachineBinding | null; locale: "cs" | "en"; catalog: Catalog; + computer?: string; }>, ): Shell { const { machine } = input; @@ -124,11 +189,15 @@ export function shellDocument( operator: { initials: login === null ? null : initialsOf(login).slice(0, 2) || null, login, + avatar: login === null ? null : githubPhoto(login), }, environments: [ { id, - label: machine?.name ?? null, + label: + kind === "workstation" + ? computerLabel(input.computer) + : teamLabel(machine, kind, input.catalog), kind, // A personal Environment belongs to no Organization, whatever its // Folder holds. @@ -136,6 +205,7 @@ export function shellDocument( kind === "personal" ? [] : organizations.map((organization) => organization.slug), + assignee: assigneeLogin(machine, kind), apps: entry === undefined ? { apps: "/", chat: null, automate: null } @@ -152,6 +222,7 @@ export function shellDocument( organizations, dashboard: dashboardUrl, account: accountUrl, + addOrganization: addOrganizationUrl, }; // The producer's own output passes the same parser as every consumer's. const parsed = parseShell(document); diff --git a/src/launchpad/ui.ts b/src/launchpad/ui.ts index 495ee4312..a04b238df 100644 --- a/src/launchpad/ui.ts +++ b/src/launchpad/ui.ts @@ -1,5 +1,7 @@ -import { parseShell, type Shell } from "../shell/contract"; +import { currentEnvironment, parseShell, type Shell } from "../shell/contract"; import { defineShellElements, provideShell } from "../shell/elements"; +import { shellMessages } from "../shell/messages"; +import { environmentName } from "../shell/view"; import { createCatalogPanel } from "./catalog-panel"; import type { PublicEntry } from "./chat"; import { @@ -61,6 +63,12 @@ let entry: PublicEntry | null = null; // own credential and hands over (the forks let the elements read it). defineShellElements(); const columnHead = document.querySelector("#column-head"); +const rail = document.querySelector("#rail"); +// The documentation of the Launchpad's "Guide" (the root Launchpad's +// `guideDocumentationUrl`), in the page's language. +const guide = document.querySelector("#catalog-guide"); +const marketplaceText = + document.querySelector("#marketplace-text"); let shellDocument: Shell | null = null; async function readShell() { try { @@ -92,6 +100,30 @@ const catalog = createCatalogPanel({ shellDocument?.organizations.find( (organization) => organization.slug.toLowerCase() === slug.toLowerCase(), )?.avatar ?? null, + environment: () => { + if (shellDocument === null) return null; + const current = currentEnvironment(shellDocument); + return { + name: environmentName(current, shellMessages(locale)), + icon: ( + { + personal: "user", + work: "user", + team: "users", + automated: "bot", + workstation: "laptop", + } as const + )[current.kind], + }; + }, + // The space the Apps home shows: on a workstation with several + // Organizations the rail and the picker name the one opened. + space: (space) => { + for (const element of [rail, columnHead]) + if (element !== null && element.getAttribute("space") !== space) + element.setAttribute("space", space); + }, + newModule: (prompt) => handOver(prompt), }); // The Files page (decision F35): the Documents folder of this Environment. // Behind a gateway a download is a plain link the session cookie admits; @@ -121,15 +153,31 @@ const recovery = createRecoveryPanel({ t3codeOrigin: () => chatHref(entry), }); // The frame: routes, the catalog and settings navigation, the breadcrumb and -// the sheet of a narrow viewport. +// the sheet of a narrow viewport. It shows its first route while it is +// created; `framed` says it exists. +let framed = false; const shell = createShell({ copy: () => copy, displayName: (organization) => catalog.displayName(organization), onRoute: (route) => { - // The switch marks Apps, except inside Settings (the target shell). - if (route.view === "settings") columnHead?.removeAttribute("active"); - else columnHead?.setAttribute("active", "apps"); + // The switch marks Apps, the gear Settings (the Organization rail). + columnHead?.setAttribute( + "active", + route.view === "settings" ? "settings" : "apps", + ); catalog.render(route); + // Back on "Všechny moduly" the catalog is read again (the first read + // starts below, once the frame exists). + if (framed && (route.view === "home" || route.view === "organization")) + void catalog.refresh(); + if (route.view === "marketplace" && marketplaceText !== null) { + const name = catalog.scopeName(route); + marketplaceText.textContent = + copy.appsMarketplaceText + + (name === null + ? "" + : copy.appsMarketplaceOrganization.replace("{name}", name)); + } files.show(route); if ( route.view === "settings" && @@ -139,6 +187,8 @@ const shell = createShell({ void recovery.refresh(); }, }); +framed = true; + type MachinePeer = { name: string; kind: string; @@ -270,6 +320,8 @@ function relabel() { if (key && Object.hasOwn(copy, key)) element.textContent = copy[key as MessageKey]; } + if (guide !== null) + guide.href = `https://documentation.lazurio.ai/${locale === "en" ? "en" : "cs"}/guide/?utm_source=launchpad&utm_medium=product&utm_campaign=guide`; shell.relabel(); recovery.render(); files.relabel(); @@ -467,6 +519,45 @@ const pairing: Readonly< accept: mausbotPairLink, }, }; +// The address to follow into Chat or Automate: a one-time pairing link on +// its origin when the server mints one, otherwise the plain origin. +async function pairedHref(app: string): Promise { + const pair = Object.hasOwn(pairing, app) ? pairing[app] : undefined; + const plain = + entry === null || pair === undefined ? undefined : pair.origin(entry); + if (pair === undefined || plain === undefined) return null; + try { + const { value, ok } = await post(pair.path, {}); + return (ok && pair.accept(value, plain)) || plain; + } catch { + return plain; + } +} +// "+ Nový modul" (decision F36 addendum of 2026-10-04): the prepared prompt +// goes to the clipboard and this Environment's Chat opens in a new tab, where +// the person pastes it into a new chat. The T3 Code fork cannot take a +// prompt draft by link yet (Lazurio/t3code#35, issue #153); once it can, Chat opens with +// the prompt in its composer instead. A workstation has no Chat origin: the +// prompt is copied all the same. +async function handOver(prompt: string): Promise { + const tab = entry === null ? null : window.open("about:blank", "_blank"); + let copied = false; + try { + await navigator.clipboard.writeText(prompt); + copied = true; + } catch { + copied = false; + } + if (tab !== null) { + const next = await pairedHref("chat"); + if (next === null) tab.close(); + else { + tab.opener = null; + tab.location.href = next; + } + } + return copied; +} let following = false; document.addEventListener("lazurio-app", (event) => { const detail = (event as CustomEvent<{ app?: unknown; href?: unknown }>) @@ -482,19 +573,14 @@ document.addEventListener("lazurio-app", (event) => { const pair = Object.hasOwn(pairing, detail.app) ? pairing[detail.app] : undefined; - const plain = - entry === null || pair === undefined ? undefined : pair.origin(entry); - if (pair === undefined || plain === undefined) return; + if (entry === null || pair === undefined || pair.origin(entry) === undefined) + return; event.preventDefault(); if (following) return; following = true; + const { app, href } = detail; void (async () => { - let next = plain; - try { - const { value, ok } = await post(pair.path, {}); - next = (ok && pair.accept(value, plain)) || next; - } catch {} - location.assign(next); + location.assign((await pairedHref(app)) ?? href); })(); }); // Back from the app restores this page from the bfcache with the click that diff --git a/src/shell/contract.ts b/src/shell/contract.ts index 5fbb463f7..c8a1b415a 100644 --- a/src/shell/contract.ts +++ b/src/shell/contract.ts @@ -1,11 +1,14 @@ -// The data contract of the Lazurio shell (decision F36): `lazurio.shell.v1`, -// the document the Launchpad serves at `/.lazurio/shell.json` on the -// Environment's origin and the elements of `/.lazurio/shell.js` draw. It names -// the Environment the page is served from, the other Environments the rail may -// show, their Organizations and the addresses of the apps. Today the Launchpad -// knows one Environment, its own; the Dashboard fills the others later through -// the Lazurio account, in this same shape, so the elements do not change. -// Pure: no DOM and no I/O, shared by the producer, the page and the elements. +// The data contract of the Lazurio shell (decision F36 and its addendum of +// 2026-10-04): `lazurio.shell.v1`, the document the Launchpad serves at +// `/.lazurio/shell.json` on the Environment's origin and the elements of +// `/.lazurio/shell.js` draw. It names the Environment the page is served +// from, the other Environments the person may enter, their Organizations +// with their Dashboards, and the addresses of the apps. Today the Launchpad +// knows one Environment, its own; the Dashboard fills the others later +// through the Lazurio account, in this same shape, so the elements do not +// change. Pure: no DOM and no I/O, shared by the producer, the page and the +// elements. The producer and the elements ship in one binary and no fork +// reads it yet, so the shape changes in place, without a compatibility layer. export const shellSchema = "lazurio.shell.v1"; @@ -35,13 +38,18 @@ export type ShellApps = Readonly<{ export type ShellEnvironment = Readonly<{ /** Stable within the document; `current` names one of them. */ id: string; - /** The name the rail shows; null for the workstation, which the elements - * name in the person's language. */ + /** Its own name when it has one: a Team Environment's Team, an Automated + * Environment's persona, a workstation's computer. Null: the elements name + * it by its kind (Pracovní, Osobní, Tento počítač). Never a hosted + * machine's technical name. */ label: string | null; kind: ShellEnvironmentKind; /** The slugs of `organizations` it holds, in order; empty for a personal - * one. An Organization's Environment sits in that Organization's folder. */ + * one. A workstation may hold several. */ organizations: readonly string[]; + /** The GitHub login of the one person a work Environment is assigned to, + * for its "who" line; null otherwise. */ + assignee: string | null; apps: ShellApps; }>; @@ -49,20 +57,21 @@ export type ShellOrganization = Readonly<{ /** The Organization slug, as the catalog names it. */ slug: string; name: string; - /** The Organization's accent colour (`#rrggbb`), from data, never from the - * design system; null until a source records it, and the elements then use - * the design system's accent. */ - accent: string | null; /** An https URL of the GitHub Organization's avatar; null shows its * initials. */ avatar: string | null; + /** The Organization's page in the Dashboard (the head of the picker). */ + dashboard: string; }>; export type ShellOperator = Readonly<{ - /** Up to three letters for the account mark; null shows a person icon. */ + /** Up to three letters for the personal space; null shows a person icon. */ initials: string | null; /** The GitHub login, when the Environment knows whose it is. */ login: string | null; + /** An https URL of the person's GitHub photo, for the account; null shows + * the initials. */ + avatar: string | null; }>; export type Shell = Readonly<{ @@ -74,10 +83,13 @@ export type Shell = Readonly<{ operator: ShellOperator; environments: readonly ShellEnvironment[]; organizations: readonly ShellOrganization[]; - /** The Lazurio Dashboard (the logo at the top of the rail). */ + /** The personal Dashboard (the logo at the top of the rail). */ dashboard: string; /** The account settings in the Dashboard (the account at the bottom). */ account: string; + /** Where an Organization is added (the "+" under the Organizations); null + * hides it. */ + addOrganization: string | null; }>; type Data = Readonly>; @@ -117,9 +129,16 @@ const isAppsUrl = (value: unknown): value is string => /^\/(?!\/)[^\s\\]*$/.test(value) && !value.includes("#")); -const slug = /^[A-Za-z0-9](?:[A-Za-z0-9_.-]{0,98}[A-Za-z0-9])?$/; +/** An Organization's slug as its canonical manifest admits it (any + * nonblank text without surrounding space), bounded here at 128 and without + * control characters. The elements only compare slugs and encode them into + * URLs, so no character set narrower than the manifest's is needed. */ +export const isShellSlug = (value: unknown): value is string => + text(value, 128) && value.trim() === value; const initials = /^[\p{Lu}\p{N}]{1,3}$/u; const login = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/; +const isLogin = (value: unknown): value is string => + typeof value === "string" && login.test(value); function apps(value: unknown): ShellApps | null { if (!isRecord(value)) return null; @@ -139,7 +158,7 @@ function apps(value: unknown): ShellApps | null { function environment(value: unknown): ShellEnvironment | null { if (!isRecord(value)) return null; - const { id, label, kind, organizations } = value; + const { id, label, kind, organizations, assignee } = value; const own = apps(value.apps); if ( !text(id, 128) || @@ -147,6 +166,7 @@ function environment(value: unknown): ShellEnvironment | null { !(shellEnvironmentKinds as readonly unknown[]).includes(kind) || !Array.isArray(organizations) || !organizations.every((entry) => typeof entry === "string") || + !(assignee === null || isLogin(assignee)) || own === null ) return null; @@ -155,29 +175,27 @@ function environment(value: unknown): ShellEnvironment | null { label: label as string | null, kind: kind as ShellEnvironmentKind, organizations: Object.freeze([...(organizations as string[])]), + assignee: assignee as string | null, apps: own, }); } function organization(value: unknown): ShellOrganization | null { if (!isRecord(value)) return null; - const { accent, avatar, name } = value; + const { avatar, name, dashboard } = value; if ( typeof value.slug !== "string" || - !slug.test(value.slug) || + !isShellSlug(value.slug) || !text(name, 128) || - !( - accent === null || - (typeof accent === "string" && /^#[0-9a-f]{6}$/i.test(accent)) - ) || - !(avatar === null || isShellUrl(avatar)) + !(avatar === null || isShellUrl(avatar)) || + !isShellUrl(dashboard) ) return null; return Object.freeze({ slug: value.slug, name, - accent: accent as string | null, avatar: avatar as string | null, + dashboard, }); } @@ -190,6 +208,8 @@ export function parseShell(input: unknown): Shell | null { if (!isRecord(input) || input.schema !== shellSchema) return null; if (input.locale !== "cs" && input.locale !== "en") return null; if (!isShellUrl(input.dashboard) || !isShellUrl(input.account)) return null; + if (!(input.addOrganization === null || isShellUrl(input.addOrganization))) + return null; const operator = input.operator; if ( !isRecord(operator) || @@ -198,10 +218,8 @@ export function parseShell(input: unknown): Shell | null { (typeof operator.initials === "string" && initials.test(operator.initials)) ) || - !( - operator.login === null || - (typeof operator.login === "string" && login.test(operator.login)) - ) + !(operator.login === null || isLogin(operator.login)) || + !(operator.avatar === null || isShellUrl(operator.avatar)) ) return null; if (!Array.isArray(input.environments) || !Array.isArray(input.organizations)) @@ -229,11 +247,13 @@ export function parseShell(input: unknown): Shell | null { operator: Object.freeze({ initials: operator.initials as string | null, login: operator.login as string | null, + avatar: operator.avatar as string | null, }), environments: Object.freeze(envs), organizations: Object.freeze(orgs), dashboard: input.dashboard, account: input.account, + addOrganization: input.addOrganization as string | null, }); } diff --git a/src/shell/elements.ts b/src/shell/elements.ts index 6e354e737..4cab064df 100644 --- a/src/shell/elements.ts +++ b/src/shell/elements.ts @@ -1,26 +1,31 @@ -import { parseShell, type Shell } from "./contract"; +import { currentEnvironment, parseShell, type Shell } from "./contract"; import { installShellFonts } from "./fonts"; import { icon } from "./icons"; -import { type ShellCopy, shellMessages } from "./messages"; +import { fillShell, type ShellCopy, shellMessages } from "./messages"; import { columnHeadCss, railCss, railWidth } from "./styles"; import { vendorText } from "./vendor-text" with { type: "macro" }; import { - jumpList, - moreText, - type RailFolder, - type RailItem, - railModel, + environmentGlyph, + environmentName, + environmentWho, + hereOf, + initialsOf, + railSpaces, type ShellApp, + type SwitcherSection, shellApps, + switcherSections, switchTabs, } from "./view"; -// The Lazurio shell as framework-free custom elements (decision F36): -// `` (level 1: the logo to the Dashboard, the jump to an -// Environment, the personal Environments, the Organization folders, the -// gear and the account) and `` (the switch -// Chat · Apps · Automate at the top of an app's left column). Each draws into -// its own shadow root, so neither the host's styles nor these leak across. +// The Lazurio shell as framework-free custom elements (decision F36, +// addendum of 2026-10-04): `` (level 1: the logo to the +// Dashboard, the jump to an Environment, your personal space, one avatar per +// Organization, the account) and `` (the head of an +// app's left column: the Environment picker with the gear of this +// Environment's Settings beside it, then the switch Chat · Apps · Automate). +// Each draws into its own shadow root, so neither the host's styles nor these +// leak across. The panel below the head stays the app's own. // `` is reserved for Buddy's bubble (decision 0180) and not // defined here. // @@ -29,11 +34,16 @@ import { // their own origin once (the forks). A host that provides it marks // `` so nothing is fetched twice. // +// Attributes: `app` on the rail (`chat`, `apps`, `automate`: a click on a +// space stays in that app), `space` on both (the space you are in, when the +// host knows it better than the document: a workstation opened for one +// Organization), `active` (`chat`, `apps`, `automate` or `settings`) and +// `settings` (the Settings address) on the head. +// // Events, both cancelable and composed, so a host can take a click over: // `lazurio-navigate` (detail `{ href }`) for a link on the document's own -// origin (the gear, the Apps tab, the current Environment), and -// `lazurio-app` (detail `{ app, href }`) for a switch tab. Without a -// listener that cancels them, the links simply navigate. +// origin, and `lazurio-app` (detail `{ app, href }`) for a switch tab. +// Without a listener that cancels them, the links simply navigate. const logo = vendorText("symbol-color.svg"); @@ -67,6 +77,30 @@ function requestShell(): void { .catch(() => undefined); } +// Where you last were in each space, in this browser: a click on a space in +// the rail returns there. Only Environment ids of the document are kept. +const lastKey = "lazurio.shell.last"; +function lastBySpace(): Record { + try { + const value: unknown = JSON.parse(localStorage.getItem(lastKey) ?? "{}"); + return value && typeof value === "object" && !Array.isArray(value) + ? (value as Record) + : {}; + } catch { + return {}; + } +} +function remember(space: string, environment: string) { + try { + const last = lastBySpace(); + if (last[space] === environment) return; + localStorage.setItem( + lastKey, + JSON.stringify({ ...last, [space]: environment }), + ); + } catch {} +} + const sameOrigin = (href: string) => href.startsWith("/") && !href.startsWith("//"); @@ -88,6 +122,26 @@ function element( return node; } +/** An Organization's avatar, or its initials when there is none or it does + * not load. */ +function organizationMark( + avatar: string | null, + initials: string, +): HTMLSpanElement { + const mark = element("span", "org-mark"); + const fallback = () => mark.replaceChildren(initials); + if (avatar === null) fallback(); + else { + const image = element("img"); + image.alt = ""; + image.referrerPolicy = "no-referrer"; + image.src = avatar; + image.addEventListener("error", fallback, { once: true }); + mark.append(image); + } + return mark; +} + abstract class ShellElement extends HTMLElement { protected readonly root: ShadowRoot; private readonly redraw = () => this.render(); @@ -113,9 +167,18 @@ abstract class ShellElement extends HTMLElement { const lang = this.getAttribute("lang"); return shellMessages(lang === "cs" || lang === "en" ? lang : shell.locale); } + protected here(shell: Shell): string { + return hereOf(shell, this.getAttribute("space")); + } + protected app(): ShellApp { + const app = this.getAttribute("app"); + return (shellApps as readonly string[]).includes(app ?? "") + ? (app as ShellApp) + : "apps"; + } /** A link the host may take over: same-origin links announce * `lazurio-navigate` before they navigate. */ - protected link(href: string, className: string): HTMLAnchorElement { + link(href: string, className: string): HTMLAnchorElement { const anchor = element("a", className); anchor.href = href; if (sameOrigin(href)) @@ -136,6 +199,169 @@ abstract class ShellElement extends HTMLElement { protected abstract render(): void; } +/** The list of Environments, as a popover under the picker (one space, + * widened by "Všechny Organizace") or as the ⌘⇧E dialog (every space). */ +class Switcher { + readonly box = element("div", "switcher-box"); + private readonly input = element("input"); + private readonly list = element("div", "switcher-list"); + private readonly foot = element("div", "switcher-foot"); + private query = ""; + private cursor = 0; + private links: HTMLAnchorElement[] = []; + constructor( + private readonly host: ShellElement, + private readonly shell: Shell, + private readonly copy: ShellCopy, + private readonly options: { + here: string; + app: ShellApp; + all: boolean; + popover: boolean; + close: () => void; + }, + ) { + const search = element("label", "switcher-search"); + this.input.type = "search"; + this.input.setAttribute("aria-label", copy.switcher); + this.input.addEventListener("input", () => { + this.query = this.input.value; + this.cursor = 0; + this.fill(); + }); + this.input.addEventListener("keydown", (event) => this.key(event)); + search.append( + icon("search", 16), + this.input, + element("span", "kbd", "⌘⇧E"), + ); + this.box.setAttribute("role", "dialog"); + this.box.setAttribute("aria-label", copy.switcher); + this.box.append(search, this.list, this.foot); + this.fill(); + } + focus() { + this.input.focus(); + } + private key(event: KeyboardEvent) { + if (event.key === "Escape") { + event.preventDefault(); + this.options.close(); + return; + } + if (event.key === "ArrowDown" || event.key === "ArrowUp") { + event.preventDefault(); + const count = this.links.length; + if (count === 0) return; + this.cursor = + (this.cursor + (event.key === "ArrowDown" ? 1 : -1) + count) % count; + this.mark(); + return; + } + if (event.key === "Enter") { + event.preventDefault(); + this.links[this.cursor]?.click(); + } + } + private mark() { + for (const [index, link] of this.links.entries()) + link.classList.toggle("is-cursor", index === this.cursor); + this.links[this.cursor]?.scrollIntoView({ block: "nearest" }); + } + private fill() { + const copy = this.copy; + const options = this.options; + const sections = switcherSections(this.shell, copy, { + here: options.here, + all: options.all, + app: options.app, + query: this.query, + }); + const scope = sections[0]?.title ?? copy.personal; + this.input.placeholder = options.all + ? copy.searchAll + : fillShell(copy.searchIn, { name: scope }); + this.links = []; + this.list.replaceChildren( + ...sections.map((section) => this.section(section)), + ); + if (this.links.length === 0 && (options.all || this.query.trim() !== "")) + this.list.append(element("p", "switcher-empty", copy.nothing)); + this.cursor = Math.min(this.cursor, Math.max(0, this.links.length - 1)); + this.mark(); + const hints: Node[] = []; + if (!options.all) { + const widen = element("button", "switcher-widen"); + widen.type = "button"; + widen.append(icon("globe", 14), copy.widen); + widen.addEventListener("click", () => { + options.all = true; + this.cursor = 0; + this.fill(); + this.input.focus(); + }); + hints.push(widen); + } + const hint = (key: string, word: string) => { + const span = element("span"); + span.append(element("span", "kbd", key), ` ${word}`); + return span; + }; + hints.push(hint("↑↓", copy.choose), hint("Enter", copy.go)); + if (!options.popover) hints.push(hint("Esc", copy.close)); + this.foot.replaceChildren(...hints); + } + private track(link: HTMLAnchorElement) { + const at = this.links.length; + this.links.push(link); + link.addEventListener("mouseenter", () => { + this.cursor = at; + this.mark(); + }); + link.addEventListener("click", () => this.options.close()); + return link; + } + private section(section: SwitcherSection): HTMLElement { + const copy = this.copy; + const group = element("div", "switcher-group"); + if (section.head !== null) { + const { organization, href } = section.head; + const head = this.track(this.host.link(href, "switcher-head")); + head.append( + organizationMark(organization.avatar, initialsOf(organization.name)), + element("span", "", organization.name), + element("span", "switcher-head-meta", copy.organizationDashboard), + ); + group.append(head); + } else group.append(element("div", "switcher-title", section.title)); + for (const row of section.rows) { + const link = this.track(this.host.link(row.href, "switcher-row")); + if (row.current) link.setAttribute("aria-current", "page"); + const glyph = element("span", "switcher-glyph"); + if (row.glyph.kind === "initials") glyph.textContent = row.glyph.text; + else glyph.append(icon(row.glyph.icon, 16)); + link.append( + glyph, + element("span", "switcher-name", row.name), + element("span", "switcher-who", row.who), + ); + if (row.current) { + const here = element("span", "switcher-here"); + here.append(icon("check", 14), copy.here); + link.append(here); + } + group.append(link); + } + if ( + section.head !== null && + section.rows.length === 0 && + this.query.trim() === "" + ) + group.append(element("p", "switcher-empty", copy.noEnvironment)); + return group; + } +} + // One rail at a time answers ⌘⇧E / Ctrl+Shift+E: the last one connected. let jumpTarget: LazurioRail | null = null; let shortcutInstalled = false; @@ -158,8 +384,7 @@ function installShortcut() { } export class LazurioRail extends ShellElement { - static observedAttributes = ["settings", "lang"]; - private readonly expanded = new Set(); + static observedAttributes = ["app", "space", "lang"]; private tip: HTMLDivElement | null = null; private jump: HTMLDialogElement | null = null; constructor() { @@ -179,49 +404,21 @@ export class LazurioRail extends ShellElement { if (jumpTarget === this) jumpTarget = null; } - /** Opens the jump list of Environments (⌘⇧E). */ + /** Opens the jump to any Environment (⌘⇧E). */ openJump() { - if (current === null || this.jump === null) return; - if (!this.jump.open) this.jump.showModal(); - const input = this.jump.querySelector("input"); - if (input) { - input.value = ""; - this.fillJump(""); - input.focus(); - } - } - - private fillJump(query: string) { - if (current === null || this.jump === null) return; - const copy = this.copy(current); - const list = this.jump.querySelector("ul"); - const empty = this.jump.querySelector(".jump-empty"); - if (!list || !empty) return; - const entries = jumpList(current, copy, query); - list.replaceChildren( - ...entries.map((entry) => { - const item = element("li"); - const anchor = this.link(entry.href, ""); - if (entry.active) anchor.setAttribute("aria-current", "page"); - anchor.append( - element("strong", "", entry.label), - element("span", "", entry.sub), - ); - anchor.addEventListener("click", () => this.jump?.close()); - item.append(anchor); - return item; - }), - ); - empty.hidden = entries.length > 0; - } - - private settingsHref(shell: Shell): string { - const own = this.getAttribute("settings"); - if (own) return own; - const apps = shell.environments.find((entry) => entry.id === shell.current) - ?.apps.apps; - if (apps === undefined || sameOrigin(apps)) return "/settings"; - return new URL("settings", apps).href; + const shell = current; + if (shell === null || this.jump === null) return; + const dialog = this.jump; + const switcher = new Switcher(this, shell, this.copy(shell), { + here: this.here(shell), + app: this.app(), + all: true, + popover: false, + close: () => dialog.close(), + }); + dialog.replaceChildren(switcher.box); + if (!dialog.open) dialog.showModal(); + switcher.focus(); } private withTip(node: T, title: string, sub: string) { @@ -230,67 +427,6 @@ export class LazurioRail extends ShellElement { return node; } - private envItem(entry: RailItem): HTMLAnchorElement { - const anchor = this.withTip( - this.link(entry.href, "item env"), - entry.label, - entry.sub, - ); - anchor.setAttribute("aria-label", entry.label); - if (entry.active) anchor.setAttribute("aria-current", "page"); - if (entry.accent !== null) - anchor.style.setProperty("--env-accent", entry.accent); - anchor.append( - entry.mark.kind === "initials" - ? element("span", "initials", entry.mark.text) - : icon(entry.mark.icon, 20), - ); - return anchor; - } - - private folder(entry: RailFolder, copy: ShellCopy): HTMLDivElement { - const box = element("div", `folder${entry.hasActive ? " has-active" : ""}`); - box.style.setProperty( - "--env-accent", - entry.organization.accent ?? "var(--lz-accent-strong)", - ); - const head = this.withTip( - element("span", "folder-head"), - entry.organization.name, - copy.organizationSub, - ); - const mark = element("span", "mark"); - const fallback = () => mark.replaceChildren(entry.initials); - if (entry.organization.avatar !== null) { - const image = element("img"); - image.alt = ""; - image.referrerPolicy = "no-referrer"; - image.src = entry.organization.avatar; - image.addEventListener("error", fallback, { once: true }); - mark.append(image); - } else fallback(); - head.append(mark, element("span", "sr-only", entry.organization.name)); - box.append(head, ...entry.items.map((item) => this.envItem(item))); - if (entry.hidden > 0 || entry.expanded) { - const words = moreText(copy, entry); - const more = this.withTip( - element("button", "more", words.text), - words.label, - "", - ); - more.type = "button"; - more.setAttribute("aria-label", words.label); - more.setAttribute("aria-expanded", String(entry.expanded)); - more.addEventListener("click", () => { - if (entry.expanded) this.expanded.delete(entry.organization.slug); - else this.expanded.add(entry.organization.slug); - this.render(); - }); - box.append(more); - } - return box; - } - protected render() { const shell = current; if (shell === null) { @@ -298,7 +434,14 @@ export class LazurioRail extends ShellElement { return; } const copy = this.copy(shell); - const model = railModel(shell, copy, this.expanded); + const here = this.here(shell); + remember(here, shell.current); + const last = lastBySpace(); + const spaces = railSpaces(shell, copy, { + here, + app: this.app(), + last: (space) => last[space] ?? null, + }); const nav = element("nav"); nav.setAttribute("aria-label", copy.rail); @@ -315,7 +458,7 @@ export class LazurioRail extends ShellElement { home.append(image); const search = this.withTip( - element("button", "item utility search"), + element("button", "item search"), copy.jump, copy.jumpShortcut, ); @@ -326,18 +469,34 @@ export class LazurioRail extends ShellElement { search.addEventListener("click", () => this.openJump()); const scroll = element("div", "scroll"); - scroll.append(...model.personal.map((entry) => this.envItem(entry))); - if (model.personal.length > 0 && model.folders.length > 0) - scroll.append(element("div", "divider")); - scroll.append(...model.folders.map((entry) => this.folder(entry, copy))); - - const gear = this.withTip( - this.link(this.settingsHref(shell), "item utility"), - copy.settings, - copy.settingsSub, - ); - gear.setAttribute("aria-label", copy.settings); - gear.append(icon("settings", 20)); + spaces.forEach((space, index) => { + if (index === 1) scroll.append(element("div", "divider")); + const link = this.withTip( + this.link(space.href, "item space"), + space.title, + space.sub, + ); + link.setAttribute("aria-label", space.title); + if (space.active) link.setAttribute("aria-current", "true"); + if (index === 0) { + const mark = element("span", "initials"); + if (space.initials !== null) mark.textContent = space.initials; + else mark.append(icon("user", 18)); + link.append(mark); + } else link.append(organizationMark(space.avatar, space.initials ?? "")); + scroll.append(link); + }); + if (shell.addOrganization !== null) { + const add = this.withTip( + element("a", "item add"), + copy.addOrganization, + "", + ); + add.href = shell.addOrganization; + add.setAttribute("aria-label", copy.addOrganization); + add.append(icon("plus", 18)); + scroll.append(add); + } const account = this.withTip( element("a", "item account"), @@ -346,11 +505,23 @@ export class LazurioRail extends ShellElement { ); account.href = shell.account; account.setAttribute("aria-label", copy.account); - const avatar = element("span", "avatar"); - if (shell.operator.initials !== null) - avatar.textContent = shell.operator.initials; - else avatar.append(icon("user", 18)); - account.append(avatar); + const photo = () => { + const mark = element("span", "avatar"); + if (shell.operator.initials !== null) + mark.textContent = shell.operator.initials; + else mark.append(icon("user", 18)); + return mark; + }; + if (shell.operator.avatar !== null) { + const picture = element("img", "avatar"); + picture.alt = ""; + picture.referrerPolicy = "no-referrer"; + picture.src = shell.operator.avatar; + picture.addEventListener("error", () => picture.replaceWith(photo()), { + once: true, + }); + account.append(picture); + } else account.append(photo()); // The rail's own label: at once, beside the item, two lines. const tip = element("div", "tip"); @@ -359,38 +530,13 @@ export class LazurioRail extends ShellElement { tip.append(element("strong"), element("span")); this.tip = tip; - const jump = element("dialog"); - jump.setAttribute("aria-label", copy.jumpTitle); - const head = element("label", "jump-head"); - const input = element("input"); - input.type = "search"; - input.placeholder = copy.jumpTitle; - input.setAttribute("aria-label", copy.jumpTitle); - input.addEventListener("input", () => this.fillJump(input.value)); - input.addEventListener("keydown", (event) => { - if (event.key !== "Enter") return; - jump.querySelector("ul a")?.click(); - }); - head.append(icon("search", 16), input); - jump.append( - head, - element("ul", "jump-list"), - element("p", "jump-empty", copy.jumpEmpty), - ); + const jump = element("dialog", "switcher-dialog"); jump.addEventListener("click", (event) => { if (event.target === jump) jump.close(); }); this.jump = jump; - nav.append( - home, - search, - element("div", "divider"), - scroll, - gear, - account, - tip, - ); + nav.append(home, search, element("div", "divider"), scroll, account, tip); const show = (event: Event) => { const target = event .composedPath() @@ -420,26 +566,152 @@ export class LazurioRail extends ShellElement { } export class LazurioColumnHead extends ShellElement { - static observedAttributes = ["active", "lang"]; + static observedAttributes = ["active", "settings", "space", "lang"]; + private open: { close: () => void } | null = null; constructor() { super(columnHeadCss); } + override disconnectedCallback() { + super.disconnectedCallback(); + this.scheme.removeEventListener("change", this.retone); + this.open?.close(); + } + + private settingsHref(shell: Shell): string { + const own = this.getAttribute("settings"); + if (own) return own; + const apps = currentEnvironment(shell).apps.apps; + if (sameOrigin(apps)) return "/settings"; + return new URL("settings", apps).href; + } + + /** Opens the list of this space's Environments under the picker. */ + /** Opens the list of this space's Environments under the picker, in the + * top layer (a popover): the host's sidebar may clip or stack over its + * children, the top layer is above both. A click outside or Escape closes + * it (light dismiss). */ + private toggle(picker: HTMLButtonElement, shell: Shell) { + if (this.open !== null) { + this.open.close(); + return; + } + const copy = this.copy(shell); + let closed = false; + const close = () => { + if (closed) return; + closed = true; + if (switcher.box.matches(":popover-open")) switcher.box.hidePopover(); + switcher.box.remove(); + picker.setAttribute("aria-expanded", "false"); + this.open = null; + }; + const switcher = new Switcher(this, shell, copy, { + here: this.here(shell), + app: this.activeApp() ?? "apps", + all: false, + popover: true, + close, + }); + const rect = picker.getBoundingClientRect(); + const box = switcher.box; + box.classList.add("switcher-popover"); + box.popover = "auto"; + box.style.top = `${rect.bottom + 6}px`; + box.style.left = `${rect.left}px`; + box.style.width = `${Math.min(Math.max(rect.width, 400), window.innerWidth - rect.left - 8)}px`; + box.addEventListener("toggle", (event) => { + if ((event as ToggleEvent).newState === "closed") { + close(); + if (document.activeElement === this || this.root.activeElement === null) + picker.focus(); + } + }); + this.root.append(box); + box.showPopover(); + picker.setAttribute("aria-expanded", "true"); + this.open = { close }; + switcher.focus(); + } + + // The host's tone (the forks have light and dark skins): the custom + // property `--lazurio-host-tone: dark | light` wins; otherwise the + // luminance of the nearest ancestor with an opaque background decides. + // Read on connect and when the colour scheme changes. + private readonly scheme = window.matchMedia("(prefers-color-scheme: dark)"); + private readonly retone = () => this.tone(); + override connectedCallback() { + super.connectedCallback(); + this.tone(); + this.scheme.addEventListener("change", this.retone); + } + private tone() { + const declared = getComputedStyle(this) + .getPropertyValue("--lazurio-host-tone") + .trim(); + const dark = + declared === "dark" || declared === "light" + ? declared === "dark" + : hostIsDark(this); + if ((this.dataset.hostTone === "dark") !== dark) + this.dataset.hostTone = dark ? "dark" : "light"; + } + + private activeApp(): ShellApp | null { + const active = this.getAttribute("active"); + return (shellApps as readonly string[]).includes(active ?? "") + ? (active as ShellApp) + : null; + } + protected render() { + this.open?.close(); const shell = current; if (shell === null) { this.root.replaceChildren(); return; } const copy = this.copy(shell); - const active = this.getAttribute("active"); - const tabs = switchTabs( - shell, - copy, - (shellApps as readonly string[]).includes(active ?? "") - ? (active as ShellApp) - : null, + const here = this.here(shell); + const environment = currentEnvironment(shell); + const name = environmentName(environment, copy); + + const picker = element("button", "pick"); + picker.type = "button"; + picker.setAttribute("aria-haspopup", "dialog"); + picker.setAttribute("aria-expanded", "false"); + picker.setAttribute("aria-label", fillShell(copy.pick, { name })); + const glyph = element("span", "pick-glyph"); + const look = environmentGlyph(shell, environment, here); + if (look.kind === "avatar") + glyph.append( + organizationMark( + look.organization.avatar, + initialsOf(look.organization.name), + ), + ); + else if (look.kind === "initials") + glyph.append(element("span", "initials", look.text)); + else glyph.append(icon(look.icon, 18)); + const text = element("span", "pick-text"); + text.append( + element("span", "pick-title", name), + element("span", "pick-who", environmentWho(environment, copy)), ); - const nav = element("nav"); + picker.append(glyph, text, icon("chevron-down", 14)); + picker.addEventListener("click", () => this.toggle(picker, shell)); + + const gear = this.link(this.settingsHref(shell), "gear"); + gear.setAttribute("aria-label", copy.settings); + gear.title = copy.settings; + if (this.getAttribute("active") === "settings") + gear.setAttribute("aria-current", "page"); + gear.append(icon("settings", 18)); + + const row = element("div", "row"); + row.append(picker, gear); + + const tabs = switchTabs(shell, copy, this.activeApp()); + const nav = element("nav", "switch"); nav.setAttribute("aria-label", copy.switchLabel); nav.append( ...tabs.map((tab) => { @@ -473,10 +745,39 @@ export class LazurioColumnHead extends ShellElement { return anchor; }), ); - this.root.replaceChildren(nav); + const head = element("div", "head"); + head.append(row, nav); + this.root.replaceChildren(head); } } +/** Whether the nearest ancestor with an opaque background is dark (its + * relative luminance below 0.4); none found is light. */ +export function hostIsDark(start: Element): boolean { + let node: Element | null = start.parentElement; + while (node !== null) { + const rgb = /rgba?\(([^)]+)\)/.exec(getComputedStyle(node).backgroundColor); + const parts = + rgb?.[1] + ?.split(/[\s,/]+/) + .filter(Boolean) + .map(Number) ?? []; + const [r = 0, g = 0, b = 0, alpha = 1] = parts; + if (parts.length >= 3 && alpha >= 0.9) return luminance(r, g, b) < 0.4; + node = node.parentElement; + } + return false; +} + +/** The relative luminance of an sRGB colour (WCAG). */ +export function luminance(r: number, g: number, b: number): number { + const channel = (value: number) => { + const c = value / 255; + return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4; + }; + return 0.2126 * channel(r) + 0.7152 * channel(g) + 0.0722 * channel(b); +} + /** Defines the elements (once) and declares the brand fonts in the document. */ export function defineShellElements(): void { installShellFonts(document); diff --git a/src/shell/icons.ts b/src/shell/icons.ts index 6864d1ded..d62dff19d 100644 --- a/src/shell/icons.ts +++ b/src/shell/icons.ts @@ -1,20 +1,32 @@ -// Icons of the shell elements: Lucide (ISC license, https://lucide.dev), the -// set the Launchpad already uses, as SVG elements built from fixed path data. +// Icons of the shell elements: Iconoir (MIT, https://iconoir.com; licence in +// vendor/LICENSE-iconoir.txt), the interface set the Lazurio design system +// mandates (design-system-lazurio `content/brand/icons/icons.md`). The path +// data is exactly what the shell wireframe draws (prototypes-lazurio 1cbad15, +// `app/v1/src/Icon.tsx`, iconoir-react 7.12.1), at its stroke of 1.5, built as +// SVG elements from fixed data of this module. const paths = { - search: '', + search: + '', settings: - '', + '', laptop: - '', - user: '', + '', + user: '', users: - '', - bot: '', - chat: '', - apps: '', + '', + bot: '', + chat: '', + apps: '', automate: - '', + '', + "chevron-down": + '', + check: + '', + globe: + '', + plus: '', } as const; export type ShellIcon = keyof typeof paths; @@ -26,10 +38,7 @@ export function icon(name: ShellIcon, size = 18): SVGSVGElement { svg.setAttribute("width", String(size)); svg.setAttribute("height", String(size)); svg.setAttribute("fill", "none"); - svg.setAttribute("stroke", "currentColor"); - svg.setAttribute("stroke-width", "2"); - svg.setAttribute("stroke-linecap", "round"); - svg.setAttribute("stroke-linejoin", "round"); + svg.setAttribute("stroke-width", "1.5"); svg.setAttribute("aria-hidden", "true"); // Fixed path data of this module, never data from a document. svg.innerHTML = paths[name]; diff --git a/src/shell/messages.ts b/src/shell/messages.ts index 649a2149b..88d267371 100644 --- a/src/shell/messages.ts +++ b/src/shell/messages.ts @@ -11,100 +11,136 @@ export type ShellCopy = Readonly<{ dashboardSub: string; jump: string; jumpShortcut: string; - jumpTitle: string; - jumpEmpty: string; - settings: string; - settingsSub: string; + personal: string; + addOrganization: string; account: string; accountSub: string; - thisComputer: string; - personal: string; - organizationSub: string; - more: string; - moreNamed: string; - less: string; - lessNamed: string; - current: string; - kinds: Readonly>; + /** "{count} Environment(s)" by the Czech plural. */ + environmentsOne: string; + environmentsFew: string; + environmentsMany: string; + last: string; + /** The name of an Environment without its own name, by kind. */ + names: Readonly>; + /** Who an Environment is for, by kind. */ + who: Readonly>; + pick: string; + settings: string; + switcher: string; + searchIn: string; + searchAll: string; + organizationDashboard: string; + here: string; + noEnvironment: string; + nothing: string; + widen: string; + choose: string; + go: string; + close: string; switchLabel: string; chat: string; apps: string; automate: string; chatMissing: string; automateMissing: string; - close: string; }>; const en: ShellCopy = { - rail: "Environments and Organizations", + rail: "Organizations", dashboard: "Dashboard", dashboardSub: "Your overview across Organizations", jump: "Go to an Environment", jumpShortcut: "⌘⇧E", - jumpTitle: "Go to an Environment", - jumpEmpty: "No Environment matches.", - settings: "Environment Settings", - settingsSub: "Settings of this Environment", + personal: "Personal", + addOrganization: "Add an Organization", account: "Lazurio account", accountSub: "Account settings in the Dashboard", - thisComputer: "This computer", - personal: "Personal", - organizationSub: "Organization", - more: "+{count}", - moreNamed: "Show {count} more Environments of {name}", - less: "less", - lessNamed: "Show fewer Environments of {name}", - current: "you are here", - kinds: { - personal: "personal", - work: "work", + environmentsOne: "{count} Environment", + environmentsFew: "{count} Environments", + environmentsMany: "{count} Environments", + last: "last {name}", + names: { + personal: "Personal", + work: "Work", team: "Team", - automated: "automated", + automated: "Automated", + workstation: "This computer", + }, + who: { + personal: "only yours", + work: "work", + team: "shared by the Team", + automated: "automation", workstation: "this computer", }, + pick: "{name}, switch Environment", + settings: "Environment Settings", + switcher: "Go to an Environment", + searchIn: "Search in {name}…", + searchAll: "Environment or Organization…", + organizationDashboard: "Organization Dashboard", + here: "you are here", + noEnvironment: "You have no Environment here.", + nothing: "Nothing like that here.", + widen: "All Organizations", + choose: "choose", + go: "go", + close: "close", switchLabel: "Apps of this Environment", chat: "Chat", apps: "Apps", automate: "Automate", chatMissing: "Chat does not run on this Environment", automateMissing: "MausBot does not run on this Environment", - close: "Close", }; const cs: ShellCopy = { - rail: "Environmenty a Organizace", + rail: "Organizace", dashboard: "Dashboard", - dashboardSub: "Tvůj přehled napříč Organizacemi", + dashboardSub: "tvůj přehled napříč Organizacemi", jump: "Přejít na Environment", jumpShortcut: "⌘⇧E", - jumpTitle: "Přejít na Environment", - jumpEmpty: "Žádný Environment neodpovídá.", - settings: "Nastavení Environmentu", - settingsSub: "Nastavení tohoto Environmentu", + personal: "Osobní", + addOrganization: "Přidat organizaci", account: "Lazurio účet", accountSub: "Nastavení účtu v Dashboardu", - thisComputer: "Tento počítač", - personal: "Osobní", - organizationSub: "Organizace", - more: "+{count}", - moreNamed: "Ukázat dalších {count} Environmentů v {name}", - less: "méně", - lessNamed: "Ukázat méně Environmentů v {name}", - current: "tady jsi", - kinds: { - personal: "osobní", + environmentsOne: "{count} Environment", + environmentsFew: "{count} Environmenty", + environmentsMany: "{count} Environmentů", + last: "naposledy {name}", + names: { + personal: "Osobní", + work: "Pracovní", + team: "Týmový", + automated: "Automatizovaný", + workstation: "Tento počítač", + }, + who: { + personal: "jen tvůj", work: "pracovní", - team: "týmový", - automated: "automatizovaný", + team: "sdílený Teamem", + automated: "automatizace", workstation: "tento počítač", }, + pick: "{name}, přepnout Environment", + settings: "Nastavení Environmentu", + switcher: "Přejít na Environment", + searchIn: "Hledat v {name}…", + searchAll: "Environment nebo Organizace…", + organizationDashboard: "Dashboard Organizace", + here: "tady jsi", + noEnvironment: "Tady nemáš žádný Environment.", + nothing: "Nic takového tu není.", + widen: "Všechny Organizace", + choose: "vybrat", + go: "přejít", + close: "zavřít", switchLabel: "Aplikace Environmentu", chat: "Chat", apps: "Apps", automate: "Automate", chatMissing: "Chat na tomto Environmentu neběží", automateMissing: "MausBot na tomto Environmentu neběží", - close: "Zavřít", }; export const shellMessages = (locale: "cs" | "en"): ShellCopy => diff --git a/src/shell/styles.ts b/src/shell/styles.ts index 4bb8fce20..122817eb8 100644 --- a/src/shell/styles.ts +++ b/src/shell/styles.ts @@ -5,73 +5,131 @@ const tokens = vendorText("tokens.css"); // The styles of the shell elements, inside their shadow roots: the Lazurio // design system's tokens (vendored byte-for-byte, declared on `:root`, here // applied to `:host` so they hold inside the shadow root and nowhere else), -// and the components of the rail and the app switch after the shell -// wireframe (prototypes-lazurio, DEV-6639). Nothing here reaches the host -// page, and the host page's styles do not reach in. +// and the components of the rail, the Environment picker and the app switch +// after the shell wireframe (prototypes-lazurio 1cbad15, the Organization +// rail) and the design system's selection rule (design-system-lazurio +// 5bbc1f7, `lz-picker`, `lz-menu__head`: a quiet surface one step darker, +// full-weight text, a check with a word; no left edge, no shadow, no +// capitals). Nothing here reaches the host page, and the host page's styles +// do not reach in. /** The tokens, scoped to the element. */ export const hostTokens = tokens.replace(":root", ":host"); /** The width the rail takes; the host lays its content beside it with - * `margin-left: var(--lazurio-rail-width, 0)`. */ + * `padding-left: var(--lazurio-rail-width, 0px)`. */ export const railWidth = "72px"; const base = ` -:host { --env-accent: var(--lz-ink); font-family: var(--lz-font-sans); font-size: 15px; font-weight: 400; line-height: 1.4; letter-spacing: normal; text-align: left; text-transform: none; color: var(--lz-ink); -webkit-font-smoothing: antialiased; } +:host { font-family: var(--lz-font-sans); font-size: 15px; font-weight: 400; line-height: 1.4; letter-spacing: normal; text-align: left; text-transform: none; color: var(--lz-ink); -webkit-font-smoothing: antialiased; } *, *::before, *::after { box-sizing: border-box; } [hidden] { display: none !important; } -a, button { font: inherit; color: inherit; } +a, button, input { font: inherit; color: inherit; } :focus-visible { outline: 2px solid var(--lz-accent); outline-offset: 2px; } .sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; } +.org-mark { display: grid; flex: none; place-items: center; overflow: hidden; border-radius: var(--lz-radius-sm); background: var(--lz-white); box-shadow: inset 0 0 0 1px var(--lz-line); color: var(--lz-ink); font-weight: var(--lz-weight-akce); letter-spacing: 0.02em; } +.org-mark img { display: block; width: 100%; height: 100%; object-fit: cover; } +`; + +/** The list of Environments: under the picker (one space) and as the ⌘⇧E + * dialog (every space). */ +const switcherCss = ` +dialog.switcher-dialog { width: min(560px, 92vw); max-height: 64vh; margin: 12vh auto auto; padding: 0; border: 1px solid var(--lz-gray-300); border-radius: 14px; background: var(--lz-white); color: var(--lz-ink); } +dialog.switcher-dialog::backdrop { background: rgb(0 0 0 / 25%); } +.switcher-box { display: flex; flex-direction: column; max-height: inherit; overflow: hidden; background: var(--lz-white); } +.switcher-popover { position: fixed; inset: auto; margin: 0; padding: 0; max-height: min(72vh, 600px); border: 1px solid var(--lz-gray-300); border-radius: 12px; color: var(--lz-ink); } +.switcher-search { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--lz-line); color: var(--lz-ink-muted); } +.switcher-search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--lz-ink); font-size: 15px; } +.kbd { padding: 1px 6px; border: 1px solid var(--lz-line); border-radius: 6px; color: var(--lz-ink-muted); font-family: var(--lz-font-mono); font-size: 11px; } +.switcher-list { overflow: auto; padding: 6px 8px 10px; } +.switcher-title { padding: 8px 8px 4px; color: var(--lz-ink-muted); font-size: 12px; font-weight: var(--lz-weight-akce); } +.switcher-head { display: flex; width: 100%; align-items: center; gap: 8px; margin: 4px 0 2px; padding: 7px 8px; border-bottom: 1px solid var(--lz-line-faint); border-radius: 8px 8px 0 0; color: var(--lz-ink); font-size: 13px; font-weight: var(--lz-weight-akce); text-decoration: none; } +.switcher-head .org-mark { width: 20px; height: 20px; border-radius: 5px; font-size: 8px; } +.switcher-head-meta { margin-left: auto; color: var(--lz-ink-muted); font-weight: 400; } +.switcher-row { display: flex; width: 100%; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 8px; color: var(--lz-ink); font-size: 14px; text-decoration: none; } +.is-cursor { background: var(--lz-gray-50); } +.switcher-row[aria-current="page"], .switcher-head[aria-current="page"] { background: var(--lz-gray-100); } +.switcher-glyph { display: grid; width: 26px; height: 26px; flex: none; place-items: center; border-radius: 7px; background: var(--lz-gray-50); color: var(--lz-ink-muted); font-size: 11px; font-weight: 700; } +.switcher-row[aria-current="page"] .switcher-glyph { background: var(--lz-white); color: var(--lz-ink); } +.switcher-name { flex: none; font-weight: 550; white-space: nowrap; } +.switcher-row[aria-current="page"] .switcher-name { font-weight: var(--lz-weight-akce); } +.switcher-who { flex: 1; min-width: 0; overflow: hidden; color: var(--lz-ink-muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; } +.switcher-here { display: flex; flex: none; align-items: center; gap: 4px; color: var(--lz-ink); font-size: 12px; font-weight: var(--lz-weight-akce); } +.switcher-empty { margin: 0; padding: 6px 8px; color: var(--lz-ink-muted); font-size: 13px; } +.switcher-foot { display: flex; align-items: center; gap: 14px; padding: 8px 14px; border-top: 1px solid var(--lz-line); color: var(--lz-ink-muted); font-size: 12px; white-space: nowrap; } +.switcher-widen { display: flex; align-items: center; gap: 6px; margin-right: auto; padding: 3px 8px; border: 1px solid var(--lz-line); border-radius: 8px; background: var(--lz-white); color: var(--lz-ink); font-size: 12px; font-weight: 550; cursor: pointer; } +.switcher-widen:hover { background: var(--lz-gray-50); } `; export const railCss = `${hostTokens} ${base} +${switcherCss} :host { position: fixed; inset: 0 auto 0 0; z-index: 40; display: block; width: ${railWidth}; background: var(--lz-gray-50); } nav { display: flex; height: 100%; flex-direction: column; align-items: center; gap: 6px; padding: 12px 0; } -.item { position: relative; display: grid; width: 44px; height: 44px; flex: none; place-items: center; padding: 0; border: 0; border-radius: var(--lz-radius-md); background: var(--lz-gray-100); color: var(--lz-ink-muted); cursor: pointer; text-decoration: none; transition: border-radius 120ms ease; } +.item { position: relative; display: grid; width: 44px; height: 44px; flex: none; place-items: center; padding: 0; border: 0; border-radius: var(--lz-radius-md); background: transparent; color: var(--lz-ink-muted); cursor: pointer; text-decoration: none; transition: border-radius 120ms ease; } .item:hover { color: var(--lz-ink); border-radius: 14px; } -.home, .utility, .account { background: transparent; } .home img { width: 30px; height: 30px; display: block; } .search { width: 36px; height: 32px; } .divider { width: 32px; height: 1px; margin: 4px 0; flex: none; background: var(--lz-line); } .scroll { display: flex; width: 100%; min-height: 0; flex: 1; flex-direction: column; align-items: center; gap: 6px; padding: 8px 0 10px; overflow-x: hidden; overflow-y: auto; scrollbar-width: none; } .scroll::-webkit-scrollbar { display: none; } -.env .initials { font-size: 13px; font-weight: 700; letter-spacing: 0.02em; } -.folder { display: flex; flex: none; flex-direction: column; align-items: center; gap: 4px; padding: 4px; border-radius: 14px; background: color-mix(in srgb, var(--env-accent) 18%, var(--lz-white)); } -.folder.has-active { box-shadow: inset 0 0 0 2px var(--env-accent); } -.folder .env { width: 40px; height: 40px; background: var(--lz-white); } -.env[aria-current="page"], .folder .env[aria-current="page"] { background: var(--env-accent); color: var(--lz-white); box-shadow: 0 0 0 2px var(--lz-white), 0 0 0 4.5px var(--env-accent), 0 4px 14px color-mix(in srgb, var(--env-accent) 45%, transparent); } -.env[aria-current="page"]::before { position: absolute; left: -14px; width: 5px; height: 36px; border-radius: 0 4px 4px 0; background: var(--env-accent); content: ""; } -.folder .env[aria-current="page"]::before { left: -18px; } -.folder-head { display: grid; width: 40px; height: 32px; place-items: center; } -.mark { display: grid; width: 24px; height: 24px; place-items: center; overflow: hidden; border-radius: var(--lz-radius-sm); background: var(--lz-white); box-shadow: inset 0 0 0 1px var(--lz-line); color: var(--lz-ink); font-size: 10px; font-weight: 600; letter-spacing: 0.02em; } -.mark img { display: block; width: 100%; height: 100%; object-fit: cover; } -.more { display: grid; width: 40px; height: 22px; place-items: center; padding: 0; border: 0; border-radius: 999px; background: var(--lz-white); color: var(--lz-ink-muted); cursor: pointer; font-size: 11px; font-weight: 650; } -.avatar { display: grid; width: 36px; height: 36px; place-items: center; border-radius: 50%; background: var(--lz-ink); color: var(--lz-white); font-size: 13px; font-weight: 600; } +.space .org-mark, .space .initials { width: 40px; height: 40px; border-radius: 12px; transition: border-radius 120ms ease; } +.space:hover .org-mark, .space:hover .initials { border-radius: 14px; } +.space .org-mark { font-size: 12px; } +.space .initials { display: grid; place-items: center; background: var(--lz-ink); color: var(--lz-white); font-size: 13px; font-weight: 700; letter-spacing: 0.02em; } +.space[aria-current="true"] .org-mark, .space[aria-current="true"] .initials { box-shadow: 0 0 0 2px var(--lz-paper), 0 0 0 4px var(--lz-ink); } +.add { border: 1px dashed var(--lz-line); } +.account .avatar { display: grid; width: 36px; height: 36px; place-items: center; overflow: hidden; border-radius: 50%; background: var(--lz-ink); color: var(--lz-white); font-size: 13px; font-weight: var(--lz-weight-akce); object-fit: cover; } .tip { position: fixed; z-index: 60; display: grid; max-width: 260px; padding: 6px 10px; border-radius: var(--lz-radius-sm); background: var(--lz-ink); color: var(--lz-white); font-size: 13px; line-height: 1.3; pointer-events: none; transform: translateY(-50%); box-shadow: 0 4px 14px rgb(0 0 0 / 18%); } .tip strong { font-weight: 600; } .tip span { color: rgb(255 255 255 / 70%); font-size: 12px; } .tip span:empty { display: none; } -dialog { width: min(28rem, calc(100vw - 2rem)); padding: 0; border: 1px solid var(--lz-line); border-radius: 14px; background: var(--lz-white); color: var(--lz-ink); box-shadow: 0 24px 64px -24px rgb(0 0 0 / 55%); font-family: var(--lz-font-sans); } -dialog::backdrop { background: rgb(0 0 0 / 28%); } -.jump-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--lz-line-faint); color: var(--lz-ink-muted); } -.jump-head input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--lz-ink); font: inherit; font-size: 15px; } -.jump-list { display: grid; gap: 2px; max-height: 50vh; margin: 0; padding: 6px; overflow-y: auto; list-style: none; } -.jump-list a { display: grid; gap: 1px; padding: 8px 10px; border-radius: var(--lz-radius-sm); text-decoration: none; } -.jump-list a:hover, .jump-list a:focus-visible { background: var(--lz-gray-100); outline: none; } -.jump-list strong { font-size: 14px; font-weight: 600; } -.jump-list span { color: var(--lz-ink-muted); font-size: 12.5px; } -.jump-empty { padding: 10px 14px 14px; color: var(--lz-ink-muted); font-size: 13px; } -@media (prefers-reduced-motion: reduce) { .item { transition: none; } } +@media (prefers-reduced-motion: reduce) { .item, .space .org-mark, .space .initials { transition: none; } } `; export const columnHeadCss = `${hostTokens} ${base} +${switcherCss} :host { display: block; } -nav { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; padding: 3px; border-radius: var(--lz-radius-md); background: var(--lz-gray-100); } +.head { display: flex; flex-direction: column; gap: 8px; } +.row { display: flex; align-items: stretch; gap: 6px; } +.pick { display: flex; flex: 1; min-width: 0; align-items: center; gap: 10px; padding: 7px 8px; border: 0; border-radius: var(--lz-radius-md); background: transparent; color: var(--lz-ink); text-align: left; cursor: pointer; } +.pick:hover, .pick[aria-expanded="true"] { background: var(--lz-gray-100); } +.pick-glyph { display: grid; width: 30px; height: 30px; flex: none; place-items: center; border-radius: 8px; color: var(--lz-ink); font-size: 11px; font-weight: 700; } +.pick-glyph .org-mark { width: 24px; height: 24px; font-size: 9px; } +.pick-glyph .initials { display: grid; width: 24px; height: 24px; place-items: center; border-radius: 6px; background: var(--lz-ink); color: var(--lz-white); } +.pick-text { display: grid; flex: 1; min-width: 0; line-height: 1.25; } +.pick-title, .pick-who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } +.pick-title { font-size: 14px; font-weight: 650; } +.pick-who { color: var(--lz-ink-muted); font-size: 12px; } +.pick > svg { flex: none; color: var(--lz-ink-muted); transition: transform 0.15s; } +.pick[aria-expanded="true"] > svg { transform: rotate(180deg); } +.gear { display: grid; width: 40px; flex: none; place-items: center; border-radius: var(--lz-radius-md); color: var(--lz-ink-muted); text-decoration: none; } +.gear:hover, .gear[aria-current="page"] { background: var(--lz-gray-100); color: var(--lz-ink); } +nav.switch { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; padding: 3px; border-radius: var(--lz-radius-md); background: var(--lz-gray-100); } .tab { display: flex; min-width: 0; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px 5px; border-radius: calc(var(--lz-radius-md) - 2px); color: var(--lz-ink-muted); font-size: 11px; font-weight: 550; line-height: 1.25; text-decoration: none; } a.tab:hover { color: var(--lz-ink); } .tab[aria-current="page"] { background: var(--lz-white); box-shadow: 0 1px 2px rgb(0 0 0 / 0.08); color: var(--lz-ink); } .tab[aria-disabled="true"] { opacity: 0.4; cursor: not-allowed; } +/* A dark host (data-host-tone="dark", from --lazurio-host-tone or the host's + background): no frame, light text, a translucent hover. */ +:host([data-host-tone="dark"]) { color: #fff; } +:host([data-host-tone="dark"]) .pick { color: #fff; } +:host([data-host-tone="dark"]) .pick-who, :host([data-host-tone="dark"]) .pick > svg, :host([data-host-tone="dark"]) .gear { color: rgb(255 255 255 / 0.65); } +:host([data-host-tone="dark"]) .pick:hover, :host([data-host-tone="dark"]) .pick[aria-expanded="true"], :host([data-host-tone="dark"]) .gear:hover, :host([data-host-tone="dark"]) .gear[aria-current="page"] { background: rgb(255 255 255 / 0.1); color: #fff; } +:host([data-host-tone="dark"]) nav.switch { background: rgb(255 255 255 / 0.06); } +:host([data-host-tone="dark"]) .tab { color: rgb(255 255 255 / 0.65); } +:host([data-host-tone="dark"]) a.tab:hover { color: #fff; } +:host([data-host-tone="dark"]) .tab[aria-current="page"] { background: rgb(255 255 255 / 0.12); box-shadow: none; color: #fff; } +/* A narrow host (a fork's icon-only sidebar): the glyphs alone. */ +:host { container-type: inline-size; } +@container (max-width: 160px) { + .row { flex-direction: column; align-items: center; } + .pick { flex: none; justify-content: center; padding: 7px; } + .pick-text, .pick > svg { display: none; } + .gear { width: 40px; height: 40px; } + nav.switch { grid-template-columns: 1fr; } + .tab span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; } +} +@media (prefers-reduced-motion: reduce) { .pick > svg { transition: none; } } `; diff --git a/src/shell/vendor/LICENSE-iconoir.txt b/src/shell/vendor/LICENSE-iconoir.txt new file mode 100644 index 000000000..29a34a856 --- /dev/null +++ b/src/shell/vendor/LICENSE-iconoir.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Luca Burgio + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/src/shell/vendor/README.md b/src/shell/vendor/README.md index 8255f2529..70ca41381 100644 --- a/src/shell/vendor/README.md +++ b/src/shell/vendor/README.md @@ -7,12 +7,16 @@ source with new hashes in this file, reviewed like code (decision F36). ## Lazurio design system Source: `HumanAndMachine-ai/design-system-lazurio` at commit -`4439aef645b7432181216aab3799d7f7819d6592` (2026-10-03, "Prvky: Describe the -Environment rail target of 2026-10-03 (#53)"). The bytes of both files are the -same at `089d6cfbb5386a00e4a9f296f9f10b2901668f11`, the commit the shell -wireframe (`prototypes-lazurio`, branch `agent/DEV-6639-shell-iteration-2`) -vendors. Matěj allowed publishing these brand assets in this public repository -(2026-10-03). +`5bbc1f78fc5a10f0dcf8936bf54d27da2e2eeafb` (2026-10-04, "Prvky: selection is a +quiet surface; picker and Organization head (variant A) (#54)"). That commit +changed only `components.css` and the prvky documentation: the bytes of every +file below are the same as at the earlier pin +`4439aef645b7432181216aab3799d7f7819d6592` and at +`089d6cfbb5386a00e4a9f296f9f10b2901668f11`, the commit the first shell +wireframe vendored. The shell draws its own components from the tokens and +mirrors #54's rules (`lz-picker`, `lz-menu__head`, the quiet selected +surface) in `src/shell/styles.ts`. Matěj allowed publishing these brand assets +in this public repository (2026-10-03). | File | Source path | SHA-256 | | --- | --- | --- | @@ -30,7 +34,7 @@ system asks for the rail in the forks. The design system's Lazurio stones (`content/brand/icons/*-96.png`, Lazurio's own artwork, 96 × 96 px, drawn at 48 × 48 on a tile and 20 × 20 in a list), byte-for-byte -from the same commit `4439aef645b7432181216aab3799d7f7819d6592`. `src/shell/stones.ts` +from the same commit (unchanged since `4439aef645b7432181216aab3799d7f7819d6592`). `src/shell/stones.ts` picks one by a generic semantic key only (the app's declared `icon`, or the org-agnostic fallback of the root Launchpad), never by an Organization or a module's name, as `content/brand/icons/icons.md` and the root Launchpad's @@ -74,3 +78,17 @@ files from `package/files/` and `package/LICENSE`. | `fonts/geist-mono-latin-ext-400-normal.woff2` | `8ede9cb664d0e0446ed066201d58e444f6147645ae0cb1108f765f68c54fe0a4` | | `fonts/LICENSE-inter-tight.txt` | `1e1c8b3dc6dfcbd5498a33f17fcc68ff2d39c599f6e8195fbf14601261dbef6a` | | `fonts/LICENSE-geist-mono.txt` | `cc815ed4fc045f0e991abb10395b7932bd028c6a067deb13316d6002105074e6` | + +## Interface icons + +The shell and the Launchpad page draw their interface icons from Iconoir +(MIT, https://iconoir.com), the set the design system mandates for the +interface (`content/brand/icons/icons.md`). The path data is copied exactly as +the shell wireframe draws it (`HumanAndMachine-ai/prototypes-lazurio` 1cbad15, +`app/v1/src/Icon.tsx`, `iconoir-react` 7.12.1) into `src/shell/icons.ts` and the +page's inlined symbols. Its licence is copied byte-for-byte from the design +system at the pinned commit (`content/brand/icons/LICENSE-iconoir.txt`). + +| File | Source path | SHA-256 | +| --- | --- | --- | +| `LICENSE-iconoir.txt` | `content/brand/icons/LICENSE-iconoir.txt` | `869b60da1ada5b896d1f285c3c24ca193d612e308d1710a77a58f2f572eb4fa2` | diff --git a/src/shell/view.ts b/src/shell/view.ts index 4043f32c5..a0445a1b3 100644 --- a/src/shell/view.ts +++ b/src/shell/view.ts @@ -2,66 +2,24 @@ import { currentEnvironment, type Shell, type ShellEnvironment, - type ShellEnvironmentKind, type ShellOrganization, } from "./contract"; import { fillShell, type ShellCopy } from "./messages"; -// Pure presentation of the shell document for the rail and the app switch -// (decision F36, the target shell of docs/launchpad-development.md): what -// each element shows, in which order, linked where. The elements in -// elements.ts only draw it. +// Pure presentation of the shell document (decision F36, addendum of +// 2026-10-04): the rail of spaces (your personal space, then one avatar per +// Organization), the Environment picker at the head of the left column with +// its list, and the switch Chat · Apps · Automate. The elements in +// elements.ts only draw it. Every Environment is named one way everywhere: +// by its own name or its kind, with a line saying who it is for, never by +// the machine's technical name. -/** At most this many Environments of one folder show before "+N". */ -export const folderLimit = 6; +/** A space of the rail: your personal space or one Organization. */ +export const personalSpace = "personal"; -export type RailMark = - | Readonly<{ kind: "initials"; text: string }> - | Readonly<{ - kind: "icon"; - icon: "laptop" | "user" | "users" | "bot"; - }>; - -export type RailItem = Readonly<{ - id: string; - /** The first line of the label. */ - label: string; - /** The second line: Organization · kind (· you are here). */ - sub: string; - href: string; - active: boolean; - mark: RailMark; - /** The fill of the active item: the Organization's accent, or null for - * the design system's ink (personal) or accent (Organization). */ - accent: string | null; -}>; - -export type RailFolder = Readonly<{ - organization: ShellOrganization; - /** The avatar, or the initials when there is none. */ - initials: string; - items: readonly RailItem[]; - /** How many are folded behind "+N" (0 when all show). */ - hidden: number; - /** Whether "less" folds them again. */ - expanded: boolean; - hasActive: boolean; -}>; - -export type RailModel = Readonly<{ - personal: readonly RailItem[]; - folders: readonly RailFolder[]; -}>; - -const kindIcons: Readonly< - Record -> = { - personal: "user", - work: "user", - team: "users", - automated: "bot", - workstation: "laptop", -}; +/** The app a link of the shell leads into. */ +export const shellApps = ["chat", "apps", "automate"] as const; +export type ShellApp = (typeof shellApps)[number]; /** Up to two letters of a name: the first letters of its first two words, * else its first two letters. */ @@ -79,109 +37,285 @@ export function initialsOf(name: string): string { .toLocaleUpperCase(); } -/** The name an Environment is shown under. */ -export function environmentLabel( +/** The name an Environment is shown under: its own, else its kind's. */ +export const environmentName = ( environment: ShellEnvironment, copy: ShellCopy, -): string { - return environment.label ?? copy.thisComputer; +): string => environment.label ?? copy.names[environment.kind]; + +/** Who an Environment is for: a work Environment's person, otherwise its + * kind's word. */ +export const environmentWho = ( + environment: ShellEnvironment, + copy: ShellCopy, +): string => + environment.kind === "work" && environment.assignee !== null + ? `@${environment.assignee}` + : copy.who[environment.kind]; + +const sameSlug = (left: string, right: string) => + left.toLowerCase() === right.toLowerCase(); + +/** The Organization of a slug the document lists. */ +export const organizationOf = ( + shell: Shell, + slug: string, +): ShellOrganization | undefined => + shell.organizations.find((entry) => sameSlug(entry.slug, slug)); + +/** The space you are in: the one the host names (`space`, a workstation + * opened for one Organization), otherwise the current Environment's: a + * personal one or a workstation is personal, any other its first + * Organization's. */ +export function hereOf(shell: Shell, space: string | null): string { + if ( + space !== null && + (space === personalSpace || organizationOf(shell, space) !== undefined) + ) + return space === personalSpace + ? space + : (organizationOf(shell, space)?.slug ?? space); + const current = currentEnvironment(shell); + return current.kind === "personal" || + current.kind === "workstation" || + current.organizations.length === 0 + ? personalSpace + : (current.organizations[0] ?? personalSpace); } -function item( +/** The Environments of a space, in document order: your personal ones and + * workstations for the personal space, and for an Organization those that + * hold it (a workstation holding it among them). */ +export function spaceEnvironments( shell: Shell, + space: string, +): readonly ShellEnvironment[] { + if (space === personalSpace) + return shell.environments.filter( + (entry) => + entry.kind === "personal" || + entry.kind === "workstation" || + entry.organizations.length === 0, + ); + const own = shell.environments.filter( + (entry) => + entry.kind !== "workstation" && + entry.organizations.some((slug) => sameSlug(slug, space)), + ); + const workstations = shell.environments.filter( + (entry) => + entry.kind === "workstation" && + entry.organizations.some((slug) => sameSlug(slug, space)), + ); + return [...own, ...workstations]; +} + +/** Where a link to an Environment leads, in a space and an app: the app's + * origin, Apps where the Environment has not that app; a workstation holding + * several Organizations opens Apps for the space's (`o/`, the + * Launchpad's route of one Organization). */ +export function environmentHref( environment: ShellEnvironment, - copy: ShellCopy, - accent: string | null, -): RailItem { - const active = environment.id === shell.current; - const where = environment.organizations - .map( - (slug) => - shell.organizations.find( - (entry) => entry.slug.toLowerCase() === slug.toLowerCase(), - )?.name ?? slug, - ) - .join(", "); - const personal = environment.kind === "personal"; - const mark: RailMark = - personal && shell.operator.initials !== null - ? { kind: "initials", text: shell.operator.initials } - : { kind: "icon", icon: kindIcons[environment.kind] }; - return Object.freeze({ - id: environment.id, - label: environmentLabel(environment, copy), - sub: [ - personal && shell.operator.login !== null - ? `@${shell.operator.login}` - : where, - copy.kinds[environment.kind], - active ? copy.current : "", - ] - .filter((part) => part !== "") - .join(" · "), - href: environment.apps.apps, - active, - mark, - accent, - }); + space: string, + app: ShellApp, +): string { + const base = + app === "chat" + ? environment.apps.chat + : app === "automate" + ? environment.apps.automate + : null; + if (base !== null) return base; + const apps = environment.apps.apps; + if (space === personalSpace || environment.organizations.length < 2) + return apps; + const root = apps.endsWith("/") ? apps : `${apps}/`; + return `${root}o/${encodeURIComponent(space)}`; } -/** The rail: first the personal Environments (personal Remote Environments - * and workstations, in document order), then one folder per Organization - * with the Environments that belong to it, in the order of - * `organizations`. A workstation holding several Organizations is personal: - * it is the person's own computer. A folder shows the first `folderLimit` - * Environments, plus the active one if it is further down; `expanded` lists - * the folders the person unfolded. An Organization without an Environment - * in the document has no folder. */ -export function railModel( +const pluralKey = (count: number) => + count === 1 + ? "environmentsOne" + : count >= 2 && count <= 4 + ? "environmentsFew" + : "environmentsMany"; + +export type RailSpace = Readonly<{ + space: string; + /** The label's first line. */ + title: string; + /** Its second line: how many Environments, and the last one. */ + sub: string; + href: string; + active: boolean; + /** The Organization's avatar or initials; the personal space's initials. */ + avatar: string | null; + initials: string | null; +}>; + +/** The rail: your personal space, then every Organization of the document + * in its order. A click leads to the space's last Environment (`last`, by + * space, what this browser remembers), else its first, in the same app; + * a space without one leads to its Dashboard. */ +export function railSpaces( shell: Shell, copy: ShellCopy, - expanded: ReadonlySet = new Set(), -): RailModel { - const personal = shell.environments - .filter( - (environment) => - environment.kind === "personal" || - environment.kind === "workstation" || - environment.organizations.length === 0, - ) - .map((environment) => item(shell, environment, copy, null)); - const folders = shell.organizations.flatMap((organization): RailFolder[] => { - const own = shell.environments.filter( - (environment) => - environment.kind !== "personal" && - environment.kind !== "workstation" && - environment.organizations[0]?.toLowerCase() === - organization.slug.toLowerCase(), - ); - if (own.length === 0) return []; - const items = own.map((environment) => - item(shell, environment, copy, organization.accent), - ); - const open = expanded.has(organization.slug); - const visible = open - ? items - : items.filter((entry, index) => index < folderLimit || entry.active); - return [ - Object.freeze({ - organization, + options: Readonly<{ + here: string; + app: ShellApp; + last: (space: string) => string | null; + }>, +): readonly RailSpace[] { + const space = ( + id: string, + title: string, + dashboard: string, + marks: Readonly<{ avatar: string | null; initials: string | null }>, + ): RailSpace => { + const environments = spaceEnvironments(shell, id); + const remembered = options.last(id); + const last = environments.find((entry) => entry.id === remembered); + const target = last ?? environments[0]; + return Object.freeze({ + space: id, + title, + sub: [ + fillShell(copy[pluralKey(environments.length)], { + count: environments.length, + }), + last === undefined + ? null + : fillShell(copy.last, { name: environmentName(last, copy) }), + ] + .filter((part) => part !== null) + .join(" · "), + href: + target === undefined + ? dashboard + : environmentHref(target, id, options.app), + active: options.here === id, + ...marks, + }); + }; + return [ + space(personalSpace, copy.personal, shell.dashboard, { + avatar: null, + initials: shell.operator.initials, + }), + ...shell.organizations.map((organization) => + space(organization.slug, organization.name, organization.dashboard, { + avatar: organization.avatar, initials: initialsOf(organization.name), - items: Object.freeze(visible), - hidden: items.length - visible.length, - expanded: open && items.length > folderLimit, - hasActive: items.some((entry) => entry.active), }), - ]; - }); - return Object.freeze({ - personal: Object.freeze(personal), - folders: Object.freeze(folders), - }); + ), + ]; } -export const shellApps = ["chat", "apps", "automate"] as const; -export type ShellApp = (typeof shellApps)[number]; +/** What the picker shows of an Environment: its glyph, its name and who it + * is for. The glyph is the Organization's avatar where it belongs to one, + * your initials for a personal one, and the kind's icon otherwise. */ +export type EnvironmentGlyph = + | Readonly<{ kind: "avatar"; organization: ShellOrganization }> + | Readonly<{ kind: "initials"; text: string }> + | Readonly<{ kind: "icon"; icon: "laptop" | "user" | "users" | "bot" }>; + +const kindIcons = { + personal: "user", + work: "user", + team: "users", + automated: "bot", + workstation: "laptop", +} as const; + +export function environmentGlyph( + shell: Shell, + environment: ShellEnvironment, + space: string, +): EnvironmentGlyph { + if (environment.kind === "personal" && shell.operator.initials !== null) + return { kind: "initials", text: shell.operator.initials }; + const organization = + space === personalSpace ? undefined : organizationOf(shell, space); + return organization !== undefined + ? { kind: "avatar", organization } + : { kind: "icon", icon: kindIcons[environment.kind] }; +} + +export type SwitcherRow = Readonly<{ + id: string; + name: string; + who: string; + href: string; + current: boolean; + /** A row's glyph: your initials for a personal Environment, otherwise its + * kind's icon (the Organization stands in the head above). */ + glyph: Exclude; +}>; + +export type SwitcherSection = Readonly<{ + space: string; + title: string; + /** An Organization's head above its Environments: its Dashboard. */ + head: Readonly<{ + organization: ShellOrganization; + href: string; + }> | null; + rows: readonly SwitcherRow[]; +}>; + +/** The list of the picker (one space, `all` false) and of ⌘⇧E (every space, + * `all` true): your personal Environments, then each Organization with its + * head and its Environments, the current one marked, filtered by `query` + * against the space, the name and who it is for. A space keeps its head + * while it matches and stays listed empty only when it is the one asked + * for. */ +export function switcherSections( + shell: Shell, + copy: ShellCopy, + options: Readonly<{ + here: string; + all: boolean; + app: ShellApp; + query: string; + }>, +): readonly SwitcherSection[] { + const words = options.query.trim().toLocaleLowerCase(); + const matches = (...parts: string[]) => + words === "" || parts.join(" ").toLocaleLowerCase().includes(words); + const row = (environment: ShellEnvironment, space: string): SwitcherRow => { + const glyph: SwitcherRow["glyph"] = + environment.kind === "personal" && shell.operator.initials !== null + ? { kind: "initials", text: shell.operator.initials } + : { kind: "icon", icon: kindIcons[environment.kind] }; + return Object.freeze({ + id: environment.id, + name: environmentName(environment, copy), + who: environmentWho(environment, copy), + href: environmentHref(environment, space, options.app), + current: environment.id === shell.current && options.here === space, + glyph, + }); + }; + const spaces = options.all + ? [personalSpace, ...shell.organizations.map((entry) => entry.slug)] + : [options.here]; + return spaces.flatMap((space): SwitcherSection[] => { + const organization = + space === personalSpace ? undefined : organizationOf(shell, space); + const title = organization?.name ?? copy.personal; + const rows = spaceEnvironments(shell, space) + .map((environment) => row(environment, space)) + .filter((entry) => matches(title, entry.name, entry.who)); + const head = + organization !== undefined && + matches(organization.name, copy.organizationDashboard) + ? { organization, href: organization.dashboard } + : null; + if (rows.length === 0 && head === null && (options.all || words !== "")) + return []; + return [Object.freeze({ space, title, head, rows: Object.freeze(rows) })]; + }); +} export type SwitchTab = Readonly<{ app: ShellApp; @@ -221,47 +355,3 @@ export function switchTabs( }), ); } - -/** The jump list of ⌘⇧E: every Environment of the document whose label, - * Organization or kind contains the query, the current one first. */ -export function jumpList( - shell: Shell, - copy: ShellCopy, - query: string, -): readonly RailItem[] { - const model = railModel( - shell, - copy, - new Set(shell.organizations.map((organization) => organization.slug)), - ); - const all = [ - ...model.personal, - ...model.folders.flatMap((folder) => folder.items), - ]; - const needle = query.trim().toLocaleLowerCase(); - return all - .filter( - (entry) => - needle === "" || - `${entry.label} ${entry.sub}`.toLocaleLowerCase().includes(needle), - ) - .sort((left, right) => Number(right.active) - Number(left.active)); -} - -/** The "+N" button's words. */ -export const moreText = ( - copy: ShellCopy, - folder: RailFolder, -): Readonly<{ text: string; label: string }> => - folder.expanded - ? { - text: copy.less, - label: fillShell(copy.lessNamed, { name: folder.organization.name }), - } - : { - text: fillShell(copy.more, { count: folder.hidden }), - label: fillShell(copy.moreNamed, { - count: folder.hidden, - name: folder.organization.name, - }), - }; diff --git a/tests/apps-view.test.ts b/tests/apps-view.test.ts index 178830e7d..53f7a0454 100644 --- a/tests/apps-view.test.ts +++ b/tests/apps-view.test.ts @@ -3,17 +3,26 @@ import { createHash } from "node:crypto"; import { readFile } from "node:fs/promises"; import { join } from "node:path"; import { - appsMatch, appsScope, appsSections, + favoriteTiles, moduleDescription, moduleName, moduleStone, + newModulePrompt, pluralKey, tileTarget, } from "../src/launchpad/apps-view"; import { parseCatalog } from "../src/launchpad/catalog-view"; import type { PublicEntry } from "../src/launchpad/chat"; +import { + favoritesFirst, + favoritesKey, + moduleFavorite, + parseFavorites, + repositoryFavorite, + toggleFavorite, +} from "../src/launchpad/favorites"; import { messages } from "../src/launchpad/messages"; import type { Catalog, @@ -22,11 +31,13 @@ import type { CatalogRepository, } from "../src/organizations/catalog"; -// Decision F36: the Apps home as pure functions, like the catalog's view -// tests. One Organization at a time, its two sections Workspace (every -// module) and Productionspace (production repositories, read-only) with -// counts, and where each tile leads: the module's own origin hosted, -// start-then-open locally, the overview without an app. +// Decision F36 and its addendum of 2026-10-04: the Apps home as pure +// functions, like the catalog's view tests. One Organization at a time, its +// two sections Workspace (every module) and Productionspace (production +// repositories, read-only) with counts, clean tiles, favourites first, and +// what a tile does: the module's app on its own origin hosted, +// start-then-open locally, otherwise a short message in the wireframe's +// words. const cs = messages("cs"); const en = messages("en"); @@ -137,7 +148,7 @@ test("the home shows the first Organization; an Organization or module route its ).toBeNull(); }); -test("two sections, Workspace with every module in catalog order and Productionspace read-only, with Czech counts; status only by exception; a module without an app is no failure", () => { +test("two sections, Workspace with every module in catalog order and Productionspace read-only, with Czech counts and no subtitles; clean tiles", () => { const group = appsScope(catalog, { view: "home" }, cs); if (group === null) throw new Error("The fixture has an Organization"); const sections = appsSections(catalog, group, cs, null); @@ -146,7 +157,6 @@ test("two sections, Workspace with every module in catalog order and Productions section.kind, section.title, section.count, - section.subtitle, section.tiles.map((tile) => tile.name), ]), ).toEqual([ @@ -154,26 +164,14 @@ test("two sections, Workspace with every module in catalog order and Productions "workspace", "Workspace", "5 modulů", - "Example Company Workspace", ["Mission Control", "Knowledgebase", "deals", "website", "notes"], ], - [ - "productionspace", - "Productionspace", - "1 repozitář", - "Repozitáře Organizace s vlastním releasem, jen pro čtení", - ["firmware"], - ], + ["productionspace", "Productionspace", "1 repozitář", ["firmware"]], ]); + expect(sections.some((section) => "subtitle" in section)).toBe(false); const [mission, ...workspace] = sections[0]?.tiles ?? []; - expect(workspace.map((tile) => tile.note?.text ?? null)).toEqual([ - null, - null, - "Nelze spustit", - null, - ]); // The declared description first, otherwise the org-agnostic sentence of - // the stone's key; "No app" without an app. + // the stone's key; "No app" without an app. No status row on a tile. expect( workspace.map((tile) => [ tile.name, @@ -198,19 +196,41 @@ test("two sections, Workspace with every module in catalog order and Productions ], ["notes", "Bez aplikace", "/.lazurio/stones/clients-96.png"], ]); + expect(workspace.some((tile) => "note" in tile)).toBe(false); expect(mission?.name).toBe("Mission Control"); expect(mission?.kind === "module" && mission.stone).toEqual({ key: "control", src: "/.lazurio/stones/mission-control-96.png", accent: "var(--lz-blue-500)", }); - const firmware = sections[1]?.tiles[0]; - expect(firmware?.kind === "repository" && firmware.href).toBe(null); - expect(firmware?.note?.text).toBe("Nenaklonovaný"); - expect(firmware?.note?.tone).toBe("muted"); + // The menu's "Informace o modulu" is the module's overview. + expect(mission?.info).toBe("/o/example/mission-control"); +}); + +test("what a tile does: open the app, or say why not, in the wireframe's words", () => { + const group = appsScope(catalog, { view: "home" }, cs); + if (group === null) throw new Error("The fixture has an Organization"); + const [workspace, productionspace] = appsSections(catalog, group, cs, entry); + expect( + workspace?.tiles.map((tile) => + tile.action.kind === "open" ? tile.action.target.kind : tile.action.text, + ), + ).toEqual([ + "hosted", + "hosted", + "hosted", + "Aplikace modulu website teď nejde spustit.", + "Modul notes zatím nemá aplikaci.", + ]); + expect(productionspace?.tiles[0]?.action).toEqual({ + kind: "say", + text: "Repozitář firmware nemá aplikaci.", + }); + // A repository has no page: its menu leads at most to its GitHub page. + expect(productionspace?.tiles[0]?.info).toBeNull(); }); -test("a production repository's tile has no action: no lifecycle target, no page, no status dot; at most its GitHub page", () => { +test("a production repository's tile: read-only, no stone, its GitHub page as its information", () => { const connect: CatalogRepository = { slug: "connect", path: "productionspace/connect", @@ -229,20 +249,75 @@ test("a production repository's tile has no action: no lifecycle target, no page expect(productionspace?.tiles).toEqual([ { kind: "repository", + key: "r:connect", repository: connect, name: "connect", description: "productionspace/connect", - note: null, - href: "https://github.com/example/connect", + action: { kind: "say", text: "The repository connect has no app." }, + info: "https://github.com/example/connect", + favorite: false, }, ]); - // Nothing a module tile has: no target to start or open, no stone. - const [tile] = productionspace?.tiles ?? []; - expect(tile && "target" in tile).toBe(false); - expect(tile && "stone" in tile).toBe(false); } }); +test("favourites: first in their section in the column's order, in the column only those the catalog has, kept per Organization in the browser", () => { + const group = appsScope(catalog, { view: "home" }, cs); + if (group === null) throw new Error("The fixture has an Organization"); + const favorites = [ + moduleFavorite("deals"), + repositoryFavorite("firmware"), + moduleFavorite("gone"), + moduleFavorite("mission-control"), + ]; + const [workspace, productionspace] = appsSections( + catalog, + group, + cs, + null, + favorites, + ); + expect(workspace?.tiles.map((tile) => [tile.name, tile.favorite])).toEqual([ + ["deals", true], + ["Mission Control", true], + ["Knowledgebase", false], + ["website", false], + ["notes", false], + ]); + expect(productionspace?.tiles[0]?.favorite).toBe(true); + expect( + favoriteTiles(catalog, group, cs, null, favorites).map((tile) => tile.key), + ).toEqual(["m:deals", "r:firmware", "m:mission-control"]); + // The stored list: one per Organization, read defensively. + expect(favoritesKey("Example")).toBe("lazurio.favorites:example"); + expect(parseFavorites(null)).toEqual([]); + expect(parseFavorites("{ not json")).toEqual([]); + expect(parseFavorites('{"m:deals": true}')).toEqual([]); + expect( + parseFavorites('["m:deals", "m:deals", "x:other", 7, "r:firmware"]'), + ).toEqual(["m:deals", "r:firmware"]); + expect(toggleFavorite(["m:a"], "m:b")).toEqual(["m:a", "m:b"]); + expect(toggleFavorite(["m:a", "m:b"], "m:a")).toEqual(["m:b"]); + expect( + favoritesFirst( + [{ key: "a" }, { key: "b" }, { key: "c" }], + ["c", "x", "a"], + ).map((item) => item.key), + ).toEqual(["c", "a", "b"]); +}); + +test("the new module's prompt names the Organization and its GitHub login, in the person's language", () => { + const prompt = newModulePrompt("Example Company", "example-org", cs); + expect(prompt).toStartWith( + "Chci založit nový modul v Organizaci Example Company (GitHub example-org).", + ); + expect(prompt).toContain("lazurio module create example-org/"); + expect(prompt).not.toContain("{"); + expect(newModulePrompt("Example Company", "example-org", en)).toContain( + "in the Organization Example Company (GitHub example-org)", + ); +}); + test("a tile opens the app on its own origin hosted, starts it locally, and falls back to the overview", () => { const [mission, knowledgebase, , website, notes] = example.modules as [ CatalogModule, @@ -299,7 +374,7 @@ test("a tile opens the app on its own origin hosted, starts it locally, and fall }); }); -test("Czech plural forms, app directories and the column's search", () => { +test("Czech plural forms, module names and descriptions", () => { const keys = { one: "appsModulesOne", few: "appsModulesFew", @@ -333,8 +408,6 @@ test("Czech plural forms, app directories and the column's search", () => { ), ).toBe("Data, records, and their safe management."); expect(moduleStone(module("ledger")).key).toBe("database"); - expect(appsMatch("knowledgebase", " KNOW ")).toBe(true); - expect(appsMatch("deals", "know")).toBe(false); }); // The vendored brand assets are the pinned bytes (src/shell/vendor/README.md). @@ -344,7 +417,7 @@ test("every vendored file has the hash its README records", async () => { const rows = [ ...readme.matchAll(/\| `([^`]+)` \|(?: `[^`]+` \|)? `([0-9a-f]{64})` \|/g), ]; - expect(rows.length).toBe(21); + expect(rows.length).toBe(22); for (const [, file, hash] of rows) { const bytes = await readFile(join(directory, file ?? "")); expect(createHash("sha256").update(bytes).digest("hex")).toBe(hash ?? ""); diff --git a/tests/launchpad-chat.test.ts b/tests/launchpad-chat.test.ts index 351aa4da3..734570b92 100644 --- a/tests/launchpad-chat.test.ts +++ b/tests/launchpad-chat.test.ts @@ -393,9 +393,10 @@ test("the page's Chat entry is the switch at the top of the column (decision F36 join(import.meta.dir, "..", "src", "launchpad", "index.html"), "utf8", ); - const head = //.exec( - html, - ); + const head = + //.exec( + html, + ); expect(head).not.toBeNull(); // Not inside a view-specific part of the column: the same switch on the // home, an Organization, a module, Files and Settings. diff --git a/tests/launchpad-mausbot.test.ts b/tests/launchpad-mausbot.test.ts index aa818478d..5661746bc 100644 --- a/tests/launchpad-mausbot.test.ts +++ b/tests/launchpad-mausbot.test.ts @@ -481,7 +481,7 @@ test("the page's MausBot entry is Automate in the switch next to Chat (decision "utf8", ); expect(html).toContain( - '', + '', ); expect(html).not.toContain('id="mausbot"'); expect(html).not.toContain('href="http'); diff --git a/tests/launchpad-routes.test.ts b/tests/launchpad-routes.test.ts index 39aaee995..67812b8bf 100644 --- a/tests/launchpad-routes.test.ts +++ b/tests/launchpad-routes.test.ts @@ -41,12 +41,16 @@ test("a path names the view and the settings section; the canonical path is one" section, }); expect(routePath({ view: "home" })).toBe("/"); + // The Marketplace at the foot of the Apps column (F36 addendum). + expect(pageRoute("/marketplace/")).toEqual({ view: "marketplace" }); + expect(routePath({ view: "marketplace" })).toBe("/marketplace"); expect(pagePaths).toEqual([ "/", "/o/:organization", "/o/:organization/:module", "/files", "/files/*", + "/marketplace", "/settings", "/settings/general", "/settings/machine", diff --git a/tests/launchpad-shell-routes.test.ts b/tests/launchpad-shell-routes.test.ts index de3ecc7c4..2ce03f3e4 100644 --- a/tests/launchpad-shell-routes.test.ts +++ b/tests/launchpad-shell-routes.test.ts @@ -193,15 +193,27 @@ posixTest( expect(shell?.locale).toBe("cs"); expect(shell?.environments[0]).toEqual({ id: machine.name, - label: machine.name, + // Named by its kind, never by its machine. + label: null, kind: "work", organizations: [], + assignee: null, apps: { apps: "https://launchpad.workspace.example.lazurio.io/", chat: "https://t3code.workspace.example.lazurio.io/", automate: null, }, }); + // The Owner question of "+ Nový modul": behind the same admission, + // and no for an Organization the Folder does not hold. + const owner = `${base}/api/organizations/example/owner`; + expect((await fetch(owner, { headers: { host } })).status).toBe(401); + const answered = await fetch(owner, { headers: valid }); + expect(answered.status).toBe(200); + expect(await answered.json()).toEqual({ + kind: "organization-owner", + owner: false, + }); } finally { await app.close(); await rm(parent, { recursive: true, force: true }); diff --git a/tests/launchpad.test.ts b/tests/launchpad.test.ts index 0363b17af..924eb3743 100644 --- a/tests/launchpad.test.ts +++ b/tests/launchpad.test.ts @@ -299,7 +299,7 @@ test.skipIf(process.platform === "win32")( expect(html).not.toContain('name="access"'); expect(html).not.toContain(url.hash.slice(1)); // The catalog home is the page; the developer form is gone from it. - expect(html).toContain('id="catalog-tree"'); + expect(html).toContain('id="catalog-body"'); expect(html).not.toContain('id="application"'); expect(html).not.toContain("Development fixture only"); // Every settings and catalog route serves the same page and nothing diff --git a/tests/organization-owner.test.ts b/tests/organization-owner.test.ts new file mode 100644 index 000000000..c45d43543 --- /dev/null +++ b/tests/organization-owner.test.ts @@ -0,0 +1,111 @@ +import { expect, test } from "bun:test"; +import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { + createOwnerCheck, + isOwnerMembership, + ownerCheck, +} from "../src/launchpad/organization-owner"; +import type { ToolRunner } from "../src/tools/status"; + +// Decision F36 addendum of 2026-10-04: whether this Environment's GitHub +// identity is an Owner of an Organization comes only from GitHub +// (`gh api user/memberships/orgs/`), fails closed, is never asked on a +// Team Environment or without a bound login, and is kept a few minutes. + +const posixTest = test.skipIf(process.platform === "win32"); + +async function withGh( + answer: (command: readonly string[]) => Awaited>, + run: ( + check: ReturnType, + calls: string[][], + clock: { now: number }, + ) => Promise, +) { + const home = await mkdtemp(join(tmpdir(), "owner-check-")); + try { + await mkdir(join(home, "bin")); + await writeFile(join(home, "bin", "gh"), "#!/bin/sh\nexit 1\n", { + mode: 0o755, + }); + const calls: string[][] = []; + const clock = { now: 1_000 }; + const check = createOwnerCheck( + { + path: join(home, "bin"), + home, + platform: process.platform, + run: async (command) => { + calls.push([...command.slice(1)]); + return answer(command); + }, + }, + () => clock.now, + ); + await run(check, calls, clock); + } finally { + await rm(home, { recursive: true, force: true }); + } +} + +test("only an active admin membership is an Owner's", () => { + expect(isOwnerMembership('{"state":"active","role":"admin"}')).toBe(true); + expect(isOwnerMembership('{"state":"pending","role":"admin"}')).toBe(false); + expect(isOwnerMembership('{"state":"active","role":"member"}')).toBe(false); + expect(isOwnerMembership("not json")).toBe(false); +}); + +posixTest("GitHub's answer, kept a few minutes per login", async () => { + await withGh( + () => ({ + exitCode: 0, + stdout: '{"state":"active","role":"admin"}', + stderr: "", + }), + async (check, calls, clock) => { + expect( + await check.owner("Example-Org", "hosted-organization-personal"), + ).toBe(true); + expect(calls).toEqual([["api", "user/memberships/orgs/Example-Org"]]); + expect(await check.owner("example-org", "local")).toBe(true); + expect(calls).toHaveLength(1); + clock.now += ownerCheck.cacheMs + 1; + expect(await check.owner("example-org", "local")).toBe(true); + expect(calls).toHaveLength(2); + }, + ); +}); + +posixTest( + "fail closed: a member, a refusal, a timeout; never asked on a Team Environment or without a login", + async () => { + for (const answer of [ + { exitCode: 0, stdout: '{"state":"active","role":"member"}', stderr: "" }, + { exitCode: 1, stdout: "", stderr: "Not Found" }, + "timeout" as const, + ]) + await withGh( + () => answer, + async (check) => { + expect(await check.owner("example-org", "local")).toBe(false); + }, + ); + await withGh( + () => ({ + exitCode: 0, + stdout: '{"state":"active","role":"admin"}', + stderr: "", + }), + async (check, calls) => { + expect( + await check.owner("example-org", "hosted-organization-team"), + ).toBe(false); + expect(await check.owner(undefined, "local")).toBe(false); + expect(await check.owner("not/a/login", "local")).toBe(false); + expect(calls).toEqual([]); + }, + ); + }, +); diff --git a/tests/owner-answer.test.ts b/tests/owner-answer.test.ts new file mode 100644 index 000000000..93e83a642 --- /dev/null +++ b/tests/owner-answer.test.ts @@ -0,0 +1,102 @@ +import { expect, test } from "bun:test"; +import { ownerCheck } from "../src/launchpad/organization-owner"; +import { + createOwnerAnswers, + ownerAnswerMs, +} from "../src/launchpad/owner-answer"; + +// Decision F36 addendum of 2026-10-04: the page's copy of GitHub's Owner +// answer stands as long as the Launchpad's own, is asked again after it (the +// page wakes at that moment), after a change of the bound login and after a +// catalog read, keeps the last answer while it is being asked again, and +// takes only the answer to the question it is asking now. + +test("the page and the Launchpad keep an answer equally long", () => { + expect(ownerCheck.cacheMs).toBe(ownerAnswerMs); +}); + +test("an answer is asked once, stands until it expires, then is asked again while the last one shows", () => { + let now = 1_000; + const answers = createOwnerAnswers(() => now); + const first = answers.read("alpha", "alpha-forge"); + expect(first.owner).toBe(false); + expect(first.ask).not.toBeNull(); + // Being asked: no second question, nothing shown yet. + expect(answers.read("alpha", "alpha-forge")).toEqual({ + owner: false, + ask: null, + }); + answers.settle("alpha", "alpha-forge", first.ask as number, true); + expect(answers.nextExpiry()).toBe(1_000 + ownerAnswerMs); + now += ownerAnswerMs - 1; + expect(answers.read("alpha", "alpha-forge")).toEqual({ + owner: true, + ask: null, + }); + now += 1; + // Expired: asked again, and the last answer stands meanwhile. + const again = answers.read("alpha", "alpha-forge"); + expect(again.owner).toBe(true); + expect(again.ask).not.toBeNull(); + expect(answers.nextExpiry()).toBeNull(); + answers.settle("alpha", "alpha-forge", again.ask as number, false); + expect(answers.read("alpha", "alpha-forge").owner).toBe(false); +}); + +test("an answer to a question no longer asked changes nothing: after a catalog read, or overtaken", () => { + const answers = createOwnerAnswers(() => 0); + const a = answers.read("alpha", "alpha-forge").ask as number; + answers.clear(); + const b = answers.read("alpha", "alpha-forge").ask as number; + answers.settle("alpha", "alpha-forge", b, false); + // The older question's late "yes" does not restore the Owner offer. + answers.settle("alpha", "alpha-forge", a, true); + expect(answers.read("alpha", "alpha-forge")).toEqual({ + owner: false, + ask: null, + }); + // A late answer after a catalog read is dropped too. + const c = answers.read("beta", "beta-forge").ask as number; + answers.clear(); + answers.settle("beta", "beta-forge", c, true); + expect(answers.read("beta", "beta-forge").owner).toBe(false); +}); + +test("another bound login is another question; a catalog read forgets every answer", () => { + const answers = createOwnerAnswers(() => 0); + const ask = answers.read("alpha", "alpha-forge").ask as number; + answers.settle("alpha", "alpha-forge", ask, true); + expect(answers.read("alpha", "Alpha-Forge")).toEqual({ + owner: true, + ask: null, + }); + expect(answers.read("alpha", "beta-forge").ask).not.toBeNull(); + answers.clear(); + expect(answers.nextExpiry()).toBeNull(); + expect(answers.read("alpha", "alpha-forge").ask).not.toBeNull(); +}); + +test("visiting A then B: the wake for A's expiry re-arms for B's, and an expired answer off screen never keeps the page waking", () => { + let now = 1_000; + const answers = createOwnerAnswers(() => now); + const a = answers.read("alpha", "alpha-forge").ask as number; + answers.settle("alpha", "alpha-forge", a, true); + now = 2_000; + const b = answers.read("beta", "beta-forge").ask as number; + answers.settle("beta", "beta-forge", b, true); + // The page wakes first for A. + expect(answers.nextExpiry()).toBe(1_000 + ownerAnswerMs); + now = 1_000 + ownerAnswerMs; + // At that wake only B is shown and still stands; the next wake is B's, + // not A's expired moment again. + expect(answers.read("beta", "beta-forge")).toEqual({ + owner: true, + ask: null, + }); + expect(answers.nextExpiry()).toBe(2_000 + ownerAnswerMs); + now = 2_000 + ownerAnswerMs; + // B expires: shown, so asked again; A stays expired off screen and sets + // no wake. + expect(answers.read("beta", "beta-forge").ask).not.toBeNull(); + expect(answers.nextExpiry()).toBeNull(); +}); diff --git a/tests/shell.test.ts b/tests/shell.test.ts index 238c73f05..e8de2f5c4 100644 --- a/tests/shell.test.ts +++ b/tests/shell.test.ts @@ -9,10 +9,14 @@ import { import { parseShell, type Shell } from "../src/shell/contract"; import { shellMessages } from "../src/shell/messages"; import { - folderLimit, + environmentHref, + environmentName, + environmentWho, + hereOf, initialsOf, - jumpList, - railModel, + railSpaces, + spaceEnvironments, + switcherSections, switchTabs, } from "../src/shell/view"; import { folderFixture, writeOrganization } from "./fixtures/catalog-folder"; @@ -22,9 +26,10 @@ import { personalWithEntry, } from "./fixtures/machine-bindings"; -// Decision F36: the Lazurio shell's data contract `lazurio.shell.v1`, its -// producer for what this Environment knows today, and the rail and switch -// as the elements draw them. Fixtures use example names only. +// Decision F36 and its addendum of 2026-10-04: the Lazurio shell's data +// contract `lazurio.shell.v1`, its producer for what this Environment knows +// today, and the rail of Organizations, the Environment picker and the +// switch as the elements draw them. Fixtures use example names only. const organization = ( slug: string, @@ -47,8 +52,9 @@ const catalog = (...organizations: CatalogOrganization[]): Catalog => ({ }); const en = shellMessages("en"); const cs = shellMessages("cs"); +const noLast = () => null; -test("a workstation's document: this computer, every Organization of the Folder, Apps on its own origin, no Chat or Automate", () => { +test("a workstation's document: this computer, every Organization of the Folder with its Dashboard, Apps on its own origin", () => { const shell = shellDocument({ preset: "local", machine: null, @@ -64,13 +70,14 @@ test("a workstation's document: this computer, every Organization of the Folder, schema: "lazurio.shell.v1", locale: "cs", current: "local", - operator: { initials: null, login: null }, + operator: { initials: null, login: null, avatar: null }, environments: [ { id: "local", label: null, kind: "workstation", organizations: ["alpha", "beta"], + assignee: null, apps: { apps: "/", chat: null, automate: null }, }, ], @@ -78,29 +85,76 @@ test("a workstation's document: this computer, every Organization of the Folder, { slug: "alpha", name: "Alpha Example", - accent: null, // The avatar of the bound login, never of the slug. avatar: "https://github.com/alpha-forge.png?size=96", + dashboard: "https://dashboard.lazurio.ai/orgs/alpha", }, { slug: "beta", name: "Beta Example", - accent: null, // No bound login: no avatar, the rail shows initials. avatar: null, + dashboard: "https://dashboard.lazurio.ai/orgs/beta", }, ], dashboard: "https://dashboard.lazurio.ai/", account: "https://dashboard.lazurio.ai/settings", + addOrganization: "https://dashboard.lazurio.ai/add-organization", }); - // The rail: this computer is personal, so no folder; Organizations - // without an Environment in the document have none. - const rail = railModel(shell, cs); - expect(rail.personal.map((entry) => [entry.label, entry.active])).toEqual([ - ["Tento počítač", true], + const current = shell.environments[0]; + if (current === undefined) throw new Error("The document has one"); + expect(environmentName(current, cs)).toBe("Tento počítač"); + expect(environmentWho(current, cs)).toBe("tento počítač"); + // Named by its computer when the host name is known, never by a hosted + // machine's name. + const named = shellDocument({ + preset: "local", + machine: null, + locale: "cs", + catalog: catalog(), + computer: "Example-MacBook.local", + }); + expect(named.environments[0]?.label).toBe("Example-MacBook"); + expect( + shellDocument({ + preset: "local", + machine: null, + locale: "cs", + catalog: catalog(), + computer: "not a host", + }).environments[0]?.label, + ).toBeNull(); + expect( + shellDocument({ + preset: "hosted-organization-personal", + machine: organizationWithEntry(), + locale: "cs", + catalog: catalog(), + computer: "Example-MacBook.local", + }).environments[0]?.label, + ).toBeNull(); + // On its own the workstation is personal; opened for an Organization it + // stands in that Organization's space, Apps scoped to it. + expect(hereOf(shell, null)).toBe("personal"); + expect(hereOf(shell, "BETA")).toBe("beta"); + expect(environmentHref(current, "beta", "apps")).toBe("/o/beta"); + expect(environmentHref(current, "personal", "apps")).toBe("/"); + // The rail: your space, then each Organization; the space a click on + // Beta leads to is this computer opened for Beta. + const spaces = railSpaces(shell, cs, { + here: "beta", + app: "apps", + last: noLast, + }); + expect( + spaces.map((space) => [space.space, space.href, space.active, space.sub]), + ).toEqual([ + ["personal", "/", false, "1 Environment"], + ["alpha", "/o/alpha", false, "1 Environment"], + ["beta", "/o/beta", true, "1 Environment"], ]); - expect(rail.personal[0]?.mark).toEqual({ kind: "icon", icon: "laptop" }); - expect(rail.folders).toEqual([]); + expect(spaces[1]?.avatar).toBe("https://github.com/alpha-forge.png?size=96"); + expect(spaces[2]?.initials).toBe("BE"); // The switch: Apps on this origin, the two others disabled with a reason. expect( switchTabs(shell, cs, "apps").map((tab) => [ @@ -116,64 +170,135 @@ test("a workstation's document: this computer, every Organization of the Folder, ]); }); -test("a hosted work Environment: its Machine name, the assigned operator's initials, the entry's origins, one Organization folder with it active", () => { +test("a hosted work Environment is named by its kind and its person, never by its machine; its Organization's space is the active one", () => { const machine = organizationWithEntry(20000, "workspace.example.lazurio.io"); const shell = shellDocument({ preset: "hosted-organization-personal", machine, locale: "en", - catalog: catalog(organization("example")), + catalog: catalog(organization("example", { forgeLogin: "example" })), }); const [environment] = shell.environments; - expect(environment?.kind).toBe("work"); - expect(environment?.label).toBe(machine.name); - expect(shell.current).toBe(machine.name); - expect(environment?.apps).toEqual({ + if (environment === undefined) throw new Error("The document has one"); + expect(environment.kind).toBe("work"); + // The machine's name is the id the document keys it by, never a label. + expect(environment.id).toBe(machine.name); + expect(environment.label).toBeNull(); + expect(environmentName(environment, cs)).toBe("Pracovní"); + expect(environment.apps).toEqual({ apps: "https://launchpad.workspace.example.lazurio.io/", chat: "https://t3code.workspace.example.lazurio.io/", automate: null, }); - const rail = railModel(shell, en); - expect(rail.personal).toEqual([]); - expect(rail.folders).toHaveLength(1); - expect(rail.folders[0]?.hasActive).toBe(true); - expect(rail.folders[0]?.items[0]?.sub).toBe( - "Example Example · work · you are here", - ); - expect(rail.folders[0]?.initials).toBe("EE"); - expect(switchTabs(shell, en, "apps").map((tab) => tab.href)).toEqual([ - "https://t3code.workspace.example.lazurio.io/", - "https://launchpad.workspace.example.lazurio.io/", - null, + expect(hereOf(shell, null)).toBe("example"); + const spaces = railSpaces(shell, en, { + here: "example", + app: "chat", + last: noLast, + }); + // Your personal space has no Environment here: its Dashboard. + expect( + spaces.map((space) => [space.space, space.href, space.active]), + ).toEqual([ + ["personal", "https://dashboard.lazurio.ai/", false], + // A click stays in the app the rail sits in (Chat). + ["example", "https://t3code.workspace.example.lazurio.io/", true], + ]); + // The picker's list: the Organization's head (its Dashboard), then its + // Environments, the current one marked. + const [section] = switcherSections(shell, cs, { + here: "example", + all: false, + app: "apps", + query: "", + }); + expect(section?.head?.href).toBe("https://dashboard.lazurio.ai/orgs/example"); + expect(section?.rows.map((row) => [row.name, row.who, row.current])).toEqual([ + ["Pracovní", "pracovní", true], ]); }); -test("a personal Remote Environment carries its owner's initials and belongs to no Organization", () => { - const machine = personalWithEntry(); +test("an assigned work Environment says whose it is; an Automated one is its persona's; a Team one its Team's", () => { + const work = shellDocument({ + preset: "hosted-organization-personal", + machine: bindings.assignedOperator as MachineBinding, + locale: "en", + catalog: catalog(organization("example")), + }); + expect(work.environments[0]?.assignee).toBe("example"); + const [assigned] = work.environments; + if (assigned === undefined) throw new Error("The document has one"); + expect(environmentWho(assigned, cs)).toBe("@example"); + // The Team the binding names, by its display name in the catalog of the + // Organization that owns the Environment. + const teams = catalog( + organization("example", { + forgeLogin: "example", + teams: [{ slug: "sample-team", displayName: "Sample" }], + }), + ); + const team = shellDocument({ + preset: "hosted-organization-team", + machine: bindings.assignedTeam as MachineBinding, + locale: "en", + catalog: teams, + }); + expect(team.operator).toEqual({ initials: null, login: null, avatar: null }); + expect(team.environments[0]?.label).toBe("Team Sample"); + expect(team.environments[0]?.assignee).toBeNull(); + const [shared] = team.environments; + if (shared === undefined) throw new Error("The document has one"); + expect(environmentWho(shared, cs)).toBe("sdílený Teamem"); + const automated = shellDocument({ + preset: "hosted-organization-steward", + machine: bindings.automated as MachineBinding, + locale: "en", + catalog: catalog( + organization("example", { + forgeLogin: "example", + teams: [{ slug: "sample-team", displayName: "Steward" }], + }), + ), + }); + expect(automated.environments[0]?.kind).toBe("automated"); + expect(automated.environments[0]?.label).toBe("Steward"); + expect(automated.operator.login).toBe("example"); + // A Team the catalog does not know: named by its kind. + const unknown = shellDocument({ + preset: "hosted-organization-team", + machine: bindings.assignedTeam as MachineBinding, + locale: "en", + catalog: catalog(organization("example")), + }); + expect(unknown.environments[0]?.label).toBeNull(); +}); + +test("a personal Remote Environment carries its owner's initials and photo and belongs to no Organization", () => { const shell = shellDocument({ preset: "hosted-personal", - machine, + machine: personalWithEntry(), locale: "en", catalog: catalog(organization("example")), }); expect(shell.environments[0]?.organizations).toEqual([]); - expect(shell.operator.login).not.toBeNull(); - expect(shell.operator.initials).toBe( - initialsOf(shell.operator.login ?? "").slice(0, 2), - ); - const rail = railModel(shell, en); - expect(rail.personal[0]?.mark).toEqual({ - kind: "initials", - text: shell.operator.initials ?? "", + expect(shell.operator.login).toBe("example"); + expect(shell.operator.initials).toBe("EX"); + expect(shell.operator.avatar).toBe("https://github.com/example.png?size=96"); + expect(hereOf(shell, null)).toBe("personal"); + const [personal] = switcherSections(shell, en, { + here: "personal", + all: false, + app: "apps", + query: "", }); - expect(rail.personal[0]?.sub).toStartWith(`@${shell.operator.login}`); - expect(rail.folders).toEqual([]); + expect(personal?.rows[0]?.glyph).toEqual({ kind: "initials", text: "EX" }); + expect(personal?.rows[0]?.name).toBe("Personal"); }); -test("a Team Environment names no operator; a template or a duplicate slug is no Organization of the shell", () => { +test("a template or a duplicate slug is no Organization of the shell", () => { const shell = shellDocument({ - preset: "hosted-organization-team", - machine: bindings.assignedTeam as MachineBinding, + preset: "local", + machine: null, locale: "en", catalog: catalog( organization("example"), @@ -188,25 +313,7 @@ test("a Team Environment names no operator; a template or a duplicate slug is no organization("broken", { organization: null, displayName: null }), ), }); - expect(shell.operator).toEqual({ initials: null, login: null }); - expect(shell.environments[0]?.kind).toBe("team"); expect(shell.organizations.map((entry) => entry.slug)).toEqual(["example"]); - expect(railModel(shell, en).folders[0]?.items[0]?.mark).toEqual({ - kind: "icon", - icon: "users", - }); -}); - -test("the Automated Environment names its responsible operator", () => { - const shell = shellDocument({ - preset: "hosted-organization-steward", - machine: bindings.assignedOperator as MachineBinding, - locale: "en", - catalog: catalog(organization("example")), - }); - expect(shell.environments[0]?.kind).toBe("automated"); - expect(shell.operator.login).toBe("example"); - expect(shell.operator.initials).toBe("EX"); }); // A document as the Dashboard will fill it: more Environments, several @@ -216,31 +323,38 @@ const filled = (): Shell => { schema: "lazurio.shell.v1", locale: "en", current: "work-3", - operator: { initials: "OP", login: "operator" }, + operator: { + initials: "OP", + login: "operator", + avatar: "https://avatars.example.invalid/operator.png", + }, environments: [ { id: "laptop", label: null, kind: "workstation", organizations: ["north"], + assignee: null, apps: { apps: "/", chat: null, automate: null }, }, { id: "personal", - label: "operator", + label: null, kind: "personal", organizations: [], + assignee: null, apps: { apps: "https://launchpad.operator.example.lazurio.io/", chat: "https://t3code.operator.example.lazurio.io/", automate: null, }, }, - ...Array.from({ length: 8 }, (_, index) => ({ + ...Array.from({ length: 4 }, (_, index) => ({ id: `work-${index}`, - label: `vm-${index}`, + label: index === 0 ? "Team North" : null, kind: index === 0 ? "team" : "work", organizations: ["north"], + assignee: index === 0 ? null : `person-${index}`, apps: { apps: `https://launchpad.vm-${index}.north.example.lazurio.io/`, chat: null, @@ -249,9 +363,10 @@ const filled = (): Shell => { })), { id: "south-1", - label: "vm-1", + label: "Steward", kind: "automated", organizations: ["South"], + assignee: null, apps: { apps: "https://launchpad.vm-1.south.example.lazurio.io/", chat: null, @@ -260,16 +375,22 @@ const filled = (): Shell => { }, ], organizations: [ - { slug: "north", name: "North Example", accent: "#0b0eb4", avatar: null }, + { + slug: "north", + name: "North Example", + avatar: null, + dashboard: "https://dashboard.example.invalid/orgs/north", + }, { slug: "south", name: "South Example", - accent: null, avatar: "https://avatars.example.invalid/south.png", + dashboard: "https://dashboard.example.invalid/orgs/south", }, ], dashboard: "https://dashboard.example.invalid/", account: "https://dashboard.example.invalid/settings", + addOrganization: null, // A member a later producer adds is ignored. buddy: { origin: "https://buddy.example.invalid" }, }); @@ -277,36 +398,86 @@ const filled = (): Shell => { return value; }; -test("several Organizations: personal first, a folder each, six then +N, the active one always shown, less folds again", () => { +test("several Organizations: a space's Environments, its last one remembered, the picker's list widened to all, filtered", () => { const shell = filled(); - const rail = railModel(shell, en); - expect(rail.personal.map((entry) => entry.id)).toEqual([ + expect(hereOf(shell, null)).toBe("north"); + expect(spaceEnvironments(shell, "north").map((entry) => entry.id)).toEqual([ + "work-0", + "work-1", + "work-2", + "work-3", "laptop", - "personal", ]); - expect(rail.folders.map((folder) => folder.organization.slug)).toEqual([ - "north", - "south", + expect(spaceEnvironments(shell, "personal").map((entry) => entry.id)).toEqual( + ["laptop", "personal"], + ); + // A click on a space: the last Environment this browser was in there, + // else its first; in Automate an Environment without it opens Apps. + const spaces = railSpaces(shell, en, { + here: "north", + app: "automate", + last: (space) => (space === "north" ? "work-2" : null), + }); + expect(spaces.map((space) => [space.space, space.href, space.sub])).toEqual([ + ["personal", "/", "2 Environments"], + [ + "north", + "https://launchpad.vm-2.north.example.lazurio.io/", + "5 Environments · last Work", + ], + [ + "south", + "https://mausbot.vm-1.south.example.lazurio.io/", + "1 Environment", + ], ]); - const [north, south] = rail.folders; - // Six first, plus the active one further down; two folded behind +N. - expect(north?.items.map((entry) => entry.id)).toEqual([ - ...Array.from({ length: folderLimit }, (_, index) => `work-${index}`), + // The list under the picker: this space only. + const one = switcherSections(shell, en, { + here: "north", + all: false, + app: "apps", + query: "", + }); + expect(one.map((section) => section.space)).toEqual(["north"]); + expect( + one[0]?.rows.map((row) => [row.id, row.name, row.who, row.current]), + ).toEqual([ + ["work-0", "Team North", "shared by the Team", false], + ["work-1", "Work", "@person-1", false], + ["work-2", "Work", "@person-2", false], + ["work-3", "Work", "@person-3", true], + ["laptop", "This computer", "this computer", false], ]); - expect(north?.hidden).toBe(2); - expect(north?.items.find((entry) => entry.active)?.id).toBe("work-3"); - expect(north?.items[0]?.accent).toBe("#0b0eb4"); - expect(south?.items[0]?.mark).toEqual({ kind: "icon", icon: "bot" }); - const open = railModel(shell, en, new Set(["north"])); - expect(open.folders[0]?.items).toHaveLength(8); - expect(open.folders[0]?.hidden).toBe(0); - expect(open.folders[0]?.expanded).toBe(true); - // The jump list: every Environment, the current one first, filtered. - expect(jumpList(shell, en, "")[0]?.id).toBe("work-3"); - expect(jumpList(shell, en, "")).toHaveLength(11); - expect(jumpList(shell, en, "south").map((entry) => entry.id)).toEqual([ - "south-1", + // "All Organizations" (and ⌘⇧E): every space, each Organization with its + // head; a query keeps what matches. + const all = switcherSections(shell, en, { + here: "north", + all: true, + app: "apps", + query: "", + }); + expect(all.map((section) => [section.space, section.head !== null])).toEqual([ + ["personal", false], + ["north", true], + ["south", true], ]); + const found = switcherSections(shell, en, { + here: "north", + all: true, + app: "apps", + query: "steward", + }); + expect( + found.map((section) => [section.space, section.rows.map((row) => row.id)]), + ).toEqual([["south", ["south-1"]]]); + expect( + switcherSections(shell, en, { + here: "north", + all: true, + app: "apps", + query: "nothing like that", + }), + ).toEqual([]); }); test("the parser refuses what the elements could not draw safely", () => { @@ -316,6 +487,8 @@ test("the parser refuses what the elements could not draw safely", () => { change(copy); return parseShell(copy); }; + const first = (value: Record, key: string) => + (value[key] as Record[])[0] as Record; expect(parseShell(valid)).not.toBeNull(); expect(variant((value) => (value.schema = "lazurio.shell.v2"))).toBeNull(); expect(variant((value) => (value.current = "missing"))).toBeNull(); @@ -327,40 +500,41 @@ test("the parser refuses what the elements could not draw safely", () => { expect( variant((value) => (value.account = "http://dashboard.example.invalid/")), ).toBeNull(); + expect( + variant((value) => (value.addOrganization = "/add-organization")), + ).toBeNull(); expect( variant((value) => { - const [first] = value.environments as Record[]; - if (first) - first.apps = { - apps: "//other.example.invalid/", - chat: null, - automate: null, - }; + first(value, "environments").apps = { + apps: "//other.example.invalid/", + chat: null, + automate: null, + }; }), ).toBeNull(); expect( variant((value) => { - const [first] = value.environments as Record[]; - if (first) - first.apps = { - apps: "/", - chat: "https://user:secret@t3.example.invalid/", - automate: null, - }; + first(value, "environments").apps = { + apps: "/", + chat: "https://user:secret@t3.example.invalid/", + automate: null, + }; }), ).toBeNull(); - // The accent is a colour, never CSS. expect( variant((value) => { - const [first] = value.organizations as Record[]; - if (first) first.accent = "red; background: url(x)"; + first(value, "organizations").dashboard = "javascript:alert(1)"; + }), + ).toBeNull(); + expect( + variant((value) => { + first(value, "environments").assignee = "not a login"; }), ).toBeNull(); // Every Organization an Environment names is listed, each id once. expect( variant((value) => { - const [first] = value.environments as Record[]; - if (first) first.organizations = ["east"]; + first(value, "environments").organizations = ["east"]; }), ).toBeNull(); expect( @@ -374,10 +548,15 @@ test("the parser refuses what the elements could not draw safely", () => { (value) => ((value.operator as Record).initials = ""), ), ).toBeNull(); + expect( + variant( + (value) => + ((value.operator as Record).avatar = "data:image/png"), + ), + ).toBeNull(); expect( variant((value) => { - const [first] = value.environments as Record[]; - if (first) first.kind = "server"; + first(value, "environments").kind = "server"; }), ).toBeNull(); }); @@ -413,15 +592,48 @@ test.skipIf(process.platform === "win32")( expect( shell.organizations.find((entry) => entry.slug === "north")?.avatar, ).toBe("https://github.com/north-forge-login.png?size=96"); - // No avatar of any slug: every avatar is a bound login's. - for (const entry of shell.organizations) - expect(entry.avatar).toBe( - `https://github.com/${ - read.organizations.find( - (candidate) => candidate.organization === entry.slug, - )?.forgeLogin - }.png?size=96`, - ); + }); + }, + 30_000, +); + +test.skipIf(process.platform === "win32")( + "an Organization whose slug is not a GitHub login keeps its place in the rail and the picker, read from a real Folder", + async () => { + await folderFixture(async (folder) => { + // A canonical slug the manifest admits but a login never could + // (underscore, dot), bound to a different GitHub login. + await writeOrganization(folder, "alpha_internal_GEN3", { + slug: "alpha_internal.v2", + forge: "alpha-forge", + state: "current", + modules: [{ id: "orders" }], + }); + const read = await readFolderCatalog(folder); + const entry = read.organizations.find( + (candidate) => candidate.organization === "alpha_internal.v2", + ); + expect(entry?.executable).toBe(true); + const shell = shellDocument({ + preset: "local", + machine: null, + locale: "en", + catalog: read, + }); + const organization = shell.organizations.find( + (candidate) => candidate.slug === "alpha_internal.v2", + ); + expect(organization?.avatar).toBe( + "https://github.com/alpha-forge.png?size=96", + ); + expect(organization?.dashboard).toBe( + "https://dashboard.lazurio.ai/orgs/alpha_internal.v2", + ); + // The workstation holds it, so the picker of its space lists it. + expect(shell.environments[0]?.organizations).toContain( + "alpha_internal.v2", + ); + expect(parseShell(JSON.parse(JSON.stringify(shell)))).not.toBeNull(); }); }, 30_000,