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.
- package/LICENSE +661 -0
- package/README.md +1 -1
- package/SOURCE-OFFER.txt +9 -0
- package/bin/aegis.js +1 -322
- package/package.json +4 -5
- package/scripts/bump.mjs +1 -211
- package/scripts/bundle.js +1 -129
- package/scripts/predist.mjs +1 -976
- package/src/child.js +1 -285
- package/src/dispatch.js +1 -269
- package/src/doctor.js +1 -639
- package/src/host.js +1 -111
- package/src/permissions.js +1 -383
- package/src/probes.js +1 -159
- package/src/release.js +1 -409
- package/vendor/cli/package.json +3 -7
- package/vendor/cli/scripts/check.mjs +1 -52
- package/vendor/cli/scripts/demo.mjs +1 -94
- package/vendor/cli/scripts/predist.mjs +1 -75
- package/vendor/cli/scripts/runtests.mjs +1 -56
- package/vendor/cli/scripts/seal-gate.mjs +1 -74
- package/vendor/cli/src/agents.js +1 -139
- package/vendor/cli/src/app.js +1 -2957
- package/vendor/cli/src/art.js +1 -289
- package/vendor/cli/src/chatflow.js +1 -3023
- package/vendor/cli/src/checkpoint.js +1 -90
- package/vendor/cli/src/clipboard.js +1 -424
- package/vendor/cli/src/cloudsync.js +1 -528
- package/vendor/cli/src/commands.js +1 -4089
- package/vendor/cli/src/config.js +1 -581
- package/vendor/cli/src/connect.js +1 -349
- package/vendor/cli/src/credentials.js +1 -33
- package/vendor/cli/src/deps.js +1 -232
- package/vendor/cli/src/devrun.js +1 -187
- package/vendor/cli/src/diff.js +1 -333
- package/vendor/cli/src/diffview.js +1 -296
- package/vendor/cli/src/engine.js +1 -297
- package/vendor/cli/src/entitlement.js +1 -355
- package/vendor/cli/src/events.js +1 -707
- package/vendor/cli/src/export.js +1 -67
- package/vendor/cli/src/filepreview.js +1 -153
- package/vendor/cli/src/fingerprint.js +1 -592
- package/vendor/cli/src/format.js +1 -259
- package/vendor/cli/src/fuzzy.js +1 -119
- package/vendor/cli/src/history.js +1 -423
- package/vendor/cli/src/init.js +1 -175
- package/vendor/cli/src/input.js +1 -139
- package/vendor/cli/src/keys.js +1 -183
- package/vendor/cli/src/markdown.js +1 -306
- package/vendor/cli/src/models.js +1 -507
- package/vendor/cli/src/naming.js +1 -57
- package/vendor/cli/src/overlays.js +1 -462
- package/vendor/cli/src/panels.js +1 -1418
- package/vendor/cli/src/ping.js +1 -226
- package/vendor/cli/src/presence.js +1 -238
- package/vendor/cli/src/render.js +1 -516
- package/vendor/cli/src/screen.js +1 -518
- package/vendor/cli/src/screens.js +1 -896
- package/vendor/cli/src/secret.js +1 -59
- package/vendor/cli/src/securefs.js +1 -359
- package/vendor/cli/src/settings.js +1 -155
- package/vendor/cli/src/shared.js +1 -52
- package/vendor/cli/src/sharedpaths.js +1 -53
- package/vendor/cli/src/signup.js +1 -156
- package/vendor/cli/src/summarize.js +1 -95
- package/vendor/cli/src/sysdiag.js +1 -585
- package/vendor/cli/src/system.js +1 -40
- package/vendor/cli/src/theme.js +1 -570
- package/vendor/cli/src/title.js +1 -220
- package/vendor/cli/src/todos.js +1 -115
- package/vendor/cli/src/tokens.js +1 -263
- package/vendor/cli/src/topup.js +1 -210
- package/vendor/cli/src/update.js +1 -191
- package/vendor/cli/vendor/client/aegis.js +1 -2441
- package/vendor/cli/vendor/client/attest.js +1 -518
- package/vendor/cli/vendor/client/authorship-key.js +1 -410
- package/vendor/cli/vendor/client/auto-provision.js +1 -134
- package/vendor/cli/vendor/client/brain-catalog.js +1 -268
- package/vendor/cli/vendor/client/byok-catalog.js +1 -199
- package/vendor/cli/vendor/client/catalog-client.js +1 -487
- package/vendor/cli/vendor/client/conversation-export.js +1 -177
- package/vendor/cli/vendor/client/credentials.js +1 -494
- package/vendor/cli/vendor/client/device-fingerprint.js +1 -141
- package/vendor/cli/vendor/client/drive-connect.js +1 -110
- package/vendor/cli/vendor/client/drive-upload.js +1 -234
- package/vendor/cli/vendor/client/env-file.js +1 -1273
- package/vendor/cli/vendor/client/fingerprint.js +1 -1064
- package/vendor/cli/vendor/client/foreign-memory.js +1 -669
- package/vendor/cli/vendor/client/google-signin.js +1 -133
- package/vendor/cli/vendor/client/hooks.js +1 -430
- package/vendor/cli/vendor/client/model-discovery.js +1 -373
- package/vendor/cli/vendor/client/naming.js +1 -283
- package/vendor/cli/vendor/client/platform.js +1 -937
- package/vendor/cli/vendor/client/prefs.js +1 -351
- package/vendor/cli/vendor/client/presence-constants.js +1 -107
- package/vendor/cli/vendor/client/presence.js +1 -438
- package/vendor/cli/vendor/client/record-vault.js +3 -1055
- package/vendor/cli/vendor/client/session-store.js +1 -575
- package/vendor/cli/vendor/client/topup.js +1 -297
- package/vendor/cli/vendor/client/touch.js +1 -458
- package/vendor/cli/vendor/client/update.js +1 -763
- package/vendor/cli/vendor/client/user-models.js +1 -381
- package/vendor/cli/vendor/desktop/lib/local/agents.js +1 -105
- package/vendor/cli/vendor/desktop/lib/local/attachments.js +1 -276
- package/vendor/cli/vendor/desktop/lib/local/autonomous.js +1 -1045
- package/vendor/cli/vendor/desktop/lib/local/claude-pro.js +1 -1028
- package/vendor/cli/vendor/desktop/lib/local/context.js +1 -125
- package/vendor/cli/vendor/desktop/lib/local/engine.js +1 -3666
- package/vendor/cli/vendor/desktop/lib/local/entitlement.js +1 -660
- package/vendor/cli/vendor/desktop/lib/local/git-scope.js +1 -228
- package/vendor/cli/vendor/desktop/lib/local/local.js +1 -2145
- package/vendor/cli/vendor/desktop/lib/local/prompt.js +1 -280
- package/vendor/cli/vendor/desktop/lib/local/queue.js +1 -560
- package/vendor/cli/vendor/desktop/lib/local/session-rounds.js +1 -238
- package/vendor/cli/vendor/desktop/lib/local/spill.js +1 -75
- package/vendor/cli/vendor/desktop/lib/local/turn-guard.js +1 -300
- package/vendor/cli/vendor/desktop/lib/local/worktree-lock.js +1 -235
- package/vendor/cli/vendor/desktop/lib/settings.js +1 -890
- package/vendor/cli/vendor/desktop/renderer/usage.js +1 -1239
- package/vendor/cli/vendor/hosts/install.js +1 -638
- package/vendor/cli/vendor/hosts/openai-shim.js +1 -515
- package/vendor/cli/vendor/hosts/spec.js +1 -164
- package/vendor/cli/vendor/hosts/targets.js +1 -346
- package/vendor/cli/vendor/mcp/server.js +1 -221
- package/vendor/cli/vendor/mcp/tools.js +1 -408
- package/vendor/cli/vendor/one/src/child.js +1 -285
- package/vendor/cli/vendor/one/src/permissions.js +1 -383
- package/vendor/desktop/bin/aegis.js +1 -32
- package/vendor/desktop/lib/account-key.js +1 -56
- package/vendor/desktop/lib/auto.js +1 -461
- package/vendor/desktop/lib/avatar/companion.js +1 -698
- package/vendor/desktop/lib/avatar/cosmetics.js +1 -532
- package/vendor/desktop/lib/avatar/events.js +1 -344
- package/vendor/desktop/lib/avatar/holder-turn.js +1 -350
- package/vendor/desktop/lib/avatar/holders.js +1 -612
- package/vendor/desktop/lib/avatar/identity.js +1 -641
- package/vendor/desktop/lib/avatar/level.js +1 -368
- package/vendor/desktop/lib/avatar/mirror.js +1 -524
- package/vendor/desktop/lib/avatar/persona.js +1 -388
- package/vendor/desktop/lib/avatar/profile.js +1 -977
- package/vendor/desktop/lib/avatar/register.js +1 -307
- package/vendor/desktop/lib/avatar/store.js +1 -472
- package/vendor/desktop/lib/avatar/tiers.js +1 -38
- package/vendor/desktop/lib/avatar/transfer.js +1 -415
- package/vendor/desktop/lib/avatar/turn.js +1 -216
- package/vendor/desktop/lib/avatar/voice.js +1 -328
- package/vendor/desktop/lib/avatar/xp.js +1 -404
- package/vendor/desktop/lib/deep-link.js +1 -120
- package/vendor/desktop/lib/fingerprint.js +2 -347
- package/vendor/desktop/lib/google-connect.js +1 -323
- package/vendor/desktop/lib/local/agents.js +1 -105
- package/vendor/desktop/lib/local/attachments.js +1 -276
- package/vendor/desktop/lib/local/autonomous.js +1 -1045
- package/vendor/desktop/lib/local/claude-pro.js +1 -1028
- package/vendor/desktop/lib/local/context.js +1 -125
- package/vendor/desktop/lib/local/engine.js +1 -3666
- package/vendor/desktop/lib/local/entitlement.js +1 -660
- package/vendor/desktop/lib/local/git-scope.js +1 -228
- package/vendor/desktop/lib/local/local.js +1 -2145
- package/vendor/desktop/lib/local/prompt.js +1 -280
- package/vendor/desktop/lib/local/queue.js +1 -560
- package/vendor/desktop/lib/local/session-rounds.js +1 -238
- package/vendor/desktop/lib/local/spill.js +1 -75
- package/vendor/desktop/lib/local/telemetry.js +1 -470
- package/vendor/desktop/lib/local/turn-guard.js +1 -300
- package/vendor/desktop/lib/local/worktree-lock.js +1 -235
- package/vendor/desktop/lib/provider-key-mirror.js +1 -252
- package/vendor/desktop/lib/quick-launcher.js +1 -84
- package/vendor/desktop/lib/settings.js +1 -890
- package/vendor/desktop/lib/sync/memory-queue.js +1 -60
- package/vendor/desktop/lib/sync/persist-gate.js +1 -148
- package/vendor/desktop/lib/sync/sessions.js +1 -106
- package/vendor/desktop/lib/window-state.js +1 -66
- package/vendor/desktop/package.json +2 -4
- package/vendor/desktop/preload.js +1 -679
- package/vendor/desktop/renderer/app.js +1 -7250
- package/vendor/desktop/renderer/avatar/assemble.js +1 -335
- package/vendor/desktop/renderer/avatar/avatar.js +1 -380
- package/vendor/desktop/renderer/avatar/cards.js +1 -141
- package/vendor/desktop/renderer/avatar/hud.js +1 -206
- package/vendor/desktop/renderer/avatar/machine.js +1 -213
- package/vendor/desktop/renderer/avatar/pane.js +1 -439
- package/vendor/desktop/renderer/avatar/parts.js +1 -437
- package/vendor/desktop/renderer/budget.js +1 -172
- package/vendor/desktop/renderer/companion.js +1 -223
- package/vendor/desktop/renderer/diff.js +1 -359
- package/vendor/desktop/renderer/diffview.js +1 -336
- package/vendor/desktop/renderer/filepreview.js +1 -211
- package/vendor/desktop/renderer/fingerprint.js +3 -789
- package/vendor/desktop/renderer/markdown.js +1 -168
- package/vendor/desktop/renderer/provider-mark.js +1 -311
- package/vendor/desktop/renderer/provider-toolbar.js +1 -134
- package/vendor/desktop/renderer/providers.js +1 -259
- package/vendor/desktop/renderer/quick.js +1 -285
- package/vendor/desktop/renderer/stream-policy.js +1 -387
- package/vendor/desktop/renderer/transcript-view.js +1 -323
- package/vendor/desktop/renderer/usage.js +1 -1239
- package/vendor/desktop/vendor/aegis.js +1 -2441
- package/vendor/desktop/vendor/attest.js +1 -518
- package/vendor/desktop/vendor/authorship-key.js +1 -410
- package/vendor/desktop/vendor/auto-provision.js +1 -134
- package/vendor/desktop/vendor/brain-catalog.js +1 -268
- package/vendor/desktop/vendor/byok-catalog.js +1 -199
- package/vendor/desktop/vendor/catalog-client.js +1 -487
- package/vendor/desktop/vendor/conversation-export.js +1 -177
- package/vendor/desktop/vendor/credentials.js +1 -494
- package/vendor/desktop/vendor/device-fingerprint.js +1 -141
- package/vendor/desktop/vendor/drive-connect.js +1 -110
- package/vendor/desktop/vendor/drive-upload.js +1 -234
- package/vendor/desktop/vendor/env-file.js +1 -1273
- package/vendor/desktop/vendor/fingerprint.js +1 -1064
- package/vendor/desktop/vendor/foreign-memory.js +1 -669
- package/vendor/desktop/vendor/google-signin.js +1 -133
- package/vendor/desktop/vendor/hooks.js +1 -430
- package/vendor/desktop/vendor/model-discovery.js +1 -373
- package/vendor/desktop/vendor/naming.js +1 -283
- package/vendor/desktop/vendor/platform.js +1 -937
- package/vendor/desktop/vendor/prefs.js +1 -351
- package/vendor/desktop/vendor/presence-constants.js +1 -107
- package/vendor/desktop/vendor/presence.js +1 -438
- package/vendor/desktop/vendor/record-vault.js +3 -1055
- package/vendor/desktop/vendor/session-store.js +1 -575
- package/vendor/desktop/vendor/topup.js +1 -297
- package/vendor/desktop/vendor/touch.js +1 -458
- package/vendor/desktop/vendor/update.js +1 -763
- 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
|
-
|
|
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});
|
|
@@ -1,213 +1,3 @@
|
|
|
1
1
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
2
|
// Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
|
|
3
|
-
|
|
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
|
-
* File preview cards for Write operations in the desktop app.
|
|
10
|
-
*
|
|
11
|
-
* Renders a collapsible file preview card showing the first N lines of
|
|
12
|
-
* newly written files with syntax highlighting and line numbers.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
// Every renderer script is a CLASSIC script (index.html loads them without
|
|
16
|
-
// `type="module"`), so they all share one global lexical scope. `diff.js`
|
|
17
|
-
// already declares a top-level `path`, and a second top-level `path` here is a
|
|
18
|
-
// redeclaration that throws "Identifier 'path' has already been declared" —
|
|
19
|
-
// which killed this whole file at load and left every preview call site with no
|
|
20
|
-
// API. The name is local and namespaced instead.
|
|
21
|
-
const previewPath = typeof require === 'function' ? require('node:path') : null;
|
|
22
|
-
|
|
23
|
-
// Max lines to show in preview (collapsed)
|
|
24
|
-
const PREVIEW_LINES = 8;
|
|
25
|
-
// Namespaced for the same reason as `previewPath` above: classic scripts share
|
|
26
|
-
// one global scope, and `diffview.js` already owns a top-level AUTO_OPEN_ROWS.
|
|
27
|
-
// A second declaration is a SyntaxError that kills this whole file.
|
|
28
|
-
const PREVIEW_AUTO_OPEN_ROWS = 30;
|
|
29
|
-
|
|
30
|
-
/** Language detection by file extension */
|
|
31
|
-
const LANGUAGE_BY_EXT = {
|
|
32
|
-
'.js': 'javascript',
|
|
33
|
-
'.ts': 'typescript',
|
|
34
|
-
'.tsx': 'typescript',
|
|
35
|
-
'.jsx': 'javascript',
|
|
36
|
-
'.py': 'python',
|
|
37
|
-
'.rb': 'ruby',
|
|
38
|
-
'.go': 'go',
|
|
39
|
-
'.rs': 'rust',
|
|
40
|
-
'.java': 'java',
|
|
41
|
-
'.c': 'c',
|
|
42
|
-
'.cpp': 'cpp',
|
|
43
|
-
'.h': 'c',
|
|
44
|
-
'.hpp': 'cpp',
|
|
45
|
-
'.cs': 'csharp',
|
|
46
|
-
'.php': 'php',
|
|
47
|
-
'.html': 'html',
|
|
48
|
-
'.htm': 'html',
|
|
49
|
-
'.css': 'css',
|
|
50
|
-
'.scss': 'scss',
|
|
51
|
-
'.json': 'json',
|
|
52
|
-
'.yaml': 'yaml',
|
|
53
|
-
'.yml': 'yaml',
|
|
54
|
-
'.xml': 'xml',
|
|
55
|
-
'.md': 'markdown',
|
|
56
|
-
'.sh': 'bash',
|
|
57
|
-
'.bash': 'bash',
|
|
58
|
-
'.sql': 'sql',
|
|
59
|
-
'.lua': 'lua',
|
|
60
|
-
'.swift': 'swift',
|
|
61
|
-
'.kt': 'kotlin',
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Extract file preview from content.
|
|
66
|
-
* @param {string} file File path
|
|
67
|
-
* @param {string} content File content
|
|
68
|
-
* @param {number} [maxLines] Max lines to show
|
|
69
|
-
* @returns {object|null} Preview object or null
|
|
70
|
-
*/
|
|
71
|
-
function extractPreview(file, content, maxLines = PREVIEW_LINES) {
|
|
72
|
-
if (!file || typeof content !== 'string') return null;
|
|
73
|
-
|
|
74
|
-
const ext = previewPath
|
|
75
|
-
? previewPath.extname(file).toLowerCase()
|
|
76
|
-
: file.match(/\.[^.]*$/)?.[0]?.toLowerCase() || '';
|
|
77
|
-
const language = LANGUAGE_BY_EXT[ext] || '';
|
|
78
|
-
|
|
79
|
-
const allLines = content.split('\n');
|
|
80
|
-
const truncated = allLines.length > maxLines;
|
|
81
|
-
const previewLines = allLines.slice(0, maxLines);
|
|
82
|
-
|
|
83
|
-
return {
|
|
84
|
-
file,
|
|
85
|
-
language,
|
|
86
|
-
lines: previewLines,
|
|
87
|
-
totalLines: allLines.length,
|
|
88
|
-
truncated,
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Extract new file content from Write/Edit args.
|
|
94
|
-
*/
|
|
95
|
-
function extractNewContent(toolName, args) {
|
|
96
|
-
if (!args || typeof args !== 'object') return null;
|
|
97
|
-
|
|
98
|
-
if (toolName === 'Write' || toolName === 'writeFile') {
|
|
99
|
-
return args.content;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (toolName === 'Edit' || toolName === 'editFile') {
|
|
103
|
-
return null; // Show diff instead for edits
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Render a file preview card as a DOM element.
|
|
111
|
-
* @param {object} preview Preview object from extractPreview()
|
|
112
|
-
* @param {function} onViewFull Callback when "View Full" is clicked
|
|
113
|
-
* @returns {HTMLElement} Card element
|
|
114
|
-
*/
|
|
115
|
-
function renderFilePreviewCard(preview, onViewFull) {
|
|
116
|
-
if (!preview) return null;
|
|
117
|
-
|
|
118
|
-
const container = document.createElement('div');
|
|
119
|
-
container.className = 'file-preview-card';
|
|
120
|
-
|
|
121
|
-
// Header with file path and line count
|
|
122
|
-
const header = document.createElement('div');
|
|
123
|
-
header.className = 'file-preview-header';
|
|
124
|
-
header.innerHTML = `
|
|
125
|
-
<div class="file-preview-path">
|
|
126
|
-
<span class="file-preview-icon">📄</span>
|
|
127
|
-
<span class="file-preview-name">${escapeHtml(preview.file)}</span>
|
|
128
|
-
<span class="file-preview-meta">${preview.totalLines} line${preview.totalLines === 1 ? '' : 's'}</span>
|
|
129
|
-
</div>
|
|
130
|
-
`;
|
|
131
|
-
|
|
132
|
-
// Content lines with line numbers
|
|
133
|
-
const content = document.createElement('div');
|
|
134
|
-
content.className = 'file-preview-content';
|
|
135
|
-
|
|
136
|
-
const gutterWidth = String(preview.totalLines).length;
|
|
137
|
-
for (let i = 0; i < preview.lines.length; i++) {
|
|
138
|
-
const lineNo = i + 1;
|
|
139
|
-
const text = preview.lines[i] || '';
|
|
140
|
-
|
|
141
|
-
const line = document.createElement('div');
|
|
142
|
-
line.className = 'file-preview-line';
|
|
143
|
-
|
|
144
|
-
const gutter = document.createElement('span');
|
|
145
|
-
gutter.className = 'file-preview-gutter';
|
|
146
|
-
gutter.textContent = String(lineNo).padStart(gutterWidth, ' ');
|
|
147
|
-
|
|
148
|
-
const lineContent = document.createElement('span');
|
|
149
|
-
lineContent.className = 'file-preview-line-text';
|
|
150
|
-
lineContent.textContent = text;
|
|
151
|
-
|
|
152
|
-
line.appendChild(gutter);
|
|
153
|
-
line.appendChild(lineContent);
|
|
154
|
-
content.appendChild(line);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// Footer with view full button or truncation notice
|
|
158
|
-
const footer = document.createElement('div');
|
|
159
|
-
footer.className = 'file-preview-footer';
|
|
160
|
-
|
|
161
|
-
if (preview.truncated) {
|
|
162
|
-
const remaining = preview.totalLines - preview.lines.length;
|
|
163
|
-
const notice = document.createElement('span');
|
|
164
|
-
notice.className = 'file-preview-notice';
|
|
165
|
-
notice.textContent = `${remaining} more line${remaining === 1 ? '' : 's'}`;
|
|
166
|
-
|
|
167
|
-
const button = document.createElement('button');
|
|
168
|
-
button.className = 'file-preview-button';
|
|
169
|
-
button.textContent = 'View Full';
|
|
170
|
-
button.onclick = (e) => {
|
|
171
|
-
e.stopPropagation();
|
|
172
|
-
if (onViewFull) onViewFull(preview);
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
footer.appendChild(notice);
|
|
176
|
-
footer.appendChild(button);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
container.appendChild(header);
|
|
180
|
-
container.appendChild(content);
|
|
181
|
-
if (preview.truncated) container.appendChild(footer);
|
|
182
|
-
|
|
183
|
-
return container;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Helper to escape HTML special characters.
|
|
188
|
-
*/
|
|
189
|
-
function escapeHtml(text) {
|
|
190
|
-
const div = document.createElement('div');
|
|
191
|
-
div.textContent = text;
|
|
192
|
-
return div.innerHTML;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// Expose for browser context (loaded as classic script in index.html)
|
|
196
|
-
if (typeof window !== 'undefined') {
|
|
197
|
-
window.extractPreview = extractPreview;
|
|
198
|
-
window.extractNewContent = extractNewContent;
|
|
199
|
-
window.renderFilePreviewCard = renderFilePreviewCard;
|
|
200
|
-
window.PREVIEW_LINES = PREVIEW_LINES;
|
|
201
|
-
window.PREVIEW_AUTO_OPEN_ROWS = PREVIEW_AUTO_OPEN_ROWS;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
// Also export for Node context (tests)
|
|
205
|
-
if (typeof module !== 'undefined' && module.exports) {
|
|
206
|
-
module.exports = {
|
|
207
|
-
extractPreview,
|
|
208
|
-
extractNewContent,
|
|
209
|
-
renderFilePreviewCard,
|
|
210
|
-
PREVIEW_LINES,
|
|
211
|
-
PREVIEW_AUTO_OPEN_ROWS,
|
|
212
|
-
};
|
|
213
|
-
}
|
|
3
|
+
"use strict";const previewPath="function"==typeof require?require("node:path"):null,PREVIEW_LINES=8,PREVIEW_AUTO_OPEN_ROWS=30,LANGUAGE_BY_EXT={".js":"javascript",".ts":"typescript",".tsx":"typescript",".jsx":"javascript",".py":"python",".rb":"ruby",".go":"go",".rs":"rust",".java":"java",".c":"c",".cpp":"cpp",".h":"c",".hpp":"cpp",".cs":"csharp",".php":"php",".html":"html",".htm":"html",".css":"css",".scss":"scss",".json":"json",".yaml":"yaml",".yml":"yaml",".xml":"xml",".md":"markdown",".sh":"bash",".bash":"bash",".sql":"sql",".lua":"lua",".swift":"swift",".kt":"kotlin"};function extractPreview(e,t,n=8){if(!e||"string"!=typeof t)return null;const i=previewPath?previewPath.extname(e).toLowerCase():e.match(/\.[^.]*$/)?.[0]?.toLowerCase()||"",a=LANGUAGE_BY_EXT[i]||"",r=t.split("\n"),l=r.length>n;return{file:e,language:a,lines:r.slice(0,n),totalLines:r.length,truncated:l}}function extractNewContent(e,t){return!t||"object"!=typeof t||"Write"!==e&&"writeFile"!==e?null:t.content}function renderFilePreviewCard(e,t){if(!e)return null;const n=document.createElement("div");n.className="file-preview-card";const i=document.createElement("div");i.className="file-preview-header",i.innerHTML=`\n <div class="file-preview-path">\n <span class="file-preview-icon">📄</span>\n <span class="file-preview-name">${escapeHtml(e.file)}</span>\n <span class="file-preview-meta">${e.totalLines} line${1===e.totalLines?"":"s"}</span>\n </div>\n `;const a=document.createElement("div");a.className="file-preview-content";const r=String(e.totalLines).length;for(let t=0;t<e.lines.length;t++){const n=t+1,i=e.lines[t]||"",l=document.createElement("div");l.className="file-preview-line";const s=document.createElement("span");s.className="file-preview-gutter",s.textContent=String(n).padStart(r," ");const c=document.createElement("span");c.className="file-preview-line-text",c.textContent=i,l.appendChild(s),l.appendChild(c),a.appendChild(l)}const l=document.createElement("div");if(l.className="file-preview-footer",e.truncated){const n=e.totalLines-e.lines.length,i=document.createElement("span");i.className="file-preview-notice",i.textContent=`${n} more line${1===n?"":"s"}`;const a=document.createElement("button");a.className="file-preview-button",a.textContent="View Full",a.onclick=n=>{n.stopPropagation(),t&&t(e)},l.appendChild(i),l.appendChild(a)}return n.appendChild(i),n.appendChild(a),e.truncated&&n.appendChild(l),n}function escapeHtml(e){const t=document.createElement("div");return t.textContent=e,t.innerHTML}"undefined"!=typeof window&&(window.extractPreview=extractPreview,window.extractNewContent=extractNewContent,window.renderFilePreviewCard=renderFilePreviewCard,window.PREVIEW_LINES=8,window.PREVIEW_AUTO_OPEN_ROWS=30),"undefined"!=typeof module&&module.exports&&(module.exports={extractPreview:extractPreview,extractNewContent:extractNewContent,renderFilePreviewCard:renderFilePreviewCard,PREVIEW_LINES:8,PREVIEW_AUTO_OPEN_ROWS:30});
|