aegisone 1.0.34 → 1.0.35

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 -976
  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 -383
  14. package/src/probes.js +1 -159
  15. package/src/release.js +1 -409
  16. package/vendor/cli/package.json +3 -7
  17. package/vendor/cli/scripts/check.mjs +1 -52
  18. package/vendor/cli/scripts/demo.mjs +1 -94
  19. package/vendor/cli/scripts/predist.mjs +1 -75
  20. package/vendor/cli/scripts/runtests.mjs +1 -56
  21. package/vendor/cli/scripts/seal-gate.mjs +1 -74
  22. package/vendor/cli/src/agents.js +1 -139
  23. package/vendor/cli/src/app.js +1 -2957
  24. package/vendor/cli/src/art.js +1 -289
  25. package/vendor/cli/src/chatflow.js +1 -3023
  26. package/vendor/cli/src/checkpoint.js +1 -90
  27. package/vendor/cli/src/clipboard.js +1 -424
  28. package/vendor/cli/src/cloudsync.js +1 -528
  29. package/vendor/cli/src/commands.js +1 -4089
  30. package/vendor/cli/src/config.js +1 -581
  31. package/vendor/cli/src/connect.js +1 -349
  32. package/vendor/cli/src/credentials.js +1 -33
  33. package/vendor/cli/src/deps.js +1 -232
  34. package/vendor/cli/src/devrun.js +1 -187
  35. package/vendor/cli/src/diff.js +1 -333
  36. package/vendor/cli/src/diffview.js +1 -296
  37. package/vendor/cli/src/engine.js +1 -297
  38. package/vendor/cli/src/entitlement.js +1 -355
  39. package/vendor/cli/src/events.js +1 -707
  40. package/vendor/cli/src/export.js +1 -67
  41. package/vendor/cli/src/filepreview.js +1 -153
  42. package/vendor/cli/src/fingerprint.js +1 -592
  43. package/vendor/cli/src/format.js +1 -259
  44. package/vendor/cli/src/fuzzy.js +1 -119
  45. package/vendor/cli/src/history.js +1 -423
  46. package/vendor/cli/src/init.js +1 -175
  47. package/vendor/cli/src/input.js +1 -139
  48. package/vendor/cli/src/keys.js +1 -183
  49. package/vendor/cli/src/markdown.js +1 -306
  50. package/vendor/cli/src/models.js +1 -507
  51. package/vendor/cli/src/naming.js +1 -57
  52. package/vendor/cli/src/overlays.js +1 -462
  53. package/vendor/cli/src/panels.js +1 -1418
  54. package/vendor/cli/src/ping.js +1 -226
  55. package/vendor/cli/src/presence.js +1 -238
  56. package/vendor/cli/src/render.js +1 -516
  57. package/vendor/cli/src/screen.js +1 -518
  58. package/vendor/cli/src/screens.js +1 -896
  59. package/vendor/cli/src/secret.js +1 -59
  60. package/vendor/cli/src/securefs.js +1 -359
  61. package/vendor/cli/src/settings.js +1 -155
  62. package/vendor/cli/src/shared.js +1 -52
  63. package/vendor/cli/src/sharedpaths.js +1 -53
  64. package/vendor/cli/src/signup.js +1 -156
  65. package/vendor/cli/src/summarize.js +1 -95
  66. package/vendor/cli/src/sysdiag.js +1 -585
  67. package/vendor/cli/src/system.js +1 -40
  68. package/vendor/cli/src/theme.js +1 -570
  69. package/vendor/cli/src/title.js +1 -220
  70. package/vendor/cli/src/todos.js +1 -115
  71. package/vendor/cli/src/tokens.js +1 -263
  72. package/vendor/cli/src/topup.js +1 -210
  73. package/vendor/cli/src/update.js +1 -191
  74. package/vendor/cli/vendor/client/aegis.js +1 -2441
  75. package/vendor/cli/vendor/client/attest.js +1 -518
  76. package/vendor/cli/vendor/client/authorship-key.js +1 -410
  77. package/vendor/cli/vendor/client/auto-provision.js +1 -134
  78. package/vendor/cli/vendor/client/brain-catalog.js +1 -268
  79. package/vendor/cli/vendor/client/byok-catalog.js +1 -199
  80. package/vendor/cli/vendor/client/catalog-client.js +1 -487
  81. package/vendor/cli/vendor/client/conversation-export.js +1 -177
  82. package/vendor/cli/vendor/client/credentials.js +1 -494
  83. package/vendor/cli/vendor/client/device-fingerprint.js +1 -141
  84. package/vendor/cli/vendor/client/drive-connect.js +1 -110
  85. package/vendor/cli/vendor/client/drive-upload.js +1 -234
  86. package/vendor/cli/vendor/client/env-file.js +1 -1273
  87. package/vendor/cli/vendor/client/fingerprint.js +1 -1064
  88. package/vendor/cli/vendor/client/foreign-memory.js +1 -669
  89. package/vendor/cli/vendor/client/google-signin.js +1 -133
  90. package/vendor/cli/vendor/client/hooks.js +1 -430
  91. package/vendor/cli/vendor/client/model-discovery.js +1 -373
  92. package/vendor/cli/vendor/client/naming.js +1 -283
  93. package/vendor/cli/vendor/client/platform.js +1 -937
  94. package/vendor/cli/vendor/client/prefs.js +1 -351
  95. package/vendor/cli/vendor/client/presence-constants.js +1 -107
  96. package/vendor/cli/vendor/client/presence.js +1 -438
  97. package/vendor/cli/vendor/client/record-vault.js +3 -1055
  98. package/vendor/cli/vendor/client/session-store.js +1 -575
  99. package/vendor/cli/vendor/client/topup.js +1 -297
  100. package/vendor/cli/vendor/client/touch.js +1 -458
  101. package/vendor/cli/vendor/client/update.js +1 -763
  102. package/vendor/cli/vendor/client/user-models.js +1 -381
  103. package/vendor/cli/vendor/desktop/lib/local/agents.js +1 -105
  104. package/vendor/cli/vendor/desktop/lib/local/attachments.js +1 -276
  105. package/vendor/cli/vendor/desktop/lib/local/autonomous.js +1 -1045
  106. package/vendor/cli/vendor/desktop/lib/local/claude-pro.js +1 -1028
  107. package/vendor/cli/vendor/desktop/lib/local/context.js +1 -125
  108. package/vendor/cli/vendor/desktop/lib/local/engine.js +1 -3666
  109. package/vendor/cli/vendor/desktop/lib/local/entitlement.js +1 -660
  110. package/vendor/cli/vendor/desktop/lib/local/git-scope.js +1 -228
  111. package/vendor/cli/vendor/desktop/lib/local/local.js +1 -2145
  112. package/vendor/cli/vendor/desktop/lib/local/prompt.js +1 -280
  113. package/vendor/cli/vendor/desktop/lib/local/queue.js +1 -560
  114. package/vendor/cli/vendor/desktop/lib/local/session-rounds.js +1 -238
  115. package/vendor/cli/vendor/desktop/lib/local/spill.js +1 -75
  116. package/vendor/cli/vendor/desktop/lib/local/turn-guard.js +1 -300
  117. package/vendor/cli/vendor/desktop/lib/local/worktree-lock.js +1 -235
  118. package/vendor/cli/vendor/desktop/lib/settings.js +1 -890
  119. package/vendor/cli/vendor/desktop/renderer/usage.js +1 -1239
  120. package/vendor/cli/vendor/hosts/install.js +1 -638
  121. package/vendor/cli/vendor/hosts/openai-shim.js +1 -515
  122. package/vendor/cli/vendor/hosts/spec.js +1 -164
  123. package/vendor/cli/vendor/hosts/targets.js +1 -346
  124. package/vendor/cli/vendor/mcp/server.js +1 -221
  125. package/vendor/cli/vendor/mcp/tools.js +1 -408
  126. package/vendor/cli/vendor/one/src/child.js +1 -285
  127. package/vendor/cli/vendor/one/src/permissions.js +1 -383
  128. package/vendor/desktop/bin/aegis.js +1 -32
  129. package/vendor/desktop/lib/account-key.js +1 -56
  130. package/vendor/desktop/lib/auto.js +1 -461
  131. package/vendor/desktop/lib/avatar/companion.js +1 -698
  132. package/vendor/desktop/lib/avatar/cosmetics.js +1 -532
  133. package/vendor/desktop/lib/avatar/events.js +1 -344
  134. package/vendor/desktop/lib/avatar/holder-turn.js +1 -350
  135. package/vendor/desktop/lib/avatar/holders.js +1 -612
  136. package/vendor/desktop/lib/avatar/identity.js +1 -641
  137. package/vendor/desktop/lib/avatar/level.js +1 -368
  138. package/vendor/desktop/lib/avatar/mirror.js +1 -524
  139. package/vendor/desktop/lib/avatar/persona.js +1 -388
  140. package/vendor/desktop/lib/avatar/profile.js +1 -977
  141. package/vendor/desktop/lib/avatar/register.js +1 -307
  142. package/vendor/desktop/lib/avatar/store.js +1 -472
  143. package/vendor/desktop/lib/avatar/tiers.js +1 -38
  144. package/vendor/desktop/lib/avatar/transfer.js +1 -415
  145. package/vendor/desktop/lib/avatar/turn.js +1 -216
  146. package/vendor/desktop/lib/avatar/voice.js +1 -328
  147. package/vendor/desktop/lib/avatar/xp.js +1 -404
  148. package/vendor/desktop/lib/deep-link.js +1 -120
  149. package/vendor/desktop/lib/fingerprint.js +2 -347
  150. package/vendor/desktop/lib/google-connect.js +1 -323
  151. package/vendor/desktop/lib/local/agents.js +1 -105
  152. package/vendor/desktop/lib/local/attachments.js +1 -276
  153. package/vendor/desktop/lib/local/autonomous.js +1 -1045
  154. package/vendor/desktop/lib/local/claude-pro.js +1 -1028
  155. package/vendor/desktop/lib/local/context.js +1 -125
  156. package/vendor/desktop/lib/local/engine.js +1 -3666
  157. package/vendor/desktop/lib/local/entitlement.js +1 -660
  158. package/vendor/desktop/lib/local/git-scope.js +1 -228
  159. package/vendor/desktop/lib/local/local.js +1 -2145
  160. package/vendor/desktop/lib/local/prompt.js +1 -280
  161. package/vendor/desktop/lib/local/queue.js +1 -560
  162. package/vendor/desktop/lib/local/session-rounds.js +1 -238
  163. package/vendor/desktop/lib/local/spill.js +1 -75
  164. package/vendor/desktop/lib/local/telemetry.js +1 -470
  165. package/vendor/desktop/lib/local/turn-guard.js +1 -300
  166. package/vendor/desktop/lib/local/worktree-lock.js +1 -235
  167. package/vendor/desktop/lib/provider-key-mirror.js +1 -252
  168. package/vendor/desktop/lib/quick-launcher.js +1 -84
  169. package/vendor/desktop/lib/settings.js +1 -890
  170. package/vendor/desktop/lib/sync/memory-queue.js +1 -60
  171. package/vendor/desktop/lib/sync/persist-gate.js +1 -148
  172. package/vendor/desktop/lib/sync/sessions.js +1 -106
  173. package/vendor/desktop/lib/window-state.js +1 -66
  174. package/vendor/desktop/package.json +2 -4
  175. package/vendor/desktop/preload.js +1 -679
  176. package/vendor/desktop/renderer/app.js +1 -7250
  177. package/vendor/desktop/renderer/avatar/assemble.js +1 -335
  178. package/vendor/desktop/renderer/avatar/avatar.js +1 -380
  179. package/vendor/desktop/renderer/avatar/cards.js +1 -141
  180. package/vendor/desktop/renderer/avatar/hud.js +1 -206
  181. package/vendor/desktop/renderer/avatar/machine.js +1 -213
  182. package/vendor/desktop/renderer/avatar/pane.js +1 -439
  183. package/vendor/desktop/renderer/avatar/parts.js +1 -437
  184. package/vendor/desktop/renderer/budget.js +1 -172
  185. package/vendor/desktop/renderer/companion.js +1 -223
  186. package/vendor/desktop/renderer/diff.js +1 -359
  187. package/vendor/desktop/renderer/diffview.js +1 -336
  188. package/vendor/desktop/renderer/filepreview.js +1 -211
  189. package/vendor/desktop/renderer/fingerprint.js +3 -789
  190. package/vendor/desktop/renderer/markdown.js +1 -168
  191. package/vendor/desktop/renderer/provider-mark.js +1 -311
  192. package/vendor/desktop/renderer/provider-toolbar.js +1 -134
  193. package/vendor/desktop/renderer/providers.js +1 -259
  194. package/vendor/desktop/renderer/quick.js +1 -285
  195. package/vendor/desktop/renderer/stream-policy.js +1 -387
  196. package/vendor/desktop/renderer/transcript-view.js +1 -323
  197. package/vendor/desktop/renderer/usage.js +1 -1239
  198. package/vendor/desktop/vendor/aegis.js +1 -2441
  199. package/vendor/desktop/vendor/attest.js +1 -518
  200. package/vendor/desktop/vendor/authorship-key.js +1 -410
  201. package/vendor/desktop/vendor/auto-provision.js +1 -134
  202. package/vendor/desktop/vendor/brain-catalog.js +1 -268
  203. package/vendor/desktop/vendor/byok-catalog.js +1 -199
  204. package/vendor/desktop/vendor/catalog-client.js +1 -487
  205. package/vendor/desktop/vendor/conversation-export.js +1 -177
  206. package/vendor/desktop/vendor/credentials.js +1 -494
  207. package/vendor/desktop/vendor/device-fingerprint.js +1 -141
  208. package/vendor/desktop/vendor/drive-connect.js +1 -110
  209. package/vendor/desktop/vendor/drive-upload.js +1 -234
  210. package/vendor/desktop/vendor/env-file.js +1 -1273
  211. package/vendor/desktop/vendor/fingerprint.js +1 -1064
  212. package/vendor/desktop/vendor/foreign-memory.js +1 -669
  213. package/vendor/desktop/vendor/google-signin.js +1 -133
  214. package/vendor/desktop/vendor/hooks.js +1 -430
  215. package/vendor/desktop/vendor/model-discovery.js +1 -373
  216. package/vendor/desktop/vendor/naming.js +1 -283
  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 -575
  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 -763
  226. package/vendor/desktop/vendor/user-models.js +1 -381
@@ -1,382 +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
- * avatar.js — the mount: stage, HUD, pane, and the rules that keep the avatar
10
- * out of everything else's way.
11
- *
12
- * The three modules beside this one are pure or nearly so (`parts.js` is data,
13
- * `assemble.js` builds a string, `hud.js` builds a view model, `machine.js`
14
- * owns the face's state). This file is where they meet the document, and that
15
- * makes it the only place the phase's non-functional promises can be kept or
16
- * broken:
17
- *
18
- * 1. **Never blocks input.** No key listener is registered anywhere in
19
- * `renderer/avatar/`, so the avatar cannot consume a keystroke — Escape
20
- * still reaches the interrupt handler and typing still reaches the
21
- * composer, whatever the avatar is doing. Painting is coalesced to at most
22
- * one write per animation frame (`schedule()`), so a stream that emits
23
- * fifty deltas in a frame still costs one repaint, and every entry point is
24
- * wrapped: a throw inside the avatar is swallowed and reported, never
25
- * propagated into the chat path. `desktop/test/electron-smoke-main.js`
26
- * proves the two behaviours this protects (scroll-hold and interrupt) with
27
- * the avatar mounted and streaming.
28
- *
29
- * 2. **Never claims a level it was not given.** There is no arithmetic on XP
30
- * in this file. It renders whatever projection main hands it, and when main
31
- * has nothing to hand it it says `level unknown` (see hud.js).
32
- *
33
- * 3. **Accessible by construction.** The SVG is `aria-hidden` +
34
- * `focusable="false"` (the assembler sets it), the layer that matters is a
35
- * `role="status"` text readout beside it, the XP bar is `aria-hidden` and
36
- * its numbers live in that readout, and `prefers-reduced-motion` is read
37
- * from the OS and forced through `persona.appliesMotion` — the same
38
- * function the storage layer uses, so a persona cannot opt out of the
39
- * accessibility preference.
40
- *
41
- * Source resolution is deliberately forward-compatible: `window.avatar` is
42
- * used when it exists, and `preview()` exists so the
43
- * harnesses (and the customization pane, which previews edits before anything
44
- * is written) can drive the avatar without it. Both are one code path — the
45
- * preview state is an override layer over the real one, and it is labelled as
46
- * such in the readout's own vocabulary (`source`), never presented as truth.
47
- */
48
-
49
- const pkg = typeof window !== 'undefined' && window.AegisAvatarAssemble
50
- ? {
51
- parts: window.AegisAvatarParts,
52
- assemble: window.AegisAvatarAssemble.assemble,
53
- hud: window.AegisAvatarHud,
54
- machine: window.AegisAvatarMachine,
55
- pane: window.AegisAvatarPane,
56
- persona: window.AegisAvatarPersona,
57
- }
58
- : typeof module !== 'undefined' && module.exports
59
- ? {
60
- parts: require('./parts.js'),
61
- assemble: require('./assemble.js').assemble,
62
- hud: require('./hud.js'),
63
- machine: require('./machine.js'),
64
- pane: require('./pane.js'),
65
- persona: require('../../lib/avatar/persona.js'),
66
- }
67
- : null;
68
-
69
- if (!pkg) throw new Error('avatar/avatar.js: the avatar modules must be loaded first');
70
-
71
- /** How long a quiet `idle` state sits before the face dozes off. */
72
- const IDLE_TIMEOUT_MS = 5 * 60 * 1000;
73
- /** The clock the idle timeout is evaluated on. Not a frame loop — see §6. */
74
- const TICK_INTERVAL_MS = 30000;
75
-
76
- function safe(fn, fallback) {
77
- try {
78
- return fn();
79
- } catch {
80
- return fallback;
81
- }
82
- }
83
-
84
- /**
85
- * The data source. `window.avatar` is the preload bridge the host will expose
86
- * (`state()` returning `{ persona, projection, capabilities, warnings }`); when
87
- * it is missing the avatar renders the honest unknown state rather than
88
- * inventing numbers.
89
- */
90
- function resolveSource(win) {
91
- const bridge = win && win.avatar;
92
- if (bridge && typeof bridge.state === 'function') {
93
- return {
94
- kind: 'main',
95
- reason: '',
96
- state: () => Promise.resolve(bridge.state()),
97
- set: typeof bridge.set === 'function' ? (patch) => Promise.resolve(bridge.set(patch)) : null,
98
- };
99
- }
100
- return {
101
- kind: 'none',
102
- reason: 'main has no avatar surface yet',
103
- state: () => Promise.resolve(null),
104
- set: null,
105
- };
106
- }
107
-
108
- /**
109
- * Mount the avatar.
110
- *
111
- * @param {object} input
112
- * @param {object} input.doc
113
- * @param {object} input.win
114
- * @param {object} input.els element handles (see ELEMENT_IDS in app.js); any
115
- * missing handle is skipped rather than thrown on
116
- * @param {object} [input.source] override the bridge lookup (tests)
117
- * @param {object} [input.persona] starting persona
118
- * @param {object} [input.projection] starting level projection
119
- * @param {object} [input.capabilities] starting capabilities
120
- * @param {number} [input.idleTimeoutMs]
121
- */
122
- function mountAvatar(input = {}) {
123
- const doc = input.doc;
124
- const win = input.win || (typeof window !== 'undefined' ? window : null);
125
- if (!doc || typeof doc.createElement !== 'function') {
126
- throw new Error('mountAvatar: a document is required');
127
- }
128
- const els = input.els || {};
129
- const source = input.source || resolveSource(win);
130
-
131
- const signals = pkg.machine.createAvatarSignals({ idleTimeoutMs: input.idleTimeoutMs || IDLE_TIMEOUT_MS });
132
-
133
- let persona = input.persona && typeof input.persona === 'object'
134
- ? input.persona
135
- : pkg.persona
136
- ? pkg.persona.defaultPersona()
137
- : pkg.parts.defaultPersona();
138
- let projection = input.projection && typeof input.projection === 'object' ? input.projection : null;
139
- let capabilities = input.capabilities && typeof input.capabilities === 'object' ? input.capabilities : null;
140
- let reason = input.reason || source.reason || '';
141
-
142
- const overrides = { persona: null, projection: null, capabilities: null, reason: null, active: false };
143
- let reducedMotion = false;
144
- let frame = null;
145
- let destroyed = false;
146
- let lastPainting = null;
147
- let tickTimer = null;
148
-
149
- // ---- OS preference -----------------------------------------------------
150
- const media = safe(() => (win && typeof win.matchMedia === 'function'
151
- ? win.matchMedia('(prefers-reduced-motion: reduce)')
152
- : null), null);
153
- reducedMotion = Boolean(media && media.matches);
154
- if (media && typeof media.addEventListener === 'function') {
155
- safe(() => media.addEventListener('change', (event) => {
156
- reducedMotion = Boolean(event && 'matches' in event ? event.matches : media.matches);
157
- schedule();
158
- }));
159
- }
160
-
161
- // ---- the customization pane -------------------------------------------
162
- const pane = safe(() => pkg.pane.buildPane({
163
- doc,
164
- persona,
165
- capabilities,
166
- onPatch: (patch) => {
167
- const validated = safe(() => (pkg.persona ? pkg.persona.update(persona, patch).persona : persona), persona);
168
- applyPersona(validated.persona || validated, { repaint: true });
169
- return persist(patch);
170
- },
171
- }), null);
172
- if (pane && els.paneHost && typeof els.paneHost.appendChild === 'function') {
173
- els.paneHost.appendChild(pane.root);
174
- }
175
-
176
- /**
177
- * Persist a patch through the bridge. Returns the shape the pane's status
178
- * line prints, so "saved" is only ever shown for a write that really landed.
179
- */
180
- function persist(patch) {
181
- if (!source.set) return { ok: true, saved: false, reason: source.reason || 'no write surface' };
182
- return source.set(patch).then(
183
- (res) => {
184
- if (res && res.ok === false) return { ok: false, reason: res.reason || 'refused' };
185
- if (res && res.persona) applyPersona(res.persona, { repaint: false });
186
- return { ok: true, saved: true };
187
- },
188
- (err) => ({ ok: false, reason: (err && err.message) || 'write failed' })
189
- );
190
- }
191
-
192
- // ---- painting ----------------------------------------------------------
193
- function schedule() {
194
- if (destroyed) return;
195
- if (frame !== null) return;
196
- const raf = win && typeof win.requestAnimationFrame === 'function' ? win.requestAnimationFrame : null;
197
- if (raf) {
198
- frame = safe(() => raf(paint), null);
199
- if (frame !== null) return;
200
- }
201
- // No rAF (a bare test document): coalesce on the microtask queue instead, so
202
- // the "one repaint per burst" property still holds without a timer.
203
- frame = 0;
204
- Promise.resolve().then(() => {
205
- frame = null;
206
- paint();
207
- });
208
- }
209
-
210
- function effective() {
211
- return {
212
- persona: overrides.active && overrides.persona ? overrides.persona : persona,
213
- projection: overrides.active ? overrides.projection : projection,
214
- capabilities: overrides.active ? overrides.capabilities : capabilities,
215
- reason: overrides.active && overrides.reason !== null ? overrides.reason : reason,
216
- };
217
- }
218
-
219
- function paint() {
220
- if (destroyed) return;
221
- const now = effective();
222
- const assembled = safe(
223
- () => pkg.assemble(now.persona, { expression: signals.expression, reducedMotion }),
224
- null
225
- );
226
- if (!assembled) {
227
- // A manifest that cannot assemble must not leave a stale face claiming to
228
- // be current: blank the stage and say so in the readout.
229
- if (els.stage) els.stage.innerHTML = '';
230
- } else if (els.stage) {
231
- // Generated markup only: ids, geometry and colour roles from the manifest.
232
- // No persona text ever reaches this string (see assemble.js rule 2), so
233
- // there is nothing here for a persona to inject through.
234
- els.stage.innerHTML = assembled.svg;
235
- }
236
-
237
- const model = pkg.hud.hudModel({
238
- persona: now.persona,
239
- projection: now.projection,
240
- capabilities: now.capabilities,
241
- expression: signals.expression,
242
- expressionLabel: signals.label,
243
- reason: now.reason,
244
- });
245
- safe(() => pkg.hud.renderHud(els, model));
246
- if (pane && typeof pane.update === 'function') safe(() => pane.update(now.persona));
247
- lastPainting = {
248
- expression: assembled ? assembled.expression : null,
249
- motion: assembled ? assembled.motion : null,
250
- warnings: assembled ? assembled.warnings.slice() : ['assemble failed'],
251
- missing: assembled ? assembled.missing.slice() : [],
252
- hud: model,
253
- source: overrides.active ? 'preview' : source.kind,
254
- };
255
- return lastPainting;
256
- }
257
-
258
- function applyPersona(next, opts = {}) {
259
- if (!next || typeof next !== 'object') return persona;
260
- const validated = safe(() => (pkg.persona ? pkg.persona.validate(next).persona : next), next);
261
- persona = validated && validated.persona ? validated.persona : validated;
262
- if (opts.repaint !== false) schedule();
263
- return persona;
264
- }
265
-
266
- // ---- reads from main ---------------------------------------------------
267
- function refresh() {
268
- if (destroyed) return Promise.resolve(null);
269
- return Promise.resolve(safe(() => source.state(), null)).then(
270
- (state) => {
271
- if (destroyed || !state || typeof state !== 'object') {
272
- if (!state && !reason) reason = source.reason || 'main has not published a level yet';
273
- schedule();
274
- return null;
275
- }
276
- if (state.persona) applyPersona(state.persona, { repaint: false });
277
- if (state.projection && typeof state.projection === 'object') projection = state.projection;
278
- else if (typeof state.level === 'number') projection = state;
279
- if (state.capabilities && typeof state.capabilities === 'object') capabilities = state.capabilities;
280
- reason = '';
281
- schedule();
282
- return state;
283
- },
284
- (err) => {
285
- reason = `level unavailable — ${(err && err.message) || 'read failed'}`;
286
- schedule();
287
- return null;
288
- }
289
- );
290
- }
291
-
292
- // ---- the face follows the engine ---------------------------------------
293
- function signal(name, meta) {
294
- const out = safe(() => signals.signal(name, meta), null);
295
- if (out) schedule();
296
- return out;
297
- }
298
-
299
- const api = {
300
- get expression() {
301
- return signals.expression;
302
- },
303
- get state() {
304
- return signals.state;
305
- },
306
- get persona() {
307
- return persona;
308
- },
309
- get painting() {
310
- return lastPainting;
311
- },
312
- signal,
313
- turnStart: (meta) => signal('turn.start', meta),
314
- stream: () => signal('turn.stream'),
315
- turnEnd: (meta) => signal('turn.end', meta),
316
- tool: (tool) => signal(pkg.machine.signalForTool(tool), { tool: pkg.machine.toolName(tool) }),
317
- approvalCard: () => signal('approval.card'),
318
- approvalDecided: () => signal('approval.decided'),
319
- queue: () => signal('queue.progress'),
320
- syncOk: () => signal('sync.ok'),
321
- syncError: (meta) => signal('sync.error', meta),
322
- poke: () => signal('poke'),
323
- celebrateDone: () => signal('celebrate.done'),
324
- reset: () => signal('reset'),
325
- tick: (now) => {
326
- const out = safe(() => signals.tick(now), null);
327
- if (out && out.changed) schedule();
328
- return out;
329
- },
330
- on: (fn) => signals.on(fn),
331
- setPersona: (next) => applyPersona(next),
332
- /** Ask main for a fresh projection (a turn that saved memory moved XP). */
333
- refresh,
334
- /**
335
- * The preview seam. Harnesses (the Electron smoke leg and the marketing
336
- * shot driver) and the pane use it to render a persona/level this process
337
- * was not handed by main, and `painting.source` reports it as `preview` so
338
- * the evidence can never read as if main had published it.
339
- */
340
- preview(next = {}) {
341
- overrides.active = true;
342
- if (next.persona) overrides.persona = next.persona;
343
- if ('projection' in next) overrides.projection = next.projection;
344
- if ('capabilities' in next) overrides.capabilities = next.capabilities;
345
- if ('reason' in next) overrides.reason = next.reason === undefined ? null : next.reason;
346
- schedule();
347
- return lastPainting;
348
- },
349
- clearPreview() {
350
- overrides.active = false;
351
- schedule();
352
- return lastPainting;
353
- },
354
- /** The readout text, for harnesses that assert on what a user would read. */
355
- readout() {
356
- return els.readout ? String(els.readout.textContent || '') : '';
357
- },
358
- destroy() {
359
- destroyed = true;
360
- if (tickTimer !== null) safe(() => win.clearInterval(tickTimer));
361
- tickTimer = null;
362
- if (pane && typeof pane.destroy === 'function') safe(() => pane.destroy());
363
- if (els.stage) els.stage.innerHTML = '';
364
- },
365
- };
366
-
367
- // ---- the idle clock ----------------------------------------------------
368
- // One 30s interval for the doze timeout — not a frame loop. §6 of the plan
369
- // spells out why: "pure SVG, no WebGL, no per-frame work". The interval only
370
- // evaluates a comparison; it paints only when the machine actually changes.
371
- if (win && typeof win.setInterval === 'function') {
372
- tickTimer = safe(() => win.setInterval(() => api.tick(Date.now()), TICK_INTERVAL_MS), null);
373
- }
374
-
375
- schedule();
376
- return api;
377
- }
378
-
379
- const API = Object.freeze({ mountAvatar, resolveSource, IDLE_TIMEOUT_MS, TICK_INTERVAL_MS });
380
-
381
- if (typeof module !== 'undefined' && module.exports) module.exports = API;
382
- else if (typeof globalThis !== 'undefined') globalThis.AegisAvatar = API;
3
+ "use strict";const pkg="undefined"!=typeof window&&window.AegisAvatarAssemble?{parts:window.AegisAvatarParts,assemble:window.AegisAvatarAssemble.assemble,hud:window.AegisAvatarHud,machine:window.AegisAvatarMachine,pane:window.AegisAvatarPane,persona:window.AegisAvatarPersona}:"undefined"!=typeof module&&module.exports?{parts:require("./parts.js"),assemble:require("./assemble.js").assemble,hud:require("./hud.js"),machine:require("./machine.js"),pane:require("./pane.js"),persona:require("../../lib/avatar/persona.js")}:null;if(!pkg)throw new Error("avatar/avatar.js: the avatar modules must be loaded first");const IDLE_TIMEOUT_MS=3e5,TICK_INTERVAL_MS=3e4;function safe(e,n){try{return e()}catch{return n}}function resolveSource(e){const n=e&&e.avatar;return n&&"function"==typeof n.state?{kind:"main",reason:"",state:()=>Promise.resolve(n.state()),set:"function"==typeof n.set?e=>Promise.resolve(n.set(e)):null}:{kind:"none",reason:"main has no avatar surface yet",state:()=>Promise.resolve(null),set:null}}function mountAvatar(e={}){const n=e.doc,a=e.win||("undefined"!=typeof window?window:null);if(!n||"function"!=typeof n.createElement)throw new Error("mountAvatar: a document is required");const t=e.els||{},o=e.source||resolveSource(a),r=pkg.machine.createAvatarSignals({idleTimeoutMs:e.idleTimeoutMs||3e5});let s=e.persona&&"object"==typeof e.persona?e.persona:pkg.persona?pkg.persona.defaultPersona():pkg.parts.defaultPersona(),i=e.projection&&"object"==typeof e.projection?e.projection:null,l=e.capabilities&&"object"==typeof e.capabilities?e.capabilities:null,p=e.reason||o.reason||"";const u={persona:null,projection:null,capabilities:null,reason:null,active:!1};let c=!1,d=null,f=!1,m=null,v=null;const g=safe((()=>a&&"function"==typeof a.matchMedia?a.matchMedia("(prefers-reduced-motion: reduce)"):null),null);c=Boolean(g&&g.matches),g&&"function"==typeof g.addEventListener&&safe((()=>g.addEventListener("change",(e=>{c=Boolean(e&&"matches"in e?e.matches:g.matches),h()}))));const b=safe((()=>pkg.pane.buildPane({doc:n,persona:s,capabilities:l,onPatch:e=>{const n=safe((()=>pkg.persona?pkg.persona.update(s,e).persona:s),s);return y(n.persona||n,{repaint:!0}),function(e){return o.set?o.set(e).then((e=>e&&!1===e.ok?{ok:!1,reason:e.reason||"refused"}:(e&&e.persona&&y(e.persona,{repaint:!1}),{ok:!0,saved:!0})),(e=>({ok:!1,reason:e&&e.message||"write failed"}))):{ok:!0,saved:!1,reason:o.reason||"no write surface"}}(e)}})),null);function h(){if(f)return;if(null!==d)return;const e=a&&"function"==typeof a.requestAnimationFrame?a.requestAnimationFrame:null;e&&(d=safe((()=>e(w)),null),null!==d)||(d=0,Promise.resolve().then((()=>{d=null,w()})))}function w(){if(f)return;const e={persona:u.active&&u.persona?u.persona:s,projection:u.active?u.projection:i,capabilities:u.active?u.capabilities:l,reason:u.active&&null!==u.reason?u.reason:p},n=safe((()=>pkg.assemble(e.persona,{expression:r.expression,reducedMotion:c})),null);n?t.stage&&(t.stage.innerHTML=n.svg):t.stage&&(t.stage.innerHTML="");const a=pkg.hud.hudModel({persona:e.persona,projection:e.projection,capabilities:e.capabilities,expression:r.expression,expressionLabel:r.label,reason:e.reason});return safe((()=>pkg.hud.renderHud(t,a))),b&&"function"==typeof b.update&&safe((()=>b.update(e.persona))),m={expression:n?n.expression:null,motion:n?n.motion:null,warnings:n?n.warnings.slice():["assemble failed"],missing:n?n.missing.slice():[],hud:a,source:u.active?"preview":o.kind},m}function y(e,n={}){if(!e||"object"!=typeof e)return s;const a=safe((()=>pkg.persona?pkg.persona.validate(e).persona:e),e);return s=a&&a.persona?a.persona:a,!1!==n.repaint&&h(),s}function k(e,n){const a=safe((()=>r.signal(e,n)),null);return a&&h(),a}b&&t.paneHost&&"function"==typeof t.paneHost.appendChild&&t.paneHost.appendChild(b.root);const A={get expression(){return r.expression},get state(){return r.state},get persona(){return s},get painting(){return m},signal:k,turnStart:e=>k("turn.start",e),stream:()=>k("turn.stream"),turnEnd:e=>k("turn.end",e),tool:e=>k(pkg.machine.signalForTool(e),{tool:pkg.machine.toolName(e)}),approvalCard:()=>k("approval.card"),approvalDecided:()=>k("approval.decided"),queue:()=>k("queue.progress"),syncOk:()=>k("sync.ok"),syncError:e=>k("sync.error",e),poke:()=>k("poke"),celebrateDone:()=>k("celebrate.done"),reset:()=>k("reset"),tick:e=>{const n=safe((()=>r.tick(e)),null);return n&&n.changed&&h(),n},on:e=>r.on(e),setPersona:e=>y(e),refresh:function(){return f?Promise.resolve(null):Promise.resolve(safe((()=>o.state()),null)).then((e=>f||!e||"object"!=typeof e?(e||p||(p=o.reason||"main has not published a level yet"),h(),null):(e.persona&&y(e.persona,{repaint:!1}),e.projection&&"object"==typeof e.projection?i=e.projection:"number"==typeof e.level&&(i=e),e.capabilities&&"object"==typeof e.capabilities&&(l=e.capabilities),p="",h(),e)),(e=>(p=`level unavailable — ${e&&e.message||"read failed"}`,h(),null)))},preview:(e={})=>(u.active=!0,e.persona&&(u.persona=e.persona),"projection"in e&&(u.projection=e.projection),"capabilities"in e&&(u.capabilities=e.capabilities),"reason"in e&&(u.reason=void 0===e.reason?null:e.reason),h(),m),clearPreview:()=>(u.active=!1,h(),m),readout:()=>t.readout?String(t.readout.textContent||""):"",destroy(){f=!0,null!==v&&safe((()=>a.clearInterval(v))),v=null,b&&"function"==typeof b.destroy&&safe((()=>b.destroy())),t.stage&&(t.stage.innerHTML="")}};return a&&"function"==typeof a.setInterval&&(v=safe((()=>a.setInterval((()=>A.tick(Date.now())),3e4)),null)),h(),A}const API=Object.freeze({mountAvatar:mountAvatar,resolveSource:resolveSource,IDLE_TIMEOUT_MS:3e5,TICK_INTERVAL_MS:3e4});"undefined"!=typeof module&&module.exports?module.exports=API:"undefined"!=typeof globalThis&&(globalThis.AegisAvatar=API);
@@ -1,143 +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
- * cards.js — the companion card, rendered in the shape of the tool approval
10
- * card.
11
- *
12
- * Two things make that more than a styling choice:
13
- *
14
- * 1. **It is genuinely the same card.** The class names, the action-row
15
- * structure, the disable-on-first-click behaviour and the "what just
16
- * happened" line are the approval card's, not a lookalike: a companion
17
- * proposal and a tool request read as the same kind of event, because they
18
- * are — an offer that does nothing until the user says yes.
19
- * 2. **It presumes nothing.** The decision is sent to `onDecision(cardId,
20
- * 'accept'|'dismiss')` and the card is dead afterwards. There is no
21
- * "auto-accept after N seconds", no default focus that a stray Enter could
22
- * resolve, and no path from rendering to acting: main's `dispatch()`
23
- * (`lib/avatar/companion.js`) still refuses anything without the ticket the
24
- * accept click produced. Rendering a card cannot cause an effect.
25
- *
26
- * Dependency-free and DOM-injectable (`doc`), so a test drives it without
27
- * jsdom, exactly like `renderer/diffview.js` and `renderer/avatar/assemble.js`.
28
- */
29
-
30
- const COMPANION_CARD_CLASS = 'companion-card';
31
- const APPROVAL_CARD_CLASS = 'approval-card';
32
-
33
- function textEl(doc, className, text) {
34
- const el = doc.createElement('div');
35
- el.className = className;
36
- el.textContent = text;
37
- return el;
38
- }
39
-
40
- /**
41
- * Build one companion card element.
42
- *
43
- * @param {Document} doc the document (injected: this module touches nothing global)
44
- * @param {object} card a card from `companion.createSession().consider(...)`
45
- * — `{id, title, body, facts, actions, behaviour}`
46
- * @param {(cardId: string, decision: 'accept'|'dismiss') => void} onDecision
47
- * @returns {HTMLElement|null} null for a malformed card (never throws)
48
- */
49
- function buildCompanionCard(doc, card, onDecision) {
50
- if (!doc || !card || !card.id) return null;
51
-
52
- const el = doc.createElement('div');
53
- // Both classes: `.approval-card` for the shared look, `.companion-card` so a
54
- // theme or a test can tell a proposal from a tool gate.
55
- el.className = `${APPROVAL_CARD_CLASS} ${COMPANION_CARD_CLASS}`;
56
- el.dataset.companionId = String(card.id);
57
- if (card.behaviour) el.dataset.companionBehaviour = String(card.behaviour);
58
- el.dataset.proactive = card.proactive ? 'true' : 'false';
59
-
60
- el.appendChild(textEl(doc, 'approval-title', String(card.title || card.label || 'Suggestion')));
61
-
62
- if (card.body) el.appendChild(textEl(doc, 'approval-summary', String(card.body)));
63
-
64
- const facts = Array.isArray(card.facts) ? card.facts.filter(Boolean) : [];
65
- if (facts.length) {
66
- const list = doc.createElement('ul');
67
- list.className = 'companion-facts';
68
- for (const fact of facts.slice(0, 6)) {
69
- const li = doc.createElement('li');
70
- li.textContent = String(fact);
71
- list.appendChild(li);
72
- }
73
- el.appendChild(list);
74
- }
75
-
76
- const actions = doc.createElement('div');
77
- actions.className = 'approval-actions';
78
-
79
- // Every button this card made, so resolving it can disable exactly those —
80
- // no `querySelectorAll` on the container (a card is self-contained).
81
- const buttons = [];
82
- let resolved = false;
83
-
84
- // No decision is sent until a click. Anything else (Enter on a focused card,
85
- // a timer, a programmatic "accept") is not a path this card offers.
86
- //
87
- // The `resolved` flag is belt-and-braces alongside `disabled`: a browser will
88
- // not fire a click on a disabled button, but the approval card's promise is
89
- // that one card produces at most one decision, and that must not depend on
90
- // the browser's event dispatch. main's `dispatch()` refuses the replayed
91
- // ticket anyway — three independent layers, none of them trusted alone.
92
- const decide = (action) => {
93
- if (resolved) return;
94
- resolved = true;
95
- for (const btn of buttons) btn.disabled = true;
96
- el.classList.add('resolved');
97
- const tag = textEl(doc, 'approval-decision', String(action.doneLabel || (action.decision === 'accept' ? 'Accepted' : 'Not now')));
98
- el.appendChild(tag);
99
- if (typeof onDecision === 'function') onDecision(String(card.id), action.decision);
100
- };
101
-
102
- for (const action of Array.isArray(card.actions) ? card.actions : []) {
103
- const btn = doc.createElement('button');
104
- btn.type = 'button';
105
- btn.className = `approval-btn ${action.decision === 'accept' ? 'allow' : 'deny'}`;
106
- btn.textContent = String(action.label || action.decision);
107
- btn.dataset.decision = String(action.decision);
108
- btn.addEventListener('click', () => decide(action));
109
- buttons.push(btn);
110
- actions.appendChild(btn);
111
- }
112
-
113
- if (!buttons.length) {
114
- // A card with no actions is a bug in the caller, not something to render
115
- // as a dead end.
116
- return null;
117
- }
118
-
119
- el.appendChild(actions);
120
- return el;
121
- }
122
-
123
- /**
124
- * Mount a card into `container`, reusing the approval card's `.approval-slot`
125
- * so the two can never interleave in the transcript.
126
- */
127
- function mountCompanionCard(doc, container, card, onDecision) {
128
- if (!container || typeof container.appendChild !== 'function') return null;
129
- const el = buildCompanionCard(doc, card, onDecision);
130
- if (!el) return null;
131
- let slot = typeof container.querySelector === 'function' ? container.querySelector('.approval-slot') : null;
132
- if (!slot) {
133
- slot = doc.createElement('div');
134
- slot.className = 'approval-slot';
135
- container.appendChild(slot);
136
- }
137
- slot.appendChild(el);
138
- return el;
139
- }
140
-
141
- if (typeof module !== 'undefined' && module.exports) {
142
- module.exports = { buildCompanionCard, mountCompanionCard, COMPANION_CARD_CLASS, APPROVAL_CARD_CLASS };
143
- }
3
+ "use strict";const COMPANION_CARD_CLASS="companion-card",APPROVAL_CARD_CLASS="approval-card";function textEl(t,e,n){const o=t.createElement("div");return o.className=e,o.textContent=n,o}function buildCompanionCard(t,e,n){if(!t||!e||!e.id)return null;const o=t.createElement("div");o.className=`${APPROVAL_CARD_CLASS} ${COMPANION_CARD_CLASS}`,o.dataset.companionId=String(e.id),e.behaviour&&(o.dataset.companionBehaviour=String(e.behaviour)),o.dataset.proactive=e.proactive?"true":"false",o.appendChild(textEl(t,"approval-title",String(e.title||e.label||"Suggestion"))),e.body&&o.appendChild(textEl(t,"approval-summary",String(e.body)));const a=Array.isArray(e.facts)?e.facts.filter(Boolean):[];if(a.length){const e=t.createElement("ul");e.className="companion-facts";for(const n of a.slice(0,6)){const o=t.createElement("li");o.textContent=String(n),e.appendChild(o)}o.appendChild(e)}const i=t.createElement("div");i.className="approval-actions";const l=[];let r=!1;const d=a=>{if(r)return;r=!0;for(const t of l)t.disabled=!0;o.classList.add("resolved");const i=textEl(t,"approval-decision",String(a.doneLabel||("accept"===a.decision?"Accepted":"Not now")));o.appendChild(i),"function"==typeof n&&n(String(e.id),a.decision)};for(const n of Array.isArray(e.actions)?e.actions:[]){const e=t.createElement("button");e.type="button",e.className="approval-btn "+("accept"===n.decision?"allow":"deny"),e.textContent=String(n.label||n.decision),e.dataset.decision=String(n.decision),e.addEventListener("click",(()=>d(n))),l.push(e),i.appendChild(e)}return l.length?(o.appendChild(i),o):null}function mountCompanionCard(t,e,n,o){if(!e||"function"!=typeof e.appendChild)return null;const a=buildCompanionCard(t,n,o);if(!a)return null;let i="function"==typeof e.querySelector?e.querySelector(".approval-slot"):null;return i||(i=t.createElement("div"),i.className="approval-slot",e.appendChild(i)),i.appendChild(a),a}"undefined"!=typeof module&&module.exports&&(module.exports={buildCompanionCard:buildCompanionCard,mountCompanionCard:mountCompanionCard,COMPANION_CARD_CLASS:COMPANION_CARD_CLASS,APPROVAL_CARD_CLASS:APPROVAL_CARD_CLASS});