Commit Graph

15 Commits

Author SHA1 Message Date
Kazuki Yamada 8321c7a11e refactor(metrics): Rename calculateSelectiveFileMetrics to calculateFileMetrics
The function now always calculates metrics for all files, so the
"Selective" prefix no longer reflects its behavior.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 20:47:06 +09:00
Kazuki Yamada ee5a748a0f refactor(core): Simplify calculateMetrics output param to Promise-only
The output parameter was typed as `string | string[] | Promise<...>` but
callers can always wrap sync values in Promise.resolve(). Simplifying to
`Promise<string | string[]>` makes the interface cleaner.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 23:14:15 +09:00
Kazuki Yamada 62b7861f2a perf(core): Replace tiktoken WASM with gpt-tokenizer (pure JS)
Replace tiktoken (WASM-based) with gpt-tokenizer (pure JS) for token
counting, eliminating ~200ms WASM initialization overhead while keeping
the existing worker pool infrastructure for parallel processing.

Changes:
- Swap tiktoken dependency for gpt-tokenizer in package.json
- Rewrite TokenCounter to use gpt-tokenizer's async dynamic import
  with lazy-loaded encoding modules cached at module level
- Add TOKEN_ENCODINGS constant with Zod enum validation in config
  schema, replacing unsafe type assertion
- Use { disallowedSpecial: new Set() } to match tiktoken's
  encode(content, [], []) behavior (treat all text as plain text)
- Add p50k_edit encoding for backward compatibility
- Update worker to handle async getTokenCounter initialization
- Rewrite tests to use real gpt-tokenizer with exact token counts

The worker pool, parallel chunk processing, and pre-warming
infrastructure are preserved — only the underlying tokenizer changes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 21:28:00 +09:00
Kazuki Yamada a94ce0f2ff fix(tests): Update test mocks for vitest v4 compatibility
Vitest v4 changed how vi.fn() and vi.mock() work with class constructors.
Arrow functions in mockImplementation no longer work as constructors
when called with 'new' keyword.

Changes:
- Use regular function syntax instead of arrow functions for constructor mocks
- Use vi.hoisted() to define class mocks that can be used in vi.mock() factories
- Replace vi.fn().mockReturnValue() with vi.fn().mockImplementation() for class mocks
- Update mock instance retrieval to use vi.mocked().mock.results[0].value
2026-01-03 16:28:31 +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 a85dd6b2a0 refactor(test): eliminate build dependency by mocking worker logic directly
Replaced worker file imports with direct function calls in tests to improve coverage
and remove CI build requirements. Key changes:

- Extracted calculateUnifiedMetrics function from unifiedMetricsWorker for direct testing
- Added taskRunner dependency injection to calculateMetrics function
- Updated all metric tests to use mocked taskRunner instead of actual worker files
- Removed build steps from CI test jobs (test, test-bun, test-coverage)

This approach provides better test coverage since worker logic runs directly
in the test process rather than being executed in separate worker threads.
Tests now run faster without requiring TypeScript compilation.
2025-09-20 19:52:13 +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 3261204059 refactor(core): remove unused calculateAllFileMetrics function and rename file
Remove calculateAllFileMetrics function that was only used in tests and rename calculateAllFileMetrics.ts to calculateSelectiveFileMetrics.ts to match the remaining function. This simplifies the metrics calculation API by keeping only the selective file metrics functionality that is actually used in production code.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-03 14:15:57 +09:00
Kazuki Yamada 7cfe658dca feat(metrics): Create dedicated git diff worker for improved memory efficiency
- Extract git diff token calculation into separate worker and dedicated module
- Parallelize git diff metrics calculation with other metrics computations using Promise.all
- Isolate TokenCounter usage for git diffs within child process worker to prevent memory leaks
- Add comprehensive worker cleanup with exit handler for proper resource management
- Update tests to reflect new worker-based architecture and remove direct TokenCounter mocking

Memory improvements:
- Git diff token calculation now runs in isolated child process
- Enables parallel execution of all three metrics calculations (files, output, git diff)
- Further reduces main process memory footprint by isolating heavy TokenCounter operations

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-27 23:53:06 +09:00
Kazuki Yamada 0efe7ba3cd test: use createMockConfig helper for all test mock configurations
- Replace manual config objects with createMockConfig() in test files
- Ensures consistency and automatic handling of new config properties
- Fixes truncateBase64 property linter errors
- Improves maintainability for future config schema changes
2025-07-15 22:44:47 +09:00
Kazuki Yamada f1d11d9fae perf(metrics): Optimize token counting for top files display
- Add character-based pre-filtering to reduce token calculation overhead
- Implement calculateSelectiveFileMetrics for targeted token counting
- Only calculate tokens for top candidates (5x display count) instead of all files
- Maintain accurate token-based ranking while improving performance for large codebases
- Update tests to cover new selective calculation functionality

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-08 17:33:25 +09:00
Kazuki Yamada 265845a9c0 fix(gitDiff): Fix syntax and tests 2025-05-10 11:26:05 +09: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