-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathworld-settings.js
More file actions
38 lines (33 loc) · 1.24 KB
/
Copy pathworld-settings.js
File metadata and controls
38 lines (33 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// §13.2 settings mirror; fed by hello + settings.sync.
// Relay enforces; gate logic reads here, never the bridge.
const DEFAULTS = {
mode: 'assistant', /* assistant | cogm | custom */
multitasking: false,
chainOffers: false,
chainOfferThreshold: 4,
chainMaxLength: 20,
mirrorEnabled: false,
mirrorPath: '',
mirrorContextualSort: false,
};
const CHAIN_HARD_CAP = 40; /* §13.1 ceiling on chainMaxLength */
export class WorldSettings {
constructor({ dispatcher, audit }) {
this.audit = audit;
this.values = { ...DEFAULTS };
dispatcher.subscribe('settings.sync', (p) => this.update(p || {}, 'sync'));
}
update(raw, via = 'hello') {
const v = this.values;
for (const k of Object.keys(DEFAULTS)) if (raw[k] !== undefined) v[k] = raw[k];
v.chainOfferThreshold = clampInt(v.chainOfferThreshold, 2, 99, DEFAULTS.chainOfferThreshold);
v.chainMaxLength = clampInt(v.chainMaxLength, 2, CHAIN_HARD_CAP, DEFAULTS.chainMaxLength);
this.audit.log('settings.update', { via, ...v });
}
get(key) { return this.values[key]; }
snapshot() { return { ...this.values }; }
}
function clampInt(n, lo, hi, fallback) {
const i = Number.parseInt(n, 10);
return Number.isFinite(i) ? Math.min(hi, Math.max(lo, i)) : fallback;
}