aegisone 1.0.22 → 1.0.24

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.
Files changed (226) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +1 -1
  3. package/SOURCE-OFFER.txt +9 -0
  4. package/bin/aegis.js +1 -322
  5. package/package.json +4 -5
  6. package/scripts/bump.mjs +1 -211
  7. package/scripts/bundle.js +1 -129
  8. package/scripts/predist.mjs +1 -939
  9. package/src/child.js +1 -285
  10. package/src/dispatch.js +1 -269
  11. package/src/doctor.js +1 -639
  12. package/src/host.js +1 -111
  13. package/src/permissions.js +1 -369
  14. package/src/probes.js +1 -159
  15. package/src/release.js +1 -409
  16. package/vendor/cli/bin/aegiscode.js +2 -914
  17. package/vendor/cli/package.json +3 -7
  18. package/vendor/cli/scripts/check.mjs +1 -52
  19. package/vendor/cli/scripts/demo.mjs +1 -94
  20. package/vendor/cli/scripts/predist.mjs +1 -75
  21. package/vendor/cli/scripts/runtests.mjs +1 -56
  22. package/vendor/cli/scripts/seal-gate.mjs +1 -74
  23. package/vendor/cli/src/agents.js +1 -139
  24. package/vendor/cli/src/app.js +1 -2932
  25. package/vendor/cli/src/art.js +1 -289
  26. package/vendor/cli/src/autonomous.js +1 -515
  27. package/vendor/cli/src/caps.js +1 -879
  28. package/vendor/cli/src/chatflow.js +1 -3020
  29. package/vendor/cli/src/checkpoint.js +1 -90
  30. package/vendor/cli/src/clipboard.js +1 -424
  31. package/vendor/cli/src/cloudsync.js +1 -528
  32. package/vendor/cli/src/commands.js +1 -4003
  33. package/vendor/cli/src/config.js +1 -581
  34. package/vendor/cli/src/connect.js +1 -349
  35. package/vendor/cli/src/credentials.js +1 -33
  36. package/vendor/cli/src/deps.js +1 -232
  37. package/vendor/cli/src/devrun.js +1 -187
  38. package/vendor/cli/src/diff.js +1 -333
  39. package/vendor/cli/src/diffview.js +1 -296
  40. package/vendor/cli/src/engine.js +1 -297
  41. package/vendor/cli/src/entitlement.js +1 -355
  42. package/vendor/cli/src/events.js +1 -707
  43. package/vendor/cli/src/export.js +1 -67
  44. package/vendor/cli/src/fingerprint.js +1 -592
  45. package/vendor/cli/src/format.js +1 -259
  46. package/vendor/cli/src/fuzzy.js +1 -119
  47. package/vendor/cli/src/gate.js +1 -55
  48. package/vendor/cli/src/history.js +1 -401
  49. package/vendor/cli/src/init.js +1 -175
  50. package/vendor/cli/src/input.js +1 -139
  51. package/vendor/cli/src/keys.js +1 -183
  52. package/vendor/cli/src/limits.js +1 -190
  53. package/vendor/cli/src/markdown.js +1 -306
  54. package/vendor/cli/src/mcp.js +1 -694
  55. package/vendor/cli/src/models.js +1 -487
  56. package/vendor/cli/src/naming.js +1 -229
  57. package/vendor/cli/src/overlays.js +1 -461
  58. package/vendor/cli/src/panels.js +1 -1418
  59. package/vendor/cli/src/permissions.js +1 -290
  60. package/vendor/cli/src/ping.js +1 -226
  61. package/vendor/cli/src/presence.js +1 -238
  62. package/vendor/cli/src/provenance.js +2 -182
  63. package/vendor/cli/src/render.js +1 -515
  64. package/vendor/cli/src/screen.js +1 -518
  65. package/vendor/cli/src/screens.js +1 -896
  66. package/vendor/cli/src/secret.js +1 -59
  67. package/vendor/cli/src/securefs.js +1 -359
  68. package/vendor/cli/src/settings.js +1 -155
  69. package/vendor/cli/src/shared.js +1 -52
  70. package/vendor/cli/src/sharedpaths.js +1 -53
  71. package/vendor/cli/src/signup.js +1 -156
  72. package/vendor/cli/src/summarize.js +1 -95
  73. package/vendor/cli/src/sysdiag.js +1 -585
  74. package/vendor/cli/src/system.js +1 -40
  75. package/vendor/cli/src/theme.js +1 -570
  76. package/vendor/cli/src/title.js +1 -220
  77. package/vendor/cli/src/todos.js +1 -115
  78. package/vendor/cli/src/tokens.js +1 -263
  79. package/vendor/cli/src/topup.js +1 -210
  80. package/vendor/cli/src/update.js +1 -181
  81. package/vendor/cli/vendor/client/aegis.js +1 -2179
  82. package/vendor/cli/vendor/client/attest.js +1 -442
  83. package/vendor/cli/vendor/client/authorship-key.js +1 -410
  84. package/vendor/cli/vendor/client/auto-provision.js +1 -134
  85. package/vendor/cli/vendor/client/brain-catalog.js +1 -268
  86. package/vendor/cli/vendor/client/byok-catalog.js +1 -230
  87. package/vendor/cli/vendor/client/credentials.js +1 -494
  88. package/vendor/cli/vendor/client/device-fingerprint.js +1 -141
  89. package/vendor/cli/vendor/client/drive-connect.js +1 -110
  90. package/vendor/cli/vendor/client/drive-upload.js +1 -174
  91. package/vendor/cli/vendor/client/env-file.js +1 -1273
  92. package/vendor/cli/vendor/client/fingerprint.js +1 -1064
  93. package/vendor/cli/vendor/client/foreign-memory.js +1 -669
  94. package/vendor/cli/vendor/client/google-signin.js +1 -133
  95. package/vendor/cli/vendor/client/hooks.js +1 -430
  96. package/vendor/cli/vendor/client/model-discovery.js +1 -373
  97. package/vendor/cli/vendor/client/platform.js +1 -937
  98. package/vendor/cli/vendor/client/prefs.js +1 -351
  99. package/vendor/cli/vendor/client/presence-constants.js +1 -107
  100. package/vendor/cli/vendor/client/presence.js +1 -438
  101. package/vendor/cli/vendor/client/record-vault.js +3 -1055
  102. package/vendor/cli/vendor/client/session-store.js +1 -548
  103. package/vendor/cli/vendor/client/topup.js +1 -297
  104. package/vendor/cli/vendor/client/touch.js +1 -458
  105. package/vendor/cli/vendor/client/update.js +1 -704
  106. package/vendor/cli/vendor/client/user-models.js +1 -381
  107. package/vendor/cli/vendor/desktop/lib/local/agents.js +1 -105
  108. package/vendor/cli/vendor/desktop/lib/local/autonomous.js +1 -1045
  109. package/vendor/cli/vendor/desktop/lib/local/claude-pro.js +1 -993
  110. package/vendor/cli/vendor/desktop/lib/local/context.js +1 -95
  111. package/vendor/cli/vendor/desktop/lib/local/engine.js +1 -3301
  112. package/vendor/cli/vendor/desktop/lib/local/entitlement.js +1 -660
  113. package/vendor/cli/vendor/desktop/lib/local/git-scope.js +1 -228
  114. package/vendor/cli/vendor/desktop/lib/local/local.js +1 -2135
  115. package/vendor/cli/vendor/desktop/lib/local/prompt.js +1 -275
  116. package/vendor/cli/vendor/desktop/lib/local/queue.js +1 -560
  117. package/vendor/cli/vendor/desktop/lib/local/session-rounds.js +1 -208
  118. package/vendor/cli/vendor/desktop/lib/local/shell.js +1 -680
  119. package/vendor/cli/vendor/desktop/lib/local/tools.js +1 -1238
  120. package/vendor/cli/vendor/desktop/lib/local/turn-guard.js +1 -300
  121. package/vendor/cli/vendor/desktop/lib/local/worktree-lock.js +1 -235
  122. package/vendor/cli/vendor/desktop/lib/settings.js +1 -890
  123. package/vendor/cli/vendor/desktop/renderer/usage.js +1 -1239
  124. package/vendor/cli/vendor/hosts/install.js +1 -638
  125. package/vendor/cli/vendor/hosts/openai-shim.js +1 -515
  126. package/vendor/cli/vendor/hosts/spec.js +1 -164
  127. package/vendor/cli/vendor/hosts/targets.js +1 -346
  128. package/vendor/cli/vendor/mcp/server.js +1 -221
  129. package/vendor/cli/vendor/mcp/tools.js +1 -408
  130. package/vendor/cli/vendor/one/src/child.js +1 -285
  131. package/vendor/cli/vendor/one/src/permissions.js +1 -369
  132. package/vendor/desktop/bin/aegis.js +1 -32
  133. package/vendor/desktop/lib/account-key.js +1 -56
  134. package/vendor/desktop/lib/auto.js +1 -430
  135. package/vendor/desktop/lib/avatar/companion.js +1 -698
  136. package/vendor/desktop/lib/avatar/cosmetics.js +1 -532
  137. package/vendor/desktop/lib/avatar/events.js +1 -344
  138. package/vendor/desktop/lib/avatar/holder-turn.js +1 -350
  139. package/vendor/desktop/lib/avatar/holders.js +1 -612
  140. package/vendor/desktop/lib/avatar/identity.js +1 -641
  141. package/vendor/desktop/lib/avatar/level.js +1 -368
  142. package/vendor/desktop/lib/avatar/mirror.js +1 -524
  143. package/vendor/desktop/lib/avatar/persona.js +1 -388
  144. package/vendor/desktop/lib/avatar/profile.js +1 -977
  145. package/vendor/desktop/lib/avatar/register.js +1 -307
  146. package/vendor/desktop/lib/avatar/store.js +1 -472
  147. package/vendor/desktop/lib/avatar/tiers.js +1 -38
  148. package/vendor/desktop/lib/avatar/transfer.js +1 -415
  149. package/vendor/desktop/lib/avatar/turn.js +1 -216
  150. package/vendor/desktop/lib/avatar/voice.js +1 -328
  151. package/vendor/desktop/lib/avatar/xp.js +1 -404
  152. package/vendor/desktop/lib/deep-link.js +1 -120
  153. package/vendor/desktop/lib/fingerprint.js +2 -347
  154. package/vendor/desktop/lib/google-connect.js +1 -227
  155. package/vendor/desktop/lib/local/agents.js +1 -105
  156. package/vendor/desktop/lib/local/autonomous.js +1 -1045
  157. package/vendor/desktop/lib/local/claude-pro.js +1 -993
  158. package/vendor/desktop/lib/local/context.js +1 -95
  159. package/vendor/desktop/lib/local/engine.js +1 -3301
  160. package/vendor/desktop/lib/local/entitlement.js +1 -660
  161. package/vendor/desktop/lib/local/git-scope.js +1 -228
  162. package/vendor/desktop/lib/local/local.js +1 -2135
  163. package/vendor/desktop/lib/local/prompt.js +1 -275
  164. package/vendor/desktop/lib/local/queue.js +1 -560
  165. package/vendor/desktop/lib/local/session-rounds.js +1 -208
  166. package/vendor/desktop/lib/local/shell.js +1 -680
  167. package/vendor/desktop/lib/local/telemetry.js +1 -470
  168. package/vendor/desktop/lib/local/tools.js +1 -1238
  169. package/vendor/desktop/lib/local/turn-guard.js +1 -300
  170. package/vendor/desktop/lib/local/worktree-lock.js +1 -235
  171. package/vendor/desktop/lib/provider-key-mirror.js +1 -252
  172. package/vendor/desktop/lib/quick-launcher.js +1 -84
  173. package/vendor/desktop/lib/settings.js +1 -890
  174. package/vendor/desktop/lib/sync/memory-queue.js +1 -60
  175. package/vendor/desktop/lib/sync/persist-gate.js +1 -148
  176. package/vendor/desktop/lib/sync/sessions.js +1 -106
  177. package/vendor/desktop/lib/window-state.js +1 -66
  178. package/vendor/desktop/main.js +1 -4529
  179. package/vendor/desktop/package.json +3 -5
  180. package/vendor/desktop/preload.js +1 -636
  181. package/vendor/desktop/renderer/app.js +1 -6660
  182. package/vendor/desktop/renderer/avatar/assemble.js +1 -335
  183. package/vendor/desktop/renderer/avatar/avatar.js +1 -380
  184. package/vendor/desktop/renderer/avatar/cards.js +1 -141
  185. package/vendor/desktop/renderer/avatar/hud.js +1 -206
  186. package/vendor/desktop/renderer/avatar/machine.js +1 -213
  187. package/vendor/desktop/renderer/avatar/pane.js +1 -439
  188. package/vendor/desktop/renderer/avatar/parts.js +1 -437
  189. package/vendor/desktop/renderer/budget.js +1 -168
  190. package/vendor/desktop/renderer/companion.js +1 -223
  191. package/vendor/desktop/renderer/diff.js +1 -359
  192. package/vendor/desktop/renderer/diffview.js +1 -336
  193. package/vendor/desktop/renderer/fingerprint.js +3 -736
  194. package/vendor/desktop/renderer/markdown.js +1 -168
  195. package/vendor/desktop/renderer/provider-toolbar.js +1 -134
  196. package/vendor/desktop/renderer/providers.js +1 -259
  197. package/vendor/desktop/renderer/quick.js +1 -191
  198. package/vendor/desktop/renderer/stream-policy.js +1 -306
  199. package/vendor/desktop/renderer/transcript-view.js +1 -323
  200. package/vendor/desktop/renderer/usage.js +1 -1239
  201. package/vendor/desktop/vendor/aegis.js +1 -2179
  202. package/vendor/desktop/vendor/attest.js +1 -442
  203. package/vendor/desktop/vendor/authorship-key.js +1 -410
  204. package/vendor/desktop/vendor/auto-provision.js +1 -134
  205. package/vendor/desktop/vendor/brain-catalog.js +1 -268
  206. package/vendor/desktop/vendor/byok-catalog.js +1 -230
  207. package/vendor/desktop/vendor/credentials.js +1 -494
  208. package/vendor/desktop/vendor/device-fingerprint.js +1 -141
  209. package/vendor/desktop/vendor/drive-connect.js +1 -110
  210. package/vendor/desktop/vendor/drive-upload.js +1 -174
  211. package/vendor/desktop/vendor/env-file.js +1 -1273
  212. package/vendor/desktop/vendor/fingerprint.js +1 -1064
  213. package/vendor/desktop/vendor/foreign-memory.js +1 -669
  214. package/vendor/desktop/vendor/google-signin.js +1 -133
  215. package/vendor/desktop/vendor/hooks.js +1 -430
  216. package/vendor/desktop/vendor/model-discovery.js +1 -373
  217. package/vendor/desktop/vendor/platform.js +1 -937
  218. package/vendor/desktop/vendor/prefs.js +1 -351
  219. package/vendor/desktop/vendor/presence-constants.js +1 -107
  220. package/vendor/desktop/vendor/presence.js +1 -438
  221. package/vendor/desktop/vendor/record-vault.js +3 -1055
  222. package/vendor/desktop/vendor/session-store.js +1 -548
  223. package/vendor/desktop/vendor/topup.js +1 -297
  224. package/vendor/desktop/vendor/touch.js +1 -458
  225. package/vendor/desktop/vendor/update.js +1 -704
  226. package/vendor/desktop/vendor/user-models.js +1 -381
@@ -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
- // AEGIS Code (aegiscode) — source: https://github.com/aegisinfo/aegiscode-plugin
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};