aegis-desktop 1.0.13 → 1.0.15
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/SOURCE-OFFER.txt +9 -0
- package/bin/aegis.js +1 -32
- package/lib/account-key.js +1 -56
- package/lib/auto.js +1 -430
- package/lib/avatar/companion.js +1 -698
- package/lib/avatar/cosmetics.js +1 -532
- package/lib/avatar/events.js +1 -344
- package/lib/avatar/holder-turn.js +1 -350
- package/lib/avatar/holders.js +1 -612
- package/lib/avatar/identity.js +1 -641
- package/lib/avatar/level.js +1 -368
- package/lib/avatar/mirror.js +1 -524
- package/lib/avatar/persona.js +1 -388
- package/lib/avatar/profile.js +1 -977
- package/lib/avatar/register.js +1 -307
- package/lib/avatar/store.js +1 -472
- package/lib/avatar/tiers.js +1 -38
- package/lib/avatar/transfer.js +1 -415
- package/lib/avatar/turn.js +1 -216
- package/lib/avatar/voice.js +1 -328
- package/lib/avatar/xp.js +1 -404
- package/lib/deep-link.js +1 -120
- package/lib/fingerprint.js +2 -347
- package/lib/google-connect.js +1 -169
- package/lib/local/agents.js +1 -105
- package/lib/local/autonomous.js +1 -1045
- package/lib/local/claude-pro.js +1 -993
- package/lib/local/context.js +1 -95
- package/lib/local/engine.js +1 -3228
- package/lib/local/entitlement.js +1 -654
- package/lib/local/git-scope.js +1 -228
- package/lib/local/local.js +1 -2135
- package/lib/local/prompt.js +1 -275
- package/lib/local/queue.js +1 -560
- package/lib/local/session-rounds.js +1 -208
- package/lib/local/shell.js +1 -680
- package/lib/local/telemetry.js +1 -470
- package/lib/local/tools.js +1 -1238
- package/lib/local/turn-guard.js +1 -300
- package/lib/local/worktree-lock.js +1 -235
- package/lib/provider-key-mirror.js +1 -252
- package/lib/quick-launcher.js +1 -84
- package/lib/settings.js +1 -890
- package/lib/sync/memory-queue.js +1 -60
- package/lib/sync/persist-gate.js +1 -148
- package/lib/sync/sessions.js +1 -106
- package/lib/window-state.js +1 -66
- package/main.js +3 -4390
- package/package.json +3 -5
- package/preload.js +3 -628
- package/renderer/app.js +1 -6560
- package/renderer/avatar/assemble.js +1 -335
- package/renderer/avatar/avatar.js +1 -380
- package/renderer/avatar/cards.js +1 -141
- package/renderer/avatar/hud.js +1 -206
- package/renderer/avatar/machine.js +1 -213
- package/renderer/avatar/pane.js +1 -439
- package/renderer/avatar/parts.js +1 -437
- package/renderer/budget.js +1 -168
- package/renderer/companion.js +1 -223
- package/renderer/diff.js +1 -359
- package/renderer/diffview.js +1 -336
- package/renderer/fingerprint.js +3 -720
- package/renderer/markdown.js +1 -168
- package/renderer/provider-toolbar.js +1 -134
- package/renderer/providers.js +1 -259
- package/renderer/quick.js +1 -191
- package/renderer/stream-policy.js +1 -306
- package/renderer/transcript-view.js +1 -323
- package/renderer/usage.js +1 -1239
- package/vendor/aegis.js +1 -2054
- package/vendor/attest.js +1 -442
- package/vendor/authorship-key.js +1 -410
- package/vendor/auto-provision.js +1 -134
- package/vendor/brain-catalog.js +1 -268
- package/vendor/byok-catalog.js +1 -230
- package/vendor/credentials.js +1 -494
- package/vendor/device-fingerprint.js +1 -141
- package/vendor/drive-connect.js +1 -85
- package/vendor/drive-upload.js +1 -174
- package/vendor/env-file.js +1 -1273
- package/vendor/fingerprint.js +1 -1064
- package/vendor/foreign-memory.js +1 -669
- package/vendor/google-signin.js +1 -125
- package/vendor/hooks.js +1 -430
- package/vendor/model-discovery.js +1 -330
- package/vendor/platform.js +1 -937
- package/vendor/prefs.js +1 -351
- package/vendor/presence-constants.js +1 -107
- package/vendor/presence.js +1 -438
- package/vendor/record-vault.js +3 -1055
- package/vendor/session-store.js +1 -548
- package/vendor/topup.js +1 -297
- package/vendor/touch.js +1 -458
- package/vendor/update.js +1 -704
- package/vendor/user-models.js +1 -381
package/lib/avatar/persona.js
CHANGED
|
@@ -1,390 +1,3 @@
|
|
|
1
1
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
2
|
// Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
|
|
3
|
-
|
|
4
|
-
// Conveying a modified copy, or running one as a network service, owes the
|
|
5
|
-
// corresponding source under this licence (§5/§13) — see LICENSING.md.
|
|
6
|
-
'use strict';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* persona.js — the avatar is DATA, not art.
|
|
10
|
-
*
|
|
11
|
-
* The user asked to "customize her or him as you want". The cheap way to build
|
|
12
|
-
* that is a settings pane with hand-written branches for every option, which
|
|
13
|
-
* makes a new outfit a code change and a commissioned art pack a fork. The way
|
|
14
|
-
* this module does it: a persona is one JSON record, validated and coerced
|
|
15
|
-
* here, and the renderer assembles layered SVG from a part manifest. A
|
|
16
|
-
* theme is then a file. Zero code changes.
|
|
17
|
-
*
|
|
18
|
-
* Validation is REPAIR-ORIENTED, not reject-oriented, with exactly two hard
|
|
19
|
-
* errors:
|
|
20
|
-
*
|
|
21
|
-
* - the input is not an object at all, or
|
|
22
|
-
* - its `schema` is newer than this build understands.
|
|
23
|
-
*
|
|
24
|
-
* Everything else is coerced to a legal value and reported in `warnings`. That
|
|
25
|
-
* ordering matters for a file the user can hand-edit: an unknown `hair` id from
|
|
26
|
-
* a newer release should render the default hair and tell the user, not blank
|
|
27
|
-
* the avatar or refuse to start the app. A persona is not a security boundary;
|
|
28
|
-
* it is the user's own file.
|
|
29
|
-
*
|
|
30
|
-
* The one place that IS adversarial is the `register` block and the identity
|
|
31
|
-
* strings, because they end up in the system prompt. Those are
|
|
32
|
-
* sanitized here at the storage boundary — control characters and newlines are
|
|
33
|
-
* stripped so a name cannot break out of its line — and the *prompt* fragment
|
|
34
|
-
* is additionally bounded and neutralized in `register.js`. Two layers, because
|
|
35
|
-
* a name is user-authored text going into a prompt.
|
|
36
|
-
*
|
|
37
|
-
* Pure: no fs, no Electron. The main process reads/writes the file.
|
|
38
|
-
*/
|
|
39
|
-
|
|
40
|
-
/** Bump when the record shape changes; `migrate` walks old records forward. */
|
|
41
|
-
const SCHEMA_VERSION = 1;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* The part manifest. Ids only — geometry lives in `renderer/avatar/`,
|
|
45
|
-
* which reads these same ids. Validation is against THIS list so a typo in a
|
|
46
|
-
* hand-edited persona is caught at load rather than rendering an empty head.
|
|
47
|
-
*/
|
|
48
|
-
const PARTS = Object.freeze({
|
|
49
|
-
frame: Object.freeze(['A', 'B', 'C']),
|
|
50
|
-
skin: Object.freeze([0, 1, 2, 3, 4, 5]),
|
|
51
|
-
hair: Object.freeze([
|
|
52
|
-
'short-1', 'bob-2', 'long-3', 'curly-4', 'buzz-5',
|
|
53
|
-
'ponytail-6', 'braids-7', 'wavy-8',
|
|
54
|
-
]),
|
|
55
|
-
eyes: Object.freeze(['soft', 'sharp', 'sleepy', 'bright']),
|
|
56
|
-
outfit: Object.freeze([
|
|
57
|
-
'hoodie', 'tshirt', 'flannel', 'jacket', 'headphones',
|
|
58
|
-
'glasses', 'scarf', 'apron', 'seasonal-winter', 'archive-coat',
|
|
59
|
-
]),
|
|
60
|
-
palette: Object.freeze(['amber', 'slate', 'moss', 'plum', 'mono', 'sunset']),
|
|
61
|
-
motion: Object.freeze(['full', 'reduced', 'minimal']),
|
|
62
|
-
size: Object.freeze(['small', 'medium', 'large']),
|
|
63
|
-
expressionPack: Object.freeze(['core', 'trusted', 'companion', 'confidant', 'archivist']),
|
|
64
|
-
proactivity: Object.freeze(['off', 'hints', 'brief']),
|
|
65
|
-
voiceEngine: Object.freeze(['none', 'local', 'system']),
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
/** How many outfit layers may be worn at once (spec §2: 3 layers at L5). */
|
|
69
|
-
const MAX_OUTFIT_LAYERS = 3;
|
|
70
|
-
|
|
71
|
-
const LIMITS = Object.freeze({
|
|
72
|
-
name: 40,
|
|
73
|
-
pronouns: 24,
|
|
74
|
-
selfDesc: 120,
|
|
75
|
-
address: 32,
|
|
76
|
-
voiceId: 64,
|
|
77
|
-
customExpressions: 24,
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
const HEX_COLOR = /^#[0-9a-f]{6}$/i;
|
|
81
|
-
/** Anything a prompt could use to start a new directive line or smuggle a role. */
|
|
82
|
-
const UNSAFE_TEXT = /[\u0000-\u001f\u007f\u2028\u2029]+/g;
|
|
83
|
-
|
|
84
|
-
function has(list, value) {
|
|
85
|
-
return list.some((v) => v === value);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Collapse whitespace and strip control characters. A name is a single line of
|
|
90
|
-
* text in a UI, and a single line in a prompt — so newlines, tabs and
|
|
91
|
-
* the unicode line separators are removed rather than escaped.
|
|
92
|
-
*/
|
|
93
|
-
function cleanText(value, max) {
|
|
94
|
-
if (typeof value !== 'string') return '';
|
|
95
|
-
const flat = value.replace(UNSAFE_TEXT, ' ').replace(/\s+/g, ' ').trim();
|
|
96
|
-
return flat.slice(0, max);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function clamp01(value, fallback) {
|
|
100
|
-
const n = typeof value === 'number' && Number.isFinite(value) ? value : fallback;
|
|
101
|
-
return Math.min(1, Math.max(0, n));
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function pick(list, value, fallback) {
|
|
105
|
-
return has(list, value) ? value : fallback;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function nonEmptyId(value, fallback, fallbackOn) {
|
|
109
|
-
if (typeof value !== 'string') return fallback;
|
|
110
|
-
const id = value.trim();
|
|
111
|
-
if (has(fallbackOn, id)) return id;
|
|
112
|
-
return fallback;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/** The persona a fresh install gets. Everything here is replaceable by the user. */
|
|
116
|
-
const DEFAULT_PERSONA = Object.freeze({
|
|
117
|
-
schema: SCHEMA_VERSION,
|
|
118
|
-
identity: Object.freeze({
|
|
119
|
-
name: 'Aegis',
|
|
120
|
-
pronouns: 'they/them',
|
|
121
|
-
selfDesc: 'your build partner',
|
|
122
|
-
}),
|
|
123
|
-
presentation: Object.freeze({
|
|
124
|
-
frame: 'A',
|
|
125
|
-
skin: 2,
|
|
126
|
-
hair: 'bob-2',
|
|
127
|
-
hairColor: '#3b2a20',
|
|
128
|
-
eyes: 'soft',
|
|
129
|
-
outfit: Object.freeze(['hoodie']),
|
|
130
|
-
palette: 'amber',
|
|
131
|
-
}),
|
|
132
|
-
expressions: Object.freeze({ pack: 'core', custom: Object.freeze({}) }),
|
|
133
|
-
voice: Object.freeze({ enabled: false, engine: 'none', id: null, rate: 1 }),
|
|
134
|
-
register: Object.freeze({
|
|
135
|
-
formality: 0.3,
|
|
136
|
-
humor: 0.4,
|
|
137
|
-
verbosity: 0.5,
|
|
138
|
-
proactivity: 'hints',
|
|
139
|
-
address: 'you',
|
|
140
|
-
emojis: false,
|
|
141
|
-
}),
|
|
142
|
-
appearance: Object.freeze({ motion: 'full', size: 'medium', docked: true }),
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
/** A deep, mutable copy of the defaults — safe for the settings pane to edit. */
|
|
146
|
-
function defaultPersona() {
|
|
147
|
-
return JSON.parse(JSON.stringify(DEFAULT_PERSONA));
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Walk an old record forward. With one schema version this is trivial, but the
|
|
152
|
-
* mechanism exists now so that adding v2 is a table entry rather than a
|
|
153
|
-
* discovery that shipped personas cannot be read.
|
|
154
|
-
*/
|
|
155
|
-
const MIGRATIONS = Object.freeze({
|
|
156
|
-
// 0 → 1: pre-schema personas are just partial records; normalisation fills them.
|
|
157
|
-
0: (raw) => Object.assign({}, raw),
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
function migrate(raw) {
|
|
161
|
-
if (!raw || typeof raw !== 'object') return { persona: defaultPersona(), migrated: false };
|
|
162
|
-
let current = raw;
|
|
163
|
-
let version = Number.isInteger(current.schema) ? current.schema : 0;
|
|
164
|
-
// A record from the future is not migrated — the validator reports it.
|
|
165
|
-
let migrated = false;
|
|
166
|
-
while (version < SCHEMA_VERSION) {
|
|
167
|
-
const step = MIGRATIONS[version];
|
|
168
|
-
current = step ? step(current) : current;
|
|
169
|
-
version += 1;
|
|
170
|
-
migrated = true;
|
|
171
|
-
}
|
|
172
|
-
return { persona: current, migrated, fromSchema: Number.isInteger(raw.schema) ? raw.schema : 0 };
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Validate and repair a persona record.
|
|
177
|
-
*
|
|
178
|
-
* @returns {{ ok: boolean, persona: object, errors: string[], warnings: string[], migrated: boolean }}
|
|
179
|
-
* `ok` is false only for a non-object input or a schema from the future. In
|
|
180
|
-
* that case `persona` is the default, so the caller always has something
|
|
181
|
-
* renderable.
|
|
182
|
-
*/
|
|
183
|
-
function validate(raw) {
|
|
184
|
-
const errors = [];
|
|
185
|
-
const warnings = [];
|
|
186
|
-
|
|
187
|
-
if (raw === undefined || raw === null) {
|
|
188
|
-
return { ok: true, persona: defaultPersona(), errors, warnings: ['no persona stored yet — using defaults'], migrated: false };
|
|
189
|
-
}
|
|
190
|
-
if (typeof raw !== 'object' || Array.isArray(raw)) {
|
|
191
|
-
return {
|
|
192
|
-
ok: false,
|
|
193
|
-
persona: defaultPersona(),
|
|
194
|
-
errors: ['persona must be a JSON object'],
|
|
195
|
-
warnings,
|
|
196
|
-
migrated: false,
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
if (Number.isInteger(raw.schema) && raw.schema > SCHEMA_VERSION) {
|
|
200
|
-
return {
|
|
201
|
-
ok: false,
|
|
202
|
-
persona: defaultPersona(),
|
|
203
|
-
errors: [`persona schema ${raw.schema} is newer than this build supports (${SCHEMA_VERSION})`],
|
|
204
|
-
warnings,
|
|
205
|
-
migrated: false,
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
const { persona: migratedPersona, migrated } = migrate(raw);
|
|
210
|
-
const src = migratedPersona;
|
|
211
|
-
const d = DEFAULT_PERSONA;
|
|
212
|
-
|
|
213
|
-
// --- identity -----------------------------------------------------------
|
|
214
|
-
const rawIdentity = src.identity && typeof src.identity === 'object' ? src.identity : {};
|
|
215
|
-
const name = cleanText(rawIdentity.name, LIMITS.name) || d.identity.name;
|
|
216
|
-
if (rawIdentity.name !== undefined && name !== rawIdentity.name) {
|
|
217
|
-
warnings.push('identity.name was trimmed to a single line and length-capped');
|
|
218
|
-
}
|
|
219
|
-
const identity = {
|
|
220
|
-
name,
|
|
221
|
-
pronouns: cleanText(rawIdentity.pronouns, LIMITS.pronouns) || d.identity.pronouns,
|
|
222
|
-
selfDesc: cleanText(rawIdentity.selfDesc, LIMITS.selfDesc),
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
// --- presentation -------------------------------------------------------
|
|
226
|
-
const rawPresentation = src.presentation && typeof src.presentation === 'object' ? src.presentation : {};
|
|
227
|
-
const skin = has(PARTS.skin, rawPresentation.skin)
|
|
228
|
-
? rawPresentation.skin
|
|
229
|
-
: (Number.isInteger(rawPresentation.skin) ? d.presentation.skin : d.presentation.skin);
|
|
230
|
-
if (rawPresentation.skin !== undefined && !has(PARTS.skin, rawPresentation.skin)) {
|
|
231
|
-
warnings.push(`unknown skin index ${JSON.stringify(rawPresentation.skin)} — using ${skin}`);
|
|
232
|
-
}
|
|
233
|
-
for (const key of ['frame', 'hair', 'eyes', 'palette']) {
|
|
234
|
-
const got = rawPresentation[key];
|
|
235
|
-
if (got !== undefined && !has(PARTS[key], got)) {
|
|
236
|
-
warnings.push(`unknown ${key} ${JSON.stringify(got)} — using ${d.presentation[key]}`);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
const hairColor = HEX_COLOR.test(String(rawPresentation.hairColor || ''))
|
|
240
|
-
? String(rawPresentation.hairColor).toLowerCase()
|
|
241
|
-
: d.presentation.hairColor;
|
|
242
|
-
if (rawPresentation.hairColor !== undefined && hairColor !== rawPresentation.hairColor) {
|
|
243
|
-
warnings.push(`hairColor must be a #rrggbb hex — using ${hairColor}`);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
let outfit = Array.isArray(rawPresentation.outfit) ? rawPresentation.outfit : d.presentation.outfit;
|
|
247
|
-
const knownOutfit = [];
|
|
248
|
-
for (const item of outfit) {
|
|
249
|
-
if (!has(PARTS.outfit, item)) {
|
|
250
|
-
warnings.push(`unknown outfit item ${JSON.stringify(item)} — dropped`);
|
|
251
|
-
continue;
|
|
252
|
-
}
|
|
253
|
-
if (!knownOutfit.includes(item)) knownOutfit.push(item);
|
|
254
|
-
}
|
|
255
|
-
if (knownOutfit.length > MAX_OUTFIT_LAYERS) {
|
|
256
|
-
warnings.push(`at most ${MAX_OUTFIT_LAYERS} outfit layers — extra layers dropped`);
|
|
257
|
-
knownOutfit.length = MAX_OUTFIT_LAYERS;
|
|
258
|
-
}
|
|
259
|
-
outfit = knownOutfit;
|
|
260
|
-
|
|
261
|
-
const presentation = {
|
|
262
|
-
frame: pick(PARTS.frame, rawPresentation.frame, d.presentation.frame),
|
|
263
|
-
skin,
|
|
264
|
-
hair: pick(PARTS.hair, rawPresentation.hair, d.presentation.hair),
|
|
265
|
-
hairColor,
|
|
266
|
-
eyes: pick(PARTS.eyes, rawPresentation.eyes, d.presentation.eyes),
|
|
267
|
-
outfit,
|
|
268
|
-
palette: pick(PARTS.palette, rawPresentation.palette, d.presentation.palette),
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
// --- expressions --------------------------------------------------------
|
|
272
|
-
const rawExpressions = src.expressions && typeof src.expressions === 'object' ? src.expressions : {};
|
|
273
|
-
const custom = {};
|
|
274
|
-
if (rawExpressions.custom && typeof rawExpressions.custom === 'object' && !Array.isArray(rawExpressions.custom)) {
|
|
275
|
-
let count = 0;
|
|
276
|
-
for (const [key, value] of Object.entries(rawExpressions.custom)) {
|
|
277
|
-
if (count >= LIMITS.customExpressions) {
|
|
278
|
-
warnings.push(`at most ${LIMITS.customExpressions} custom expressions — extras dropped`);
|
|
279
|
-
break;
|
|
280
|
-
}
|
|
281
|
-
const id = cleanText(key, 40);
|
|
282
|
-
if (!id || typeof value !== 'object' || value === null) continue;
|
|
283
|
-
custom[id] = JSON.parse(JSON.stringify(value));
|
|
284
|
-
count += 1;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
const expressions = {
|
|
288
|
-
pack: pick(PARTS.expressionPack, rawExpressions.pack, d.expressions.pack),
|
|
289
|
-
custom,
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
// --- voice --------------------------------------------------------------
|
|
293
|
-
const rawVoice = src.voice && typeof src.voice === 'object' ? src.voice : {};
|
|
294
|
-
const engine = pick(PARTS.voiceEngine, rawVoice.engine, d.voice.engine);
|
|
295
|
-
const rateNum = typeof rawVoice.rate === 'number' && Number.isFinite(rawVoice.rate)
|
|
296
|
-
? Math.min(2, Math.max(0.5, rawVoice.rate))
|
|
297
|
-
: d.voice.rate;
|
|
298
|
-
const voice = {
|
|
299
|
-
enabled: rawVoice.enabled === true,
|
|
300
|
-
engine,
|
|
301
|
-
id: engine === 'none' ? null : cleanText(rawVoice.id, LIMITS.voiceId) || null,
|
|
302
|
-
rate: rateNum,
|
|
303
|
-
};
|
|
304
|
-
if (voice.id && /clone|voiceprint|imitat/i.test(voice.id)) {
|
|
305
|
-
// Non-goal from the spec: no cloning of real people. Refuse, don't warn.
|
|
306
|
-
warnings.push('voice.id looks like a cloned voice — refused (no cloning of real people)');
|
|
307
|
-
voice.id = null;
|
|
308
|
-
voice.enabled = false;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
// --- register (feeds the prompt, so it is the sanitized one) ------------
|
|
312
|
-
const rawRegister = src.register && typeof src.register === 'object' ? src.register : {};
|
|
313
|
-
const register = {
|
|
314
|
-
formality: clamp01(rawRegister.formality, d.register.formality),
|
|
315
|
-
humor: clamp01(rawRegister.humor, d.register.humor),
|
|
316
|
-
verbosity: clamp01(rawRegister.verbosity, d.register.verbosity),
|
|
317
|
-
proactivity: pick(PARTS.proactivity, rawRegister.proactivity, d.register.proactivity),
|
|
318
|
-
address: cleanText(rawRegister.address, LIMITS.address) || d.register.address,
|
|
319
|
-
emojis: rawRegister.emojis === true,
|
|
320
|
-
};
|
|
321
|
-
|
|
322
|
-
// --- appearance ---------------------------------------------------------
|
|
323
|
-
const rawAppearance = src.appearance && typeof src.appearance === 'object' ? src.appearance : {};
|
|
324
|
-
const appearance = {
|
|
325
|
-
motion: pick(PARTS.motion, rawAppearance.motion, d.appearance.motion),
|
|
326
|
-
size: pick(PARTS.size, rawAppearance.size, d.appearance.size),
|
|
327
|
-
docked: rawAppearance.docked !== false,
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
// Unknown top-level keys are dropped, not carried: a persona that silently
|
|
331
|
-
// accumulates junk is a persona that grows forever in the user's profile.
|
|
332
|
-
const known = ['schema', 'identity', 'presentation', 'expressions', 'voice', 'register', 'appearance'];
|
|
333
|
-
for (const key of Object.keys(src)) {
|
|
334
|
-
if (!known.includes(key)) warnings.push(`unknown persona key ${JSON.stringify(key)} — ignored`);
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
return {
|
|
338
|
-
ok: true,
|
|
339
|
-
errors,
|
|
340
|
-
warnings,
|
|
341
|
-
migrated,
|
|
342
|
-
persona: { schema: SCHEMA_VERSION, identity, presentation, expressions, voice, register, appearance },
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/** Convenience: validate and hand back just the record. */
|
|
347
|
-
function load(raw) {
|
|
348
|
-
return validate(raw).persona;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
/** Deep-merge a partial update onto a valid persona, then re-validate. */
|
|
352
|
-
function update(current, patch) {
|
|
353
|
-
const base = validate(current).persona;
|
|
354
|
-
if (!patch || typeof patch !== 'object') return validate(base);
|
|
355
|
-
const merged = {
|
|
356
|
-
schema: SCHEMA_VERSION,
|
|
357
|
-
identity: { ...base.identity, ...(patch.identity || {}) },
|
|
358
|
-
presentation: { ...base.presentation, ...(patch.presentation || {}) },
|
|
359
|
-
expressions: { ...base.expressions, ...(patch.expressions || {}) },
|
|
360
|
-
voice: { ...base.voice, ...(patch.voice || {}) },
|
|
361
|
-
register: { ...base.register, ...(patch.register || {}) },
|
|
362
|
-
appearance: { ...base.appearance, ...(patch.appearance || {}) },
|
|
363
|
-
};
|
|
364
|
-
return validate(merged);
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
/**
|
|
368
|
-
* Apply an accessibility preference. `prefers-reduced-motion` is not advisory:
|
|
369
|
-
* it forces the least motion the renderer has, regardless of what the persona
|
|
370
|
-
* stored.
|
|
371
|
-
*/
|
|
372
|
-
function appliesMotion(persona, prefersReducedMotion) {
|
|
373
|
-
const motion = prefersReducedMotion ? 'minimal' : persona.appearance.motion;
|
|
374
|
-
return motion === 'minimal' ? 'minimal' : motion;
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
module.exports = {
|
|
378
|
-
SCHEMA_VERSION,
|
|
379
|
-
PARTS,
|
|
380
|
-
LIMITS,
|
|
381
|
-
MAX_OUTFIT_LAYERS,
|
|
382
|
-
DEFAULT_PERSONA,
|
|
383
|
-
defaultPersona,
|
|
384
|
-
migrate,
|
|
385
|
-
validate,
|
|
386
|
-
load,
|
|
387
|
-
update,
|
|
388
|
-
appliesMotion,
|
|
389
|
-
cleanText,
|
|
390
|
-
};
|
|
3
|
+
"use strict";const SCHEMA_VERSION=1,PARTS=Object.freeze({frame:Object.freeze(["A","B","C"]),skin:Object.freeze([0,1,2,3,4,5]),hair:Object.freeze(["short-1","bob-2","long-3","curly-4","buzz-5","ponytail-6","braids-7","wavy-8"]),eyes:Object.freeze(["soft","sharp","sleepy","bright"]),outfit:Object.freeze(["hoodie","tshirt","flannel","jacket","headphones","glasses","scarf","apron","seasonal-winter","archive-coat"]),palette:Object.freeze(["amber","slate","moss","plum","mono","sunset"]),motion:Object.freeze(["full","reduced","minimal"]),size:Object.freeze(["small","medium","large"]),expressionPack:Object.freeze(["core","trusted","companion","confidant","archivist"]),proactivity:Object.freeze(["off","hints","brief"]),voiceEngine:Object.freeze(["none","local","system"])}),MAX_OUTFIT_LAYERS=3,LIMITS=Object.freeze({name:40,pronouns:24,selfDesc:120,address:32,voiceId:64,customExpressions:24}),HEX_COLOR=/^#[0-9a-f]{6}$/i,UNSAFE_TEXT=/[\u0000-\u001f\u007f\u2028\u2029]+/g;function has(e,t){return e.some((e=>e===t))}function cleanText(e,t){return"string"!=typeof e?"":e.replace(UNSAFE_TEXT," ").replace(/\s+/g," ").trim().slice(0,t)}function clamp01(e,t){const r="number"==typeof e&&Number.isFinite(e)?e:t;return Math.min(1,Math.max(0,r))}function pick(e,t,r){return has(e,t)?t:r}function nonEmptyId(e,t,r){if("string"!=typeof e)return t;const n=e.trim();return has(r,n)?n:t}const DEFAULT_PERSONA=Object.freeze({schema:SCHEMA_VERSION,identity:Object.freeze({name:"Aegis",pronouns:"they/them",selfDesc:"your build partner"}),presentation:Object.freeze({frame:"A",skin:2,hair:"bob-2",hairColor:"#3b2a20",eyes:"soft",outfit:Object.freeze(["hoodie"]),palette:"amber"}),expressions:Object.freeze({pack:"core",custom:Object.freeze({})}),voice:Object.freeze({enabled:!1,engine:"none",id:null,rate:1}),register:Object.freeze({formality:.3,humor:.4,verbosity:.5,proactivity:"hints",address:"you",emojis:!1}),appearance:Object.freeze({motion:"full",size:"medium",docked:!0})});function defaultPersona(){return JSON.parse(JSON.stringify(DEFAULT_PERSONA))}const MIGRATIONS=Object.freeze({0:e=>Object.assign({},e)});function migrate(e){if(!e||"object"!=typeof e)return{persona:defaultPersona(),migrated:!1};let t=e,r=Number.isInteger(t.schema)?t.schema:0,n=!1;for(;r<SCHEMA_VERSION;){const e=MIGRATIONS[r];t=e?e(t):t,r+=1,n=!0}return{persona:t,migrated:n,fromSchema:Number.isInteger(e.schema)?e.schema:0}}function validate(e){const t=[],r=[];if(null==e)return{ok:!0,persona:defaultPersona(),errors:t,warnings:["no persona stored yet — using defaults"],migrated:!1};if("object"!=typeof e||Array.isArray(e))return{ok:!1,persona:defaultPersona(),errors:["persona must be a JSON object"],warnings:r,migrated:!1};if(Number.isInteger(e.schema)&&e.schema>SCHEMA_VERSION)return{ok:!1,persona:defaultPersona(),errors:[`persona schema ${e.schema} is newer than this build supports (${SCHEMA_VERSION})`],warnings:r,migrated:!1};const{persona:n,migrated:i}=migrate(e),s=n,o=DEFAULT_PERSONA,a=s.identity&&"object"==typeof s.identity?s.identity:{},c=cleanText(a.name,LIMITS.name)||o.identity.name;void 0!==a.name&&c!==a.name&&r.push("identity.name was trimmed to a single line and length-capped");const p={name:c,pronouns:cleanText(a.pronouns,LIMITS.pronouns)||o.identity.pronouns,selfDesc:cleanText(a.selfDesc,LIMITS.selfDesc)},u=s.presentation&&"object"==typeof s.presentation?s.presentation:{},l=has(PARTS.skin,u.skin)?u.skin:(Number.isInteger(u.skin),o.presentation.skin);void 0===u.skin||has(PARTS.skin,u.skin)||r.push(`unknown skin index ${JSON.stringify(u.skin)} — using ${l}`);for(const e of["frame","hair","eyes","palette"]){const t=u[e];void 0===t||has(PARTS[e],t)||r.push(`unknown ${e} ${JSON.stringify(t)} — using ${o.presentation[e]}`)}const f=HEX_COLOR.test(String(u.hairColor||""))?String(u.hairColor).toLowerCase():o.presentation.hairColor;void 0!==u.hairColor&&f!==u.hairColor&&r.push(`hairColor must be a #rrggbb hex — using ${f}`);let m=Array.isArray(u.outfit)?u.outfit:o.presentation.outfit;const d=[];for(const e of m)has(PARTS.outfit,e)?d.includes(e)||d.push(e):r.push(`unknown outfit item ${JSON.stringify(e)} — dropped`);d.length>MAX_OUTFIT_LAYERS&&(r.push(`at most ${MAX_OUTFIT_LAYERS} outfit layers — extra layers dropped`),d.length=MAX_OUTFIT_LAYERS),m=d;const y={frame:pick(PARTS.frame,u.frame,o.presentation.frame),skin:l,hair:pick(PARTS.hair,u.hair,o.presentation.hair),hairColor:f,eyes:pick(PARTS.eyes,u.eyes,o.presentation.eyes),outfit:m,palette:pick(PARTS.palette,u.palette,o.presentation.palette)},h=s.expressions&&"object"==typeof s.expressions?s.expressions:{},b={};if(h.custom&&"object"==typeof h.custom&&!Array.isArray(h.custom)){let e=0;for(const[t,n]of Object.entries(h.custom)){if(e>=LIMITS.customExpressions){r.push(`at most ${LIMITS.customExpressions} custom expressions — extras dropped`);break}const i=cleanText(t,40);i&&"object"==typeof n&&null!==n&&(b[i]=JSON.parse(JSON.stringify(n)),e+=1)}}const S={pack:pick(PARTS.expressionPack,h.pack,o.expressions.pack),custom:b},g=s.voice&&"object"==typeof s.voice?s.voice:{},O=pick(PARTS.voiceEngine,g.engine,o.voice.engine),A="number"==typeof g.rate&&Number.isFinite(g.rate)?Math.min(2,Math.max(.5,g.rate)):o.voice.rate,T={enabled:!0===g.enabled,engine:O,id:"none"===O?null:cleanText(g.id,LIMITS.voiceId)||null,rate:A};T.id&&/clone|voiceprint|imitat/i.test(T.id)&&(r.push("voice.id looks like a cloned voice — refused (no cloning of real people)"),T.id=null,T.enabled=!1);const k=s.register&&"object"==typeof s.register?s.register:{},E={formality:clamp01(k.formality,o.register.formality),humor:clamp01(k.humor,o.register.humor),verbosity:clamp01(k.verbosity,o.register.verbosity),proactivity:pick(PARTS.proactivity,k.proactivity,o.register.proactivity),address:cleanText(k.address,LIMITS.address)||o.register.address,emojis:!0===k.emojis},I=s.appearance&&"object"==typeof s.appearance?s.appearance:{},j={motion:pick(PARTS.motion,I.motion,o.appearance.motion),size:pick(PARTS.size,I.size,o.appearance.size),docked:!1!==I.docked},v=["schema","identity","presentation","expressions","voice","register","appearance"];for(const e of Object.keys(s))v.includes(e)||r.push(`unknown persona key ${JSON.stringify(e)} — ignored`);return{ok:!0,errors:t,warnings:r,migrated:i,persona:{schema:SCHEMA_VERSION,identity:p,presentation:y,expressions:S,voice:T,register:E,appearance:j}}}function load(e){return validate(e).persona}function update(e,t){const r=validate(e).persona;return validate(t&&"object"==typeof t?{schema:SCHEMA_VERSION,identity:{...r.identity,...t.identity||{}},presentation:{...r.presentation,...t.presentation||{}},expressions:{...r.expressions,...t.expressions||{}},voice:{...r.voice,...t.voice||{}},register:{...r.register,...t.register||{}},appearance:{...r.appearance,...t.appearance||{}}}:r)}function appliesMotion(e,t){const r=t?"minimal":e.appearance.motion;return"minimal"===r?"minimal":r}module.exports={SCHEMA_VERSION:SCHEMA_VERSION,PARTS:PARTS,LIMITS:LIMITS,MAX_OUTFIT_LAYERS:MAX_OUTFIT_LAYERS,DEFAULT_PERSONA:DEFAULT_PERSONA,defaultPersona:defaultPersona,migrate:migrate,validate:validate,load:load,update:update,appliesMotion:appliesMotion,cleanText:cleanText};
|