@haneinfo/settings
v0.2.8
Published
Runtime-adjustable settings and feature flags declared by plugins, with audited overrides, agent proposals and an optional MCP tool switch.
Readme
@haneinfo/settings
Runtime-adjustable settings and feature flags. Plugins declare the values that are safe to change
while the App runs; administrators override them over HTTP without redeploying, every change is
audited, agents can only propose changes, and @haneinfo/mcp-server uses it to switch off single
MCP tools. Implemented from approved decision 202610-e6c1. See package.json for the current package
version. There is no frontend (settings screen, flag rule
editor and proposal review come with a later decision), no scheduled rollout, no per-organization
rules and no fine-grained "who may change which setting".
Register settings() from @haneinfo/settings/plugin with configRef settings, or
SettingsModule.register({}). The module exports SettingsService, SettingsMcpTools, SETTINGS
(haneinfo.settings, the SettingsPort) and SETTING_DECLARATIONS (the declaration registry).
Requires plugin-api contract 1.22.0. The capability is optional: without this package every plugin
keeps reading its static configuration and nothing changes.
What is (not) a setting
haneinfo.config.ts stays the only place for startup wiring: drivers, paths, connections, key
sources. Those must never be declared as settings. Settings never hold secrets: a declaration with
sensitive or secret, or a code segment that looks like a credential (password, token, apiKey,
databaseUrl, webhook, …), fails startup. Keys, passwords and connection strings belong in the
environment and static configuration only.
Declarations
Contributors inject the optional registry and register during module initialization (their
manifests list haneinfo.settings in optionalRequires):
constructor(@Optional() @Inject(SETTING_DECLARATIONS) private readonly declarations?: SettingDeclarationRegistry) {}
onModuleInit() {
this.declarations?.register({
code: 'example.maxRows',
kind: 'setting',
type: 'integer',
description: 'Most rows a page returns',
default: 200,
min: 1,
max: 10000,
staticRef: 'example.maxRows',
});
}| Field | Meaning |
| --- | --- |
| code | <plugin>.<name>: letters, digits, dots, hyphens, underscores; at most 128; globally unique (a duplicate fails startup) |
| kind | setting (a typed value) or flag (a boolean with optional rollout rules) |
| type | boolean, integer, number, string, enum, stringList; flags are boolean |
| description | 1–2,000 characters, shown to administrators and agents |
| default | must satisfy the declaration; a flag default may be a boolean |
| min, max | integer and number |
| values | enum: 1–200 distinct strings |
| pattern | string and stringList items: the whole value must match |
| maxLength | string and stringList items: 1–2,000 code points (2,000 is also the hard cap) |
| maxItems | stringList: 0–200 (200 is also the hard cap) |
| staticRef | optional dotted path into the App's static runtime configuration |
| knownItems | stringList only: a function listing names that exist; stored entries outside it are reported as unknownItems |
Value types exclude binary data and nested objects (only flag values are objects). Unknown
declaration properties are refused. A static value found at staticRef that does not satisfy the
declaration fails startup.
Resolution and reading
A value resolves as runtime override > static configuration (staticRef) > declared default, and
reports source OVERRIDE, STATIC or DEFAULT. Deleting the override falls back to static or
default. An override that no longer satisfies a narrowed declaration is ignored (the view shows
overrideProblems and storedValue) until it is changed or deleted.
SettingsPort (inject SETTINGS) reads without a caller: get(code) → { code, value, source,
revision }, value(code), evaluateFlag(code, { userId, roleNames? }) and isEnabled(code,
subject). Undeclared codes throw SETTING_NOT_FOUND.
Reads go through an in-process cache (default 30 seconds). A write, delete or approved proposal on this instance invalidates the code at once; other App instances follow within one cache period (there is no NOTIFY or external cache). A read that raced a local write is never cached. A deleted override therefore stops applying everywhere within one period.
Feature flags
A flag value is { enabled: boolean, rules?: { allowUsers?, denyUsers?, allowRoles?, percent? } }
(a boolean is accepted and stored as { enabled }). Evaluation order: denyUsers (false) →
allowUsers (true) → allowRoles, any role (true) → percent, users whose stable bucket is below
the percentage (true) → enabled. Without rules a flag is a plain switch. Lists hold at most 200
entries; roles are machine names (EQUIPMENT_MANAGER); percent is an integer 0–100. When
roleNames is omitted the roles are loaded through RBAC.
The bucket is plugin-api's settingFlagBucket(code, userId): 32-bit FNV-1a over the UTF-8 bytes of
<code>:<userId>, modulo 100. The same person always gets the same result for a flag; raising the
percentage only adds people. SETTING_FLAG_BUCKET_TEST_VECTORS pins the function.
Data and migration
Apply prisma/settings.prisma and the App migration in prisma/settings.sql before enabling. No
relation to other models is needed.
| Model / table | Columns |
| --- | --- |
| Setting / settings | code (primary key), value JSONB, revision, updatedBy, updatedAt. No override, no row. |
| SettingChange / setting_changes | id, code, before, after (JSONB, NULL when there was no override), actorId, reason, source (HTTP, PROPOSAL; CHECK), at; index (code, at) |
| SettingProposal / setting_proposals | id, code, value, reason, proposedBy, status (PENDING, APPLIED, REJECTED; CHECK), decidedBy, decidedAt, createdAt; unique partial index: one PENDING per code |
Overrides whose code no plugin declares any more stay in the table and are listed as ORPHAN; they
can be read and deleted but not set. Back up these tables with the rest of the database.
HTTP
All routes use InteractiveAuthGuard (401 without a login). Reads need settings:setting:read,
changes and proposal decisions need settings:setting:write (403 otherwise; ADMIN, ALLOW_ALL and
READ_ALL for reads apply as usual). Without an RBAC plugin every route is 403.
| Route | Notes |
| --- | --- |
| GET /settings | { items }: every declaration with value, source, default, constraints, staticRef, revision (0 = no override), updatedBy, updatedAt, unknownItems; then ORPHAN overrides; sorted by code |
| GET /settings/:code | one item |
| PUT /settings/:code | { value, expectedRevision?, reason? }; validated against the declaration and maxValueBytes; an unchanged override returns 200 without an audit record |
| DELETE /settings/:code?expectedRevision=&reason= | removes the override (204); no override is a no-op |
| GET /settings/:code/history?offset=&limit= | { items, total, offset, limit }, newest first |
| POST /settings/flags/:code/evaluate | { userId } → { code, userId, enabled, matched, bucket, source, revision } for debugging |
| GET /settings/proposals?status=&offset=&limit= | { items, total, offset, limit }, newest first |
| POST /settings/proposals/:id/approve | { reason? }: applies the value as the approver (audit source PROPOSAL), returns { proposal, setting } |
| POST /settings/proposals/:id/reject | marks REJECTED |
expectedRevision 0 means "expect no override". After a delete the next override starts again at
revision 1. A write, delete or approval runs in one transaction under a per-code advisory lock: the
override, its SettingChange row and the settings.changed domain event (when
@haneinfo/domain-events is installed) commit together. The event carries code, revision (0 after
a delete), actor and source, never the value. Change records are only appended; there is no update
or delete API (only the optional retention limit prunes the oldest).
Errors use the shared envelope: SETTING_NOT_FOUND / 404, SETTING_INVALID / 400 with
details.problems ([{ path, message }]), SETTING_REVISION_CONFLICT / 409 with
details.currentRevision, SETTING_PROPOSAL_NOT_FOUND / 404, SETTING_PROPOSAL_NOT_PENDING / 409 and
FORBIDDEN / 403.
Agent proposals (MCP)
Register SettingsMcpTools with commands({ scopeNamespace }).
| Tool | Scope | Notes |
| --- | --- | --- |
| list_settings | <namespace>:settings:read | same items as GET /settings |
| get_setting | <namespace>:settings:read | { code } |
| propose_setting_change | <namespace>:settings:propose | { code, value, reason? } → a PENDING proposal |
Every tool must be user-bound and acts with that user's settings:setting:read. Proposals are
validated exactly like a write; a newer proposal for the same code replaces the pending one (marked
REJECTED without a decider). Nothing changes until a person approves it. Descriptions, values,
defaults and reasons are wrapped as $userContent. There is no MCP tool that changes, deletes or
approves a setting.
Switching off MCP tools
With this package installed, @haneinfo/mcp-server declares mcp-server.disabledTools
(stringList of tool names, at most 200). Listed tools disappear from tools/list and a direct
tools/call returns a JSON-RPC -32602 (InvalidParams) error with data.code: "tool_unavailable"
without running the handler; prefixed aliases follow their tool. Names that do not exist are ignored
and reported as unknownItems. Without this package the MCP server behaves exactly as before.
Configuration
runtime.settings has no secrets: cacheTtlMs 30,000 (0–3,600,000; 0 disables the cache),
maxValueBytes 8,192 (256–65,536, UTF-8 bytes of the value JSON), historyPageMaxLimit 100 (1–1,000)
and maxHistoryPerCode (absent keeps every record; 1–1,000,000).
