@causyne/agent 1.20.118 → 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 (101) 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 +51 -351
  9. package/src/agentLoop.ts +69 -363
  10. package/src/autoUpdate.js +111 -8
  11. package/src/autoUpdate.ts +144 -8
  12. package/src/browser/causyneBrowser.js +231 -136
  13. package/src/browser/causyneBrowser.ts +229 -140
  14. package/src/browser/searchProviders.js +41 -30
  15. package/src/browser/searchProviders.ts +24 -14
  16. package/src/browser/workspacePathSafety.js +50 -0
  17. package/src/browser/workspacePathSafety.ts +50 -0
  18. package/src/browser/workspacePreview.js +27 -4
  19. package/src/browser/workspacePreview.ts +28 -4
  20. package/src/cliMode.js +17 -3
  21. package/src/commands.js +15 -22
  22. package/src/config.js +42 -63
  23. package/src/configVault.js +204 -0
  24. package/src/configVault.ts +213 -0
  25. package/src/core/contextCompactor.js +70 -11
  26. package/src/core/contextCompactor.ts +83 -11
  27. package/src/creative/liveBridge.js +34 -1
  28. package/src/creative/liveBridge.ts +28 -1
  29. package/src/dynamicCatalogue.js +42 -73
  30. package/src/dynamicCatalogue.ts +74 -60
  31. package/src/entrypoint.js +77 -4
  32. package/src/headlessCli.js +304 -0
  33. package/src/headlessCli.ts +380 -0
  34. package/src/mcp/mcpClient.js +38 -11
  35. package/src/mcp/mcpClient.ts +44 -11
  36. package/src/mcp/mcpRegistry.js +2 -5
  37. package/src/mcp/mcpRegistry.ts +2 -5
  38. package/src/mcp/mcpSecurity.js +189 -0
  39. package/src/mcp/mcpSecurity.ts +190 -0
  40. package/src/observer/evidence.js +23 -0
  41. package/src/observer/evidence.ts +21 -0
  42. package/src/osKeychain.js +209 -0
  43. package/src/osKeychain.ts +245 -0
  44. package/src/providers/anthropic.js +61 -28
  45. package/src/providers/base.js +14 -0
  46. package/src/providers/byokHttp.js +354 -0
  47. package/src/providers/byokHttp.ts +454 -0
  48. package/src/providers/byokStream.js +657 -0
  49. package/src/providers/byokStream.ts +759 -0
  50. package/src/providers/dashscope-byok.js +47 -32
  51. package/src/providers/deepseek.js +43 -39
  52. package/src/providers/gemini.js +73 -38
  53. package/src/providers/moonshot.js +43 -33
  54. package/src/providers/muse.js +10 -10
  55. package/src/providers/ollama.js +46 -31
  56. package/src/providers/openai-compatible.js +57 -32
  57. package/src/providers/openrouter.js +77 -113
  58. package/src/providers/openrouter.ts +99 -118
  59. package/src/providers/qwen-byok.js +46 -23
  60. package/src/providers/toolContracts.js +9 -3
  61. package/src/providers/toolContracts.ts +9 -3
  62. package/src/providers/wireNormalizer.js +238 -0
  63. package/src/providers/wireNormalizer.ts +279 -0
  64. package/src/providers/xai.js +43 -33
  65. package/src/sandbox.js +77 -56
  66. package/src/sandboxPolicy.js +1208 -0
  67. package/src/sandboxPolicy.ts +1300 -0
  68. package/src/sessionJournal.js +47 -0
  69. package/src/sessionJournal.ts +49 -0
  70. package/src/tools/browserAutomator.js +13 -1
  71. package/src/tools/browserAutomator.ts +13 -0
  72. package/src/tools/creativeApps.js +2 -1
  73. package/src/tools/creativeApps.ts +2 -1
  74. package/src/tools/gameAssetFetcher.js +130 -26
  75. package/src/tools/gameAssetHarvester.js +80 -58
  76. package/src/tools/nativeEngine.js +1 -1
  77. package/src/tools/nativeEngine.ts +1 -1
  78. package/src/tools/osSandbox.js +473 -0
  79. package/src/tools/osSandbox.ts +554 -0
  80. package/src/tools/persistentShell.js +8 -3
  81. package/src/tools/registry.js +13 -0
  82. package/src/tools/subprocessEnv.js +197 -0
  83. package/src/tools/subprocessEnv.ts +212 -0
  84. package/src/tools/sysRun.js +39 -6
  85. package/src/tools/sysRun.ts +53 -7
  86. package/src/tools/toolScanner.js +596 -140
  87. package/src/tools/toolScanner.ts +665 -147
  88. package/src/tools/toolSelfRepair.js +243 -114
  89. package/src/tools/toolSelfRepair.ts +262 -111
  90. package/src/tools/webFetch.js +161 -24
  91. package/src/tools/webFetch.ts +157 -22
  92. package/src/tools/webSearch.js +33 -4
  93. package/src/tools/webSearch.ts +27 -4
  94. package/src/tui/sessionPicker.js +132 -35
  95. package/src/tui/sessionPicker.ts +153 -32
  96. package/src/tui/sessionPickerView.js +277 -34
  97. package/src/tui/sessionPickerView.ts +328 -34
  98. package/src/tui/statusLine.js +3 -0
  99. package/src/tui/statusLine.ts +5 -0
  100. package/src/tui/workspaceIdentity.js +133 -0
  101. package/src/tui/workspaceIdentity.ts +146 -0
package/src/sandbox.js CHANGED
@@ -5,29 +5,14 @@ import { loadConfig } from './config.js';
5
5
  import { isDevEmulator } from './devMode.js';
6
6
  import { validateBrowserActSandbox } from './browser/causyneBrowser.js';
7
7
  import { isPhysicalPathAllowed } from './agent/workspaceBoundary.js';
8
-
9
-
10
- function maskQuotedSpans(text) {
11
- return text
12
- .replace(/"(?:[^"\\]|\\.)*"/g, '""')
13
- .replace(/'(?:[^'\\]|\\.)*'/g, "''")
14
- .replace(/`(?:[^`\\]|\\.)*`/g, '``');
15
- }
16
-
17
- /**
18
- * Split a command line into the individual commands the shell will run.
19
- *
20
- * Prefix matching only ever inspected the FIRST word of the whole line, so any
21
- * leading token disguised everything after it: `cd ~/Documents && rm -f x` was
22
- * classified from `cd` and auto-executed with no approval. Each segment must be
23
- * judged on its own.
24
- */
25
- function splitShellSegments(text) {
26
- return text
27
- .split(/&&|\|\||[;\n|&]/)
28
- .map((segment) => segment.trim())
29
- .filter((segment) => segment.length > 0);
30
- }
8
+ import {
9
+ isBlockedWorkspaceRoot,
10
+ isExtendedCredentialPath,
11
+ isSensitiveWriteTarget,
12
+ analyzeShellCommand,
13
+ isExtremeRemovalSegment,
14
+ isFetchAndExecPipeline
15
+ } from './sandboxPolicy.js';
31
16
 
32
17
  /**
33
18
  * Read-only invocations of tools whose NAME is dangerous but whose subcommand
@@ -115,13 +100,18 @@ const CREDENTIAL_PATHS = [
115
100
  /(^|\/)Library\/Keychains(\/|$)/i,
116
101
  // Causyne's own vault: config.json holds the encrypted provider key and
117
102
  // .vault_key is the key that decrypts it.
118
- /(^|\/)\.causyne(\/|$)/
103
+ /(^|\/)\.causyne(\/|$)/,
104
+ /(^|\/)\.envrc$/i,
105
+ /(^|\/)\.git-credentials$/i,
106
+ /(^|\/)\.pypirc$/i,
107
+ /(^|\/)\.pgpass$/i,
108
+ /(^|\/)\.my\.cnf$/i
119
109
  ];
120
110
 
121
111
  export function isCredentialPath(targetPath) {
122
112
  if (typeof targetPath !== 'string' || targetPath.length === 0) return false;
123
113
  const normalized = targetPath.replace(/\\/g, '/');
124
- return CREDENTIAL_PATHS.some(pattern => pattern.test(normalized));
114
+ return CREDENTIAL_PATHS.some(pattern => pattern.test(normalized)) || isExtendedCredentialPath(normalized);
125
115
  }
126
116
 
127
117
  const SENSITIVE_WRITE_TARGETS = [
@@ -130,6 +120,13 @@ const SENSITIVE_WRITE_TARGETS = [
130
120
  /(^|\/)\.config\/fish\/config\.fish$/,
131
121
  // Remote session routing profiles and authentication credentials.
132
122
  /(^|\/)\.ssh\//,
123
+ /(^|\/)\.aws\//,
124
+ /(^|\/)\.kube\//,
125
+ /(^|\/)\.gnupg\//,
126
+ /(^|\/)\.docker\/config\.json$/,
127
+ /(^|\/)\.(npmrc|netrc|git-credentials|pypirc|envrc)$/,
128
+ // Git hooks and repository config can execute arbitrary commands on next git invocation.
129
+ /(^|\/)\.git\/(hooks(\/|$)|config$)/,
133
130
  // Scheduled execution.
134
131
  /(^|\/)(crontab|cron\.d)(\/|$)/,
135
132
  /\/etc\//,
@@ -195,13 +192,11 @@ export class Sandbox {
195
192
 
196
193
  updateWorkspacePaths(newPaths) {
197
194
  if (Array.isArray(newPaths) && newPaths.length > 0) {
198
- // Validate: reject any system-critical paths
199
- const BLOCKED_ROOTS = ['/etc', '/usr', '/bin', '/sbin', '/System', '/var', '/private', '/Library'];
200
- const safePaths = newPaths.filter(p => {
201
- const resolved = path.resolve(p);
202
- return !BLOCKED_ROOTS.some(blocked => resolved.startsWith(blocked));
203
- });
204
-
195
+ // Validate: reject any system-critical roots, filesystem roots, or symlinks to them
196
+ const safePaths = newPaths
197
+ .filter(p => typeof p === 'string' && !isBlockedWorkspaceRoot(p))
198
+ .map(p => path.resolve(p));
199
+
205
200
  if (safePaths.length > 0) {
206
201
  this.workspacePaths = safePaths;
207
202
  return { success: true, paths: this.workspacePaths };
@@ -210,8 +205,11 @@ export class Sandbox {
210
205
  return { success: false, reason: 'Invalid or blocked paths provided' };
211
206
  }
212
207
 
213
- // V5: Add a single workspace path
208
+ // V5: Add a single workspace path (enforces the same blocked-root checks as updateWorkspacePaths)
214
209
  addWorkspacePath(newPath) {
210
+ if (typeof newPath !== 'string' || isBlockedWorkspaceRoot(newPath)) {
211
+ return this.workspacePaths;
212
+ }
215
213
  const resolved = path.resolve(newPath);
216
214
  if (!this.workspacePaths.includes(resolved)) {
217
215
  this.workspacePaths.push(resolved);
@@ -467,25 +465,34 @@ export class Sandbox {
467
465
  // several of these patterns deliberately span shell separators (the fork
468
466
  // bomb contains ; and |, the pipe-to-shell patterns contain |), so
469
467
  // splitting first would stop them matching at all.
468
+ const analyzed = analyzeShellCommand(command);
470
469
  for (const pattern of FORBIDDEN_PATTERNS) {
471
470
  if (pattern.test(normalized)) return 'forbidden';
471
+ for (const rawUnit of analyzed.allRawUnits) {
472
+ if (pattern.test(rawUnit.toLowerCase())) return 'forbidden';
473
+ }
472
474
  }
475
+ if (isFetchAndExecPipeline(analyzed.normalizedPipelines)) return 'forbidden';
473
476
 
474
477
  // Everything below judges what the shell will actually execute.
475
- const masked = maskQuotedSpans(normalized);
476
-
478
+ const masked = analyzed.maskedTopLevel;
477
479
 
478
- // L3 (local-path audit): classify the redirection target, not just the verb.
480
+ // L3 (local-path audit): classify the redirection / tee write target, not just the verb.
479
481
  // Tool argument validation enforces boundaries on named arguments, but
480
- // shell redirection targets appended via operators (>> or >) require independent
481
- // audit. Writing into sensitive paths (such as user startup profiles, remote
482
- // authentication directories, or agent configuration stores) must always escalate
483
- // to extreme classification regardless of which command performs the redirection.
484
- if (redirectsIntoSensitiveTarget(masked)) return 'extreme';
485
- const executesQuotedText = INTERPRETER_INVOCATION.test(masked);
486
- const destructiveScanTarget = executesQuotedText ? normalized : masked;
482
+ // shell redirection targets appended via operators (>> or >) or `tee` require independent
483
+ // audit — including quoted targets, `$HOME` expansions, and command substitutions.
484
+ if (
485
+ redirectsIntoSensitiveTarget(masked) ||
486
+ analyzed.writeTargets.some(target => isSensitiveWriteTarget(target))
487
+ ) {
488
+ return 'extreme';
489
+ }
490
+
491
+ const executesQuotedText = analyzed.allMaskedUnits.some(unit => INTERPRETER_INVOCATION.test(unit));
492
+ const scanUnits = executesQuotedText
493
+ ? analyzed.allRawUnits.map(u => u.toLowerCase())
494
+ : analyzed.allMaskedUnits;
487
495
 
488
-
489
496
  const EXTREME_PATTERNS = [
490
497
  /rm\s+(-rf|-fr)\s+[\/~]/,
491
498
  /rm\s+(-rf|-fr)\s+\*/,
@@ -498,8 +505,16 @@ export class Sandbox {
498
505
  /diskpart/i
499
506
  ];
500
507
 
501
- for (const pattern of EXTREME_PATTERNS) {
502
- if (pattern.test(destructiveScanTarget)) return 'extreme';
508
+ for (const unit of scanUnits) {
509
+ for (const pattern of EXTREME_PATTERNS) {
510
+ if (pattern.test(unit)) return 'extreme';
511
+ }
512
+ }
513
+ for (const seg of analyzed.normalizedSegments) {
514
+ if (isExtremeRemovalSegment(seg)) return 'extreme';
515
+ }
516
+ for (const seg of analyzed.unwrappedRawSegments) {
517
+ if (isExtremeRemovalSegment(seg)) return 'extreme';
503
518
  }
504
519
 
505
520
  // DANGEROUS — requires approval in Mode B, auto-executes in Mode C
@@ -512,13 +527,16 @@ export class Sandbox {
512
527
  'mv ', 'crontab ', 'systemctl ', 'service '
513
528
  ];
514
529
 
515
- // Prefix rules are per-segment: `cd x && rm -f y` must be judged on `rm`,
516
- // not on `cd`. Highest risk across all segments wins.
517
- const segments = splitShellSegments(masked);
518
-
519
- for (const segment of segments) {
530
+ // Prefix rules are evaluated per normalized segment (including env-prefixed,
531
+ // wrapper-prefixed, absolute-path, and `$(...)`/backtick substituted commands).
532
+ // Highest risk across all segments wins.
533
+ for (const seg of analyzed.normalizedSegments) {
534
+ if (seg.isReadOnlyLookup) continue;
535
+ if (seg.executable === 'su') return 'dangerous';
520
536
  for (const prefix of DANGEROUS_PREFIXES) {
521
- if (segment.startsWith(prefix) && !isReadOnlyInvocation(segment)) return 'dangerous';
537
+ if (seg.normalized.startsWith(prefix) && !isReadOnlyInvocation(seg.normalized)) {
538
+ return 'dangerous';
539
+ }
522
540
  }
523
541
  }
524
542
 
@@ -528,8 +546,10 @@ export class Sandbox {
528
546
  const DANGEROUS_PATTERNS = [
529
547
  /\bfind\b[\s\S]*\s-(exec|execdir|delete)\b/,
530
548
  ];
531
- for (const pattern of DANGEROUS_PATTERNS) {
532
- if (pattern.test(destructiveScanTarget)) return 'dangerous';
549
+ for (const unit of scanUnits) {
550
+ for (const pattern of DANGEROUS_PATTERNS) {
551
+ if (pattern.test(unit)) return 'dangerous';
552
+ }
533
553
  }
534
554
 
535
555
  // MODERATE — auto-execute + notify in Mode B
@@ -548,9 +568,10 @@ export class Sandbox {
548
568
  'curl ', 'wget '
549
569
  ];
550
570
 
551
- for (const segment of segments) {
571
+ for (const seg of analyzed.normalizedSegments) {
572
+ if (seg.isReadOnlyLookup) continue;
552
573
  for (const prefix of MODERATE_PREFIXES) {
553
- if (segment.startsWith(prefix)) return 'moderate';
574
+ if (seg.normalized.startsWith(prefix)) return 'moderate';
554
575
  }
555
576
  }
556
577