@happyvertical/smrt-preferences 0.60.18 → 0.61.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +3 -1
- package/agents/preference-kinds.md +45 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +230 -46
- package/dist/index.js.map +1 -1
- package/dist/kinds/builtin.d.ts.map +1 -1
- package/dist/kinds/prebuilt-components.d.ts +22 -0
- package/dist/kinds/prebuilt-components.d.ts.map +1 -0
- package/dist/kinds/work-profiles.d.ts +26 -0
- package/dist/kinds/work-profiles.d.ts.map +1 -0
- package/dist/manifest.json +4 -2
- package/dist/permissions.d.ts.map +1 -1
- package/dist/smrt-knowledge.json +10 -8
- package/dist/smrt-knowledge.okf.md +2 -2
- package/package.json +8 -8
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Owner work-profile overrides; inference owns recommendations and resolution. */
|
|
2
|
+
import type { AssistantSafetySettings, WorkProfileName, WorkProfileSettings } from '@happyvertical/smrt-inference';
|
|
3
|
+
import { type PreferencePrincipal } from '../context.js';
|
|
4
|
+
import type { PreferenceKindDefinition } from '../kinds.js';
|
|
5
|
+
import type { PreferenceStore } from '../store.js';
|
|
6
|
+
export type WorkProfilePreferences = Partial<Record<WorkProfileName, WorkProfileSettings>> & {
|
|
7
|
+
safety?: AssistantSafetySettings;
|
|
8
|
+
};
|
|
9
|
+
export declare const WORK_PROFILES_PREFERENCE_KIND = "work-profiles";
|
|
10
|
+
export declare const workProfilesPreferenceKind: PreferenceKindDefinition;
|
|
11
|
+
/** Owner check and the generic store permission/CAS both apply to writes and reset. */
|
|
12
|
+
export declare function createWorkProfilesPreference(options: {
|
|
13
|
+
store: PreferenceStore;
|
|
14
|
+
isOwner(principal: PreferencePrincipal): Promise<boolean>;
|
|
15
|
+
}): {
|
|
16
|
+
read(): Promise<{
|
|
17
|
+
settings: WorkProfilePreferences;
|
|
18
|
+
revision: string | null;
|
|
19
|
+
issues: import("../kinds.js").PreferenceIssue[];
|
|
20
|
+
}>;
|
|
21
|
+
write(settings: WorkProfilePreferences, revision: string | null, confirmation?: {
|
|
22
|
+
confirmUnprotectedCli?: boolean;
|
|
23
|
+
}): Promise<import("../store.js").PreferenceSaveResult>;
|
|
24
|
+
reset(revision: string | null): Promise<import("../store.js").PreferenceResetResult>;
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=work-profiles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"work-profiles.d.ts","sourceRoot":"","sources":["../../src/kinds/work-profiles.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,OAAO,KAAK,EACV,uBAAuB,EACvB,eAAe,EACf,mBAAmB,EACpB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAEL,KAAK,mBAAmB,EAEzB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,MAAM,MAAM,sBAAsB,GAAG,OAAO,CAC1C,MAAM,CAAC,eAAe,EAAE,mBAAmB,CAAC,CAC7C,GAAG;IAAE,MAAM,CAAC,EAAE,uBAAuB,CAAA;CAAE,CAAC;AACzC,eAAO,MAAM,6BAA6B,kBAAkB,CAAC;AAsD7D,eAAO,MAAM,0BAA0B,EAAE,wBAmCxC,CAAC;AAEF,uFAAuF;AACvF,wBAAgB,4BAA4B,CAAC,OAAO,EAAE;IACpD,KAAK,EAAE,eAAe,CAAC;IACvB,OAAO,CAAC,SAAS,EAAE,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC3D;;kBAciD,sBAAsB;;;;oBAMxD,sBAAsB,YACtB,MAAM,GAAG,IAAI,iBACR;QAAE,qBAAqB,CAAC,EAAE,OAAO,CAAA;KAAE;oBAmB9B,MAAM,GAAG,IAAI;EAQtC"}
|
package/dist/manifest.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"version": "1.0.0",
|
|
3
3
|
"timestamp": 0,
|
|
4
4
|
"packageName": "@happyvertical/smrt-preferences",
|
|
5
|
-
"packageVersion": "0.
|
|
5
|
+
"packageVersion": "0.61.1",
|
|
6
6
|
"objects": {
|
|
7
7
|
"@happyvertical/smrt-preferences:UiPreferenceRecordCollection": {
|
|
8
8
|
"name": "uipreferencerecordcollection",
|
|
@@ -546,10 +546,12 @@
|
|
|
546
546
|
"issues": [
|
|
547
547
|
"#3617",
|
|
548
548
|
"#3624",
|
|
549
|
-
"#3626"
|
|
549
|
+
"#3626",
|
|
550
|
+
"#3627"
|
|
550
551
|
],
|
|
551
552
|
"via": [
|
|
552
553
|
"@happyvertical/smrt-profiles",
|
|
554
|
+
"@happyvertical/smrt-secrets",
|
|
553
555
|
"@happyvertical/smrt-tenancy",
|
|
554
556
|
"@happyvertical/smrt-users"
|
|
555
557
|
]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permissions.d.ts","sourceRoot":"","sources":["../src/permissions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"permissions.d.ts","sourceRoot":"","sources":["../src/permissions.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,oBAAoB,EAE1B,MAAM,2BAA2B,CAAC;AAEnC,6EAA6E;AAC7E,eAAO,MAAM,6BAA6B,wBAAwB,CAAC;AAEnE,iEAAiE;AACjE,eAAO,MAAM,+BAA+B,0BAA0B,CAAC;AAEvE,yEAAyE;AACzE,eAAO,MAAM,0BAA0B,oBAAoB,CAAC;AAE5D,0EAA0E;AAC1E,eAAO,MAAM,4BAA4B,sBAAsB,CAAC;AAEhE,eAAO,MAAM,iCAAiC,EAAE,oBAAoB,EAkCnE,CAAC;AAIF,yDAAyD;AACzD,wBAAgB,qCAAqC,IAAI,IAAI,CAM5D;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG;IACjD,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB,CAMA"}
|
package/dist/smrt-knowledge.json
CHANGED
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
"sensitiveFieldsExcluded": true,
|
|
4
4
|
"generatedAt": "1970-01-01T00:00:00.000Z",
|
|
5
5
|
"packageName": "@happyvertical/smrt-preferences",
|
|
6
|
-
"packageVersion": "0.
|
|
6
|
+
"packageVersion": "0.61.1",
|
|
7
7
|
"sourceManifestPath": "dist/manifest.json",
|
|
8
8
|
"agentDocPath": "AGENTS.md",
|
|
9
9
|
"sourceHashes": {
|
|
10
|
-
"manifest": "
|
|
11
|
-
"packageJson": "
|
|
12
|
-
"agents": "
|
|
13
|
-
"moduleDoc:agents/preference-kinds.md": "
|
|
10
|
+
"manifest": "218b42073a8533495f4b2876daef10adb531c40b29c5286f488205e51ac37820",
|
|
11
|
+
"packageJson": "9152f9f3dac6f62c768ab83950f7703608f019a40aef99eceac548d276f0e1b9",
|
|
12
|
+
"agents": "a1f1b06b7fd385c43a9b48f9abd2063b71294bb94d64c13b2c80ed7b296dcf0f",
|
|
13
|
+
"moduleDoc:agents/preference-kinds.md": "ed2e18460868844827cc3574ef31c041b35b01792ae474739329d661004a4423"
|
|
14
14
|
},
|
|
15
15
|
"exports": [
|
|
16
16
|
".",
|
|
@@ -298,12 +298,12 @@
|
|
|
298
298
|
"polymorphicAssociations": 0,
|
|
299
299
|
"uuidColumns": 8
|
|
300
300
|
},
|
|
301
|
-
"agentDoc": "# smrt-preferences\n\nUser-interface preferences (#3727): one `_smrt_ui_preferences` system table\nfor tenant defaults and per-user preferences of any registered **kind**, the\nkind registry, the generic store, and two built-in kinds: `overview`\n(customizable overview pages of `@happyvertical/smrt-svelte/overview`, with an\noverview-shaped layer on top) and `shell-layout` (the AdminShell\n`ShellSettingsDelta`). The kind contract is in\n[agents/preference-kinds.md](agents/preference-kinds.md); the overview\nsurface itself is in\n[smrt-svelte overview-surfaces.md](../smrt-svelte/agents/overview-surfaces.md).\n\n## Why a package of its own\n\nThe repo puts each layered-override table in the package that owns its\nresolution (`smrt-prompts`, `smrt-playbooks`, `smrt-features`,\n`smrt-fields`). `smrt-svelte` has no runtime dependency on core, tenancy or\nusers and holds no tables. This package imports only smrt-svelte's\nSvelte-free entries (`./overview/server`, `./workspace/server`).\n\n## Pieces\n\n| File | Contents |\n| --- | --- |\n| `src/models/UiPreferenceRecord.ts` | The row; owns identity, scope shape and authorization; refuses unregistered kinds |\n| `src/collections/UiPreferenceRecordCollection.ts` | Undecorated reads (`findTier`); internal, not exported; no generated surface |\n| `src/write-capability.ts` | The store-only write capability (internal) |\n| `src/read-guard.ts` | The owner-read interceptor (internal) |\n| `src/kinds.ts` | `registerPreferenceKind`, `requirePreferenceKind`, `UnknownPreferenceKindError`, the validation contract |\n| `src/store.ts` | `createPreferenceStore({ db })`: generic `load` / `save` / `reset(kind, surfaceId, ...)` |\n| `src/kinds/overview.ts`, `src/overview.ts` | The `overview` kind and `createOverviewStore` (`load`, `save`, `reset`, `loadPage`, `loadWidget`, `withTenantDefaults`) |\n| `src/kinds/shell-layout.ts` | The `shell-layout` kind and `createShellSettingsPreferences` (the server half of a `ShellSettingsAdapter`) |\n| `src/kinds/builtin.ts` | Registers the
|
|
301
|
+
"agentDoc": "# smrt-preferences\n\nUser-interface preferences (#3727): one `_smrt_ui_preferences` system table\nfor tenant defaults and per-user preferences of any registered **kind**, the\nkind registry, the generic store, and two built-in kinds: `overview`\n(customizable overview pages of `@happyvertical/smrt-svelte/overview`, with an\noverview-shaped layer on top) and `shell-layout` (the AdminShell\n`ShellSettingsDelta`). The kind contract is in\n[agents/preference-kinds.md](agents/preference-kinds.md); the overview\nsurface itself is in\n[smrt-svelte overview-surfaces.md](../smrt-svelte/agents/overview-surfaces.md).\n\n## Why a package of its own\n\nThe repo puts each layered-override table in the package that owns its\nresolution (`smrt-prompts`, `smrt-playbooks`, `smrt-features`,\n`smrt-fields`). `smrt-svelte` has no runtime dependency on core, tenancy or\nusers and holds no tables. This package imports only smrt-svelte's\nSvelte-free entries (`./overview/server`, `./workspace/server`).\n\n## Pieces\n\n| File | Contents |\n| --- | --- |\n| `src/models/UiPreferenceRecord.ts` | The row; owns identity, scope shape and authorization; refuses unregistered kinds |\n| `src/collections/UiPreferenceRecordCollection.ts` | Undecorated reads (`findTier`); internal, not exported; no generated surface |\n| `src/write-capability.ts` | The store-only write capability (internal) |\n| `src/read-guard.ts` | The owner-read interceptor (internal) |\n| `src/kinds.ts` | `registerPreferenceKind`, `requirePreferenceKind`, `UnknownPreferenceKindError`, the validation contract |\n| `src/store.ts` | `createPreferenceStore({ db })`: generic `load` / `save` / `reset(kind, surfaceId, ...)` |\n| `src/kinds/overview.ts`, `src/overview.ts` | The `overview` kind and `createOverviewStore` (`load`, `save`, `reset`, `loadPage`, `loadWidget`, `withTenantDefaults`) |\n| `src/kinds/shell-layout.ts` | The `shell-layout` kind and `createShellSettingsPreferences` (the server half of a `ShellSettingsAdapter`) |\n| `src/kinds/prebuilt-components.ts` | Tenant-wide pre-built components toggle, owner facade and exposure invalidation |\n| `src/kinds/work-profiles.ts` | Owner work-profile overrides and revision-safe reset; inference owns resolution |\n| `src/kinds/builtin.ts` | Registers the built-in kinds (imported by the entry and the store) |\n| `src/context.ts` | The ambient principal and `PreferenceAccessError` |\n| `src/permissions.ts` | `overviews.customize` / `overviews.personalize`, `shell.customize` / `shell.personalize` |\n\n## Table\n\n`_smrt_ui_preferences`: `tenant_id` (UUID), `kind`, `surface_id`,\n`scope_type` (`tenant` | `user`), `user_id` (UUID, NULL on tenant rows),\n`scope_key` (`__tenant__` or the user id), `payload_json` (the kind's\ncanonical payload), `format_version`, `updated_by`, plus the SmrtObject\ncolumns. Unique key `(tenant_id, kind, surface_id, scope_type, scope_key)`;\nevery key column is NOT NULL, so the index is total on every engine. It ships\nthrough manifest-driven migrations (`smrt db:migrate`), never runtime DDL;\n`src/__tests__/migration.test.ts` applies it with `migrateSmrtSchemas` on\nSQLite and DuckDB and asserts parity afterwards. On DuckDB only this table is\nmigrated in tests: smrt-users' tables carry ON UPDATE CASCADE foreign keys\nDuckDB cannot create.\n\n## Invariants\n\n- **Kinds gate everything.** The store and the model refuse a kind that is\n not registered (`UnknownPreferenceKindError`), so no row exists that no code\n can validate. A kind's `validate` runs strictly on save (refuse unless `ok`,\n store only `canonical`, `null` deletes the row) and leniently on load (use\n `canonical`, report `issues`, never rewrite the row). A row written at a\n newer `format_version` than the kind's is dropped and reported.\n- **Store-only writes.** Only the store writes rows: it passes a\n module-private symbol capability (`src/write-capability.ts`, not exported;\n the smrt-approvals pattern) bound to the exact `payloadJson` the kind\n validated, single-use, and grants each delete the same way. The model\n refuses any insert, update (also in `validateBeforeSave`, so bulk creates\n are covered) or delete without it, so `new UiPreferenceRecord(...).save()`,\n a collection `create()` or `row.setPayload(); row.save()` never store an\n unvalidated payload. Tests seed corrupt storage with raw SQL\n (`src/__tests__/raw-rows.ts`). This guards in-process callers, not raw SQL.\n- **Owner-safe reads, in the predicate.** A principal never reads another\n user's row. `src/read-guard.ts` (registered when the model loads and again\n before every store read) adds `scope_key IN ('__tenant__', <own user id>)`\n (tenant rows only without a user id) to the read predicate BEFORE SQL\n runs, intersecting any caller `scopeKey in`. Core's read entry points and\n the hook each runs: `list`, `listByIds`, `findAll`, `listWithLatestRelated`\n (`beforeList` + `afterList`); `get`, `findById`, `findOne`, `getOrUpsert`,\n `update` / `delete` lookups, and model hydration `loadFromId` /\n `loadFromSlug` (`beforeGet`; collection `get` also `afterGet`); `count`,\n `counts`, `facets` (`beforeList` only, so ownership must be in the\n predicate); `semanticSearch*`, `findSimilar*` (`beforeList`, some also\n `afterList`); `query` (`beforeQuery` + `afterQuery`; raw SQL cannot carry\n the predicate, so the guard refuses it). Every read path runs at least one\n hook. The after-read hooks re-check hydrated rows as defence in depth (a\n row whose scope cannot be told is dropped), and hydration also re-checks in\n the model. `count()` and `facets()` therefore count only visible rows.\n- **Not an app API.** `UiPreferenceRecord` stays a root export only because\n generated consumer registration imports every public manifest object from\n the root; the collection is not exported. Apps use `createPreferenceStore`,\n `createOverviewStore` and `createShellSettingsPreferences`.\n- **Tiers.** The tenant row is the default; the user row applies on top, and\n `validate` for the user tier receives the tenant tier's canonical payload\n (`ctx.tenant`). User rows are per tenant: preferences name tenant data.\n- **Identity is ambient.** No API takes a tenant or user id. A missing\n principal throws `PreferenceAccessError`; a principal without a user id has\n no user tier and cannot write one. A session-only principal (users\n `createSessionHandler()` without `enterTenantContext`) is entered as a\n tenant context with the same identity before any table access.\n- **Tenancy.** The model is `@TenantScoped({ mode: 'required' })`, and every\n store read also names the tenant explicitly (a super-admin bypass context\n does not filter reads). `save()`/`delete()` refuse a row whose stored\n tenant, kind, surface or tier differs from memory (matched by predicate:\n DuckDB returns raw UUID columns as lossy HUGEINTs), a foreign tenant, and a\n user row that is not the principal's.\n- **Permissions are per kind.** Each kind names `{ tenant, user }` slugs;\n the model asserts them (`assertOperationPermission`, fail closed) and the\n store reports them as `canCustomize` (`checkOperationPermission`). A slug\n must be in the users catalog or it never grants. The users resolver denies\n a principal with no user id even with the slug in its set. The built-in\n `personalize` slugs are in users' self-personalization list (seeded for\n owner/admin/member/viewer once registered).\n- **Permission source.** The principal's permission set is authoritative,\n including an explicit empty set: a tenancy adapter without\n `resolvePermissions` refuses everyone (fails closed). Hosts must configure\n it, or enter identity through users' `enterTenantContext`; never widen it\n here.\n- **Concurrency.** Optimistic: a save passes the `revision` (ISO\n `updated_at`) it loaded, `null` meaning \"no row\". Updates use core's\n revision CAS (`save({ expectedUpdatedAt })`), a first write is a strict\n insert (`_insertOnly`) so a racing first write hits the unique index, and\n a delete is guarded the same way. `reset` treats `revision: null` like\n save does (a row that exists now conflicts); only an omitted revision\n resets unguarded. Mismatch: `{ ok: false, reason: 'conflict' }`. Exception, documented: `createShellSettingsPreferences().write`\n without a revision reads the current one first, i.e. last-writer-wins,\n because the shell's `ShellSettingsAdapter.write(delta)` carries none.\n- **Overview `loadWidget`** lets a principal without either customize\n permission load only a widget on their resolved overview; anything else is\n `not_allowed`. The widget is sanitized against the page definition first.\n- **No generated surface** (`api: { include: [] }`, `cli: false`,\n `mcp: { include: [] }`): a generated route would skip kind validation.\n\n## Tests\n\n`pnpm test` runs the overview suite and the kinds suite on SQLite and DuckDB\nplus the migration suite; `pnpm test:postgres` runs both suites on PostgreSQL\n(`*.optional.test.ts`, skipped without a database).\n",
|
|
302
302
|
"moduleDocs": [
|
|
303
303
|
{
|
|
304
304
|
"path": "agents/preference-kinds.md",
|
|
305
305
|
"module": "preference-kinds",
|
|
306
|
-
"content": "# Preference kinds\n\nThe contract between `_smrt_ui_preferences` and the code that owns a\npreference's meaning (#3727). Package rules are in [../AGENTS.md](../AGENTS.md).\n\n## Registering a kind\n\n```ts\nregisterPreferenceKind({\n kind: 'board-columns', // /^[a-z][a-z0-9-]{0,47}$/\n formatVersion: 1, // positive integer, stored per row\n permissions: { tenant: 'boards.customize', user: 'boards.personalize' },\n validate(payload, ctx) { // never throws\n return { ok, canonical, issues };\n },\n}, { replace? }) // -> dispose()\n```\n\nRegistration is code at module scope, process-wide (one registry per\nprocess). Registering a kind twice throws unless `{ replace: true }`. Both\nslugs must be `collection.action` and registered in the users catalog\n(`registerPermissionDefinitions`), or they never grant; add a `personalize`\nslug to users' built-in self-personalization list only when every built-in\nrole should hold it.\n\nThe store authorizes against the principal's permission set from the\nambient context and never widens it. A tenancy adapter (SvelteKit, Express)\nwithout `resolvePermissions` supplies an explicit empty set, which the store\ntreats as authoritative: every write is `not_allowed` and `canCustomize` is\nfalse for everyone, owners included. Configure `resolvePermissions`, or let\nusers' `createSessionHandler({ enterTenantContext: true })` enter the context.\n\n## `validate(payload, ctx)`\n\n| `ctx` field | Meaning |\n| --- | --- |\n| `kind`, `surfaceId` | What is being validated (`surfaceId` matches `PREFERENCE_SURFACE_PATTERN`) |\n| `scope` | `tenant` or `user` |\n| `phase` | `save` (strict) or `load` (lenient) |\n| `formatVersion` | The version the payload was written at (the kind's own on save); migrate older payloads here |\n| `tenant` | User tier only: the tenant tier's canonical payload, or `null` |\n| `options` | Host-supplied, kind-specific inputs, passed through from `load` / `save` |\n\nReturn `canonical`: the payload with every invalid part removed (`null` means\nno preference), `issues`: what was removed and why (`{ path, code, message,\ndetail? }`), and `ok`: false whenever anything was removed or refused.\n\n- On **save** the store refuses unless `ok`, stores only `canonical` (as\n JSON with the kind's `formatVersion`), and deletes the row when `canonical`\n is `null`.\n- On **load** the store uses `canonical` and reports `issues` per tier; the\n row is not rewritten. Unparseable JSON and rows from a newer\n `formatVersion` are dropped before `validate` runs. A `validate` that\n throws on load drops the tier with a `validator_error` issue; on save the\n error propagates and nothing is stored. Validators should not throw.\n- A payload is data, never code: no query strings, URLs or expressions a\n reader would execute. Authorization happens where the data is read, never\n through payload values.\n\n## Built-in kinds\n\n| Kind | Payload | Validator | Permissions | `options` |\n| --- | --- | --- | --- | --- |\n| `overview` | `OverviewOverride` (sparse, version 1) | save: `checkOverviewOverride`; load: `resolveOverview` + `diffOverview`, against the page definition (user tier: tenant-merged via `withTenantDefaults`) | `overviews.customize` / `overviews.personalize` | `{ definition, registry }`; `definition.id` must equal the surface id |\n| `shell-layout` | `ShellSettingsDelta` | `sanitizeShellSettingsDelta` from `@happyvertical/smrt-svelte/workspace/server` | `shell.customize` / `shell.personalize` | none |\n\n## Store calls\n\n`createPreferenceStore({ db })` returns `load(kind, surfaceId, { options })`\n(both tiers, `canCustomize` from the kind's pair), `save(kind, surfaceId, {\nscope, payload, revision, options })` and `reset(kind, surfaceId, { scope,\nrevision? })` (`null` conflicts when a row exists; omitted is unguarded). Failures are `{ ok: false, reason: 'not_allowed' | 'conflict'\n| 'invalid' }`; an unregistered kind throws `UnknownPreferenceKindError`.\n\nKind-shaped layers sit on top: `createOverviewStore` (the overview page API)\nand `createShellSettingsPreferences` (the server half of the shell's\n`ShellSettingsAdapter`: `read(surfaceId)` merges tenant and user with\n`mergeShellSettingsDelta`; `write(surfaceId, delta, { scope?, revision? })`\nis last-writer-wins only when the revision is omitted).\n"
|
|
306
|
+
"content": "# Preference kinds\n\nThe contract between `_smrt_ui_preferences` and the code that owns a\npreference's meaning (#3727). Package rules are in [../AGENTS.md](../AGENTS.md).\n\n## Registering a kind\n\n```ts\nregisterPreferenceKind({\n kind: 'board-columns', // /^[a-z][a-z0-9-]{0,47}$/\n formatVersion: 1, // positive integer, stored per row\n permissions: { tenant: 'boards.customize', user: 'boards.personalize' },\n validate(payload, ctx) { // never throws\n return { ok, canonical, issues };\n },\n}, { replace? }) // -> dispose()\n```\n\nRegistration is code at module scope, process-wide (one registry per\nprocess). Registering a kind twice throws unless `{ replace: true }`. Both\nslugs must be `collection.action` and registered in the users catalog\n(`registerPermissionDefinitions`), or they never grant; add a `personalize`\nslug to users' built-in self-personalization list only when every built-in\nrole should hold it.\n\nThe store authorizes against the principal's permission set from the\nambient context and never widens it. A tenancy adapter (SvelteKit, Express)\nwithout `resolvePermissions` supplies an explicit empty set, which the store\ntreats as authoritative: every write is `not_allowed` and `canCustomize` is\nfalse for everyone, owners included. Configure `resolvePermissions`, or let\nusers' `createSessionHandler({ enterTenantContext: true })` enter the context.\n\n## `validate(payload, ctx)`\n\n| `ctx` field | Meaning |\n| --- | --- |\n| `kind`, `surfaceId` | What is being validated (`surfaceId` matches `PREFERENCE_SURFACE_PATTERN`) |\n| `scope` | `tenant` or `user` |\n| `phase` | `save` (strict) or `load` (lenient) |\n| `formatVersion` | The version the payload was written at (the kind's own on save); migrate older payloads here |\n| `tenant` | User tier only: the tenant tier's canonical payload, or `null` |\n| `options` | Host-supplied, kind-specific inputs, passed through from `load` / `save` |\n\nReturn `canonical`: the payload with every invalid part removed (`null` means\nno preference), `issues`: what was removed and why (`{ path, code, message,\ndetail? }`), and `ok`: false whenever anything was removed or refused.\n\n- On **save** the store refuses unless `ok`, stores only `canonical` (as\n JSON with the kind's `formatVersion`), and deletes the row when `canonical`\n is `null`.\n- On **load** the store uses `canonical` and reports `issues` per tier; the\n row is not rewritten. Unparseable JSON and rows from a newer\n `formatVersion` are dropped before `validate` runs. A `validate` that\n throws on load drops the tier with a `validator_error` issue; on save the\n error propagates and nothing is stored. Validators should not throw.\n- A payload is data, never code: no query strings, URLs or expressions a\n reader would execute. Authorization happens where the data is read, never\n through payload values.\n\n## Built-in kinds\n\n| Kind | Payload | Validator | Permissions | `options` |\n| --- | --- | --- | --- | --- |\n| `overview` | `OverviewOverride` (sparse, version 1) | save: `checkOverviewOverride`; load: `resolveOverview` + `diffOverview`, against the page definition (user tier: tenant-merged via `withTenantDefaults`) | `overviews.customize` / `overviews.personalize` | `{ definition, registry }`; `definition.id` must equal the surface id |\n| `shell-layout` | `ShellSettingsDelta` | `sanitizeShellSettingsDelta` from `@happyvertical/smrt-svelte/workspace/server` | `shell.customize` / `shell.personalize` | none |\n\n## Store calls\n\n`createPreferenceStore({ db })` returns `load(kind, surfaceId, { options })`\n(both tiers, `canCustomize` from the kind's pair), `save(kind, surfaceId, {\nscope, payload, revision, options })` and `reset(kind, surfaceId, { scope,\nrevision? })` (`null` conflicts when a row exists; omitted is unguarded). Failures are `{ ok: false, reason: 'not_allowed' | 'conflict'\n| 'invalid' }`; an unregistered kind throws `UnknownPreferenceKindError`.\n\nKind-shaped layers sit on top: `createOverviewStore` (the overview page API)\nand `createShellSettingsPreferences` (the server half of the shell's\n`ShellSettingsAdapter`: `read(surfaceId)` merges tenant and user with\n`mergeShellSettingsDelta`; `write(surfaceId, delta, { scope?, revision? })`\nis last-writer-wins only when the revision is omitted).\n\n## Pre-built components\n\n`createPrebuiltComponentsPreference({store,isOwner})` wraps the existing generic\nstore for the one tenant-wide `pre-built-components` / `app` preference,\n`{enabled: boolean}`. The facade checks live owner membership on writes and the\nstore additionally requires `recipes.configure`. Personal tiers are invalid;\nthere is no user override. The default is enabled after a successful load with\nno stored preference. Unknown tenants, malformed rows and unreadable storage\nremain disabled. `write(enabled, revision)` uses the existing revision CAS.\n\nLoad/refresh before serving and after external changes. Connect its synchronous\n`isEnabled(tenantId)` to the core cookbook runtime gate's host predicate. Writes\nand `invalidate(tenantId)` call `notifyRuntimeExposureChanged`, so MCP hosts emit\n`tools/list_changed`. Invalidation closes the cached value until the next good\nread; multiple host processes must propagate invalidation. Hosts should expose\nthis facade to owner settings, not a generic kind/surface write endpoint.\nThe core [server tools](../../core/agents/cookbook-tools.md) use this same gate\nfor offering and execution, including retained tools and approval resume.\n\nThe permission registry reads the shared cookbook tool names from core's\nbrowser-safe `./cookbook` entry. Do not import the server-only `./cookbook/tools`\nadapter from this model package root: even a metadata import makes its\n`node:crypto` dependency reachable to browser bundlers. The preferences suite\nreuses bundle-gate's browser build and ownership attribution to guard this edge.\n\n## Assistant work profiles\n\n`createWorkProfilesPreference({store,isOwner})` owns the tenant-wide\n`work-profiles` / `assistant` kind. Its sparse design, assist and background\nsettings contain engine, model, effort, budgets, automatic escalation and preview\npreferences. Inference owns recommendations and resolution; this package imports\nonly its types, preserving the dependency direction. Missing settings resolve to\nrecommendations. `write(settings,revision)` and `reset(revision)` both check the\nlive owner plus `inference.customize`, and retain store CAS. User-tier overrides,\nunknown fields (including approval/CLI authority), malformed budgets and models\nare refused. Reads return validation issues without rewriting stored data.\n\nReuse inventory: MCP architecture context and name/purpose searches of the intent\nindex, preferences, inference, chat, core, smrt-ui and smrt-svelte found the generic\nkind/store and the existing owner pre-built facade. This new kind reuses both;\nno new table or preference persistence layer was added. Round-trip/reset and\nowner/conflict/invalid-value assertions run in the existing SQLite/DuckDB suite.\n\nS1 extends the existing owner `work-profiles` tenant preference with `safety.requireRemovalApproval` and `safety.protectLocalCli` booleans; absent means true. Unknown safety keys are invalid. Turning protection off requires the facade's explicit `confirmUnprotectedCli` acknowledgement unless already off; owner authorization and optimistic revision checks still apply. Reset removes the override and restores both defaults. Hosts must require an owner browser session, not just a scoped API principal, and must not register preference mutation as an assistant tool.\n"
|
|
307
307
|
}
|
|
308
308
|
],
|
|
309
309
|
"browser": {
|
|
@@ -311,10 +311,12 @@
|
|
|
311
311
|
"issues": [
|
|
312
312
|
"#3617",
|
|
313
313
|
"#3624",
|
|
314
|
-
"#3626"
|
|
314
|
+
"#3626",
|
|
315
|
+
"#3627"
|
|
315
316
|
],
|
|
316
317
|
"via": [
|
|
317
318
|
"@happyvertical/smrt-profiles",
|
|
319
|
+
"@happyvertical/smrt-secrets",
|
|
318
320
|
"@happyvertical/smrt-tenancy",
|
|
319
321
|
"@happyvertical/smrt-users"
|
|
320
322
|
]
|
|
@@ -5,10 +5,10 @@ description: "Tenant defaults and per-user overrides for user-interface preferen
|
|
|
5
5
|
status: "stable"
|
|
6
6
|
generated:
|
|
7
7
|
by: "smrt/scripts/generate-knowledge-okf.ts"
|
|
8
|
-
at: "2026-11-
|
|
8
|
+
at: "2026-11-12T21:58:14Z"
|
|
9
9
|
audience: "internal"
|
|
10
10
|
evidence_level: "source-inspected"
|
|
11
|
-
source_revision: "sha256:
|
|
11
|
+
source_revision: "sha256:0bdeb335356ae32497b3a474f4758e70fda60ef1a0a7bcc38eb3961d6a94bc08"
|
|
12
12
|
sources:
|
|
13
13
|
- id: "manifest"
|
|
14
14
|
resource: "https://github.com/happyvertical/smrt/blob/main/packages/preferences/package.json"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@happyvertical/smrt-preferences",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.61.1",
|
|
4
4
|
"description": "Tenant defaults and per-user overrides for user-interface preferences (overview layouts, shell layout), validated per registered kind",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -20,15 +20,15 @@
|
|
|
20
20
|
"./manifest.json": "./dist/manifest.json"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@happyvertical/smrt-core": "0.
|
|
24
|
-
"@happyvertical/smrt-svelte": "0.
|
|
25
|
-
"@happyvertical/smrt-tenancy": "0.
|
|
26
|
-
"@happyvertical/smrt-users": "0.
|
|
27
|
-
"@happyvertical/sql": "^0.112.
|
|
23
|
+
"@happyvertical/smrt-core": "0.61.1",
|
|
24
|
+
"@happyvertical/smrt-svelte": "0.61.1",
|
|
25
|
+
"@happyvertical/smrt-tenancy": "0.61.1",
|
|
26
|
+
"@happyvertical/smrt-users": "0.61.1",
|
|
27
|
+
"@happyvertical/sql": "^0.112.3",
|
|
28
|
+
"@happyvertical/smrt-inference": "0.61.1"
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|
|
30
|
-
"@happyvertical/smrt-
|
|
31
|
-
"@happyvertical/smrt-vitest": "0.60.18",
|
|
31
|
+
"@happyvertical/smrt-vitest": "0.61.1",
|
|
32
32
|
"@types/node": "24.13.6",
|
|
33
33
|
"svelte": "^5.57.1",
|
|
34
34
|
"typescript": "6.0.3",
|