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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 8 additions & 20 deletions .github/fork-seams.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,28 +170,17 @@
"apps/web/src/components/settings/settingsSearch.ts": {
"why": "The fork's Settings page \"Fork\" (/settings/fork) is one more SettingsPath, so it needs its label, its place in the nav (the Agents group) and its search scope here; its rows are the fork's own search items (forkSettingsSearchItems.ts), spread in at one place. The import and the spread predate the list (they were \"pending\").",
"added": [
"import { FORK_SETTINGS_SEARCH_ITEMS } from \"./forkSettingsSearchItems\"; // Fork",
"...FORK_SETTINGS_SEARCH_ITEMS, // Fork: waits and agent slots."
],
"announced": {
"since": "2026-11-19",
"added": [
"import { FORK_SETTINGS_LABEL, FORK_SETTINGS_SEARCH_ITEMS } from \"./forkSettingsSearchItems\"; // Fork",
"| \"/settings/fork\" // Fork",
"\"/settings/fork\": FORK_SETTINGS_LABEL, // Fork",
"\"/settings/fork\", // Fork",
"\"/settings/fork\": null, // Fork",
"...FORK_SETTINGS_SEARCH_ITEMS, // Fork: the rows of the Fork page."
]
}
"import { FORK_SETTINGS_LABEL, FORK_SETTINGS_SEARCH_ITEMS } from \"./forkSettingsSearchItems\"; // Fork",
"| \"/settings/fork\" // Fork",
"\"/settings/fork\": FORK_SETTINGS_LABEL, // Fork",
"\"/settings/fork\", // Fork",
"\"/settings/fork\": null, // Fork",
"...FORK_SETTINGS_SEARCH_ITEMS, // Fork: the rows of the Fork page."
]
},
"apps/web/src/components/settings/SettingsSidebarNav.tsx": {
"why": "The fork's Settings page \"Fork\" (/settings/fork) needs its icon in the nav's icon table, which every SettingsPath must have.",
"added": [],
"announced": {
"since": "2026-11-19",
"added": ["GitForkIcon,", "\"/settings/fork\": GitForkIcon, // Fork"]
}
"added": ["GitForkIcon,", "\"/settings/fork\": GitForkIcon, // Fork"]
}
},
"//pending": "Upstream files whose fork lines predate counting every upstream file, each with its ceiling: the most fork lines it may hold against upstream (counted from upstream, as fork-follow runs the check). To move into fork files or pin as seams; lower a ceiling when lines move out and take a file off when none are left. A pull request may change them but not grow them.",
Expand Down Expand Up @@ -238,7 +227,6 @@
"apps/web/src/components/ChatMarkdown.tsx": 39,
"apps/web/src/components/chat/MarkdownFileLink.tsx": 32,
"apps/web/src/components/media/mediaContent.ts": 8,
"apps/web/src/components/settings/SettingsPanels.tsx": 4,
"apps/web/src/components/settings/scopedSettings.test.ts": 153,
"apps/web/src/components/settings/scopedSettings.ts": 9,
"apps/web/src/components/settings/useScopedSettings.ts": 27,
Expand Down
60 changes: 30 additions & 30 deletions FORK_CHANGES.md

Large diffs are not rendered by default.

78 changes: 7 additions & 71 deletions apps/server/src/golive/forkReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ import * as NodeSqlite from "node:sqlite";
import * as NodeURL from "node:url";

import {
effectiveReviewRules,
FORK_PROJECT_SCOPED_KEYS,
FORK_REPORT_PROJECT_FEATURES,
FORK_SERVER_SETTING_KEYS,
type HandoffSettings,
type PlaytestSettings,
type ReviewRules,
forkFeaturesWhere,
type ServerSettings,
} from "@t3tools/contracts";
import * as Cause from "effect/Cause";
Expand Down Expand Up @@ -534,75 +531,14 @@ function readSettings(
}

type ForkReportFeature = keyof ForkReport["fork"]["features"];
type ForkProjectScopedKey = (typeof FORK_PROJECT_SCOPED_KEYS)[number];

/**
* The counted features a project's override can switch on: the report reads each one's override in
* every project. A test holds it to every counted feature that is also a project-scoped setting.
*/
export const FORK_REPORT_PROJECT_FEATURES = [
"reviewRules",
"handoff",
"playtest",
] as const satisfies ReadonlyArray<ForkReportFeature & ForkProjectScopedKey>;
type ForkReportProjectFeature = (typeof FORK_REPORT_PROJECT_FEATURES)[number];
/** The counted features a project's override can switch on (the rules live in the contracts). */
export { FORK_REPORT_PROJECT_FEATURES };

/** Where each counted feature is on in `settings`: `server`, `project:<id>` or a thread's entry. */
function whereEachFeature(
/** Where each counted feature is on in `settings`, by the rules the Fork settings page reads too. */
const whereEachFeature = (
settings: ServerSettings,
): Record<ForkReportFeature, ReadonlyArray<string>> {
// A project's override replaces the server's value for that project, so it can switch a feature
// on while the server's is off. A bad value already reads as off (the settings decode).
const overrides = <K extends ForkReportProjectFeature>(key: K) =>
Object.entries(settings.projectSettingsOverrides).map(
([projectId, project]) => [projectId, project[key]] as const,
);
const server = (on: boolean) => (on ? ["server"] : []);
const perProject = {
reviewRules: whereOn(settings.reviewRules, overrides("reviewRules"), reviewRulesOn),
handoff: whereOn(settings.handoff, overrides("handoff"), handoffWhere),
playtest: whereOn(settings.playtest, overrides("playtest"), playtestOn),
} satisfies Record<ForkReportProjectFeature, ReadonlyArray<string>>;
return {
agentSlots: server(settings.agentSlots.enabled),
waitFor: server(settings.waitFor.enabled),
usagePacingGate: server(settings.usagePacingGate !== "off"),
automaticUpdates: server(settings.automaticUpdates),
...perProject,
modelPolicy: server(settings.modelPolicy.mode !== "off"),
activityProbe: server(settings.activityProbe),
};
}

/** Where a value switches its feature on, below `at` (`server` or `project:<id>`). */
type WhereOn<T> = (value: T, at: string) => ReadonlyArray<string>;
const when =
<T>(isOn: (value: T) => boolean): WhereOn<T> =>
(value, at) =>
isOn(value) ? [at] : [];
const reviewRulesOn = when((value: ReviewRules) => effectiveReviewRules(value).preset !== "off");
const playtestOn = when((value: PlaytestSettings) => value.enabled);
/** The value's own mode, and each thread whose entry is `handoff` (it wins over the mode). */
const handoffWhere: WhereOn<HandoffSettings> = (value, at) => [
...(value.mode === "handoff" ? [at] : []),
...Object.entries(value.threads)
.filter(([, mode]) => mode === "handoff")
.map(([threadId]) => `${at === "server" ? "" : `${at}/`}thread:${threadId}`),
];

/** Where the server's value and each project's (not set or null: the server's) is on. */
function whereOn<T>(
server: T,
projects: ReadonlyArray<readonly [string, T | null | undefined]>,
where: WhereOn<T>,
): ReadonlyArray<string> {
return [
...where(server, "server"),
...projects.flatMap(([projectId, value]) =>
value == null ? [] : where(value, `project:${projectId}`),
),
];
}
): Record<ForkReportFeature, ReadonlyArray<string>> => forkFeaturesWhere(settings);

/** The report as the command prints it: indented JSON. */
export const formatForkReport = (report: ForkReport): string => JSON.stringify(report, null, 2);
Expand Down
5 changes: 0 additions & 5 deletions apps/web/src/components/settings/SettingsPanels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ import {
usePrimaryEnvironmentId,
} from "../../state/environments";
import { EMPTY_SERVER_PROVIDERS } from "../../state/server";
import { WaitsAndSlotsSettings } from "./WaitsAndSlotsSettings";
import { ReviewRulesSettings } from "./ReviewRulesSettings";
import { Button } from "../ui/button";
import { DraftInput } from "../ui/draft-input";
import { Input } from "../ui/input";
Expand Down Expand Up @@ -2027,9 +2025,6 @@ export function ThreadsSettingsPanel() {
/>
</SettingsSection>

{hasServerTargets ? <WaitsAndSlotsSettings isProjectScope={isProjectScope} /> : null}
{hasServerTargets ? <ReviewRulesSettings isProjectScope={isProjectScope} /> : null}

{hasServerTargets ? (
<SettingsSection id="auto-settle" title={gt("Auto-settle")}>
<SettingsRow
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/components/settings/SettingsSidebarNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
FileDiffIcon,
FolderTreeIcon,
GitBranchIcon,
GitForkIcon,
GlobeIcon,
InfoIcon,
MessageSquareTextIcon,
Expand Down Expand Up @@ -110,6 +111,7 @@ const SETTINGS_SECTION_ICONS: Readonly<
"/settings/secrets": KeyRoundIcon,
"/settings/maintenance": WrenchIcon,
"/settings/labs": FlaskConicalIcon,
"/settings/fork": GitForkIcon, // Fork
"/settings/about": InfoIcon,
"/settings/archived": ArchiveIcon,
};
Expand Down
88 changes: 88 additions & 0 deletions apps/web/src/components/settings/fork/ForkRow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* Fork: a settings row whose every control follows the row's lock. Upstream's row greys out only its
* main control under an administrator's lock, and its sub-controls only when it is server-scoped;
* the Fork page's rows keep switches, lists and text boxes below the title, so those are made inert
* too. The server refuses such a write anyway; this only keeps a click from ending in an error.
*/
/* oxlint-disable t3code/no-untranslated-copy -- Fork: the fork's own settings are English only; upstream's translation catalogs hold no fork keys. */
import { isManagedSettingPath } from "@t3tools/contracts";
import { type ComponentProps, useState } from "react";

import { useEnvironmentProviders } from "../../../state/environments";
import { EMPTY_SERVER_PROVIDERS } from "../../../state/server";
import { IntervalSecondsField } from "../IntervalSecondsField";
import { useSettingsScope } from "../SettingsScopeContext";
import { SettingsRow } from "../settingsLayout";
import { useScopedSettingsWriteAllowed } from "../useScopedSettings";

/** Every selected environment's accounts, the primary's first, as the agent slots rows list them. */
export function useSelectedProviders() {
const { environment, connectedEnvironments } = useSettingsScope();
const providersByEnvironment = useEnvironmentProviders();
return [
...(environment ? [environment] : []),
...connectedEnvironments.filter(
(candidate) => candidate.environmentId !== environment?.environmentId,
),
].flatMap(
(candidate) => providersByEnvironment.get(candidate.environmentId) ?? EMPTY_SERVER_PROVIDERS,
);
}

/** Why the row's setting cannot be changed here: an administrator's lock or no write permission. */
function useForkRowLock(paths: ReadonlyArray<string>): string | undefined {
const { connectedEnvironments } = useSettingsScope();
const writeAllowed = useScopedSettingsWriteAllowed();
const organization = connectedEnvironments
.map((environment) => environment.serverConfig?.managedPolicy)
.find(
(policy) => policy !== undefined && paths.some((path) => isManagedSettingPath(policy, path)),
)?.organization;
if (organization !== undefined) return `Managed by ${organization}.`;
if (!writeAllowed) return "This connection lacks permission to change settings here.";
return undefined;
}

/** A settings row locked by `lockPaths` (setting keys or dot paths): its control and children alike. */
export function ForkRow({
lockPaths,
children,
...props
}: ComponentProps<typeof SettingsRow> & { readonly lockPaths: ReadonlyArray<string> }) {
const lock = useForkRowLock(lockPaths);
return (
<SettingsRow {...props} {...(lock === undefined ? {} : { managed: lock })}>
{lock === undefined || !children ? (
children
) : (
<div inert className="opacity-50">
{children}
</div>
)}
</SettingsRow>
);
}

/**
* Upstream's number field, with the value bounded before it is saved. When the bound changes the
* typed number, the field starts again from the saved value; otherwise it would keep showing the
* typed number, as the saved value (and so the field's prop) may not change.
*/
export function BoundedNumberField({
bound,
onCommit,
...props
}: ComponentProps<typeof IntervalSecondsField> & { readonly bound: (value: number) => number }) {
const [resets, setResets] = useState(0);
return (
<IntervalSecondsField
key={resets}
{...props}
onCommit={(value, options) => {
const bounded = bound(value);
if (bounded !== value) setResets((count) => count + 1);
onCommit(bounded, options);
}}
/>
);
}
84 changes: 84 additions & 0 deletions apps/web/src/components/settings/fork/ForkSettingsPanel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* Fork: the Settings page "Fork" (/settings/fork), every fork setting in one place. Each group
* mounts the fork's own panels; a project screen shows only the settings a project may override.
*/
/* oxlint-disable t3code/no-untranslated-copy -- Fork: this page is the fork's own and its text is English only; upstream's translation catalogs hold no fork keys. */
import { DEFAULT_SERVER_SETTINGS } from "@t3tools/contracts";
import type { ReactNode } from "react";

import { ReviewRulesSettings } from "../ReviewRulesSettings";
import { useSettingsScope } from "../SettingsScopeContext";
import { SettingsPageContainer, SettingsRow, SettingsSection } from "../settingsLayout";
import { useSearchableSetting } from "../settingsSearch";
import { WaitsAndSlotsSettings } from "../WaitsAndSlotsSettings";
import { forkFeatureStatuses } from "./forkStatus.logic";
import { ModelPolicySettings } from "./ModelPolicySettings";
import { UsagePacingSettings } from "./UsagePacingSettings";

export function ForkSettingsPanel() {
const { connectedEnvironments, scope } = useSettingsScope();
const isProjectScope = scope.kind === "project" || scope.kind === "checkout";
if (connectedEnvironments.length === 0) {
return (
<SettingsPageContainer>
<SettingsSection id="fork-status-section" title="Fork">
<SettingsRow
title="No server connected"
description="Fork settings live on a server. Connect one to see and change them."
/>
</SettingsSection>
</SettingsPageContainer>
);
}
return (
<SettingsPageContainer>
<ForkStatusSection />
<ForkGroup title="Agents">
<WaitsAndSlotsSettings isProjectScope={isProjectScope} />
{isProjectScope ? null : <UsagePacingSettings />}
{isProjectScope ? null : <ModelPolicySettings />}
</ForkGroup>
<ForkGroup title="Reviews">
<ReviewRulesSettings isProjectScope={isProjectScope} />
</ForkGroup>
</SettingsPageContainer>
);
}

function ForkStatusSection() {
const searchableSetting = useSearchableSetting();
const { targets } = useSettingsScope();
const statuses = forkFeatureStatuses(
targets.length > 0 ? targets : [{ projectId: null, settings: DEFAULT_SERVER_SETTINGS }],
);
return (
<SettingsSection id="fork-status-section" title="Overview">
<SettingsRow
{...searchableSetting("fork-status")}
description="What the selected server or project has on, by the fork report's rules: on a server, a project's override or one thread's handoff entry counts too. Every feature starts off."
>
<ul className="grid gap-x-8 gap-y-1 pb-2 text-xs sm:grid-cols-2">
{statuses.map((status) => (
<li key={status.key} className="flex justify-between gap-2">
<span className="text-muted-foreground">{status.label}</span>
<span className={status.on ? "font-medium text-foreground" : "text-muted-foreground"}>
{status.detail}
</span>
</li>
))}
</ul>
</SettingsRow>
</SettingsSection>
);
}

function ForkGroup({ title, children }: { readonly title: string; readonly children: ReactNode }) {
return (
<div role="group" aria-label={title} className="flex flex-col gap-8">
<p className="-mb-4 px-3 text-xs font-medium uppercase tracking-wide text-muted-foreground sm:px-4">
{title}
</p>
{children}
</div>
);
}
Loading
Loading