2025-12-31 14:07:14 +09:00
|
|
|
# SHARED UTILITIES KNOWLEDGE BASE
|
|
|
|
|
|
|
|
|
|
## OVERVIEW
|
|
|
|
|
|
2026-01-02 10:42:38 +09:00
|
|
|
Cross-cutting utilities: path resolution, config management, text processing, Claude Code compatibility helpers.
|
2025-12-31 14:07:14 +09:00
|
|
|
|
|
|
|
|
## STRUCTURE
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
shared/
|
2026-01-02 10:42:38 +09:00
|
|
|
├── index.ts # Barrel export
|
|
|
|
|
├── claude-config-dir.ts # ~/.claude resolution
|
|
|
|
|
├── command-executor.ts # Shell exec with variable expansion
|
|
|
|
|
├── config-errors.ts # Global error tracking
|
|
|
|
|
├── config-path.ts # User/project config paths
|
|
|
|
|
├── data-path.ts # XDG data directory
|
|
|
|
|
├── deep-merge.ts # Type-safe recursive merge
|
|
|
|
|
├── dynamic-truncator.ts # Token-aware truncation
|
|
|
|
|
├── file-reference-resolver.ts # @filename syntax
|
|
|
|
|
├── file-utils.ts # Symlink, markdown detection
|
2025-12-31 14:07:14 +09:00
|
|
|
├── frontmatter.ts # YAML frontmatter parsing
|
2026-01-02 10:42:38 +09:00
|
|
|
├── hook-disabled.ts # Check if hook disabled
|
|
|
|
|
├── jsonc-parser.ts # JSON with Comments
|
|
|
|
|
├── logger.ts # File-based logging
|
|
|
|
|
├── migration.ts # Legacy name compat (omo → Sisyphus)
|
2025-12-31 14:07:14 +09:00
|
|
|
├── model-sanitizer.ts # Normalize model names
|
2026-01-02 10:42:38 +09:00
|
|
|
├── pattern-matcher.ts # Tool name matching
|
|
|
|
|
├── snake-case.ts # Case conversion
|
|
|
|
|
└── tool-name.ts # PascalCase normalization
|
2025-12-31 14:07:14 +09:00
|
|
|
```
|
|
|
|
|
|
2026-01-02 10:42:38 +09:00
|
|
|
## WHEN TO USE
|
2025-12-31 14:07:14 +09:00
|
|
|
|
2026-01-02 10:42:38 +09:00
|
|
|
| Task | Utility |
|
|
|
|
|
|------|---------|
|
|
|
|
|
| Find ~/.claude | `getClaudeConfigDir()` |
|
|
|
|
|
| Merge configs | `deepMerge(base, override)` |
|
|
|
|
|
| Parse user files | `parseJsonc()` |
|
|
|
|
|
| Check hook enabled | `isHookDisabled(name, list)` |
|
|
|
|
|
| Truncate output | `dynamicTruncate(text, budget)` |
|
|
|
|
|
| Resolve @file | `resolveFileReferencesInText()` |
|
|
|
|
|
| Execute shell | `resolveCommandsInText()` |
|
|
|
|
|
| Legacy names | `migrateLegacyAgentNames()` |
|
2025-12-31 14:07:14 +09:00
|
|
|
|
|
|
|
|
## CRITICAL PATTERNS
|
|
|
|
|
|
|
|
|
|
```typescript
|
2026-01-02 10:42:38 +09:00
|
|
|
// Dynamic truncation
|
2025-12-31 14:07:14 +09:00
|
|
|
const output = dynamicTruncate(result, remainingTokens, 0.5)
|
|
|
|
|
|
2026-01-02 10:42:38 +09:00
|
|
|
// Deep merge priority
|
|
|
|
|
const final = deepMerge(deepMerge(defaults, userConfig), projectConfig)
|
2025-12-31 14:07:14 +09:00
|
|
|
|
2026-01-02 10:42:38 +09:00
|
|
|
// Safe JSONC
|
2025-12-31 14:07:14 +09:00
|
|
|
const { config, error } = parseJsoncSafe(content)
|
|
|
|
|
```
|
|
|
|
|
|
2026-01-02 10:42:38 +09:00
|
|
|
## ANTI-PATTERNS
|
2025-12-31 14:07:14 +09:00
|
|
|
|
2026-01-02 10:42:38 +09:00
|
|
|
- Hardcoding paths (use getClaudeConfigDir, getUserConfigPath)
|
|
|
|
|
- JSON.parse for user files (use parseJsonc)
|
|
|
|
|
- Ignoring truncation (large outputs MUST use dynamicTruncate)
|
|
|
|
|
- Direct string concat for configs (use deepMerge)
|