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.
Files changed (93) hide show
  1. package/LICENSE +21 -0
  2. package/README.ar.md +113 -0
  3. package/README.md +272 -2
  4. package/SECURITY.md +49 -0
  5. package/dist/cli.d.ts +2 -0
  6. package/dist/cli.js +659 -0
  7. package/dist/core/contract-drift.d.ts +49 -0
  8. package/dist/core/contract-drift.js +302 -0
  9. package/dist/core/converters.d.ts +18 -0
  10. package/dist/core/converters.js +981 -0
  11. package/dist/core/cron.d.ts +33 -0
  12. package/dist/core/cron.js +306 -0
  13. package/dist/core/crypto.d.ts +59 -0
  14. package/dist/core/crypto.js +250 -0
  15. package/dist/core/curl.d.ts +17 -0
  16. package/dist/core/curl.js +170 -0
  17. package/dist/core/diff.d.ts +36 -0
  18. package/dist/core/diff.js +148 -0
  19. package/dist/core/encoding.d.ts +3 -0
  20. package/dist/core/encoding.js +143 -0
  21. package/dist/core/importers.d.ts +65 -0
  22. package/dist/core/importers.js +361 -0
  23. package/dist/core/jwt.d.ts +39 -0
  24. package/dist/core/jwt.js +256 -0
  25. package/dist/core/llm-tokens.d.ts +38 -0
  26. package/dist/core/llm-tokens.js +125 -0
  27. package/dist/core/log-analyzer.d.ts +30 -0
  28. package/dist/core/log-analyzer.js +155 -0
  29. package/dist/core/network.d.ts +72 -0
  30. package/dist/core/network.js +185 -0
  31. package/dist/core/oauth-protobuf.d.ts +74 -0
  32. package/dist/core/oauth-protobuf.js +390 -0
  33. package/dist/core/openapi.d.ts +27 -0
  34. package/dist/core/openapi.js +257 -0
  35. package/dist/core/pipeline.d.ts +28 -0
  36. package/dist/core/pipeline.js +154 -0
  37. package/dist/core/regex.d.ts +50 -0
  38. package/dist/core/regex.js +351 -0
  39. package/dist/core/runner.d.ts +53 -0
  40. package/dist/core/runner.js +250 -0
  41. package/dist/core/secrets.d.ts +87 -0
  42. package/dist/core/secrets.js +599 -0
  43. package/dist/core/security.d.ts +34 -0
  44. package/dist/core/security.js +284 -0
  45. package/dist/core/sql-explain.d.ts +50 -0
  46. package/dist/core/sql-explain.js +259 -0
  47. package/dist/core/tls.d.ts +44 -0
  48. package/dist/core/tls.js +166 -0
  49. package/dist/index.d.ts +31 -0
  50. package/dist/index.js +31 -0
  51. package/dist/server/app.d.ts +31 -0
  52. package/dist/server/app.js +348 -0
  53. package/dist/server/http-proxy.d.ts +55 -0
  54. package/dist/server/http-proxy.js +364 -0
  55. package/dist/server/http-utils.d.ts +28 -0
  56. package/dist/server/http-utils.js +106 -0
  57. package/dist/server/load-tester.d.ts +53 -0
  58. package/dist/server/load-tester.js +134 -0
  59. package/dist/server/mcp.d.ts +35 -0
  60. package/dist/server/mcp.js +466 -0
  61. package/dist/server/mock-store.d.ts +38 -0
  62. package/dist/server/mock-store.js +197 -0
  63. package/dist/server/plugin-loader.d.ts +60 -0
  64. package/dist/server/plugin-loader.js +285 -0
  65. package/dist/server/recorder-store.d.ts +35 -0
  66. package/dist/server/recorder-store.js +146 -0
  67. package/dist/server/routes/network-routes.d.ts +3 -0
  68. package/dist/server/routes/network-routes.js +391 -0
  69. package/dist/server/routes/tools-routes.d.ts +3 -0
  70. package/dist/server/routes/tools-routes.js +292 -0
  71. package/dist/server/routes/workspace-routes.d.ts +3 -0
  72. package/dist/server/routes/workspace-routes.js +240 -0
  73. package/dist/server/webhook-store.d.ts +29 -0
  74. package/dist/server/webhook-store.js +90 -0
  75. package/dist/server/workspace-store.d.ts +91 -0
  76. package/dist/server/workspace-store.js +447 -0
  77. package/dist/server/ws-probe.d.ts +34 -0
  78. package/dist/server/ws-probe.js +283 -0
  79. package/dist/ui/app.js +274 -0
  80. package/dist/ui/favicon.svg +14 -0
  81. package/dist/ui/index.html +83 -0
  82. package/dist/ui/logo.png +0 -0
  83. package/dist/ui/styles.css +694 -0
  84. package/dist/ui/tools-data.js +704 -0
  85. package/dist/ui/tools-network.js +727 -0
  86. package/dist/ui/tools-ops.js +295 -0
  87. package/dist/ui/tools-pro.js +500 -0
  88. package/dist/ui/tools-security.js +389 -0
  89. package/dist/ui/tools-v12.js +745 -0
  90. package/dist/ui/tools-v13.js +321 -0
  91. package/dist/ui/tools-v20.js +563 -0
  92. package/dist/ui/tools-v21.js +395 -0
  93. package/package.json +75 -4
@@ -0,0 +1,704 @@
1
+ (function () {
2
+ 'use strict';
3
+ const { h, api, toast, copyText, registerTool } = window.DevAnvil;
4
+
5
+ // ───────────────────────────────────────────────────────────────────────────
6
+ // 5. Data Studio (JSON/YAML/TOML/CSV/TS/Schema + JSONPath + SQL)
7
+ // ───────────────────────────────────────────────────────────────────────────
8
+ registerTool({
9
+ id: 'data-studio',
10
+ group: 'Data & Code',
11
+ name: 'Data Studio',
12
+ icon: '{}',
13
+ subtitle: 'Bidirectional JSON ↔ YAML ↔ TOML ↔ CSV ↔ TypeScript ↔ JSON Schema, JSONPath & SQL',
14
+ keywords: ['json', 'yaml', 'toml', 'csv', 'typescript', 'schema', 'jsonpath', 'sql', 'format', 'convert'],
15
+ render(root) {
16
+ const fromSel = h(
17
+ 'select',
18
+ { style: { width: '125px' } },
19
+ ['json', 'yaml', 'toml', 'csv', 'query'].map((f) => h('option', { value: f }, f.toUpperCase())),
20
+ );
21
+ const toSel = h(
22
+ 'select',
23
+ { style: { width: '150px' } },
24
+ [
25
+ ['yaml', 'YAML'],
26
+ ['json', 'JSON'],
27
+ ['toml', 'TOML'],
28
+ ['csv', 'CSV'],
29
+ ['query', 'URL Query'],
30
+ ['typescript', 'TypeScript Types'],
31
+ ['jsonschema', 'JSON Schema'],
32
+ ].map(([v, l]) => h('option', { value: v }, l)),
33
+ );
34
+ const sortKeysChk = h('input', { type: 'checkbox' });
35
+ const minifyChk = h('input', { type: 'checkbox' });
36
+
37
+ const sampleJson = JSON.stringify(
38
+ {
39
+ service: 'devanvil-gateway',
40
+ version: '1.0.0',
41
+ server: { host: '127.0.0.1', port: 4321, tls: false },
42
+ endpoints: [
43
+ { path: '/api/health', auth: false, rateLimit: 120 },
44
+ { path: '/api/proxy', auth: true, rateLimit: 30 },
45
+ ],
46
+ maintainer: 'dev@devanvil.local',
47
+ },
48
+ null,
49
+ 2,
50
+ );
51
+
52
+ const inputArea = h('textarea', { rows: 13, value: sampleJson });
53
+ const outputPre = h('pre', { class: 'code-box', style: { minHeight: '240px' } }, '');
54
+
55
+ async function doConvert() {
56
+ try {
57
+ const res = await api('/api/convert', {
58
+ body: {
59
+ input: inputArea.value,
60
+ from: fromSel.value,
61
+ to: toSel.value,
62
+ sortKeys: sortKeysChk.checked,
63
+ minify: minifyChk.checked,
64
+ },
65
+ });
66
+ outputPre.textContent = res.output;
67
+ } catch (err) {
68
+ outputPre.textContent = `Conversion error: ${err.message}`;
69
+ toast(err.message, 'err');
70
+ }
71
+ }
72
+
73
+ // JSONPath
74
+ const jpInput = h('input', { type: 'text', class: 'mono', value: '$.endpoints[*].path', placeholder: '$.a.b[0] or $..key' });
75
+ const jpOut = h('pre', { class: 'code-box' }, '');
76
+ async function runJsonPath() {
77
+ try {
78
+ const res = await api('/api/jsonpath', { body: { input: inputArea.value, expression: jpInput.value } });
79
+ jpOut.textContent = JSON.stringify(res, null, 2);
80
+ } catch (err) {
81
+ jpOut.textContent = err.message;
82
+ }
83
+ }
84
+
85
+ // Interactive JSON Tree Explorer (safe DOM, 1-click Copy JSONPath)
86
+ const treeSearch = h('input', { type: 'text', placeholder: 'Filter keys or values in JSON tree…' });
87
+ const treeBox = h('div', { class: 'json-tree' });
88
+
89
+ function buildTreeNode(keyLabel, val, jsonPath, depth, filter) {
90
+ const isObj = val !== null && typeof val === 'object';
91
+ if (!isObj) {
92
+ const valStr = JSON.stringify(val);
93
+ if (filter && !`${keyLabel} ${valStr} ${jsonPath}`.toLowerCase().includes(filter)) return null;
94
+ return h(
95
+ 'div',
96
+ { class: 'tree-leaf' },
97
+ h('span', { class: 'tree-key' }, keyLabel),
98
+ h('span', { class: 'tree-val' }, `: ${valStr}`),
99
+ h('button', { type: 'button', class: 'tree-path-btn', onClick: () => copyText(jsonPath, `Copied ${jsonPath}`) }, jsonPath),
100
+ );
101
+ }
102
+ const entries = Array.isArray(val) ? val.map((v, i) => [`[${i}]`, v, `${jsonPath}[${i}]`]) : Object.entries(val).map(([k, v]) => [k, v, `${jsonPath}.${k}`]);
103
+ const childNodes = entries
104
+ .map(([k, v, p]) => buildTreeNode(k, v, p, depth + 1, filter))
105
+ .filter(Boolean);
106
+ if (filter && !childNodes.length && !`${keyLabel} ${jsonPath}`.toLowerCase().includes(filter)) return null;
107
+ return h(
108
+ 'details',
109
+ { class: 'tree-node', open: depth < 2 || Boolean(filter) },
110
+ h(
111
+ 'summary',
112
+ { class: 'tree-summary' },
113
+ h('span', { class: 'tree-key' }, keyLabel),
114
+ h('span', { class: 'badge badge-subtle' }, Array.isArray(val) ? `Array(${val.length})` : `Object(${entries.length})`),
115
+ h('button', { type: 'button', class: 'tree-path-btn', onClick: (e) => { e.preventDefault(); copyText(jsonPath, `Copied ${jsonPath}`); } }, jsonPath),
116
+ ),
117
+ h('div', { class: 'tree-children' }, childNodes),
118
+ );
119
+ }
120
+
121
+ function renderJsonTree() {
122
+ treeBox.textContent = '';
123
+ try {
124
+ const parsed = JSON.parse(inputArea.value);
125
+ const filter = treeSearch.value.trim().toLowerCase();
126
+ const node = buildTreeNode('$', parsed, '$', 0, filter);
127
+ treeBox.appendChild(node || h('div', { class: 'finding info' }, 'No nodes match current filter.'));
128
+ } catch {
129
+ treeBox.appendChild(h('div', { class: 'finding info' }, 'Enter valid JSON in the converter input above to explore interactively.'));
130
+ }
131
+ }
132
+ treeSearch.addEventListener('input', renderJsonTree);
133
+ inputArea.addEventListener('input', renderJsonTree);
134
+
135
+ // SQL Formatter
136
+ const sqlIn = h('textarea', {
137
+ rows: 4,
138
+ value: "select u.id, u.email, count(o.id) as orders from users u left join orders o on o.user_id = u.id where u.active = true and u.tier = 'pro' group by u.id, u.email order by orders desc limit 25",
139
+ });
140
+ const sqlOut = h('pre', { class: 'code-box' }, '');
141
+ async function runSql() {
142
+ const res = await api('/api/sql/format', { body: { sql: sqlIn.value } });
143
+ sqlOut.textContent = res.formatted;
144
+ }
145
+
146
+ const layout = h(
147
+ 'div',
148
+ { class: 'stack' },
149
+ h(
150
+ 'div',
151
+ { class: 'card' },
152
+ h(
153
+ 'div',
154
+ { class: 'row-between' },
155
+ h(
156
+ 'div',
157
+ { class: 'row' },
158
+ h('span', { style: { fontSize: '12px', color: 'var(--text-muted)' } }, 'From'),
159
+ fromSel,
160
+ h('span', { style: { fontSize: '12px', color: 'var(--text-muted)' } }, '-> To'),
161
+ toSel,
162
+ h('label', { class: 'row', style: { fontSize: '12px' } }, sortKeysChk, 'Sort Keys'),
163
+ h('label', { class: 'row', style: { fontSize: '12px' } }, minifyChk, 'Minify'),
164
+ ),
165
+ h(
166
+ 'div',
167
+ { class: 'row' },
168
+ h('button', { type: 'button', class: 'btn btn-primary btn-sm', onClick: doConvert }, 'Convert'),
169
+ h('button', { type: 'button', class: 'btn btn-ghost btn-sm', onClick: () => copyText(outputPre.textContent) }, 'Copy Output'),
170
+ ),
171
+ ),
172
+ h('div', { class: 'grid-2' }, inputArea, outputPre),
173
+ ),
174
+ h(
175
+ 'div',
176
+ { class: 'grid-2' },
177
+ h(
178
+ 'div',
179
+ { class: 'card' },
180
+ h('h2', { class: 'card-title' }, 'JSONPath Evaluator (queries input JSON above)'),
181
+ h('div', { class: 'row' }, h('div', { style: { flex: '1' } }, jpInput), h('button', { type: 'button', class: 'btn btn-sm', onClick: runJsonPath }, 'Evaluate')),
182
+ jpOut,
183
+ ),
184
+ h(
185
+ 'div',
186
+ { class: 'card' },
187
+ h('div', { class: 'row-between' }, h('h2', { class: 'card-title' }, 'Interactive JSON Tree Explorer'), h('span', { class: 'badge badge-subtle' }, 'Click any path to copy')),
188
+ treeSearch,
189
+ treeBox,
190
+ ),
191
+ ),
192
+ h(
193
+ 'div',
194
+ { class: 'card' },
195
+ h(
196
+ 'div',
197
+ { class: 'row-between' },
198
+ h('h2', { class: 'card-title' }, 'SQL Formatter'),
199
+ h('div', { class: 'row' }, h('button', { type: 'button', class: 'btn btn-sm', onClick: runSql }, 'Format SQL'), h('button', { type: 'button', class: 'btn btn-ghost btn-xs', onClick: () => copyText(sqlOut.textContent) }, 'Copy')),
200
+ ),
201
+ sqlIn,
202
+ sqlOut,
203
+ ),
204
+ );
205
+
206
+ root.appendChild(layout);
207
+ void doConvert();
208
+ void runJsonPath();
209
+ renderJsonTree();
210
+ void runSql();
211
+ },
212
+ });
213
+
214
+ // ───────────────────────────────────────────────────────────────────────────
215
+ // 6. Diff Studio (Text Line Diff & Semantic JSON Diff)
216
+ // ───────────────────────────────────────────────────────────────────────────
217
+ registerTool({
218
+ id: 'diff-studio',
219
+ group: 'Data & Code',
220
+ name: 'Diff Studio',
221
+ icon: '±',
222
+ subtitle: 'Exact LCS line-by-line diff & order-independent Semantic JSON structural diff',
223
+ keywords: ['diff', 'compare', 'json diff', 'patch', 'semantic'],
224
+ render(root) {
225
+ let mode = 'json';
226
+ const leftArea = h('textarea', {
227
+ rows: 10,
228
+ value: JSON.stringify({ name: 'devanvil', version: '0.9.0', security: { ssrf: true, csp: 'strict' }, tags: ['cli', 'web'] }, null, 2),
229
+ });
230
+ const rightArea = h('textarea', {
231
+ rows: 10,
232
+ value: JSON.stringify({ version: '1.0.0', name: 'devanvil', tags: ['cli', 'web', 'offline'], security: { csp: 'strict', ssrf: true, zeroDeps: true } }, null, 2),
233
+ });
234
+ const statsRow = h('div', { class: 'row' });
235
+ const resultBox = h('div', {});
236
+
237
+ async function runDiff() {
238
+ try {
239
+ const res = await api('/api/diff', { body: { left: leftArea.value, right: rightArea.value, mode } });
240
+ statsRow.textContent = '';
241
+ resultBox.textContent = '';
242
+
243
+ if (mode === 'json') {
244
+ statsRow.appendChild(h('span', { class: `badge ${res.equal ? 'badge-ok' : 'badge-warn'}` }, res.equal ? 'Semantically Identical' : `${res.changes.length} structural change(s)`));
245
+ statsRow.appendChild(h('span', { class: 'badge badge-ok' }, `+${res.summary.added} added`));
246
+ statsRow.appendChild(h('span', { class: 'badge badge-err' }, `-${res.summary.removed} removed`));
247
+ statsRow.appendChild(h('span', { class: 'badge badge-info' }, `~${res.summary.changed} changed`));
248
+ const list = h('div', { class: 'stack' });
249
+ if (res.equal) {
250
+ list.appendChild(h('div', { class: 'finding pass' }, 'No semantic differences (key order differences are ignored).'));
251
+ }
252
+ for (const ch of res.changes) {
253
+ const cls = ch.kind === 'added' ? 'pass' : ch.kind === 'removed' ? 'critical' : 'warning';
254
+ list.appendChild(
255
+ h(
256
+ 'div',
257
+ { class: `finding ${cls}` },
258
+ h('span', { class: 'mono', style: { fontWeight: '700' } }, ch.path),
259
+ h('span', { class: 'badge badge-subtle' }, ch.kind),
260
+ h('span', { class: 'mono' }, `${ch.before !== undefined ? JSON.stringify(ch.before) : ''}${ch.before !== undefined && ch.after !== undefined ? ' -> ' : ''}${ch.after !== undefined ? JSON.stringify(ch.after) : ''}`),
261
+ ),
262
+ );
263
+ }
264
+ resultBox.appendChild(list);
265
+ } else {
266
+ statsRow.appendChild(h('span', { class: 'badge badge-ok' }, `+${res.stats.added} added`));
267
+ statsRow.appendChild(h('span', { class: 'badge badge-err' }, `-${res.stats.removed} removed`));
268
+ statsRow.appendChild(h('span', { class: 'badge badge-subtle' }, `${res.stats.unchanged} unchanged`));
269
+ const diffList = h('div', { class: 'diff-list' });
270
+ for (const ln of res.lines) {
271
+ const prefix = ln.type === 'add' ? '+' : ln.type === 'remove' ? '-' : ' ';
272
+ diffList.appendChild(
273
+ h(
274
+ 'div',
275
+ { class: `diff-row ${ln.type}` },
276
+ h('span', { class: 'diff-ln' }, ln.leftLine ?? ''),
277
+ h('span', { class: 'diff-ln' }, ln.rightLine ?? ''),
278
+ h('span', {}, prefix),
279
+ h('span', {}, ln.text),
280
+ ),
281
+ );
282
+ }
283
+ resultBox.appendChild(diffList);
284
+ }
285
+ } catch (err) {
286
+ toast(err.message, 'err');
287
+ }
288
+ }
289
+
290
+ const modeTabs = h('div', { class: 'tabs' });
291
+ [
292
+ ['json', 'Semantic JSON Diff'],
293
+ ['text', 'Line-by-Line Text Diff'],
294
+ ].forEach(([m, label]) => {
295
+ const btn = h(
296
+ 'button',
297
+ {
298
+ type: 'button',
299
+ class: `tab-btn ${mode === m ? 'active' : ''}`,
300
+ onClick: () => {
301
+ mode = m;
302
+ Array.from(modeTabs.children).forEach((el) => el.classList.remove('active'));
303
+ btn.classList.add('active');
304
+ void runDiff();
305
+ },
306
+ },
307
+ label,
308
+ );
309
+ modeTabs.appendChild(btn);
310
+ });
311
+
312
+ const layout = h(
313
+ 'div',
314
+ { class: 'stack' },
315
+ h(
316
+ 'div',
317
+ { class: 'card' },
318
+ h('div', { class: 'row-between' }, modeTabs, h('button', { type: 'button', class: 'btn btn-primary btn-sm', onClick: runDiff }, 'Compare')),
319
+ h('div', { class: 'grid-2' }, h('div', {}, h('label', { class: 'field-label' }, 'Original (Left)'), leftArea), h('div', {}, h('label', { class: 'field-label' }, 'Modified (Right)'), rightArea)),
320
+ ),
321
+ h('div', { class: 'card' }, h('div', { class: 'row-between' }, h('h2', { class: 'card-title' }, 'Diff Output'), statsRow), resultBox),
322
+ );
323
+
324
+ root.appendChild(layout);
325
+ void runDiff();
326
+ },
327
+ });
328
+
329
+ // ───────────────────────────────────────────────────────────────────────────
330
+ // 7. Visual Regex & ReDoS Lab
331
+ // ───────────────────────────────────────────────────────────────────────────
332
+ registerTool({
333
+ id: 'regex-lab',
334
+ group: 'Data & Code',
335
+ name: 'Regex & ReDoS Lab',
336
+ icon: '/.*/',
337
+ subtitle: 'Timeout-guarded live regex tester, highlight matches, AST token explainer & ReDoS detector',
338
+ keywords: ['regex', 'regexp', 'redos', 'match', 'replace', 'pattern'],
339
+ render(root) {
340
+ const patternIn = h('input', {
341
+ type: 'text',
342
+ class: 'mono',
343
+ value: '(?<user>[a-zA-Z0-9._%+-]+)@(?<domain>[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,})',
344
+ style: { flex: '1' },
345
+ });
346
+ const flagsIn = h('input', { type: 'text', class: 'mono', value: 'g', style: { width: '75px' }, title: 'Flags (g, i, m, s, u)' });
347
+ const textIn = h('textarea', {
348
+ rows: 5,
349
+ value: 'Send alerts to security@devanvil.local or maintainers+ci@github.com before v1.0.0.',
350
+ });
351
+ const replaceIn = h('input', { type: 'text', class: 'mono', value: '[$<user> at $<domain>]', placeholder: 'Optional replacement string…' });
352
+
353
+ const presetRow = h('div', { class: 'row' });
354
+ const metaRow = h('div', { class: 'row' });
355
+ const highlightBox = h('div', { class: 'code-box' });
356
+ const redosBox = h('div', { class: 'stack' });
357
+ const explainBox = h('div', { class: 'stack' });
358
+ const replacePre = h('pre', { class: 'code-box' }, '');
359
+
360
+ function renderHighlighted(text, matches) {
361
+ highlightBox.textContent = '';
362
+ let pos = 0;
363
+ for (const m of matches) {
364
+ if (m.index > pos) {
365
+ highlightBox.appendChild(document.createTextNode(text.slice(pos, m.index)));
366
+ }
367
+ highlightBox.appendChild(h('mark', { class: 'regex-mark' }, text.slice(m.index, m.end)));
368
+ pos = Math.max(pos, m.end);
369
+ }
370
+ if (pos < text.length) {
371
+ highlightBox.appendChild(document.createTextNode(text.slice(pos)));
372
+ }
373
+ }
374
+
375
+ async function runRegex() {
376
+ try {
377
+ const res = await api('/api/regex/test', {
378
+ body: { pattern: patternIn.value, flags: flagsIn.value, text: textIn.value, replacement: replaceIn.value },
379
+ });
380
+ metaRow.textContent = '';
381
+ metaRow.appendChild(h('span', { class: 'badge badge-info' }, `${res.matchCount} match(es)`));
382
+ metaRow.appendChild(h('span', { class: 'badge badge-subtle' }, `${res.executionMs}ms`));
383
+ const riskCls = res.redos.risk === 'safe' ? 'badge-ok' : res.redos.risk === 'caution' ? 'badge-warn' : 'badge-err';
384
+ metaRow.appendChild(h('span', { class: `badge ${riskCls}` }, `ReDoS Risk: ${res.redos.risk.toUpperCase()}`));
385
+
386
+ renderHighlighted(textIn.value, res.matches);
387
+ replacePre.textContent = res.replaced ?? '';
388
+
389
+ redosBox.textContent = '';
390
+ for (const f of res.redos.findings) {
391
+ const cls = res.redos.risk === 'high' ? 'critical' : res.redos.risk === 'caution' ? 'warning' : 'pass';
392
+ redosBox.appendChild(h('div', { class: `finding ${cls}` }, f));
393
+ }
394
+
395
+ explainBox.textContent = '';
396
+ for (const tok of res.explanation) {
397
+ explainBox.appendChild(
398
+ h(
399
+ 'div',
400
+ { class: 'row-between', style: { padding: '5px 8px', background: 'var(--bg-input)', borderRadius: '6px', border: '1px solid var(--border)' } },
401
+ h('code', { class: 'mono', style: { color: 'var(--accent)', fontWeight: '700' } }, tok.token),
402
+ h('span', { style: { fontSize: '12px', color: 'var(--text-muted)' } }, tok.description),
403
+ ),
404
+ );
405
+ }
406
+ } catch (err) {
407
+ metaRow.textContent = '';
408
+ metaRow.appendChild(h('span', { class: 'badge badge-err' }, err.message));
409
+ toast(err.message, 'err');
410
+ }
411
+ }
412
+
413
+ async function loadPresets() {
414
+ const { presets } = await api('/api/regex/presets');
415
+ presetRow.textContent = '';
416
+ for (const p of presets) {
417
+ presetRow.appendChild(
418
+ h(
419
+ 'button',
420
+ {
421
+ type: 'button',
422
+ class: 'btn btn-ghost btn-xs',
423
+ onClick: () => {
424
+ patternIn.value = p.pattern;
425
+ flagsIn.value = p.flags;
426
+ textIn.value = p.sample;
427
+ void runRegex();
428
+ },
429
+ },
430
+ p.name,
431
+ ),
432
+ );
433
+ }
434
+ }
435
+
436
+ const layout = h(
437
+ 'div',
438
+ { class: 'stack' },
439
+ h(
440
+ 'div',
441
+ { class: 'card' },
442
+ h('div', { class: 'row' }, patternIn, flagsIn, h('button', { type: 'button', class: 'btn btn-primary', onClick: runRegex }, 'Test Regex')),
443
+ h('div', { class: 'row' }, h('span', { style: { fontSize: '11.5px', color: 'var(--text-dim)' } }, 'Presets:'), presetRow),
444
+ metaRow,
445
+ h('div', { class: 'grid-2' }, h('div', {}, h('label', { class: 'field-label' }, 'Test String'), textIn), h('div', {}, h('label', { class: 'field-label' }, 'Highlighted Matches'), highlightBox)),
446
+ h('div', {}, h('label', { class: 'field-label' }, 'Replace Pattern'), replaceIn),
447
+ replacePre,
448
+ ),
449
+ h(
450
+ 'div',
451
+ { class: 'grid-2' },
452
+ h('div', { class: 'card' }, h('h2', { class: 'card-title' }, 'ReDoS Static Security Analysis'), redosBox),
453
+ h('div', { class: 'card' }, h('h2', { class: 'card-title' }, 'Token-by-Token Explanation'), explainBox),
454
+ ),
455
+ );
456
+
457
+ root.appendChild(layout);
458
+ void loadPresets();
459
+ void runRegex();
460
+ },
461
+ });
462
+
463
+ // ───────────────────────────────────────────────────────────────────────────
464
+ // 8. Visual Composable Data Pipeline Lab ("Recipes")
465
+ // ───────────────────────────────────────────────────────────────────────────
466
+ registerTool({
467
+ id: 'pipeline-lab',
468
+ group: 'Data & Code',
469
+ name: 'Pipeline Lab',
470
+ icon: '⛓',
471
+ subtitle: 'Chain encoding, compression, JSONPath, YAML, Regex & crypto steps with live trace',
472
+ keywords: ['pipeline', 'recipe', 'cyberchef', 'chain', 'transform', 'workflow'],
473
+ render(root) {
474
+ let opsCatalog = [];
475
+ let steps = [
476
+ { op: 'base64_decode', enabled: true },
477
+ { op: 'json_sort', enabled: true },
478
+ { op: 'json_to_yaml', enabled: true },
479
+ ];
480
+
481
+ const inputArea = h('textarea', {
482
+ rows: 5,
483
+ value: btoa('{"z_mode":"offline","a_tool":"DevAnvil","deps":0,"features":["mock","jwt","pipeline"]}'),
484
+ });
485
+ const opSelect = h('select', { style: { flex: '1' } });
486
+ const stepsBox = h('div', { class: 'stack' });
487
+ const finalOut = h('pre', { class: 'code-box', style: { minHeight: '160px' } }, '');
488
+ const traceBox = h('div', { class: 'stack' });
489
+
490
+ function renderSteps() {
491
+ stepsBox.textContent = '';
492
+ steps.forEach((step, idx) => {
493
+ const meta = opsCatalog.find((o) => o.id === step.op) || { label: step.op };
494
+ const row = h(
495
+ 'div',
496
+ { class: 'list-item' },
497
+ h(
498
+ 'div',
499
+ { class: 'row-between' },
500
+ h('div', { class: 'row' }, h('span', { class: 'badge badge-subtle' }, `#${idx + 1}`), h('strong', {}, meta.label)),
501
+ h(
502
+ 'div',
503
+ { class: 'row' },
504
+ h(
505
+ 'button',
506
+ {
507
+ type: 'button',
508
+ class: 'btn btn-ghost btn-xs',
509
+ disabled: idx === 0,
510
+ onClick: () => {
511
+ const tmp = steps[idx - 1];
512
+ steps[idx - 1] = steps[idx];
513
+ steps[idx] = tmp;
514
+ renderSteps();
515
+ void executePipeline();
516
+ },
517
+ },
518
+ '↑',
519
+ ),
520
+ h(
521
+ 'button',
522
+ {
523
+ type: 'button',
524
+ class: 'btn btn-ghost btn-xs',
525
+ disabled: idx === steps.length - 1,
526
+ onClick: () => {
527
+ const tmp = steps[idx + 1];
528
+ steps[idx + 1] = steps[idx];
529
+ steps[idx] = tmp;
530
+ renderSteps();
531
+ void executePipeline();
532
+ },
533
+ },
534
+ '↓',
535
+ ),
536
+ h(
537
+ 'button',
538
+ {
539
+ type: 'button',
540
+ class: 'btn btn-danger btn-xs',
541
+ onClick: () => {
542
+ steps.splice(idx, 1);
543
+ renderSteps();
544
+ void executePipeline();
545
+ },
546
+ },
547
+ 'Remove',
548
+ ),
549
+ ),
550
+ ),
551
+ meta.arg1Label
552
+ ? h('input', {
553
+ type: 'text',
554
+ class: 'mono',
555
+ value: step.arg1 || '',
556
+ placeholder: meta.arg1Label,
557
+ onInput: (e) => {
558
+ step.arg1 = e.target.value;
559
+ },
560
+ })
561
+ : null,
562
+ meta.arg2Label
563
+ ? h('input', {
564
+ type: 'text',
565
+ class: 'mono',
566
+ value: step.arg2 || '',
567
+ placeholder: meta.arg2Label,
568
+ onInput: (e) => {
569
+ step.arg2 = e.target.value;
570
+ },
571
+ })
572
+ : null,
573
+ );
574
+ stepsBox.appendChild(row);
575
+ });
576
+ }
577
+
578
+ async function executePipeline() {
579
+ try {
580
+ const res = await api('/api/pipeline/run', { body: { input: inputArea.value, steps } });
581
+ finalOut.textContent = res.output;
582
+ traceBox.textContent = '';
583
+ for (const st of res.steps) {
584
+ traceBox.appendChild(
585
+ h(
586
+ 'div',
587
+ { class: `finding ${st.error ? 'critical' : 'pass'}` },
588
+ h('span', { class: 'mono', style: { fontWeight: '700' } }, `#${st.index + 1} ${st.op}`),
589
+ h('span', { class: 'badge badge-subtle' }, `${st.durationMs}ms`),
590
+ h('span', { class: 'mono', style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, st.error ? st.error : st.output.slice(0, 80)),
591
+ ),
592
+ );
593
+ }
594
+ } catch (err) {
595
+ toast(err.message, 'err');
596
+ }
597
+ }
598
+
599
+ async function initOps() {
600
+ const { operations } = await api('/api/pipeline/ops');
601
+ opsCatalog = operations;
602
+ opSelect.textContent = '';
603
+ for (const op of operations) {
604
+ opSelect.appendChild(h('option', { value: op.id }, `[${op.category}] ${op.label}`));
605
+ }
606
+ renderSteps();
607
+ void executePipeline();
608
+ }
609
+
610
+ const starterRecipes = [
611
+ {
612
+ label: 'Base64 -> Sort JSON -> YAML',
613
+ input: btoa('{"z_mode":"offline","a_tool":"DevAnvil","deps":0,"studios":13}'),
614
+ steps: [{ op: 'base64_decode', enabled: true }, { op: 'json_sort', enabled: true }, { op: 'json_to_yaml', enabled: true }],
615
+ },
616
+ {
617
+ label: 'Redact Secrets -> Pretty JSON',
618
+ input: '{"service":"billing","aws":"AKIAIOSFODNN7EXAMPLE","db":"postgres://admin:SecretPass99@db:5432/app"}',
619
+ steps: [{ op: 'redact_secrets', enabled: true }, { op: 'json_pretty', enabled: true }],
620
+ },
621
+ {
622
+ label: 'URL Decode -> JSON -> TS Types',
623
+ input: encodeURIComponent('{"user":{"id":42,"email":"ada@devanvil.local","active":true}}'),
624
+ steps: [{ op: 'url_decode', enabled: true }, { op: 'json_to_ts', enabled: true }],
625
+ },
626
+ {
627
+ label: 'Deduplicate & Sort Lines',
628
+ input: 'zebra\nalpha\nbeta\nalpha\ndelta\nzeta\nbeta',
629
+ steps: [{ op: 'unique_lines', enabled: true }, { op: 'sort_lines', enabled: true }],
630
+ },
631
+ ];
632
+
633
+ const recipeBar = h(
634
+ 'div',
635
+ { class: 'row' },
636
+ starterRecipes.map((rec) =>
637
+ h(
638
+ 'button',
639
+ {
640
+ type: 'button',
641
+ class: 'btn btn-ghost btn-xs',
642
+ onClick: () => {
643
+ inputArea.value = rec.input;
644
+ steps = rec.steps.map((s) => ({ ...s }));
645
+ renderSteps();
646
+ void executePipeline();
647
+ },
648
+ },
649
+ rec.label,
650
+ ),
651
+ ),
652
+ );
653
+
654
+ const layout = h(
655
+ 'div',
656
+ { class: 'grid-2' },
657
+ h(
658
+ 'div',
659
+ { class: 'stack' },
660
+ h('div', { class: 'card' }, h('h2', { class: 'card-title' }, 'Pipeline Input & Starter Recipes'), recipeBar, inputArea),
661
+ h(
662
+ 'div',
663
+ { class: 'card' },
664
+ h('h2', { class: 'card-title' }, 'Recipe Steps'),
665
+ h(
666
+ 'div',
667
+ { class: 'row' },
668
+ opSelect,
669
+ h(
670
+ 'button',
671
+ {
672
+ type: 'button',
673
+ class: 'btn btn-sm',
674
+ onClick: () => {
675
+ steps.push({ op: opSelect.value, enabled: true });
676
+ renderSteps();
677
+ void executePipeline();
678
+ },
679
+ },
680
+ '+ Add Step',
681
+ ),
682
+ h('button', { type: 'button', class: 'btn btn-primary btn-sm', onClick: executePipeline }, 'Run Pipeline'),
683
+ ),
684
+ stepsBox,
685
+ ),
686
+ ),
687
+ h(
688
+ 'div',
689
+ { class: 'stack' },
690
+ h(
691
+ 'div',
692
+ { class: 'card' },
693
+ h('div', { class: 'row-between' }, h('h2', { class: 'card-title' }, 'Final Output'), h('button', { type: 'button', class: 'btn btn-ghost btn-xs', onClick: () => copyText(finalOut.textContent) }, 'Copy')),
694
+ finalOut,
695
+ ),
696
+ h('div', { class: 'card' }, h('h2', { class: 'card-title' }, 'Step-by-Step Execution Trace'), traceBox),
697
+ ),
698
+ );
699
+
700
+ root.appendChild(layout);
701
+ void initOps();
702
+ },
703
+ });
704
+ })();