vanguard-cli 3.1.10 → 3.1.12

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/bin/vanguard.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  import { Command } from 'commander';
4
4
  import inquirer from 'inquirer';
5
+ import chalk from 'chalk';
5
6
  import { runConfigWizard } from '../lib/commands/config.js';
6
7
  import { runIntegrate } from '../lib/commands/integrate.js';
7
8
  import { handlePull, handleClone } from '../lib/commands/scan.js';
@@ -59,6 +60,22 @@ program
59
60
  program.command('config').description('Configure AI providers').action(runConfigWizard);
60
61
  program.command('integrate').description('Install "Invisible Protection" shell wrapper').action(runIntegrate);
61
62
 
63
+ program
64
+ .command('status')
65
+ .description('Check firewall protection status')
66
+ .action(() => {
67
+ showBanner();
68
+ const isInternal = process.env.VANGUARD_INTERNAL === '1';
69
+ console.log(chalk.bold('🔥 Firewall Status:'));
70
+ if (isInternal) {
71
+ console.log(chalk.green(' ✅ ACTIVE (Intercepted Session)'));
72
+ } else {
73
+ console.log(chalk.yellow(' ⚠️ OFFLINE (Direct CLI Access)'));
74
+ console.log(chalk.dim('\nTo activate Invisible Protection, run: vanguard integrate'));
75
+ }
76
+ showFooter();
77
+ });
78
+
62
79
 
63
80
  program
64
81
  .command('pull')
@@ -2,138 +2,136 @@ import fs from 'fs-extra';
2
2
  import path from 'path';
3
3
  import os from 'os';
4
4
  import chalk from 'chalk';
5
- import { execSync } from 'child_process';
6
5
  import { createSpinner } from '../utils/spinner.js';
7
6
 
8
- const BASH_ZSH_TEMPLATE = `
9
- # --- VANGUARD PROTECTION START ---
10
- git() {
11
- if [ "$1" = "clone" ] && [ -z "$VANGUARD_INTERNAL" ]; then
12
- export VANGUARD_INTERNAL=1
13
- vanguard clone "\${@:2}"
14
- unset VANGUARD_INTERNAL
15
- else
16
- command git "$@"
17
- fi
18
- }
19
- # --- VANGUARD PROTECTION END ---
20
- `;
21
-
22
- const FISH_TEMPLATE = `
23
- # --- VANGUARD PROTECTION START ---
24
- function git
25
- if test "$argv[1]" = "clone"
26
- vanguard clone $argv[2..-1]
27
- else
28
- command git $argv
29
- end
30
- end
31
- # --- VANGUARD PROTECTION END ---
32
- `;
33
-
34
- const POWERSHELL_TEMPLATE = `
35
- # --- VANGUARD PROTECTION START ---
36
- function git {
37
- if ($args[0] -eq "clone" -and !$env:VANGUARD_INTERNAL) {
38
- $env:VANGUARD_INTERNAL = "1"
39
- try {
40
- vanguard clone @(if ($args.Length -gt 1) { $args[1..($args.Length-1)] })
41
- } finally {
42
- $env:VANGUARD_INTERNAL = $null
43
- }
44
- } else {
45
- & (Get-Command git -CommandType Application) @args
46
- }
47
- }
48
- # --- VANGUARD PROTECTION END ---
49
- `;
50
-
51
- const SCRIPTS = {
52
- bash: { file: '.bashrc', template: BASH_ZSH_TEMPLATE },
53
- zsh: { file: '.zshrc', template: BASH_ZSH_TEMPLATE },
54
- fish: { file: '.config/fish/config.fish', template: FISH_TEMPLATE },
55
- powershell: { file: 'Documents/PowerShell/Microsoft.PowerShell_profile.ps1', template: POWERSHELL_TEMPLATE }
56
- };
7
+ // We use raw strings for templates to avoid JS interpolation issues
8
+ const BASH_ZSH_TEMPLATE = [
9
+ '# --- VANGUARD PROTECTION START ---',
10
+ '# Universal Interceptor for Bash/Zsh',
11
+ 'git() {',
12
+ ' if [ "$1" = "clone" ] && [ -z "$VANGUARD_INTERNAL" ]; then',
13
+ ' export VANGUARD_INTERNAL=1',
14
+ ' vanguard clone "${@:2}"',
15
+ ' unset VANGUARD_INTERNAL',
16
+ ' else',
17
+ ' command git "$@"',
18
+ ' fi',
19
+ '}',
20
+ '# --- VANGUARD PROTECTION END ---'
21
+ ].join('\n');
22
+
23
+ const POWERSHELL_TEMPLATE = [
24
+ '# --- VANGUARD PROTECTION START ---',
25
+ '# Universal Interceptor for PowerShell',
26
+ 'function git {',
27
+ ' if ($args[0] -eq "clone" -and !$env:VANGUARD_INTERNAL) {',
28
+ ' $env:VANGUARD_INTERNAL = "1"',
29
+ ' try {',
30
+ ' vanguard clone @(if ($args.Length -gt 1) { $args[1..($args.Length-1)] })',
31
+ ' } finally {',
32
+ ' $env:VANGUARD_INTERNAL = $null',
33
+ ' }',
34
+ ' } else {',
35
+ ' & (Get-Command git -CommandType Application) @args',
36
+ ' }',
37
+ '}',
38
+ '# --- VANGUARD PROTECTION END ---'
39
+ ].join('\n');
40
+
41
+ const FISH_TEMPLATE = [
42
+ '# --- VANGUARD PROTECTION START ---',
43
+ '# Universal Interceptor for Fish',
44
+ 'function git',
45
+ ' if test "$argv[1]" = "clone"; and test -z "$VANGUARD_INTERNAL"',
46
+ ' set -gx VANGUARD_INTERNAL 1',
47
+ ' vanguard clone $argv[2..-1]',
48
+ ' set -e VANGUARD_INTERNAL',
49
+ ' else',
50
+ ' command git $argv',
51
+ ' end',
52
+ 'end',
53
+ '# --- VANGUARD PROTECTION END ---'
54
+ ].join('\n');
57
55
 
58
56
  export async function runIntegrate() {
59
- console.log(chalk.bold('🐚 Vanguard Shell Integrator\n'));
60
- const spinner = createSpinner('🔍 Detecting shells and profiles...').start();
57
+ console.log(chalk.bold('🐚 Vanguard Shell Integrator (Universal Edition)\n'));
58
+ const spinner = createSpinner('🔍 Probing environment for shell profiles...').start();
61
59
 
62
60
  const home = os.homedir();
61
+ const isWin = os.platform() === 'win32';
63
62
  let detected = [];
64
63
 
65
- // Check Unix shells
66
- for (const [shell, info] of Object.entries(SCRIPTS)) {
67
- if (shell === 'powershell') continue;
68
- const profilePath = path.join(home, info.file);
69
- if (await fs.pathExists(profilePath)) {
70
- detected.push({ name: shell, path: profilePath, template: info.template });
64
+ // 1. Detect Unix-based Shells (Linux/macOS)
65
+ const unixShells = [
66
+ { name: 'zsh', file: '.zshrc', template: BASH_ZSH_TEMPLATE },
67
+ { name: 'bash', file: '.bashrc', template: BASH_ZSH_TEMPLATE },
68
+ { name: 'bash_profile', file: '.bash_profile', template: BASH_ZSH_TEMPLATE },
69
+ { name: 'fish', file: '.config/fish/config.fish', template: FISH_TEMPLATE }
70
+ ];
71
+
72
+ for (const shell of unixShells) {
73
+ const p = path.join(home, shell.file);
74
+ if (await fs.pathExists(p)) {
75
+ detected.push({ ...shell, path: p });
71
76
  }
72
77
  }
73
78
 
74
- // Check PowerShell with robust detection
75
- const psProfiles = [];
76
- if (os.platform() === 'win32') {
77
- const documentsPath = path.join(home, 'Documents');
78
- const oneDriveDocumentsPath = path.join(home, 'OneDrive', 'Documents');
79
- const oneDriveBelgelerPath = path.join(home, 'OneDrive', 'Belgeler'); // User specific Turkish path
80
-
81
- const possibleRoots = [documentsPath, oneDriveDocumentsPath, oneDriveBelgelerPath, home];
82
- const psFolders = ['PowerShell', 'WindowsPowerShell'];
83
-
84
- for (const root of possibleRoots) {
85
- for (const folder of psFolders) {
86
- const profile = path.join(root, folder, 'Microsoft.PowerShell_profile.ps1');
87
- psProfiles.push(profile);
88
- }
79
+ // 2. Detect PowerShell Profiles
80
+ const psFolders = [
81
+ path.join(home, 'Documents', 'PowerShell'),
82
+ path.join(home, 'Documents', 'WindowsPowerShell'),
83
+ path.join(home, 'OneDrive', 'Documents', 'PowerShell'),
84
+ path.join(home, 'OneDrive', 'Documents', 'WindowsPowerShell'),
85
+ path.join(home, 'OneDrive', 'Belgeler', 'PowerShell'),
86
+ path.join(home, 'OneDrive', 'Belgeler', 'WindowsPowerShell'),
87
+ path.join(home, '.config', 'powershell')
88
+ ];
89
+
90
+ for (const folder of psFolders) {
91
+ const p = path.join(folder, 'Microsoft.PowerShell_profile.ps1');
92
+ if (await fs.pathExists(p)) {
93
+ detected.push({ name: 'powershell', path: p, template: POWERSHELL_TEMPLATE });
89
94
  }
90
- } else {
91
- psProfiles.push(path.join(home, SCRIPTS.powershell.file));
92
95
  }
93
96
 
94
- for (const profilePath of psProfiles) {
95
- if (await fs.pathExists(profilePath) || (os.platform() === 'win32' && profilePath.includes('PowerShell'))) {
96
- if (!detected.some(d => d.path === profilePath)) {
97
- detected.push({ name: 'powershell', path: profilePath, template: POWERSHELL_TEMPLATE });
98
- }
99
- }
97
+ if (isWin && !detected.some(sh => sh.name === 'powershell')) {
98
+ const p = path.join(home, 'Documents', 'PowerShell', 'Microsoft.PowerShell_profile.ps1');
99
+ detected.push({ name: 'powershell', path: p, template: POWERSHELL_TEMPLATE });
100
100
  }
101
101
 
102
102
  if (detected.length === 0) {
103
- spinner.fail('No supported shell profiles detected.');
103
+ spinner.fail('No shell profiles found.');
104
104
  return;
105
105
  }
106
106
 
107
- spinner.succeed(`Detected ${detected.length} shell profiles.`);
107
+ spinner.succeed(`Identified ${detected.length} active Shell targets.`);
108
108
 
109
109
  for (const shell of detected) {
110
- const profilePath = shell.path;
111
- const backupPath = `${profilePath}.backup`;
112
-
113
110
  try {
114
- // Backup
115
- if (await fs.pathExists(profilePath)) {
116
- await fs.copy(profilePath, backupPath);
117
- console.log(chalk.dim(`💾 Backup created: ${backupPath}`));
111
+ const profileContent = await fs.readFile(shell.path, 'utf-8').catch(() => '');
112
+
113
+ if (profileContent) {
114
+ await fs.copy(shell.path, `${shell.path}.vanguard_backup`);
118
115
  } else {
119
- await fs.ensureDir(path.dirname(profilePath));
120
- await fs.writeFile(profilePath, '');
116
+ await fs.ensureDir(path.dirname(shell.path));
121
117
  }
122
118
 
123
- const content = await fs.readFile(profilePath, 'utf-8');
124
- if (content.includes('VANGUARD PROTECTION START')) {
125
- // Update existing integration if template differs significantly
126
- console.log(chalk.yellow(`⏩ ${shell.name} already integrated. Updating wrapper...`));
127
- const stripped = content.replace(/# --- VANGUARD PROTECTION START ---[\s\S]*?# --- VANGUARD PROTECTION END ---/g, '').trim();
128
- await fs.writeFile(profilePath, stripped + '\n' + shell.template);
119
+ if (profileContent.includes('VANGUARD PROTECTION START')) {
120
+ console.log(chalk.dim(` ⏩ ${shell.name} already protected. Synchronizing logic...`));
121
+ const newContent = profileContent.replace(
122
+ /# --- VANGUARD PROTECTION START ---[\s\S]*?# --- VANGUARD PROTECTION END ---/g,
123
+ shell.template.trim()
124
+ );
125
+ await fs.writeFile(shell.path, newContent);
129
126
  } else {
130
- await fs.appendFile(profilePath, '\n' + shell.template);
127
+ await fs.appendFile(shell.path, `\n${shell.template}\n`);
128
+ console.log(chalk.green(` ✅ ${shell.name} protection INJECTED!`));
131
129
  }
132
- console.log(chalk.green(`✅ Integrated with ${shell.name} (${profilePath})`));
133
- } catch (err) {
134
- console.log(chalk.red(`❌ Failed to integrate with ${shell.name}: ${err.message}`));
130
+ } catch (e) {
131
+ console.log(chalk.red(` ❌ Error securing ${shell.name}: ${e.message}`));
135
132
  }
136
133
  }
137
134
 
138
- console.log(chalk.bold('\nInvisible Protection Active! Restart your terminal to apply. 🛡️'));
135
+ console.log(chalk.bold('\n🛡️ Invisible Protection is now armed across your system.'));
136
+ console.log(chalk.cyan('👉 ACTION REQUIRED: Fully restart your terminal application to activate the shield.\n'));
139
137
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vanguard-cli",
3
- "version": "3.1.10",
3
+ "version": "3.1.12",
4
4
  "description": "AI-Powered Supply Chain Firewall for Git",
5
5
  "type": "module",
6
6
  "bin": {