devanvil 0.0.0-stage → 2.1.0
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 +21 -0
- package/README.ar.md +113 -0
- package/README.md +272 -2
- package/SECURITY.md +49 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +659 -0
- package/dist/core/contract-drift.d.ts +49 -0
- package/dist/core/contract-drift.js +302 -0
- package/dist/core/converters.d.ts +18 -0
- package/dist/core/converters.js +981 -0
- package/dist/core/cron.d.ts +33 -0
- package/dist/core/cron.js +306 -0
- package/dist/core/crypto.d.ts +59 -0
- package/dist/core/crypto.js +250 -0
- package/dist/core/curl.d.ts +17 -0
- package/dist/core/curl.js +170 -0
- package/dist/core/diff.d.ts +36 -0
- package/dist/core/diff.js +148 -0
- package/dist/core/encoding.d.ts +3 -0
- package/dist/core/encoding.js +143 -0
- package/dist/core/importers.d.ts +65 -0
- package/dist/core/importers.js +361 -0
- package/dist/core/jwt.d.ts +39 -0
- package/dist/core/jwt.js +256 -0
- package/dist/core/llm-tokens.d.ts +38 -0
- package/dist/core/llm-tokens.js +125 -0
- package/dist/core/log-analyzer.d.ts +30 -0
- package/dist/core/log-analyzer.js +155 -0
- package/dist/core/network.d.ts +72 -0
- package/dist/core/network.js +185 -0
- package/dist/core/oauth-protobuf.d.ts +74 -0
- package/dist/core/oauth-protobuf.js +390 -0
- package/dist/core/openapi.d.ts +27 -0
- package/dist/core/openapi.js +257 -0
- package/dist/core/pipeline.d.ts +28 -0
- package/dist/core/pipeline.js +154 -0
- package/dist/core/regex.d.ts +50 -0
- package/dist/core/regex.js +351 -0
- package/dist/core/runner.d.ts +53 -0
- package/dist/core/runner.js +250 -0
- package/dist/core/secrets.d.ts +87 -0
- package/dist/core/secrets.js +599 -0
- package/dist/core/security.d.ts +34 -0
- package/dist/core/security.js +284 -0
- package/dist/core/sql-explain.d.ts +50 -0
- package/dist/core/sql-explain.js +259 -0
- package/dist/core/tls.d.ts +44 -0
- package/dist/core/tls.js +166 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +31 -0
- package/dist/server/app.d.ts +31 -0
- package/dist/server/app.js +348 -0
- package/dist/server/http-proxy.d.ts +55 -0
- package/dist/server/http-proxy.js +364 -0
- package/dist/server/http-utils.d.ts +28 -0
- package/dist/server/http-utils.js +106 -0
- package/dist/server/load-tester.d.ts +53 -0
- package/dist/server/load-tester.js +134 -0
- package/dist/server/mcp.d.ts +35 -0
- package/dist/server/mcp.js +466 -0
- package/dist/server/mock-store.d.ts +38 -0
- package/dist/server/mock-store.js +197 -0
- package/dist/server/plugin-loader.d.ts +60 -0
- package/dist/server/plugin-loader.js +285 -0
- package/dist/server/recorder-store.d.ts +35 -0
- package/dist/server/recorder-store.js +146 -0
- package/dist/server/routes/network-routes.d.ts +3 -0
- package/dist/server/routes/network-routes.js +391 -0
- package/dist/server/routes/tools-routes.d.ts +3 -0
- package/dist/server/routes/tools-routes.js +292 -0
- package/dist/server/routes/workspace-routes.d.ts +3 -0
- package/dist/server/routes/workspace-routes.js +240 -0
- package/dist/server/webhook-store.d.ts +29 -0
- package/dist/server/webhook-store.js +90 -0
- package/dist/server/workspace-store.d.ts +91 -0
- package/dist/server/workspace-store.js +447 -0
- package/dist/server/ws-probe.d.ts +34 -0
- package/dist/server/ws-probe.js +283 -0
- package/dist/ui/app.js +274 -0
- package/dist/ui/favicon.svg +14 -0
- package/dist/ui/index.html +83 -0
- package/dist/ui/logo.png +0 -0
- package/dist/ui/styles.css +694 -0
- package/dist/ui/tools-data.js +704 -0
- package/dist/ui/tools-network.js +727 -0
- package/dist/ui/tools-ops.js +295 -0
- package/dist/ui/tools-pro.js +500 -0
- package/dist/ui/tools-security.js +389 -0
- package/dist/ui/tools-v12.js +745 -0
- package/dist/ui/tools-v13.js +321 -0
- package/dist/ui/tools-v20.js +563 -0
- package/dist/ui/tools-v21.js +395 -0
- package/package.json +75 -4
|
@@ -0,0 +1,563 @@
|
|
|
1
|
+
(function () {
|
|
2
|
+
'use strict';
|
|
3
|
+
const { h, api, toast, copyText, registerTool } = window.DevAnvil;
|
|
4
|
+
|
|
5
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
6
|
+
// 16. HTTP Load Benchmarker (k6-lite) & SQL EXPLAIN ANALYZE Visualizer
|
|
7
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
8
|
+
registerTool({
|
|
9
|
+
id: 'load-sql-explain',
|
|
10
|
+
group: 'Performance & DB',
|
|
11
|
+
name: 'Load Bench & SQL Explain',
|
|
12
|
+
icon: '🔥',
|
|
13
|
+
subtitle: 'Concurrent HTTP Load & P95/P99 Latency Benchmarker + Postgres/SQLite EXPLAIN ANALYZE Bottleneck Visualizer',
|
|
14
|
+
keywords: ['load', 'bench', 'k6', 'autocannon', 'latency', 'p95', 'p99', 'sql', 'explain', 'postgres', 'sqlite', 'query'],
|
|
15
|
+
render(root) {
|
|
16
|
+
let activeTab = 'load';
|
|
17
|
+
const tabBar = h('div', { class: 'tabs' });
|
|
18
|
+
const paneLoad = h('div', { class: 'stack' });
|
|
19
|
+
const paneExplain = h('div', { class: 'stack' });
|
|
20
|
+
|
|
21
|
+
// ─── Tab 1: Concurrent HTTP Load Benchmarker ──────────────────────────
|
|
22
|
+
const loadMethod = h(
|
|
23
|
+
'select',
|
|
24
|
+
{ style: { width: '100px', flexShrink: '0', fontFamily: 'var(--font-mono)', fontWeight: '700' } },
|
|
25
|
+
['GET', 'POST', 'PUT', 'DELETE', 'HEAD'].map((m) => h('option', { value: m }, m)),
|
|
26
|
+
);
|
|
27
|
+
const loadUrl = h('input', { type: 'text', value: 'https://httpbin.org/get', placeholder: 'https://api.example.com/health or {{BASE_URL}}/mock/health' });
|
|
28
|
+
const loadReqCount = h('input', { type: 'number', value: '40', min: '1', max: '1000', style: { width: '90px' } });
|
|
29
|
+
const loadConcurrency = h('input', { type: 'number', value: '8', min: '1', max: '50', style: { width: '80px' } });
|
|
30
|
+
const loadHeaders = h('textarea', { rows: 2, placeholder: 'Authorization: Bearer {{env.API_TOKEN}}' });
|
|
31
|
+
const loadBody = h('textarea', { rows: 2, placeholder: 'Optional JSON body for POST/PUT…' });
|
|
32
|
+
|
|
33
|
+
const loadStatsRow = h('div', { class: 'row' });
|
|
34
|
+
const loadDiffRow = h('div', { class: 'row' });
|
|
35
|
+
const loadHistBox = h('div', { class: 'stack' });
|
|
36
|
+
const loadJsonOut = h('pre', { class: 'code-box' }, 'Configure URL, total requests & concurrency and click "Run Load Test" to measure RPS, P50/P90/P95/P99 & histogram.');
|
|
37
|
+
let lastLoadReport = null;
|
|
38
|
+
let baselineReport = null;
|
|
39
|
+
|
|
40
|
+
function renderBaselineDiff(curr) {
|
|
41
|
+
loadDiffRow.textContent = '';
|
|
42
|
+
if (!baselineReport || !curr) return;
|
|
43
|
+
const rpsDelta = baselineReport.requestsPerSec > 0
|
|
44
|
+
? Math.round(((curr.requestsPerSec - baselineReport.requestsPerSec) / baselineReport.requestsPerSec) * 1000) / 10
|
|
45
|
+
: 0;
|
|
46
|
+
const p95Delta = Math.round((curr.latencyMs.p95 - baselineReport.latencyMs.p95) * 10) / 10;
|
|
47
|
+
loadDiffRow.appendChild(h('span', { class: 'badge badge-subtle' }, `Baseline: ${baselineReport.requestsPerSec} req/s · P95 ${baselineReport.latencyMs.p95}ms`));
|
|
48
|
+
loadDiffRow.appendChild(
|
|
49
|
+
h('span', { class: rpsDelta >= 0 ? 'badge badge-ok' : 'badge badge-err' }, `RPS ${rpsDelta >= 0 ? '+' : ''}${rpsDelta}%`),
|
|
50
|
+
);
|
|
51
|
+
loadDiffRow.appendChild(
|
|
52
|
+
h('span', { class: p95Delta <= 0 ? 'badge badge-ok' : 'badge badge-warn' }, `P95 ${p95Delta >= 0 ? '+' : ''}${p95Delta}ms`),
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const pinBaselineBtn = h(
|
|
57
|
+
'button',
|
|
58
|
+
{
|
|
59
|
+
type: 'button',
|
|
60
|
+
class: 'btn btn-ghost btn-sm',
|
|
61
|
+
onClick: () => {
|
|
62
|
+
if (!lastLoadReport) {
|
|
63
|
+
toast('Run a load test first before pinning a baseline', 'err');
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
baselineReport = lastLoadReport;
|
|
67
|
+
renderBaselineDiff(lastLoadReport);
|
|
68
|
+
toast(`Pinned baseline (${baselineReport.requestsPerSec} req/s, P95 ${baselineReport.latencyMs.p95}ms)`, 'ok');
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
'Pin Baseline',
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
function parseHeaders(text) {
|
|
75
|
+
const out = {};
|
|
76
|
+
for (const line of text.split(/\r?\n/)) {
|
|
77
|
+
const idx = line.indexOf(':');
|
|
78
|
+
if (idx > 0) out[line.slice(0, idx).trim()] = line.slice(idx + 1).trim();
|
|
79
|
+
}
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const runLoadBtn = h(
|
|
84
|
+
'button',
|
|
85
|
+
{
|
|
86
|
+
type: 'button',
|
|
87
|
+
class: 'btn btn-primary btn-sm',
|
|
88
|
+
onClick: async () => {
|
|
89
|
+
runLoadBtn.disabled = true;
|
|
90
|
+
runLoadBtn.textContent = 'Running…';
|
|
91
|
+
try {
|
|
92
|
+
const rep = await api('/api/load-test', {
|
|
93
|
+
body: {
|
|
94
|
+
method: loadMethod.value,
|
|
95
|
+
url: loadUrl.value.trim(),
|
|
96
|
+
headers: parseHeaders(loadHeaders.value),
|
|
97
|
+
body: loadBody.value,
|
|
98
|
+
totalRequests: Number(loadReqCount.value) || 40,
|
|
99
|
+
concurrency: Number(loadConcurrency.value) || 8,
|
|
100
|
+
useEnvironment: true,
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
lastLoadReport = rep;
|
|
104
|
+
loadStatsRow.textContent = '';
|
|
105
|
+
loadStatsRow.appendChild(h('span', { class: 'badge badge-ok' }, `${rep.requestsPerSec} req/s`));
|
|
106
|
+
loadStatsRow.appendChild(h('span', { class: 'badge badge-info' }, `P50 ${rep.latencyMs.p50}ms`));
|
|
107
|
+
loadStatsRow.appendChild(h('span', { class: 'badge badge-warn' }, `P95 ${rep.latencyMs.p95}ms`));
|
|
108
|
+
loadStatsRow.appendChild(h('span', { class: 'badge badge-warn' }, `P99 ${rep.latencyMs.p99}ms`));
|
|
109
|
+
loadStatsRow.appendChild(h('span', { class: rep.failedRequests ? 'badge badge-err' : 'badge badge-ok' }, `${rep.succeededRequests}/${rep.completedRequests} OK`));
|
|
110
|
+
loadStatsRow.appendChild(h('span', { class: 'badge badge-subtle' }, `${rep.throughputKbPerSec} KB/s`));
|
|
111
|
+
renderBaselineDiff(rep);
|
|
112
|
+
|
|
113
|
+
loadHistBox.textContent = '';
|
|
114
|
+
for (const b of rep.histogram || []) {
|
|
115
|
+
const fill = h('div', { class: 'heat-fill' });
|
|
116
|
+
fill.style.width = `${Math.max(b.percent, 1)}%`;
|
|
117
|
+
loadHistBox.appendChild(
|
|
118
|
+
h(
|
|
119
|
+
'div',
|
|
120
|
+
{ class: 'hist-row' },
|
|
121
|
+
h('span', { class: 'hist-label mono' }, b.label),
|
|
122
|
+
h('div', { class: 'heat-track' }, fill),
|
|
123
|
+
h('span', { class: 'hist-val mono' }, `${b.count} (${b.percent}%)`),
|
|
124
|
+
),
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
loadJsonOut.textContent = JSON.stringify(rep, null, 2);
|
|
128
|
+
toast(`Load test done: ${rep.requestsPerSec} req/s (P95: ${rep.latencyMs.p95}ms)`, 'ok');
|
|
129
|
+
} catch (err) {
|
|
130
|
+
loadStatsRow.textContent = '';
|
|
131
|
+
loadStatsRow.appendChild(h('span', { class: 'badge badge-err' }, 'Load Test Blocked / Failed'));
|
|
132
|
+
loadJsonOut.textContent = err.message;
|
|
133
|
+
toast(err.message, 'err');
|
|
134
|
+
} finally {
|
|
135
|
+
runLoadBtn.disabled = false;
|
|
136
|
+
runLoadBtn.textContent = 'Run Load Test';
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
'Run Load Test',
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
paneLoad.appendChild(
|
|
144
|
+
h(
|
|
145
|
+
'div',
|
|
146
|
+
{ class: 'card' },
|
|
147
|
+
h(
|
|
148
|
+
'div',
|
|
149
|
+
{ class: 'row' },
|
|
150
|
+
loadMethod,
|
|
151
|
+
loadUrl,
|
|
152
|
+
h('span', { style: { fontSize: '12px', color: 'var(--text-dim)' } }, 'Reqs:'),
|
|
153
|
+
loadReqCount,
|
|
154
|
+
h('span', { style: { fontSize: '12px', color: 'var(--text-dim)' } }, 'Conc:'),
|
|
155
|
+
loadConcurrency,
|
|
156
|
+
runLoadBtn,
|
|
157
|
+
pinBaselineBtn,
|
|
158
|
+
),
|
|
159
|
+
h('div', { class: 'grid-2' }, loadHeaders, loadBody),
|
|
160
|
+
loadStatsRow,
|
|
161
|
+
loadDiffRow,
|
|
162
|
+
loadHistBox,
|
|
163
|
+
loadJsonOut,
|
|
164
|
+
),
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
// ─── Tab 2: SQL EXPLAIN ANALYZE Visualizer ────────────────────────────
|
|
168
|
+
const sampleExplain = JSON.stringify(
|
|
169
|
+
[
|
|
170
|
+
{
|
|
171
|
+
'Planning Time': 0.42,
|
|
172
|
+
'Execution Time': 142.8,
|
|
173
|
+
Plan: {
|
|
174
|
+
'Node Type': 'Sort',
|
|
175
|
+
'Sort Method': 'external merge Disk',
|
|
176
|
+
'Actual Total Time': 141.9,
|
|
177
|
+
'Actual Rows': 2500,
|
|
178
|
+
'Plan Rows': 2500,
|
|
179
|
+
'Actual Loops': 1,
|
|
180
|
+
Plans: [
|
|
181
|
+
{
|
|
182
|
+
'Node Type': 'Seq Scan',
|
|
183
|
+
'Relation Name': 'orders',
|
|
184
|
+
Filter: "(status = 'pending'::text)",
|
|
185
|
+
'Rows Removed by Filter': 97500,
|
|
186
|
+
'Actual Total Time': 88.4,
|
|
187
|
+
'Actual Rows': 2500,
|
|
188
|
+
'Plan Rows': 120,
|
|
189
|
+
'Actual Loops': 1,
|
|
190
|
+
},
|
|
191
|
+
],
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
],
|
|
195
|
+
null,
|
|
196
|
+
2,
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
const explainIn = h('textarea', { rows: 12, value: sampleExplain });
|
|
200
|
+
const explainInsights = h('div', { class: 'stack' });
|
|
201
|
+
const explainTree = h('div', { class: 'json-tree' });
|
|
202
|
+
|
|
203
|
+
function renderPlanNode(node) {
|
|
204
|
+
const fill = h('div', { class: `heat-fill ${node.percentOfTotal >= 40 ? 'heat-hot' : ''}` });
|
|
205
|
+
fill.style.width = `${Math.min(Math.max(node.percentOfTotal, 2), 100)}%`;
|
|
206
|
+
const summary = h(
|
|
207
|
+
'summary',
|
|
208
|
+
{ class: 'tree-summary' },
|
|
209
|
+
h('strong', { class: 'tree-key' }, node.nodeType),
|
|
210
|
+
node.relation ? h('span', { class: 'badge badge-subtle' }, node.relation) : null,
|
|
211
|
+
h('span', { class: 'badge badge-info' }, `${node.exclusiveTimeMs}ms (${node.percentOfTotal}%)`),
|
|
212
|
+
node.actualRows !== undefined ? h('span', { class: 'badge badge-subtle' }, `rows=${node.actualRows}`) : null,
|
|
213
|
+
node.warnings.length ? h('span', { class: 'badge badge-err' }, `${node.warnings.length} issue(s)`) : null,
|
|
214
|
+
);
|
|
215
|
+
const bodyKids = [
|
|
216
|
+
h('div', { class: 'heat-track', style: { margin: '4px 0 6px' } }, fill),
|
|
217
|
+
node.filter ? h('div', { class: 'mono', style: { fontSize: '11.5px', color: 'var(--text-muted)' } }, `Filter: ${node.filter}`) : null,
|
|
218
|
+
...node.children.map(renderPlanNode),
|
|
219
|
+
];
|
|
220
|
+
return h('details', { class: 'tree-node', open: true }, summary, h('div', { class: 'tree-children' }, bodyKids));
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
async function runExplain() {
|
|
224
|
+
try {
|
|
225
|
+
const rep = await api('/api/sql/explain', { body: { input: explainIn.value } });
|
|
226
|
+
explainInsights.textContent = '';
|
|
227
|
+
for (const ins of rep.insights || []) {
|
|
228
|
+
const cls = ins.severity === 'critical' ? 'fail' : ins.severity === 'warning' ? 'warn' : 'pass';
|
|
229
|
+
explainInsights.appendChild(
|
|
230
|
+
h(
|
|
231
|
+
'div',
|
|
232
|
+
{ class: `finding ${cls}` },
|
|
233
|
+
h('strong', {}, `${ins.title}: `),
|
|
234
|
+
`${ins.detail} -> ${ins.recommendation}`,
|
|
235
|
+
),
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
explainTree.textContent = '';
|
|
239
|
+
explainTree.appendChild(renderPlanNode(rep.root));
|
|
240
|
+
toast(`Analyzed ${rep.totalNodes} plan node(s) (${rep.engine})`, 'ok');
|
|
241
|
+
} catch (err) {
|
|
242
|
+
toast(err.message, 'err');
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
paneExplain.appendChild(
|
|
247
|
+
h(
|
|
248
|
+
'div',
|
|
249
|
+
{ class: 'grid-2' },
|
|
250
|
+
h(
|
|
251
|
+
'div',
|
|
252
|
+
{ class: 'card' },
|
|
253
|
+
h(
|
|
254
|
+
'div',
|
|
255
|
+
{ class: 'row-between' },
|
|
256
|
+
h('h2', { class: 'card-title' }, 'Postgres EXPLAIN (FORMAT JSON) / SQLite Plan'),
|
|
257
|
+
h('button', { type: 'button', class: 'btn btn-primary btn-sm', onClick: runExplain }, 'Analyze Plan'),
|
|
258
|
+
),
|
|
259
|
+
explainIn,
|
|
260
|
+
),
|
|
261
|
+
h(
|
|
262
|
+
'div',
|
|
263
|
+
{ class: 'card' },
|
|
264
|
+
h('h2', { class: 'card-title' }, 'Bottlenecks & Execution Heat Tree'),
|
|
265
|
+
explainInsights,
|
|
266
|
+
explainTree,
|
|
267
|
+
),
|
|
268
|
+
),
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
function showTab(id) {
|
|
272
|
+
activeTab = id;
|
|
273
|
+
paneLoad.style.display = id === 'load' ? '' : 'none';
|
|
274
|
+
paneExplain.style.display = id === 'explain' ? '' : 'none';
|
|
275
|
+
Array.from(tabBar.children).forEach((b) => b.classList.toggle('active', b.dataset.tab === id));
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
[
|
|
279
|
+
['load', 'HTTP Load Benchmarker (k6-lite)'],
|
|
280
|
+
['explain', 'SQL EXPLAIN Visualizer (Postgres / SQLite)'],
|
|
281
|
+
].forEach(([id, label]) => {
|
|
282
|
+
tabBar.appendChild(h('button', { type: 'button', class: `tab-btn ${activeTab === id ? 'active' : ''}`, 'data-tab': id, onClick: () => showTab(id) }, label));
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
root.appendChild(h('div', { class: 'stack' }, tabBar, paneLoad, paneExplain));
|
|
286
|
+
showTab('load');
|
|
287
|
+
void runExplain();
|
|
288
|
+
},
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
292
|
+
// 17. Structured Log Analyzer & Zero-Trust Local Plugins
|
|
293
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
294
|
+
registerTool({
|
|
295
|
+
id: 'logs-plugins',
|
|
296
|
+
group: 'Performance & DB',
|
|
297
|
+
name: 'Log Analyzer & Plugins',
|
|
298
|
+
icon: '🧩',
|
|
299
|
+
subtitle: 'NDJSON/Server Log Analyzer (Error Fingerprinting + P95) & Zero-Trust Sandboxed Local Plugins',
|
|
300
|
+
keywords: ['log', 'logs', 'ndjson', 'jsonl', 'error', 'fingerprint', 'plugin', 'plugins', 'sandbox', 'vm'],
|
|
301
|
+
render(root) {
|
|
302
|
+
let activeTab = 'logs';
|
|
303
|
+
const tabBar = h('div', { class: 'tabs' });
|
|
304
|
+
const paneLogs = h('div', { class: 'stack' });
|
|
305
|
+
const panePlugins = h('div', { class: 'stack' });
|
|
306
|
+
|
|
307
|
+
// ─── Tab 1: Structured Log & Error Fingerprint Analyzer ───────────────
|
|
308
|
+
const sampleLogs = [
|
|
309
|
+
'{"level":"info","msg":"GET /api/orders","status":200,"latencyMs":18}',
|
|
310
|
+
'{"level":"info","msg":"GET /api/orders","status":200,"latencyMs":24}',
|
|
311
|
+
'{"level":"error","msg":"DB connection timeout for order 550e8400-e29b-41d4-a716-446655440000 after 5002ms","status":503,"latencyMs":5002}',
|
|
312
|
+
'{"level":"error","msg":"DB connection timeout for order 123e4567-e89b-12d3-a456-426614174000 after 5011ms","status":503,"latencyMs":5011}',
|
|
313
|
+
'{"level":"warn","msg":"Rate limit approaching for IP 10.0.4.22","status":429,"latencyMs":9}',
|
|
314
|
+
].join('\n');
|
|
315
|
+
|
|
316
|
+
const logIn = h('textarea', { rows: 11, value: sampleLogs });
|
|
317
|
+
const logBadges = h('div', { class: 'row' });
|
|
318
|
+
const logErrorsBox = h('div', { class: 'stack' });
|
|
319
|
+
const logJsonOut = h('pre', { class: 'code-box' }, '');
|
|
320
|
+
|
|
321
|
+
async function runLogs() {
|
|
322
|
+
try {
|
|
323
|
+
const rep = await api('/api/logs/analyze', { body: { input: logIn.value } });
|
|
324
|
+
logBadges.textContent = '';
|
|
325
|
+
logBadges.appendChild(h('span', { class: 'badge badge-subtle' }, `${rep.totalLines} lines (${rep.parsedJsonLines} JSON)`));
|
|
326
|
+
logBadges.appendChild(h('span', { class: rep.levels.error + rep.levels.fatal > 0 ? 'badge badge-err' : 'badge badge-ok' }, `${rep.levels.error + rep.levels.fatal} errors`));
|
|
327
|
+
logBadges.appendChild(h('span', { class: 'badge badge-warn' }, `${rep.levels.warn} warns`));
|
|
328
|
+
if (rep.latencyStats) {
|
|
329
|
+
logBadges.appendChild(h('span', { class: 'badge badge-info' }, `P50 ${rep.latencyStats.p50Ms}ms · P95 ${rep.latencyStats.p95Ms}ms`));
|
|
330
|
+
}
|
|
331
|
+
if (rep.secretFindingsCount > 0) {
|
|
332
|
+
logBadges.appendChild(h('span', { class: 'badge badge-err' }, `${rep.secretFindingsCount} SECRET LEAK(S)!`));
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
logErrorsBox.textContent = '';
|
|
336
|
+
for (const g of rep.topErrors || []) {
|
|
337
|
+
logErrorsBox.appendChild(
|
|
338
|
+
h(
|
|
339
|
+
'div',
|
|
340
|
+
{ class: 'finding fail' },
|
|
341
|
+
h('span', { class: 'badge badge-err' }, `${g.count}x`),
|
|
342
|
+
h('span', { class: 'mono' }, ` ${g.fingerprint}`),
|
|
343
|
+
),
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
if (!rep.topErrors || !rep.topErrors.length) {
|
|
347
|
+
logErrorsBox.appendChild(h('div', { class: 'finding pass' }, 'No error fingerprints detected in logs.'));
|
|
348
|
+
}
|
|
349
|
+
logJsonOut.textContent = JSON.stringify(rep, null, 2);
|
|
350
|
+
} catch (err) {
|
|
351
|
+
toast(err.message, 'err');
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
paneLogs.appendChild(
|
|
356
|
+
h(
|
|
357
|
+
'div',
|
|
358
|
+
{ class: 'grid-2' },
|
|
359
|
+
h(
|
|
360
|
+
'div',
|
|
361
|
+
{ class: 'card' },
|
|
362
|
+
h(
|
|
363
|
+
'div',
|
|
364
|
+
{ class: 'row-between' },
|
|
365
|
+
h('h2', { class: 'card-title' }, 'Paste NDJSON / Nginx / App Logs'),
|
|
366
|
+
h('button', { type: 'button', class: 'btn btn-primary btn-sm', onClick: runLogs }, 'Analyze Logs'),
|
|
367
|
+
),
|
|
368
|
+
logIn,
|
|
369
|
+
),
|
|
370
|
+
h(
|
|
371
|
+
'div',
|
|
372
|
+
{ class: 'card' },
|
|
373
|
+
h(
|
|
374
|
+
'div',
|
|
375
|
+
{ class: 'row-between' },
|
|
376
|
+
h('h2', { class: 'card-title' }, 'Deduplicated Error Fingerprints & Latency'),
|
|
377
|
+
h('button', { type: 'button', class: 'btn btn-ghost btn-xs', onClick: () => copyText(logJsonOut.textContent) }, 'Copy JSON'),
|
|
378
|
+
),
|
|
379
|
+
logBadges,
|
|
380
|
+
logErrorsBox,
|
|
381
|
+
logJsonOut,
|
|
382
|
+
),
|
|
383
|
+
),
|
|
384
|
+
);
|
|
385
|
+
|
|
386
|
+
// ─── Tab 2: Zero-Trust Sandboxed Local Plugins (Worker + VM + In-Browser Code Editor) ──
|
|
387
|
+
const pluginsDirBadge = h('span', { class: 'badge badge-subtle' }, 'Loading…');
|
|
388
|
+
const scaffoldIdIn = h('input', { type: 'text', placeholder: 'New plugin id (e.g. my-formatter)' });
|
|
389
|
+
const pluginSel = h('select', { style: { width: '240px' } });
|
|
390
|
+
const pluginCodeEditor = h('textarea', { rows: 8, placeholder: 'Select a plugin to view & edit its handler.js source right here…' });
|
|
391
|
+
const pluginInput = h('textarea', { rows: 6, value: 'alpha\nbeta\ngamma', placeholder: 'Input passed into plugin transform(input, options)…' });
|
|
392
|
+
const pluginOut = h('pre', { class: 'code-box' }, 'Scaffold or install a plugin in ~/.devanvil/plugins/<id>/ and run it safely inside the isolated Worker Thread + VM Sandbox.');
|
|
393
|
+
|
|
394
|
+
async function loadSelectedPluginSource() {
|
|
395
|
+
if (!pluginSel.value) {
|
|
396
|
+
pluginCodeEditor.value = '';
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
try {
|
|
400
|
+
const data = await api(`/api/plugins/${encodeURIComponent(pluginSel.value)}/source`);
|
|
401
|
+
pluginCodeEditor.value = data.code || '';
|
|
402
|
+
} catch (err) {
|
|
403
|
+
pluginCodeEditor.value = '';
|
|
404
|
+
toast(err.message, 'err');
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
pluginSel.addEventListener('change', () => { void loadSelectedPluginSource(); });
|
|
409
|
+
|
|
410
|
+
async function refreshPlugins(selectId) {
|
|
411
|
+
try {
|
|
412
|
+
const data = await api('/api/plugins');
|
|
413
|
+
pluginsDirBadge.textContent = `Plugins Dir: ${data.pluginsDir} (${data.plugins.length} installed · ${data.isolation || 'worker_threads+vm'})`;
|
|
414
|
+
const prev = selectId || pluginSel.value;
|
|
415
|
+
pluginSel.textContent = '';
|
|
416
|
+
if (!data.plugins.length) {
|
|
417
|
+
pluginSel.appendChild(h('option', { value: '' }, '(No plugins installed yet — scaffold one!)'));
|
|
418
|
+
pluginCodeEditor.value = '';
|
|
419
|
+
} else {
|
|
420
|
+
for (const p of data.plugins) {
|
|
421
|
+
pluginSel.appendChild(h('option', { value: p.id, selected: p.id === prev }, `${p.name} (v${p.version})`));
|
|
422
|
+
}
|
|
423
|
+
await loadSelectedPluginSource();
|
|
424
|
+
}
|
|
425
|
+
} catch (err) {
|
|
426
|
+
toast(err.message, 'err');
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
panePlugins.appendChild(
|
|
431
|
+
h(
|
|
432
|
+
'div',
|
|
433
|
+
{ class: 'card' },
|
|
434
|
+
h(
|
|
435
|
+
'div',
|
|
436
|
+
{ class: 'row-between' },
|
|
437
|
+
h('div', { class: 'row' }, h('h2', { class: 'card-title' }, 'Zero-Trust Worker + VM Plugin Sandbox'), pluginsDirBadge),
|
|
438
|
+
h('button', { type: 'button', class: 'btn btn-ghost btn-xs', onClick: () => refreshPlugins() }, 'Refresh'),
|
|
439
|
+
),
|
|
440
|
+
h(
|
|
441
|
+
'div',
|
|
442
|
+
{ class: 'finding pass' },
|
|
443
|
+
'Hardened Isolation: isolated node:worker_threads + no-codegen VM (no eval/Function/constructor escape, empty env, 48MB heap cap, hard terminate on 500ms timeout).',
|
|
444
|
+
),
|
|
445
|
+
h(
|
|
446
|
+
'div',
|
|
447
|
+
{ class: 'row' },
|
|
448
|
+
scaffoldIdIn,
|
|
449
|
+
h(
|
|
450
|
+
'button',
|
|
451
|
+
{
|
|
452
|
+
type: 'button',
|
|
453
|
+
class: 'btn btn-sm',
|
|
454
|
+
onClick: async () => {
|
|
455
|
+
try {
|
|
456
|
+
const id = scaffoldIdIn.value.trim();
|
|
457
|
+
const res = await api('/api/plugins/scaffold', { body: { id } });
|
|
458
|
+
scaffoldIdIn.value = '';
|
|
459
|
+
toast(`Scaffolded plugin at ${res.created.dirPath}`, 'ok');
|
|
460
|
+
await refreshPlugins(id.toLowerCase().replace(/[^a-z0-9-_]+/g, '-'));
|
|
461
|
+
} catch (err) {
|
|
462
|
+
toast(err.message, 'err');
|
|
463
|
+
}
|
|
464
|
+
},
|
|
465
|
+
},
|
|
466
|
+
'Scaffold New Plugin',
|
|
467
|
+
),
|
|
468
|
+
),
|
|
469
|
+
h(
|
|
470
|
+
'div',
|
|
471
|
+
{ class: 'row' },
|
|
472
|
+
pluginSel,
|
|
473
|
+
h(
|
|
474
|
+
'button',
|
|
475
|
+
{
|
|
476
|
+
type: 'button',
|
|
477
|
+
class: 'btn btn-primary btn-sm',
|
|
478
|
+
onClick: async () => {
|
|
479
|
+
if (!pluginSel.value) {
|
|
480
|
+
toast('Scaffold or select a plugin first', 'err');
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
try {
|
|
484
|
+
const res = await api(`/api/plugins/${encodeURIComponent(pluginSel.value)}/run`, {
|
|
485
|
+
body: { input: pluginInput.value },
|
|
486
|
+
});
|
|
487
|
+
pluginOut.textContent = res.output;
|
|
488
|
+
toast(`Plugin "${res.pluginId}" ran in ${res.durationMs}ms (${res.isolation})`, 'ok');
|
|
489
|
+
} catch (err) {
|
|
490
|
+
pluginOut.textContent = err.message;
|
|
491
|
+
toast(err.message, 'err');
|
|
492
|
+
}
|
|
493
|
+
},
|
|
494
|
+
},
|
|
495
|
+
'Run in Worker Sandbox',
|
|
496
|
+
),
|
|
497
|
+
h(
|
|
498
|
+
'button',
|
|
499
|
+
{
|
|
500
|
+
type: 'button',
|
|
501
|
+
class: 'btn btn-sm',
|
|
502
|
+
onClick: async () => {
|
|
503
|
+
if (!pluginSel.value) return;
|
|
504
|
+
try {
|
|
505
|
+
await api(`/api/plugins/${encodeURIComponent(pluginSel.value)}/source`, {
|
|
506
|
+
method: 'PUT',
|
|
507
|
+
body: { code: pluginCodeEditor.value },
|
|
508
|
+
});
|
|
509
|
+
toast(`Saved source for "${pluginSel.value}"`, 'ok');
|
|
510
|
+
} catch (err) {
|
|
511
|
+
toast(err.message, 'err');
|
|
512
|
+
}
|
|
513
|
+
},
|
|
514
|
+
},
|
|
515
|
+
'Save Code',
|
|
516
|
+
),
|
|
517
|
+
h(
|
|
518
|
+
'button',
|
|
519
|
+
{
|
|
520
|
+
type: 'button',
|
|
521
|
+
class: 'btn btn-ghost btn-sm',
|
|
522
|
+
onClick: async () => {
|
|
523
|
+
if (!pluginSel.value) return;
|
|
524
|
+
try {
|
|
525
|
+
const target = pluginSel.value;
|
|
526
|
+
await api(`/api/plugins/${encodeURIComponent(target)}`, { method: 'DELETE' });
|
|
527
|
+
toast(`Deleted plugin "${target}"`, 'ok');
|
|
528
|
+
await refreshPlugins();
|
|
529
|
+
} catch (err) {
|
|
530
|
+
toast(err.message, 'err');
|
|
531
|
+
}
|
|
532
|
+
},
|
|
533
|
+
},
|
|
534
|
+
'Delete Plugin',
|
|
535
|
+
),
|
|
536
|
+
),
|
|
537
|
+
h('label', { class: 'field-label' }, 'Plugin Source (handler.js)'),
|
|
538
|
+
pluginCodeEditor,
|
|
539
|
+
h('div', { class: 'grid-2' }, pluginInput, pluginOut),
|
|
540
|
+
),
|
|
541
|
+
);
|
|
542
|
+
|
|
543
|
+
function showTab(id) {
|
|
544
|
+
activeTab = id;
|
|
545
|
+
paneLogs.style.display = id === 'logs' ? '' : 'none';
|
|
546
|
+
panePlugins.style.display = id === 'plugins' ? '' : 'none';
|
|
547
|
+
Array.from(tabBar.children).forEach((b) => b.classList.toggle('active', b.dataset.tab === id));
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
[
|
|
551
|
+
['logs', 'Structured Log Analyzer'],
|
|
552
|
+
['plugins', 'Zero-Trust Local Plugins'],
|
|
553
|
+
].forEach(([id, label]) => {
|
|
554
|
+
tabBar.appendChild(h('button', { type: 'button', class: `tab-btn ${activeTab === id ? 'active' : ''}`, 'data-tab': id, onClick: () => showTab(id) }, label));
|
|
555
|
+
});
|
|
556
|
+
|
|
557
|
+
root.appendChild(h('div', { class: 'stack' }, tabBar, paneLogs, panePlugins));
|
|
558
|
+
showTab('logs');
|
|
559
|
+
void runLogs();
|
|
560
|
+
void refreshPlugins();
|
|
561
|
+
},
|
|
562
|
+
});
|
|
563
|
+
})();
|