diff --git a/.github/fork-seams.json b/.github/fork-seams.json index 231c84f8c3b1b..d87b5963d0cdb 100644 --- a/.github/fork-seams.json +++ b/.github/fork-seams.json @@ -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.", @@ -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, diff --git a/FORK_CHANGES.md b/FORK_CHANGES.md index a87e13667c849..c99b0ea304364 100644 --- a/FORK_CHANGES.md +++ b/FORK_CHANGES.md @@ -12,36 +12,36 @@ setting is missing here or a setting named here does not exist. ## In T3 Code itself -| Change | Why | Setting | Default | PR | -| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| The server, the CLI and the desktop app look for updates in this fork's releases, not upstream's. | A fork build must never "update" to an upstream build and lose the fork's changes. | none | always | [#1](https://github.com/scuttletoby/t3code/pull/1) | -| A server installed as a boot service can update itself once no thread is working, after an optional "is it quiet?" command agrees. | Updates without someone watching, and without cutting off running work. | `server.automaticUpdates`, `server.automaticUpdatesQuietCommand` | off | [#5](https://github.com/scuttletoby/t3code/pull/5) | -| Every fork setting has a pinned default, and lives in the fork's own file (`forkSettings.ts`). | An upstream sync can never switch a fork feature on, and a new setting touches no upstream file. | none | always | [#171](https://github.com/scuttletoby/t3code/pull/171), [#185](https://github.com/scuttletoby/t3code/pull/185) | -| The server keeps a history of each provider account's usage-limit readings. | Pacing needs to know how fast a limit is being used, not only where it stands. | none | always (read only) | [#24](https://github.com/scuttletoby/t3code/pull/24) | -| The server reads usage limits every 10 minutes while no app is open. | Pacing has current numbers on a machine nobody is looking at. | `server.headlessUsageRefreshInterval` | on (10 minutes); read only | [#42](https://github.com/scuttletoby/t3code/pull/42) | -| Usage pacing: a reserve of each limit window kept free for the person, and an even pace for agents. | Agents should not use up a subscription before its owner needs it. | `server.usagePacing` | off | [#52](https://github.com/scuttletoby/t3code/pull/52) | -| The pacing gate on `delegate_task`: advise only, or move, lower the effort of, or hold a task on an account that is ahead of pace. | Delegated work follows the pace without the agent having to check. | `server.usagePacingGate`, `server.usagePacingLowerEffort` | off | [#73](https://github.com/scuttletoby/t3code/pull/73) | -| Agent slots: `delegate_task` is refused above a number of running agents per machine or account, or below a memory floor. | Too many agents at once can overload a small machine. | `server.agentSlots` | off; rule only observes | [#84](https://github.com/scuttletoby/t3code/pull/84), [#89](https://github.com/scuttletoby/t3code/pull/89) | -| Waits: agents can wait for a pull request, a file, a system unit, a named check command or a free agent slot (`wait_for`, `wait_list`, `wait_cancel`), and are woken when it happens. | An agent no longer polls or sleeps while it waits. | `server.waitFor`, `server.waitChecks`, `projectOverride.waitChecks` | off | [#84](https://github.com/scuttletoby/t3code/pull/84), [#90](https://github.com/scuttletoby/t3code/pull/90), [#91](https://github.com/scuttletoby/t3code/pull/91), [#103](https://github.com/scuttletoby/t3code/pull/103), [#106](https://github.com/scuttletoby/t3code/pull/106), [#109](https://github.com/scuttletoby/t3code/pull/109), [#110](https://github.com/scuttletoby/t3code/pull/110), [#116](https://github.com/scuttletoby/t3code/pull/116), [#119](https://github.com/scuttletoby/t3code/pull/119) | -| Settings pages for waits, wait checks and agent slots. | Switch these on without editing a file. | `server.waitFor`, `server.waitChecks`, `server.agentSlots` | off | [#104](https://github.com/scuttletoby/t3code/pull/104) | -| The fork's checks on `delegate_task` (pacing, slots) sit behind one fork module. | Fewer fork lines in upstream's code, so syncs conflict less. No change in behaviour. | none | always | [#174](https://github.com/scuttletoby/t3code/pull/174) | -| The fork's service layers in the server are wired from one fork file (`apps/server/src/fork/forkLayers.ts`). | Fewer fork lines in upstream's code, so syncs conflict less. No change in behaviour. | none | always | [#384](https://github.com/scuttletoby/t3code/pull/384) | -| A pure capacity rule for "dynamic slots" (one budget per machine), with shared test cases. Not wired into anything yet. | A later step replaces fixed agent counts with what the machine can take. | none | not used | [#203](https://github.com/scuttletoby/t3code/pull/203) | -| File links in chat open in the files viewer, full size, or in an editor on a remote machine, and can be downloaded, from their menu. | File links were only copyable on remote machines and had no menu on touch screens. | none | always | [#17](https://github.com/scuttletoby/t3code/pull/17) | -| A hidden read-only command, `t3 __fork-report --base-dir `, prints what a T3 home holds and which fork features are on, and where. | The go-live kit checks a build and a home before switching, without writing anything. | none | only when run | [#172](https://github.com/scuttletoby/t3code/pull/172), [#184](https://github.com/scuttletoby/t3code/pull/184) | -| A local, read-only "is T3 busy?" answer: `GET /api/fork/activity` on loopback, and `t3 __fork-report --base-dir --activity`, which asks it and exits 0 only when nothing is working. | A host quiet check reads T3's own turns and approvals instead of guessing from processes. | `server.activityProbe` | off | [#547](https://github.com/scuttletoby/t3code/pull/547) | -| `t3 serve --hold-work` starts a server on a copy of a T3 home with all agent work and T3 Connect held. | Look at a new build's threads and migrations on a copy before it replaces a running T3. | none | only with the flag | [#175](https://github.com/scuttletoby/t3code/pull/175) | -| Docs: one machine for new work through upstream's load-balancing weights; settings saved with an early draft's client setting for it still load. | Upstream already has the feature, so the fork's own setting was removed. | none | - | [#25](https://github.com/scuttletoby/t3code/pull/25) | -| MCP profiles: named profiles (which outside MCP servers and T3 tool groups a thread gets), a default, a sub-agent rule, a pick per thread and the rules that pick one. Claude applies the outside servers and refuses a turn when its profile cannot. | Fewer tools per thread saves tokens and keeps agents from tools they should not use. | `server.mcpProfiles`, `server.mcpProfile`, `server.mcpSubagentProfile`, `server.mcpThreadProfiles`, `projectOverride.mcpProfile`, `projectOverride.mcpSubagentProfile` | off | [#227](https://github.com/scuttletoby/t3code/pull/227), [#528](https://github.com/scuttletoby/t3code/pull/528) | -| Playtest mode, part 1: settings for a project's playtest adapter (claim, renew, push and release steps only the person sets) and the contract those steps follow. Nothing starts a session yet. | A person tries an agent's unfinished work on a test target, round after round, no PR per round. | `server.playtest`, `projectOverride.playtest` | off | [#260](https://github.com/scuttletoby/t3code/pull/260) | -| Playtest mode, part 2: the session store and service: start (claim), rounds of push steps, end (release), kept across restarts. A session keeps the steps it started with. No tool calls it yet. | A person tries an agent's unfinished work on a test target, round after round, no PR per round. | `server.playtest`, `projectOverride.playtest` | off | [#261](https://github.com/scuttletoby/t3code/pull/261) | -| Playtest mode, part 3: the worker renews claims, ends idle, too-long and gone-thread sessions, finishes what a restart cut, and tells the thread once when T3 ended a session. | A person tries an agent's unfinished work on a test target, round after round, no PR per round. | `server.playtest`, `projectOverride.playtest` | off | [#262](https://github.com/scuttletoby/t3code/pull/262) | -| Handoff instead of compaction, part 1: the setting and the pure "should this thread hand off now?" decision. Nothing acts on it yet. | Long threads keep their children, PRs and waits instead of compacting. | `server.handoff`, `projectOverride.handoff` | off | [#282](https://github.com/scuttletoby/t3code/pull/282) | -| Review rules, part 1: the setting for how this machine runs a review lens (runner, state question), off by default; `{"preset": "recommended"}` turns the fork's defaults on. A bad hand edit reads as off and is kept. Nothing reads it yet. | The repo says what a pull request needs and CI enforces it; the machine says how reviews run. | `server.reviewRules`, `projectOverride.reviewRules` | off | [#291](https://github.com/scuttletoby/t3code/pull/291) | -| An interval setting the settings file cannot hold (negative, not finite, too large) is refused when saved; one already in the file reads as its default instead of resetting every setting. A test finds every interval setting from the schema. | A `1e400` saved as `null` made the next start reject the whole settings file. | none | always | [#323](https://github.com/scuttletoby/t3code/pull/323) | -| Handoff instead of compaction, part 2: the handoff service hands a big or idle thread to a fresh session in the same thread, with T3's state and the recent conversation, only while the thread is quiet and still at the run that triggered it. | Long threads keep their children, PRs and waits instead of compacting. | `server.handoff`, `projectOverride.handoff` | off | [#320](https://github.com/scuttletoby/t3code/pull/320) | -| A task delegated to a linked environment is still followed if the delegating call is cut off, and still delivers its reply when that environment runs another T3 version. | Its parent was never told: the task stayed running here and its result never arrived. | none | always | [#412](https://github.com/scuttletoby/t3code/pull/412), [#540](https://github.com/scuttletoby/t3code/pull/540) | -| Model policy, part 1: the setting for which models (and efforts) agents may pick, per provider driver: off, advise or enforce, and the allowed rows. A bad hand edit reads as nothing allowed. Nothing reads the setting yet. | Agents should use the models the person chose for each kind of work. | `server.modelPolicy` | off | [#268](https://github.com/scuttletoby/t3code/pull/268) | +| Change | Why | Setting | Default | PR | +| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| The server, the CLI and the desktop app look for updates in this fork's releases, not upstream's. | A fork build must never "update" to an upstream build and lose the fork's changes. | none | always | [#1](https://github.com/scuttletoby/t3code/pull/1) | +| A server installed as a boot service can update itself once no thread is working, after an optional "is it quiet?" command agrees. | Updates without someone watching, and without cutting off running work. | `server.automaticUpdates`, `server.automaticUpdatesQuietCommand` | off | [#5](https://github.com/scuttletoby/t3code/pull/5) | +| Every fork setting has a pinned default, and lives in the fork's own file (`forkSettings.ts`). | An upstream sync can never switch a fork feature on, and a new setting touches no upstream file. | none | always | [#171](https://github.com/scuttletoby/t3code/pull/171), [#185](https://github.com/scuttletoby/t3code/pull/185) | +| The server keeps a history of each provider account's usage-limit readings. | Pacing needs to know how fast a limit is being used, not only where it stands. | none | always (read only) | [#24](https://github.com/scuttletoby/t3code/pull/24) | +| The server reads usage limits every 10 minutes while no app is open. | Pacing has current numbers on a machine nobody is looking at. | `server.headlessUsageRefreshInterval` | on (10 minutes); read only | [#42](https://github.com/scuttletoby/t3code/pull/42) | +| Usage pacing: a reserve of each limit window kept free for the person, and an even pace for agents. | Agents should not use up a subscription before its owner needs it. | `server.usagePacing` | off | [#52](https://github.com/scuttletoby/t3code/pull/52) | +| The pacing gate on `delegate_task`: advise only, or move, lower the effort of, or hold a task on an account that is ahead of pace. | Delegated work follows the pace without the agent having to check. | `server.usagePacingGate`, `server.usagePacingLowerEffort` | off | [#73](https://github.com/scuttletoby/t3code/pull/73) | +| Agent slots: `delegate_task` is refused above a number of running agents per machine or account, or below a memory floor. | Too many agents at once can overload a small machine. | `server.agentSlots` | off; rule only observes | [#84](https://github.com/scuttletoby/t3code/pull/84), [#89](https://github.com/scuttletoby/t3code/pull/89) | +| Waits: agents can wait for a pull request, a file, a system unit, a named check command or a free agent slot (`wait_for`, `wait_list`, `wait_cancel`), and are woken when it happens. | An agent no longer polls or sleeps while it waits. | `server.waitFor`, `server.waitChecks`, `projectOverride.waitChecks` | off | [#84](https://github.com/scuttletoby/t3code/pull/84), [#90](https://github.com/scuttletoby/t3code/pull/90), [#91](https://github.com/scuttletoby/t3code/pull/91), [#103](https://github.com/scuttletoby/t3code/pull/103), [#106](https://github.com/scuttletoby/t3code/pull/106), [#109](https://github.com/scuttletoby/t3code/pull/109), [#110](https://github.com/scuttletoby/t3code/pull/110), [#116](https://github.com/scuttletoby/t3code/pull/116), [#119](https://github.com/scuttletoby/t3code/pull/119) | +| The Settings page **Fork** (`/settings/fork`): every fork setting in one place, with one line per feature at the top saying whether it is on. So far: waits, wait checks, agent slots, usage pacing (per account by name), model policy and review rules. | Change every fork setting without editing a file. | `server.waitFor`, `server.waitChecks`, `server.agentSlots`, `server.usagePacing`, `server.usagePacingGate`, `server.usagePacingLowerEffort`, `server.reviewRules`, `server.modelPolicy` | off | [#104](https://github.com/scuttletoby/t3code/pull/104) | +| The fork's checks on `delegate_task` (pacing, slots) sit behind one fork module. | Fewer fork lines in upstream's code, so syncs conflict less. No change in behaviour. | none | always | [#174](https://github.com/scuttletoby/t3code/pull/174) | +| The fork's service layers in the server are wired from one fork file (`apps/server/src/fork/forkLayers.ts`). | Fewer fork lines in upstream's code, so syncs conflict less. No change in behaviour. | none | always | [#384](https://github.com/scuttletoby/t3code/pull/384) | +| A pure capacity rule for "dynamic slots" (one budget per machine), with shared test cases. Not wired into anything yet. | A later step replaces fixed agent counts with what the machine can take. | none | not used | [#203](https://github.com/scuttletoby/t3code/pull/203) | +| File links in chat open in the files viewer, full size, or in an editor on a remote machine, and can be downloaded, from their menu. | File links were only copyable on remote machines and had no menu on touch screens. | none | always | [#17](https://github.com/scuttletoby/t3code/pull/17) | +| A hidden read-only command, `t3 __fork-report --base-dir `, prints what a T3 home holds and which fork features are on, and where. | The go-live kit checks a build and a home before switching, without writing anything. | none | only when run | [#172](https://github.com/scuttletoby/t3code/pull/172), [#184](https://github.com/scuttletoby/t3code/pull/184) | +| A local, read-only "is T3 busy?" answer: `GET /api/fork/activity` on loopback, and `t3 __fork-report --base-dir --activity`, which asks it and exits 0 only when nothing is working. | A host quiet check reads T3's own turns and approvals instead of guessing from processes. | `server.activityProbe` | off | [#547](https://github.com/scuttletoby/t3code/pull/547) | +| `t3 serve --hold-work` starts a server on a copy of a T3 home with all agent work and T3 Connect held. | Look at a new build's threads and migrations on a copy before it replaces a running T3. | none | only with the flag | [#175](https://github.com/scuttletoby/t3code/pull/175) | +| Docs: one machine for new work through upstream's load-balancing weights; settings saved with an early draft's client setting for it still load. | Upstream already has the feature, so the fork's own setting was removed. | none | - | [#25](https://github.com/scuttletoby/t3code/pull/25) | +| MCP profiles: named profiles (which outside MCP servers and T3 tool groups a thread gets), a default, a sub-agent rule, a pick per thread and the rules that pick one. Claude applies the outside servers and refuses a turn when its profile cannot. | Fewer tools per thread saves tokens and keeps agents from tools they should not use. | `server.mcpProfiles`, `server.mcpProfile`, `server.mcpSubagentProfile`, `server.mcpThreadProfiles`, `projectOverride.mcpProfile`, `projectOverride.mcpSubagentProfile` | off | [#227](https://github.com/scuttletoby/t3code/pull/227), [#528](https://github.com/scuttletoby/t3code/pull/528) | +| Playtest mode, part 1: settings for a project's playtest adapter (claim, renew, push and release steps only the person sets) and the contract those steps follow. Nothing starts a session yet. | A person tries an agent's unfinished work on a test target, round after round, no PR per round. | `server.playtest`, `projectOverride.playtest` | off | [#260](https://github.com/scuttletoby/t3code/pull/260) | +| Playtest mode, part 2: the session store and service: start (claim), rounds of push steps, end (release), kept across restarts. A session keeps the steps it started with. No tool calls it yet. | A person tries an agent's unfinished work on a test target, round after round, no PR per round. | `server.playtest`, `projectOverride.playtest` | off | [#261](https://github.com/scuttletoby/t3code/pull/261) | +| Playtest mode, part 3: the worker renews claims, ends idle, too-long and gone-thread sessions, finishes what a restart cut, and tells the thread once when T3 ended a session. | A person tries an agent's unfinished work on a test target, round after round, no PR per round. | `server.playtest`, `projectOverride.playtest` | off | [#262](https://github.com/scuttletoby/t3code/pull/262) | +| Handoff instead of compaction, part 1: the setting and the pure "should this thread hand off now?" decision. Nothing acts on it yet. | Long threads keep their children, PRs and waits instead of compacting. | `server.handoff`, `projectOverride.handoff` | off | [#282](https://github.com/scuttletoby/t3code/pull/282) | +| Review rules, part 1: the setting for how this machine runs a review lens (runner, state question), off by default; `{"preset": "recommended"}` turns the fork's defaults on. A bad hand edit reads as off and is kept. Nothing reads it yet. | The repo says what a pull request needs and CI enforces it; the machine says how reviews run. | `server.reviewRules`, `projectOverride.reviewRules` | off | [#291](https://github.com/scuttletoby/t3code/pull/291) | +| An interval setting the settings file cannot hold (negative, not finite, too large) is refused when saved; one already in the file reads as its default instead of resetting every setting. A test finds every interval setting from the schema. | A `1e400` saved as `null` made the next start reject the whole settings file. | none | always | [#323](https://github.com/scuttletoby/t3code/pull/323) | +| Handoff instead of compaction, part 2: the handoff service hands a big or idle thread to a fresh session in the same thread, with T3's state and the recent conversation, only while the thread is quiet and still at the run that triggered it. | Long threads keep their children, PRs and waits instead of compacting. | `server.handoff`, `projectOverride.handoff` | off | [#320](https://github.com/scuttletoby/t3code/pull/320) | +| A task delegated to a linked environment is still followed if the delegating call is cut off, and still delivers its reply when that environment runs another T3 version. | Its parent was never told: the task stayed running here and its result never arrived. | none | always | [#412](https://github.com/scuttletoby/t3code/pull/412), [#540](https://github.com/scuttletoby/t3code/pull/540) | +| Model policy, part 1: the setting for which models (and efforts) agents may pick, per provider driver: off, advise or enforce, and the allowed rows. A bad hand edit reads as nothing allowed. Nothing reads the setting yet. | Agents should use the models the person chose for each kind of work. | `server.modelPolicy` | off | [#268](https://github.com/scuttletoby/t3code/pull/268) | ## Repository, CI and releases diff --git a/apps/server/src/golive/forkReport.ts b/apps/server/src/golive/forkReport.ts index 455c99050c812..71a631e5a1134 100644 --- a/apps/server/src/golive/forkReport.ts +++ b/apps/server/src/golive/forkReport.ts @@ -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"; @@ -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; -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:` 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> { - // 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 = (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>; - 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:`). */ -type WhereOn = (value: T, at: string) => ReadonlyArray; -const when = - (isOn: (value: T) => boolean): WhereOn => - (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 = (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( - server: T, - projects: ReadonlyArray, - where: WhereOn, -): ReadonlyArray { - return [ - ...where(server, "server"), - ...projects.flatMap(([projectId, value]) => - value == null ? [] : where(value, `project:${projectId}`), - ), - ]; -} +): Record> => forkFeaturesWhere(settings); /** The report as the command prints it: indented JSON. */ export const formatForkReport = (report: ForkReport): string => JSON.stringify(report, null, 2); diff --git a/apps/web/src/components/settings/SettingsPanels.tsx b/apps/web/src/components/settings/SettingsPanels.tsx index eee39d849d745..e0a12417848fa 100644 --- a/apps/web/src/components/settings/SettingsPanels.tsx +++ b/apps/web/src/components/settings/SettingsPanels.tsx @@ -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"; @@ -2027,9 +2025,6 @@ export function ThreadsSettingsPanel() { /> - {hasServerTargets ? : null} - {hasServerTargets ? : null} - {hasServerTargets ? ( 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 | 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 & { readonly lockPaths: ReadonlyArray }) { + const lock = useForkRowLock(lockPaths); + return ( + + {lock === undefined || !children ? ( + children + ) : ( +
+ {children} +
+ )} +
+ ); +} + +/** + * 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 & { readonly bound: (value: number) => number }) { + const [resets, setResets] = useState(0); + return ( + { + const bounded = bound(value); + if (bounded !== value) setResets((count) => count + 1); + onCommit(bounded, options); + }} + /> + ); +} diff --git a/apps/web/src/components/settings/fork/ForkSettingsPanel.tsx b/apps/web/src/components/settings/fork/ForkSettingsPanel.tsx new file mode 100644 index 0000000000000..95a3da387ea91 --- /dev/null +++ b/apps/web/src/components/settings/fork/ForkSettingsPanel.tsx @@ -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 ( + + + + + + ); + } + return ( + + + + + {isProjectScope ? null : } + {isProjectScope ? null : } + + + + + + ); +} + +function ForkStatusSection() { + const searchableSetting = useSearchableSetting(); + const { targets } = useSettingsScope(); + const statuses = forkFeatureStatuses( + targets.length > 0 ? targets : [{ projectId: null, settings: DEFAULT_SERVER_SETTINGS }], + ); + return ( + + +
    + {statuses.map((status) => ( +
  • + {status.label} + + {status.detail} + +
  • + ))} +
+
+
+ ); +} + +function ForkGroup({ title, children }: { readonly title: string; readonly children: ReactNode }) { + return ( +
+

+ {title} +

+ {children} +
+ ); +} diff --git a/apps/web/src/components/settings/fork/ModelPolicySettings.tsx b/apps/web/src/components/settings/fork/ModelPolicySettings.tsx new file mode 100644 index 0000000000000..5c20b19aba109 --- /dev/null +++ b/apps/web/src/components/settings/fork/ModelPolicySettings.tsx @@ -0,0 +1,311 @@ +/** + * Fork: the model policy (`modelPolicy`), which models agents may pick. Server-wide (a project cannot + * override it), so a project screen does not show it. A save sends the whole value, `mode` and + * `allow`, as the server requires. Every write is an ordinary settings patch from the person at the + * screen; agents cannot change it. + */ +/* oxlint-disable t3code/no-untranslated-copy -- Fork: this panel is the fork's own and its text is English only; upstream's translation catalogs hold no fork keys. */ +import { + DEFAULT_MODEL_POLICY, + type ModelPolicy, + type ModelPolicyMode, + type ModelPolicyPatch, +} from "@t3tools/contracts"; +import { useState } from "react"; + +import { Button } from "../../ui/button"; +import { + Dialog, + DialogDescription, + DialogFooter, + DialogHeader, + DialogPanel, + DialogPopup, + DialogTitle, +} from "../../ui/dialog"; +import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../../ui/select"; +import { Textarea } from "../../ui/textarea"; +import { useSettingsScope } from "../SettingsScopeContext"; +import { SettingResetButton, SettingsSection } from "../settingsLayout"; +import { useSearchableSetting } from "../settingsSearch"; +import { useScopedSettings, useUpdateScopedSettings } from "../useScopedSettings"; +import { targetsDiffer } from "../waitsAndSlotsSettings.logic"; +import { ForkRow, useSelectedProviders } from "./ForkRow"; +import { + MODEL_POLICY_MODE_OPTIONS, + modelPolicyEditorText, + modelPolicyRowLine, + unknownModelPolicyDrivers, + unreadableModelPolicyMode, + unreadableModelPolicyText, + withModelPolicyAllow, +} from "./modelPolicySettings.logic"; + +const MIXED = "The selected environments have different values. Select one environment to edit it."; + +/** The warning for a settings-file value that cannot be read, with the file's own text. */ +function UnreadableWarning({ + text, + children, +}: { + readonly text: string; + readonly children: string; +}) { + return ( +
+ The settings file's model policy cannot be read, so it reads as Enforce with nothing + allowed: every pick is refused. It is kept as written until you save here. {children} + {text} +
+ ); +} + +function AllowDialog({ + value, + onOpenChange, + onSave, +}: { + readonly value: ModelPolicy; + readonly onOpenChange: (open: boolean) => void; + readonly onSave: (next: ModelPolicyPatch, onSaved: () => void, onFailed: () => void) => void; +}) { + const unreadableText = unreadableModelPolicyText(value); + const [text, setText] = useState(() => modelPolicyEditorText(value)); + // An unreadable value has no mode to keep: its `enforce` is only the fail-closed reading, so the + // person picks the mode this save writes, the file's own one offered first when it names one. + const [mode, setMode] = useState( + unreadableText === null ? value.mode : null, + ); + const fileMode = unreadableModelPolicyMode(value); + const [error, setError] = useState(null); + const [saving, setSaving] = useState(false); + const save = () => { + if (saving) return; + if (mode === null) { + setError("Choose the mode this save writes."); + return; + } + const result = withModelPolicyAllow(mode, text); + if ("error" in result) { + setError(result.error); + return; + } + setError(null); + setSaving(true); + onSave( + result.value, + () => onOpenChange(false), + () => { + setSaving(false); + setError("The server refused the rows; your text is kept to fix and save again."); + }, + ); + }; + return ( + + + + Edit allowed models + + A JSON list, as in the settings file. Each row names a driver (such as claudeAgent or + codex) and a model; efforts limits its efforts (a row without it checks only the model), + defaultEffort is one of them, and useFor is a note shown to agents. + + + +
+ {unreadableText !== null ? ( + <> + + Saving here replaces it with the rows below, which start from the file's own + rows when it has a list of them, and the mode you choose. + + + + ) : null} +