aegisone 1.0.21 → 1.0.23

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 -2
  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 -2
  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 -3008
  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 -3987
  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 -2054
  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 -85
  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 -125
  95. package/vendor/cli/vendor/client/hooks.js +1 -430
  96. package/vendor/cli/vendor/client/model-discovery.js +1 -330
  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 -3228
  112. package/vendor/cli/vendor/desktop/lib/local/entitlement.js +1 -654
  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 -169
  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 -3228
  160. package/vendor/desktop/lib/local/entitlement.js +1 -654
  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 -4390
  179. package/vendor/desktop/package.json +3 -5
  180. package/vendor/desktop/preload.js +1 -628
  181. package/vendor/desktop/renderer/app.js +1 -6560
  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 -720
  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 -2054
  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 -85
  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 -125
  215. package/vendor/desktop/vendor/hooks.js +1 -430
  216. package/vendor/desktop/vendor/model-discovery.js +1 -330
  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,441 +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
- * pane.js — the customization pane.
10
- *
11
- * The whole pane is BUILT FROM THE MANIFEST. Every select is a list of
12
- * `persona.PARTS` ids, every label comes from `parts.LABELS` (and falls back to
13
- * the raw id when a label is missing), every number bound comes from
14
- * `persona.LIMITS`. There is not one `if (part === 'hoodie')` in this file, and
15
- * that is the phase's contract: adding a part is adding an entry to the
16
- * manifest, and `desktop/test/avatar-pane.test.mjs` proves it by handing the
17
- * pane a manifest with an extra hair id and asserting the control grew a new
18
- * option with no code change anywhere.
19
- *
20
- * Three decisions worth stating, because the alternatives are the usual bugs:
21
- *
22
- * 1. **Previewing is not saving.** The pane always edits a live, in-memory
23
- * persona and re-renders, so the user can try things on; whether that
24
- * reaches disk is a separate answer (`onPatch`'s return) which the pane
25
- * shows verbatim in its status line. A control that looks like it saved
26
- * when nothing was written is the exact defect this avoids.
27
- * 2. **Cosmetics follow the level table, not this file.** An outfit or pack is
28
- * disabled only when main says the id is not unlocked (`capabilities
29
- * .cosmeticsUnlocked`). No capabilities ⇒ NO gating at all, because a pane
30
- * that invents a lock is as wrong as one that invents an unlock.
31
- * 3. **Nothing here touches input routing.** No key handlers, no focus trap, no
32
- * `preventDefault`, no modal. The pane is a plain block of form controls in
33
- * the sidebar; opening or closing it cannot consume a keystroke meant for
34
- * the composer, and the Escape-interrupt path stays exactly where it
35
- * was put.
36
- */
37
-
38
- 'use strict';
39
-
40
- const pkg = typeof window !== 'undefined' && window.AegisAvatarParts
41
- ? { parts: window.AegisAvatarParts, persona: window.AegisAvatarPersona || null }
42
- : typeof module !== 'undefined' && module.exports
43
- ? { parts: require('./parts.js'), persona: require('../../lib/avatar/persona.js') }
44
- : { parts: null, persona: null };
45
-
46
- if (!pkg.parts) throw new Error('avatar/pane.js: avatar/parts.js must be loaded first');
47
-
48
- /**
49
- * Cosmetic id → unlock id. Persona ids and unlock ids are not the same
50
- * vocabulary (a seasonal SET is `seasonal-winter` in the persona and
51
- * `outfit.seasonal` in `level.js`), so the few that differ are named here and
52
- * everything else follows the obvious `<kind>.<id>` rule. An unlock id that the
53
- * level table does not list at all is treated as FREE — see rule 2 above.
54
- */
55
- const UNLOCK_ALIASES = Object.freeze({
56
- 'outfit.seasonal-winter': 'outfit.seasonal',
57
- 'outfit.archive-coat': 'outfit.archive',
58
- });
59
-
60
- /**
61
- * Facial kinds are cosmetics and may be gated by level. Everything else
62
- * (frame, skin, hair, eyes, motion, size, proactivity, engine) is part of the
63
- * companion the user already has — the level table sells cosmetics only, and a
64
- * pane that locks a non-cosmetic would be inventing a paywall (spec §3).
65
- */
66
- const GATED_KINDS = Object.freeze(new Set(['outfit', 'palette', 'expressions']));
67
-
68
- /** Labels for the register/voice controls. The `en` keys are the persona's. */
69
- const FIELD_LABELS = Object.freeze({
70
- formality: 'Formality',
71
- humor: 'Humour',
72
- verbosity: 'Verbosity',
73
- proactivity: 'Proactivity',
74
- address: 'Addresses you as',
75
- emojis: 'Use emojis',
76
- enabled: 'Voice',
77
- engine: 'Voice engine',
78
- voiceId: 'Voice id',
79
- rate: 'Rate',
80
- motion: 'Motion',
81
- size: 'Size',
82
- docked: 'Dock in the sidebar',
83
- hairColor: 'Hair colour',
84
- pack: 'Expression pack',
85
- });
86
-
87
- function readPath(source, path) {
88
- let node = source;
89
- for (const key of path) {
90
- if (node === null || typeof node !== 'object') return undefined;
91
- node = node[key];
92
- }
93
- return node;
94
- }
95
-
96
- /** Turn a `['presentation','hair']` path + value into a persona-shaped patch. */
97
- function patchFor(path, value) {
98
- const patch = {};
99
- let node = patch;
100
- for (let i = 0; i < path.length; i += 1) {
101
- if (i === path.length - 1) node[path[i]] = value;
102
- else {
103
- node[path[i]] = {};
104
- node = node[path[i]];
105
- }
106
- }
107
- return patch;
108
- }
109
-
110
- /** `<div class="avatar-field" data-path="presentation.hair">` and friends. */
111
- function make(doc, tag, attrs, text) {
112
- const node = doc.createElement(tag);
113
- for (const [k, v] of Object.entries(attrs || {})) {
114
- if (v === undefined || v === null || v === false) continue;
115
- if (k === 'class') node.className = v;
116
- else if (k === 'text') node.textContent = String(v);
117
- else if (node.setAttribute) node.setAttribute(k, String(v));
118
- }
119
- if (text !== undefined) node.textContent = String(text);
120
- return node;
121
- }
122
-
123
- /**
124
- * Build the pane.
125
- *
126
- * @param {object} input
127
- * @param {object} input.doc the document to build into
128
- * @param {object} input.persona the starting persona (validated or raw)
129
- * @param {object} [input.manifest] `avatar/parts.js` — injectable so a test can
130
- * extend the manifest and watch the pane follow
131
- * @param {object} [input.capabilities] `level.capabilities()` output, for the
132
- * cosmetics gate only
133
- * @param {function} [input.onPatch] called with a persona-shaped patch for every
134
- * change; its return value (or promise) is what the status line reports
135
- */
136
- function buildPane(input = {}) {
137
- const doc = input.doc;
138
- if (!doc || typeof doc.createElement !== 'function') {
139
- throw new Error('buildPane: a document is required');
140
- }
141
- const manifest = input.manifest || pkg.parts;
142
- const limits = (pkg.persona && pkg.persona.LIMITS) || { name: 40, address: 32, voiceId: 64 };
143
- const maxLayers = (pkg.persona && pkg.persona.MAX_OUTFIT_LAYERS) || 3;
144
-
145
- let persona = input.persona && typeof input.persona === 'object'
146
- ? input.persona
147
- : pkg.persona
148
- ? pkg.persona.defaultPersona()
149
- : manifest.defaultPersona();
150
-
151
- const unlocked = input.capabilities && Array.isArray(input.capabilities.cosmeticsUnlocked)
152
- ? new Set(input.capabilities.cosmeticsUnlocked)
153
- : null;
154
-
155
- const controls = [];
156
- const root = make(doc, 'div', { class: 'avatar-pane', id: 'avatar-pane' });
157
-
158
- /** Is this cosmetic available? Unknown capabilities never gate anything. */
159
- function cosmeticState(kind, id) {
160
- if (kind === 'expressionPack' || kind === 'expressions') kind = 'expressions';
161
- const unlockId = UNLOCK_ALIASES[`${kind}.${id}`] || `${kind}.${id}`;
162
- if (!GATED_KINDS.has(kind)) return { id: unlockId, known: false, unlocked: true };
163
- if (!unlocked) return { id: unlockId, known: false, unlocked: true };
164
- return { id: unlockId, known: true, unlocked: unlocked.has(unlockId) };
165
- }
166
-
167
- /** The unlock id behind a pack id, for the pack select's label. */
168
- function packNote(id) {
169
- const state = cosmeticState('expressions', id);
170
- return state.known && !state.unlocked ? `locked · needs ${state.id}` : '';
171
- }
172
-
173
- function label(kind, id) {
174
- const table = manifest.LABELS && manifest.LABELS[kind];
175
- return (table && table[id]) || String(id);
176
- }
177
-
178
- /** One `<select>` whose options ARE a manifest id list. */
179
- function selectField(group, kindKey, path, kind) {
180
- const field = make(doc, 'div', { class: 'avatar-field', 'data-path': path.join('.') });
181
- const labelNode = make(doc, 'label', { class: 'avatar-label' }, FIELD_LABELS[kindKey] || kindKey);
182
- const control = make(doc, 'select', { id: `avatar-${kind}-${path.join('-')}`, class: 'avatar-select' });
183
- const ids = manifest.IDS[kind] || [];
184
- for (const id of ids) {
185
- const state = cosmeticState(kind, id);
186
- const option = make(doc, 'option', { value: id }, label(kind, id));
187
- option.value = id;
188
- if (!state.unlocked) {
189
- option.disabled = true;
190
- option.textContent = `${label(kind, id)} · locked`;
191
- }
192
- control.appendChild(option);
193
- }
194
- control.value = String(readPath(persona, path));
195
- const note = make(doc, 'span', { class: 'avatar-field-note' });
196
- const record = { path, kind, control, tag: 'select', group };
197
- control.addEventListener('change', () => {
198
- const state = cosmeticState(kind, control.value);
199
- if (!state.unlocked) {
200
- // Refused rather than applied: the option is disabled, but a programmatic
201
- // change can still set it, and a silent "saved" for a locked cosmetic is
202
- // the dishonesty this branch exists to prevent.
203
- note.textContent = `${label(kind, control.value)} is not unlocked yet (${state.id})`;
204
- emit(record, readPath(persona, path));
205
- return;
206
- }
207
- note.textContent = '';
208
- emit(record, control.value);
209
- });
210
- controls.push(record);
211
- field.appendChild(labelNode);
212
- field.appendChild(control);
213
- field.appendChild(note);
214
- return { field, control };
215
- }
216
-
217
- function rangeField(group, key, path, { min, max, step, format }) {
218
- const field = make(doc, 'div', { class: 'avatar-field', 'data-path': path.join('.') });
219
- const value = readPath(persona, path);
220
- const valueNode = make(doc, 'span', { class: 'avatar-value' }, format ? format(value) : String(value));
221
- const labelNode = make(doc, 'label', { class: 'avatar-label' }, FIELD_LABELS[key] || key);
222
- const control = make(doc, 'input', {
223
- type: 'range',
224
- id: `avatar-${key}`,
225
- min: String(min),
226
- max: String(max),
227
- step: String(step),
228
- });
229
- control.value = String(value);
230
- const record = { path, kind: key, control, tag: 'input', group };
231
- control.addEventListener('input', () => {
232
- valueNode.textContent = format ? format(control.value) : String(control.value);
233
- emit(record, Number(control.value));
234
- });
235
- controls.push(record);
236
- field.appendChild(labelNode);
237
- field.appendChild(control);
238
- field.appendChild(valueNode);
239
- return { field, control };
240
- }
241
-
242
- function toggleField(group, key, path) {
243
- const field = make(doc, 'div', { class: 'avatar-field', 'data-path': path.join('.') });
244
- const control = make(doc, 'input', { type: 'checkbox', id: `avatar-${key}` });
245
- control.checked = readPath(persona, path) === true;
246
- const labelNode = make(doc, 'label', { class: 'avatar-label', for: `avatar-${key}` }, FIELD_LABELS[key] || key);
247
- const record = { path, kind: key, control, tag: 'input', group };
248
- control.addEventListener('change', () => emit(record, control.checked === true));
249
- controls.push(record);
250
- field.appendChild(control);
251
- field.appendChild(labelNode);
252
- return { field, control };
253
- }
254
-
255
- function textField(group, key, path, maxLength) {
256
- const field = make(doc, 'div', { class: 'avatar-field', 'data-path': path.join('.') });
257
- const labelNode = make(doc, 'label', { class: 'avatar-label' }, FIELD_LABELS[key] || key);
258
- const control = make(doc, 'input', { type: 'text', id: `avatar-${key}`, maxlength: maxLength });
259
- control.value = String(readPath(persona, path) || '');
260
- const record = { path, kind: key, control, tag: 'input', group };
261
- control.addEventListener('change', () => emit(record, String(control.value).slice(0, maxLength)));
262
- controls.push(record);
263
- field.appendChild(labelNode);
264
- field.appendChild(control);
265
- return { field, control };
266
- }
267
-
268
- function colorField(group, key, path) {
269
- const field = make(doc, 'div', { class: 'avatar-field', 'data-path': path.join('.') });
270
- const labelNode = make(doc, 'label', { class: 'avatar-label' }, FIELD_LABELS[key] || key);
271
- const control = make(doc, 'input', { type: 'color', id: `avatar-${key}` });
272
- control.value = String(readPath(persona, path) || '#3b2a20');
273
- const record = { path, kind: key, control, tag: 'input', group };
274
- control.addEventListener('change', () => emit(record, String(control.value).toLowerCase()));
275
- controls.push(record);
276
- field.appendChild(labelNode);
277
- field.appendChild(control);
278
- return { field, control };
279
- }
280
-
281
- /** Outfit multi-select, capped by `persona.MAX_OUTFIT_LAYERS` (spec §2). */
282
- function outfitField(group) {
283
- const field = make(doc, 'div', { class: 'avatar-field', 'data-path': 'presentation.outfit' });
284
- field.appendChild(make(doc, 'div', { class: 'avatar-label' }, 'Outfit (up to ' + maxLayers + ' layers)'));
285
- const chosen = Array.isArray(readPath(persona, ['presentation', 'outfit']))
286
- ? readPath(persona, ['presentation', 'outfit']).slice()
287
- : [];
288
- const boxes = [];
289
- const note = make(doc, 'span', { class: 'avatar-field-note' });
290
- for (const id of manifest.IDS.outfit || []) {
291
- const state = cosmeticState('outfit', id);
292
- const row = make(doc, 'div', { class: 'avatar-check' });
293
- const box = make(doc, 'input', { type: 'checkbox', id: `avatar-outfit-${id}` });
294
- box.checked = chosen.includes(id);
295
- box.disabled = !state.unlocked;
296
- const labelNode = make(doc, 'label', { for: `avatar-outfit-${id}` }, label('outfit', id) + (state.unlocked ? '' : ' · locked'));
297
- const record = { path: ['presentation', 'outfit'], kind: 'outfitLayer', control: box, tag: 'input', group, id };
298
- box.addEventListener('change', () => {
299
- const current = Array.isArray(readPath(persona, ['presentation', 'outfit']))
300
- ? readPath(persona, ['presentation', 'outfit']).slice()
301
- : [];
302
- let next;
303
- if (box.checked) {
304
- if (current.length >= maxLayers) {
305
- // Refuse, uncheck the box, and say why. Silently dropping the oldest
306
- // layer would look like the click worked.
307
- box.checked = false;
308
- note.textContent = `at most ${maxLayers} outfit layers (earned at level 5)`;
309
- return;
310
- }
311
- next = current.concat([id]);
312
- } else {
313
- next = current.filter((x) => x !== id);
314
- }
315
- note.textContent = '';
316
- emit(record, next);
317
- });
318
- controls.push(record);
319
- boxes.push(box);
320
- row.appendChild(box);
321
- row.appendChild(labelNode);
322
- field.appendChild(row);
323
- }
324
- field.appendChild(note);
325
- return { field, control: boxes };
326
- }
327
-
328
- function group(title, key) {
329
- const node = make(doc, 'div', { class: 'avatar-group', 'data-group': key });
330
- node.appendChild(make(doc, 'div', { class: 'avatar-group-title' }, title));
331
- root.appendChild(node);
332
- return node;
333
- }
334
-
335
- // ---- presentation ------------------------------------------------------
336
- const presentation = group('Presentation', 'presentation');
337
- presentation.appendChild(selectField('presentation', 'frame', ['presentation', 'frame'], 'frame').field);
338
- presentation.appendChild(selectField('presentation', 'skin', ['presentation', 'skin'], 'skin').field);
339
- presentation.appendChild(selectField('presentation', 'hair', ['presentation', 'hair'], 'hair').field);
340
- presentation.appendChild(colorField('presentation', 'hairColor', ['presentation', 'hairColor']).field);
341
- presentation.appendChild(selectField('presentation', 'eyes', ['presentation', 'eyes'], 'eyes').field);
342
- presentation.appendChild(selectField('presentation', 'palette', ['presentation', 'palette'], 'palette').field);
343
- presentation.appendChild(outfitField('presentation').field);
344
-
345
- // ---- expressions -------------------------------------------------------
346
- const expressions = group('Expressions', 'expressions');
347
- expressions.appendChild(selectField('expressions', 'pack', ['expressions', 'pack'], 'expressionPack').field);
348
-
349
- // ---- voice -------------------------------------------------------------
350
- const voice = group('Voice', 'voice');
351
- voice.appendChild(toggleField('voice', 'enabled', ['voice', 'enabled']).field);
352
- voice.appendChild(selectField('voice', 'engine', ['voice', 'engine'], 'voiceEngine').field);
353
- voice.appendChild(textField('voice', 'voiceId', ['voice', 'id'], limits.voiceId || 64).field);
354
- voice.appendChild(rangeField('voice', 'rate', ['voice', 'rate'], { min: 0.5, max: 2, step: 0.1, format: (v) => `${Number(v).toFixed(1)}×` }).field);
355
-
356
- // ---- register ----------------------------------------------------------
357
- const register = group('Register', 'register');
358
- const pct = (v) => `${Math.round(Number(v) * 100)}%`;
359
- register.appendChild(rangeField('register', 'formality', ['register', 'formality'], { min: 0, max: 1, step: 0.05, format: pct }).field);
360
- register.appendChild(rangeField('register', 'humor', ['register', 'humor'], { min: 0, max: 1, step: 0.05, format: pct }).field);
361
- register.appendChild(rangeField('register', 'verbosity', ['register', 'verbosity'], { min: 0, max: 1, step: 0.05, format: pct }).field);
362
- register.appendChild(selectField('register', 'proactivity', ['register', 'proactivity'], 'proactivity').field);
363
- register.appendChild(textField('register', 'address', ['register', 'address'], limits.address || 32).field);
364
- register.appendChild(toggleField('register', 'emojis', ['register', 'emojis']).field);
365
-
366
- // ---- appearance --------------------------------------------------------
367
- const appearance = group('Appearance', 'appearance');
368
- appearance.appendChild(selectField('appearance', 'motion', ['appearance', 'motion'], 'motion').field);
369
- appearance.appendChild(selectField('appearance', 'size', ['appearance', 'size'], 'size').field);
370
- appearance.appendChild(toggleField('appearance', 'docked', ['appearance', 'docked']).field);
371
-
372
- // ---- status ------------------------------------------------------------
373
- const status = make(doc, 'p', { class: 'avatar-pane-status', id: 'avatar-pane-status', role: 'status' });
374
- root.appendChild(status);
375
-
376
- /** Every control fires through here, so "preview vs saved" has ONE answer. */
377
- function emit(record, value) {
378
- persona = pkg.persona ? pkg.persona.validate(merge(persona, patchFor(record.path, value))).persona : persona;
379
- const patch = patchFor(record.path, value);
380
- let result;
381
- try {
382
- result = typeof input.onPatch === 'function' ? input.onPatch(patch, { persona, record }) : undefined;
383
- } catch (err) {
384
- result = { ok: false, reason: (err && err.message) || 'change handler threw' };
385
- }
386
- Promise.resolve(result).then(
387
- (res) => {
388
- if (res && res.ok) setStatus(res.saved === false ? 'preview only' : 'saved');
389
- else if (res && res.reason) setStatus(`not saved — ${res.reason}`);
390
- else if (res === undefined) setStatus('');
391
- else setStatus('preview only');
392
- },
393
- (err) => setStatus(`not saved — ${(err && err.message) || 'error'}`)
394
- );
395
- return persona;
396
- }
397
-
398
- function setStatus(text) {
399
- status.textContent = String(text || '');
400
- status.hidden = !text;
401
- }
402
-
403
- function merge(base, patch) {
404
- const out = {};
405
- for (const key of ['identity', 'presentation', 'expressions', 'voice', 'register', 'appearance']) {
406
- out[key] = Object.assign({}, base[key], patch[key]);
407
- }
408
- return out;
409
- }
410
-
411
- return {
412
- root,
413
- controls,
414
- status,
415
- get persona() {
416
- return persona;
417
- },
418
- /** Reset every control to a persona (used when main's copy wins). */
419
- update(next) {
420
- if (!next || typeof next !== 'object') return persona;
421
- persona = next;
422
- for (const record of controls) {
423
- const value = readPath(persona, record.path);
424
- if (record.tag === 'select') record.control.value = String(value);
425
- else if ((record.control.type || '') === 'checkbox') record.control.checked = value === true;
426
- else if (Array.isArray(value) && record.kind === 'outfitLayer') record.control.checked = value.includes(record.id);
427
- else record.control.value = String(value);
428
- }
429
- return persona;
430
- },
431
- setStatus,
432
- destroy() {
433
- if (root.parentNode && root.parentNode.removeChild) root.parentNode.removeChild(root);
434
- },
435
- };
436
- }
437
-
438
- const API = Object.freeze({ buildPane, patchFor, readPath, UNLOCK_ALIASES, FIELD_LABELS });
439
-
440
- if (typeof module !== 'undefined' && module.exports) module.exports = API;
441
- else if (typeof globalThis !== 'undefined') globalThis.AegisAvatarPane = API;
3
+ "use strict";const pkg="undefined"!=typeof window&&window.AegisAvatarParts?{parts:window.AegisAvatarParts,persona:window.AegisAvatarPersona||null}:"undefined"!=typeof module&&module.exports?{parts:require("./parts.js"),persona:require("../../lib/avatar/persona.js")}:{parts:null,persona:null};if(!pkg.parts)throw new Error("avatar/pane.js: avatar/parts.js must be loaded first");const UNLOCK_ALIASES=Object.freeze({"outfit.seasonal-winter":"outfit.seasonal","outfit.archive-coat":"outfit.archive"}),GATED_KINDS=Object.freeze(new Set(["outfit","palette","expressions"])),FIELD_LABELS=Object.freeze({formality:"Formality",humor:"Humour",verbosity:"Verbosity",proactivity:"Proactivity",address:"Addresses you as",emojis:"Use emojis",enabled:"Voice",engine:"Voice engine",voiceId:"Voice id",rate:"Rate",motion:"Motion",size:"Size",docked:"Dock in the sidebar",hairColor:"Hair colour",pack:"Expression pack"});function readPath(e,t){let a=e;for(const e of t){if(null===a||"object"!=typeof a)return;a=a[e]}return a}function patchFor(e,t){const a={};let n=a;for(let a=0;a<e.length;a+=1)a===e.length-1?n[e[a]]=t:(n[e[a]]={},n=n[e[a]]);return a}function make(e,t,a,n){const i=e.createElement(t);for(const[e,t]of Object.entries(a||{}))null!=t&&!1!==t&&("class"===e?i.className=t:"text"===e?i.textContent=String(t):i.setAttribute&&i.setAttribute(e,String(t)));return void 0!==n&&(i.textContent=String(n)),i}function buildPane(e={}){const t=e.doc;if(!t||"function"!=typeof t.createElement)throw new Error("buildPane: a document is required");const a=e.manifest||pkg.parts,n=pkg.persona&&pkg.persona.LIMITS||{name:40,address:32,voiceId:64},i=pkg.persona&&pkg.persona.MAX_OUTFIT_LAYERS||3;let r=e.persona&&"object"==typeof e.persona?e.persona:pkg.persona?pkg.persona.defaultPersona():a.defaultPersona();const o=e.capabilities&&Array.isArray(e.capabilities.cosmeticsUnlocked)?new Set(e.capabilities.cosmeticsUnlocked):null,s=[],d=make(t,"div",{class:"avatar-pane",id:"avatar-pane"});function p(e,t){"expressionPack"!==e&&"expressions"!==e||(e="expressions");const a=UNLOCK_ALIASES[`${e}.${t}`]||`${e}.${t}`;return GATED_KINDS.has(e)&&o?{id:a,known:!0,unlocked:o.has(a)}:{id:a,known:!1,unlocked:!0}}function l(e,t){const n=a.LABELS&&a.LABELS[e];return n&&n[t]||String(t)}function c(e,n,i,o){const d=make(t,"div",{class:"avatar-field","data-path":i.join(".")}),c=make(t,"label",{class:"avatar-label"},FIELD_LABELS[n]||n),u=make(t,"select",{id:`avatar-${o}-${i.join("-")}`,class:"avatar-select"}),h=a.IDS[o]||[];for(const e of h){const a=p(o,e),n=make(t,"option",{value:e},l(o,e));n.value=e,a.unlocked||(n.disabled=!0,n.textContent=`${l(o,e)} · locked`),u.appendChild(n)}u.value=String(readPath(r,i));const f=make(t,"span",{class:"avatar-field-note"}),v={path:i,kind:o,control:u,tag:"select",group:e};return u.addEventListener("change",(()=>{const e=p(o,u.value);if(!e.unlocked)return f.textContent=`${l(o,u.value)} is not unlocked yet (${e.id})`,void L(v,readPath(r,i));f.textContent="",L(v,u.value)})),s.push(v),d.appendChild(c),d.appendChild(u),d.appendChild(f),{field:d,control:u}}function u(e,a,n,{min:i,max:o,step:d,format:p}){const l=make(t,"div",{class:"avatar-field","data-path":n.join(".")}),c=readPath(r,n),u=make(t,"span",{class:"avatar-value"},p?p(c):String(c)),h=make(t,"label",{class:"avatar-label"},FIELD_LABELS[a]||a),f=make(t,"input",{type:"range",id:`avatar-${a}`,min:String(i),max:String(o),step:String(d)});f.value=String(c);const v={path:n,kind:a,control:f,tag:"input",group:e};return f.addEventListener("input",(()=>{u.textContent=p?p(f.value):String(f.value),L(v,Number(f.value))})),s.push(v),l.appendChild(h),l.appendChild(f),l.appendChild(u),{field:l,control:f}}function h(e,a,n){const i=make(t,"div",{class:"avatar-field","data-path":n.join(".")}),o=make(t,"input",{type:"checkbox",id:`avatar-${a}`});o.checked=!0===readPath(r,n);const d=make(t,"label",{class:"avatar-label",for:`avatar-${a}`},FIELD_LABELS[a]||a),p={path:n,kind:a,control:o,tag:"input",group:e};return o.addEventListener("change",(()=>L(p,!0===o.checked))),s.push(p),i.appendChild(o),i.appendChild(d),{field:i,control:o}}function f(e,a,n,i){const o=make(t,"div",{class:"avatar-field","data-path":n.join(".")}),d=make(t,"label",{class:"avatar-label"},FIELD_LABELS[a]||a),p=make(t,"input",{type:"text",id:`avatar-${a}`,maxlength:i});p.value=String(readPath(r,n)||"");const l={path:n,kind:a,control:p,tag:"input",group:e};return p.addEventListener("change",(()=>L(l,String(p.value).slice(0,i)))),s.push(l),o.appendChild(d),o.appendChild(p),{field:o,control:p}}function v(e,a){const n=make(t,"div",{class:"avatar-group","data-group":a});return n.appendChild(make(t,"div",{class:"avatar-group-title"},e)),d.appendChild(n),n}const m=v("Presentation","presentation");m.appendChild(c("presentation","frame",["presentation","frame"],"frame").field),m.appendChild(c("presentation","skin",["presentation","skin"],"skin").field),m.appendChild(c("presentation","hair",["presentation","hair"],"hair").field),m.appendChild(function(e,a,n){const i=make(t,"div",{class:"avatar-field","data-path":n.join(".")}),o=make(t,"label",{class:"avatar-label"},FIELD_LABELS[a]||a),d=make(t,"input",{type:"color",id:`avatar-${a}`});d.value=String(readPath(r,n)||"#3b2a20");const p={path:n,kind:a,control:d,tag:"input",group:"presentation"};return d.addEventListener("change",(()=>L(p,String(d.value).toLowerCase()))),s.push(p),i.appendChild(o),i.appendChild(d),{field:i,control:d}}(0,"hairColor",["presentation","hairColor"]).field),m.appendChild(c("presentation","eyes",["presentation","eyes"],"eyes").field),m.appendChild(c("presentation","palette",["presentation","palette"],"palette").field),m.appendChild(function(e){const n=make(t,"div",{class:"avatar-field","data-path":"presentation.outfit"});n.appendChild(make(t,"div",{class:"avatar-label"},"Outfit (up to "+i+" layers)"));const o=Array.isArray(readPath(r,["presentation","outfit"]))?readPath(r,["presentation","outfit"]).slice():[],d=[],c=make(t,"span",{class:"avatar-field-note"});for(const e of a.IDS.outfit||[]){const a=p("outfit",e),u=make(t,"div",{class:"avatar-check"}),h=make(t,"input",{type:"checkbox",id:`avatar-outfit-${e}`});h.checked=o.includes(e),h.disabled=!a.unlocked;const f=make(t,"label",{for:`avatar-outfit-${e}`},l("outfit",e)+(a.unlocked?"":" · locked")),v={path:["presentation","outfit"],kind:"outfitLayer",control:h,tag:"input",group:"presentation",id:e};h.addEventListener("change",(()=>{const t=Array.isArray(readPath(r,["presentation","outfit"]))?readPath(r,["presentation","outfit"]).slice():[];let a;if(h.checked){if(t.length>=i)return h.checked=!1,void(c.textContent=`at most ${i} outfit layers (earned at level 5)`);a=t.concat([e])}else a=t.filter((t=>t!==e));c.textContent="",L(v,a)})),s.push(v),d.push(h),u.appendChild(h),u.appendChild(f),n.appendChild(u)}return n.appendChild(c),{field:n,control:d}}().field),v("Expressions","expressions").appendChild(c("expressions","pack",["expressions","pack"],"expressionPack").field);const g=v("Voice","voice");g.appendChild(h("voice","enabled",["voice","enabled"]).field),g.appendChild(c("voice","engine",["voice","engine"],"voiceEngine").field),g.appendChild(f("voice","voiceId",["voice","id"],n.voiceId||64).field),g.appendChild(u("voice","rate",["voice","rate"],{min:.5,max:2,step:.1,format:e=>`${Number(e).toFixed(1)}×`}).field);const k=v("Register","register"),C=e=>`${Math.round(100*Number(e))}%`;k.appendChild(u("register","formality",["register","formality"],{min:0,max:1,step:.05,format:C}).field),k.appendChild(u("register","humor",["register","humor"],{min:0,max:1,step:.05,format:C}).field),k.appendChild(u("register","verbosity",["register","verbosity"],{min:0,max:1,step:.05,format:C}).field),k.appendChild(c("register","proactivity",["register","proactivity"],"proactivity").field),k.appendChild(f("register","address",["register","address"],n.address||32).field),k.appendChild(h("register","emojis",["register","emojis"]).field);const b=v("Appearance","appearance");b.appendChild(c("appearance","motion",["appearance","motion"],"motion").field),b.appendChild(c("appearance","size",["appearance","size"],"size").field),b.appendChild(h("appearance","docked",["appearance","docked"]).field);const y=make(t,"p",{class:"avatar-pane-status",id:"avatar-pane-status",role:"status"});function L(t,a){r=pkg.persona?pkg.persona.validate(function(e,t){const a={};for(const n of["identity","presentation","expressions","voice","register","appearance"])a[n]=Object.assign({},e[n],t[n]);return a}(r,patchFor(t.path,a))).persona:r;const n=patchFor(t.path,a);let i;try{i="function"==typeof e.onPatch?e.onPatch(n,{persona:r,record:t}):void 0}catch(e){i={ok:!1,reason:e&&e.message||"change handler threw"}}return Promise.resolve(i).then((e=>{e&&e.ok?S(!1===e.saved?"preview only":"saved"):e&&e.reason?S(`not saved — ${e.reason}`):S(void 0===e?"":"preview only")}),(e=>S(`not saved — ${e&&e.message||"error"}`))),r}function S(e){y.textContent=String(e||""),y.hidden=!e}return d.appendChild(y),{root:d,controls:s,status:y,get persona(){return r},update(e){if(!e||"object"!=typeof e)return r;r=e;for(const e of s){const t=readPath(r,e.path);"select"===e.tag?e.control.value=String(t):"checkbox"===(e.control.type||"")?e.control.checked=!0===t:Array.isArray(t)&&"outfitLayer"===e.kind?e.control.checked=t.includes(e.id):e.control.value=String(t)}return r},setStatus:S,destroy(){d.parentNode&&d.parentNode.removeChild&&d.parentNode.removeChild(d)}}}const API=Object.freeze({buildPane:buildPane,patchFor:patchFor,readPath:readPath,UNLOCK_ALIASES:UNLOCK_ALIASES,FIELD_LABELS:FIELD_LABELS});"undefined"!=typeof module&&module.exports?module.exports=API:"undefined"!=typeof globalThis&&(globalThis.AegisAvatarPane=API);