codemerge-cli 1.2.2 → 1.2.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.
package/README.md CHANGED
@@ -1,893 +1,775 @@
1
- # CodeMerge CLI
2
-
3
- AI-focused code and data preparation utility. Merge multiple files into a single output optimized for AI context windows, with HTTP API for dynamic content generation.
4
-
5
- ## 📋 Table of Contents
6
-
7
- - [Overview](#overview)
8
- - [Installation](#installation)
9
- - [Quick Start](#quick-start)
10
- - [Commands](#commands)
11
- - [Configuration](#configuration)
12
- - [HTTP Server & API](#http-server--api)
13
- - [Use Cases](#use-cases)
14
- - [Advanced Usage](#advanced-usage)
15
- - [Troubleshooting](#troubleshooting)
16
-
17
- ---
18
-
19
- ## 🎯 Overview
20
-
21
- CodeMerge is a CLI tool that:
22
-
23
- - **Merges** multiple code files into a single, structured text file
24
- - **Optimizes** output for AI tools (ChatGPT, Claude, etc.)
25
- - **Respects** .gitignore patterns and custom ignore rules
26
- - **Watches** for file changes and auto-regenerates
27
- - **Serves** content via HTTP API for dynamic access
28
- - **Provides** project structure visualization in JSON
29
- - **Enables** selective file merging via API
30
-
31
- Perfect for:
32
- - Preparing codebases for AI analysis
33
- - Generating context for code reviews
34
- - Creating documentation snapshots
35
- - Sharing project structure with AI assistants
36
- - Building AI-powered developer tools
37
-
38
- ---
39
-
40
- ## 📦 Installation
41
-
42
- ### Global Installation (Recommended)
43
-
44
- ```bash
45
- npm install -g codemerge-cli
46
- ```
47
-
48
- ### Local Project Installation
49
-
50
- ```bash
51
- npm install --save-dev codemerge-cli
52
- ```
53
-
54
- ### Requirements
55
-
56
- - Node.js >= 16.0.0
57
-
58
- ---
59
-
60
- ## 🚀 Quick Start
61
-
62
- ### 1. Initialize Project
63
-
64
- ```bash
65
- # Initialize in current directory
66
- codemerge init
67
-
68
- # Initialize in specific directory
69
- codemerge init ./my-project
70
-
71
- # Force overwrite existing config
72
- codemerge init --force
73
- ```
74
-
75
- This creates:
76
- - `codemerge.json` - Configuration file
77
- - Updates `.gitignore` - Adds output file
78
-
79
- ### 2. Merge Files
80
-
81
- ```bash
82
- # Merge current directory
83
- codemerge use
84
-
85
- # Merge specific directory
86
- codemerge use ./src
87
-
88
- # Custom output file
89
- codemerge use --output my-code.txt
90
-
91
- # Watch for changes
92
- codemerge use --watch
93
- ```
94
-
95
- ### 3. Start HTTP Server
96
-
97
- ```bash
98
- # Start server on default port (9876)
99
- codemerge watch
100
-
101
- # Custom port
102
- codemerge watch --port 3000
103
-
104
- # Custom output and filters
105
- codemerge watch --output api-code.txt --ignore "*.test.ts"
106
- ```
107
-
108
- ---
109
-
110
- ## 🎮 Commands
111
-
112
- ### `codemerge init`
113
-
114
- Initialize CodeMerge in a project.
115
-
116
- ```bash
117
- codemerge init [path] [options]
118
- ```
119
-
120
- **Arguments:**
121
- - `path` - Target directory (default: `.`)
122
-
123
- **Options:**
124
- - `-f, --force` - Overwrite existing configuration
125
-
126
- **What it does:**
127
- - Creates `codemerge.json` with default settings
128
- - Detects project name from `package.json`
129
- - Adds output file to `.gitignore`
130
- - Sets up recommended ignore patterns
131
-
132
- **Example:**
133
- ```bash
134
- codemerge init ./backend --force
135
- ```
136
-
137
- ---
138
-
139
- ### `codemerge use`
140
-
141
- Merge code files into a single output.
142
-
143
- ```bash
144
- codemerge use [path] [options]
145
- ```
146
-
147
- **Arguments:**
148
- - `path` - Input directory to scan (default: `.`)
149
-
150
- **Options:**
151
- - `-o, --output <path>` - Custom output file path
152
- - `-w, --watch` - Watch for file changes
153
- - `--ignore <patterns>` - Additional ignore patterns (comma-separated)
154
- - `--include <patterns>` - Include patterns (comma-separated)
155
-
156
- **Examples:**
157
-
158
- ```bash
159
- # Basic merge
160
- codemerge use
161
-
162
- # Merge src folder only
163
- codemerge use ./src
164
-
165
- # Custom output
166
- codemerge use --output ai-context.txt
167
-
168
- # Watch mode
169
- codemerge use --watch
170
-
171
- # Custom filters
172
- codemerge use --ignore "*.test.ts,*.spec.js" --include "**/*.ts,**/*.js"
173
-
174
- # Combine options
175
- codemerge use ./src --output src-merged.txt --watch
176
- ```
177
-
178
- **Output Format:**
179
-
180
- ```
181
- # Code Merge Output
182
- Generated at: 2026-01-07T01:02:50.588Z
183
- Source path: .
184
- Files processed: 21
185
- Total lines: 1596
186
- Total characters: 45777
187
-
188
- File types:
189
- - ts: 17 files (1442 lines)
190
- - json: 2 files (80 lines)
191
- - js: 1 files (2 lines)
192
-
193
- Project structure & file index:
194
- ./
195
- lib/
196
- - cli.ts (75 lines)
197
- core/
198
- - codeMerger.ts (273 lines)
199
-
200
- ================================================================================
201
-
202
- STARTOFFILE: lib/cli.ts
203
- ----------------------------------------
204
- [file content here]
205
- ----------------------------------------
206
- ENDOFFILE: lib/cli.ts
207
- ```
208
-
209
- ---
210
-
211
- ### `codemerge watch`
212
-
213
- Start HTTP server with file watching.
214
-
215
- ```bash
216
- codemerge watch [path] [options]
217
- ```
218
-
219
- **Arguments:**
220
- - `path` - Input directory to scan (default: `.`)
221
-
222
- **Options:**
223
- - `-o, --output <path>` - Output file path
224
- - `-p, --port <number>` - Server port (default: `9876`)
225
- - `--ignore <patterns>` - Additional ignore patterns
226
- - `--include <patterns>` - Include patterns
227
-
228
- **Examples:**
229
-
230
- ```bash
231
- # Start server on default port
232
- codemerge watch
233
-
234
- # Custom port
235
- codemerge watch --port 8080
236
-
237
- # Watch specific directory
238
- codemerge watch ./src --port 3000
239
-
240
- # With filters
241
- codemerge watch --ignore "*.test.ts" --include "**/*.ts,**/*.tsx"
242
- ```
243
-
244
- **Server Endpoints:**
245
- - `GET /health` - Server health status
246
- - `GET /content` - Full merged content
247
- - `GET /structure` - Project structure JSON
248
- - `POST /selective-content` - Merge selected files
249
- - `POST /upsert` - Create/update files
250
-
251
- See [HTTP Server & API](#http-server--api) for details.
252
-
253
- ---
254
-
255
- ### `codemerge help`
256
-
257
- Display help information.
258
-
259
- ```bash
260
- codemerge help [command]
261
- ```
262
-
263
- **Examples:**
264
-
265
- ```bash
266
- # General help
267
- codemerge help
268
-
269
- # Command-specific help
270
- codemerge help init
271
- codemerge help use
272
- codemerge help watch
273
- ```
274
-
275
- ---
276
-
277
- ### `codemerge version`
278
-
279
- Display version information.
280
-
281
- ```bash
282
- codemerge version
283
- ```
284
-
285
- ---
286
-
287
- ## ⚙️ Configuration
288
-
289
- ### Configuration File: `codemerge.json`
290
-
291
- ```json
292
- {
293
- "projectName": "my-project",
294
- "outputPath": "merged-output.txt",
295
- "port": 9876,
296
- "useGitignore": true,
297
- "ignorePatterns": [
298
- "node_modules/**",
299
- ".git/**",
300
- "dist/**",
301
- "build/**",
302
- "**/*.log",
303
- "coverage/**"
304
- ],
305
- "includePatterns": [
306
- "**/*.ts",
307
- "**/*.js",
308
- "**/*.tsx",
309
- "**/*.jsx",
310
- "**/*.json",
311
- "**/*.md"
312
- ]
313
- }
314
- ```
315
-
316
- ### Configuration Options
317
-
318
- | Option | Type | Default | Description |
319
- |--------|------|---------|-------------|
320
- | `projectName` | `string` | Auto-detected | Project name |
321
- | `outputPath` | `string` | `merged-output.txt` | Output file path |
322
- | `port` | `number` | `9876` | HTTP server port |
323
- | `useGitignore` | `boolean` | `true` | Respect .gitignore rules |
324
- | `ignorePatterns` | `string[]` | See below | Files/folders to ignore |
325
- | `includePatterns` | `string[]` | See below | Files to include |
326
-
327
- ### Default Ignore Patterns
328
-
329
- ```javascript
330
- [
331
- 'node_modules/**',
332
- '.git/**',
333
- 'dist/**',
334
- 'build/**',
335
- 'coverage/**',
336
- '**/*.log',
337
- 'package-lock.json',
338
- 'yarn.lock',
339
- '.env',
340
- '**/.DS_Store'
341
- ]
342
- ```
343
-
344
- ### Default Include Patterns
345
-
346
- ```javascript
347
- [
348
- '**/*.ts',
349
- '**/*.js',
350
- '**/*.tsx',
351
- '**/*.jsx',
352
- '**/*.json',
353
- '**/*.md'
354
- ]
355
- ```
356
-
357
- ### Alternative: package.json Configuration
358
-
359
- You can also configure in `package.json`:
360
-
361
- ```json
362
- {
363
- "name": "my-project",
364
- "codemergeConfig": {
365
- "outputPath": "ai-digest.txt",
366
- "ignorePatterns": ["**/*.test.ts"],
367
- "includePatterns": ["src/**/*.ts"]
368
- }
369
- }
370
- ```
371
-
372
- ---
373
-
374
- ## 🌐 HTTP Server & API
375
-
376
- ### Starting the Server
377
-
378
- ```bash
379
- codemerge watch --port 9876
380
- ```
381
-
382
- ### API Endpoints
383
-
384
- #### 1. Health Check
385
-
386
- **GET** `/health`
387
-
388
- Check server status.
389
-
390
- **Response:**
391
- ```json
392
- {
393
- "status": "ok",
394
- "project": "my-project",
395
- "endpoints": {
396
- "merge": "/content",
397
- "structure": "/structure",
398
- "selectiveContent": "/selective-content",
399
- "upsert": "/upsert",
400
- "health": "/health"
401
- },
402
- "mergeReady": true
403
- }
404
- ```
405
-
406
- **Example:**
407
- ```bash
408
- curl http://localhost:9876/health
409
- ```
410
-
411
- ---
412
-
413
- #### 2. Get Merged Content
414
-
415
- **GET** `/content`
416
-
417
- Get full merged content of all files.
418
-
419
- **Response:**
420
- ```
421
- # Code Merge Output
422
- Generated at: 2026-01-07T01:02:50.588Z
423
- ...
424
- [merged content]
425
- ```
426
-
427
- **Example:**
428
- ```bash
429
- curl http://localhost:9876/content > output.txt
430
- ```
431
-
432
- ---
433
-
434
- #### 3. Get Project Structure
435
-
436
- **GET** `/structure`
437
-
438
- Get project structure as JSON tree.
439
-
440
- **Response:**
441
- ```json
442
- {
443
- "root": {
444
- "name": ".",
445
- "type": "directory",
446
- "path": ".",
447
- "children": [
448
- {
449
- "name": "package.json",
450
- "type": "file",
451
- "path": "package.json",
452
- "lines": 55
453
- },
454
- {
455
- "name": "src",
456
- "type": "directory",
457
- "path": "src",
458
- "children": [
459
- {
460
- "name": "index.ts",
461
- "type": "file",
462
- "path": "src/index.ts",
463
- "lines": 120
464
- }
465
- ]
466
- }
467
- ]
468
- },
469
- "totalFiles": 21,
470
- "totalDirectories": 8,
471
- "fileTypes": {
472
- "ts": 17,
473
- "json": 2,
474
- "js": 1,
475
- "md": 1
476
- }
477
- }
478
- ```
479
-
480
- **Example:**
481
- ```bash
482
- curl http://localhost:9876/structure | jq
483
- ```
484
-
485
- **Frontend Integration:**
486
- ```javascript
487
- async function getProjectStructure() {
488
- const response = await fetch('http://localhost:9876/structure');
489
- const structure = await response.json();
490
- return structure;
491
- }
492
- ```
493
-
494
- ---
495
-
496
- #### 4. Get Selective Content
497
-
498
- **POST** `/selective-content`
499
-
500
- Merge only selected files/folders.
501
-
502
- **Request Body:**
503
- ```json
504
- {
505
- "selectedPaths": [
506
- "src/core/codeMerger.ts",
507
- "src/types",
508
- "package.json"
509
- ]
510
- }
511
- ```
512
-
513
- **Response:**
514
- ```
515
- # Code Merge Output
516
- Generated at: 2026-01-07T01:02:50.588Z
517
- Files processed: 5
518
- ...
519
- [merged content of selected files]
520
- ```
521
-
522
- **Example:**
523
- ```bash
524
- curl -X POST http://localhost:9876/selective-content \
525
- -H "Content-Type: application/json" \
526
- -d '{
527
- "selectedPaths": [
528
- "src/core",
529
- "package.json"
530
- ]
531
- }' > selected-output.txt
532
- ```
533
-
534
- **Frontend Integration:**
535
- ```javascript
536
- async function getSelectiveContent(selectedPaths) {
537
- const response = await fetch('http://localhost:9876/selective-content', {
538
- method: 'POST',
539
- headers: { 'Content-Type': 'application/json' },
540
- body: JSON.stringify({ selectedPaths })
541
- });
542
- return await response.text();
543
- }
544
-
545
- // Usage
546
- const content = await getSelectiveContent([
547
- 'src/core/codeMerger.ts',
548
- 'src/types'
549
- ]);
550
- ```
551
-
552
- **Note:** When you select a folder, all files within it are automatically included.
553
-
554
- ---
555
-
556
- #### 5. Upsert Files
557
-
558
- **POST** `/upsert`
559
-
560
- Create or update files in the project.
561
-
562
- **Request Body:**
563
- ```json
564
- {
565
- "basePath": "./",
566
- "files": [
567
- {
568
- "path": "src/new-file.ts",
569
- "content": "export const hello = 'world';"
570
- },
571
- {
572
- "path": "README.md",
573
- "content": "# Updated content"
574
- }
575
- ]
576
- }
577
- ```
578
-
579
- **Response:**
580
- ```json
581
- {
582
- "success": true,
583
- "filesProcessed": 2,
584
- "errors": [],
585
- "results": [
586
- {
587
- "path": "src/new-file.ts",
588
- "action": "created",
589
- "success": true
590
- },
591
- {
592
- "path": "README.md",
593
- "action": "updated",
594
- "success": true
595
- }
596
- ]
597
- }
598
- ```
599
-
600
- **Example:**
601
- ```bash
602
- curl -X POST http://localhost:9876/upsert \
603
- -H "Content-Type: application/json" \
604
- -d '{
605
- "files": [
606
- {
607
- "path": "src/hello.ts",
608
- "content": "console.log(\"Hello\");"
609
- }
610
- ]
611
- }'
612
- ```
613
-
614
- ---
615
-
616
- ## 💡 Use Cases
617
-
618
- ### 1. AI Code Analysis
619
-
620
- Prepare your entire codebase for AI analysis:
621
-
622
- ```bash
623
- # Generate merged file
624
- codemerge use --output for-ai.txt
625
-
626
- # Copy content and paste into ChatGPT/Claude
627
- cat for-ai.txt | pbcopy # macOS
628
- cat for-ai.txt | xclip # Linux
629
- ```
630
-
631
- ### 2. Code Review Context
632
-
633
- Generate context for code reviews:
634
-
635
- ```bash
636
- # Merge only source files
637
- codemerge use ./src --output review-context.txt --ignore "*.test.ts,*.spec.js"
638
- ```
639
-
640
- ### 3. Documentation Generation
641
-
642
- Create documentation snapshots:
643
-
644
- ```bash
645
- # Include docs and source
646
- codemerge use --include "**/*.md,**/*.ts" --output docs-snapshot.txt
647
- ```
648
-
649
- ### 4. AI-Powered Developer Tools
650
-
651
- Build tools that need dynamic project access:
652
-
653
- ```javascript
654
- // Get project structure
655
- const structure = await fetch('http://localhost:9876/structure').then(r => r.json());
656
-
657
- // Let user select files in UI
658
- const selectedPaths = userSelection;
659
-
660
- // Get only selected content
661
- const content = await fetch('http://localhost:9876/selective-content', {
662
- method: 'POST',
663
- headers: { 'Content-Type': 'application/json' },
664
- body: JSON.stringify({ selectedPaths })
665
- }).then(r => r.text());
666
-
667
- // Send to AI
668
- await sendToAI(content);
669
- ```
670
-
671
- ### 5. Continuous Context Updates
672
-
673
- Watch mode for real-time updates:
674
-
675
- ```bash
676
- # Terminal 1: Watch and serve
677
- codemerge watch --port 3000
678
-
679
- # Terminal 2: Your app constantly fetches latest
680
- while true; do
681
- curl http://localhost:3000/content > latest.txt
682
- sleep 5
683
- done
684
- ```
685
-
686
- ### 6. Multi-Project Monitoring
687
-
688
- Monitor multiple projects:
689
-
690
- ```bash
691
- # Project 1
692
- cd ~/project1 && codemerge watch --port 9001
693
-
694
- # Project 2
695
- cd ~/project2 && codemerge watch --port 9002
696
-
697
- # Project 3
698
- cd ~/project3 && codemerge watch --port 9003
699
- ```
700
-
701
- ---
702
-
703
- ## 🔧 Advanced Usage
704
-
705
- ### Custom Patterns
706
-
707
- #### Include TypeScript Only
708
- ```bash
709
- codemerge use --include "**/*.ts,**/*.tsx"
710
- ```
711
-
712
- #### Exclude Tests and Configs
713
- ```bash
714
- codemerge use --ignore "**/*.test.ts,**/*.spec.js,**/*.config.js"
715
- ```
716
-
717
- #### Specific Directories
718
- ```bash
719
- codemerge use --include "src/**/*.ts,lib/**/*.ts"
720
- ```
721
-
722
- ### Combining Options
723
-
724
- ```bash
725
- codemerge use \
726
- ./backend \
727
- --output backend-code.txt \
728
- --watch \
729
- --ignore "**/*.test.ts,**/migrations/**" \
730
- --include "**/*.ts,**/*.js"
731
- ```
732
-
733
- ### Environment-Specific Configs
734
-
735
- Create multiple config files:
736
-
737
- **codemerge.dev.json:**
738
- ```json
739
- {
740
- "outputPath": "dev-merged.txt",
741
- "includePatterns": ["**/*.ts", "**/*.tsx"]
742
- }
743
- ```
744
-
745
- **codemerge.prod.json:**
746
- ```json
747
- {
748
- "outputPath": "prod-merged.txt",
749
- "ignorePatterns": ["**/*.test.ts", "**/*.dev.ts"]
750
- }
751
- ```
752
-
753
- Use with symbolic links:
754
- ```bash
755
- ln -sf codemerge.dev.json codemerge.json
756
- codemerge use
757
- ```
758
-
759
- ### Scripting
760
-
761
- **package.json:**
762
- ```json
763
- {
764
- "scripts": {
765
- "merge": "codemerge use",
766
- "merge:watch": "codemerge use --watch",
767
- "serve": "codemerge watch --port 3000",
768
- "merge:src": "codemerge use ./src --output src-only.txt"
769
- }
770
- }
771
- ```
772
-
773
- ```bash
774
- npm run merge
775
- npm run serve
776
- ```
777
-
778
- ### CI/CD Integration
779
-
780
- **GitHub Actions:**
781
- ```yaml
782
- - name: Generate Code Context
783
- run: |
784
- npm install -g codemerge-cli
785
- codemerge use --output code-context.txt
786
-
787
- - name: Upload Artifact
788
- uses: actions/upload-artifact@v2
789
- with:
790
- name: code-context
791
- path: code-context.txt
792
- ```
793
-
794
- ---
795
-
796
- ## 🐛 Troubleshooting
797
-
798
- ### Port Already in Use
799
-
800
- ```
801
- Error: Port 9876 is already in use
802
- ```
803
-
804
- **Solution:**
805
- ```bash
806
- # Use different port
807
- codemerge watch --port 8080
808
-
809
- # Or find and kill the process
810
- lsof -ti:9876 | xargs kill -9
811
- ```
812
-
813
- ### Large Output Files
814
-
815
- If output is too large:
816
-
817
- ```bash
818
- # Limit to specific directories
819
- codemerge use ./src ./lib
820
-
821
- # Exclude verbose files
822
- codemerge use --ignore "**/*.json,**/*.lock,**/*.min.js"
823
-
824
- # Include only specific types
825
- codemerge use --include "**/*.ts"
826
- ```
827
-
828
- ### Files Not Being Merged
829
-
830
- **Check .gitignore:**
831
- ```bash
832
- # Disable gitignore checking
833
- # Edit codemerge.json:
834
- {
835
- "useGitignore": false
836
- }
837
- ```
838
-
839
- **Check patterns:**
840
- ```bash
841
- # Add debug logging (in code)
842
- console.log('Include patterns:', includePatterns);
843
- console.log('Ignore patterns:', ignorePatterns);
844
- ```
845
-
846
- ### Watch Not Detecting Changes
847
-
848
- **Increase delay:**
849
- Edit `codemerge.json`:
850
- ```json
851
- {
852
- "watchDelay": 3000
853
- }
854
- ```
855
-
856
- **Check file permissions:**
857
- ```bash
858
- ls -la | grep codemerge
859
- ```
860
-
861
- ### Binary Files in Output
862
-
863
- Binary files are automatically excluded. If you see them:
864
-
865
- ```bash
866
- # Explicitly ignore
867
- codemerge use --ignore "**/*.png,**/*.jpg,**/*.pdf"
868
- ```
869
-
870
- ---
871
-
872
- ## 📚 Additional Resources
873
-
874
- - **GitHub:** [github.com/odutradev/codemerge-cli](https://github.com/odutradev/codemerge-cli)
875
- - **Issues:** [Report bugs](https://github.com/odutradev/codemerge-cli/issues)
876
- - **NPM:** [npmjs.com/package/codemerge-cli](https://www.npmjs.com/package/codemerge-cli)
877
-
878
- ---
879
-
880
- ## 📝 License
881
-
882
- MIT License - feel free to use in your projects!
883
-
884
- ---
885
-
886
- ## 🤝 Contributing
887
-
888
- Contributions welcome! Please:
889
-
890
- 1. Fork the repository
891
- 2. Create a feature branch
892
- 3. Make your changes
893
- 4. Submit a pull request
1
+ # CodeMerge CLI
2
+
3
+ AI-focused code and data preparation utility. Merge multiple files into a single output optimized for AI context windows, with HTTP API for dynamic content generation.
4
+
5
+ ## 📋 Table of Contents
6
+
7
+ - [Overview](https://www.google.com/search?q=%23overview)
8
+ - [Installation](https://www.google.com/search?q=%23installation)
9
+ - [Quick Start](https://www.google.com/search?q=%23quick-start)
10
+ - [Commands](https://www.google.com/search?q=%23commands)
11
+ - [Configuration](https://www.google.com/search?q=%23configuration)
12
+ - [HTTP Server & API](https://www.google.com/search?q=%23http-server--api)
13
+ - [Use Cases](https://www.google.com/search?q=%23use-cases)
14
+ - [Advanced Usage](https://www.google.com/search?q=%23advanced-usage)
15
+ - [Troubleshooting](https://www.google.com/search?q=%23troubleshooting)
16
+
17
+ -----
18
+
19
+ ## 🎯 Overview
20
+
21
+ CodeMerge is a CLI tool that:
22
+
23
+ - **Merges** multiple code files into a single, structured text file
24
+ - **Optimizes** output for AI tools (ChatGPT, Claude, etc.)
25
+ - **Respects** .gitignore patterns and custom ignore rules
26
+ - **Watches** for file changes and auto-regenerates
27
+ - **Serves** content via HTTP API for dynamic access
28
+ - **Provides** project structure visualization in JSON
29
+ - **Enables** selective file merging via API
30
+ - **Executes** system commands upon file updates (Upsert hooks)
31
+
32
+ Perfect for:
33
+
34
+ - Preparing codebases for AI analysis
35
+ - Generating context for code reviews
36
+ - Creating documentation snapshots
37
+ - Sharing project structure with AI assistants
38
+ - Building AI-powered developer tools
39
+
40
+ -----
41
+
42
+ ## 📦 Installation
43
+
44
+ ### Global Installation (Recommended)
45
+
46
+ ```bash
47
+ npm install -g codemerge-cli
48
+ ```
49
+
50
+ ### Local Project Installation
51
+
52
+ ```bash
53
+ npm install --save-dev codemerge-cli
54
+ ```
55
+
56
+ ### Requirements
57
+
58
+ - Node.js \>= 16.0.0
59
+
60
+ -----
61
+
62
+ ## 🚀 Quick Start
63
+
64
+ ### 1\. Initialize Project
65
+
66
+ ```bash
67
+ # Initialize in current directory
68
+ codemerge init
69
+
70
+ # Initialize in specific directory
71
+ codemerge init ./my-project
72
+
73
+ # Force overwrite existing config
74
+ codemerge init --force
75
+ ```
76
+
77
+ This creates:
78
+
79
+ - `codemerge.json` - Configuration file
80
+ - Updates `.gitignore` - Adds output file
81
+
82
+ ### 2\. Merge Files
83
+
84
+ ```bash
85
+ # Merge current directory
86
+ codemerge use
87
+
88
+ # Merge specific directory
89
+ codemerge use ./src
90
+
91
+ # Custom output file
92
+ codemerge use --output my-code.txt
93
+
94
+ # Watch for changes
95
+ codemerge use --watch
96
+ ```
97
+
98
+ ### 3\. Start HTTP Server
99
+
100
+ ```bash
101
+ # Start server on default port (9876)
102
+ codemerge watch
103
+
104
+ # Custom port
105
+ codemerge watch --port 3000
106
+
107
+ # Custom output and filters
108
+ codemerge watch --output api-code.txt --ignore "*.test.ts"
109
+ ```
110
+
111
+ -----
112
+
113
+ ## 🎮 Commands
114
+
115
+ ### `codemerge init`
116
+
117
+ Initialize CodeMerge in a project.
118
+
119
+ ```bash
120
+ codemerge init [path] [options]
121
+ ```
122
+
123
+ **Arguments:**
124
+
125
+ - `path` - Target directory (default: `.`)
126
+
127
+ **Options:**
128
+
129
+ - `-f, --force` - Overwrite existing configuration
130
+
131
+ **What it does:**
132
+
133
+ - Creates `codemerge.json` with default settings
134
+ - Detects project name from `package.json`
135
+ - Adds output file to `.gitignore`
136
+ - Sets up recommended ignore patterns
137
+
138
+ **Example:**
139
+
140
+ ```bash
141
+ codemerge init ./backend --force
142
+ ```
143
+
144
+ -----
145
+
146
+ ### `codemerge use`
147
+
148
+ Merge code files into a single output.
149
+
150
+ ```bash
151
+ codemerge use [path] [options]
152
+ ```
153
+
154
+ **Arguments:**
155
+
156
+ - `path` - Input directory to scan (default: `.`)
157
+
158
+ **Options:**
159
+
160
+ - `-o, --output <path>` - Custom output file path
161
+ - `-w, --watch` - Watch for file changes
162
+ - `--ignore <patterns>` - Additional ignore patterns (comma-separated)
163
+ - `--include <patterns>` - Include patterns (comma-separated)
164
+
165
+ **Examples:**
166
+
167
+ ```bash
168
+ # Basic merge
169
+ codemerge use
170
+
171
+ # Merge src folder only
172
+ codemerge use ./src
173
+
174
+ # Custom output
175
+ codemerge use --output ai-context.txt
176
+
177
+ # Watch mode
178
+ codemerge use --watch
179
+
180
+ # Custom filters
181
+ codemerge use --ignore "*.test.ts,*.spec.js" --include "***.js"
182
+
183
+ # Combine options
184
+ codemerge use ./src --output src-merged.txt --watch
185
+ ```
186
+
187
+ **Output Format:**
188
+
189
+ ```
190
+ # Code Merge Output
191
+ Generated at: 2026-01-07T01:02:50.588Z
192
+ Source path: .
193
+ Files processed: 21
194
+ Total lines: 1596
195
+ Total characters: 45777
196
+
197
+ File types:
198
+ - ts: 17 files (1442 lines)
199
+ - json: 2 files (80 lines)
200
+ - js: 1 files (2 lines)
201
+
202
+ Project structure & file index:
203
+ ./
204
+ lib/
205
+ - cli.ts (75 lines)
206
+ core/
207
+ - codeMerger.ts (273 lines)
208
+
209
+ ================================================================================
210
+
211
+ STARTOFFILE: lib/cli.ts
212
+ ----------------------------------------
213
+ [file content here]
214
+ ----------------------------------------
215
+ ENDOFFILE: lib/cli.ts
216
+ ```
217
+
218
+ -----
219
+
220
+ ### `codemerge watch`
221
+
222
+ Start HTTP server with file watching.
223
+
224
+ ```bash
225
+ codemerge watch [path] [options]
226
+ ```
227
+
228
+ **Arguments:**
229
+
230
+ - `path` - Input directory to scan (default: `.`)
231
+
232
+ **Options:**
233
+
234
+ - `-o, --output <path>` - Output file path
235
+ - `-p, --port <number>` - Server port (default: `9876`)
236
+ - `--ignore <patterns>` - Additional ignore patterns
237
+ - `--include <patterns>` - Include patterns
238
+
239
+ **Examples:**
240
+
241
+ ```bash
242
+ # Start server on default port
243
+ codemerge watch
244
+
245
+ # Custom port
246
+ codemerge watch --port 8080
247
+
248
+ # Watch specific directory
249
+ codemerge watch ./src --port 3000
250
+
251
+ # With filters
252
+ codemerge watch --ignore "*.test.ts" --include "***.tsx"
253
+ ```
254
+
255
+ **Server Endpoints:**
256
+
257
+ - `GET /health` - Server health status
258
+ - `GET /content` - Full merged content
259
+ - `GET /structure` - Project structure JSON
260
+ - `POST /selective-content` - Merge selected files
261
+ - `POST /upsert` - Create/update files
262
+ - `GET /command-output` - Get output of the last post-upsert command
263
+
264
+ See [HTTP Server & API](https://www.google.com/search?q=%23http-server--api) for details.
265
+
266
+ -----
267
+
268
+ ### `codemerge help`
269
+
270
+ Display help information.
271
+
272
+ ```bash
273
+ codemerge help [command]
274
+ ```
275
+
276
+ **Examples:**
277
+
278
+ ```bash
279
+ # General help
280
+ codemerge help
281
+
282
+ # Command-specific help
283
+ codemerge help init
284
+ codemerge help use
285
+ codemerge help watch
286
+ ```
287
+
288
+ -----
289
+
290
+ ### `codemerge version`
291
+
292
+ Display version information.
293
+
294
+ ```bash
295
+ codemerge version
296
+ ```
297
+
298
+ -----
299
+
300
+ ## ⚙️ Configuration
301
+
302
+ ### Configuration File: `codemerge.json`
303
+
304
+ ```json
305
+ {
306
+ "projectName": "my-project",
307
+ "outputPath": "merged-output.txt",
308
+ "port": 9876,
309
+ "useGitignore": true,
310
+ "onUpsertCommand": "npm run build",
311
+ "ignorePatterns": [
312
+ "node_modules*.log",
313
+ "coverage*.ts",
314
+ "***.tsx",
315
+ "***.json",
316
+ "***.log",
317
+ "package-lock.json",
318
+ "yarn.lock",
319
+ ".env",
320
+ "**/.DS_Store"
321
+ ]
322
+ }
323
+ ```
324
+
325
+ **New Option:** `onUpsertCommand` allows defining a shell command to be executed immediately after a successful POST to `/upsert`.
326
+
327
+ ### Default Include Patterns
328
+
329
+ ```javascript
330
+ [
331
+ '***.js',
332
+ '***.jsx',
333
+ '***.md'
334
+ ]
335
+ ```
336
+
337
+ ### Alternative: package.json Configuration
338
+
339
+ You can also configure in `package.json`:
340
+
341
+ ```json
342
+ {
343
+ "name": "my-project",
344
+ "codemergeConfig": {
345
+ "outputPath": "ai-digest.txt",
346
+ "onUpsertCommand": "echo 'Upsert complete'",
347
+ "ignorePatterns": ["***.ts"]
348
+ }
349
+ }
350
+ ```
351
+
352
+ -----
353
+
354
+ ## 🌐 HTTP Server & API
355
+
356
+ ### Starting the Server
357
+
358
+ ```bash
359
+ codemerge watch --port 9876
360
+ ```
361
+
362
+ ### API Endpoints
363
+
364
+ #### 1\. Health Check
365
+
366
+ **GET** `/health`
367
+
368
+ Check server status.
369
+
370
+ **Response:**
371
+
372
+ ```json
373
+ {
374
+ "status": "ok",
375
+ "project": "my-project",
376
+ "endpoints": {
377
+ "merge": "/content",
378
+ "structure": "/structure",
379
+ "selectiveContent": "/selective-content",
380
+ "upsert": "/upsert",
381
+ "commandOutput": "/command-output",
382
+ "health": "/health"
383
+ },
384
+ "mergeReady": true
385
+ }
386
+ ```
387
+
388
+ **Example:**
389
+
390
+ ```bash
391
+ curl http://localhost:9876/health
392
+ ```
393
+
394
+ -----
395
+
396
+ #### 2\. Get Merged Content
397
+
398
+ **GET** `/content`
399
+
400
+ Get full merged content of all files.
401
+
402
+ **Response:**
403
+
404
+ ```
405
+ # Code Merge Output
406
+ Generated at: 2026-01-07T01:02:50.588Z
407
+ ...
408
+ [merged content]
409
+ ```
410
+
411
+ **Example:**
412
+
413
+ ```bash
414
+ curl http://localhost:9876/content > output.txt
415
+ ```
416
+
417
+ -----
418
+
419
+ #### 3\. Get Project Structure
420
+
421
+ **GET** `/structure`
422
+
423
+ Get project structure as JSON tree.
424
+
425
+ **Response:**
426
+
427
+ ```json
428
+ {
429
+ "root": {
430
+ "name": ".",
431
+ "type": "directory",
432
+ "path": ".",
433
+ "children": [
434
+ {
435
+ "name": "package.json",
436
+ "type": "file",
437
+ "path": "package.json",
438
+ "lines": 55
439
+ },
440
+ {
441
+ "name": "src",
442
+ "type": "directory",
443
+ "path": "src",
444
+ "children": [
445
+ {
446
+ "name": "index.ts",
447
+ "type": "file",
448
+ "path": "src/index.ts",
449
+ "lines": 120
450
+ }
451
+ ]
452
+ }
453
+ ]
454
+ },
455
+ "totalFiles": 21,
456
+ "totalDirectories": 8,
457
+ "fileTypes": {
458
+ "ts": 17,
459
+ "json": 2,
460
+ "js": 1,
461
+ "md": 1
462
+ }
463
+ }
464
+ ```
465
+
466
+ **Example:**
467
+
468
+ ```bash
469
+ curl http://localhost:9876/structure | jq
470
+ ```
471
+
472
+ **Frontend Integration:**
473
+
474
+ ```javascript
475
+ async function getProjectStructure() {
476
+ const response = await fetch('http://localhost:9876/structure');
477
+ const structure = await response.json();
478
+ return structure;
479
+ }
480
+ ```
481
+
482
+ -----
483
+
484
+ #### 4\. Get Selective Content
485
+
486
+ **POST** `/selective-content`
487
+
488
+ Merge only selected files/folders.
489
+
490
+ **Request Body:**
491
+
492
+ ```json
493
+ {
494
+ "selectedPaths": [
495
+ "src/core/codeMerger.ts",
496
+ "src/types",
497
+ "package.json"
498
+ ]
499
+ }
500
+ ```
501
+
502
+ **Response:**
503
+
504
+ ```
505
+ # Code Merge Output
506
+ Generated at: 2026-01-07T01:02:50.588Z
507
+ Files processed: 5
508
+ ...
509
+ [merged content of selected files]
510
+ ```
511
+
512
+ **Example:**
513
+
514
+ ```bash
515
+ curl -X POST http://localhost:9876/selective-content \
516
+ -H "Content-Type: application/json" \
517
+ -d '{
518
+ "selectedPaths": [
519
+ "src/core",
520
+ "package.json"
521
+ ]
522
+ }' > selected-output.txt
523
+ ```
524
+
525
+ **Frontend Integration:**
526
+
527
+ ```javascript
528
+ async function getSelectiveContent(selectedPaths) {
529
+ const response = await fetch('http://localhost:9876/selective-content', {
530
+ method: 'POST',
531
+ headers: { 'Content-Type': 'application/json' },
532
+ body: JSON.stringify({ selectedPaths })
533
+ });
534
+ return await response.text();
535
+ }
536
+ const content = await getSelectiveContent([
537
+ 'src/core/codeMerger.ts',
538
+ 'src/types'
539
+ ]);
540
+ ```
541
+
542
+ **Note:** When you select a folder, all files within it are automatically included.
543
+
544
+ -----
545
+
546
+ #### 5\. Upsert Files
547
+
548
+ **POST** `/upsert`
549
+
550
+ Create or update files in the project. If `onUpsertCommand` is configured, it will be executed after a successful upsert.
551
+
552
+ **Request Body:**
553
+
554
+ ```json
555
+ {
556
+ "basePath": "./",
557
+ "files": [
558
+ {
559
+ "path": "src/new-file.ts",
560
+ "content": "export const hello = 'world';"
561
+ },
562
+ {
563
+ "path": "README.md",
564
+ "content": "# Updated content"
565
+ }
566
+ ]
567
+ }
568
+ ```
569
+
570
+ **Response:**
571
+
572
+ ```json
573
+ {
574
+ "success": true,
575
+ "filesProcessed": 2,
576
+ "errors": [],
577
+ "results": [
578
+ {
579
+ "path": "src/new-file.ts",
580
+ "action": "created",
581
+ "success": true
582
+ },
583
+ {
584
+ "path": "README.md",
585
+ "action": "updated",
586
+ "success": true
587
+ }
588
+ ]
589
+ }
590
+ ```
591
+
592
+ **Example:**
593
+
594
+ ```bash
595
+ curl -X POST http://localhost:9876/upsert \
596
+ -H "Content-Type: application/json" \
597
+ -d '{
598
+ "files": [
599
+ {
600
+ "path": "src/hello.ts",
601
+ "content": "console.log(\"Hello\");"
602
+ }
603
+ ]
604
+ }'
605
+ ```
606
+
607
+ -----
608
+
609
+ #### 6\. Get Command Output
610
+
611
+ **GET** `/command-output`
612
+
613
+ Retrieves the result (stdout/stderr) of the last executed command triggered by an upsert operation. Requires `onUpsertCommand` to be set in configuration.
614
+
615
+ **Response:**
616
+
617
+ ```json
618
+ {
619
+ "timestamp": "2026-02-13T12:30:00.000Z",
620
+ "command": "npm run build",
621
+ "output": "Build successful...",
622
+ "error": null,
623
+ "success": true
624
+ }
625
+ ```
626
+
627
+ OR (if no command was executed):
628
+
629
+ ```json
630
+ {
631
+ "status": "no_command_executed"
632
+ }
633
+ ```
634
+
635
+ **Example:**
636
+
637
+ ```bash
638
+ curl http://localhost:9876/command-output
639
+ ```
640
+
641
+ -----
642
+
643
+ ## 💡 Use Cases
644
+
645
+ ### 1\. AI Code Analysis
646
+
647
+ Prepare your entire codebase for AI analysis:
648
+
649
+ ```bash
650
+ # Generate merged file
651
+ codemerge use --output for-ai.txt
652
+
653
+ # Copy content and paste into ChatGPT/Claude
654
+ cat for-ai.txt | pbcopy # macOS
655
+ cat for-ai.txt | xclip # Linux
656
+ ```
657
+
658
+ ### 2\. Code Review Context
659
+
660
+ Generate context for code reviews:
661
+
662
+ ```bash
663
+ # Merge only source files
664
+ codemerge use ./src --output review-context.txt --ignore "*.test.ts,*.spec.js"
665
+ ```
666
+
667
+ ### 3\. Documentation Generation
668
+
669
+ Create documentation snapshots:
670
+
671
+ ```bash
672
+ # Include docs and source
673
+ codemerge use --include "***.ts" --output docs-snapshot.txt
674
+ ```
675
+
676
+ ### 4\. AI-Powered Developer Tools
677
+
678
+ Build tools that need dynamic project access:
679
+
680
+ ```javascript
681
+ const structure = await fetch('http://localhost:9876/structure').then(r => r.json());
682
+ const selectedPaths = userSelection;
683
+ const content = await fetch('http://localhost:9876/selective-content', {
684
+ method: 'POST',
685
+ headers: { 'Content-Type': 'application/json' },
686
+ body: JSON.stringify({ selectedPaths })
687
+ }).then(r => r.text());
688
+ await sendToAI(content);
689
+ ```
690
+
691
+ ### 5\. Continuous Context Updates
692
+
693
+ Watch mode for real-time updates:
694
+
695
+ ```bash
696
+ # Terminal 1: Watch and serve
697
+ codemerge watch --port 3000
698
+
699
+ # Terminal 2: Your app constantly fetches latest
700
+ while true; do
701
+ curl http://localhost:3000/content > latest.txt
702
+ sleep 5
703
+ done
704
+ ```
705
+
706
+ ### 6\. Multi-Project Monitoring
707
+
708
+ Monitor multiple projects:
709
+
710
+ ```bash
711
+ # Project 1
712
+ cd ~/project1 && codemerge watch --port 9001
713
+
714
+ # Project 2
715
+ cd ~/project2 && codemerge watch --port 9002
716
+
717
+ # Project 3
718
+ cd ~/project3 && codemerge watch --port 9003
719
+ ```
720
+
721
+ -----
722
+
723
+ ## 🔧 Advanced Usage
724
+
725
+ ### Custom Patterns
726
+
727
+ #### Include TypeScript Only
728
+
729
+ ```bash
730
+ codemerge use --include "***.tsx"
731
+ ```
732
+
733
+ #### Exclude Tests and Configs
734
+
735
+ ```bash
736
+ codemerge use --ignore "***.spec.js,***.ts,lib*.ts"
737
+ ```
738
+
739
+ ### Combining Options
740
+
741
+ ```bash
742
+ codemerge use \
743
+ ./backend \
744
+ --output backend-code.txt \
745
+ --watch \
746
+ --ignore "**migrations*.ts,***.ts", "***.test.ts", "***.json,***.min.js"
747
+
748
+ # Include only specific types
749
+ codemerge use --include "***.png,***.pdf"
750
+ ```
751
+
752
+ -----
753
+
754
+ ## 📚 Additional Resources
755
+
756
+ - **GitHub:** [github.com/odutradev/codemerge-cli](https://github.com/odutradev/codemerge-cli)
757
+ - **Issues:** [Report bugs](https://github.com/odutradev/codemerge-cli/issues)
758
+ - **NPM:** [npmjs.com/package/codemerge-cli](https://www.npmjs.com/package/codemerge-cli)
759
+
760
+ -----
761
+
762
+ ## 📝 License
763
+
764
+ MIT License - feel free to use in your projects\!
765
+
766
+ -----
767
+
768
+ ## 🤝 Contributing
769
+
770
+ Contributions welcome\! Please:
771
+
772
+ 1. Fork the repository
773
+ 2. Create a feature branch
774
+ 3. Make your changes
775
+ 4. Submit a pull request