Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

docs: catalog the shared preset re-derivation helpers

[._.]/ Adam Eivy188c401dd651
diff --git a/server/lib/README.md b/server/lib/README.md
index ae625a335b..d8893893d5 100644
--- a/server/lib/README.md
+++ b/server/lib/README.md
@@ -256,7 +256,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub
| `providerGraphRecords.js` | The DURABLE half of the provider connection graph (#6367) — the pure record layer over `ai_connections` / `ai_harness_bindings` / `ai_route_bindings`. `graphFromPreview` / `importGraphFromProviders` mint UUID-keyed rows from a #6366 preview while every executable `providerId` stays untouched; `toManagementGraphDto` (`managementGraphSchema`) sanitizes them for `GET /api/providers/management` (credential PRESENCE only, no projection snapshots); `connectionOwnedSnapshot` / `applyProjections` materialize connection-owned values back into providers.json so a downgraded install still runs; `routeBelongsOnConnection` answers whether a stored connection still CONTAINS the backend one route describes (the create-time and reconcile-time test, looser than `sameConnectionIdentity`); and `planGraphReconciliation` / `reconciliationIsNoop` are the reconciliation contract shared by boot, legacy provider writes and downgrade-edit-reupgrade — acknowledging a landed projection, retrying an interrupted one, REFUSING a third externally changed value, dropping deleted records without resurrecting them, and detaching or splitting a binding whose backend moved. Pure: no DB handle, no file I/O, no provider call. |
| `providerModelAliases.js` | HAND-AUTHORED canonical→executable model aliases for one provider route (#6369) — the correction surface for a `modelMap` a refresh could only fill with what it could VERIFY. Observed aliases (`ai_route_bindings.model_map`) and user overrides (`model_alias_overrides`) are stored apart and merged on READ by `effectiveModelAliases` (`{ ...observed, ...overrides }`), which is what lets a hand-authored alias outlast the next refresh; `applyModelAliasPatch` is the three-valued edit (absent preserves, a string sets, `null` is the only thing that removes); `staleModelAliases` reports — never repairs — an override naming a spelling the record no longer lists, and makes no claim at all about a route listing no models; `connectionCatalogModels` is the union an alias write re-derives the shared catalog from, so a correction actually reaches the model menus; `modelAliasRevision` is the stale-edit fingerprint, reusing `routeSettingsRevision` because `ai_route_bindings` has no revision column. Pure: no I/O. |
| `providerModePairing.js` | May an existing record gain the OTHER execution mode of its harness (#7501) — `tuiModeAddition(provider, providers, executionModes?)` is the ONE verdict behind both the `canAddTuiMode` flag `GET /providers` decorates each record with (so the card offers "Add interactive mode") and the refusal `POST /providers/:id/modes/tui` answers with, so a card can never advertise an action the server rejects. Refuses a non-CLI record (the CLI id is the stem, so minting it from a TUI record would be a rename), a record storing no command, and a KNOWN harness declaring no TUI mode; an UNKNOWN harness passes with empty argv rather than a guess, while a known one starts from its recipe’s proven interactive line. Asks whether the harness already HAS its interactive mode (the record’s `providerModeGroups` group — the shipped `grok-cli`/`grok-tui` pair leaves `grok-cli-tui` unclaimed, so an id-only check would mint a third record beside it), and separately 409s on a taken `<id>-tui` rather than suffixing around it. Pure: no I/O. |
-| `providerPresets.js` | PRESETS (#7565, epic #7561) — a stored `data/providers.json` record read as a (harness, method, service) tuple plus the user's own defaults and overrides. A record carrying `harnessId` + `method` + `serviceId` is a DERIVED preset (`isDerivedPreset` in `providerGraphRecords.js`, `presetKind`): `materializeDerivedPreset({record, harness, instance, catalog, bootstrap})` re-derives every connection-owned value (program, endpoint, credential, backend markers, inline bootstrap, `models` = plan-filtered catalog ∩ `catalogNarrowing`) through `materializeRoute` while keeping every per-preset field (name, argv with a binding's suffix preserved, timeouts, pins, effort, fallback, generation params, consent flags, unknown fields) and the record's own OpenCode inline config when it already reaches the service; `refusedDerivedEdits(updates, derived, ownedEnvNames)` names the connection-owned keys a direct edit would move (`DERIVED_PRESET_OWNED_KEYS`, plus env vars by name); `derivedPresetDrift` / `derivedPresetPatch` compare a record with its derivation; `presetDerivable(record)` is the editor's "offer the button" test; `matchBootstrapApp` / `bootstrapInputFor` map an inline `credentialBootstrap` to a configured app and back; `planPresetBackfill({graph, providers, bootstraps, env})` is the boot-time stamp of every routed legacy record whose re-derivation is a FIXPOINT — additive keys only, every refusal reported with a reason. Pure; the store-backed half is `services/providerPresets.js`. |
+| `providerPresets.js` | PRESETS (#7565, epic #7561) — a stored `data/providers.json` record read as a (harness, method, service) tuple plus the user's own defaults and overrides. A record carrying `harnessId` + `method` + `serviceId` is a DERIVED preset (`isDerivedPreset` in `providerGraphRecords.js`, `presetKind`): `materializeDerivedPreset({record, harness, instance, catalog, bootstrap})` re-derives every connection-owned value (program, endpoint, credential, backend markers, inline bootstrap, `models` = plan-filtered catalog ∩ `catalogNarrowing`) through `materializeRoute` while keeping every per-preset field (name, argv with a binding's suffix preserved, timeouts, pins, effort, fallback, generation params, consent flags, unknown fields) and the record's own OpenCode inline config when it already reaches the service; `refusedDerivedEdits(updates, derived, ownedEnvNames)` names the connection-owned keys a direct edit would move (`DERIVED_PRESET_OWNED_KEYS`, plus env vars by name); `derivedPresetDrift` / `derivedPresetPatch` compare a record with its derivation; `presetDerivable(record)` is the editor's "offer the button" test; `matchBootstrapApp` / `bootstrapInputFor` map an inline `credentialBootstrap` to a configured app and back; `planPresetBackfill({graph, providers, bootstraps, env})` is the boot-time stamp of every routed legacy record whose re-derivation is a FIXPOINT — additive keys only, every refusal reported with a reason. Pure; the store-backed half is `services/providerPresets.js`. `impliedCatalogNarrowing` is the narrowing that keeps a record on its current list once derived, and `rederivePreset` re-derives one derived preset from an instance (derived record + patch), shared by the backfill, `rematerializeDerivedPresets` and the service fold. |
| `providerRef.js` | Provider REFERENCE grammar (#7564, epic #7561) — the two spellings a `{ providerId, model, effort }` selection may name a provider by: a PRESET record id (`PRESET_ID_RE`, the slug `createProvider` mints) or a COMPOSITE `<harness>.<cli|tui|api>@<service-slug>[+<bootstrap-slug>]` (`COMPOSITE_ID_RE`; the bootstrap suffix only with a process method). `parseProviderRef(id)` → `{kind:'preset'}` / `{kind:'composite', harnessId, method, serviceSlug, bootstrapSlug}` / `null`, `isCompositeProviderId` / `isPresetProviderId`, `formatCompositeId(parts)` (throws on parts that would not parse back), `MAX_PROVIDER_REF_LENGTH`, and the two validation messages (`PROVIDER_REF_MESSAGE`, `PRESET_ONLY_MESSAGE`). The zod forms — `providerRefSchema` / `providerRefFieldSchema` (either grammar) and `presetProviderIdSchema` (preset-only, for `PUT /providers/active`, a record's `fallbackProvider`, an app's `taskTypeOverrides` pin) — live in `zodCompat.js` so `cosValidation.js` can share them. Pure and dependency-free; mirrored in `aiToolkit/internal/providerRef.js` (the toolkit may not import out) behind `providerRef.parity.test.js`. Resolution is host-side: `services/compositeProviders.js`. |
| `providerRouteRecipes.js` | Minting a FRESH executable route from a connection and a harness command recipe (#6369) — the reverse of `providerConnections.js`, which reads an existing record. `buildRouteRecord({harnessId, mode, providerId, name, connection})` materializes a connection's endpoint, credentials and backend marker into a DISABLED `data/providers.json` record through `PROVIDER_HARNESSES[].recipe`; `mintRouteIds` allocates readable ids keeping the `<stem>` / `<stem>-tui` pairing `providerModeGroups` recognizes; `bindingBlocker` is the pre-write refusal (no recipe, unsupported mode, a transport the backend does not declare, a credential the program requires); `CREATABLE_CONNECTION_KINDS` / `connectionKindLabel` / `connectionKindMarkers` bound the backends a route can honestly describe (`slotstream` and `vendor` deliberately excluded); `bindingProtocol` names the wire a binding needs. `materializeRoute({harness, method, serviceInstance, bootstrap?, selection?, overrides?})` (#7562) generalizes `buildRouteRecord` from a connection to a SERVICE instance: picks the harness's first compatible binding, writes base URL / credential / static env / backend markers / inline OpenCode config / Pi `--provider` per that binding plus the recipe's mode argv, stamps `harnessId` / `method` / `serviceId` / `servicePlan`, and — for a non-`api` method with a bootstrap app — the `credentialBootstrap` object `composeBootstrapSpawn` turns into `<bootstrap> run <harness> -- <args>`; throws typed errors (`HARNESS_SERVICE_INCOMPATIBLE`, `SERVICE_ENDPOINT_REQUIRED`, `SERVICE_CREDENTIAL_REQUIRED`, `SERVICE_CREDENTIAL_BOOTSTRAP_REQUIRED`) rather than minting a route that cannot run. `materializeRouteOutcome(input)` is the same body as a VERDICT (`{ record }` or `{ error }` — the typed 400 without the throw) for the composite resolver (#7564), which reads a refusal as the reason to show beside a saved selection. `routeDescribesService(profile, instance)` is the round-trip contract: fed back through `providerConnectionProfile`, a materialized record classifies onto the service it was built for. Pure: no I/O, no spawn, no provider call.
| `providerRouteSettings.js` | The MODE-OVERRIDE half of a provider route (#6369) — the route-owned fields a human tunes per execution mode (`args`, `timeout`, `effort` and the `defaultModel`/`lightModel`/`mediumModel`/`heavyModel`/`ultraModel` pins), mirroring what the toolkit's `sharedModeUpdates` already declares mode-specific. `ROUTE_SETTING_FIELDS` / `ROUTE_SETTING_KEYS` / `routeSettingKeys(mode)` name the set (`args` reaches cli/tui only); `routeSettingsFor(provider)` reads it off a record with absent and cleared collapsing to `null`; `routeSettingsSchema` is the wire shape `GET /api/providers/management` publishes; `unsupportedRouteSettings` rejects a key the route's mode does not accept; and `routeSettingsRevision` is the stale-edit fingerprint — a hash of the values as they are in providers.json rather than a graph row revision, so an edit made through `/ai/edit/:providerId` is caught too. Connection-owned values and execution consent (`enabled`) are deliberately absent. Pure: no I/O.