Commit Graph

70 Commits

Author SHA1 Message Date
Kazuki Yamada 7ff8c8b155 test: Address PR review feedback (RepomixError instances + mock isolation)
- outputGenerate: tests titled "throws RepomixError…" / "wraps … in
  RepomixError" now assert the rejection is an instance of RepomixError
  in addition to the message regex, matching the test names.
- LanguageParser: collapse the duplicate getParserForLang('javascript')
  rejection assertions into a single .catch capture that checks both
  type and message.
- calculateMetrics: vi.mocked(initTaskRunner).mockReset() before
  mockReturnValueOnce so a future test that omits taskRunner can't
  silently consume the override.
- packager: pre-attach a no-op .catch on the rejected warmupPromise so
  vitest's unhandled-rejection detection doesn't fire before pack
  awaits it. Production code mirrors this pattern in packager.ts:262.
2026-04-26 22:29:06 +09:00
Kazuki Yamada cbdfc29b4d test: Cover error/edge paths in core (output, file, security, treeSitter)
Lift the four most impactful uncovered files past 90% lines without
introducing fragile or contrived tests. Each block targets real
user-facing branches (error handling, optional features, init/dispose).

- core/output/outputGenerate (78% -> ~90%):
  - buildOutputGeneratorContext: instructionFilePath success and missing-file
    paths; pre-computed vs. searchFiles fallback for empty directories;
    full-tree mode (success and listing failure); searchFiles failure wrap.
  - generateOutput: unsupported style throws RepomixError.

- core/security/validateFileSafety (79% -> ~95%):
  - logSuspiciousContentWarning loop: header line per section, plus
    singular ("issue") and plural ("issues") suffix per result.
  - No-op behavior when no suspicious git diff/log entries exist.

- core/file/fileSearch (88% -> ~92%):
  - handleGlobbyError: EPERM and EACCES translated to PermissionError;
    other error codes pass through.
  - Outer catch: generic Error wrapped with directory context;
    non-Error throw produces the generic fallback message.

- core/treeSitter/languageParser (74% -> ~88%):
  - getResources before init() throws RepomixError.
  - init() is idempotent (Parser.init is called only once across two calls).
  - Parser.init() failure is wrapped as RepomixError.
  - dispose() resets state so subsequent calls require re-init.

Coverage:
- Statements 89.51% -> 90.23%
- Branches   79.31% -> 80.26%
- Functions  89.37% -> 89.69%
- Lines      90.06% -> 90.80%
2026-04-26 19:35:00 +09:00
Kazuki Yamada 96ebaaeb88 test(output): Update xmldom API usage for v0.9
The @xmldom/xmldom upgrade removed the errorHandler option and changed
documentElement to be nullable. Switch to the new onError callback and
add null checks so the test suite compiles and runs against the new API.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 18:29:06 +09:00
Kazuki Yamada 96a6a7c804 perf(core): Cache empty directory paths to avoid redundant file search
When includeEmptyDirectories is enabled, buildOutputGeneratorContext
called searchFiles a second time just to obtain emptyDirPaths, despite
these already being computed during the initial file search in packager.

Changes:
- Capture emptyDirPaths from the initial searchFiles result in packager
  and thread them through the pipeline (packager → produceOutput →
  generateOutput/outputSplit → buildOutputGeneratorContext)
- Guard emptyDirPaths processing with includeEmptyDirectories check to
  skip unnecessary work when the feature is disabled
- Fix split output path which was not receiving emptyDirPaths despite
  the parameter being declared in produceOutput's signature
- Add tests for cache hit (searchFiles not called) and fallback paths

Local benchmark (repomix on itself, includeEmptyDirectories: true):
  main:   696.6ms ± 4.2ms
  branch: 637.1ms ± 2.6ms
  Improvement: ~60ms (~8.5%)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-02 00:03:49 +09:00
Kazuki Yamada cdb6ab156c test(output): Add strict XML error handling to DOMParser in tests
Use a strict error handler for @xmldom/xmldom's DOMParser that throws on
all severity levels (warning, error, fatalError). By default, xmldom
silently continues parsing malformed XML, which could mask XMLBuilder
regressions. This ensures tests fail immediately on any XML well-formedness
issue.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-21 01:02:37 +09:00
Kazuki Yamada 04b277f269 refactor(deps): Replace fast-xml-parser with fast-xml-builder
fast-xml-parser has accumulated 10 CVEs (6 in 2026 alone), with a recurring
pattern of incomplete fixes in its DOCTYPE/entity parser. Since Repomix only
uses the XMLBuilder functionality (not the parser), switching to
fast-xml-builder — the standalone builder package that fast-xml-parser v5
internally delegates to — eliminates 9/10 parser-side CVE noise while
maintaining identical behavior.

- Replace fast-xml-parser (831KB) with fast-xml-builder (176KB) as dependency
- Add @xmldom/xmldom as devDependency for XML validation in tests
- Update import in outputGenerate.ts (named → default export)
- Migrate test XML parsing from fast-xml-parser's XMLParser to @xmldom/xmldom's
  DOMParser, providing cross-implementation validation of generated XML

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-21 01:02:37 +09:00
Kazuki Yamada f41b75c560 fix(test): fix lint errors and update test signatures for filePathsByRoot
- Remove unused imports (generateFileTree, treeToString) in fileTreeGenerate.test.ts
- Add filePathsByRoot parameter to generateOutput and produceOutput calls in tests
- Update expect assertions to include filePathsByRoot argument
2026-01-04 23:11:28 +09:00
spandan-kumar 3f2680e5d5 feat(tree): add multi-root directory labels
When packing multiple directories, the directory tree output now shows
labeled sections like [cli]/, [config]/ to clarify which files belong
to which root directory.

- Add FilesByRoot interface and generateTreeStringWithRoots function
- Update output pipeline to pass file-to-root mapping
- Add unit tests for new tree generation functions
- Update existing tests for new function signatures

Closes #1023
2026-01-04 22:57:10 +09:00
Kazuki Yamada 05c3245984 test(output): Add getRootEntry edge case tests
Add test coverage for edge cases as suggested by CodeRabbit:
- Empty string input
- Paths with leading separators (/absolute/path.ts)
- Single separator (/)
2025-12-21 23:32:31 +09:00
Kazuki Yamada 0364f3c676 test(output): Add split output success pattern tests
Add comprehensive tests for generateSplitOutputParts:
- Test successful splitting into multiple parts when content exceeds limit
- Test git diff/log is only included in first part

Also optimize byteLength recalculation by tracking currentBytes variable
to avoid redundant getUtf8ByteLength() calls.
2025-12-21 23:12:24 +09:00
Kazuki Yamada 5f8be420d0 perf(output): Cache git file change counts in sortOutputFiles
Add module-level caching for git operations to avoid repeated expensive
git commands during split output generation. This significantly improves
performance when generateOutput is called multiple times (O(N²) in split
output mode).

- Add fileChangeCountsCache for git log results (~133ms savings per call)
- Add gitAvailabilityCache for git installation/folder checks (~65ms savings)
- Extract sortFilesByChangeCounts helper function
- Add test for cache behavior verification
2025-12-21 21:56:39 +09:00
Kazuki Yamada a49a8f932c test(cli): Add generateSplitOutputParts error case tests
Cover error scenarios:
- Single root entry exceeding maxBytesPerPart
- Invalid maxBytesPerPart values (0, negative)
- Empty files array returning empty result
2025-12-21 21:56:39 +09:00
Dango233 e51d77a7c6 feat(cli): Add --split-output option
Adds a size-based output splitter via --split-output (kb/mb) and writes numbered parts without splitting within a top-level folder.

Also updates metrics aggregation for multi-part output and adds unit tests.
2025-12-21 21:56:39 +09:00
Kazuki Yamada 0fa885cb79 refactor(skill): Move skill-related code to core/skill/ directory
Reorganize skill generation code for better domain separation:
- Move files from core/output/skill/ to core/skill/ (5 files)
- Move writeSkillOutput.ts from core/packager/ to core/skill/
- Create packSkill.ts to encapsulate skill generation logic
- Simplify packager.ts by delegating skill generation to packSkill()
- Add re-exports in outputGenerate.ts for backward compatibility

This change improves code organization by:
- Separating skill domain from output domain
- Reducing packager.ts complexity
- Centralizing all skill-related code in one location
2025-12-11 00:12:34 +09:00
Kazuki Yamada 1987d1d886 refactor(skill): Remove unused git diffs/logs section generators
Remove generateGitDiffsSection and generateGitLogsSection functions
and their tests as they are no longer used in the skill generation flow.
These became dead code after removing git diffs/logs from skill output.
2025-12-10 00:27:43 +09:00
Kazuki Yamada 84c14cc028 feat(skill): Enhance tech-stack detection and improve skill output
- Show all dependencies without truncation (removed 20/10 limits)
- Add runtime version detection (.node-version, .nvmrc, .tool-versions, etc.)
- Add configuration files section to tech-stack.md
- Move statistics section from SKILL.md to summary.md
- Update summary.md to use multi-file format language
- Increase largest files display from 5 to 10
- Improve generate_skill MCP tool description with skill types and paths
2025-12-10 00:27:43 +09:00
Kazuki Yamada 2a4209d42c feat(skill): Add tech-stack detection and file statistics to skill output
Add new features to improve skill output for understanding codebases:

- Add tech-stack.md: Auto-detect languages, frameworks, and dependencies
  from package.json, requirements.txt, go.mod, Cargo.toml, etc.
- Add file statistics section to SKILL.md with language breakdown
  and largest files list
- Rename structure.md to project-structure.md for clarity
- Add total lines count to SKILL.md header
2025-12-10 00:27:43 +09:00
Kazuki Yamada 8aa10c5ebc docs(skill): Improve SKILL.md template with overview and use cases
Add Overview, Common Use Cases, and Tips sections to make the template
more actionable and instantly understandable. Remove redundant File Format
section (delegated to summary.md).

Changes:
- Add Overview section explaining when to use this skill
- Add Common Use Cases with concrete scenarios (understand feature, debug, find usages)
- Add Tips section for effective usage
- Remove File Format section to reduce redundancy
2025-12-10 00:27:43 +09:00
Kazuki Yamada 9916cec976 docs(skill): Improve SKILL.md template for better usability
Restructure SKILL.md to be more practical and scannable:
- Add reference files table with descriptions
- Include Quick Reference section with concrete examples
- Show exact grep patterns for finding files
- Display file format examples for understanding structure
- Move statistics inline with header for brevity
2025-12-10 00:27:43 +09:00
Kazuki Yamada e40c5f3d63 refactor(skill): Remove git diffs and logs from skill output
Skill output is designed for referencing external codebases (e.g., GitHub
repositories) as persistent skills. Git diffs (uncommitted changes) and
git logs (commit history) are not meaningful in this context since:
- Remote repositories have no uncommitted changes
- Commit history is less relevant for reference skills

This simplifies the skill output to include only:
- SKILL.md
- references/summary.md
- references/structure.md
- references/files.md
2025-12-10 00:27:43 +09:00
Kazuki Yamada c57dd552fc feat(skill): Add line counts to directory structure in skill output
Display the number of lines next to each file in the directory
structure section of skill output. This helps when using grep
to find specific files by line count.

Example:
  src/
    index.ts (42 lines)
    utils.ts (128 lines)
2025-12-10 00:27:43 +09:00
Kazuki Yamada f854dd4250 refactor(skill): Improve skill output generation and add tests
Refactor and improve the skill generation feature based on code review:

- Split generateSkillOutput into generateSkillReferences and
  generateSkillMdFromReferences to avoid double generation
- Add try-catch error handling to writeSkillOutput with proper
  permission error messages
- Add unit tests for skillSectionGenerators (12 tests)
- Add validation tests for --skill-generate flag combinations
- Update createMockConfig to support skillGenerate and remoteUrl
2025-12-10 00:27:43 +09:00
Kazuki Yamada df5647c682 feat(skill): Enhance skill output with split files and auto-naming
Improve the Claude Agent Skills generation feature:

- Rename CLI option from --generate-skill to --skill-generate [name]
- Make skill name optional with auto-generation (repomix-reference-<folder>)
- Split skill output into multiple reference files:
  - summary.md: Purpose, format description, and notes
  - structure.md: Directory tree view
  - files.md: Complete file contents
  - git-diffs.md: Uncommitted changes (optional)
  - git-logs.md: Recent commit history (optional)
- Move skill-related code to src/core/output/skill/ folder
- Extract shared language mapping to outputStyleUtils.ts
- Add 100+ language mappings for syntax highlighting
2025-12-10 00:27:43 +09:00
Kazuki Yamada 71515c70ac feat(cli): Add --generate-skill option for Claude Agent Skills output
Implement Claude Agent Skills format output support for Repomix.
This feature was requested in issue #952 to enable seamless integration
with Claude Code's skill system.

New CLI option:
  repomix --generate-skill <name>

Output structure:
  .claude/skills/<name>/
  ├── SKILL.md                # Entry point with YAML frontmatter
  └── references/
      └── codebase.md         # Packed codebase in Markdown format

Features:
- Skill name auto-converts to kebab-case (max 64 chars)
- SKILL.md includes usage guidance for reading the codebase
- Incompatible with --stdout and --copy options
- MCP tool `generate_skill` for programmatic access

New files:
- src/core/output/skillUtils.ts
- src/core/output/outputStyles/skillStyle.ts
- src/core/packager/writeSkillOutput.ts
- src/mcp/tools/generateSkillTool.ts

Closes #952
2025-12-10 00:27:43 +09:00
Kazuki Yamada 438b79f654 docs(website): Add .ignore file documentation for all languages
Updated documentation for all supported languages to include:
- ignore.useDotIgnore configuration option
- --no-dot-ignore CLI flag
- .ignore file explanation and priority order
- Benefits of using .ignore file with ripgrep and ag tools

Also updated test files to include useDotIgnore in mock configs
to satisfy TypeScript type checking after adding the new
configuration option.

Languages updated:
- zh-cn (Simplified Chinese)
- zh-tw (Traditional Chinese)
- ko (Korean)
- vi (Vietnamese)
- id (Indonesian)
- hi (Hindi)
- fr (French)
- de (German)
- es (Spanish)
- pt-br (Brazilian Portuguese)
2025-11-08 20:02:14 +09:00
Kazuki Yamada 72735cfdb1 test(coverage): Improve test coverage for CLI and core modules
Added comprehensive test coverage for critical CLI and core functionality:

- Created new test file for cliSpinner with 15 tests covering:
  * Spinner start/stop/update operations
  * Quiet/verbose/stdout mode handling
  * Success/fail message display
  * Interval management

- Enhanced initAction tests (11→17 tests):
  * Added isCancel handling for user cancellation
  * Added return value validation tests
  * Covered config and ignore file creation flows

- Enhanced cliReport tests (8→15 tests):
  * Added git diffs/logs reporting tests
  * Added security check reporting for git content
  * Added single vs multiple issue message handling

- Enhanced permissionCheck tests (13→16 tests):
  * Added macOS-specific error message tests
  * Added platform-specific error handling tests
  * Added unknown error code handling

- Enhanced outputGenerate tests (7→12 tests):
  * Added git diffs/logs inclusion tests
  * Added JSON format output tests
  * Added file/directory structure exclusion tests

Overall improvements:
- Test count: 804 → 840 (+36 tests)
- Code coverage: 70.63% → 71.00% (+0.37%)
- Branch coverage: 77.64% → 78.55% (+0.91%)
- Significant improvement in CLI modules (cliSpinner: 25% → 59.61%)
2025-10-31 01:18:21 +09:00
Slava Kurilyak 532c38f833 feat(core): Include all repository files in full directory tree
When --include-full-directory-structure flag is enabled, the tree now
displays all files in the repository (subject to ignore patterns), not
just files matching include patterns. This provides a more complete
view of the repository structure.

Changes:
- Add listFiles() function to scan all repository files
- Merge additional files into tree visualization
- Update tests to verify root-level files appear in tree
- Bump Biome schema to 2.2.6
- Improve Secretlint TypeScript type declarations
2025-10-17 17:50:08 -07:00
autofix-ci[bot] 770f5122f9 [autofix.ci] apply automated fixes 2025-10-17 17:50:08 -07:00
Slava Kurilyak c6015f1856 test(core): add negative-path test for full-directory-structure flag 2025-10-17 17:50:08 -07:00
Slava Kurilyak bc5f1342f5 feat(cli,core,config): Add --include-full-directory-structure and full repository tree 2025-10-17 17:50:08 -07:00
Kazuki Yamada f87e00dbdf chore(lint): upgrade biome to v2.2.4 and fix all lint errors
Updated biome from v1.9.4 to v2.2.4 to take advantage of latest linting improvements.

- Upgraded @biomejs/biome from ^1.9.4 to ^2.2.4
- Updated biome.json configuration for v2 compatibility:
  - Changed schema to 2.2.4
  - Updated file includes/ignores syntax
  - Added Vue file overrides to disable noUnusedVariables/noUnusedImports
- Fixed all lint errors:
  - Added radix parameter to parseInt calls
  - Prefixed unused parameters with underscore
  - Removed unused imports
  - Fixed biome suppression comments
  - Removed !important from CSS
  - Added type ignores for Vue component definitions

All 325 files now pass lint with 0 warnings and 0 errors.
2025-09-21 13:39:43 +09:00
Kazuki Yamada 313e978e11 feat(core): add JSON output style support
Add comprehensive JSON output style with camelCase naming convention:
- JSON output generates machine-readable format using JSON.stringify()
- Always uses parsable style for valid JSON structure
- Parameter names follow camelCase convention (fileSummary, userProvidedHeader, etc.)
- Includes CLI option, config schema, and interactive prompt support
- Comprehensive test coverage for unit and integration tests
- Error handling with clear unsupported style messages

This enables easier programmatic consumption of Repomix output for AI systems and automated tools.
2025-09-14 14:50:38 +09:00
Kazuki Yamada b7fe6f25c5 fix(lint): resolve all oxlint warnings for code quality
- Remove unused imports across 67 files (RepomixConfigMerged, QueryCapture, etc.)
- Fix unused parameters by prefixing with underscore (_context, _index, etc.)
- Remove unused catch parameters using modern JavaScript syntax
- Fix require-yield warnings in generator functions
- Remove unused variables and interface declarations
- Add oxlint configuration to ignore integration test fixtures

Resolves 144 linting warnings while preserving all functionality.
All 743 tests continue to pass. Code quality significantly improved.
2025-08-24 18:25:08 +09:00
Kazuki Yamada 5b5ee862a0 feat(cli): Add --include-logs option for git commit history
This feature allows users to include git log information in the output to help AI understand development patterns and file change relationships.

Key changes:
- Added --include-logs and --include-logs-count CLI options
- Default to 50 commits, configurable via CLI and config file
- Includes commit date, message, and changed file paths (excludes commit hashes)
- Added security checks and metrics calculation for git logs
- Updated output templates to include git logs section
- Comprehensive test coverage and TypeScript fixes

Resolves user request for including git commit history to provide development context for AI analysis.
2025-08-22 14:09:58 +09:00
Kazuki Yamada 34685042be feat(core): Show largest files in 'Invalid string length' error message
When output size exceeds JavaScript string limit, now displays the top 5 largest files with their sizes to help users identify which files to exclude. This makes it easier to decide which --ignore patterns to use.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-23 00:29:21 +09:00
Erik Nygren 78b9f75598 feat(output): Make summary purpose conditional based on file selection
- Update generateSummaryPurpose function to accept RepomixConfigMerged
  parameter
- Add logic to differentiate between entire codebase vs subset in
  purpose description
- Update function call in outputGenerate.ts to pass config parameter
- Add comprehensive tests for both entire codebase and subset scenarios

Previously, the summary purpose section always claimed the file
contained "the entire repository's contents", even when repomix was
configured to process only a subset of files (e.g., with include
patterns). This created inconsistency with other parts of the output
that correctly indicated when only a subset was processed.

This change ensures the purpose section accurately describes the content
as either "the entire repository's contents" or "a subset of the
repository's contents that is considered the most important context"
based on the actual file selection configuration.
2025-06-22 11:49:36 +01:00
Kazuki Yamada fecebc2ca6 refactor(core): Update GitDiffResult imports and restructure git handling modules 2025-05-24 14:14:26 +09:00
Kazuki Yamada b13a21aebd refactor(core): Migrate GitDiffResult and related functions to gitHandle module 2025-05-24 13:59:32 +09:00
Kazuki Yamada 0be489dcbb refactor(core): Update git command imports and restructure gitHandle module 2025-05-24 13:37:57 +09:00
Kazuki Yamada 9538395cdf refactor(core): Move Git-related modules to dedicated core/git directory 2025-05-19 14:53:28 +00:00
Kazuki Yamada 5e8ff25335 feat(output): Ensure consistent order of sections (Summary, UserProvidedHeader, Directory Structure) across all output styles 2025-05-17 16:22:22 +09:00
Josh Wand 1862005828 feat: --no-file-summary now also suppresses generationHeader; doesn't suppress headerText (fixes #554) 2025-05-15 16:31:50 +00:00
Devin AI 48ec00c63a - Replace hardcoded config objects with createMockConfig utility
- Add proper typing to mock objects and functions
- Remove unnecessary type casting
- Add GitDiffResult type to git diff objects

Co-Authored-By: Kazuki Yamada <koukun0120@gmail.com>
2025-05-13 22:55:50 +09:00
Devin AI 8ebb7c1c86 Replace type assertions with createMockConfig in treeSitter test files and fix outputSort test
Co-Authored-By: Kazuki Yamada <koukun0120@gmail.com>
2025-05-12 14:36:55 +00:00
Devin AI 7b81a2660f Replace type assertions with createMockConfig in outputSort.test.ts
Co-Authored-By: Kazuki Yamada <koukun0120@gmail.com>
2025-05-12 14:33:23 +00:00
Kazuki Yamada 464ccc582b feat(diff): Refactor CLI and output generation to support git diffs
- Updated CLI options to use `--include-diffs` instead of `--diffs`.
- Refactored `printSummary` to accept a `PackResult` object for better data handling.
- Introduced `getStagedDiff` function to retrieve staged changes from git.
- Created `getGitDiffs` function to encapsulate logic for fetching both worktree and staged diffs.
- Modified output generation functions to include git diffs in various formats (markdown, XML, plain text).
- Updated tests to reflect changes in CLI options and output generation logic, ensuring proper handling of git diffs.
- Removed deprecated `diffContent` from config schema and adjusted related logic.
2025-05-07 00:25:23 +09:00
pmdyy 412a94b9d9 fix(output): fix lints 2025-05-06 00:08:51 -06:00
pmdyy cdfa93c594 feat(output): Add git diff support with --diffs flag 2025-05-05 23:57:05 -06:00
Kazuki Yamada f1993c62c4 Fix tests for metadata-only output mode 2025-04-19 17:58:44 +09:00
Kazuki Yamada 12cbde363c Add metadata-only output mode with --no-files flag 2025-04-19 17:41:31 +09:00