aegisone 1.0.22 → 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 -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 -2
  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,325 +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
- * The DOM-touching half of the transcript policy, extracted
10
- * from app.js so the two symptoms this work exists to prevent can be asserted
11
- * *behaviourally* — not just as pure math in stream-policy.js:
12
- *
13
- * - the transcript snapping to the bottom while you read → `follow()` asks
14
- * stream-policy's `shouldFollow()` and the reader's own scroll sets the
15
- * veto through `attachScrollVeto()`;
16
- * - Escape failing to interrupt → `bindEscapeInterrupt()` is the one place
17
- * the keyboard listener is registered.
18
- *
19
- * Why extract instead of testing app.js itself: app.js boots only under the
20
- * Electron host (`window.aegis`/`window.models`) and builds a 2000-line UI, so
21
- * a test that drives it would assert on a mock of everything. Everything here
22
- * touches exactly four DOM surfaces — three numbers on the transcript element
23
- * (scrollHeight/scrollTop/clientHeight), one passive `scroll` listener, one
24
- * `keydown` listener on the document, and `requestAnimationFrame` — so
25
- * test/renderer-dom.test.mjs drives the real file with a 60-line fake DOM and
26
- * no third-party dependency. app.js only calls into this.
27
- *
28
- * Loaded as a classic script (index.html) *before* app.js, and requireable
29
- * from Node like budget.js/stream-policy.js.
30
- */
31
-
32
- // The decisions stay in stream-policy.js — one definition of "at the tail" and
33
- // of "the reader has the veto". Classic script: resolve the globals declared by
34
- // the sibling script tag; CommonJS: resolve the module. Eager, so a missing
35
- // stream-policy.js script tag fails at load instead of on the first paint.
36
- const policy =
37
- typeof module !== 'undefined' && module.exports
38
- ? require('./stream-policy.js')
39
- : { nearBottom: nearBottom, shouldFollow: shouldFollow };
40
-
41
- /**
42
- * Coalescing paint + follow-the-tail state for the one transcript element.
43
- *
44
- * `messages` is the transcript (`#messages`); `requestFrame` defaults to the
45
- * window's `requestAnimationFrame` and is injectable so a test can flush
46
- * frames deterministically.
47
- */
48
- function createTranscriptView(deps) {
49
- const d = deps || {};
50
- const messages = d.messages;
51
- const requestFrame =
52
- typeof d.requestFrame === 'function'
53
- ? d.requestFrame
54
- : typeof requestAnimationFrame === 'function'
55
- ? requestAnimationFrame
56
- : (fn) => fn();
57
-
58
- /** Set while the reader has deliberately scrolled away from the tail. */
59
- let scrolledUp = false;
60
-
61
- /** Current transcript scroll metrics, or null when there is no transcript. */
62
- function metrics() {
63
- if (!messages) return null;
64
- return {
65
- scrollHeight: messages.scrollHeight,
66
- scrollTop: messages.scrollTop,
67
- clientHeight: messages.clientHeight,
68
- };
69
- }
70
-
71
- /**
72
- * The reader's veto over the streaming auto-scroll. This is the passive
73
- * `scroll` listener: without it `scrolledUp` can never become true, leaving
74
- * the transcript pinned to the tail no matter how far up you read while a
75
- * model is working. Fires on every scroll frame, so it only records position.
76
- */
77
- function noteScroll() {
78
- scrolledUp = !policy.nearBottom(metrics());
79
- return scrolledUp;
80
- }
81
-
82
- function attachScrollVeto(el) {
83
- const target = el || messages;
84
- if (!target || typeof target.addEventListener !== 'function') return false;
85
- target.addEventListener('scroll', noteScroll, { passive: true });
86
- return true;
87
- }
88
-
89
- /**
90
- * Follow the tail only while the reader is still there (was
91
- * `stickToBottom`). A streaming turn must never yank the view back down once
92
- * someone has scrolled up to read — that was why the transcript felt
93
- * unscrollable while a model was working. `force` is for the cases where the
94
- * view genuinely must follow: a message the user just sent, or a card they
95
- * just opened. Returns whether the view moved.
96
- */
97
- function follow(opts) {
98
- if (!messages) return false;
99
- if (!policy.shouldFollow(metrics(), { force: opts && opts.force, userScrolledUp: scrolledUp })) {
100
- return false;
101
- }
102
- if (opts && opts.force) scrolledUp = false;
103
- messages.scrollTop = messages.scrollHeight;
104
- return true;
105
- }
106
-
107
- /**
108
- * Coalesce high-frequency stream updates to one paint per frame (was
109
- * `rafPainter`). A cloud brain fan-out emits dozens of chunks a second, and
110
- * each repaint read scrollHeight (forcing a synchronous layout) — that
111
- * thrash is what made the window feel frozen mid-turn. Only the latest
112
- * payload is painted; dropped frames are invisible because the text is
113
- * cumulative. The returned function is idempotent within a frame.
114
- */
115
- function paint(fn) {
116
- let queued = false;
117
- return function schedule() {
118
- if (queued) return;
119
- queued = true;
120
- requestFrame(() => {
121
- queued = false;
122
- fn();
123
- });
124
- };
125
- }
126
-
127
- return {
128
- metrics: metrics,
129
- noteScroll: noteScroll,
130
- attachScrollVeto: attachScrollVeto,
131
- follow: follow,
132
- paint: paint,
133
- isScrolledUp: () => scrolledUp,
134
- };
135
- }
136
-
137
- /**
138
- * The pane-scroll signal behind the UI "lift" (see the scroll-lift section in
139
- * style.css): while any scrolling pane is off its top edge, the chrome around
140
- * it gains depth instead of reading as a static page.
141
- *
142
- * Registered *here*, next to the veto, for the same reason that veto lives
143
- * here and not inline: this file is the one owner of `scroll` listeners, so
144
- * "the reader's scroll position" has exactly one definition. A second listener
145
- * with its own idea of it is how the two drift apart — which is what
146
- * test/renderer-wiring.test.mjs's 5b guard exists to prevent.
147
- *
148
- * The panes arrive from app.js (it knows which elements scroll); this function
149
- * owns the listener, the frame coalescing and the class toggle. A `window`
150
- * listener would never fire at all — html/body are `height: 100%`, so the
151
- * window itself never scrolls — hence the explicit pane list.
152
- *
153
- * `threshold` is 4px, not 0: sub-pixel scroll positions read from a pane at
154
- * rest would otherwise flicker the shadow on and off at the top.
155
- */
156
- function attachScrollLift(deps) {
157
- const d = deps || {};
158
- const panes = Array.prototype.slice.call(d.panes || []);
159
- const target =
160
- d.target || (typeof document !== 'undefined' && document.body ? document.body : null);
161
- if (!panes.length || !target || !target.classList) return null;
162
-
163
- const schedule =
164
- typeof d.requestFrame === 'function'
165
- ? d.requestFrame
166
- : typeof requestAnimationFrame === 'function'
167
- ? requestAnimationFrame
168
- : (fn) => fn();
169
- const className = d.className || 'is-scrolled';
170
- const threshold = typeof d.threshold === 'number' ? d.threshold : 4;
171
-
172
- let queued = false;
173
- /** Idempotent: one class toggle per frame no matter how many events fired. */
174
- function sync() {
175
- queued = false;
176
- let lifted = false;
177
- for (const pane of panes) {
178
- if (pane && pane.scrollTop > threshold) {
179
- lifted = true;
180
- break;
181
- }
182
- }
183
- target.classList.toggle(className, lifted);
184
- }
185
- function onScroll() {
186
- if (queued) return;
187
- queued = true;
188
- schedule(sync);
189
- }
190
-
191
- for (const pane of panes) {
192
- if (pane && typeof pane.addEventListener === 'function') {
193
- pane.addEventListener('scroll', onScroll, { passive: true });
194
- }
195
- }
196
- sync();
197
-
198
- return {
199
- sync: sync,
200
- panes: panes,
201
- unbind: () => {
202
- for (const pane of panes) {
203
- if (pane && typeof pane.removeEventListener === 'function') {
204
- pane.removeEventListener('scroll', onScroll);
205
- }
206
- }
207
- },
208
- };
209
- }
210
-
211
- /**
212
- * Escape → the running turn's interrupt (the keyboard twin of the cancel
213
- * button, for the window that is too busy to aim at it).
214
- *
215
- * Deliberately the only `keydown` registration: the memory overlay wins while
216
- * it is open — Escape closes it rather than reaching past it to cancel a turn
217
- * the user may not be looking at — and Escape does nothing at all when no turn
218
- * is pending, so the key never becomes a surprise.
219
- *
220
- * Returns the handler plus an `unbind()` for symmetry with the listener it
221
- * owns; the return value is also what lets a test call the decision directly.
222
- */
223
- function bindEscapeInterrupt(deps) {
224
- const d = deps || {};
225
-
226
- // Why the last Escape did what it did.
227
- //
228
- // This exists because the only externally visible signal an ignored Escape
229
- // leaves behind is `defaultPrevented === false`, and that single bit cannot
230
- // tell four legitimate refusals (overlay open, no pending turn, no stopTurn,
231
- // auto-repeat) apart from the one genuinely broken case: a dependency threw
232
- // inside the listener, and `dispatchEvent` reported the listener error as
233
- // uncaught instead of propagating it to the caller. Both look identical from
234
- // outside — the turn keeps running and `defaultPrevented` is false — so a
235
- // wiring fault is indistinguishable from a policy decision without this.
236
- let lastDecision = null;
237
-
238
- function handle(e) {
239
- const decision = {
240
- at: Date.now(),
241
- key: e && e.key,
242
- repeat: Boolean(e && e.repeat),
243
- overlayOpen: null,
244
- hasPendingTurn: null,
245
- consumed: false,
246
- threw: null,
247
- };
248
- lastDecision = decision;
249
-
250
- if (!e || e.key !== 'Escape') return false;
251
- // A held key is one intent, not one per repeat. Without this the auto-repeat
252
- // events keep arriving after the interrupted turn has already ended, and
253
- // the ones that land once the user has sent the next message stop that turn
254
- // instead — the keyboard twin of a stuck cancel button.
255
- if (e.repeat) return false;
256
- if (typeof d.isOverlayOpen === 'function') {
257
- try {
258
- decision.overlayOpen = Boolean(d.isOverlayOpen());
259
- } catch (err) {
260
- // A probe that breaks must not disarm the interrupt: the user's only
261
- // keyboard route to stopping a runaway turn is this handler, and
262
- // "unknown" is not "open". The reason is recorded rather than raised,
263
- // so the smoke run fails on it while the user still gets their Escape.
264
- decision.threw = 'isOverlayOpen: ' + ((err && err.message) || err);
265
- decision.overlayOpen = false;
266
- }
267
- if (decision.overlayOpen) {
268
- if (typeof d.onOverlayEscape === 'function') {
269
- try {
270
- d.onOverlayEscape();
271
- } catch (err) {
272
- decision.threw = 'onOverlayEscape: ' + ((err && err.message) || err);
273
- }
274
- }
275
- return false;
276
- }
277
- }
278
- if (typeof d.hasPendingTurn === 'function') {
279
- try {
280
- decision.hasPendingTurn = Boolean(d.hasPendingTurn());
281
- } catch (err) {
282
- decision.threw = 'hasPendingTurn: ' + ((err && err.message) || err);
283
- return false;
284
- }
285
- if (!decision.hasPendingTurn) return false;
286
- }
287
- if (typeof d.stopTurn !== 'function') return false;
288
- if (typeof e.preventDefault === 'function') e.preventDefault();
289
- decision.consumed = true;
290
- // The key is consumed either way — the interrupt has been asked for and the
291
- // turn must not survive a throw from the stop itself. What the stop
292
- // ANSWERED is recorded, because a consumed key with a refused stop is the
293
- // one combination that looks like success from outside while nothing has
294
- // happened: `defaultPrevented` is true, the bubble never appears, and the
295
- // turn runs to completion.
296
- let stopResult = null;
297
- try {
298
- const r = d.stopTurn();
299
- stopResult = r === undefined ? null : Boolean(r);
300
- } catch (err) {
301
- stopResult = false;
302
- decision.threw = 'stopTurn: ' + ((err && err.message) || err);
303
- }
304
- decision.stopAccepted = stopResult;
305
- return true;
306
- }
307
-
308
- if (d.doc && typeof d.doc.addEventListener === 'function') {
309
- d.doc.addEventListener('keydown', handle);
310
- }
311
-
312
- return {
313
- handle: handle,
314
- lastDecision: () => lastDecision,
315
- unbind: () => {
316
- if (d.doc && typeof d.doc.removeEventListener === 'function') {
317
- d.doc.removeEventListener('keydown', handle);
318
- }
319
- },
320
- };
321
- }
322
-
323
- if (typeof module !== 'undefined' && module.exports) {
324
- module.exports = { createTranscriptView, bindEscapeInterrupt, attachScrollLift };
325
- }
3
+ "use strict";const policy="undefined"!=typeof module&&module.exports?require("./stream-policy.js"):{nearBottom:nearBottom,shouldFollow:shouldFollow};function createTranscriptView(e){const t=e||{},n=t.messages,o="function"==typeof t.requestFrame?t.requestFrame:"function"==typeof requestAnimationFrame?requestAnimationFrame:e=>e();let r=!1;function c(){return n?{scrollHeight:n.scrollHeight,scrollTop:n.scrollTop,clientHeight:n.clientHeight}:null}function l(){return r=!policy.nearBottom(c()),r}return{metrics:c,noteScroll:l,attachScrollVeto:function(e){const t=e||n;return!(!t||"function"!=typeof t.addEventListener||(t.addEventListener("scroll",l,{passive:!0}),0))},follow:function(e){return!!n&&!!policy.shouldFollow(c(),{force:e&&e.force,userScrolledUp:r})&&(e&&e.force&&(r=!1),n.scrollTop=n.scrollHeight,!0)},paint:function(e){let t=!1;return function(){t||(t=!0,o((()=>{t=!1,e()})))}},isScrolledUp:()=>r}}function attachScrollLift(e){const t=e||{},n=Array.prototype.slice.call(t.panes||[]),o=t.target||("undefined"!=typeof document&&document.body?document.body:null);if(!n.length||!o||!o.classList)return null;const r="function"==typeof t.requestFrame?t.requestFrame:"function"==typeof requestAnimationFrame?requestAnimationFrame:e=>e(),c=t.className||"is-scrolled",l="number"==typeof t.threshold?t.threshold:4;let s=!1;function i(){s=!1;let e=!1;for(const t of n)if(t&&t.scrollTop>l){e=!0;break}o.classList.toggle(c,e)}function u(){s||(s=!0,r(i))}for(const e of n)e&&"function"==typeof e.addEventListener&&e.addEventListener("scroll",u,{passive:!0});return i(),{sync:i,panes:n,unbind:()=>{for(const e of n)e&&"function"==typeof e.removeEventListener&&e.removeEventListener("scroll",u)}}}function bindEscapeInterrupt(e){const t=e||{};let n=null;function o(e){const o={at:Date.now(),key:e&&e.key,repeat:Boolean(e&&e.repeat),overlayOpen:null,hasPendingTurn:null,consumed:!1,threw:null};if(n=o,!e||"Escape"!==e.key)return!1;if(e.repeat)return!1;if("function"==typeof t.isOverlayOpen){try{o.overlayOpen=Boolean(t.isOverlayOpen())}catch(e){o.threw="isOverlayOpen: "+(e&&e.message||e),o.overlayOpen=!1}if(o.overlayOpen){if("function"==typeof t.onOverlayEscape)try{t.onOverlayEscape()}catch(e){o.threw="onOverlayEscape: "+(e&&e.message||e)}return!1}}if("function"==typeof t.hasPendingTurn){try{o.hasPendingTurn=Boolean(t.hasPendingTurn())}catch(e){return o.threw="hasPendingTurn: "+(e&&e.message||e),!1}if(!o.hasPendingTurn)return!1}if("function"!=typeof t.stopTurn)return!1;"function"==typeof e.preventDefault&&e.preventDefault(),o.consumed=!0;let r=null;try{const e=t.stopTurn();r=void 0===e?null:Boolean(e)}catch(e){r=!1,o.threw="stopTurn: "+(e&&e.message||e)}return o.stopAccepted=r,!0}return t.doc&&"function"==typeof t.doc.addEventListener&&t.doc.addEventListener("keydown",o),{handle:o,lastDecision:()=>n,unbind:()=>{t.doc&&"function"==typeof t.doc.removeEventListener&&t.doc.removeEventListener("keydown",o)}}}"undefined"!=typeof module&&module.exports&&(module.exports={createTranscriptView:createTranscriptView,bindEscapeInterrupt:bindEscapeInterrupt,attachScrollLift:attachScrollLift});