@causyne/agent 1.20.120 → 1.20.121

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 (59) hide show
  1. package/package.json +1 -1
  2. package/src/agent/errorClassifier.js +113 -0
  3. package/src/agent/errorClassifier.ts +161 -0
  4. package/src/agent/promptIntent.js +200 -0
  5. package/src/agent/promptIntent.ts +203 -0
  6. package/src/agent/toolArgValidator.js +97 -0
  7. package/src/agent/toolArgValidator.ts +112 -0
  8. package/src/agentLoop.js +22 -339
  9. package/src/agentLoop.ts +40 -347
  10. package/src/autoUpdate.js +111 -8
  11. package/src/autoUpdate.ts +144 -8
  12. package/src/cliMode.js +16 -2
  13. package/src/commands.js +10 -9
  14. package/src/config.js +42 -63
  15. package/src/configVault.js +204 -0
  16. package/src/configVault.ts +213 -0
  17. package/src/core/contextCompactor.js +70 -11
  18. package/src/core/contextCompactor.ts +83 -11
  19. package/src/dynamicCatalogue.js +42 -73
  20. package/src/dynamicCatalogue.ts +74 -60
  21. package/src/entrypoint.js +77 -4
  22. package/src/headlessCli.js +304 -0
  23. package/src/headlessCli.ts +380 -0
  24. package/src/mcp/mcpClient.js +38 -11
  25. package/src/mcp/mcpClient.ts +44 -11
  26. package/src/mcp/mcpRegistry.js +2 -5
  27. package/src/mcp/mcpRegistry.ts +2 -5
  28. package/src/mcp/mcpSecurity.js +189 -0
  29. package/src/mcp/mcpSecurity.ts +190 -0
  30. package/src/osKeychain.js +209 -0
  31. package/src/osKeychain.ts +245 -0
  32. package/src/providers/anthropic.js +28 -11
  33. package/src/providers/byokHttp.js +354 -0
  34. package/src/providers/byokHttp.ts +454 -0
  35. package/src/providers/byokStream.js +657 -0
  36. package/src/providers/byokStream.ts +759 -0
  37. package/src/providers/dashscope-byok.js +34 -25
  38. package/src/providers/deepseek.js +31 -22
  39. package/src/providers/gemini.js +40 -13
  40. package/src/providers/moonshot.js +31 -22
  41. package/src/providers/muse.js +10 -10
  42. package/src/providers/ollama.js +25 -10
  43. package/src/providers/openai-compatible.js +46 -14
  44. package/src/providers/openrouter.js +63 -29
  45. package/src/providers/openrouter.ts +73 -29
  46. package/src/providers/qwen-byok.js +33 -16
  47. package/src/providers/xai.js +31 -22
  48. package/src/sandbox.js +77 -56
  49. package/src/sandboxPolicy.js +1208 -0
  50. package/src/sandboxPolicy.ts +1300 -0
  51. package/src/sessionJournal.js +47 -0
  52. package/src/sessionJournal.ts +49 -0
  53. package/src/tools/osSandbox.js +473 -0
  54. package/src/tools/osSandbox.ts +554 -0
  55. package/src/tools/persistentShell.js +8 -3
  56. package/src/tools/subprocessEnv.js +197 -0
  57. package/src/tools/subprocessEnv.ts +212 -0
  58. package/src/tools/sysRun.js +39 -6
  59. package/src/tools/sysRun.ts +53 -7
@@ -0,0 +1,1300 @@
1
+ /**
2
+ * Causyne Agent — Sandbox Workspace, Credential & Shell Command Policy
3
+ *
4
+ * Linear-time (O(n), zero ReDoS) security helpers supporting `src/sandbox.js`:
5
+ * 1. Canonical blocked-workspace-root checks (POSIX + Windows + symlink resolution)
6
+ * enforced uniformly by both `updateWorkspacePaths()` and `addWorkspacePath()`.
7
+ * 2. Expanded credential-path recognition (`.env*` excluding example/sample/template
8
+ * files, `.envrc`, `.git-credentials`, `.pypirc`, `.pgpass`, `.my.cnf`, private
9
+ * SSH key filenames, and cloud service-account credential JSONs).
10
+ * 3. Quote-aware shell parser that extracts nested command substitutions
11
+ * (`$(...)` and backticks, including inside double quotes), strips leading env
12
+ * assignments and wrapper commands (`env`, `command`, `nohup`, `nice`, `time`,
13
+ * `timeout`, `exec`, `stdbuf`, `builtin`, `caffeinate`), resolves absolute
14
+ * executable basenames (`/bin/rm` -> `rm`), and extracts redirection + `tee`
15
+ * write targets even when quoted or prefixed with `$HOME`.
16
+ */
17
+
18
+ import os from 'node:os';
19
+ import path from 'node:path';
20
+ import { isWithinPhysicalPath, physicalPath } from './agent/workspaceBoundary.js';
21
+
22
+ const MAX_SUBSTITUTION_DEPTH = 16;
23
+
24
+ const SAFE_ENV_TEMPLATE_EXACT = new Set([
25
+ '.env.example',
26
+ '.env.sample',
27
+ '.env.template',
28
+ '.env.dist',
29
+ '.env.defaults',
30
+ '.env.schema'
31
+ ]);
32
+
33
+ const SAFE_ENV_TEMPLATE_SUFFIXES = [
34
+ '.example',
35
+ '.sample',
36
+ '.template',
37
+ '.dist'
38
+ ];
39
+
40
+ const CREDENTIAL_DIR_SEGMENTS = new Set([
41
+ '.ssh',
42
+ '.aws',
43
+ '.gnupg',
44
+ '.kube',
45
+ '.causyne'
46
+ ]);
47
+
48
+ const CREDENTIAL_EXACT_BASENAMES = new Set([
49
+ '.netrc',
50
+ '.npmrc',
51
+ '.envrc',
52
+ '.git-credentials',
53
+ '.pypirc',
54
+ '.pgpass',
55
+ '.my.cnf',
56
+ 'id_rsa',
57
+ 'id_ed25519',
58
+ 'id_ecdsa',
59
+ 'id_dsa',
60
+ 'credentials.json',
61
+ 'application_default_credentials.json'
62
+ ]);
63
+
64
+ const SENSITIVE_WRITE_EXACT_BASENAMES = new Set([
65
+ '.bashrc',
66
+ '.bash_profile',
67
+ '.bash_login',
68
+ '.profile',
69
+ '.zshrc',
70
+ '.zprofile',
71
+ '.zshenv',
72
+ '.zlogin',
73
+ '.npmrc',
74
+ '.netrc',
75
+ '.git-credentials',
76
+ '.pypirc',
77
+ '.envrc'
78
+ ]);
79
+
80
+ const SHELL_INTERPRETERS = new Set([
81
+ 'sh',
82
+ 'bash',
83
+ 'zsh',
84
+ 'dash',
85
+ 'ksh',
86
+ 'fish',
87
+ 'ash',
88
+ 'pwsh',
89
+ 'powershell'
90
+ ]);
91
+
92
+ const LEADING_SHELL_KEYWORDS = new Set([
93
+ '!',
94
+ '(',
95
+ '{',
96
+ 'if',
97
+ 'then',
98
+ 'else',
99
+ 'elif',
100
+ 'do',
101
+ 'while',
102
+ 'until',
103
+ 'case'
104
+ ]);
105
+
106
+ const POSIX_TEMP_ALLOWLIST = [
107
+ '/tmp',
108
+ '/private/tmp',
109
+ '/private/var/tmp',
110
+ '/private/var/folders',
111
+ '/var/tmp',
112
+ '/var/folders'
113
+ ];
114
+
115
+ const POSIX_BLOCKED_WORKSPACE_ROOTS = [
116
+ '/etc',
117
+ '/private/etc',
118
+ '/usr',
119
+ '/bin',
120
+ '/sbin',
121
+ '/System',
122
+ '/var',
123
+ '/private',
124
+ '/Library',
125
+ '/dev',
126
+ '/proc',
127
+ '/sys',
128
+ '/boot',
129
+ '/root'
130
+ ];
131
+
132
+ function expandLeadingTilde(targetPath: string): string {
133
+ if (targetPath === '~') return os.homedir();
134
+ if (targetPath.startsWith('~/') || targetPath.startsWith('~\\')) {
135
+ return path.join(os.homedir(), targetPath.slice(2));
136
+ }
137
+ return targetPath;
138
+ }
139
+
140
+ function isWithinForPlatform(child: string, parent: string, platform: NodeJS.Platform): boolean {
141
+ if (platform === 'win32') {
142
+ const rel = path.win32.relative(parent.toLowerCase(), child.toLowerCase());
143
+ return rel === '' || (rel !== '..' && !rel.startsWith('..\\') && !path.win32.isAbsolute(rel));
144
+ }
145
+ return isWithinPhysicalPath(child, parent);
146
+ }
147
+
148
+ function isBlockedResolvedRoot(candidate: string, platform: NodeJS.Platform): boolean {
149
+ const pathApi = platform === 'win32' ? path.win32 : path.posix;
150
+ const parsedRoot = pathApi.parse(candidate).root;
151
+ if (parsedRoot && candidate.toLowerCase() === parsedRoot.toLowerCase()) {
152
+ return true;
153
+ }
154
+
155
+ if (platform === 'win32') {
156
+ const sysRoot = process.env.SystemRoot || process.env.SYSTEMROOT || 'C:\\Windows';
157
+ const winBlocked = [
158
+ sysRoot,
159
+ 'C:\\Windows',
160
+ 'C:\\Program Files',
161
+ 'C:\\Program Files (x86)',
162
+ 'C:\\ProgramData',
163
+ 'C:\\System Volume Information'
164
+ ];
165
+ return winBlocked.some(root => isWithinForPlatform(candidate, root, 'win32'));
166
+ }
167
+
168
+ if (POSIX_TEMP_ALLOWLIST.some(allowed => isWithinForPlatform(candidate, allowed, platform))) {
169
+ return false;
170
+ }
171
+
172
+ return POSIX_BLOCKED_WORKSPACE_ROOTS.some(root => isWithinForPlatform(candidate, root, platform));
173
+ }
174
+
175
+ /**
176
+ * Returns true if `targetPath` is a system-critical root, filesystem root,
177
+ * invalid/dangling symlink, or resolves via symlinks into a blocked system root.
178
+ * Used uniformly by `updateWorkspacePaths()` and `addWorkspacePath()`.
179
+ */
180
+ export function isBlockedWorkspaceRoot(
181
+ targetPath: string,
182
+ options?: { platform?: NodeJS.Platform | undefined }
183
+ ): boolean {
184
+ if (typeof targetPath !== 'string' || targetPath.trim().length === 0) return true;
185
+ const platform = options?.platform ?? process.platform;
186
+ const expanded = expandLeadingTilde(targetPath.trim());
187
+ const resolved = platform === 'win32' ? path.win32.resolve(expanded) : path.resolve(expanded);
188
+
189
+ if (isBlockedResolvedRoot(resolved, platform)) return true;
190
+
191
+ if (platform === process.platform) {
192
+ const realTarget = physicalPath(resolved);
193
+ if (!realTarget) return true;
194
+ if (isBlockedResolvedRoot(realTarget, platform)) return true;
195
+ }
196
+
197
+ return false;
198
+ }
199
+
200
+ /**
201
+ * Recognizes credential stores, private key files, and secret env files
202
+ * without backtracking regexes. Explicitly excludes `.env.example`, `.env.sample`,
203
+ * `.env.template`, and `.env.dist` templates to prevent developer false positives.
204
+ */
205
+ export function isExtendedCredentialPath(targetPath: string): boolean {
206
+ if (typeof targetPath !== 'string' || targetPath.length === 0) return false;
207
+ const normalized = targetPath.replace(/\\/g, '/').trim();
208
+ if (!normalized) return false;
209
+
210
+ const trimmed = normalized.endsWith('/') && normalized.length > 1
211
+ ? normalized.slice(0, -1)
212
+ : normalized;
213
+ const parts = trimmed.split('/').filter(Boolean);
214
+ if (parts.length === 0) return false;
215
+
216
+ const lowerParts = parts.map(p => p.toLowerCase());
217
+
218
+ for (const part of lowerParts) {
219
+ if (CREDENTIAL_DIR_SEGMENTS.has(part)) return true;
220
+ }
221
+
222
+ for (let i = 0; i < lowerParts.length - 1; i++) {
223
+ if (lowerParts[i] === 'library' && lowerParts[i + 1] === 'keychains') return true;
224
+ if (lowerParts[i] === '.docker' && lowerParts[i + 1] === 'config.json') return true;
225
+ }
226
+
227
+ const baseLower = lowerParts[lowerParts.length - 1] ?? '';
228
+ if (CREDENTIAL_EXACT_BASENAMES.has(baseLower)) return true;
229
+
230
+ if (baseLower === '.env') return true;
231
+ if (baseLower.startsWith('.env.')) {
232
+ if (SAFE_ENV_TEMPLATE_EXACT.has(baseLower)) return false;
233
+ for (const suffix of SAFE_ENV_TEMPLATE_SUFFIXES) {
234
+ if (baseLower.endsWith(suffix)) return false;
235
+ }
236
+ return true;
237
+ }
238
+
239
+ if (
240
+ (baseLower.startsWith('service-account') || baseLower.startsWith('service_account')) &&
241
+ baseLower.endsWith('.json')
242
+ ) {
243
+ return true;
244
+ }
245
+
246
+ return false;
247
+ }
248
+
249
+ /**
250
+ * Returns true if a file target is a high-risk persistence or credential target
251
+ * for shell redirection (`>`, `>>`) or `tee`.
252
+ */
253
+ export function isSensitiveWriteTarget(rawTarget: string): boolean {
254
+ if (typeof rawTarget !== 'string' || rawTarget.length === 0) return false;
255
+
256
+ let target = rawTarget.trim();
257
+ if (
258
+ (target.startsWith('"') && target.endsWith('"') && target.length >= 2) ||
259
+ (target.startsWith("'") && target.endsWith("'") && target.length >= 2)
260
+ ) {
261
+ target = target.slice(1, -1);
262
+ }
263
+ target = target.replace(/\\/g, '/');
264
+
265
+ // Normalize common home-directory expansions for matching
266
+ if (target === '~' || target.startsWith('~/')) {
267
+ target = `/home/user${target.slice(1)}`;
268
+ } else if (target.startsWith('$home/') || target.startsWith('${home}/')) {
269
+ const slash = target.indexOf('/');
270
+ target = `/home/user${target.slice(slash)}`;
271
+ } else if (target.startsWith('$HOME/') || target.startsWith('${HOME}/')) {
272
+ const slash = target.indexOf('/');
273
+ target = `/home/user${target.slice(slash)}`;
274
+ }
275
+
276
+ const lower = target.toLowerCase();
277
+ const parts = lower.split('/').filter(Boolean);
278
+ if (parts.length === 0) return false;
279
+
280
+ const base = parts[parts.length - 1] ?? '';
281
+ if (SENSITIVE_WRITE_EXACT_BASENAMES.has(base)) return true;
282
+
283
+ // Protected system / persistence directories
284
+ if (lower.startsWith('/etc/') || lower === '/etc' || lower.includes('/etc/')) return true;
285
+
286
+ for (let i = 0; i < parts.length; i++) {
287
+ const seg = parts[i];
288
+ if (seg === '.ssh' || seg === '.causyne' || seg === '.aws' || seg === '.kube' || seg === '.gnupg') {
289
+ return true;
290
+ }
291
+ if (seg === 'crontab' || seg === 'cron.d') return true;
292
+ if (seg === '.git' && (parts[i + 1] === 'hooks' || parts[i + 1] === 'config')) return true;
293
+ if (seg === '.docker' && parts[i + 1] === 'config.json') return true;
294
+ if (seg === '.config' && parts[i + 1] === 'fish' && parts[i + 2] === 'config.fish') return true;
295
+ }
296
+
297
+ return false;
298
+ }
299
+
300
+ interface ParsedMaskResult {
301
+ masked: string;
302
+ substitutions: string[];
303
+ }
304
+
305
+ /**
306
+ * Single-pass quote-aware scanner that masks literal single/double-quoted text
307
+ * while extracting executable command substitutions (`$(...)` and backticks)
308
+ * both outside quotes and inside double quotes (single quotes stay literal).
309
+ */
310
+ export function parseMaskAndExtractSubstitutions(
311
+ input: string,
312
+ depth = 0
313
+ ): ParsedMaskResult {
314
+ let masked = '';
315
+ const substitutions: string[] = [];
316
+ const len = input.length;
317
+ let i = 0;
318
+
319
+ while (i < len) {
320
+ const ch = input[i];
321
+
322
+ // Backslash escape outside quotes
323
+ if (ch === '\\' && i + 1 < len) {
324
+ masked += ch + input[i + 1];
325
+ i += 2;
326
+ continue;
327
+ }
328
+
329
+ // Single-quoted literal span (no variable or command substitution in POSIX)
330
+ if (ch === "'") {
331
+ i++;
332
+ while (i < len && input[i] !== "'") {
333
+ i++;
334
+ }
335
+ if (i < len) i++; // consume closing quote
336
+ masked += "''";
337
+ continue;
338
+ }
339
+
340
+ // Double-quoted span: literal text is masked, but `$(...)` and `` `...` `` EXECUTE!
341
+ if (ch === '"') {
342
+ i++;
343
+ while (i < len && input[i] !== '"') {
344
+ const inner = input[i];
345
+ if (inner === '\\' && i + 1 < len) {
346
+ i += 2;
347
+ continue;
348
+ }
349
+ if (inner === '$' && input[i + 1] === '(') {
350
+ const captured = readDollarSubshell(input, i + 2);
351
+ if (captured.content.trim().length > 0) {
352
+ substitutions.push(captured.content);
353
+ }
354
+ i = captured.nextIndex;
355
+ continue;
356
+ }
357
+ if (inner === '`') {
358
+ const captured = readBacktickSubshell(input, i + 1);
359
+ if (captured.content.trim().length > 0) {
360
+ substitutions.push(captured.content);
361
+ }
362
+ i = captured.nextIndex;
363
+ continue;
364
+ }
365
+ i++;
366
+ }
367
+ if (i < len) i++; // consume closing quote
368
+ masked += '""';
369
+ continue;
370
+ }
371
+
372
+ // Unquoted `$(...)` command substitution
373
+ if (ch === '$' && input[i + 1] === '(') {
374
+ const captured = readDollarSubshell(input, i + 2);
375
+ if (captured.content.trim().length > 0) {
376
+ substitutions.push(captured.content);
377
+ }
378
+ masked += ' ';
379
+ i = captured.nextIndex;
380
+ continue;
381
+ }
382
+
383
+ // Unquoted backtick command substitution
384
+ if (ch === '`') {
385
+ const captured = readBacktickSubshell(input, i + 1);
386
+ if (captured.content.trim().length > 0) {
387
+ substitutions.push(captured.content);
388
+ }
389
+ masked += ' ';
390
+ i = captured.nextIndex;
391
+ continue;
392
+ }
393
+
394
+ masked += ch;
395
+ i++;
396
+ }
397
+
398
+ if (depth < MAX_SUBSTITUTION_DEPTH && substitutions.length > 0) {
399
+ const nested: string[] = [];
400
+ for (const sub of substitutions) {
401
+ const parsed = parseMaskAndExtractSubstitutions(sub, depth + 1);
402
+ for (const deeper of parsed.substitutions) {
403
+ nested.push(deeper);
404
+ }
405
+ }
406
+ for (const deeper of nested) {
407
+ substitutions.push(deeper);
408
+ }
409
+ }
410
+
411
+ return { masked, substitutions };
412
+ }
413
+
414
+ function readDollarSubshell(input: string, startIndex: number): { content: string; nextIndex: number } {
415
+ const len = input.length;
416
+ let i = startIndex;
417
+ let parenDepth = 1;
418
+ let inSingle = false;
419
+ let inDouble = false;
420
+
421
+ while (i < len && parenDepth > 0) {
422
+ const ch = input[i];
423
+ if (inSingle) {
424
+ if (ch === "'") inSingle = false;
425
+ i++;
426
+ continue;
427
+ }
428
+ if (inDouble) {
429
+ if (ch === '\\' && i + 1 < len) {
430
+ i += 2;
431
+ continue;
432
+ }
433
+ if (ch === '"') inDouble = false;
434
+ i++;
435
+ continue;
436
+ }
437
+ if (ch === '\\' && i + 1 < len) {
438
+ i += 2;
439
+ continue;
440
+ }
441
+ if (ch === "'") {
442
+ inSingle = true;
443
+ i++;
444
+ continue;
445
+ }
446
+ if (ch === '"') {
447
+ inDouble = true;
448
+ i++;
449
+ continue;
450
+ }
451
+ if (ch === '(') {
452
+ parenDepth++;
453
+ i++;
454
+ continue;
455
+ }
456
+ if (ch === ')') {
457
+ parenDepth--;
458
+ if (parenDepth === 0) {
459
+ return { content: input.slice(startIndex, i), nextIndex: i + 1 };
460
+ }
461
+ i++;
462
+ continue;
463
+ }
464
+ i++;
465
+ }
466
+ return { content: input.slice(startIndex, i), nextIndex: i };
467
+ }
468
+
469
+ function readBacktickSubshell(input: string, startIndex: number): { content: string; nextIndex: number } {
470
+ const len = input.length;
471
+ let i = startIndex;
472
+ while (i < len) {
473
+ const ch = input[i];
474
+ if (ch === '\\' && i + 1 < len) {
475
+ i += 2;
476
+ continue;
477
+ }
478
+ if (ch === '`') {
479
+ return { content: input.slice(startIndex, i), nextIndex: i + 1 };
480
+ }
481
+ i++;
482
+ }
483
+ return { content: input.slice(startIndex, i), nextIndex: i };
484
+ }
485
+
486
+ /**
487
+ * Splits a masked shell command string into sequential command lists and
488
+ * pipe-connected pipeline groups while keeping `2>&1` / `>&2` descriptor
489
+ * duplications intact.
490
+ */
491
+ export function splitIntoPipelinesAndSegments(maskedText: string): {
492
+ segments: string[];
493
+ pipelines: string[][];
494
+ } {
495
+ const listGroups: string[] = [];
496
+ let current = '';
497
+ const len = maskedText.length;
498
+ let i = 0;
499
+
500
+ const pushGroup = (): void => {
501
+ const trimmed = current.trim();
502
+ if (trimmed.length > 0) listGroups.push(trimmed);
503
+ current = '';
504
+ };
505
+
506
+ while (i < len) {
507
+ const ch = maskedText[i]!;
508
+ const next = maskedText[i + 1];
509
+
510
+ if (ch === ';' || ch === '\n') {
511
+ pushGroup();
512
+ i++;
513
+ continue;
514
+ }
515
+ if (ch === '&' && next === '&') {
516
+ pushGroup();
517
+ i += 2;
518
+ continue;
519
+ }
520
+ if (ch === '|' && next === '|') {
521
+ pushGroup();
522
+ i += 2;
523
+ continue;
524
+ }
525
+ if (ch === '&') {
526
+ const prev = i > 0 ? maskedText[i - 1] : '';
527
+ // Keep `>&1`, `2>&1`, `<&0`, `&>` redirections intact
528
+ if (prev === '>' || prev === '<' || next === '>') {
529
+ current += ch;
530
+ i++;
531
+ continue;
532
+ }
533
+ pushGroup();
534
+ i++;
535
+ continue;
536
+ }
537
+
538
+ current += ch;
539
+ i++;
540
+ }
541
+ pushGroup();
542
+
543
+ const segments: string[] = [];
544
+ const pipelines: string[][] = [];
545
+
546
+ for (const group of listGroups) {
547
+ const stages: string[] = [];
548
+ let stage = '';
549
+ for (let j = 0; j < group.length; j++) {
550
+ const ch = group[j]!;
551
+ if (ch === '|') {
552
+ const trimmed = stage.trim();
553
+ if (trimmed.length > 0) {
554
+ stages.push(trimmed);
555
+ segments.push(trimmed);
556
+ }
557
+ stage = '';
558
+ continue;
559
+ }
560
+ stage += ch;
561
+ }
562
+ const trimmed = stage.trim();
563
+ if (trimmed.length > 0) {
564
+ stages.push(trimmed);
565
+ segments.push(trimmed);
566
+ }
567
+ if (stages.length > 0) {
568
+ pipelines.push(stages);
569
+ }
570
+ }
571
+
572
+ return { segments, pipelines };
573
+ }
574
+
575
+ function isEnvAssignmentToken(token: string): boolean {
576
+ const eq = token.indexOf('=');
577
+ if (eq <= 0) return false;
578
+ const name = token.slice(0, eq);
579
+ const first = name.charCodeAt(0);
580
+ const isFirstValid =
581
+ (first >= 97 && first <= 122) || // a-z
582
+ (first >= 65 && first <= 90) || // A-Z
583
+ first === 95; // _
584
+ if (!isFirstValid) return false;
585
+ for (let i = 1; i < name.length; i++) {
586
+ const code = name.charCodeAt(i);
587
+ const valid =
588
+ (code >= 97 && code <= 122) ||
589
+ (code >= 65 && code <= 90) ||
590
+ (code >= 48 && code <= 57) ||
591
+ code === 95;
592
+ if (!valid) return false;
593
+ }
594
+ return true;
595
+ }
596
+
597
+ function isStandaloneRedirectOperator(token: string): boolean {
598
+ return (
599
+ token === '>' ||
600
+ token === '>>' ||
601
+ token === '<' ||
602
+ token === '1>' ||
603
+ token === '1>>' ||
604
+ token === '2>' ||
605
+ token === '2>>' ||
606
+ token === '&>' ||
607
+ token === '&>>'
608
+ );
609
+ }
610
+
611
+ function isAttachedRedirectToken(token: string): boolean {
612
+ return (
613
+ token.startsWith('>') ||
614
+ token.startsWith('<') ||
615
+ token.startsWith('1>') ||
616
+ token.startsWith('2>') ||
617
+ token.startsWith('&>')
618
+ );
619
+ }
620
+
621
+ function resolveExecutableBasename(token: string): string {
622
+ const normalized = token.replace(/\\/g, '/');
623
+ const slash = normalized.lastIndexOf('/');
624
+ let base = slash !== -1 ? normalized.slice(slash + 1) : normalized;
625
+ if (base.endsWith('.exe') && base.length > 4) {
626
+ base = base.slice(0, -4);
627
+ }
628
+ return base;
629
+ }
630
+
631
+ export interface NormalizedSegment {
632
+ normalized: string;
633
+ executable: string;
634
+ args: string[];
635
+ isReadOnlyLookup: boolean;
636
+ }
637
+
638
+ /**
639
+ * Normalizes one already-lowercased, quote-masked shell segment by stripping
640
+ * leading env assignments (`FOO=1`), redirections, control keywords, and
641
+ * benign command wrappers (`env`, `command`, `nohup`, `nice`, `time`, `timeout`,
642
+ * `exec`, `stdbuf`, `builtin`, `caffeinate`), then resolving the executable
643
+ * basename (`/bin/rm` -> `rm`).
644
+ *
645
+ * Preserves read-only lookup semantics for `command -v` / `command -V` so
646
+ * existence probes do not trigger false alarms.
647
+ */
648
+ export function normalizeExecutableSegment(segment: string): NormalizedSegment {
649
+ const tokens = segment.trim().split(/\s+/).filter(Boolean);
650
+ let idx = 0;
651
+
652
+ // Bounded normalization loop
653
+ for (let guard = 0; guard < 32 && idx < tokens.length; guard++) {
654
+ const tok = tokens[idx]!;
655
+
656
+ // Strip leading parentheses attached to a token, e.g. `(rm`
657
+ if (tok.startsWith('(') && tok.length > 1) {
658
+ tokens[idx] = tok.slice(1);
659
+ continue;
660
+ }
661
+
662
+ if (LEADING_SHELL_KEYWORDS.has(tok)) {
663
+ idx++;
664
+ continue;
665
+ }
666
+
667
+ if (isStandaloneRedirectOperator(tok)) {
668
+ idx += 2; // operator + filename
669
+ continue;
670
+ }
671
+ if (isAttachedRedirectToken(tok)) {
672
+ idx++;
673
+ continue;
674
+ }
675
+
676
+ if (isEnvAssignmentToken(tok)) {
677
+ idx++;
678
+ continue;
679
+ }
680
+
681
+ const base = resolveExecutableBasename(tok);
682
+
683
+ if (base === 'env') {
684
+ idx++;
685
+ while (idx < tokens.length) {
686
+ const next = tokens[idx]!;
687
+ if (next === '--') {
688
+ idx++;
689
+ break;
690
+ }
691
+ if (next === '-u' || next === '-c' || next === '-s' || next === '--unset' || next === '--chdir') {
692
+ idx += 2;
693
+ continue;
694
+ }
695
+ if (next.startsWith('-')) {
696
+ idx++;
697
+ continue;
698
+ }
699
+ if (isEnvAssignmentToken(next)) {
700
+ idx++;
701
+ continue;
702
+ }
703
+ break;
704
+ }
705
+ continue;
706
+ }
707
+
708
+ if (base === 'command') {
709
+ let scan = idx + 1;
710
+ let isQueryOnly = false;
711
+ while (scan < tokens.length) {
712
+ const next = tokens[scan]!;
713
+ if (next === '--') {
714
+ scan++;
715
+ break;
716
+ }
717
+ if (next.startsWith('-') && next.length > 1) {
718
+ // POSIX `command -v` and `command -V` only look up the path; never execute
719
+ if (next.includes('v')) {
720
+ isQueryOnly = true;
721
+ }
722
+ scan++;
723
+ continue;
724
+ }
725
+ break;
726
+ }
727
+ if (isQueryOnly) {
728
+ const rest = tokens.slice(idx);
729
+ return {
730
+ normalized: rest.join(' '),
731
+ executable: 'command',
732
+ args: rest.slice(1),
733
+ isReadOnlyLookup: true
734
+ };
735
+ }
736
+ idx = scan;
737
+ continue;
738
+ }
739
+
740
+ if (base === 'nohup' || base === 'builtin') {
741
+ idx++;
742
+ if (tokens[idx] === '--') idx++;
743
+ continue;
744
+ }
745
+
746
+ if (base === 'time') {
747
+ idx++;
748
+ while (idx < tokens.length && tokens[idx]!.startsWith('-')) {
749
+ if (tokens[idx] === '--') {
750
+ idx++;
751
+ break;
752
+ }
753
+ idx++;
754
+ }
755
+ continue;
756
+ }
757
+
758
+ if (base === 'nice') {
759
+ idx++;
760
+ while (idx < tokens.length && tokens[idx]!.startsWith('-')) {
761
+ const flag = tokens[idx]!;
762
+ if (flag === '--') {
763
+ idx++;
764
+ break;
765
+ }
766
+ if (flag === '-n' || flag === '--adjustment') {
767
+ idx += 2;
768
+ continue;
769
+ }
770
+ idx++;
771
+ }
772
+ continue;
773
+ }
774
+
775
+ if (base === 'exec') {
776
+ idx++;
777
+ while (idx < tokens.length && tokens[idx]!.startsWith('-')) {
778
+ const flag = tokens[idx]!;
779
+ if (flag === '--') {
780
+ idx++;
781
+ break;
782
+ }
783
+ if (flag === '-a') {
784
+ idx += 2;
785
+ continue;
786
+ }
787
+ idx++;
788
+ }
789
+ continue;
790
+ }
791
+
792
+ if (base === 'stdbuf') {
793
+ idx++;
794
+ while (idx < tokens.length && tokens[idx]!.startsWith('-')) {
795
+ const flag = tokens[idx]!;
796
+ if (flag === '--') {
797
+ idx++;
798
+ break;
799
+ }
800
+ if (flag === '-i' || flag === '-o' || flag === '-e') {
801
+ idx += 2;
802
+ continue;
803
+ }
804
+ idx++;
805
+ }
806
+ continue;
807
+ }
808
+
809
+ if (base === 'caffeinate') {
810
+ idx++;
811
+ while (idx < tokens.length && tokens[idx]!.startsWith('-')) {
812
+ const flag = tokens[idx]!;
813
+ if (flag === '--') {
814
+ idx++;
815
+ break;
816
+ }
817
+ if (flag === '-t' || flag === '-w') {
818
+ idx += 2;
819
+ continue;
820
+ }
821
+ idx++;
822
+ }
823
+ continue;
824
+ }
825
+
826
+ if (base === 'timeout') {
827
+ idx++;
828
+ while (idx < tokens.length && tokens[idx]!.startsWith('-')) {
829
+ const flag = tokens[idx]!;
830
+ if (flag === '--') {
831
+ idx++;
832
+ break;
833
+ }
834
+ if (flag === '-k' || flag === '-s' || flag === '--signal' || flag === '--kill-after') {
835
+ idx += 2;
836
+ continue;
837
+ }
838
+ idx++;
839
+ }
840
+ // Consume duration operand (e.g. `10`, `30s`, `2m`)
841
+ if (idx < tokens.length && /^\d+(?:\.\d+)?[smhd]?$/.test(tokens[idx]!)) {
842
+ idx++;
843
+ }
844
+ continue;
845
+ }
846
+
847
+ break;
848
+ }
849
+
850
+ if (idx >= tokens.length) {
851
+ return { normalized: '', executable: '', args: [], isReadOnlyLookup: false };
852
+ }
853
+
854
+ const executable = resolveExecutableBasename(tokens[idx]!);
855
+ const args = tokens.slice(idx + 1);
856
+ const normalized = args.length > 0 ? `${executable} ${args.join(' ')}` : executable;
857
+
858
+ return {
859
+ normalized,
860
+ executable,
861
+ args,
862
+ isReadOnlyLookup: false
863
+ };
864
+ }
865
+
866
+ /**
867
+ * Splits a raw command string into sequential/piped stages while ignoring
868
+ * separators (`;`, `&&`, `||`, `|`, `&`, `\n`) inside single or double quotes.
869
+ */
870
+ function splitRawIntoStages(rawCommand: string): string[] {
871
+ const stages: string[] = [];
872
+ let current = '';
873
+ const len = rawCommand.length;
874
+ let i = 0;
875
+ let inSingle = false;
876
+ let inDouble = false;
877
+
878
+ const pushStage = (): void => {
879
+ const trimmed = current.trim();
880
+ if (trimmed.length > 0) stages.push(trimmed);
881
+ current = '';
882
+ };
883
+
884
+ while (i < len) {
885
+ const ch = rawCommand[i]!;
886
+ const next = rawCommand[i + 1];
887
+
888
+ if (inSingle) {
889
+ current += ch;
890
+ if (ch === "'") inSingle = false;
891
+ i++;
892
+ continue;
893
+ }
894
+ if (inDouble) {
895
+ if (ch === '\\' && i + 1 < len) {
896
+ current += ch + next;
897
+ i += 2;
898
+ continue;
899
+ }
900
+ current += ch;
901
+ if (ch === '"') inDouble = false;
902
+ i++;
903
+ continue;
904
+ }
905
+ if (ch === '\\' && i + 1 < len) {
906
+ current += ch + next;
907
+ i += 2;
908
+ continue;
909
+ }
910
+ if (ch === "'") {
911
+ inSingle = true;
912
+ current += ch;
913
+ i++;
914
+ continue;
915
+ }
916
+ if (ch === '"') {
917
+ inDouble = true;
918
+ current += ch;
919
+ i++;
920
+ continue;
921
+ }
922
+
923
+ if (ch === ';' || ch === '\n') {
924
+ pushStage();
925
+ i++;
926
+ continue;
927
+ }
928
+ if (ch === '|' && next === '|') {
929
+ pushStage();
930
+ i += 2;
931
+ continue;
932
+ }
933
+ if (ch === '&' && next === '&') {
934
+ pushStage();
935
+ i += 2;
936
+ continue;
937
+ }
938
+ if (ch === '|') {
939
+ pushStage();
940
+ i++;
941
+ continue;
942
+ }
943
+ if (ch === '&') {
944
+ const prev = i > 0 ? rawCommand[i - 1] : '';
945
+ if (prev === '>' || prev === '<' || next === '>') {
946
+ current += ch;
947
+ i++;
948
+ continue;
949
+ }
950
+ pushStage();
951
+ i++;
952
+ continue;
953
+ }
954
+
955
+ current += ch;
956
+ i++;
957
+ }
958
+ pushStage();
959
+ return stages;
960
+ }
961
+
962
+ /**
963
+ * Extracts unquoted and quoted file targets written via redirection (`>`, `>>`)
964
+ * or `tee` across a raw command string without matching operators inside quotes.
965
+ */
966
+ export function extractWriteTargetsFromRaw(rawCommand: string): string[] {
967
+ const targets: string[] = [];
968
+ const len = rawCommand.length;
969
+ let i = 0;
970
+ let inSingle = false;
971
+ let inDouble = false;
972
+
973
+ const readShellWord = (start: number): { word: string; nextIndex: number } => {
974
+ let j = start;
975
+ while (j < len && (rawCommand[j] === ' ' || rawCommand[j] === '\t')) j++;
976
+ let word = '';
977
+ while (j < len) {
978
+ const c = rawCommand[j]!;
979
+ if (c === ' ' || c === '\t' || c === '\n' || c === ';' || c === '|' || c === '&' || c === '<' || c === '>') {
980
+ break;
981
+ }
982
+ if (c === "'") {
983
+ j++;
984
+ while (j < len && rawCommand[j] !== "'") {
985
+ word += rawCommand[j];
986
+ j++;
987
+ }
988
+ if (j < len) j++;
989
+ continue;
990
+ }
991
+ if (c === '"') {
992
+ j++;
993
+ while (j < len && rawCommand[j] !== '"') {
994
+ if (rawCommand[j] === '\\' && j + 1 < len) {
995
+ word += rawCommand[j + 1];
996
+ j += 2;
997
+ continue;
998
+ }
999
+ word += rawCommand[j];
1000
+ j++;
1001
+ }
1002
+ if (j < len) j++;
1003
+ continue;
1004
+ }
1005
+ if (c === '\\' && j + 1 < len) {
1006
+ word += rawCommand[j + 1];
1007
+ j += 2;
1008
+ continue;
1009
+ }
1010
+ word += c;
1011
+ j++;
1012
+ }
1013
+ return { word, nextIndex: j };
1014
+ };
1015
+
1016
+ while (i < len) {
1017
+ const ch = rawCommand[i]!;
1018
+ if (inSingle) {
1019
+ if (ch === "'") inSingle = false;
1020
+ i++;
1021
+ continue;
1022
+ }
1023
+ if (inDouble) {
1024
+ if (ch === '\\' && i + 1 < len) {
1025
+ i += 2;
1026
+ continue;
1027
+ }
1028
+ if (ch === '"') inDouble = false;
1029
+ i++;
1030
+ continue;
1031
+ }
1032
+ if (ch === '\\' && i + 1 < len) {
1033
+ i += 2;
1034
+ continue;
1035
+ }
1036
+ if (ch === "'") {
1037
+ inSingle = true;
1038
+ i++;
1039
+ continue;
1040
+ }
1041
+ if (ch === '"') {
1042
+ inDouble = true;
1043
+ i++;
1044
+ continue;
1045
+ }
1046
+
1047
+ if (ch === '>') {
1048
+ // Handle `>>`, `>|`, and ignore descriptor duplications `>&1`, `>&2`, `>&-`
1049
+ let next = i + 1;
1050
+ if (rawCommand[next] === '&') {
1051
+ // Descriptor duplication (e.g. `2>&1`, `>&2`) is not a file target
1052
+ i = next + 1;
1053
+ continue;
1054
+ }
1055
+ if (rawCommand[next] === '>' || rawCommand[next] === '|') {
1056
+ next++;
1057
+ }
1058
+ const { word, nextIndex } = readShellWord(next);
1059
+ if (word && !word.startsWith('&')) {
1060
+ targets.push(word);
1061
+ }
1062
+ i = nextIndex;
1063
+ continue;
1064
+ }
1065
+
1066
+ i++;
1067
+ }
1068
+
1069
+ // Also capture `tee [-a|-i] <target...>` destinations on unquoted pipe/command stages
1070
+ const stages = splitRawIntoStages(rawCommand);
1071
+ for (const seg of stages) {
1072
+ const words = tokenizeRawShellWords(seg);
1073
+ if (words.length < 2) continue;
1074
+ const norm = normalizeExecutableSegment(words.map(w => w.toLowerCase()).join(' '));
1075
+ if (norm.executable === 'tee') {
1076
+ // Re-scan original-case words after the `tee` token
1077
+ const teeIndex = words.findIndex(w => resolveExecutableBasename(w.toLowerCase()) === 'tee');
1078
+ if (teeIndex !== -1) {
1079
+ for (let k = teeIndex + 1; k < words.length; k++) {
1080
+ const arg = words[k]!;
1081
+ if (arg === '--') continue;
1082
+ if (arg.startsWith('-')) continue;
1083
+ targets.push(arg);
1084
+ }
1085
+ }
1086
+ }
1087
+ }
1088
+
1089
+ return targets;
1090
+ }
1091
+
1092
+ function tokenizeRawShellWords(segment: string): string[] {
1093
+ const words: string[] = [];
1094
+ const len = segment.length;
1095
+ let i = 0;
1096
+
1097
+ while (i < len) {
1098
+ while (i < len && (segment[i] === ' ' || segment[i] === '\t' || segment[i] === '\n')) i++;
1099
+ if (i >= len) break;
1100
+
1101
+ let word = '';
1102
+ while (i < len) {
1103
+ const ch = segment[i]!;
1104
+ if (ch === ' ' || ch === '\t' || ch === '\n') break;
1105
+ if (ch === "'") {
1106
+ i++;
1107
+ while (i < len && segment[i] !== "'") {
1108
+ word += segment[i];
1109
+ i++;
1110
+ }
1111
+ if (i < len) i++;
1112
+ continue;
1113
+ }
1114
+ if (ch === '"') {
1115
+ i++;
1116
+ while (i < len && segment[i] !== '"') {
1117
+ if (segment[i] === '\\' && i + 1 < len) {
1118
+ word += segment[i + 1];
1119
+ i += 2;
1120
+ continue;
1121
+ }
1122
+ word += segment[i];
1123
+ i++;
1124
+ }
1125
+ if (i < len) i++;
1126
+ continue;
1127
+ }
1128
+ if (ch === '\\' && i + 1 < len) {
1129
+ word += segment[i + 1];
1130
+ i += 2;
1131
+ continue;
1132
+ }
1133
+ word += ch;
1134
+ i++;
1135
+ }
1136
+ if (word.length > 0) words.push(word);
1137
+ }
1138
+ return words;
1139
+ }
1140
+
1141
+ /**
1142
+ * Detects destructive recursive-force removals regardless of flag order or
1143
+ * flag bundling (e.g. `rm -r -f /`, `rm -f -r ~`, `rm -rfv /`, `rm --recursive --force *`).
1144
+ */
1145
+ export function isExtremeRemovalSegment(seg: NormalizedSegment): boolean {
1146
+ if (seg.executable !== 'rm') return false;
1147
+
1148
+ let hasRecursive = false;
1149
+ let hasForce = false;
1150
+ const targets: string[] = [];
1151
+ let endOfFlags = false;
1152
+
1153
+ for (const arg of seg.args) {
1154
+ if (!endOfFlags && arg === '--') {
1155
+ endOfFlags = true;
1156
+ continue;
1157
+ }
1158
+ if (!endOfFlags && arg.startsWith('--')) {
1159
+ if (arg === '--recursive') hasRecursive = true;
1160
+ if (arg === '--force') hasForce = true;
1161
+ continue;
1162
+ }
1163
+ if (!endOfFlags && arg.startsWith('-') && arg.length > 1) {
1164
+ const flags = arg.slice(1);
1165
+ if (flags.includes('r')) hasRecursive = true;
1166
+ if (flags.includes('f')) hasForce = true;
1167
+ continue;
1168
+ }
1169
+ targets.push(arg);
1170
+ }
1171
+
1172
+ if (!hasRecursive || !hasForce) return false;
1173
+
1174
+ for (const target of targets) {
1175
+ if (
1176
+ target === '/' ||
1177
+ target.startsWith('/') ||
1178
+ target === '~' ||
1179
+ target.startsWith('~/') ||
1180
+ target.startsWith('~') ||
1181
+ target.startsWith('*') ||
1182
+ target === '$home' ||
1183
+ target.startsWith('$home/') ||
1184
+ target === '${home}' ||
1185
+ target.startsWith('${home}/')
1186
+ ) {
1187
+ // Allow `/tmp/...`? Wait — `rm -rf /tmp/foo` is dangerous, not necessarily root wipe,
1188
+ // EXCEPT existing classifier explicitly treated `/rm\s+(-rf|-fr)\s+[\/~]/` as extreme!
1189
+ // Preserve exact strictness: any leading `/` or `~` or `*` with recursive+force is extreme.
1190
+ return true;
1191
+ }
1192
+ }
1193
+ return false;
1194
+ }
1195
+
1196
+ /**
1197
+ * Detects fetch-and-execute pipelines (`curl ... | bash`, `wget ... | /bin/zsh`,
1198
+ * `curl ... | sudo sh`, `curl ... | env bash`) in linear time.
1199
+ */
1200
+ export function isFetchAndExecPipeline(pipelines: readonly (readonly NormalizedSegment[])[]): boolean {
1201
+ for (const pipeline of pipelines) {
1202
+ if (pipeline.length < 2) continue;
1203
+ let sawFetcher = false;
1204
+ for (const stage of pipeline) {
1205
+ if (stage.executable === 'curl' || stage.executable === 'wget') {
1206
+ sawFetcher = true;
1207
+ continue;
1208
+ }
1209
+ if (!sawFetcher) continue;
1210
+ if (SHELL_INTERPRETERS.has(stage.executable)) return true;
1211
+ // Handle `curl ... | sudo bash` or `curl ... | sudo -E sh`
1212
+ if (stage.executable === 'sudo' || stage.executable === 'su') {
1213
+ for (const arg of stage.args) {
1214
+ if (arg.startsWith('-')) continue;
1215
+ if (SHELL_INTERPRETERS.has(resolveExecutableBasename(arg))) return true;
1216
+ break;
1217
+ }
1218
+ }
1219
+ }
1220
+ }
1221
+ return false;
1222
+ }
1223
+
1224
+ export interface AnalyzedShellCommand {
1225
+ maskedTopLevel: string;
1226
+ allRawUnits: string[];
1227
+ allMaskedUnits: string[];
1228
+ normalizedSegments: NormalizedSegment[];
1229
+ unwrappedRawSegments: NormalizedSegment[];
1230
+ normalizedPipelines: NormalizedSegment[][];
1231
+ writeTargets: string[];
1232
+ }
1233
+
1234
+ /**
1235
+ * Parses a shell command string (including nested `$(...)` and backtick
1236
+ * substitutions) into normalized executable segments, pipelines, and write targets.
1237
+ */
1238
+ export function analyzeShellCommand(rawCommand: string): AnalyzedShellCommand {
1239
+ const lower = rawCommand.trim().toLowerCase();
1240
+ const topParsed = parseMaskAndExtractSubstitutions(lower, 0);
1241
+
1242
+ const allRawUnits: string[] = [rawCommand.trim()];
1243
+ const allMaskedUnits: string[] = [topParsed.masked];
1244
+
1245
+ // Also keep original-case substitutions for accurate path-target extraction
1246
+ const rawCaseParsed = parseMaskAndExtractSubstitutions(rawCommand.trim(), 0);
1247
+ for (const sub of rawCaseParsed.substitutions) {
1248
+ allRawUnits.push(sub);
1249
+ }
1250
+ for (const sub of topParsed.substitutions) {
1251
+ const subParsed = parseMaskAndExtractSubstitutions(sub, MAX_SUBSTITUTION_DEPTH);
1252
+ allMaskedUnits.push(subParsed.masked);
1253
+ }
1254
+
1255
+ const normalizedSegments: NormalizedSegment[] = [];
1256
+ const normalizedPipelines: NormalizedSegment[][] = [];
1257
+
1258
+ for (const unit of allMaskedUnits) {
1259
+ const { pipelines } = splitIntoPipelinesAndSegments(unit);
1260
+ for (const pipeline of pipelines) {
1261
+ const normPipeline: NormalizedSegment[] = [];
1262
+ for (const stage of pipeline) {
1263
+ const norm = normalizeExecutableSegment(stage);
1264
+ if (norm.normalized.length > 0) {
1265
+ normalizedSegments.push(norm);
1266
+ normPipeline.push(norm);
1267
+ }
1268
+ }
1269
+ if (normPipeline.length > 0) {
1270
+ normalizedPipelines.push(normPipeline);
1271
+ }
1272
+ }
1273
+ }
1274
+
1275
+ const unwrappedRawSegments: NormalizedSegment[] = [];
1276
+ const writeTargets: string[] = [];
1277
+ for (const rawUnit of allRawUnits) {
1278
+ for (const target of extractWriteTargetsFromRaw(rawUnit)) {
1279
+ writeTargets.push(target);
1280
+ }
1281
+ for (const stage of splitRawIntoStages(rawUnit)) {
1282
+ const words = tokenizeRawShellWords(stage);
1283
+ if (words.length === 0) continue;
1284
+ const norm = normalizeExecutableSegment(words.map(w => w.toLowerCase()).join(' '));
1285
+ if (norm.normalized.length > 0) {
1286
+ unwrappedRawSegments.push(norm);
1287
+ }
1288
+ }
1289
+ }
1290
+
1291
+ return {
1292
+ maskedTopLevel: topParsed.masked,
1293
+ allRawUnits,
1294
+ allMaskedUnits,
1295
+ normalizedSegments,
1296
+ unwrappedRawSegments,
1297
+ normalizedPipelines,
1298
+ writeTargets
1299
+ };
1300
+ }