@amirdaraee/namewise 0.3.1 → 0.4.0

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 (59) hide show
  1. package/.github/workflows/build.yml +49 -0
  2. package/.github/workflows/publish.yml +65 -22
  3. package/.github/workflows/test.yml +17 -8
  4. package/README.md +85 -9
  5. package/RELEASE.md +155 -0
  6. package/dist/cli/commands.d.ts.map +1 -1
  7. package/dist/cli/commands.js +44 -7
  8. package/dist/cli/commands.js.map +1 -1
  9. package/dist/cli/rename.d.ts.map +1 -1
  10. package/dist/cli/rename.js +27 -12
  11. package/dist/cli/rename.js.map +1 -1
  12. package/dist/index.js +39 -2
  13. package/dist/index.js.map +1 -1
  14. package/dist/services/ai-factory.d.ts +6 -1
  15. package/dist/services/ai-factory.d.ts.map +1 -1
  16. package/dist/services/ai-factory.js +11 -1
  17. package/dist/services/ai-factory.js.map +1 -1
  18. package/dist/services/file-renamer.d.ts.map +1 -1
  19. package/dist/services/file-renamer.js +20 -4
  20. package/dist/services/file-renamer.js.map +1 -1
  21. package/dist/services/lmstudio-service.d.ts +14 -0
  22. package/dist/services/lmstudio-service.d.ts.map +1 -0
  23. package/dist/services/lmstudio-service.js +109 -0
  24. package/dist/services/lmstudio-service.js.map +1 -0
  25. package/dist/services/ollama-service.d.ts +14 -0
  26. package/dist/services/ollama-service.d.ts.map +1 -0
  27. package/dist/services/ollama-service.js +107 -0
  28. package/dist/services/ollama-service.js.map +1 -0
  29. package/dist/types/index.d.ts +6 -2
  30. package/dist/types/index.d.ts.map +1 -1
  31. package/package.json +1 -1
  32. package/src/cli/commands.ts +44 -7
  33. package/src/cli/rename.ts +26 -12
  34. package/src/index.ts +39 -2
  35. package/src/services/ai-factory.ts +24 -1
  36. package/src/services/file-renamer.ts +22 -4
  37. package/src/services/lmstudio-service.ts +161 -0
  38. package/src/services/ollama-service.ts +147 -0
  39. package/src/types/index.ts +7 -2
  40. package/tests/data/console-test-1.txt +1 -0
  41. package/tests/data/console-test-2.txt +1 -0
  42. package/tests/data/console-test-long-filename-for-display-testing.txt +1 -0
  43. package/tests/data/failure.txt +1 -0
  44. package/tests/data/file1.txt +1 -0
  45. package/tests/data/file2.txt +1 -0
  46. package/tests/data/much-longer-filename-to-test-clearing.txt +1 -0
  47. package/tests/data/short.txt +1 -0
  48. package/tests/data/single-file.txt +1 -0
  49. package/tests/data/success.txt +1 -0
  50. package/tests/data/this-is-a-very-long-filename-that-should-be-truncated-for-better-display-purposes.txt +1 -0
  51. package/tests/data/very-long-filename-that-should-be-cleared-properly.txt +1 -0
  52. package/tests/data/x.txt +1 -0
  53. package/tests/integration/end-to-end.test.ts +2 -2
  54. package/tests/unit/cli/commands.test.ts +5 -5
  55. package/tests/unit/services/ai-factory.test.ts +49 -1
  56. package/tests/unit/services/file-renamer.test.ts +215 -0
  57. package/tests/unit/services/lmstudio-service.test.ts +326 -0
  58. package/tests/unit/services/ollama-service.test.ts +264 -0
  59. package/.github/workflows/ci.yml +0 -78
@@ -0,0 +1,49 @@
1
+ name: Build Pipeline
2
+
3
+ on:
4
+ workflow_dispatch: # Allows manual triggering
5
+ push:
6
+ branches: [ main ]
7
+ workflow_call: # Allows this workflow to be called by other workflows
8
+
9
+ jobs:
10
+ build:
11
+ name: Build Project
12
+ runs-on: ubuntu-latest
13
+
14
+ steps:
15
+ - name: Checkout code
16
+ uses: actions/checkout@v4
17
+
18
+ - name: Setup Node.js
19
+ uses: actions/setup-node@v4
20
+ with:
21
+ node-version: '22'
22
+ cache: 'npm'
23
+
24
+ - name: Install dependencies
25
+ run: npm ci
26
+
27
+ - name: Build project
28
+ run: npm run build
29
+
30
+ - name: Test CLI build
31
+ run: |
32
+ node dist/index.js --help
33
+ node dist/index.js --version
34
+
35
+ - name: Upload build artifacts
36
+ uses: actions/upload-artifact@v4
37
+ with:
38
+ name: build-artifacts-${{ github.sha }}
39
+ path: |
40
+ dist/
41
+ package.json
42
+ package-lock.json
43
+ README.md
44
+ LICENSE
45
+ CHANGELOG.md
46
+ retention-days: 30
47
+
48
+ - name: Build success notification
49
+ run: echo "✅ Build completed successfully for commit ${{ github.sha }}"
@@ -1,43 +1,86 @@
1
- name: Publish Package
1
+ name: Publish Pipeline
2
2
 
3
3
  on:
4
+ workflow_dispatch: # Allows manual triggering
4
5
  release:
5
- types: [created]
6
+ types: [published]
6
7
 
7
8
  jobs:
8
- publish-npm:
9
+ publish:
10
+ name: Publish Package
9
11
  runs-on: ubuntu-latest
12
+ environment: production # Requires environment approval for production
13
+
10
14
  steps:
11
- - uses: actions/checkout@v4
12
- - uses: actions/setup-node@v4
15
+ - name: Checkout code
16
+ uses: actions/checkout@v4
17
+
18
+ - name: Setup Node.js
19
+ uses: actions/setup-node@v4
13
20
  with:
14
21
  node-version: '22'
15
- registry-url: https://registry.npmjs.org/
16
- - run: npm ci
17
- - run: npm run build
18
- - run: npm run test:run
19
- - run: npm publish
22
+ registry-url: 'https://registry.npmjs.org'
23
+ cache: 'npm'
24
+
25
+ - name: Install dependencies
26
+ run: npm ci
27
+
28
+ - name: Run tests
29
+ run: npm run test:run
30
+
31
+ - name: Build project
32
+ run: npm run build
33
+
34
+ - name: Publish to NPM
35
+ run: npm publish
20
36
  env:
21
37
  NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
38
+
39
+ - name: Publish success notification
40
+ run: echo "✅ Package published to NPM successfully"
22
41
 
23
- publish-gpr:
42
+ publish-github:
43
+ name: Publish to GitHub Packages
24
44
  runs-on: ubuntu-latest
45
+ needs: publish
25
46
  permissions:
26
47
  contents: read
27
48
  packages: write
49
+
28
50
  steps:
29
- - uses: actions/checkout@v4
30
- - uses: actions/setup-node@v4
51
+ - name: Checkout code
52
+ uses: actions/checkout@v4
53
+
54
+ - name: Setup Node.js
55
+ uses: actions/setup-node@v4
31
56
  with:
32
57
  node-version: '22'
33
- registry-url: https://npm.pkg.github.com/
34
- - run: npm ci
35
- - run: npm run build
36
- - run: npm run test:run
37
- - name: Publish to GitHub Packages
58
+ registry-url: 'https://npm.pkg.github.com'
59
+ cache: 'npm'
60
+
61
+ - name: Install dependencies
62
+ run: npm ci
63
+
64
+ - name: Build project
65
+ run: npm run build
66
+
67
+ - name: Configure package for GitHub Packages
38
68
  run: |
39
- echo "registry=https://npm.pkg.github.com/" > .npmrc
40
- echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" >> .npmrc
41
- npm publish
69
+ cp package.json package.json.backup
70
+ node -e "
71
+ const pkg = require('./package.json');
72
+ pkg.name = '@${{ github.repository_owner }}/' + pkg.name.split('/').pop();
73
+ require('fs').writeFileSync('package.json', JSON.stringify(pkg, null, 2));
74
+ "
75
+
76
+ - name: Publish to GitHub Packages
77
+ run: npm publish
42
78
  env:
43
- NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
79
+ NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
80
+
81
+ - name: Restore original package.json
82
+ run: mv package.json.backup package.json
83
+ if: always()
84
+
85
+ - name: GitHub Packages success notification
86
+ run: echo "✅ Package published to GitHub Packages successfully"
@@ -1,21 +1,24 @@
1
- name: Test
1
+ name: Test Pipeline
2
2
 
3
3
  on:
4
+ workflow_dispatch: # Allows manual triggering
4
5
  push:
5
- branches: [ main ]
6
+ branches: [ main, develop ]
6
7
  pull_request:
7
8
  branches: [ main ]
8
9
 
9
10
  jobs:
10
11
  test:
12
+ name: Run Tests
11
13
  runs-on: ubuntu-latest
12
14
 
13
15
  strategy:
14
16
  matrix:
15
17
  node-version: [18, 20, 22]
16
-
18
+
17
19
  steps:
18
- - uses: actions/checkout@v4
20
+ - name: Checkout code
21
+ uses: actions/checkout@v4
19
22
 
20
23
  - name: Setup Node.js ${{ matrix.node-version }}
21
24
  uses: actions/setup-node@v4
@@ -26,12 +29,18 @@ jobs:
26
29
  - name: Install dependencies
27
30
  run: npm ci
28
31
 
29
- - name: Build project
30
- run: npm run build
32
+ - name: Run linter (if available)
33
+ run: npm run lint --if-present
31
34
 
32
35
  - name: Run tests
33
36
  run: npm run test:run
34
37
 
35
- - name: Run coverage
38
+ - name: Generate coverage report
36
39
  run: npm run test:coverage
37
- if: matrix.node-version == '22'
40
+ if: matrix.node-version == '22'
41
+
42
+ - name: Upload coverage reports
43
+ uses: codecov/codecov-action@v3
44
+ if: matrix.node-version == '22'
45
+ with:
46
+ fail_ci_if_error: false
package/README.md CHANGED
@@ -8,13 +8,15 @@
8
8
 
9
9
  🤖 **AI-Powered File Renaming CLI Tool**
10
10
 
11
- Automatically rename files based on their content using Claude or OpenAI. Transform messy filenames like `document1.pdf` or `IMG_20240315_143022.pdf` into descriptive names like `project-requirements-document.pdf` or `quarterly-sales-report-q4-2023.pdf`.
11
+ Automatically rename files based on their content using AI providers (Claude, OpenAI, Ollama, LMStudio). Transform messy filenames like `document1.pdf` or `IMG_20240315_143022.pdf` into descriptive names like `project-requirements-document.pdf` or `quarterly-sales-report-q4-2023.pdf`.
12
12
 
13
13
  > **Perfect for**: Document management, file organization, bulk renaming based on content analysis
14
14
 
15
15
  ## Features
16
16
 
17
- - **AI-Powered Renaming**: Uses Claude or OpenAI to generate descriptive filenames based on document content
17
+ - **AI-Powered Renaming**: Uses cloud providers (Claude, OpenAI) or local LLMs (Ollama, LMStudio) to generate descriptive filenames
18
+ - **Privacy First**: Local LLM support means your files never leave your machine
19
+ - **Cost Effective**: Use free local models or pay-per-use cloud APIs
18
20
  - **Personal File Templates**: Customizable templates for different file categories (documents, movies, music, series, photos, books)
19
21
  - **Smart Categorization**: Automatic file type detection or manual category selection
20
22
  - **Naming Convention Options**: 6 different formats (kebab-case, snake_case, camelCase, PascalCase, lowercase, UPPERCASE)
@@ -63,7 +65,9 @@ namewise rename <directory> [options]
63
65
  ### Options Reference
64
66
  | Option | Description | Default |
65
67
  |--------|-------------|---------|
66
- | `--provider` | AI provider (`claude` or `openai`) | `claude` |
68
+ | `--provider` | AI provider (`claude`, `openai`, `ollama`, `lmstudio`) | `claude` |
69
+ | `--base-url` | Base URL for local LLM providers | Auto-detected |
70
+ | `--model` | Model name for local LLM providers | Provider default |
67
71
  | `--api-key` | API key for the chosen provider | Interactive prompt |
68
72
  | `--case` | Naming convention (kebab-case, snake_case, camelCase, PascalCase, lowercase, UPPERCASE) | `kebab-case` |
69
73
  | `--template` | File category template (document, movie, music, series, photo, book, general, auto) | `general` |
@@ -110,6 +114,35 @@ namewise rename ./docs --case snake_case --dry-run
110
114
  # Result: project_requirements_document.pdf
111
115
  ```
112
116
 
117
+ **Local LLMs (Privacy-First, No API Keys):**
118
+ ```bash
119
+ # Ollama - requires 'ollama serve' running
120
+ namewise rename ./documents --provider ollama --dry-run
121
+ # Result: quarterly-financial-report.pdf
122
+
123
+ # Custom Ollama model
124
+ namewise rename ./code --provider ollama --model codellama --dry-run
125
+ # Result: user-authentication-service.js
126
+
127
+ # LMStudio - requires local server enabled
128
+ namewise rename ./contracts --provider lmstudio --dry-run
129
+ # Result: employment-agreement-template.docx
130
+
131
+ # Remote Ollama server
132
+ namewise rename ./files --provider ollama --base-url http://192.168.1.100:11434 --model llama3.1
133
+ ```
134
+
135
+ **Cloud Providers (API Keys Required):**
136
+ ```bash
137
+ # Claude (recommended for accuracy)
138
+ export CLAUDE_API_KEY=your-key
139
+ namewise rename ./documents --provider claude --dry-run
140
+
141
+ # OpenAI
142
+ export OPENAI_API_KEY=your-key
143
+ namewise rename ./files --provider openai --max-size 20 --dry-run
144
+ ```
145
+
113
146
  **Before and After Example:**
114
147
  ```
115
148
  📁 Before:
@@ -147,19 +180,54 @@ Choose from specialized templates for different file types:
147
180
  | `book` | `{author}-{content}` | `george-orwell-1984.pdf` | Books and ebooks |
148
181
  | `auto` | *Automatic* | *Varies by detected type* | Let AI detect and choose best template |
149
182
 
150
- ## 🔑 API Keys Setup
183
+ ## 🔑 AI Provider Setup
184
+
185
+ ### 🏠 Local LLMs (Privacy-First, No API Keys)
151
186
 
152
- ### Claude (Anthropic) - Recommended
187
+ **Ollama** - Recommended for privacy
188
+ 1. Install: Download from [ollama.ai](https://ollama.ai)
189
+ 2. Start server: `ollama serve`
190
+ 3. Pull model: `ollama pull llama3.1` (or your preferred model)
191
+ 4. Use: `--provider ollama`
192
+
193
+ **LMStudio** - User-friendly interface
194
+ 1. Install: Download from [lmstudio.ai](https://lmstudio.ai)
195
+ 2. Download and load a model in LMStudio
196
+ 3. Enable "Local Server" mode in LMStudio
197
+ 4. Use: `--provider lmstudio`
198
+
199
+ ### ☁️ Cloud Providers (Require API Keys)
200
+
201
+ **Claude (Anthropic)** - Recommended for accuracy
153
202
  1. Visit [Anthropic Console](https://console.anthropic.com/)
154
203
  2. Create an account and generate an API key
155
204
  3. Set as environment variable: `export CLAUDE_API_KEY=your-key`
156
205
 
157
- ### OpenAI
206
+ **OpenAI**
158
207
  1. Visit [OpenAI Platform](https://platform.openai.com/api-keys)
159
208
  2. Create an API key
160
209
  3. Set as environment variable: `export OPENAI_API_KEY=your-key`
161
210
 
162
- > 💡 **Tip**: The tool will prompt for API keys if not provided via command line or environment variables.
211
+ ### 🚀 Quick Start by Privacy Preference
212
+
213
+ **Maximum Privacy (Local Processing):**
214
+ ```bash
215
+ # Setup Ollama
216
+ ollama serve
217
+ ollama pull llama3.1
218
+
219
+ # Use locally - no data leaves your machine
220
+ namewise rename ./documents --provider ollama --dry-run
221
+ ```
222
+
223
+ **Balanced (Cloud with API key):**
224
+ ```bash
225
+ # Use Claude for best accuracy
226
+ export CLAUDE_API_KEY=your-key
227
+ namewise rename ./documents --provider claude --dry-run
228
+ ```
229
+
230
+ > 💡 **Tip**: Local LLMs require no API keys and keep your data private. Cloud providers may offer better accuracy but require API keys and send data externally.
163
231
 
164
232
  ## ⚙️ How It Works
165
233
 
@@ -214,7 +282,9 @@ The project includes comprehensive tests with 65 test cases covering all functio
214
282
 
215
283
  - **Node.js**: 18.0.0 or higher
216
284
  - **TypeScript**: 5.0.0 or higher
217
- - **API Key**: Claude (Anthropic) or OpenAI
285
+ - **AI Provider**: Choose one:
286
+ - **Local**: Ollama or LMStudio (no API key needed)
287
+ - **Cloud**: Claude (Anthropic) or OpenAI API key
218
288
 
219
289
  ## 🐛 Troubleshooting
220
290
 
@@ -226,11 +296,17 @@ The project includes comprehensive tests with 65 test cases covering all functio
226
296
  - Check file is not corrupted
227
297
  - Try reducing max-size limit
228
298
 
229
- **API errors:**
299
+ **API errors (Cloud providers):**
230
300
  - Verify API key is valid
231
301
  - Check internet connection
232
302
  - Ensure sufficient API credits
233
303
 
304
+ **Local LLM connection errors:**
305
+ - Ensure Ollama server is running (`ollama serve`)
306
+ - Check LMStudio local server is enabled
307
+ - Verify correct base URL and port
308
+ - Confirm model is loaded/available
309
+
234
310
  **Permission errors:**
235
311
  - Check file permissions
236
312
  - Run with appropriate user privileges
package/RELEASE.md ADDED
@@ -0,0 +1,155 @@
1
+ # Release Process Documentation
2
+
3
+ This document explains how to release a new version of the Namewise CLI tool.
4
+
5
+ ## Quick Release Commands
6
+
7
+ Based on your `package.json` scripts, you can use these commands for automated releases:
8
+
9
+ ```bash
10
+ npm run release # Patch version (1.0.0 → 1.0.1)
11
+ npm run release:minor # Minor version (1.0.0 → 1.1.0)
12
+ npm run release:major # Major version (1.0.0 → 2.0.0)
13
+ ```
14
+
15
+ These commands will:
16
+ 1. Run tests and build
17
+ 2. Bump the version in `package.json`
18
+ 3. Trigger the auto-release workflow
19
+
20
+ ## Manual Release Process
21
+
22
+ If you prefer to do it manually:
23
+
24
+ ### 1. Prepare the Release
25
+
26
+ ```bash
27
+ # Ensure you're on main branch with latest changes
28
+ git checkout main
29
+ git pull origin main
30
+
31
+ # Run tests and build to ensure everything works
32
+ npm run test:run
33
+ npm run build
34
+ ```
35
+
36
+ ### 2. Update Version
37
+
38
+ Choose the appropriate version bump:
39
+ - **Patch** (bug fixes): `1.0.0 → 1.0.1`
40
+ - **Minor** (new features): `1.0.0 → 1.1.0`
41
+ - **Major** (breaking changes): `1.0.0 → 2.0.0`
42
+
43
+ ```bash
44
+ # Update version in package.json
45
+ npm version patch # or minor, or major
46
+ ```
47
+
48
+ ### 3. Push Changes
49
+
50
+ ```bash
51
+ # Push the version bump commit
52
+ git push origin main
53
+ ```
54
+
55
+ This will trigger the `auto-release.yml` workflow which will:
56
+ - Create a Git tag
57
+ - Publish to NPM automatically
58
+
59
+ ### 4. Create GitHub Release (Optional)
60
+
61
+ To also publish to GitHub Packages:
62
+
63
+ 1. Go to your GitHub repository
64
+ 2. Click "Releases" → "Create a new release"
65
+ 3. Choose the tag that was just created (e.g., `v1.0.1`)
66
+ 4. Add release notes
67
+ 5. Click "Publish release"
68
+
69
+ This triggers the `publish.yml` workflow.
70
+
71
+ ## GitHub Workflows
72
+
73
+ Your project has three separate, independently runnable workflows:
74
+
75
+ ### 1. Test Pipeline (`test.yml`)
76
+ - **Triggers**: Push to main/develop, PRs, manual dispatch
77
+ - **Purpose**: Run tests and linting across Node.js versions
78
+ - **Manual run**: Go to Actions → Test Pipeline → "Run workflow"
79
+
80
+ ### 2. Build Pipeline (`build.yml`)
81
+ - **Triggers**: Push to main, manual dispatch, or called by other workflows
82
+ - **Purpose**: Build the project and create artifacts
83
+ - **Manual run**: Go to Actions → Build Pipeline → "Run workflow"
84
+
85
+ ### 3. Publish Pipeline (`publish.yml`)
86
+ - **Triggers**: GitHub releases, manual dispatch
87
+ - **Purpose**: Publish to NPM and GitHub Packages
88
+ - **Manual run**: Go to Actions → Publish Pipeline → "Run workflow"
89
+
90
+ ### 4. Auto Release (`auto-release.yml`)
91
+ - **Triggers**: Push to main when package.json version changes
92
+ - **Purpose**: Automatically create tags and publish when version is bumped
93
+
94
+ ## Prerequisites
95
+
96
+ ### NPM Token
97
+ Add `NPM_TOKEN` to your GitHub repository secrets:
98
+ 1. Go to npmjs.com → Access Tokens → Generate New Token
99
+ 2. Copy the token
100
+ 3. In GitHub: Settings → Secrets → Actions → New repository secret
101
+ 4. Name: `NPM_TOKEN`, Value: your token
102
+
103
+ ### Production Environment (Optional)
104
+ For extra safety, create a production environment:
105
+ 1. GitHub → Settings → Environments → New environment
106
+ 2. Name: `production`
107
+ 3. Add protection rules (require reviews, etc.)
108
+
109
+ ## Version Strategy
110
+
111
+ Follow [Semantic Versioning](https://semver.org/):
112
+
113
+ - **Major** (`X.0.0`): Breaking changes that require user action
114
+ - **Minor** (`0.X.0`): New features that are backward compatible
115
+ - **Patch** (`0.0.X`): Bug fixes and small improvements
116
+
117
+ ## Troubleshooting
118
+
119
+ ### Release Failed
120
+ - Check the Actions tab for error details
121
+ - Ensure NPM_TOKEN is valid
122
+ - Verify package.json version was actually changed
123
+ - Make sure tests pass: `npm run test:run`
124
+
125
+ ### Package Already Published
126
+ - NPM doesn't allow republishing the same version
127
+ - Bump the version: `npm version patch`
128
+ - Push: `git push origin main`
129
+
130
+ ### Manual Publishing
131
+ If workflows fail, you can publish manually:
132
+ ```bash
133
+ npm run build
134
+ npm run test:run
135
+ npm publish
136
+ ```
137
+
138
+ ## Example Release Workflow
139
+
140
+ Here's a complete example of releasing version 1.2.3:
141
+
142
+ ```bash
143
+ # 1. Prepare
144
+ git checkout main
145
+ git pull origin main
146
+ npm run test:run
147
+
148
+ # 2. Release (this does everything)
149
+ npm run release:minor # 1.2.2 → 1.2.3
150
+
151
+ # 3. Create GitHub release (optional)
152
+ # Go to GitHub → Releases → Create release from v1.2.3 tag
153
+ ```
154
+
155
+ That's it! The automation handles the rest.
@@ -1 +1 @@
1
- {"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../src/cli/commands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAgBpD"}
1
+ {"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../../src/cli/commands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAqDpD"}
@@ -2,16 +2,53 @@ import { renameFiles } from './rename.js';
2
2
  export function setupCommands(program) {
3
3
  program
4
4
  .command('rename')
5
- .description('Rename files in a directory based on their content')
5
+ .description('🚀 Rename files in a directory based on their content using AI analysis')
6
6
  .argument('<directory>', 'Directory containing files to rename')
7
- .option('-p, --provider <provider>', 'AI provider (claude|openai)', 'claude')
8
- .option('-k, --api-key <key>', 'API key for the AI provider')
7
+ .option('-p, --provider <provider>', 'AI provider (claude|openai|ollama|lmstudio)', 'claude')
8
+ .option('-k, --api-key <key>', 'API key for cloud providers (or set CLAUDE_API_KEY/OPENAI_API_KEY)')
9
9
  .option('-c, --case <convention>', 'Naming convention (kebab-case|snake_case|camelCase|PascalCase|lowercase|UPPERCASE)', 'kebab-case')
10
10
  .option('-t, --template <category>', 'File category template (document|movie|music|series|photo|book|general|auto)', 'general')
11
- .option('-n, --name <personalName>', 'Personal name to include in filenames')
12
- .option('-d, --date <format>', 'Date format (YYYY-MM-DD|YYYY|YYYYMMDD|none)', 'none')
13
- .option('--dry-run', 'Preview changes without renaming files', false)
14
- .option('--max-size <size>', 'Maximum file size in MB', '10')
11
+ .option('-n, --name <personalName>', 'Personal name to include in filenames (for document/photo templates)')
12
+ .option('-d, --date <format>', 'Date format to include (YYYY-MM-DD|YYYY|YYYYMMDD|none)', 'none')
13
+ .option('--dry-run', 'Preview changes without actually renaming files (RECOMMENDED first!)', false)
14
+ .option('--max-size <size>', 'Maximum file size in MB to process', '10')
15
+ .option('--base-url <url>', 'Base URL for local LLM providers (default: ollama=http://localhost:11434, lmstudio=http://localhost:1234)')
16
+ .option('--model <name>', 'Model name for local LLM providers (default: ollama=llama3.1, lmstudio=local-model)')
17
+ .addHelpText('after', `
18
+
19
+ 🔍 How it works:
20
+ 1. Scans directory for supported files (PDF, DOCX, XLSX, TXT, MD, RTF)
21
+ 2. Extracts content and metadata from each file
22
+ 3. Uses AI to analyze content and generate descriptive names
23
+ 4. Applies your chosen template and naming convention
24
+ 5. Renames files (or shows preview with --dry-run)
25
+
26
+ 💡 Pro Tips:
27
+ • Always use --dry-run first to preview changes
28
+ • Use 'auto' template for smart file type detection
29
+ • Personal templates work great for documents and photos
30
+ • Set API keys as environment variables for cloud providers
31
+ • Local LLMs (Ollama/LMStudio) require running servers first
32
+
33
+ 🖥️ Local LLM Setup:
34
+ • Ollama: Start with 'ollama serve' (default: http://localhost:11434)
35
+ • LMStudio: Enable local server mode (default: http://localhost:1234)
36
+
37
+ 📝 Examples:
38
+ # Safe preview first
39
+ namewise rename ./documents --dry-run
40
+
41
+ # Cloud providers (require API keys)
42
+ namewise rename ./docs --provider claude --template document --name "alice"
43
+ namewise rename ./media --provider openai --template auto
44
+
45
+ # Local LLMs (no API key needed)
46
+ namewise rename ./documents --provider ollama --model llama3.1 --dry-run
47
+ namewise rename ./contracts --provider lmstudio --base-url http://localhost:1234
48
+
49
+ # Custom Ollama setup
50
+ namewise rename ./files --provider ollama --base-url http://192.168.1.100:11434 --model codellama
51
+ `)
15
52
  .action(async (directory, options) => {
16
53
  await renameFiles(directory, options);
17
54
  });
@@ -1 +1 @@
1
- {"version":3,"file":"commands.js","sourceRoot":"","sources":["../../src/cli/commands.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,MAAM,UAAU,aAAa,CAAC,OAAgB;IAC5C,OAAO;SACJ,OAAO,CAAC,QAAQ,CAAC;SACjB,WAAW,CAAC,oDAAoD,CAAC;SACjE,QAAQ,CAAC,aAAa,EAAE,sCAAsC,CAAC;SAC/D,MAAM,CAAC,2BAA2B,EAAE,6BAA6B,EAAE,QAAQ,CAAC;SAC5E,MAAM,CAAC,qBAAqB,EAAE,6BAA6B,CAAC;SAC5D,MAAM,CAAC,yBAAyB,EAAE,oFAAoF,EAAE,YAAY,CAAC;SACrI,MAAM,CAAC,2BAA2B,EAAE,8EAA8E,EAAE,SAAS,CAAC;SAC9H,MAAM,CAAC,2BAA2B,EAAE,uCAAuC,CAAC;SAC5E,MAAM,CAAC,qBAAqB,EAAE,6CAA6C,EAAE,MAAM,CAAC;SACpF,MAAM,CAAC,WAAW,EAAE,wCAAwC,EAAE,KAAK,CAAC;SACpE,MAAM,CAAC,mBAAmB,EAAE,yBAAyB,EAAE,IAAI,CAAC;SAC5D,MAAM,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE;QACnC,MAAM,WAAW,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;AACP,CAAC"}
1
+ {"version":3,"file":"commands.js","sourceRoot":"","sources":["../../src/cli/commands.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,MAAM,UAAU,aAAa,CAAC,OAAgB;IAC5C,OAAO;SACJ,OAAO,CAAC,QAAQ,CAAC;SACjB,WAAW,CAAC,yEAAyE,CAAC;SACtF,QAAQ,CAAC,aAAa,EAAE,sCAAsC,CAAC;SAC/D,MAAM,CAAC,2BAA2B,EAAE,6CAA6C,EAAE,QAAQ,CAAC;SAC5F,MAAM,CAAC,qBAAqB,EAAE,oEAAoE,CAAC;SACnG,MAAM,CAAC,yBAAyB,EAAE,oFAAoF,EAAE,YAAY,CAAC;SACrI,MAAM,CAAC,2BAA2B,EAAE,8EAA8E,EAAE,SAAS,CAAC;SAC9H,MAAM,CAAC,2BAA2B,EAAE,sEAAsE,CAAC;SAC3G,MAAM,CAAC,qBAAqB,EAAE,wDAAwD,EAAE,MAAM,CAAC;SAC/F,MAAM,CAAC,WAAW,EAAE,sEAAsE,EAAE,KAAK,CAAC;SAClG,MAAM,CAAC,mBAAmB,EAAE,oCAAoC,EAAE,IAAI,CAAC;SACvE,MAAM,CAAC,kBAAkB,EAAE,2GAA2G,CAAC;SACvI,MAAM,CAAC,gBAAgB,EAAE,qFAAqF,CAAC;SAC/G,WAAW,CAAC,OAAO,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkCzB,CAAC;SACG,MAAM,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE;QACnC,MAAM,WAAW,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"rename.d.ts","sourceRoot":"","sources":["../../src/cli/rename.ts"],"names":[],"mappings":"AAQA,wBAAsB,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAiFhF"}
1
+ {"version":3,"file":"rename.d.ts","sourceRoot":"","sources":["../../src/cli/rename.ts"],"names":[],"mappings":"AAQA,wBAAsB,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CA+FhF"}
@@ -11,18 +11,28 @@ export async function renameFiles(directory, options) {
11
11
  if (!stats.isDirectory()) {
12
12
  throw new Error(`${directory} is not a directory`);
13
13
  }
14
- // Get API key
14
+ // Get API key for cloud providers only
15
15
  let apiKey = options.apiKey;
16
- if (!apiKey) {
17
- const keyPrompt = await inquirer.prompt([
18
- {
19
- type: 'password',
20
- name: 'apiKey',
21
- message: `Enter your ${options.provider} API key:`,
22
- mask: '*'
23
- }
24
- ]);
25
- apiKey = keyPrompt.apiKey;
16
+ const requiresApiKey = ['claude', 'openai'].includes(options.provider);
17
+ if (requiresApiKey && !apiKey) {
18
+ // Check environment variables first
19
+ if (options.provider === 'claude' && process.env.CLAUDE_API_KEY) {
20
+ apiKey = process.env.CLAUDE_API_KEY;
21
+ }
22
+ else if (options.provider === 'openai' && process.env.OPENAI_API_KEY) {
23
+ apiKey = process.env.OPENAI_API_KEY;
24
+ }
25
+ else {
26
+ const keyPrompt = await inquirer.prompt([
27
+ {
28
+ type: 'password',
29
+ name: 'apiKey',
30
+ message: `Enter your ${options.provider} API key:`,
31
+ mask: '*'
32
+ }
33
+ ]);
34
+ apiKey = keyPrompt.apiKey;
35
+ }
26
36
  }
27
37
  // Create config
28
38
  const config = {
@@ -36,11 +46,16 @@ export async function renameFiles(directory, options) {
36
46
  category: options.template,
37
47
  personalName: options.name,
38
48
  dateFormat: options.date
49
+ },
50
+ // Local LLM specific configuration
51
+ localLLMConfig: {
52
+ baseUrl: options.baseUrl,
53
+ model: options.model
39
54
  }
40
55
  };
41
56
  // Initialize services
42
57
  const parserFactory = new DocumentParserFactory();
43
- const aiService = AIServiceFactory.create(config.aiProvider, apiKey);
58
+ const aiService = AIServiceFactory.create(config.aiProvider, apiKey, config.localLLMConfig);
44
59
  const fileRenamer = new FileRenamer(parserFactory, aiService, config);
45
60
  // Get files to process
46
61
  const files = await getFilesToProcess(directory, config.supportedExtensions);