Commit Graph

33 Commits

Author SHA1 Message Date
Kazuki Yamada fb281d4560 test(core): Wire createSecurityTaskRunner mock into smaller packager tests
Continuation of the perf(core) Pre-warm security worker pool change —
extends `mockDeps` / inline pack-test plumbing in the three smaller test
files so the default-scope path no longer attempts to spawn a real
worker pool from the test environment.

- tests/core/packager/diffsFunctionality.test.ts: adds
  `mockCreateSecurityTaskRunner` to both pack-call sites.
- tests/core/packager/splitOutput.test.ts: same — adds the stub to the
  inline mock deps.
- tests/core/security/validateFileSafety.test.ts: updates the
  `runSecurityCheck` call assertion to include the new
  `{ taskRunner: undefined }` deps argument forwarded by
  `validateFileSafety` when no pre-warmed runner is provided.

(See PR description / parent commit for the full perf change rationale,
benchmark numbers, and correctness notes.)
2026-05-09 02:30:26 +09:00
Kazuki Yamada f67731056a test: Round-3 PR review feedback
- validateFileSafety: pin the negative path of `if (config.security.enableSecurityCheck)`
  — every other test enabled the check, so a regression that always runs
  the security check would have passed silently.
- unifiedWorker:
  - Add a positive workerData=securityCheck + ambiguous-task case so the
    pair (override + this) distinguishes "inference always wins" from
    "inference wins only when it yields a value".
  - Stop pretending the handler-cache test verifies caching. Both branches
    of `if (cached) return cached;` end with the same Map.set, and Node's
    own module cache makes the dynamic import effectively free, so the
    cache is unobservable from outside without exposing internals.
    Renamed to "repeated calls" with a comment explaining the limitation.
- fileSystemReadDirectoryTool: translate the pre-existing Japanese comment
  to English per CLAUDE.md.
- TokenCounter: extract `LoadEncodingFn` type alias instead of the
  unusual `typeof loadEncoding`, so a signature drift between the local
  function and the deps field would surface at the type level.
2026-04-26 22:47:21 +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 7de692329a refactor(core): Inject getProcessConcurrency via deps in securityCheck
Move getProcessConcurrency from a direct module import to the deps
parameter for consistency with initTaskRunner. This makes it easier
to test with different concurrency values without module-level mocking.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-06 01:29:35 +09:00
Kazuki Yamada 2a879425a0 perf(core): Reduce worker thread contention for faster pipeline execution
Add maxWorkerThreads option to WorkerOptions for explicit thread count
capping, then use it to reduce CPU contention when metrics and security
worker pools run concurrently during the pipeline overlap phase.

- Metrics pool: capped at (processConcurrency - 1)
- Security pool: capped at floor(processConcurrency / 2)

On a 4-core machine this reduces concurrent threads from 8 (4+4) to 5
(3+2), avoiding context-switching overhead during gpt-tokenizer warmup.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-06 00:48:48 +09:00
Kazuki Yamada d30ad69c68 perf(security): Reduce batch size from 500 to 50 for better parallelism
A batch size of 50 still reduces IPC round-trips by ~98% (990 → 20)
while producing enough batches to utilize all available CPU cores
on multi-core systems.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 00:31:31 +09:00
Kazuki Yamada fbb925b467 fix(security): Add numOfTasks comment and fix test batch size references
- Add comment explaining why numOfTasks uses totalItems instead of
  batches.length (passing batches.length would yield maxThreads=1,
  forcing sequential execution)
- Fix test comments that incorrectly referenced batch size 100
  when actual BATCH_SIZE is 500

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 00:23:54 +09:00
Kazuki Yamada 1c99f9617b perf(security): Batch security check tasks to reduce IPC overhead 2026-04-03 23:42:52 +09:00
Kazuki Yamada ea1cc485c2 chore(config): disable organizeImports for src/index.ts
Added override configuration to disable Biome's organizeImports feature
specifically for src/index.ts to allow manual import order management
while keeping automatic import organization enabled for other files.
2025-09-21 13:54:12 +09:00
Kazuki Yamada ddd2814f84 fix(tests): Update test mocks to use new WorkerOptions interface 2025-08-31 16:32:49 +09:00
Kazuki Yamada 8f07b63a61 feat(core): Add runtime selection support for worker pools
Add WorkerRuntime type and configurable runtime parameter to createWorkerPool and initTaskRunner functions. This allows choosing between 'worker_threads' and 'child_process' runtimes based on performance requirements.

- Add WorkerRuntime type definition for type safety
- Add optional runtime parameter to createWorkerPool with child_process default
- Add optional runtime parameter to initTaskRunner with child_process default
- Configure fileCollectWorker to use worker_threads for better performance
- Update all test files to use WorkerRuntime type
- Add comprehensive tests for runtime parameter functionality
- Maintain backward compatibility with existing code

The fileCollectWorker now benefits from worker_threads faster startup and shared memory, while other workers continue using child_process for stability.
2025-08-31 16:18:12 +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 748ce7cead refactor(shared): Consolidate initTaskRunner implementations
Add generic initTaskRunner function to processConcurrency.ts to eliminate
duplicate initialization logic across multiple modules. This reduces code
duplication and provides consistent worker pool management with proper
type safety through generic parameters.

- Add TaskRunner<T, R> interface and initTaskRunner function
- Remove duplicate createTaskRunner wrappers from 5 modules
- Update all deps parameters to use shared initTaskRunner directly
- Maintain type safety with explicit generic type parameters
- Update corresponding test mocks to match new signature

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-24 23:47:07 +09:00
Kazuki Yamada 97d4171176 fix(core): Fix TokenCounter memory leak in worker threads
TokenCounter instances were not being properly freed when worker threads
were terminated by Tinypool's idle timeout. This caused memory leaks
when using runCli as a library.

Changes:
- Add SIGTERM/SIGINT handlers to fileMetricsWorker and outputMetricsWorker
- Add freeTokenCounters function with proper cleanup and debug logging
- Convert all worker usage to consistent taskRunner pattern with cleanup
- Add cleanupWorkerPool function for explicit worker pool termination
- Update all related tests to match new taskRunner interface

The fix ensures TokenCounter resources are properly freed when workers
terminate, preventing memory accumulation during library usage.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-24 23:25:23 +09:00
Kazuki Yamada c1edfff082 Rename initTinypool to initWorker for better semantic clarity
Updated all references throughout the codebase:
- Import statements in 5 core modules
- Function calls in file processing, metrics, and security modules
- Test mocks and descriptions
- Maintained backward compatibility and functionality

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-05 00:27:34 +09:00
Kazuki Yamada a2c5a15838 feat: migrate from Piscina to Tinypool for worker thread management
Replace Piscina with Tinypool to significantly reduce bundle size (800KB → 38KB) while maintaining full API compatibility and performance. This migration affects all worker thread pools used in file processing, security checks, and metrics calculations.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-05 00:23:56 +09:00
Kazuki Yamada 7c2bac6d30 test(security): Update logger mock to use repomixLogLevels and clean up expectations 2025-05-25 14:45:59 +09:00
Kazuki Yamada e67d0bf384 test(security): Add tests for runSecurityCheck with Git diff processing 2025-05-25 12:18:58 +09:00
Kazuki Yamada 1e7a09c4c7 refactor(security): Enhance security check structure by introducing SecurityCheckType and updating file path handling 2025-05-10 16:12:00 +09:00
Kazuki Yamada 265845a9c0 fix(gitDiff): Fix syntax and tests 2025-05-10 11:26:05 +09:00
Kazuki Yamada 6c9a149eb5 feat(pack): Simplify various processes 2025-01-25 13:55:19 +09:00
Kazuki Yamada ebacdd967c feat(pack): Simplify the process and make it testable with DI 2025-01-25 12:43:38 +09:00
Yamada Dev 64fcd143db feat(pack): Execute various processes such as security checks in multi-threaded mode 2025-01-25 12:01:39 +09:00
Kazuki Yamada 79df207866 feat(process): Prevent main thread blocking in file processing 2024-12-29 22:09:21 +09:00
Mike Judge 33d9c14650 Fixes from linter 2024-12-24 17:42:55 -08:00
Mike Judge e57aea8940 Split up validateFileSafety into smaller functions that each do one thing 2024-12-24 16:11:10 -08:00
Mike Judge ce136f3397 Move validateFileSafety into the security folder 2024-12-24 13:58:40 -08:00
Kazuki Yamada 487287c22c refactor: refine directory structure and files 2024-10-08 01:17:05 +09:00
Kazuki Yamada c51435e24a refact: Migrate from ESLint and Prettier to Biome 2024-08-26 23:54:23 +09:00
Kazuki Yamada d1514bce47 refact: Refactor output generation and security check processes 2024-08-12 01:47:34 +09:00
Kazuki Yamada 5ae3f921d7 chore(lint): Update ESLint configuration and dependencies 2024-08-10 15:29:39 +09:00
Kazuki Yamada 0d8016e7a4 refactor(structure): Reorganize project file structure for improved modularity 2024-08-10 14:39:05 +09:00