Skip to content

Commit 5443185

Browse files
committed
feat(cli): Add checking for git and gh CLI tools in GitHub mode
Closes #217 - Enable GitHub mode by default - Add automatic checking for git and gh CLI tools when GitHub mode is enabled - Disable GitHub mode if required tools are not available or not authenticated - Update README.md with information about the new behavior - Update tsconfig.json to exclude test files from build
1 parent 8996f36 commit 5443185

File tree

5 files changed

+28
-26
lines changed

5 files changed

+28
-26
lines changed

packages/cli/README.md

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,47 +52,42 @@ MyCoder includes a GitHub mode that enables the agent to work with GitHub issues
5252
- Create PRs when work is complete
5353
- Create additional GitHub issues for follow-up tasks or ideas
5454

55-
To enable GitHub mode:
55+
GitHub mode is **enabled by default** but requires the Git and GitHub CLI tools to be installed and configured:
5656

57-
1. Via CLI option (overrides config file):
58-
59-
```bash
60-
mycoder --githubMode true
61-
```
62-
63-
2. Via configuration file:
57+
- Git CLI (`git`) must be installed
58+
- GitHub CLI (`gh`) must be installed and authenticated
6459

65-
```js
66-
// mycoder.config.js
67-
export default {
68-
githubMode: true,
69-
// other configuration options...
70-
};
71-
```
60+
MyCoder will automatically check for these requirements when GitHub mode is enabled and will:
61+
- Warn you if any requirements are missing
62+
- Automatically disable GitHub mode if the required tools are not available or not authenticated
7263

73-
To disable GitHub mode:
64+
To manually enable/disable GitHub mode:
7465

75-
1. Via CLI option:
66+
1. Via CLI option (overrides config file):
7667

7768
```bash
78-
mycoder --githubMode false
69+
mycoder --githubMode true # Enable GitHub mode
70+
mycoder --githubMode false # Disable GitHub mode
7971
```
8072

8173
2. Via configuration file:
8274

8375
```js
8476
// mycoder.config.js
8577
export default {
86-
githubMode: false,
78+
githubMode: true, // Enable GitHub mode (default)
8779
// other configuration options...
8880
};
8981
```
9082

9183
Requirements for GitHub mode:
9284

85+
- Git CLI (`git`) needs to be installed
9386
- GitHub CLI (`gh`) needs to be installed and authenticated
9487
- User needs to have appropriate GitHub permissions for the target repository
9588

89+
If GitHub mode is enabled but the requirements are not met, MyCoder will provide instructions on how to install and configure the missing tools.
90+
9691
## Configuration
9792

9893
MyCoder is configured using a `mycoder.config.js` file in your project root, similar to ESLint and other modern JavaScript tools. This file exports a configuration object with your preferred settings.

packages/cli/src/commands/$default.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ import { TokenTracker } from 'mycoder-agent/dist/core/tokens.js';
2020
import { SharedOptions } from '../options.js';
2121
import { captureException } from '../sentry/index.js';
2222
import { getConfigFromArgv, loadConfig } from '../settings/config.js';
23-
import { checkGitHubTools, getGitHubModeWarning } from '../utils/githubTools.js';
23+
import { checkGitCli } from '../utils/gitCliCheck.js';
2424
import { nameToLogIndex } from '../utils/nameToLogIndex.js';
2525
import { checkForUpdates, getPackageInfo } from '../utils/versionCheck.js';
26-
import { checkGitCli } from '../utils/gitCliCheck.js';
2726

2827
import type { CommandModule, Argv } from 'yargs';
2928

@@ -73,8 +72,14 @@ export const command: CommandModule<SharedOptions, DefaultArgs> = {
7372
if (!gitCliCheck.gitAvailable || !gitCliCheck.ghAvailable) {
7473
logger.warn('GitHub mode requires git and gh CLI tools to be installed.');
7574
logger.warn('Please install the missing tools or disable GitHub mode with --githubMode false');
75+
// Disable GitHub mode if git or gh CLI is not available
76+
logger.info('Disabling GitHub mode due to missing CLI tools.');
77+
config.githubMode = false;
7678
} else if (!gitCliCheck.ghAuthenticated) {
7779
logger.warn('GitHub CLI is not authenticated. Please run "gh auth login" to authenticate.');
80+
// Disable GitHub mode if gh CLI is not authenticated
81+
logger.info('Disabling GitHub mode due to unauthenticated GitHub CLI.');
82+
config.githubMode = false;
7883
}
7984
} else {
8085
logger.info('GitHub mode is enabled and all required CLI tools are available.');

packages/cli/src/options.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ export const sharedOptions = {
8888
} as const,
8989
githubMode: {
9090
type: 'boolean',
91-
description: 'Enable GitHub mode for working with issues and PRs',
91+
description: 'Enable GitHub mode for working with issues and PRs (requires git and gh CLI tools)',
92+
default: true,
9293
} as const,
9394
upgradeCheck: {
9495
type: 'boolean',

packages/cli/src/utils/gitCliCheck.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async function checkGitAvailable(): Promise<boolean> {
2121
try {
2222
await execAsync('git --version');
2323
return true;
24-
} catch (error) {
24+
} catch {
2525
return false;
2626
}
2727
}
@@ -33,7 +33,7 @@ async function checkGhAvailable(): Promise<boolean> {
3333
try {
3434
await execAsync('gh --version');
3535
return true;
36-
} catch (error) {
36+
} catch {
3737
return false;
3838
}
3939
}
@@ -45,7 +45,7 @@ async function checkGhAuthenticated(): Promise<boolean> {
4545
try {
4646
const { stdout } = await execAsync('gh auth status');
4747
return stdout.includes('Logged in to');
48-
} catch (error) {
48+
} catch {
4949
return false;
5050
}
5151
}

packages/cli/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,6 @@
4444
"allowJs": false,
4545
"checkJs": false
4646
},
47-
"include": ["src/**/*"]
47+
"include": ["src/**/*"],
48+
"exclude": ["src/**/*.test.ts", "src/**/*.spec.ts"]
4849
}

0 commit comments

Comments
 (0)