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,338 +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 edit block's paint layer for the DOM transcript: a one-line, clickable
10
- * summary plus, when the block is open, the diff itself in Monokai Extended
11
- * colors.
12
- *
13
- * Two shapes, driven by one boolean (`open`):
14
- *
15
- * collapsed ⎿ Update(src/diff.js) +12 -3 · click to view diff
16
- *
17
- * open ⎿ Update(src/diff.js) +12 -3 · click to collapse
18
- * 12 const a = 1;
19
- * 13 - const b = 2;
20
- * 13 + const b = 3;
21
- *
22
- * This is the DOM twin of `cli/src/diffview.js`: same structure decisions, same
23
- * tokenizer, but it builds real element nodes instead of ANSI strings. Small
24
- * diffs open themselves (AUTO_OPEN_ROWS) so the common one-line edit is
25
- * readable with no gesture at all; anything bigger starts collapsed so a
26
- * 300-line rewrite cannot bury the transcript.
27
- *
28
- * Every piece of text goes in through `textContent`/`createTextNode` and never
29
- * `innerHTML` — a diff's content is arbitrary file bytes, so the one thing this
30
- * module must never do is let a line like `<img src=x onerror=…>` become live
31
- * markup.
32
- */
33
-
34
- /** Diff body rows at or below this size open without a gesture. */
35
- const AUTO_OPEN_ROWS = 30;
36
- /** Rows painted inside one open block before the "… more diff lines" footer. */
37
- const MAX_BLOCK_ROWS = 200;
38
-
39
- // The Monokai Extended diff palette, copied from cli/src/theme.js's DIFF so the
40
- // desktop block and the CLI block read as the same object.
41
- const DIFF_COLORS = {
42
- delFg: '#dc5a5a',
43
- delBg: '#3d0100',
44
- addFg: '#50c850',
45
- addBg: '#022800',
46
- delHiFg: '#f8f8f2',
47
- delHiBg: '#5c0200',
48
- addHiFg: '#ffffff',
49
- addHiBg: '#044700',
50
- codeFg: '#f8f8f2',
51
- gutter: '#787878',
52
- kind: '#c099ff',
53
- kw: '#66d9ef',
54
- fn: '#a6e22e',
55
- str: '#e6db74',
56
- num: '#ae81ff',
57
- comment: '#75715e',
58
- };
59
-
60
- const KEYWORDS = new Set([
61
- 'const', 'let', 'var', 'function', 'return', 'if', 'else', 'for', 'while', 'do', 'switch',
62
- 'case', 'break', 'continue', 'import', 'export', 'from', 'default', 'class', 'extends',
63
- 'new', 'try', 'catch', 'finally', 'throw', 'async', 'await', 'yield', 'static', 'typeof',
64
- 'instanceof', 'in', 'of', 'delete', 'this', 'super', 'null', 'undefined', 'true', 'false',
65
- 'def', 'elif', 'lambda', 'pass', 'raise', 'with', 'as', 'not', 'and', 'or', 'is', 'None',
66
- 'True', 'False', 'self', 'fn', 'mut', 'pub', 'impl', 'struct', 'enum', 'trait', 'match',
67
- 'package', 'func', 'defer', 'chan', 'nil', 'echo', 'local', 'then', 'fi', 'esac',
68
- ]);
69
-
70
- /**
71
- * Split one line of code into colored tokens. Deliberately line-local and cheap
72
- * — it runs on every changed row of every block — so it colors comments,
73
- * strings, numbers, keywords and called functions and leaves the rest plain,
74
- * which is all the tinted diff rows need to read as code.
75
- *
76
- * @param {string} text
77
- * @param {object} [d] Diff palette (defaults to the dark one).
78
- * @returns {Array<{t: string, c: string}>} tokens; `c` is a foreground color.
79
- */
80
- function highlightLine(text, d) {
81
- const D = d || DIFF_COLORS;
82
- const out = [];
83
- const src = String(text == null ? '' : text);
84
- const re = /(\/\/[^\n]*|#[^\n]*|\/\*[\s\S]*?\*\/)|('(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"|`(?:\\.|[^`\\])*`)|(0[xX][0-9a-fA-F]+|\d+(?:\.\d+)?)|([A-Za-z_$][A-Za-z0-9_$]*)/g;
85
- const push = (t, c) => { if (t) out.push({ t, c }); };
86
- let last = 0;
87
- let m;
88
- while ((m = re.exec(src))) {
89
- if (m.index > last) push(src.slice(last, m.index), D.codeFg);
90
- if (m[1]) push(m[1], D.comment);
91
- else if (m[2]) push(m[2], D.str);
92
- else if (m[3]) push(m[3], D.num);
93
- else {
94
- const word = m[4];
95
- const isCall = /^\s*\(/.test(src.slice(m.index + word.length));
96
- push(word, KEYWORDS.has(word) ? D.kw : isCall ? D.fn : D.codeFg);
97
- }
98
- last = m.index + m[0].length;
99
- }
100
- if (last < src.length) push(src.slice(last), D.codeFg);
101
- return out;
102
- }
103
-
104
- /**
105
- * Pair a run of removed rows with the added run that follows it and mark the
106
- * slice that actually differs, so the changed word renders in the bright
107
- * variant of the diff color. Equal run lengths only, and only when the shared
108
- * prefix+suffix dominates the line — otherwise the mark would land on
109
- * unrelated text. Mutates rows in place, adding `hi = {start, end, side}` in
110
- * code-point offsets.
111
- */
112
- function markIntraLine(rows) {
113
- for (let i = 0; i < rows.length; i++) {
114
- if (rows[i].sign !== '-') continue;
115
- let d = i;
116
- while (d < rows.length && rows[d].sign === '-') d++;
117
- let a = d;
118
- while (a < rows.length && rows[a].sign === '+') a++;
119
- const delCount = d - i;
120
- const addCount = a - d;
121
- if (delCount && delCount === addCount) {
122
- for (let k = 0; k < delCount; k++) {
123
- const pair = intraLine(rows[i + k].text, rows[d + k].text);
124
- if (!pair) continue;
125
- rows[i + k].hi = { start: pair.delStart, end: pair.delEnd, side: 'del' };
126
- rows[d + k].hi = { start: pair.addStart, end: pair.addEnd, side: 'add' };
127
- }
128
- }
129
- i = a - 1;
130
- }
131
- return rows;
132
- }
133
-
134
- function intraLine(delText, addText) {
135
- const d = [...String(delText == null ? '' : delText)];
136
- const a = [...String(addText == null ? '' : addText)];
137
- let pre = 0;
138
- while (pre < d.length && pre < a.length && d[pre] === a[pre]) pre++;
139
- let post = 0;
140
- while (post < d.length - pre && post < a.length - pre && d[d.length - 1 - post] === a[a.length - 1 - post]) post++;
141
- const shared = pre + post;
142
- const longest = Math.max(d.length, a.length) || 1;
143
- if (shared < longest * 0.4) return null;
144
- return {
145
- delStart: pre,
146
- delEnd: d.length - post,
147
- addStart: pre,
148
- addEnd: a.length - post,
149
- };
150
- }
151
-
152
- /**
153
- * Should this preview start open? Small diffs (the routine edit) do, so the
154
- * change is readable immediately; a big one stays a one-line summary.
155
- */
156
- function defaultOpen(preview) {
157
- if (!preview || !preview.rows) return false;
158
- return preview.rows.length <= AUTO_OPEN_ROWS;
159
- }
160
-
161
- /** One colored span. `bg` set means this is an intra-line highlight slice. */
162
- function tokenSpan(document, text, color, bg, fg) {
163
- const span = document.createElement('span');
164
- if (bg) {
165
- span.style.background = bg;
166
- span.style.color = fg;
167
- } else {
168
- span.style.color = color;
169
- }
170
- span.textContent = String(text);
171
- return span;
172
- }
173
-
174
- /** A single colored code/highlight fragment inside a row's `.diff-code`. */
175
- function appendCode(document, container, text, hi) {
176
- const src = String(text == null ? '' : text);
177
- let idx = 0;
178
- for (const tk of highlightLine(src, DIFF_COLORS)) {
179
- const chars = [...tk.t];
180
- const start = idx;
181
- const end = idx + chars.length;
182
- idx = end;
183
- if (!hi || end <= hi.start || start >= hi.end) {
184
- container.appendChild(tokenSpan(document, tk.t, tk.c));
185
- continue;
186
- }
187
- const a = Math.max(hi.start, start) - start;
188
- const b = Math.min(hi.end, end) - start;
189
- if (a > 0) container.appendChild(tokenSpan(document, chars.slice(0, a).join(''), tk.c));
190
- if (b > a) {
191
- const bg = hi.side === 'del' ? DIFF_COLORS.delHiBg : DIFF_COLORS.addHiBg;
192
- const fg = hi.side === 'del' ? DIFF_COLORS.delHiFg : DIFF_COLORS.addHiFg;
193
- container.appendChild(tokenSpan(document, chars.slice(a, b).join(''), null, bg, fg));
194
- }
195
- if (b < chars.length) container.appendChild(tokenSpan(document, chars.slice(b).join(''), tk.c));
196
- }
197
- }
198
-
199
- /** One `<div class="diff-row diff-add|diff-del|diff-ctx">` with gutter + tokens. */
200
- function renderRow(document, r, gutterW) {
201
- const side = r.sign === '-' ? 'del' : r.sign === '+' ? 'add' : 'ctx';
202
- const row = document.createElement('div');
203
- row.className = `diff-row diff-${side}`;
204
-
205
- const gutter = document.createElement('span');
206
- gutter.className = 'diff-gutter';
207
- gutter.textContent = `${String(r.no == null ? '' : r.no).padStart(gutterW)} `;
208
- row.appendChild(gutter);
209
-
210
- const sign = document.createElement('span');
211
- sign.className = 'diff-sign';
212
- sign.textContent = r.sign === ' ' ? ' ' : r.sign;
213
- row.appendChild(sign);
214
-
215
- const code = document.createElement('span');
216
- code.className = 'diff-code';
217
- appendCode(document, code, r.text, r.hi);
218
- row.appendChild(code);
219
-
220
- return row;
221
- }
222
-
223
- /** A collapsed-context / truncation row: `.diff-marker`. */
224
- function markerRow(document, note) {
225
- const row = document.createElement('div');
226
- row.className = 'diff-row diff-marker';
227
- const code = document.createElement('span');
228
- code.className = 'diff-code';
229
- code.textContent = String(note == null ? '' : note);
230
- row.appendChild(code);
231
- return row;
232
- }
233
-
234
- /**
235
- * Build the collapsible diff block for one edit preview.
236
- *
237
- * @param {object} preview From diff.js's editPreview(). Falsy → null.
238
- * @param {Document} doc The document (injectable so tests need no jsdom).
239
- * @param {{open?: boolean}} [opts] `open` overrides the AUTO_OPEN_ROWS default.
240
- * @returns {HTMLElement|null} `div.diff-block` with a clickable `.diff-summary`.
241
- */
242
- function renderDiffBlock(preview, doc, opts = {}) {
243
- const document = doc || (typeof document !== 'undefined' ? document : null);
244
- if (!document || !preview || !preview.rows) return null;
245
- let open = opts.open == null ? defaultOpen(preview) : !!opts.open;
246
-
247
- const block = document.createElement('div');
248
- block.className = 'diff-block';
249
-
250
- const summary = document.createElement('div');
251
- summary.className = 'diff-summary';
252
- if (typeof summary.setAttribute === 'function') {
253
- summary.setAttribute('role', 'button');
254
- summary.setAttribute('aria-expanded', String(open));
255
- }
256
-
257
- const body = document.createElement('div');
258
- body.className = 'diff-body';
259
-
260
- /**
261
- * Repaint just the summary's text segments. Called on every toggle so the
262
- * "click to view/collapse" hint and aria-expanded always match the state.
263
- */
264
- function paintSummary() {
265
- summary.textContent = '';
266
- const segs = [
267
- { t: '⎿ ', c: DIFF_COLORS.gutter },
268
- { t: `${preview.kind}(${preview.short})`, c: DIFF_COLORS.kind },
269
- ];
270
- if (preview.adds) segs.push({ t: ` +${preview.adds}`, c: DIFF_COLORS.addFg });
271
- if (preview.dels) segs.push({ t: ` -${preview.dels}`, c: DIFF_COLORS.delFg });
272
- if (!preview.adds && !preview.dels) segs.push({ t: ' no line changes', c: DIFF_COLORS.gutter });
273
- if (preview.misses) segs.push({ t: ` ${preview.misses} edit(s) not applied`, c: '#ffd166' });
274
- segs.push({ t: ` ${open ? '· click to collapse' : '· click to view diff'}`, c: DIFF_COLORS.comment });
275
- for (const s of segs) {
276
- const span = document.createElement('span');
277
- span.style.color = s.c;
278
- span.textContent = s.t;
279
- summary.appendChild(span);
280
- }
281
- if (typeof summary.setAttribute === 'function') summary.setAttribute('aria-expanded', String(open));
282
- }
283
-
284
- /** Repaint the body rows. Nothing is built while collapsed. */
285
- function paintBody() {
286
- body.textContent = '';
287
- if (!open) return;
288
- const rows = markIntraLine(
289
- preview.rows.slice(0, MAX_BLOCK_ROWS).map((r) => Object.assign({}, r)),
290
- );
291
- let maxNo = 1;
292
- for (const r of rows) if (r.no && r.no > maxNo) maxNo = r.no;
293
- const gutterW = Math.max(2, String(maxNo).length);
294
- for (const r of rows) {
295
- if (r.marker) body.appendChild(markerRow(document, r.note));
296
- else body.appendChild(renderRow(document, r, gutterW));
297
- }
298
- const hidden = preview.rows.length - MAX_BLOCK_ROWS;
299
- if (hidden > 0) body.appendChild(markerRow(document, `… ${hidden} more diff lines`));
300
- if (preview.truncated) {
301
- body.appendChild(markerRow(document, '… diff truncated (file too large to compare in full)'));
302
- }
303
- }
304
-
305
- /** The whole point: clicking the summary flips the one block's open state. */
306
- function toggle() {
307
- open = !open;
308
- paintSummary();
309
- paintBody();
310
- }
311
- if (typeof summary.addEventListener === 'function') {
312
- summary.addEventListener('click', toggle);
313
- summary.addEventListener('keydown', (e) => {
314
- if (e && (e.key === 'Enter' || e.key === ' ')) {
315
- if (typeof e.preventDefault === 'function') e.preventDefault();
316
- toggle();
317
- }
318
- });
319
- }
320
-
321
- paintSummary();
322
- paintBody();
323
- block.appendChild(summary);
324
- block.appendChild(body);
325
- return block;
326
- }
327
-
328
- if (typeof module !== 'undefined' && module.exports) {
329
- module.exports = {
330
- AUTO_OPEN_ROWS,
331
- MAX_BLOCK_ROWS,
332
- DIFF_COLORS,
333
- defaultOpen,
334
- highlightLine,
335
- markIntraLine,
336
- renderDiffBlock,
337
- };
338
- }
3
+ "use strict";const AUTO_OPEN_ROWS=30,MAX_BLOCK_ROWS=200,DIFF_COLORS={delFg:"#dc5a5a",delBg:"#3d0100",addFg:"#50c850",addBg:"#022800",delHiFg:"#f8f8f2",delHiBg:"#5c0200",addHiFg:"#ffffff",addHiBg:"#044700",codeFg:"#f8f8f2",gutter:"#787878",kind:"#c099ff",kw:"#66d9ef",fn:"#a6e22e",str:"#e6db74",num:"#ae81ff",comment:"#75715e"},KEYWORDS=new Set(["const","let","var","function","return","if","else","for","while","do","switch","case","break","continue","import","export","from","default","class","extends","new","try","catch","finally","throw","async","await","yield","static","typeof","instanceof","in","of","delete","this","super","null","undefined","true","false","def","elif","lambda","pass","raise","with","as","not","and","or","is","None","True","False","self","fn","mut","pub","impl","struct","enum","trait","match","package","func","defer","chan","nil","echo","local","then","fi","esac"]);function highlightLine(e,t){const n=t||DIFF_COLORS,i=[],d=String(null==e?"":e),l=/(\/\/[^\n]*|#[^\n]*|\/\*[\s\S]*?\*\/)|('(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"|`(?:\\.|[^`\\])*`)|(0[xX][0-9a-fA-F]+|\d+(?:\.\d+)?)|([A-Za-z_$][A-Za-z0-9_$]*)/g,a=(e,t)=>{e&&i.push({t:e,c:t})};let o,s=0;for(;o=l.exec(d);){if(o.index>s&&a(d.slice(s,o.index),n.codeFg),o[1])a(o[1],n.comment);else if(o[2])a(o[2],n.str);else if(o[3])a(o[3],n.num);else{const e=o[4],t=/^\s*\(/.test(d.slice(o.index+e.length));a(e,KEYWORDS.has(e)?n.kw:t?n.fn:n.codeFg)}s=o.index+o[0].length}return s<d.length&&a(d.slice(s),n.codeFg),i}function markIntraLine(e){for(let t=0;t<e.length;t++){if("-"!==e[t].sign)continue;let n=t;for(;n<e.length&&"-"===e[n].sign;)n++;let i=n;for(;i<e.length&&"+"===e[i].sign;)i++;const d=n-t;if(d&&d===i-n)for(let i=0;i<d;i++){const d=intraLine(e[t+i].text,e[n+i].text);d&&(e[t+i].hi={start:d.delStart,end:d.delEnd,side:"del"},e[n+i].hi={start:d.addStart,end:d.addEnd,side:"add"})}t=i-1}return e}function intraLine(e,t){const n=[...String(null==e?"":e)],i=[...String(null==t?"":t)];let d=0;for(;d<n.length&&d<i.length&&n[d]===i[d];)d++;let l=0;for(;l<n.length-d&&l<i.length-d&&n[n.length-1-l]===i[i.length-1-l];)l++;return d+l<.4*(Math.max(n.length,i.length)||1)?null:{delStart:d,delEnd:n.length-l,addStart:d,addEnd:i.length-l}}function defaultOpen(e){return!(!e||!e.rows)&&e.rows.length<=AUTO_OPEN_ROWS}function tokenSpan(e,t,n,i,d){const l=e.createElement("span");return i?(l.style.background=i,l.style.color=d):l.style.color=n,l.textContent=String(t),l}function appendCode(e,t,n,i){const d=String(null==n?"":n);let l=0;for(const n of highlightLine(d,DIFF_COLORS)){const d=[...n.t],a=l,o=l+d.length;if(l=o,!i||o<=i.start||a>=i.end){t.appendChild(tokenSpan(e,n.t,n.c));continue}const s=Math.max(i.start,a)-a,r=Math.min(i.end,o)-a;if(s>0&&t.appendChild(tokenSpan(e,d.slice(0,s).join(""),n.c)),r>s){const n="del"===i.side?DIFF_COLORS.delHiBg:DIFF_COLORS.addHiBg,l="del"===i.side?DIFF_COLORS.delHiFg:DIFF_COLORS.addHiFg;t.appendChild(tokenSpan(e,d.slice(s,r).join(""),null,n,l))}r<d.length&&t.appendChild(tokenSpan(e,d.slice(r).join(""),n.c))}}function renderRow(e,t,n){const i="-"===t.sign?"del":"+"===t.sign?"add":"ctx",d=e.createElement("div");d.className=`diff-row diff-${i}`;const l=e.createElement("span");l.className="diff-gutter",l.textContent=`${String(null==t.no?"":t.no).padStart(n)} `,d.appendChild(l);const a=e.createElement("span");a.className="diff-sign",a.textContent=" "===t.sign?" ":t.sign,d.appendChild(a);const o=e.createElement("span");return o.className="diff-code",appendCode(e,o,t.text,t.hi),d.appendChild(o),d}function markerRow(e,t){const n=e.createElement("div");n.className="diff-row diff-marker";const i=e.createElement("span");return i.className="diff-code",i.textContent=String(null==t?"":t),n.appendChild(i),n}function renderDiffBlock(e,t,n={}){const i=t||(void 0!==i?i:null);if(!i||!e||!e.rows)return null;let d=null==n.open?defaultOpen(e):!!n.open;const l=i.createElement("div");l.className="diff-block";const a=i.createElement("div");a.className="diff-summary","function"==typeof a.setAttribute&&(a.setAttribute("role","button"),a.setAttribute("aria-expanded",String(d)));const o=i.createElement("div");function s(){a.textContent="";const t=[{t:"⎿ ",c:DIFF_COLORS.gutter},{t:`${e.kind}(${e.short})`,c:DIFF_COLORS.kind}];e.adds&&t.push({t:` +${e.adds}`,c:DIFF_COLORS.addFg}),e.dels&&t.push({t:` -${e.dels}`,c:DIFF_COLORS.delFg}),e.adds||e.dels||t.push({t:" no line changes",c:DIFF_COLORS.gutter}),e.misses&&t.push({t:` ${e.misses} edit(s) not applied`,c:"#ffd166"}),t.push({t:" "+(d?"· click to collapse":"· click to view diff"),c:DIFF_COLORS.comment});for(const e of t){const t=i.createElement("span");t.style.color=e.c,t.textContent=e.t,a.appendChild(t)}"function"==typeof a.setAttribute&&a.setAttribute("aria-expanded",String(d))}function r(){if(o.textContent="",!d)return;const t=markIntraLine(e.rows.slice(0,200).map((e=>Object.assign({},e))));let n=1;for(const e of t)e.no&&e.no>n&&(n=e.no);const l=Math.max(2,String(n).length);for(const e of t)e.marker?o.appendChild(markerRow(i,e.note)):o.appendChild(renderRow(i,e,l));const a=e.rows.length-200;a>0&&o.appendChild(markerRow(i,`… ${a} more diff lines`)),e.truncated&&o.appendChild(markerRow(i,"… diff truncated (file too large to compare in full)"))}function c(){d=!d,s(),r()}return o.className="diff-body","function"==typeof a.addEventListener&&(a.addEventListener("click",c),a.addEventListener("keydown",(e=>{!e||"Enter"!==e.key&&" "!==e.key||("function"==typeof e.preventDefault&&e.preventDefault(),c())}))),s(),r(),l.appendChild(a),l.appendChild(o),l}"undefined"!=typeof module&&module.exports&&(module.exports={AUTO_OPEN_ROWS:AUTO_OPEN_ROWS,MAX_BLOCK_ROWS:200,DIFF_COLORS:DIFF_COLORS,defaultOpen:defaultOpen,highlightLine:highlightLine,markIntraLine:markIntraLine,renderDiffBlock:renderDiffBlock});