husky-ai 1.0.2 → 1.0.4

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.
@@ -42,24 +42,63 @@ export async function initCommand() {
42
42
  ]);
43
43
  // Handle Installation
44
44
  if (engine === 'install-opencode') {
45
- const spinner = ora('Installing OpenCode globally...').start();
45
+ const spinner = ora('Installing OpenCode...').start();
46
46
  try {
47
- await execa('npm', ['install', '-g', 'opencode']);
48
- spinner.succeed('OpenCode installed successfully!');
47
+ // Try global install first
48
+ spinner.text = 'Attempting global install...';
49
+ await execa('npm', ['install', '-g', 'opencode-ai']);
50
+ spinner.succeed('OpenCode installed globally!');
49
51
  engine = 'opencode';
50
52
  }
51
53
  catch (e) {
52
- spinner.fail('Installation failed.');
53
- console.log(chalk.yellow('⚠️ We could not install OpenCode automatically (permission error?).'));
54
- console.log(chalk.yellow('Please run this command manually:'));
55
- console.log(chalk.bold('npm install -g opencode'));
56
- console.log(chalk.yellow('\nOr use the official install script:'));
57
- console.log(chalk.bold('curl -fsSL https://opencode.ai/install | bash'));
58
- return;
54
+ // Fallback to local install
55
+ spinner.text = 'Global install failed. Attempting local install...';
56
+ try {
57
+ await execa('npm', ['install', '--save-dev', 'opencode-ai']);
58
+ spinner.succeed('OpenCode installed locally (devDependencies).');
59
+ engine = 'opencode';
60
+ }
61
+ catch (innerError) {
62
+ spinner.fail('Installation failed.');
63
+ console.log(chalk.yellow('⚠️ We could not install OpenCode automatically.'));
64
+ console.log(chalk.yellow('Please run one of these commands manually:'));
65
+ console.log(chalk.bold(' npm install -g opencode-ai'));
66
+ console.log(chalk.bold(' npm install --save-dev opencode-ai'));
67
+ return;
68
+ }
69
+ }
70
+ }
71
+ // 3. Verify Auth
72
+ const authSpinner = ora('Verifying OpenCode authentication...').start();
73
+ try {
74
+ // Try a simple run command to see if it works
75
+ await execa('opencode', ['run', 'hi'], {
76
+ input: '',
77
+ timeout: 10000, // Give it a moment (some models are slow)
78
+ env: { ...process.env, CI: 'true' }
79
+ });
80
+ authSpinner.succeed('Authenticated with OpenCode.');
81
+ }
82
+ catch (e) {
83
+ authSpinner.fail('OpenCode authentication check failed.');
84
+ console.log(chalk.yellow('\nYou may need to log in to OpenCode to use the reviewer.'));
85
+ console.log(chalk.gray('(If you are using a local LLM or custom provider, you might be okay to skip this.)'));
86
+ const { doLogin } = await inquirer.prompt([{
87
+ type: 'confirm',
88
+ name: 'doLogin',
89
+ message: 'Would you like to run "opencode auth login" now?',
90
+ default: true
91
+ }]);
92
+ if (doLogin) {
93
+ try {
94
+ await execa('opencode', ['auth', 'login'], { stdio: 'inherit' });
95
+ console.log(chalk.green('\nLogin flow completed.'));
96
+ }
97
+ catch (loginErr) {
98
+ console.error(chalk.red('\nLogin command failed/cancelled. Please run "opencode auth login" manually.'));
99
+ }
59
100
  }
60
101
  }
61
- // 3. Verify Auth (Stub for now)
62
- // TODO: Add actual auth check command here
63
102
  // 4. Install Husky
64
103
  const pkg = getPackageJson();
65
104
  const hasHusky = pkg?.devDependencies?.husky || pkg?.dependencies?.husky;
@@ -62,6 +62,7 @@ export async function reviewCommand() {
62
62
  // console.log("Sending prompt to OpenCode...");
63
63
  const { stdout } = await execa('opencode', ['run', prompt], {
64
64
  input: '',
65
+ preferLocal: true,
65
66
  env: { ...process.env, CI: 'true', NO_COLOR: 'true' }
66
67
  });
67
68
  // console.log("Got response length:", stdout.length);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "husky-ai",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Zero-config AI code review hook for git commits",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",