Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 957b01583daa67a2db91b3b5eaf1cbdd9b761d35
parent 5362b71171a6911c4d62d03fc12577e6d06bb45e
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Fri, 13 Nov 2026 02:21:57 -0500

privacy D4: the seams in the editor and umtool

Both root layouts render <PrivacyProvider> only while settings.privacy has
browser rules (absent: the tree is unchanged). Drawn through the displayers
(server-side unless marked client):
- editor: the "Media relocated to <path>" badge on / and /channels
  (buildChannelRowView `show`); a channel page's Storage summary
  (computeStageStatuses `show`); /settings' System paths; /saved-videos' store
  dir; /storage's location root and volume, the saved-video store's path and
  detail (client);
- umtool: /jobs' render records (RenderRecord `show`; client in the Takes
  panel and the work dirs); the queue panel's label, command, error and runner
  line (client); /settings/system's roots, index and storage panels; a tool's
  path title (client); a research case's local source folder (client);
  CopyButton's refused-clipboard box and title (client) -- the clipboard
  still gets the real text.
hidePrivateSites filters only what a page DRAWS: the editor's site picker
("All sites" and its empty state over every site; a hidden scope shows as "A
private site"), /channels' Focus bar and empty state, a channel's site
memberships (a hidden one is not drawn but still saved: membershipsJsonOf);
umtool's home, /projects, /work and the research source pickers
(shownSources -- listSources stays whole, as openSource's allow-list and every
reader's default). umtool's privateFilter fails closed when the sites cannot
be read.

Co-Authored-By: Claude <noreply@anthropic.com>

Diffstat:
Mcommon/views/channelRow.ts | 8++++++--
Mcommon/views/pipeline/stageStatus.ts | 11+++++++++--
Meditor/app/channels/[slug]/page.tsx | 8++++++++
Aeditor/app/channels/components/SiteMembershipsSection.test.ts | 29+++++++++++++++++++++++++++++
Meditor/app/channels/components/SiteMembershipsSection.tsx | 57+++++++++++++++++++++++++++++++++++----------------------
Meditor/app/channels/page.tsx | 29+++++++++++++++++++++++------
Meditor/app/components/SiteScopeSelect.tsx | 15+++++++++++++--
Meditor/app/layout.tsx | 33+++++++++++++++++++++++++++------
Meditor/app/page.tsx | 3+++
Meditor/app/saved-videos/page.tsx | 3++-
Meditor/app/settings/page.tsx | 3++-
Meditor/app/storage/components/SavedVideosStoreCard.tsx | 10+++++++---
Meditor/app/storage/components/StorageLocationsTable.tsx | 11++++++++---
Mumtool/app/create/page.tsx | 7++++++-
Mumtool/app/jobs/page.tsx | 3++-
Mumtool/app/layout.tsx | 7++++++-
Mumtool/app/page.tsx | 4+++-
Mumtool/app/projects/page.tsx | 6+++++-
Mumtool/app/research/archive/page.tsx | 7+++++--
Mumtool/app/research/page.tsx | 4++--
Mumtool/app/work/page.tsx | 7++++++-
Mumtool/components/CopyButton.tsx | 12+++++++++---
Mumtool/components/projects/TakeVariants.tsx | 4+++-
Mumtool/components/projects/TakesBench.tsx | 4+++-
Mumtool/components/queue/QueuePanel.tsx | 14+++++++++-----
Mumtool/components/queue/RenderRecord.tsx | 16+++++++++++++---
Mumtool/components/research/BoardView.tsx | 5++++-
Mumtool/components/system/Maintenance.tsx | 15++++++++-------
Mumtool/components/system/ToolsPanel.tsx | 7+++++--
Mumtool/lib/inbox.ts | 9+++++++--
Aumtool/lib/privacy.test.ts | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/lib/privacy.ts | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/lib/research/privacySources.test.ts | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/lib/research/sources.ts | 27+++++++++++++++++++++++++++
Mumtool/package.json | 2+-
35 files changed, 478 insertions(+), 84 deletions(-)

diff --git a/common/views/channelRow.ts b/common/views/channelRow.ts @@ -154,6 +154,10 @@ export type ChannelRowInput = { // before locations existed). The dashboard names it from the media target, // as it always has, and passes that here. mediaLocationLabel?: string; + // The page's displayer for the media target and detail (settings.privacy, + // lib/privacy/privacy-server.ts displayPath): the row is drawn, never acted + // on, so the drawn path is the displayed one. Absent = as they are. + show?: (s: string) => string; }; // How old a channel's report is, in the three states /channels draws: @@ -227,8 +231,8 @@ export function buildChannelRowView(i: ChannelRowInput): ChannelRowView { i.media && i.media.status !== "in-place" ? { status: i.media.status, - target: i.media.target, - detail: i.media.detail, + target: i.show && i.media.target ? i.show(i.media.target) : i.media.target, + detail: i.show && i.media.detail ? i.show(i.media.detail) : i.media.detail, locationLabel: "mediaLocationLabel" in i ? i.mediaLocationLabel diff --git a/common/views/pipeline/stageStatus.ts b/common/views/pipeline/stageStatus.ts @@ -199,6 +199,10 @@ export type ComputeStageStatusesInput = { // null when it has none. Read only by the `mirror` stage, which the page // lists only for a channel with `mirror` in its config; omitted = no scan. mirrorScan?: { videos: number; onlyCopy: number; removedInWindow: number; held: number } | null; + // The page's displayer for the Storage stage's drawn path and detail + // (settings.privacy, lib/privacy/privacy-server.ts displayPath). Absent = as + // they are. + show?: (s: string) => string; }; export function computeStageStatuses( @@ -213,6 +217,7 @@ export function computeStageStatuses( backfillKindIds, media, mirrorScan, + show = (t: string) => t, } = input; const buckets = normalizeBuckets(snapshot.buckets); @@ -634,8 +639,10 @@ export function computeStageStatuses( mediaStatus === "in-place" ? "Media is in the channel directory." : mediaStatus === "ok" - ? `Media relocated to ${media?.target ?? "another drive"}.` - : (media?.detail ?? mediaStatus), + ? `Media relocated to ${media?.target != null ? show(media.target) : "another drive"}.` + : media?.detail != null + ? show(media.detail) + : mediaStatus, tone: mediaStatus === "in-transition" ? "running" diff --git a/editor/app/channels/[slug]/page.tsx b/editor/app/channels/[slug]/page.tsx @@ -1,3 +1,5 @@ +import { displayPath, hidePrivateSites } from "yt-dlp-transcript-common/lib/privacy/privacy-server"; +import { isPrivateSite } from "yt-dlp-transcript-common/lib/siteSchema"; import path from "node:path"; import { Suspense, type ReactNode } from "react"; import type { Metadata } from "next"; @@ -464,6 +466,8 @@ export default async function ChannelDetailPage({ backfillEnabled: laneOperations.length > 0, backfillKindIds: laneOperations.map((k) => k.id), media, + // settings.privacy: the Storage summary's path as displayed. + show: displayPath, mirrorScan: mirrorScan ? { videos: mirrorScan.totals.videos, @@ -554,11 +558,15 @@ export default async function ChannelDetailPage({ // Sites membership section: every configured site plus this channel's // current membership (and group) on each. const allSites = listSites(paths); + // settings.privacy.hidePrivateSites: a private site is not drawn but + // stays in the list, so its membership survives a save. + const hidePrivate = hidePrivateSites(); const siteOptions: SiteMembershipOption[] = allSites.map((s) => ({ siteId: s.siteId, siteTitle: s.siteTitle, defaultGroupId: s.defaultGroupId, groups: sortGroups(s.groups).map((g) => ({ id: g.id, name: g.name })), + ...(hidePrivate && isPrivateSite(s) ? { hidden: true as const } : {}), })); const initialMemberships: InitialMembership[] = allSites.flatMap( (s) => { diff --git a/editor/app/channels/components/SiteMembershipsSection.test.ts b/editor/app/channels/components/SiteMembershipsSection.test.ts @@ -0,0 +1,29 @@ +// settings.privacy.hidePrivateSites on a channel's configure tab (review round +// 1, S1): a private site is not DRAWN, but its membership is submitted exactly +// as it was — a save must never drop a membership the operator cannot see. +// +// Run with: pnpm --filter editor test + +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { membershipsJsonOf, type Row, type SiteMembershipOption } from "./SiteMembershipsSection"; + +const site = (siteId: string, hidden = false): SiteMembershipOption => ({ + siteId, + siteTitle: `T ${siteId}`, + defaultGroupId: "default", + groups: [{ id: "g1", name: "G1" }], + ...(hidden ? { hidden: true as const } : {}), +}); + +test("a hidden site's membership (and its group) is in what the form submits", () => { + const sites = [site("pub"), site("priv", true), site("other")]; + const selected = new Map<string, Row>([ + ["pub", { groupId: "", newGroupName: "" }], + ["priv", { groupId: "g1", newGroupName: "" }], + ]); + assert.deepEqual(JSON.parse(membershipsJsonOf(sites, selected)), [{ siteId: "pub" }, { siteId: "priv", groupId: "g1" }]); + // The same answer with nothing hidden: the flag changes what is drawn only. + const plain = [site("pub"), site("priv"), site("other")]; + assert.equal(membershipsJsonOf(plain, selected), membershipsJsonOf(sites, selected)); +}); diff --git a/editor/app/channels/components/SiteMembershipsSection.tsx b/editor/app/channels/components/SiteMembershipsSection.tsx @@ -20,6 +20,10 @@ export type SiteMembershipOption = { defaultGroupId: string; // Pre-sorted server-side via sortGroups. groups: { id: string; name: string }[]; + // settings.privacy.hidePrivateSites: a private site is NOT DRAWN, but it + // stays in the list so its membership is submitted as it was — a save never + // drops a membership the operator cannot see. Set only when true. + hidden?: true; }; export type InitialMembership = { siteId: string; groupId?: string }; @@ -28,7 +32,7 @@ export type InitialMembership = { siteId: string; groupId?: string }; // group id — underscores fail isValidGroupId (same trick as ALL_SITES). const NEW_GROUP = "__new__"; -type Row = { groupId: string; newGroupName: string }; +export type Row = { groupId: string; newGroupName: string }; type Props = { sites: SiteMembershipOption[]; @@ -40,6 +44,34 @@ type Props = { activeSiteId?: string | null; }; +// One entry per CHECKED site; an unchecked site is simply absent (= remove +// membership on edit). See MembershipRequest in lib/siteMemberships.ts. A +// HIDDEN site (hidePrivateSites) is in `sites` and so in here: its membership +// is kept exactly as it was. +export function membershipsJsonOf( + sites: ReadonlyArray<SiteMembershipOption>, + selected: ReadonlyMap<string, Row>, +): string { + return JSON.stringify( + sites + .filter((s) => selected.has(s.siteId)) + .map((s) => { + const row = selected.get(s.siteId)!; + if (row.groupId === NEW_GROUP) { + const name = row.newGroupName.trim(); + // The visible name input is `required`, so an empty name never + // submits; falling back to default is belt-and-braces only. + return name + ? { siteId: s.siteId, newGroupName: name } + : { siteId: s.siteId }; + } + return row.groupId + ? { siteId: s.siteId, groupId: row.groupId } + : { siteId: s.siteId }; + }), + ); +} + export function SiteMembershipsSection({ sites, initialMemberships, @@ -104,26 +136,7 @@ export function SiteMembershipsSection({ return next; }); - // One entry per CHECKED site; an unchecked site is simply absent (= remove - // membership on edit). See MembershipRequest in lib/siteMemberships.ts. - const membershipsJson = JSON.stringify( - sites - .filter((s) => selected.has(s.siteId)) - .map((s) => { - const row = selected.get(s.siteId)!; - if (row.groupId === NEW_GROUP) { - const name = row.newGroupName.trim(); - // The visible name input is `required`, so an empty name never - // submits; falling back to default is belt-and-braces only. - return name - ? { siteId: s.siteId, newGroupName: name } - : { siteId: s.siteId }; - } - return row.groupId - ? { siteId: s.siteId, groupId: row.groupId } - : { siteId: s.siteId }; - }), - ); + const membershipsJson = membershipsJsonOf(sites, selected); return ( <div className="flex flex-col gap-1"> @@ -132,7 +145,7 @@ export function SiteMembershipsSection({ Pick the sites this channel appears on, and the group it belongs to on each. </p> - {sites.map((s) => { + {sites.filter((s) => !s.hidden).map((s) => { const row = selected.get(s.siteId); const on = !!row; const label = s.siteTitle || s.siteId; diff --git a/editor/app/channels/page.tsx b/editor/app/channels/page.tsx @@ -1,3 +1,5 @@ +import { displayPath, hidePrivateSites } from "yt-dlp-transcript-common/lib/privacy/privacy-server"; +import { isPrivateSite } from "yt-dlp-transcript-common/lib/siteSchema"; import type { Metadata } from "next"; import Link from "next/link"; import { @@ -150,10 +152,13 @@ function focusLabelOf( focus: SiteSettings["channelPriority"]["focus"], focusSlugs: ReadonlyArray<string>, sites: ReadonlyArray<Site>, + hidden: (site: Site) => boolean = () => false, ): string | null { if (focusSlugs.length === 0) return null; if (focus.kind === "site") { const site = sites.find((s) => s.siteId === focus.siteId); + // settings.privacy.hidePrivateSites: a private focus is not named. + if (site && hidden(site)) return "a private site"; return `site ${site?.siteTitle ?? focus.siteId}`; } return focusSlugs.length === 1 @@ -201,7 +206,11 @@ export default async function ChannelsPage({ // returns [] for an unknown siteId deliberately, so a typo never holds the // corpus, and the bar must say "No focus" rather than name a site that is not // there. - const focusLabel = focusLabelOf(priority.focus, focusSlugs, sites); + // settings.privacy.hidePrivateSites: what the Focus bar DRAWS of a private + // site (the focus itself, and what a pick submits, are unchanged). + const hidePrivate = hidePrivateSites(); + const hiddenSite = (s: Site) => hidePrivate && isPrivateSite(s); + const focusLabel = focusLabelOf(priority.focus, focusSlugs, sites, hiddenSite); // Keyed by slug rather than by index: listChannelStatsFromSnapshots happens // to map the briefs in order today, and pairing a channel's counts with // another channel's bands is exactly the kind of silent wrongness this whole @@ -252,6 +261,8 @@ export default async function ChannelsPage({ // in-place one and names the location from the volume, which is the // same prefix match the Location column shows — one answer, not two. media: mediaBySlug.get(stat.slug) ?? null, + // settings.privacy: the badge's "relocated to <path>" as displayed. + show: displayPath, volume: channelVolumeOf(brief?.config, locations), priority: { tier: tierOf(priority, stat.slug), @@ -424,7 +435,11 @@ export default async function ChannelsPage({ {channels.length === 0 ? ( <p className="text-sm text-muted-foreground border border-dashed border-border rounded p-4"> {active.siteId && !active.isAll - ? `No channels assigned to ${active.siteId} yet — add some on the Sites page, or create a channel to add it here.` + ? `No channels assigned to ${ + // settings.privacy.hidePrivateSites: a private scope (a + // `?site=` link, or the stored choice) is not named. + activeSite && hiddenSite(activeSite) ? "this private site" : active.siteId + } yet — add some on the Sites page, or create a channel to add it here.` : "No channels yet."} </p> ) : ( @@ -450,10 +465,12 @@ export default async function ChannelsPage({ root: loc.root, }))} defaultLocationId={settings.storage.defaultLocationId} - sites={sites.map((s) => ({ - siteId: s.siteId, - title: s.siteTitle || s.siteId, - }))} + sites={sites + .filter((s) => !hiddenSite(s) || (priority.focus.kind === "site" && priority.focus.siteId === s.siteId)) + .map((s) => ({ + siteId: s.siteId, + title: hiddenSite(s) ? "A private site" : s.siteTitle || s.siteId, + }))} focusLabel={focusLabel} /> )} diff --git a/editor/app/components/SiteScopeSelect.tsx b/editor/app/components/SiteScopeSelect.tsx @@ -59,7 +59,9 @@ export function SiteScopeSelect({ sites }: { sites: SiteScopeOption[] }) { [held, onSite?.siteId, param, stored], siteIds, ); - const multi = sites.length > 1; + // Over EVERY site (siteIds), not the drawn list: hidePrivateSites leaves + // private ones out of `sites`, and "All sites" must stay offered. + const multi = siteIds.length > 1; async function onChange(value: string) { if (onSite) { @@ -97,7 +99,7 @@ export function SiteScopeSelect({ sites }: { sites: SiteScopeOption[] }) { router.replace(withoutSiteParam(pathname, search), { scroll: false }); } - if (sites.length === 0) { + if (siteIds.length === 0) { return ( <div className="px-4 py-2 text-xs text-muted-foreground"> No sites — create one under Sites. @@ -124,6 +126,15 @@ export function SiteScopeSelect({ sites }: { sites: SiteScopeOption[] }) { {s.siteTitle} ({s.siteId}) </option> ))} + {/* settings.privacy.hidePrivateSites: the layout leaves the private + sites out of `sites` (they stay valid scopes). One that is the + scope anyway — the stored choice, or the site this path names — + is shown without its name rather than as some other option. */} + {resolved.value !== ALL_SITES && !sites.some((s) => s.siteId === resolved.value) && ( + <option value={resolved.value} data-private-site=""> + A private site + </option> + )} </select> </label> ); diff --git a/editor/app/layout.tsx b/editor/app/layout.tsx @@ -7,6 +7,9 @@ import { getPaths } from "yt-dlp-transcript-common/lib/paths"; import { getSettings } from "yt-dlp-transcript-common/lib/settings"; import { getLatestChangelogDate } from "yt-dlp-transcript-common/lib/changelog"; import { listSites } from "yt-dlp-transcript-common/lib/site"; +import { isPrivateSite } from "yt-dlp-transcript-common/lib/siteSchema"; +import { clientPrivacyRules, hidePrivateSites } from "yt-dlp-transcript-common/lib/privacy/privacy-server"; +import { PrivacyProvider } from "yt-dlp-transcript-common/components/PrivacyProvider"; import { fontVars } from "yt-dlp-transcript-common/styles/fonts"; import { ThemeScript } from "yt-dlp-transcript-common/components/ThemeScript"; import { ThemeProvider } from "yt-dlp-transcript-common/components/ThemeProvider"; @@ -39,6 +42,13 @@ export async function generateMetadata(): Promise<Metadata> { // NAV_GROUPS now lives in ./lib/nav (shared with the command palette). +// The privacy provider around `children` while settings.privacy has browser +// rules; otherwise `children` itself. A plain call, not a component, so a page +// with the block absent has exactly the tree it had before. +function withPrivacy(rules: ReturnType<typeof clientPrivacyRules>, children: React.ReactElement) { + return rules ? <PrivacyProvider rules={rules}>{children}</PrivacyProvider> : children; +} + function readChangelogLatestDate(): string | null { try { const source = readFileSync(getPaths().editorChangelogFile, "utf8"); @@ -60,11 +70,20 @@ export default async function RootLayout({ (j) => j.status === "running" || j.status === "queued", ).length; const latestChangelogDate = readChangelogLatestDate(); - const sites = listSites().map((s) => ({ - siteId: s.siteId, - siteTitle: s.siteTitle, - })); - const siteIds = sites.map((s) => s.siteId); + const allSites = listSites(); + // Every site stays a valid scope (siteIds); settings.privacy.hidePrivateSites + // only leaves the private ones out of the picker's list. + const siteIds = allSites.map((s) => s.siteId); + const hidePrivate = hidePrivateSites(); + const sites = allSites + .filter((s) => !(hidePrivate && isPrivateSite(s))) + .map((s) => ({ + siteId: s.siteId, + siteTitle: s.siteTitle, + })); + // The browser's display rules (settings.privacy; never the private files'), + // and the provider ONLY while there are some: absent, the tree is unchanged. + const privacyRules = clientPrivacyRules(); // THE SITE SCOPE, read once per request from its cookie and supplied to the // picker (and anything else that asks) by SiteScopeProvider. A layout has no // searchParams, so a `?site=` link is applied by the picker from the URL and @@ -136,6 +155,7 @@ export default async function RootLayout({ <body className="min-h-full flex flex-col md:flex-row bg-background text-foreground"> <ThemeScript /> <ThemeProvider> + {withPrivacy(privacyRules, <SiteScopeProvider activeSite={scope.value} fromCookie={scope.stored !== null} @@ -214,7 +234,8 @@ export default async function RootLayout({ > {children} </AppFrame> - </SiteScopeProvider> + </SiteScopeProvider>, + )} </ThemeProvider> </body> </html> diff --git a/editor/app/page.tsx b/editor/app/page.tsx @@ -1,3 +1,4 @@ +import { displayPath } from "yt-dlp-transcript-common/lib/privacy/privacy-server"; import { existsSync, readFileSync } from "node:fs"; import type { Metadata } from "next"; import { getPaths } from "yt-dlp-transcript-common/lib/paths"; @@ -127,6 +128,8 @@ export default async function Dashboard({ mediaLocationLabel: media ? locationLabelOfDataDir(media.target, locations) : undefined, + // settings.privacy: the badge's "relocated to <path>" as displayed. + show: displayPath, }); }); diff --git a/editor/app/saved-videos/page.tsx b/editor/app/saved-videos/page.tsx @@ -1,6 +1,7 @@ import type { Metadata } from "next"; import Link from "next/link"; import { getPaths } from "yt-dlp-transcript-common/lib/paths"; +import { displayPath } from "yt-dlp-transcript-common/lib/privacy/privacy-server"; import { getSettings } from "yt-dlp-transcript-common/lib/settings"; import { formatBytes } from "yt-dlp-transcript-common/lib/format"; import { listSavedVideos } from "yt-dlp-transcript-common/controller/savedVideoInventory"; @@ -85,7 +86,7 @@ export default async function SavedVideosPage() { <section aria-label="store location" className="flex flex-col gap-1 text-sm"> <div> <span className="text-muted-foreground">Default store dir: </span> - <span className="font-mono">{paths.savedVideosDir}</span> + <span className="font-mono">{displayPath(paths.savedVideosDir)}</span> </div> <div> <span className="text-muted-foreground">Last backup: </span> diff --git a/editor/app/settings/page.tsx b/editor/app/settings/page.tsx @@ -1,6 +1,7 @@ import type { Metadata } from "next"; import Link from "next/link"; import { getPaths } from "yt-dlp-transcript-common/lib/paths"; +import { displayPath } from "yt-dlp-transcript-common/lib/privacy/privacy-server"; import { getSettings } from "yt-dlp-transcript-common/lib/settings"; import { readXSessionStatus } from "yt-dlp-transcript-common/social/xSessionBroker"; import { resolveXCookieSourceFor } from "yt-dlp-transcript-common/social/xBrowserLogin"; @@ -133,7 +134,7 @@ export default async function SettingsPage() { <th className="text-left font-medium py-2 pr-4 align-top whitespace-nowrap"> {key} </th> - <td className="py-2 font-mono text-xs break-all">{value}</td> + <td className="py-2 font-mono text-xs break-all">{displayPath(value)}</td> </tr> ))} </tbody> diff --git a/editor/app/storage/components/SavedVideosStoreCard.tsx b/editor/app/storage/components/SavedVideosStoreCard.tsx @@ -1,5 +1,6 @@ "use client"; +import { useDisplay } from "yt-dlp-transcript-common/components/PrivacyProvider"; import Link from "next/link"; import { useState } from "react"; import { StreamActionLog } from "yt-dlp-transcript-common/components/StreamActionLog"; @@ -31,6 +32,9 @@ import { // `disabled` rather than becoming a second Run button. export function SavedVideosStoreCard({ store }: { store: SavedVideosView }) { + // settings.privacy: the store's path and detail as displayed (client-side: + // never the private files' rules). + const { displayPath, displayText } = useDisplay(); const [destId, setDestId] = useState(() => store.destinations[0]?.id ?? ""); const [ranResumeHere, setRanResumeHere] = useState(false); const [note, setNote] = useState<string | null>(null); @@ -82,8 +86,8 @@ export function SavedVideosStoreCard({ store }: { store: SavedVideosView }) { <dd aria-label="saved videos location">{store.locationLabel}</dd> <dt className="text-muted-foreground">Path</dt> <dd className="font-mono text-xs break-all" aria-label="saved videos path"> - {store.at} - {store.at !== store.dir ? ` (read as ${store.dir})` : ""} + {displayPath(store.at)} + {store.at !== store.dir ? ` (read as ${displayPath(store.dir)})` : ""} </dd> <dt className="text-muted-foreground">Size</dt> <dd aria-label="saved videos bytes"> @@ -99,7 +103,7 @@ export function SavedVideosStoreCard({ store }: { store: SavedVideosView }) { aria-label="saved videos detail" className="text-sm rounded border border-border bg-muted px-3 py-2" > - {store.detail} + {displayText(store.detail)} </p> )} {store.busy && ( diff --git a/editor/app/storage/components/StorageLocationsTable.tsx b/editor/app/storage/components/StorageLocationsTable.tsx @@ -1,5 +1,6 @@ "use client"; +import { useDisplay } from "yt-dlp-transcript-common/components/PrivacyProvider"; import Link from "next/link"; import { useState } from "react"; import { useRouter } from "next/navigation"; @@ -130,6 +131,9 @@ function LocationCard({ row: StorageRow; onChanged: () => void; }) { + // settings.privacy: the root and the volume as displayed (client-side: + // never the private files' rules). Actions keep the real root. + const { displayPath, displayText } = useDisplay(); const [editing, setEditing] = useState(false); const [note, setNote] = useState<string | null>(null); const [error, setError] = useState<string | null>(null); @@ -208,14 +212,15 @@ function LocationCard({ a trap for a screen reader user for the same reason. */} <dt className="text-muted-foreground">Root</dt> <dd className="font-mono text-xs break-all" aria-label="location path"> - {row.root} + {displayPath(row.root)} </dd> <dt className="text-muted-foreground">Volume</dt> <dd className="text-xs" aria-label="volume identity"> {row.kind === "internal" ? "the corpus volume" - : (row.identity ?? - "unknown — nothing here can ask (no findmnt, or a container)")} + : row.identity != null + ? displayText(row.identity) + : "unknown — nothing here can ask (no findmnt, or a container)"} </dd> <dt className="text-muted-foreground">Channels</dt> {/* THE COUNT AND THE LINK ARE TWO ELEMENTS, not one. `location channels` diff --git a/umtool/app/create/page.tsx b/umtool/app/create/page.tsx @@ -4,6 +4,7 @@ import AppShell from "@/components/shell/AppShell"; import { readCreate } from "@/lib/create"; import { policyChip } from "@/lib/create/policy.mjs"; import { generationPolicyHref, isMake, type Make } from "@/lib/hrefs"; +import { shownSources } from "@/lib/research/sources"; export const dynamic = "force-dynamic"; @@ -30,6 +31,10 @@ export default async function CreatePage({ const from = typeof sp.from === "string" && sp.from.trim() ? sp.from.trim() : null; const initial: Make | null = from ? "video-recording" : isMake(sp.make) ? sp.make : null; const data = await readCreate(); + // settings.privacy.hidePrivateSites: the research form's source picker + // DRAWS no private site (the data itself stays whole). + const sources = await shownSources(data.sources); + const shown = sources === data.sources ? data : { ...data, sources }; const chip = policyChip(data.policy?.generation ?? null, data.policy?.tasks); return ( @@ -51,7 +56,7 @@ export default async function CreatePage({ } /> <main className="deck-main flex-1 px-4 pb-6 pt-4"> - <CreateView data={data} initial={initial} from={from} initialCase={sp.case ?? null} initialArticle={sp.article ?? null} /> + <CreateView data={shown} initial={initial} from={from} initialCase={sp.case ?? null} initialArticle={sp.article ?? null} /> </main> </div> ); diff --git a/umtool/app/jobs/page.tsx b/umtool/app/jobs/page.tsx @@ -7,6 +7,7 @@ import { ActivityPanel } from "@/components/system/Status"; import { Panel } from "@/components/ui/panel"; import { listActivity, runningActivity } from "@/lib/activity"; import { queueView, rendersView } from "@/lib/queue/view"; +import { displayText } from "yt-dlp-transcript-common/lib/privacy/privacy-server"; export const dynamic = "force-dynamic"; export const metadata: Metadata = { title: "Jobs · umtool" }; @@ -39,7 +40,7 @@ export default async function JobsPage() { ) : ( <div className="space-y-1.5"> {renders.map((r) => ( - <RenderRecord key={`${r.project}:${r.take}`} project={r.project ?? ""} rec={r} showProject compact={r.state === "done"} /> + <RenderRecord key={`${r.project}:${r.take}`} project={r.project ?? ""} rec={r} showProject compact={r.state === "done"} show={displayText} /> ))} </div> )} diff --git a/umtool/app/layout.tsx b/umtool/app/layout.tsx @@ -5,6 +5,8 @@ import { fontVariables } from "./fonts"; import { LastPageRecorder } from "@/components/LastPage"; import JumpPalette from "@/components/shell/JumpPalette"; import { THEME_COOKIE, parseTheme, themeAttr } from "@/lib/theme"; +import { PrivacyProvider } from "yt-dlp-transcript-common/components/PrivacyProvider"; +import { clientPrivacyRules } from "yt-dlp-transcript-common/lib/privacy/privacy-server"; export const metadata: Metadata = { title: "umtool", @@ -31,13 +33,16 @@ export const viewport: Viewport = { // route dynamic; every page here reads the disk per request anyway. export default async function RootLayout({ children }: { children: React.ReactNode }) { const theme = parseTheme((await cookies()).get(THEME_COOKIE)?.value); + // The browser's display rules (settings.privacy; never the private files'), + // and the provider only while there are some: absent, the tree is unchanged. + const privacy = clientPrivacyRules(); return ( <html lang="en" data-theme={themeAttr(theme)} className={fontVariables}> <body className="h-full"> {/* Writes down where you are, so / can bring you back. Renders nothing, and needs no Suspense boundary -- see components/LastPage.tsx. */} <LastPageRecorder /> - {children} + {privacy ? <PrivacyProvider rules={privacy}>{children}</PrivacyProvider> : children} {/* ⌘K, on every page -- a bench with no rail included. */} <JumpPalette /> </body> diff --git a/umtool/app/page.tsx b/umtool/app/page.tsx @@ -7,6 +7,7 @@ import { buttonVariants } from "@/components/ui/button"; import { machineCalls } from "@/lib/machine"; import { homeHref, systemHref } from "@/lib/hrefs"; import { readInbox, type GroupCard, type GroupSummary } from "@/lib/inbox"; +import { privateFilter } from "@/lib/privacy"; import { summarizeGroups } from "@/lib/inbox/groups.mjs"; import { headlineNote, inboxHeadline } from "@/lib/inbox/headline.mjs"; import { whatOf } from "@/lib/inbox/what.mjs"; @@ -100,7 +101,8 @@ export default async function Inbox({ searchParams: Promise<{ hidden?: string; muted?: string }>; }) { const { hidden: showHidden, muted: showMuted } = await searchParams; - const inbox = await readInbox(); + // settings.privacy.hidePrivateSites: the private sites' cards are left out. + const inbox = await readInbox({ hide: await privateFilter() }); const lifeOf = new Map<string, LifecycleState>(); for (const d of inbox.items) if (d.piece && d.lifecycle) lifeOf.set(d.piece, d.lifecycle as LifecycleState); diff --git a/umtool/app/projects/page.tsx b/umtool/app/projects/page.tsx @@ -12,6 +12,7 @@ import ProjectGrid from "@/components/projects/ProjectGrid"; import { KINDS, decisionCounts, indexHealth, listFolders, listProjects } from "@/lib/projects"; import { PROJECT_STATES } from "@/lib/project-types"; import { projectsNote } from "@/lib/system/status"; +import { privateFilter } from "@/lib/privacy"; export const dynamic = "force-dynamic"; @@ -50,7 +51,10 @@ export default async function BrowsePage({ const sp = await searchParams; const { kind, template, state, open, q, sort } = sp; - const all = await listProjects(); + // settings.privacy.hidePrivateSites: a private site's projects are left out. + const hide = await privateFilter(); + const listed = await listProjects(); + const all = hide ? listed.filter((p) => !hide.projects.has(p.id)) : listed; const counts = await decisionCounts(); const folders = await listFolders(); diff --git a/umtool/app/research/archive/page.tsx b/umtool/app/research/archive/page.tsx @@ -5,7 +5,7 @@ import { badgeVariants } from "@/components/ui/badge"; import { scopeFrom } from "@/lib/research/corpus"; import { coverageOf } from "@/lib/research/coverage"; import { researchArchiveHref, researchHref } from "@/lib/research/hrefs"; -import { listSources } from "@/lib/research/sources"; +import { listSources, shownSources } from "@/lib/research/sources"; import type { CoverageResponse } from "@/lib/research/types"; export const dynamic = "force-dynamic"; @@ -30,6 +30,9 @@ export default async function ArchivePage({ searchParams }: { searchParams: Prom error = (e as Error).message; } const at = (handle: string) => (handle === sources[0].handle ? undefined : handle); + // settings.privacy.hidePrivateSites: what the source links DRAW (the full + // list above stays the allow-list and the default). + const shown = await shownSources(sources, scope.source); return ( <div className="flex h-full flex-col"> <AppShell @@ -39,7 +42,7 @@ export default async function ArchivePage({ searchParams }: { searchParams: Prom note={data ? `${data.rows.length} channels · ${data.years.length ? `${data.years[0]}–${data.years[data.years.length - 1]}` : "no dates"}` : undefined} /> <nav aria-label="Source" className="flex flex-wrap items-center gap-1.5 border-b border-seam px-7 py-2.5"> - {sources.map((s) => ( + {shown.map((s) => ( <Link key={s.handle} href={researchArchiveHref({ source: at(s.handle) })} diff --git a/umtool/app/research/page.tsx b/umtool/app/research/page.tsx @@ -6,7 +6,7 @@ import { listCases } from "@/lib/research/boards"; import { scopeFrom, scopeOf } from "@/lib/research/corpus"; import { researchArchiveHref } from "@/lib/research/hrefs"; import { runsHref } from "@/lib/research/runs-hrefs"; -import { listSources } from "@/lib/research/sources"; +import { listSources, shownSources } from "@/lib/research/sources"; import type { ScopeSummary } from "@/lib/research/types"; export const dynamic = "force-dynamic"; @@ -52,7 +52,7 @@ export default async function ResearchPage({ searchParams }: { searchParams: Pro } /> <ResearchView - sources={sources} + sources={await shownSources(sources, scope.source)} initialQuery={q} initialScope={scope} initialSummary={summary} diff --git a/umtool/app/work/page.tsx b/umtool/app/work/page.tsx @@ -15,6 +15,7 @@ import { createHref, siteHref, workHref, type WorkQuery } from "@/lib/hrefs"; import { ARTICLES_KEY } from "@/lib/articles/key.mjs"; import { KINDS } from "@/lib/projects"; import { readWork, type WorkRow } from "@/lib/work"; +import { privateFilter } from "@/lib/privacy"; import { LIFECYCLES, STAGES, keepRow, lifeFilter, sortRows } from "@/lib/work/facets.mjs"; import { cn } from "@/lib/utils"; @@ -62,7 +63,11 @@ const EXTRA: { key: keyof Search; label: string }[] = [ export default async function WorkPage({ searchParams }: { searchParams: Promise<Search> }) { const sp = await searchParams; - const { rows: all, lifecycleError } = await readWork(); + const { rows: read, lifecycleError } = await readWork(); + // settings.privacy.hidePrivateSites: the rows DRAWN leave out a private + // site's pieces and the projects they own (readWork itself stays whole). + const hide = await privateFilter(); + const all = hide ? read.filter((r) => !hide.pieces.has(r.id) && !(r.project && hide.projects.has(r.project))) : read; const q = sp as Record<string, string | undefined>; const shown = sortRows( all.filter((r) => keepRow(r, q)), diff --git a/umtool/components/CopyButton.tsx b/umtool/components/CopyButton.tsx @@ -1,6 +1,7 @@ "use client"; import { useState } from "react"; +import { useDisplay } from "yt-dlp-transcript-common/components/PrivacyProvider"; // Put something on the clipboard, and fall back visibly when that is not // allowed. @@ -21,6 +22,9 @@ type Props = { }; export default function CopyButton({ text, url, label = "copy", title, className }: Props) { + // settings.privacy: the clipboard always gets the REAL text; only the + // on-screen fallback box below is drawn through the displayer. + const { displayText } = useDisplay(); const [state, setState] = useState<"idle" | "busy" | "done" | "failed">("idle"); const [fallback, setFallback] = useState<string | null>(null); @@ -55,7 +59,7 @@ export default function CopyButton({ text, url, label = "copy", title, className <button type="button" onClick={run} - title={title} + title={title === undefined ? undefined : displayText(title)} data-copy data-state={state} className={ @@ -68,13 +72,15 @@ export default function CopyButton({ text, url, label = "copy", title, className {fallback !== null && ( <div className="mt-1 w-full"> <p className="text-[10px] text-[var(--color-dim)]"> - the clipboard was refused — select and copy: + {displayText(fallback) === fallback + ? "the clipboard was refused — select and copy:" + : "the clipboard was refused — privacy is on, so this is the text as shown, not the real one:"} </p> <textarea readOnly autoFocus onFocus={(e) => e.currentTarget.select()} - value={fallback} + value={displayText(fallback)} rows={8} className="w-full rounded border border-[var(--color-line)] bg-[var(--color-ink)] p-2 font-mono text-[11px] text-[var(--color-text)]" /> diff --git a/umtool/components/projects/TakeVariants.tsx b/umtool/components/projects/TakeVariants.tsx @@ -5,6 +5,7 @@ import { useRouter } from "next/navigation"; import { useState } from "react"; import DeletePlan from "@/components/DeletePlan"; import RenderRecord from "@/components/queue/RenderRecord"; +import { useDisplay } from "yt-dlp-transcript-common/components/PrivacyProvider"; import type { RenderView } from "@/lib/queue/view"; import { buttonVariants } from "@/components/ui/button"; import { takesCompareHref, takesHref } from "@/lib/hrefs"; @@ -186,6 +187,7 @@ export function CompareWith({ project, take, options }: { project: string; take: */ export function TakeWorkDirs({ project, dirs, ready }: { project: string; dirs: WorkDirs; ready: boolean }) { const router = useRouter(); + const { displayText } = useDisplay(); const [show, setShow] = useState(false); const [said, setSaid] = useState<CancelSaid | null>(null); const failed = dirs.failed ?? []; @@ -222,7 +224,7 @@ export function TakeWorkDirs({ project, dirs, ready }: { project: string; dirs: <DeletePlan label={`Delete take ${f.id}`} subject={`the failed take ${f.id}`} endpoint="/api/report/takes/delete" body={{ project, take: f.id }} onDone={() => router.refresh()} /> </span> </div> - <RenderRecord project={project} rec={f.record} /> + <RenderRecord project={project} rec={f.record} show={displayText} /> </div> ))} {dirs.cancelled.length > 0 && ( diff --git a/umtool/components/projects/TakesBench.tsx b/umtool/components/projects/TakesBench.tsx @@ -13,6 +13,7 @@ import { fmtAgo, fmtBytes } from "@/lib/format"; import { cn } from "@/lib/utils"; import { openInDraftHref, playHref, presentHref } from "@/lib/hrefs"; import RenderRecord from "@/components/queue/RenderRecord"; +import { useDisplay } from "yt-dlp-transcript-common/components/PrivacyProvider"; import type { RenderView } from "@/lib/queue/view"; import { BenchBody, VerdictBar } from "./bench/BenchShell"; import { startTakeJob } from "./NewTakePanel"; @@ -552,6 +553,7 @@ function TakeCard({ onFreed: () => void; }) { const notes = useSharedNotes({ project }); + const { displayText } = useDisplay(); const router = useRouter(); // The element, for the timed notes; the parent's callback (audio routing) // still gets it. Stable, so it runs once per mount, not once per render. @@ -790,7 +792,7 @@ function TakeCard({ </button> </div> {t.summary && <p className="text-[12px] text-[var(--color-text)]">{t.summary}</p>} - {t.render && <RenderRecord project={project} rec={t.render} compact />} + {t.render && <RenderRecord project={project} rec={t.render} compact show={displayText} />} {t.changes.length > 0 && ( <ul className="list-disc pl-4 text-[11px] text-[var(--color-dim)]"> {t.changes.map((c, i) => ( diff --git a/umtool/components/queue/QueuePanel.tsx b/umtool/components/queue/QueuePanel.tsx @@ -6,6 +6,7 @@ import { badgeVariants, type BadgeVariants } from "@/components/ui/badge"; import { buttonVariants } from "@/components/ui/button"; import { queueLogHref } from "@/lib/hrefs"; import type { RunnerView, StepView } from "@/lib/queue/view"; +import { useDisplay } from "yt-dlp-transcript-common/components/PrivacyProvider"; // THE DURABLE QUEUE (lib/queue/store.mjs), as a list: the runner (is the umtool // app running it), then each step -- its qid, state, label, what it waits on, @@ -33,6 +34,9 @@ const clock = (iso: string | null) => (iso ? iso.slice(11, 16) : ""); export default function QueuePanel({ initial, project = null, emptyText = "Nothing queued." }: { initial: View; project?: string | null; emptyText?: string }) { const router = useRouter(); + // settings.privacy: what a step's label, command and error DRAW (client-side, + // so never the private files' rules); the identity when it is off. + const { displayText } = useDisplay(); const [view, setView] = useState<View>(initial); const [said, setSaid] = useState<{ text: string; ok: boolean } | null>(null); const [ready, setReady] = useState(false); @@ -80,7 +84,7 @@ export default function QueuePanel({ initial, project = null, emptyText = "Nothi {runner.live ? ( <> Run by the umtool app (pid {runner.pid}) one step at a time. - {runner.waiting ? <span className="text-[var(--color-dim)]"> {runner.waiting}.</span> : null} + {runner.waiting ? <span className="text-[var(--color-dim)]"> {displayText(runner.waiting)}.</span> : null} </> ) : ( <span className="text-reject-text">No runner: nothing in the queue runs until the umtool app is up (archilyzer-umtool.service).</span> @@ -91,7 +95,7 @@ export default function QueuePanel({ initial, project = null, emptyText = "Nothi </p> {said && ( <p className={`m-0 text-[11.5px] ${said.ok ? "text-text-2" : "text-reject-text"}`} data-queue-said=""> - {said.text} + {displayText(said.text)} </p> )} {view.steps.length === 0 ? ( @@ -110,8 +114,8 @@ export default function QueuePanel({ initial, project = null, emptyText = "Nothi <div className="flex flex-wrap items-baseline gap-2"> <span className="font-mono text-text">{s.qid}</span> <span className={badgeVariants({ variant: TONE[s.state], size: "sm" })}>{s.state}</span> - <span className="min-w-0 truncate" title={`umtool ${s.argv.join(" ")}`} data-queue-label=""> - {s.label} + <span className="min-w-0 truncate" title={displayText(`umtool ${s.argv.join(" ")}`)} data-queue-label=""> + {displayText(s.label)} </span> {s.after && <span className="text-[11px] text-[var(--color-dim)]">after {s.after}</span>} <span className="num text-[11px] text-[var(--color-dim)]" suppressHydrationWarning> @@ -139,7 +143,7 @@ export default function QueuePanel({ initial, project = null, emptyText = "Nothi </div> {s.error && ( <p className="m-0 font-mono text-[11px] text-reject-text" data-queue-error=""> - {s.error} + {displayText(s.error)} </p> )} </li> diff --git a/umtool/components/queue/RenderRecord.tsx b/umtool/components/queue/RenderRecord.tsx @@ -10,6 +10,11 @@ import type { RenderView } from "@/lib/queue/view"; // stage and percent while it runs, and when it failed the error, the log's // last lines (folded) and the full log. Server-safe: no hooks. Used by the // Takes panel (a take's card, a first render that failed) and /jobs. +// +// `show` is the page's displayer (settings.privacy, demo epic D4): the +// server's displayText on /jobs, useDisplay()'s in a client panel; the +// identity when absent. It changes what is DRAWN — the path, the error, the +// tail — never the copied path or a data-* attribute. const TONE: Record<RenderView["state"], BadgeVariants["variant"]> = { queued: "info", @@ -20,6 +25,8 @@ const TONE: Record<RenderView["state"], BadgeVariants["variant"]> = { cancelled: "state", }; +const same = (s: string) => s; + const clock = (iso: string | null) => (iso ? iso.slice(0, 16).replace("T", " ") : ""); export default function RenderRecord({ @@ -27,6 +34,7 @@ export default function RenderRecord({ rec, showProject = false, compact = false, + show = same, }: { project: string; rec: RenderView; @@ -34,6 +42,8 @@ export default function RenderRecord({ showProject?: boolean; /** A take's card: one line, the tail folded. */ compact?: boolean; + /** The displayer for drawn text (settings.privacy); identity by default. */ + show?: (s: string) => string; }) { const live = rec.state === "running" || rec.state === "waiting"; // The output file as a local path (never an /api/ URL shown as where a file is). @@ -77,19 +87,19 @@ export default function RenderRecord({ </div> {rec.state === "done" && mp4Path && ( <p className="m-0 flex flex-wrap items-center gap-1.5 font-mono text-[11px] text-text-2" data-render-mp4={mp4Path}> - {mp4Path} + {show(mp4Path)} <CopyButton text={mp4Path} label="copy path" /> </p> )} {rec.error && ( <p className="m-0 font-mono text-[11px] text-reject-text" data-render-error=""> - {rec.error} + {show(rec.error)} </p> )} {bad && rec.tail?.length > 0 && ( <details data-render-tail="" open={!compact}> <summary className="cursor-pointer text-[11px] text-[var(--color-dim)]">the log&rsquo;s last {Math.min(rec.tail.length, 40)} lines</summary> - <pre className="m-0 mt-1 max-h-56 overflow-auto whitespace-pre-wrap break-all rounded bg-panel-2 p-1.5 text-[10.5px] leading-snug">{rec.tail.slice(-40).join("\n")}</pre> + <pre className="m-0 mt-1 max-h-56 overflow-auto whitespace-pre-wrap break-all rounded bg-panel-2 p-1.5 text-[10.5px] leading-snug">{show(rec.tail.slice(-40).join("\n"))}</pre> </details> )} </div> diff --git a/umtool/components/research/BoardView.tsx b/umtool/components/research/BoardView.tsx @@ -3,6 +3,7 @@ import Link from "next/link"; import { useRouter } from "next/navigation"; import { useCallback, useEffect, useMemo, useRef, useState } from "react"; +import { useDisplay } from "yt-dlp-transcript-common/components/PrivacyProvider"; import AppHeader from "@/components/shell/AppHeader"; import { buttonVariants } from "@/components/ui/button"; import { Dialog } from "@/components/ui/dialog"; @@ -122,6 +123,8 @@ type Ask = | { kind: "remove-quote"; q: Quote }; export default function BoardView({ initial }: { initial: CaseView }) { + // settings.privacy: a `local:` source's directory as displayed (client-side). + const { displayPath } = useDisplay(); const router = useRouter(); const hydrated = useHydrated(); // WHAT IS DRAWN, as ONE state: the case's view, the light, the list's key @@ -502,7 +505,7 @@ export default function BoardView({ initial }: { initial: CaseView }) { }, []); const s = doc.scope; - const where = view.sourceLabel ?? (s.source ? s.source.replace(/^(local|remote|hub):/, "") : "no source yet"); + const where = view.sourceLabel ?? (s.source ? displayPath(s.source.replace(/^(local|remote|hub):/, "")) : "no source yet"); const scopeLine = [where, s.channels?.length ? `${s.channels.length} ${s.channels.length === 1 ? "channel" : "channels"}` : "all channels", s.dateFrom || s.dateTo ? `${s.dateFrom ?? "…"} – ${s.dateTo ?? "…"}` : ""].filter(Boolean).join(" · "); const se = doc.search; const meta = [ diff --git a/umtool/components/system/Maintenance.tsx b/umtool/components/system/Maintenance.tsx @@ -1,3 +1,4 @@ +import { displayPath, displayText } from "yt-dlp-transcript-common/lib/privacy/privacy-server"; import ActionPlan from "@/components/system/ActionPlan"; import { Panel } from "@/components/ui/panel"; import { fmtAgo } from "@/lib/format"; @@ -32,18 +33,18 @@ export function RootsPanel({ roots }: { roots: Roots }) { <Panel title="Roots" aside={<span className="text-muted-2">umtool doctor</span>} data-panel="roots" data-roots-ok={roots.ok ? "yes" : "no"}> <dl className="m-0 grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1 text-[12px]"> <Row k="reports" bad={!roots.reports.present}> - {roots.reports.path} + {displayPath(roots.reports.path)} {roots.reports.present ? "" : " — not there"} </Row> <Row k="media" bad={!!roots.media.problem}> - {roots.media.tiered ? roots.media.path : "= reports · UMTOOL_MEDIA_DIR unset"} - {roots.media.problem ? ` — ${roots.media.problem}` : ""} + {roots.media.tiered ? displayPath(roots.media.path) : "= reports · UMTOOL_MEDIA_DIR unset"} + {roots.media.problem ? ` — ${displayText(roots.media.problem)}` : ""} </Row> <Row k="cache"> - {roots.cache.path} + {displayPath(roots.cache.path)} {roots.cache.index ? "" : " — no index yet"} </Row> - {roots.oldCache.present && <Row k="old cache">{roots.oldCache.path} — not read; safe to delete</Row>} + {roots.oldCache.present && <Row k="old cache">{displayPath(roots.oldCache.path)} — not read; safe to delete</Row>} </dl> </Panel> ); @@ -65,7 +66,7 @@ export function IndexPanel({ index }: { index: { ok: boolean; records: number; p ) : ( <p className="m-0 text-[12.5px] text-text-2">No index — every read walks the disk.</p> )} - {index.path && <p className="m-0 mt-1 truncate font-mono text-[11px] text-muted-2">{index.path}</p>} + {index.path && <p className="m-0 mt-1 truncate font-mono text-[11px] text-muted-2">{displayPath(index.path)}</p>} <div className="mt-2.5 flex flex-wrap items-start gap-2"> <ActionPlan label="Rebuild…" subject="index rebuild" endpoint="/api/system/index" body={{ action: "rebuild" }} /> <ActionPlan label="Prune…" subject="index prune" endpoint="/api/system/index" body={{ action: "prune" }} /> @@ -81,7 +82,7 @@ export function StoragePanel({ rows, tiered, mediaRoot }: { rows: StorageRow[]; return ( <Panel title="Storage" - aside={<span className="text-muted-2">umtool storage · {tiered ? `media root ${mediaRoot}` : "no media root (UMTOOL_MEDIA_DIR unset)"}</span>} + aside={<span className="text-muted-2">umtool storage · {tiered ? `media root ${displayPath(mediaRoot)}` : "no media root (UMTOOL_MEDIA_DIR unset)"}</span>} data-panel="storage" className="lg:col-span-2 2xl:col-span-3" > diff --git a/umtool/components/system/ToolsPanel.tsx b/umtool/components/system/ToolsPanel.tsx @@ -1,6 +1,7 @@ "use client"; import { useState } from "react"; +import { useDisplay } from "yt-dlp-transcript-common/components/PrivacyProvider"; import { buttonVariants } from "@/components/ui/button"; import { Panel } from "@/components/ui/panel"; import type { DoctorReport } from "@/lib/tool-types"; @@ -14,6 +15,8 @@ import { fmtAgo } from "@/lib/format"; // Red ONLY when the report pipeline needs a tool and it is absent. A missing // python on a machine that never cuts a face is a fact, not a fault. export default function ToolsPanel({ initial, freeBytes }: { initial: DoctorReport | null; freeBytes: number | null }) { + // settings.privacy: a tool's path (its title) as displayed, client-side. + const { displayText } = useDisplay(); const [report, setReport] = useState<DoctorReport | null>(initial); const [busy, setBusy] = useState(false); @@ -59,11 +62,11 @@ export default function ToolsPanel({ initial, freeBytes }: { initial: DoctorRepo data-tool={t.id} data-present={t.present ? "1" : "0"} data-required={t.required ? "1" : "0"} - title={t.error ?? t.bin} + title={displayText(t.error ?? t.bin)} className={`flex gap-1.5 ${bad ? "text-reject-text" : t.present ? "text-muted" : "text-muted opacity-70"}`} > <span className="font-mono text-text">{t.id}</span> - <span className="num truncate">{t.present ? (t.version ?? "present") : "absent"}</span> + <span className="num truncate">{t.present ? (t.version != null ? displayText(t.version) : "present") : "absent"}</span> </li> ); })} diff --git a/umtool/lib/inbox.ts b/umtool/lib/inbox.ts @@ -29,6 +29,7 @@ import { refreshDecisions } from "./inbox/refresh"; import { sourceWatchDecisions } from "./inbox/sourceWatch"; import { projectCallsAll } from "./inbox/projectCalls"; import { caseCuesDecisions } from "./inbox/caseCues"; +import { decisionIsPrivate, type PrivateFilter } from "./privacy"; // --------------------------------------------------------------------------- // THE INBOX, AS DATA: every open decision (lib/projects.ts openDecisions: the @@ -417,7 +418,7 @@ export async function diskDecisions(graph: PieceGraph, life: LifecycleRead): Pro * The inbox. `project` narrows to one song's reducer (the decisions route's * `?project=`), annotated the same way, with no disk sources added. */ -export async function readInbox({ project }: { project?: string | null } = {}): Promise<Inbox> { +export async function readInbox({ project, hide = null }: { project?: string | null; hide?: PrivateFilter | null } = {}): Promise<Inbox> { const [base, graph, life, mutes] = await Promise.all([ project ? decisionsForSong(project) : openDecisions(), readPieceGraph(), @@ -426,8 +427,12 @@ export async function readInbox({ project }: { project?: string | null } = {}): ]); // A disk source that cannot be read adds nothing; it never hides the rest. const extra = project ? [] : await diskDecisions(graph, life).catch(() => [] as Decision[]); + // settings.privacy.hidePrivateSites (lib/privacy.ts): a page that passes the + // filter leaves the private sites' decisions out; null leaves every one in. + const all = [...base, ...extra]; + const kept = hide ? all.filter((d) => !decisionIsPrivate(d, graph, hide)) : all; const items = rankDecisions( - annotate([...base, ...extra], { + annotate(kept, { pieceOf: (d: Decision) => pieceOfDecision(d, graph), lifecycleOf: (id: string) => lifecycleOf(life, id), isMuted: (piece: string, kind: string) => isMuted(mutes, piece, kind), diff --git a/umtool/lib/privacy.test.ts b/umtool/lib/privacy.test.ts @@ -0,0 +1,71 @@ +// settings.privacy.hidePrivateSites in umtool (lib/privacy.ts): which pieces, +// projects and decisions home, /projects and /work leave out — over a temp +// sites dir and a temp settings file, never the real ones. +// +// Run with: pnpm --filter umtool test (or ../node_modules/.bin/tsx --test lib/privacy.test.ts) + +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import path from "node:path"; + +const DIR = mkdtempSync(path.join(tmpdir(), "umtool-privacy-")); +const SITES = path.join(DIR, "sites"); +const SETTINGS = path.join(DIR, "settings.json"); +for (const [id, extra] of [ + ["pub", {}], + ["sec", { audience: "private" }], +] as const) { + mkdirSync(path.join(SITES, id), { recursive: true }); + writeFileSync(path.join(SITES, id, "site.json"), JSON.stringify({ siteId: id, siteTitle: id, ...extra })); +} +Object.assign(process.env, { SITES_DIR: SITES, SETTINGS_FILE: SETTINGS }); + +const { privateFilter, decisionIsPrivate } = await import("./privacy"); +const { resetPrivacyMemo } = await import("yt-dlp-transcript-common/lib/privacy/privacy-server"); +type Graph = NonNullable<Parameters<typeof privateFilter>[0]>; + +const piece = (id: string, site: string | null) => ({ id, site }) as unknown as Graph["pieces"][number]; +const GRAPH = { + pieces: [piece("a:pub/one", "pub"), piece("a:sec/two", "sec"), piece("p:loose", null)], + byId: new Map(), + pieceOfProject: new Map([ + ["videos/for-pub", "a:pub/one"], + ["videos/for-sec", "a:sec/two"], + ["loose", "p:loose"], + ]), + projectByName: new Map(), +} as unknown as Graph; + +const settings = (privacy: unknown) => { + writeFileSync(SETTINGS, JSON.stringify({ privacy })); + resetPrivacyMemo(); +}; + +test("off: null, so every list is as it was", async () => { + settings({ hidePrivateSites: false, displayPaths: "home" }); + assert.equal(await privateFilter(GRAPH), null); +}); + +test("on: a private site's articles and the projects they own; a decision about either", async () => { + settings({ hidePrivateSites: true }); + const hide = await privateFilter(GRAPH); + assert.ok(hide); + assert.deepEqual([...hide.sites], ["sec"]); + assert.deepEqual([...hide.pieces], ["a:sec/two"]); + assert.deepEqual([...hide.projects], ["videos/for-sec"]); + const d = (x: object) => ({ kind: "k", project: "", ...x }) as unknown as Parameters<typeof decisionIsPrivate>[0]; + assert.equal(decisionIsPrivate(d({ piece: "a:sec/two" }), GRAPH, hide), true); + assert.equal(decisionIsPrivate(d({ project: "videos/for-sec" }), GRAPH, hide), true); + assert.equal(decisionIsPrivate(d({ piece: "a:pub/one" }), GRAPH, hide), false); + assert.equal(decisionIsPrivate(d({ project: "loose" }), GRAPH, hide), false); +}); + +test("on, with no private site: null", async () => { + rmSync(path.join(SITES, "sec"), { recursive: true, force: true }); + settings({ hidePrivateSites: true }); + assert.equal(await privateFilter(GRAPH), null); +}); + +test.after(() => rmSync(DIR, { recursive: true, force: true })); diff --git a/umtool/lib/privacy.ts b/umtool/lib/privacy.ts @@ -0,0 +1,53 @@ +// settings.privacy.hidePrivateSites in umtool (demo epic D4): which pieces and +// projects home, /projects and /work leave out. The one notion of "private" +// is a site's own (site.json `audience: "private"`, isPrivateSite); a piece is +// private when it is an article of a private site, and a project when the +// piece it belongs to (the piece graph's pieceOfProject) is. An article's own +// `audience` is a different thing and hides nothing. +// +// A LIST FILTER, not access control: a private site's pages still open by URL. +// Null while the setting is off or no site is private — every caller then +// does exactly what it did before. +// +// SERVER ONLY. + +import { hidePrivateSites } from "yt-dlp-transcript-common/lib/privacy/privacy-server"; +import { isPrivateSite, listSites } from "yt-dlp-transcript-common/lib/site"; +import { sitesPaths } from "./articles/sites"; +import { ARTICLES_KEY } from "./articles/key.mjs"; +import { pieceOfDecision, readPieceGraph, type PieceGraph } from "./pieces"; +import type { Decision } from "./decisions"; + +export type PrivateFilter = { + sites: Set<string>; + pieces: Set<string>; + projects: Set<string>; +}; + +/** The private sites' pieces and projects, or null when nothing is hidden. */ +export async function privateFilter(graph?: PieceGraph): Promise<PrivateFilter | null> { + if (!hidePrivateSites()) return null; + let sites: Set<string> | null; + try { + sites = new Set(listSites(sitesPaths()).filter(isPrivateSite).map((s) => s.siteId)); + } catch { + // FAIL CLOSED (review round 1, S3): the sites cannot be read, so which + // are private is unknown — every site's pieces are hidden. Home, /projects + // and /work then show the article store's pieces and the projects no site + // article claims. + sites = null; + } + if (sites && !sites.size) return null; + const g = graph ?? (await readPieceGraph()); + if (!sites) sites = new Set(g.pieces.flatMap((p) => (p.site !== null && p.site !== ARTICLES_KEY ? [p.site] : []))); + const pieces = new Set(g.pieces.filter((p) => p.site !== null && sites.has(p.site)).map((p) => p.id)); + const projects = new Set([...g.pieceOfProject].filter(([, piece]) => pieces.has(piece)).map(([project]) => project)); + return { sites, pieces, projects }; +} + +/** Is this decision about a hidden piece or project? */ +export function decisionIsPrivate(d: Decision, graph: PieceGraph, hide: PrivateFilter): boolean { + if (hide.projects.has(d.project)) return true; + const piece = pieceOfDecision(d, graph); + return piece !== null && hide.pieces.has(piece); +} diff --git a/umtool/lib/research/privacySources.test.ts b/umtool/lib/research/privacySources.test.ts @@ -0,0 +1,58 @@ +// settings.privacy.hidePrivateSites and the research sources (review round 1, +// M2): the flag filters what a PICKER draws (shownSources) and nothing else. +// listSources() is also openSource's allow-list and every reader's default +// (corpus, boards, case-verify, coverage, fetch, runs-board, triage), so with +// the flag ON it must still name a private site's archive — a case on that +// source keeps reading it. Temp dirs only; nothing is fetched. +// +// Run with: pnpm --filter umtool test + +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { mkdirSync, mkdtempSync, rmSync, utimesSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import path from "node:path"; + +const D = mkdtempSync(path.join(tmpdir(), "umtool-privacy-sources-")); +const SITES = path.join(D, "sites"); +const SETTINGS = path.join(D, "settings.json"); +for (const [id, extra] of [ + ["priv", { audience: "private", siteUrl: "https://priv.invalid" }], + ["pub", { siteUrl: "https://pub.invalid" }], +] as const) { + mkdirSync(path.join(SITES, id), { recursive: true }); + writeFileSync(path.join(SITES, id, "site.json"), JSON.stringify({ siteId: id, siteTitle: `T-${id}`, ...extra })); +} +mkdirSync(path.join(D, "export"), { recursive: true }); +Object.assign(process.env, { SITES_DIR: SITES, SETTINGS_FILE: SETTINGS, TRANSCRIPT_LOCAL_DIR: path.join(D, "export"), TRANSCRIPT_HUB_URL: "" }); + +const srv = await import("yt-dlp-transcript-common/lib/privacy/privacy-server"); +const { listSources, shownSources } = await import("./sources"); + +let t = 0; +const set = (privacy: unknown) => { + writeFileSync(SETTINGS, JSON.stringify({ privacy })); + t += 10; + const d = new Date(Date.UTC(2026, 0, 1) + t * 1000); + utimesSync(SETTINGS, d, d); + srv.resetPrivacyMemo(); +}; +const handles = (l: { handle: string }[]) => l.map((s) => s.handle).filter((h) => h.startsWith("remote:")).sort(); + +test("flag ON: listSources (the allow-list, the default) still has the private site; only the picker's list drops it", async () => { + set({ hidePrivateSites: false }); + const off = await listSources(); + assert.deepEqual(handles(off), ["remote:https://priv.invalid", "remote:https://pub.invalid"]); + assert.equal(await shownSources(off), off, "off: the very same list"); + + set({ hidePrivateSites: true }); + const on = await listSources(); + assert.deepEqual(handles(on), handles(off), "every non-UI caller sees the full list"); + assert.deepEqual(handles(await shownSources(on)), ["remote:https://pub.invalid"]); + // The chosen source stays drawn, without its name. + const kept = (await shownSources(on, "remote:https://priv.invalid")).find((s) => s.handle === "remote:https://priv.invalid"); + assert.equal(kept?.label, "A private site"); + assert.equal(kept?.detail, ""); +}); + +test.after(() => rmSync(D, { recursive: true, force: true })); diff --git a/umtool/lib/research/sources.ts b/umtool/lib/research/sources.ts @@ -6,6 +6,7 @@ import { fetchOnOrigin, readBounded, type FetchLike } from "yt-dlp-transcript-co import { REPO_ROOT, REPORTS_ROOT, SITES_DIR } from "../paths.mjs"; import { readCensus } from "./census.mjs"; import type { SourceOption } from "./types"; +import { hidePrivateSites } from "yt-dlp-transcript-common/lib/privacy/privacy-server"; // --------------------------------------------------------------------------- // THE SOURCE PICKER (plans/umtool-redesign.md, "Research, first-class" 1): @@ -56,6 +57,32 @@ async function readJson<T>(file: string): Promise<T | null> { } /** Every corpus the ask bar may read, the default first: the local one, unless it has no build and an archive is offered. */ +/** + * The sources a PICKER draws (settings.privacy.hidePrivateSites): `list` + * without a private site's published archive (isPrivateSite's rule, + * `audience: "private"`). The one the page has chosen (`keep`) stays, as + * "A private site", so the picker shows what is in use. Only a page that DRAWS + * the list calls this — listSources() itself stays the full list, because it + * is also openSource's allow-list and every reader's default: a case on a + * private site's source must keep reading that source. + */ +export async function shownSources(list: SourceOption[], keep?: string | null): Promise<SourceOption[]> { + if (!hidePrivateSites()) return list; + const ids = await readdir(/* turbopackIgnore: true */ SITES_DIR).catch(() => [] as string[]); + const hidden = new Set<string>(); + for (const id of ids) { + if (id.startsWith("_") || id.startsWith(".")) continue; + const site = await readJson<{ siteUrl?: unknown; audience?: unknown }>(path.join(/* turbopackIgnore: true */ SITES_DIR, id, "site.json")); + if (site?.audience !== "private") continue; + const url = typeof site.siteUrl === "string" ? site.siteUrl.trim().replace(/\/+$/, "") : ""; + if (url) hidden.add(`remote:${url}`); + } + if (!hidden.size) return list; + return list.flatMap((s) => + !hidden.has(s.handle) ? [s] : s.handle === keep ? [{ ...s, label: "A private site", detail: "" }] : [], + ); +} + export async function listSources(): Promise<SourceOption[]> { const dir = localDir(); const corpus = await readJson<{ site?: { title?: string } }>(path.join(/* turbopackIgnore: true */ dir, "corpus.json")); diff --git a/umtool/package.json b/umtool/package.json @@ -8,7 +8,7 @@ "build": "next build", "start": "next start --port ${UMTOOL_PORT:-3050}", "typecheck": "tsc --noEmit", - "test": "tsx --test lib/brandIcon.test.ts lib/articles/*.test.ts lib/research/*.test.ts lib/inbox/*.test.ts lib/clips/*.test.ts components/projects/bench/*.test.ts", + "test": "tsx --test lib/brandIcon.test.ts lib/privacy.test.ts lib/articles/*.test.ts lib/research/*.test.ts lib/inbox/*.test.ts lib/clips/*.test.ts components/projects/bench/*.test.ts", "e2e": "node ../scripts/worktree.mjs run -- node ../scripts/queue-lock.mjs --name e2e-umtool --estimate 1500 --prebuild umtool --ports UMTOOL_E2E_PORT:3051,EDITOR_STUB_PORT:3052 -- playwright test" }, "dependencies": {