@kosuke-ai/cli 0.0.7 → 0.0.9

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/README.md CHANGED
@@ -16,25 +16,96 @@ Or use with npx (no installation required):
16
16
  npx @kosuke-ai/cli <command>
17
17
  ```
18
18
 
19
+ ### Use as Library in TypeScript Projects
20
+
21
+ Install as a project dependency:
22
+
23
+ ```bash
24
+ npm install @kosuke-ai/cli
25
+ ```
26
+
27
+ Then import and use programmatically:
28
+
29
+ ```typescript
30
+ import {
31
+ analyseCommand,
32
+ lintCommand,
33
+ syncRulesCommand,
34
+ requirementsCommand,
35
+ discoverFiles,
36
+ createBatches,
37
+ runLint,
38
+ runTypecheck,
39
+ } from '@kosuke-ai/cli';
40
+
41
+ // Run commands programmatically
42
+ await analyseCommand({
43
+ scope: 'src/components',
44
+ pr: false,
45
+ });
46
+
47
+ await lintCommand({ pr: false });
48
+
49
+ // Use utilities
50
+ const files = await discoverFiles({
51
+ types: ['ts', 'tsx'],
52
+ scope: 'lib',
53
+ });
54
+
55
+ const batches = createBatches(files, {
56
+ maxSize: 10,
57
+ groupBy: 'directory',
58
+ });
59
+
60
+ const lintResult = await runLint();
61
+ if (!lintResult.success) {
62
+ console.error('Linting failed:', lintResult.error);
63
+ }
64
+ ```
65
+
66
+ #### Local Development with npm link
67
+
68
+ To develop against a local version of kosuke-cli:
69
+
70
+ ```bash
71
+ # In kosuke-cli directory
72
+ npm run dev:link # Builds, links, and watches for changes
73
+
74
+ # In your project directory
75
+ npm link @kosuke-ai/cli
76
+ ```
77
+
78
+ Now your project will use the local kosuke-cli, and changes will be reflected automatically.
79
+
19
80
  ## Prerequisites
20
81
 
21
- Before using Kosuke CLI, set up the required environment variables:
82
+ Set up the required environment variable:
22
83
 
23
84
  ```bash
24
85
  # Required for Claude API access
25
86
  export ANTHROPIC_API_KEY="your-api-key-here"
26
87
 
27
- # Required for creating pull requests
88
+ # Optional: Only required when using --pr flag
28
89
  export GITHUB_TOKEN="your-github-token-here"
29
90
  ```
30
91
 
31
92
  You can also create a `.env` file in your project root:
32
93
 
33
- ```
94
+ ```env
34
95
  ANTHROPIC_API_KEY=your-api-key-here
35
96
  GITHUB_TOKEN=your-github-token-here
36
97
  ```
37
98
 
99
+ ## Workflow
100
+
101
+ By default, all commands apply changes **locally** without git operations. This allows you to:
102
+
103
+ - Review changes before committing
104
+ - Test fixes in your local environment
105
+ - Iterate quickly without creating PRs
106
+
107
+ Use the `--pr` flag to automatically create a pull request with the changes.
108
+
38
109
  ## Commands
39
110
 
40
111
  ### `kosuke sync-rules`
@@ -44,28 +115,40 @@ Sync rules and documentation from kosuke-template repository.
44
115
  **Options:**
45
116
 
46
117
  - `--force` - Compare files regardless of recent commit history
118
+ - `--pr` - Create a pull request with the changes
119
+ - `--base-branch=<name>` - Base branch for PR (default: current branch)
47
120
 
48
121
  **Examples:**
49
122
 
50
123
  ```bash
124
+ # Sync locally
51
125
  kosuke sync-rules
126
+
127
+ # Force comparison and sync locally
52
128
  kosuke sync-rules --force
129
+
130
+ # Create PR with synced changes
131
+ kosuke sync-rules --pr
132
+
133
+ # Create PR with custom base branch
134
+ kosuke sync-rules --pr --base-branch=develop
53
135
  ```
54
136
 
55
137
  ### `kosuke analyse`
56
138
 
57
- Analyze and fix code quality issues against CLAUDE.md rules. Creates a single PR with all fixes from multiple isolated Claude runs.
139
+ Analyze and fix code quality issues against CLAUDE.md rules. Applies fixes locally by default.
58
140
 
59
141
  **Options:**
60
142
 
61
- - `--dry-run` - Report violations only, don't create PR
143
+ - `--pr` - Create a pull request with fixes
144
+ - `--base-branch=<name>` - Base branch for PR (default: current branch)
62
145
  - `--scope=<dirs>` - Analyze specific directories (comma-separated)
63
146
  - `--types=<exts>` - Analyze specific file types (comma-separated)
64
147
 
65
148
  **Examples:**
66
149
 
67
150
  ```bash
68
- # Analyze entire project
151
+ # Analyze and fix locally
69
152
  kosuke analyse
70
153
 
71
154
  # Analyze specific directories
@@ -74,35 +157,38 @@ kosuke analyse --scope=hooks,lib/trpc
74
157
  # Analyze specific file types
75
158
  kosuke analyse --types=ts,tsx
76
159
 
77
- # Dry run (report only)
78
- kosuke analyse --dry-run
160
+ # Create PR with fixes
161
+ kosuke analyse --pr
162
+
163
+ # Create PR with custom base branch
164
+ kosuke analyse --pr --base-branch=main
79
165
  ```
80
166
 
81
167
  ### `kosuke lint`
82
168
 
83
- Use Claude AI to automatically fix linting errors in your codebase. Runs the lint command from package.json, analyzes the errors, and applies fixes.
169
+ Use Claude AI to automatically fix linting errors. Applies fixes locally by default.
84
170
 
85
171
  **Options:**
86
172
 
87
- - `--dry-run` - Report errors only, don't fix them
88
- - `--no-pr` - Fix locally without creating PR
173
+ - `--pr` - Create a pull request with fixes
174
+ - `--base-branch=<name>` - Base branch for PR (default: current branch)
89
175
 
90
176
  **Examples:**
91
177
 
92
178
  ```bash
93
- # Fix all linting errors and create PR
179
+ # Fix linting errors locally
94
180
  kosuke lint
95
181
 
96
- # Preview what errors would be fixed
97
- kosuke lint --dry-run
182
+ # Create PR with fixes
183
+ kosuke lint --pr
98
184
 
99
- # Fix errors locally without creating PR
100
- kosuke lint --no-pr
185
+ # Create PR with custom base branch
186
+ kosuke lint --pr --base-branch=main
101
187
  ```
102
188
 
103
189
  **Requirements:**
104
190
 
105
- - Your `package.json` must have a `lint` script (e.g., `"lint": "eslint . --fix"`)
191
+ - Your `package.json` must have a `lint` script (e.g., `"lint": "eslint ."`)
106
192
  - The lint script should support the `--fix` flag for auto-fixing
107
193
 
108
194
  ### `kosuke requirements`
@@ -146,7 +232,7 @@ Create a `.kosukeignore` file in your project root to exclude files and director
146
232
 
147
233
  Example:
148
234
 
149
- ```
235
+ ```gitignore
150
236
  # Ignore build outputs
151
237
  dist/
152
238
  build/
package/dist/index.js CHANGED
@@ -26,20 +26,25 @@ import { requirementsCommand } from './kosuke/commands/requirements.js';
26
26
  async function main() {
27
27
  const args = process.argv.slice(2);
28
28
  const command = args[0];
29
- if (!command) {
29
+ if (!command || command === '--help' || command === '-h' || command === 'help') {
30
30
  showHelp();
31
- process.exit(1);
31
+ process.exit(0);
32
32
  }
33
33
  try {
34
34
  switch (command) {
35
35
  case 'sync-rules': {
36
- const hasForceFlag = args.includes('--force');
37
- await syncRulesCommand(hasForceFlag);
36
+ const options = {
37
+ force: args.includes('--force'),
38
+ pr: args.includes('--pr'),
39
+ baseBranch: args.find((arg) => arg.startsWith('--base-branch='))?.split('=')[1],
40
+ };
41
+ await syncRulesCommand(options);
38
42
  break;
39
43
  }
40
44
  case 'analyse': {
41
45
  const options = {
42
- dryRun: args.includes('--dry-run'),
46
+ pr: args.includes('--pr'),
47
+ baseBranch: args.find((arg) => arg.startsWith('--base-branch='))?.split('=')[1],
43
48
  scope: args.find((arg) => arg.startsWith('--scope='))?.split('=')[1],
44
49
  types: args
45
50
  .find((arg) => arg.startsWith('--types='))
@@ -51,8 +56,8 @@ async function main() {
51
56
  }
52
57
  case 'lint': {
53
58
  const options = {
54
- dryRun: args.includes('--dry-run'),
55
- noPr: args.includes('--no-pr'),
59
+ pr: args.includes('--pr'),
60
+ baseBranch: args.find((arg) => arg.startsWith('--base-branch='))?.split('=')[1],
56
61
  };
57
62
  await lintCommand(options);
58
63
  break;
@@ -80,43 +85,49 @@ function showHelp() {
80
85
 
81
86
  COMMANDS:
82
87
 
83
- sync-rules [--force]
88
+ sync-rules [options]
84
89
  Sync rules and documentation from kosuke-template
85
90
 
86
91
  Options:
87
- --force Compare files regardless of recent commit history
92
+ --force Compare files regardless of recent commit history
93
+ --pr Create a pull request with changes
94
+ --base-branch=<name> Base branch for PR (default: current branch)
88
95
 
89
96
  Examples:
90
- kosuke sync-rules
91
- kosuke sync-rules --force
97
+ kosuke sync-rules # Local changes only
98
+ kosuke sync-rules --force # Force comparison
99
+ kosuke sync-rules --pr # Create PR
100
+ kosuke sync-rules --pr --base-branch=develop
92
101
 
93
- analyse
102
+ analyse [options]
94
103
  Analyze and fix code quality issues against CLAUDE.md rules
95
- Creates a single PR with all fixes from multiple isolated Claude runs
104
+ Applies fixes locally by default
96
105
 
97
106
  Options:
98
- --dry-run Report violations only, don't create PR
99
- --scope=<dirs> Analyze specific directories (comma-separated)
100
- --types=<exts> Analyze specific file types (comma-separated)
107
+ --pr Create a pull request with fixes
108
+ --base-branch=<name> Base branch for PR (default: current branch)
109
+ --scope=<dirs> Analyze specific directories (comma-separated)
110
+ --types=<exts> Analyze specific file types (comma-separated)
101
111
 
102
112
  Examples:
103
- kosuke analyse
113
+ kosuke analyse # Local fixes only
114
+ kosuke analyse --pr # Create PR with fixes
104
115
  kosuke analyse --scope=hooks,lib/trpc
105
116
  kosuke analyse --types=ts,tsx
106
- kosuke analyse --dry-run
117
+ kosuke analyse --pr --base-branch=main
107
118
 
108
- lint
119
+ lint [options]
109
120
  Use Claude AI to automatically fix linting errors
110
- Creates a PR with all lint fixes
121
+ Applies fixes locally by default
111
122
 
112
123
  Options:
113
- --dry-run Report errors only, don't fix them
114
- --no-pr Fix locally without creating PR
124
+ --pr Create a pull request with fixes
125
+ --base-branch=<name> Base branch for PR (default: current branch)
115
126
 
116
127
  Examples:
117
- kosuke lint
118
- kosuke lint --dry-run
119
- kosuke lint --no-pr
128
+ kosuke lint # Local fixes only
129
+ kosuke lint --pr # Create PR with fixes
130
+ kosuke lint --pr --base-branch=main
120
131
 
121
132
  requirements
122
133
  Interactive requirements gathering with Claude AI
@@ -125,10 +136,15 @@ COMMANDS:
125
136
  Examples:
126
137
  kosuke requirements
127
138
 
139
+ WORKFLOW:
140
+
141
+ By default, all commands apply changes locally without git operations.
142
+ Use the --pr flag to create a pull request with the changes.
143
+
128
144
  ENVIRONMENT VARIABLES:
129
145
 
130
146
  ANTHROPIC_API_KEY Required for Claude API access
131
- GITHUB_TOKEN Required for creating pull requests
147
+ GITHUB_TOKEN Required when using --pr flag
132
148
 
133
149
  CONFIGURATION:
134
150
 
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRo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K,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;QACzC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,SAAS,QAAQ;IACf,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwEb,CAAC,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -5,7 +5,7 @@
5
5
  * - Each batch of 10-12 files gets its own Claude run
6
6
  * - Claude only sees those specific files (no repository-wide context)
7
7
  * - Validate after each batch, commit locally
8
- * - Push all commits at once and create single PR
8
+ * - If --pr flag: Push all commits and create single PR
9
9
  */
10
10
  import type { AnalyseOptions } from '../types.js';
11
11
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"analyse.d.ts","sourceRoot":"","sources":["../../../kosuke/commands/analyse.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAkBH,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,aAAa,CAAC;AAkR9D;;GAEG;AACH,wBAAsB,cAAc,CAAC,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CA6JhF"}
1
+ {"version":3,"file":"analyse.d.ts","sourceRoot":"","sources":["../../../kosuke/commands/analyse.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AASH,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,aAAa,CAAC;AA4R9D;;GAEG;AACH,wBAAsB,cAAc,CAAC,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAkFhF"}