lidge-jun/codexclaw / plugins/codexclaw/skills/repo-map
cxc-repo-map
VerifiedUse for repo structure and symbol maps. Triggers: repo map, codebase overview, architecture map, 와꾸.
scripts/utils.py
View on GitHub"""
Utility functions for RepoMap.
"""
import os
from pathlib import Path
from typing import Optional, List
from collections import namedtuple
# Tag namedtuple for storing parsed code definitions and references
Tag = namedtuple("Tag", "rel_fname fname line name kind".split())
def count_tokens(text: str, model_name: str = "gpt-4") -> int:
"""Count tokens in text using tiktoken."""
if not text:
return 0
try:
import tiktoken
except ImportError:
return max(1, len(text) // 4)
try:
encoding = tiktoken.encoding_for_model(model_name)
except KeyError:
# Fallback for unknown models
encoding = tiktoken.get_encoding("cl100k_base")
return len(encoding.encode(text))
def read_text(filename: str, encoding: str = "utf-8", silent: bool = False) -> Optional[str]:
"""Read text from file with error handling."""
try:
return Path(filename).read_text(encoding=encoding, errors='ignore')
except FileNotFoundError:
if not silent:
print(f"Error: {filename} not found.")
return None
except IsADirectoryError:
if not silent:
print(f"Error: {filename} is a directory.")
return None
except OSError as e:
if not silent:
print(f"Error reading {filename}: {e}")
return None
except UnicodeError as e:
if not silent:
print(f"Error decoding {filename}: {e}")
return None
except Exception as e:
if not silent:
print(f"An unexpected error occurred while reading {filename}: {e}")
return None
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementation | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirements | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |