mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-11 02:33:51 +08:00
Merge branch 'main' of https://github.com/catlog22/Claude-Code-Workflow
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { existsSync, mkdirSync, readFileSync, writeFileSync, statSync } from 'fs';
|
import { existsSync, mkdirSync, readFileSync, writeFileSync, statSync, unlinkSync, readdirSync } from 'fs';
|
||||||
import { join, dirname } from 'path';
|
import { join, dirname } from 'path';
|
||||||
import { StoragePaths, ensureStorageDir } from '../config/storage-paths.js';
|
import { StoragePaths, ensureStorageDir } from '../config/storage-paths.js';
|
||||||
|
|
||||||
@@ -118,8 +118,7 @@ export class CacheManager<T> {
|
|||||||
invalidate(): void {
|
invalidate(): void {
|
||||||
try {
|
try {
|
||||||
if (existsSync(this.cacheFile)) {
|
if (existsSync(this.cacheFile)) {
|
||||||
const fs = require('fs');
|
unlinkSync(this.cacheFile);
|
||||||
fs.unlinkSync(this.cacheFile);
|
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn(`Cache invalidation error for ${this.cacheFile}:`, (err as Error).message);
|
console.warn(`Cache invalidation error for ${this.cacheFile}:`, (err as Error).message);
|
||||||
@@ -180,8 +179,7 @@ export class CacheManager<T> {
|
|||||||
if (depth > 3) return; // Limit recursion depth
|
if (depth > 3) return; // Limit recursion depth
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const fs = require('fs');
|
const entries = readdirSync(dirPath, { withFileTypes: true });
|
||||||
const entries = fs.readdirSync(dirPath, { withFileTypes: true });
|
|
||||||
|
|
||||||
for (const entry of entries) {
|
for (const entry of entries) {
|
||||||
const fullPath = join(dirPath, entry.name);
|
const fullPath = join(dirPath, entry.name);
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ const GLOBAL_SETTINGS_PATH = join(homedir(), '.claude', 'settings.json');
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
function getProjectSettingsPath(projectPath) {
|
function getProjectSettingsPath(projectPath) {
|
||||||
const normalizedPath = projectPath.replace(/\//g, '\\').replace(/^\\([a-zA-Z])\\/, '$1:\\');
|
// path.join automatically handles cross-platform path separators
|
||||||
return join(normalizedPath, '.claude', 'settings.json');
|
return join(projectPath, '.claude', 'settings.json');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1000,8 +1000,8 @@ function writeSettingsFile(filePath, settings) {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
function getProjectSettingsPath(projectPath) {
|
function getProjectSettingsPath(projectPath) {
|
||||||
const normalizedPath = projectPath.replace(/\//g, '\\').replace(/^\\([a-zA-Z])\\/, '$1:\\');
|
// path.join automatically handles cross-platform path separators
|
||||||
return join(normalizedPath, '.claude', 'settings.json');
|
return join(projectPath, '.claude', 'settings.json');
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========================================
|
// ========================================
|
||||||
|
|||||||
@@ -79,36 +79,37 @@ def get_cache_dir() -> Path:
|
|||||||
"""Get fastembed cache directory.
|
"""Get fastembed cache directory.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Path to cache directory (usually ~/.cache/fastembed or %LOCALAPPDATA%\\Temp\\fastembed_cache)
|
Path to cache directory (~/.cache/huggingface or custom path)
|
||||||
"""
|
"""
|
||||||
# Check HF_HOME environment variable first
|
# Check HF_HOME environment variable first
|
||||||
if "HF_HOME" in os.environ:
|
if "HF_HOME" in os.environ:
|
||||||
return Path(os.environ["HF_HOME"])
|
return Path(os.environ["HF_HOME"])
|
||||||
|
|
||||||
# Default cache locations
|
# fastembed 0.7.4+ uses HuggingFace cache when cache_dir is specified
|
||||||
if os.name == "nt": # Windows
|
# Models are stored directly under the cache directory
|
||||||
cache_dir = Path(os.environ.get("LOCALAPPDATA", Path.home() / "AppData" / "Local")) / "Temp" / "fastembed_cache"
|
return Path.home() / ".cache" / "huggingface"
|
||||||
else: # Unix-like
|
|
||||||
cache_dir = Path.home() / ".cache" / "fastembed"
|
|
||||||
|
|
||||||
return cache_dir
|
|
||||||
|
|
||||||
|
|
||||||
def _get_model_cache_path(cache_dir: Path, info: Dict) -> Path:
|
def _get_model_cache_path(cache_dir: Path, info: Dict) -> Path:
|
||||||
"""Get the actual cache path for a model.
|
"""Get the actual cache path for a model.
|
||||||
|
|
||||||
fastembed uses ONNX versions of models with different names than the original.
|
fastembed 0.7.4+ uses HuggingFace Hub's naming convention:
|
||||||
This function returns the correct path based on the cache_name field.
|
- Prefix: 'models--'
|
||||||
|
- Replace '/' with '--' in model name
|
||||||
|
Example: jinaai/jina-embeddings-v2-base-code
|
||||||
|
-> models--jinaai--jina-embeddings-v2-base-code
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
cache_dir: The fastembed cache directory
|
cache_dir: The fastembed cache directory (HuggingFace hub path)
|
||||||
info: Model profile info dictionary
|
info: Model profile info dictionary
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Path to the model cache directory
|
Path to the model cache directory
|
||||||
"""
|
"""
|
||||||
cache_name = info.get("cache_name", info["model_name"])
|
# HuggingFace Hub naming: models--{org}--{model}
|
||||||
return cache_dir / f"models--{cache_name.replace('/', '--')}"
|
model_name = info["model_name"]
|
||||||
|
sanitized_name = f"models--{model_name.replace('/', '--')}"
|
||||||
|
return cache_dir / sanitized_name
|
||||||
|
|
||||||
|
|
||||||
def list_models() -> Dict[str, any]:
|
def list_models() -> Dict[str, any]:
|
||||||
@@ -194,18 +195,29 @@ def download_model(profile: str, progress_callback: Optional[callable] = None) -
|
|||||||
model_name = info["model_name"]
|
model_name = info["model_name"]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Download model by instantiating TextEmbedding
|
# Get cache directory
|
||||||
# This will automatically download to cache if not present
|
cache_dir = get_cache_dir()
|
||||||
|
|
||||||
|
# Download model by instantiating TextEmbedding with explicit cache_dir
|
||||||
|
# This ensures fastembed uses the correct HuggingFace Hub cache location
|
||||||
if progress_callback:
|
if progress_callback:
|
||||||
progress_callback(f"Downloading {model_name}...")
|
progress_callback(f"Downloading {model_name}...")
|
||||||
|
|
||||||
embedder = TextEmbedding(model_name=model_name)
|
# CRITICAL: Must specify cache_dir to use HuggingFace cache
|
||||||
|
# and call embed() to trigger actual download
|
||||||
|
embedder = TextEmbedding(model_name=model_name, cache_dir=str(cache_dir))
|
||||||
|
|
||||||
|
# Trigger actual download by calling embed
|
||||||
|
# TextEmbedding.__init__ alone doesn't download files
|
||||||
|
if progress_callback:
|
||||||
|
progress_callback(f"Initializing {model_name}...")
|
||||||
|
|
||||||
|
list(embedder.embed(["test"])) # Trigger download
|
||||||
|
|
||||||
if progress_callback:
|
if progress_callback:
|
||||||
progress_callback(f"Model {model_name} downloaded successfully")
|
progress_callback(f"Model {model_name} downloaded successfully")
|
||||||
|
|
||||||
# Get cache info using correct cache_name
|
# Get cache info using correct HuggingFace Hub path
|
||||||
cache_dir = get_cache_dir()
|
|
||||||
model_cache_path = _get_model_cache_path(cache_dir, info)
|
model_cache_path = _get_model_cache_path(cache_dir, info)
|
||||||
|
|
||||||
cache_size = 0
|
cache_size = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user