claude-statusline 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/LICENSE +203 -0
  2. package/README.md +362 -0
  3. package/bin/claude-statusline +22 -0
  4. package/dist/core/cache.d.ts +67 -0
  5. package/dist/core/cache.js +223 -0
  6. package/dist/core/cache.js.map +1 -0
  7. package/dist/core/config.d.ts +190 -0
  8. package/dist/core/config.js +192 -0
  9. package/dist/core/config.js.map +1 -0
  10. package/dist/core/security.d.ts +27 -0
  11. package/dist/core/security.js +154 -0
  12. package/dist/core/security.js.map +1 -0
  13. package/dist/env/context.d.ts +92 -0
  14. package/dist/env/context.js +295 -0
  15. package/dist/env/context.js.map +1 -0
  16. package/dist/git/native.d.ts +35 -0
  17. package/dist/git/native.js +141 -0
  18. package/dist/git/native.js.map +1 -0
  19. package/dist/git/status.d.ts +65 -0
  20. package/dist/git/status.js +256 -0
  21. package/dist/git/status.js.map +1 -0
  22. package/dist/index.bundle.js +11 -0
  23. package/dist/index.d.ts +9 -0
  24. package/dist/index.js +396 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/metafile.prod.json +473 -0
  27. package/dist/ui/symbols.d.ts +31 -0
  28. package/dist/ui/symbols.js +308 -0
  29. package/dist/ui/symbols.js.map +1 -0
  30. package/dist/ui/width.d.ts +29 -0
  31. package/dist/ui/width.js +261 -0
  32. package/dist/ui/width.js.map +1 -0
  33. package/dist/utils/runtime.d.ts +31 -0
  34. package/dist/utils/runtime.js +82 -0
  35. package/dist/utils/runtime.js.map +1 -0
  36. package/docs/ARCHITECTURE.md +336 -0
  37. package/docs/FEATURE_COMPARISON.md +178 -0
  38. package/docs/MIGRATION.md +354 -0
  39. package/docs/README.md +101 -0
  40. package/docs/eval-01-terminal-widths.md +519 -0
  41. package/docs/guide-01-configuration.md +277 -0
  42. package/docs/guide-02-troubleshooting.md +416 -0
  43. package/docs/guide-03-performance.md +183 -0
  44. package/docs/prd-01-typescript-perf-optimization.md +480 -0
  45. package/docs/research-01-sandbox-detection.md +169 -0
  46. package/docs/research-02-competitive-analysis.md +226 -0
  47. package/docs/research-03-platform-analysis.md +142 -0
  48. package/package.json +89 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"width.js","sourceRoot":"","sources":["../../src/ui/width.ts"],"names":[],"mappings":"AAEA;;;GAGG;AAEH;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,MAAc;IACnD,8DAA8D;IAC9D,IAAI,MAAM,CAAC,UAAU,IAAI,MAAM,CAAC,UAAU,GAAG,CAAC,EAAE,CAAC;QAC/C,OAAO,MAAM,CAAC,UAAU,CAAC;IAC3B,CAAC;IAED,6CAA6C;IAC7C,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC;IACvC,IAAI,UAAU,EAAE,CAAC;QACf,MAAM,OAAO,GAAG,QAAQ,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;QACzC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;YACnC,OAAO,OAAO,CAAC;QACjB,CAAC;IACH,CAAC;IAED,+CAA+C;IAC/C,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO,GAAG,CAAC,EAAE,CAAC;QACzD,OAAO,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC;IAChC,CAAC;IAED,gDAAgD;IAChD,MAAM,SAAS,GAAG,MAAM,UAAU,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IACrD,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,gDAAgD;IAChD,MAAM,SAAS,GAAG,MAAM,OAAO,EAAE,CAAC;IAClC,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,mDAAmD;IACnD,MAA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C9C,IAAI,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QAE1C,6DAA6D;QAC7D,IAAI,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YAC/B,UAAU,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QACvC,CAAC;QAED,kDAAkD;QAClD,IAAI,UAAU,EAAE,CAAC;YACf,OAAO,GAAG,SAAS,KAAK,WAAW,GAAG,UAAU,EAAE,CAAC;QACrD,CAAC;aAAM,CAAC;YACN,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;SAAM,CAAC;QACN,mCAAmC;QACnC,IAAI,QAAQ,GAAG,SAAS,CAAC;QAEzB,uEAAuE;QACvE,yFAAyF;QACzF,OAAO,QAAQ,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;YACnE,QAAQ,EAAE,CAAC;QACb,CAAC;QAED,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;QAC9C,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QAC5C,OAAO,GAAG,SAAS,IAAI,UAAU,EAAE,CAAC;IACtC,CAAC;AACH,CAAC","sourcesContent":["import { Config } from '../core/config.js';\n\n/**\n * Terminal width detection utilities\n * Ported from bash implementation with cross-platform Node.js support\n */\n\n/**\n * Get terminal width using multiple detection methods\n * Ordered from most reliable to fallback methods\n */\nexport async function getTerminalWidth(config: Config): Promise<number> {\n // Method 0: Respect manual width override first (for testing)\n if (config.forceWidth && config.forceWidth > 0) {\n return config.forceWidth;\n }\n\n // Method 1: Try COLUMNS environment variable\n const columnsEnv = process.env.COLUMNS;\n if (columnsEnv) {\n const columns = parseInt(columnsEnv, 10);\n if (!isNaN(columns) && columns > 0) {\n return columns;\n }\n }\n\n // Method 2: Try Node.js process.stdout.columns\n if (process.stdout.columns && process.stdout.columns > 0) {\n return process.stdout.columns;\n }\n\n // Method 3: Try tput command (Unix/Linux/macOS)\n const tputWidth = await tryCommand('tput', ['cols']);\n if (tputWidth) {\n return tputWidth;\n }\n\n // Method 4: Try stty command (Unix/Linux/macOS)\n const sttyWidth = await tryStty();\n if (sttyWidth) {\n return sttyWidth;\n }\n\n // Method 5: Check Claude Code specific environment\n const claudeWidth = process.env.CLAUDE_CODE_TERMINAL_WIDTH;\n if (claudeWidth) {\n const width = parseInt(claudeWidth, 10);\n if (!isNaN(width) && width > 0) {\n return width;\n }\n }\n\n // Method 6: Terminal-specific defaults\n const termProgram = process.env.TERM_PROGRAM;\n const term = process.env.TERM;\n\n if (termProgram === 'vscode' && process.env.VSCODE_PID) {\n return 120; // VS Code default\n }\n\n if (['ghostty', 'wezterm', 'iterm'].includes(termProgram || '')) {\n return 120; // Modern terminals default to wider\n }\n\n if (term && ['alacritty', 'kitty', 'wezterm', 'ghostty', 'xterm-256color'].includes(term)) {\n return 120; // Modern terminals\n }\n\n // Method 7: Check for Windows Terminal\n if (process.env.WT_SESSION || process.env.WT_PROFILE_ID) {\n return 120; // Windows Terminal\n }\n\n // Final fallback: conservative 80-column default\n return 80;\n}\n\n/**\n * Execute a command and parse numeric output\n */\nasync function tryCommand(command: string, args: string[]): Promise<number | null> {\n try {\n const { exec } = await import('child_process');\n const { promisify } = await import('util');\n const execAsync = promisify(exec);\n\n const { stdout } = await execAsync(`${command} ${args.join(' ')}`, {\n timeout: 1000, // 1 second timeout\n encoding: 'utf-8',\n });\n\n const width = parseInt(stdout.trim(), 10);\n if (!isNaN(width) && width > 0) {\n return width;\n }\n } catch {\n // Command failed or not available\n }\n\n return null;\n}\n\n/**\n * Try stty size command\n */\nasync function tryStty(): Promise<number | null> {\n try {\n const { exec } = await import('child_process');\n const { promisify } = await import('util');\n const execAsync = promisify(exec);\n\n const { stdout } = await execAsync('stty size', {\n timeout: 1000,\n encoding: 'utf-8',\n });\n\n // stty size returns: \"rows cols\"\n const parts = stdout.trim().split(' ');\n if (parts.length === 2) {\n const width = parseInt(parts[1] || '0', 10);\n if (!isNaN(width) && width > 0) {\n return width;\n }\n }\n } catch {\n // stty failed or not available\n }\n\n return null;\n}\n\n/**\n * Debug width detection (matches bash implementation)\n */\nexport async function debugWidthDetection(config: Config): Promise<void> {\n if (!config.debugWidth) {\n return;\n }\n\n console.error('[WIDTH DEBUG] Debug mode enabled');\n\n console.error('[WIDTH DEBUG] Methods tried:');\n\n // Test process.stdout.columns\n if (process.stdout.columns) {\n console.error(`[WIDTH DEBUG] process.stdout.columns: ${process.stdout.columns}`);\n } else {\n console.error('[WIDTH DEBUG] process.stdout.columns: not available');\n }\n\n // Test COLUMNS variable\n const columnsEnv = process.env.COLUMNS;\n if (columnsEnv) {\n console.error(`[WIDTH DEBUG] COLUMNS variable: ${columnsEnv}`);\n } else {\n console.error('[WIDTH DEBUG] COLUMNS variable: not set');\n }\n\n // Test tput\n const tputWidth = await tryCommand('tput', ['cols']);\n if (tputWidth) {\n console.error(`[WIDTH DEBUG] tput cols: ${tputWidth}`);\n } else {\n console.error('[WIDTH DEBUG] tput: not available or failed');\n }\n\n // Test stty\n const sttyWidth = await tryStty();\n if (sttyWidth) {\n console.error(`[WIDTH DEBUG] stty size: ${sttyWidth}`);\n } else {\n console.error('[WIDTH DEBUG] stty: not available or failed');\n }\n\n // Test environment variables\n console.error(`[WIDTH DEBUG] CLAUDE_CODE_STATUSLINE_FORCE_WIDTH: ${config.forceWidth || 'not set'}`);\n console.error(`[WIDTH DEBUG] COLUMNS variable: ${columnsEnv || 'not set'}`);\n console.error(`[WIDTH DEBUG] CLAUDE_CODE_TERMINAL_WIDTH: ${process.env.CLAUDE_CODE_TERMINAL_WIDTH || 'not set'}`);\n console.error(`[WIDTH DEBUG] TERM_PROGRAM: ${process.env.TERM_PROGRAM || 'not set'}`);\n console.error(`[WIDTH DEBUG] TERM: ${process.env.TERM || 'not set'}`);\n\n // Show final result\n const finalWidth = await getTerminalWidth(config);\n console.error(`[WIDTH DEBUG] Final detected width: ${finalWidth}`);\n console.error(`[WIDTH DEBUG] Statusline will use: ${finalWidth - config.rightMargin} columns max`);\n}\n\n/**\n * Text truncation utilities\n */\n\n/**\n * Simple text truncation with ellipsis\n */\nexport function truncateText(text: string, maxLength: number): string {\n if (text.length <= maxLength) {\n return text;\n }\n\n // Edge case: if maxLength is too small, return minimal result\n if (maxLength < 4) {\n return '..';\n }\n\n return `${text.substring(0, maxLength - 2)}..`;\n}\n\n/**\n * Smart truncation with branch prioritization (matches bash implementation)\n */\nexport function smartTruncate(\n project: string,\n gitInfo: string,\n maxLen: number,\n _config: Config\n): string {\n // Step 1: Check if everything fits\n if (project.length + gitInfo.length <= maxLen) {\n return '';\n }\n\n // Step 2: Truncate project only (preserve branch)\n const projLen = maxLen - gitInfo.length - 2;\n if (projLen >= 5) {\n return `${project.substring(0, projLen)}..${gitInfo}`;\n }\n\n // Step 3: Truncate project + branch (preserve indicators)\n let indicators = '';\n const bracketMatch = gitInfo.match(/\\[([^\\]]+)\\]/);\n if (bracketMatch) {\n indicators = bracketMatch[1] || '';\n }\n\n const branchLen = maxLen - indicators.length - 8;\n if (branchLen >= 8) {\n const gitPrefix = gitInfo.substring(0, Math.min(gitInfo.length, branchLen));\n return `${project.substring(0, 4)}..${gitPrefix}..${indicators ? ` [${indicators}]` : ''}`;\n }\n\n // Step 4: Basic fallback\n return `${project.substring(0, maxLen)}..`;\n}\n\n/**\n * Soft wrapping function (experimental)\n */\nexport function softWrapText(\n text: string,\n maxLength: number,\n wrapChar: 'newline' | 'space' = 'newline',\n modelPrefix: string = '*'\n): string {\n if (text.length <= maxLength) {\n return text;\n }\n\n if (wrapChar === 'newline') {\n // Smart wrap: try to break at space or safe character\n let breakPos = maxLength;\n let foundBreak = false;\n\n // Look for safe break points (spaces)\n for (let i = Math.min(maxLength - 1, text.length - 1); i > Math.max(maxLength - 20, 0) && i >= 0; i--) {\n const char = text[i];\n if (char === ' ') {\n breakPos = i;\n foundBreak = true;\n break;\n }\n }\n\n // If no safe break found and we're very close to max_length, just fit without wrapping\n if (!foundBreak && maxLength - text.length > -3) {\n return text;\n }\n\n // Adjust break position to avoid splitting multi-byte UTF-8 characters\n // UTF-8 continuation bytes have their two most significant bits set to 10 (0x80 to 0xBF)\n while (breakPos > 0 && (text.charCodeAt(breakPos) & 0xC0) === 0x80) {\n breakPos--;\n }\n\n const firstLine = text.substring(0, breakPos);\n let secondLine = text.substring(breakPos);\n\n // Remove leading space from second line if we broke at space\n if (secondLine.startsWith(' ')) {\n secondLine = secondLine.substring(1);\n }\n\n // Only wrap if second line has meaningful content\n if (secondLine) {\n return `${firstLine}\\n${modelPrefix}${secondLine}`;\n } else {\n return firstLine;\n }\n } else {\n // Use space separator for wrapping\n let breakPos = maxLength;\n\n // Adjust break position to avoid splitting multi-byte UTF-8 characters\n // UTF-8 continuation bytes have their two most significant bits set to 10 (0x80 to 0xBF)\n while (breakPos > 0 && (text.charCodeAt(breakPos) & 0xC0) === 0x80) {\n breakPos--;\n }\n\n const firstLine = text.substring(0, breakPos);\n const secondLine = text.substring(breakPos);\n return `${firstLine} ${secondLine}`;\n }\n}"]}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Runtime detection utilities for optimizing performance based on the JavaScript runtime
3
+ */
4
+ export type Runtime = 'node' | 'bun' | 'unknown';
5
+ interface RuntimeInfo {
6
+ runtime: Runtime;
7
+ version: string;
8
+ isBun: boolean;
9
+ isNode: boolean;
10
+ }
11
+ /**
12
+ * Detect the current JavaScript runtime
13
+ */
14
+ export declare function detectRuntime(): RuntimeInfo;
15
+ /**
16
+ * Get the optimal executable for git commands based on runtime
17
+ */
18
+ export declare function getGitExecutable(): string;
19
+ /**
20
+ * Check if the runtime supports native performance optimizations
21
+ */
22
+ export declare function supportsNativeOptimizations(): boolean;
23
+ /**
24
+ * Get runtime-specific performance recommendations
25
+ */
26
+ export declare function getPerformanceRecommendations(): string[];
27
+ /**
28
+ * Log runtime information for debugging
29
+ */
30
+ export declare function logRuntimeInfo(): void;
31
+ export {};
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Runtime detection utilities for optimizing performance based on the JavaScript runtime
3
+ */
4
+ /**
5
+ * Detect the current JavaScript runtime
6
+ */
7
+ export function detectRuntime() {
8
+ // Check for Bun
9
+ if (typeof globalThis !== 'undefined' && 'Bun' in globalThis) {
10
+ // @ts-ignore - Bun is a global when running in Bun runtime
11
+ const bunVersion = globalThis.Bun?.version || 'unknown';
12
+ return {
13
+ runtime: 'bun',
14
+ version: bunVersion,
15
+ isBun: true,
16
+ isNode: false,
17
+ };
18
+ }
19
+ // Check for Node.js
20
+ if (typeof process !== 'undefined' && process.versions && process.versions.node) {
21
+ return {
22
+ runtime: 'node',
23
+ version: process.versions.node,
24
+ isBun: false,
25
+ isNode: true,
26
+ };
27
+ }
28
+ // Unknown runtime
29
+ return {
30
+ runtime: 'unknown',
31
+ version: 'unknown',
32
+ isBun: false,
33
+ isNode: false,
34
+ };
35
+ }
36
+ /**
37
+ * Get the optimal executable for git commands based on runtime
38
+ */
39
+ export function getGitExecutable() {
40
+ // On Windows, use git.exe
41
+ if (process.platform === 'win32') {
42
+ return 'git.exe';
43
+ }
44
+ // On Unix-like systems, use git
45
+ return 'git';
46
+ }
47
+ /**
48
+ * Check if the runtime supports native performance optimizations
49
+ */
50
+ export function supportsNativeOptimizations() {
51
+ const { runtime } = detectRuntime();
52
+ return runtime === 'bun';
53
+ }
54
+ /**
55
+ * Get runtime-specific performance recommendations
56
+ */
57
+ export function getPerformanceRecommendations() {
58
+ const { runtime, version } = detectRuntime();
59
+ const recommendations = [];
60
+ if (runtime === 'node') {
61
+ recommendations.push('Consider using Bun runtime for 42% better performance');
62
+ const majorVersion = parseInt(version.split('.')[0] || '0');
63
+ if (majorVersion < 20) {
64
+ recommendations.push('Upgrade to Node.js 20+ for better performance');
65
+ }
66
+ }
67
+ else if (runtime === 'bun') {
68
+ recommendations.push('Using optimal Bun runtime');
69
+ }
70
+ else {
71
+ recommendations.push('Unknown runtime - performance may vary');
72
+ }
73
+ return recommendations;
74
+ }
75
+ /**
76
+ * Log runtime information for debugging
77
+ */
78
+ export function logRuntimeInfo() {
79
+ const { runtime, version } = detectRuntime();
80
+ console.debug(`Running on ${runtime} ${version}`);
81
+ }
82
+ //# sourceMappingURL=runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/utils/runtime.ts"],"names":[],"mappings":"AAAA;;GAEG;AAWH;;GAEG;AACH,MAAM,UAAU,aAAa;IAC3B,gBAAgB;IAChB,IAAI,OAAO,UAAU,KAAK,WAAW,IAAI,KAAK,IAAI,UAAU,EAAE,CAAC;QAC7D,2DAA2D;QAC3D,MAAM,UAAU,GAAI,UAAkB,CAAC,GAAG,EAAE,OAAO,IAAI,SAAS,CAAC;QACjE,OAAO;YACL,OAAO,EAAE,KAAK;YACd,OAAO,EAAE,UAAU;YACnB,KAAK,EAAE,IAAI;YACX,MAAM,EAAE,KAAK;SACd,CAAC;IACJ,CAAC;IAED,oBAAoB;IACpB,IAAI,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;QAChF,OAAO;YACL,OAAO,EAAE,MAAM;YACf,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI;YAC9B,KAAK,EAAE,KAAK;YACZ,MAAM,EAAE,IAAI;SACb,CAAC;IACJ,CAAC;IAED,kBAAkB;IAClB,OAAO;QACL,OAAO,EAAE,SAAS;QAClB,OAAO,EAAE,SAAS;QAClB,KAAK,EAAE,KAAK;QACZ,MAAM,EAAE,KAAK;KACd,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB;IAC9B,0BAA0B;IAC1B,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QACjC,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,gCAAgC;IAChC,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,2BAA2B;IACzC,MAAM,EAAE,OAAO,EAAE,GAAG,aAAa,EAAE,CAAC;IACpC,OAAO,OAAO,KAAK,KAAK,CAAC;AAC3B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,6BAA6B;IAC3C,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,aAAa,EAAE,CAAC;IAC7C,MAAM,eAAe,GAAa,EAAE,CAAC;IAErC,IAAI,OAAO,KAAK,MAAM,EAAE,CAAC;QACvB,eAAe,CAAC,IAAI,CAAC,uDAAuD,CAAC,CAAC;QAC9E,MAAM,YAAY,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC;QAC5D,IAAI,YAAY,GAAG,EAAE,EAAE,CAAC;YACtB,eAAe,CAAC,IAAI,CAAC,+CAA+C,CAAC,CAAC;QACxE,CAAC;IACH,CAAC;SAAM,IAAI,OAAO,KAAK,KAAK,EAAE,CAAC;QAC7B,eAAe,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;IACpD,CAAC;SAAM,CAAC;QACN,eAAe,CAAC,IAAI,CAAC,wCAAwC,CAAC,CAAC;IACjE,CAAC;IAED,OAAO,eAAe,CAAC;AACzB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,aAAa,EAAE,CAAC;IAC7C,OAAO,CAAC,KAAK,CAAC,cAAc,OAAO,IAAI,OAAO,EAAE,CAAC,CAAC;AACpD,CAAC","sourcesContent":["/**\n * Runtime detection utilities for optimizing performance based on the JavaScript runtime\n */\n\nexport type Runtime = 'node' | 'bun' | 'unknown';\n\ninterface RuntimeInfo {\n runtime: Runtime;\n version: string;\n isBun: boolean;\n isNode: boolean;\n}\n\n/**\n * Detect the current JavaScript runtime\n */\nexport function detectRuntime(): RuntimeInfo {\n // Check for Bun\n if (typeof globalThis !== 'undefined' && 'Bun' in globalThis) {\n // @ts-ignore - Bun is a global when running in Bun runtime\n const bunVersion = (globalThis as any).Bun?.version || 'unknown';\n return {\n runtime: 'bun',\n version: bunVersion,\n isBun: true,\n isNode: false,\n };\n }\n\n // Check for Node.js\n if (typeof process !== 'undefined' && process.versions && process.versions.node) {\n return {\n runtime: 'node',\n version: process.versions.node,\n isBun: false,\n isNode: true,\n };\n }\n\n // Unknown runtime\n return {\n runtime: 'unknown',\n version: 'unknown',\n isBun: false,\n isNode: false,\n };\n}\n\n/**\n * Get the optimal executable for git commands based on runtime\n */\nexport function getGitExecutable(): string {\n // On Windows, use git.exe\n if (process.platform === 'win32') {\n return 'git.exe';\n }\n\n // On Unix-like systems, use git\n return 'git';\n}\n\n/**\n * Check if the runtime supports native performance optimizations\n */\nexport function supportsNativeOptimizations(): boolean {\n const { runtime } = detectRuntime();\n return runtime === 'bun';\n}\n\n/**\n * Get runtime-specific performance recommendations\n */\nexport function getPerformanceRecommendations(): string[] {\n const { runtime, version } = detectRuntime();\n const recommendations: string[] = [];\n\n if (runtime === 'node') {\n recommendations.push('Consider using Bun runtime for 42% better performance');\n const majorVersion = parseInt(version.split('.')[0] || '0');\n if (majorVersion < 20) {\n recommendations.push('Upgrade to Node.js 20+ for better performance');\n }\n } else if (runtime === 'bun') {\n recommendations.push('Using optimal Bun runtime');\n } else {\n recommendations.push('Unknown runtime - performance may vary');\n }\n\n return recommendations;\n}\n\n/**\n * Log runtime information for debugging\n */\nexport function logRuntimeInfo(): void {\n const { runtime, version } = detectRuntime();\n console.debug(`Running on ${runtime} ${version}`);\n}"]}
@@ -0,0 +1,336 @@
1
+ # Architecture
2
+
3
+ This document describes the technical architecture and design decisions for Claude Statusline v2.0.
4
+
5
+ ## Overview
6
+
7
+ Claude Statusline is a TypeScript CLI tool that provides git status indicators and environment context for Claude Code. The architecture prioritizes:
8
+
9
+ - **Performance**: Native JavaScript optimizations over bash interpretation
10
+ - **Security**: Type safety and input validation
11
+ - **Modularity**: Clean separation of concerns
12
+ - **Maintainability**: Testable, documented code
13
+
14
+ ## Project Structure
15
+
16
+ ```
17
+ claude-statusline/
18
+ ├── src/ # TypeScript source code
19
+ │ ├── core/ # Core functionality
20
+ │ │ ├── config.ts # Configuration management with Zod validation
21
+ │ │ ├── security.ts # Input validation and sanitization
22
+ │ │ └── cache.ts # TTL-based caching system
23
+ │ ├── git/ # Git operations
24
+ │ │ └── status.ts # Git status parsing and indicator formatting
25
+ │ ├── ui/ # User interface components
26
+ │ │ ├── symbols.ts # Symbol detection and Nerd Font support
27
+ │ │ └── width.ts # Terminal width detection and text truncation
28
+ │ ├── env/ # Environment detection
29
+ │ │ └── context.ts # Development tool version detection
30
+ │ └── index.ts # Main entry point
31
+ ├── bin/ # Executable wrappers
32
+ │ └── claude-statusline # Main executable with shebang
33
+ ├── tests/ # Test suite
34
+ ├── scripts/ # Development utilities
35
+ │ └── benchmark.js # Performance benchmarking
36
+ └── dist/ # Compiled JavaScript (generated)
37
+ ```
38
+
39
+ ## Core Modules
40
+
41
+ ### Configuration System (`core/config.ts`)
42
+
43
+ **Purpose**: Centralized configuration management with validation
44
+
45
+ **Features**:
46
+ - **Zod schema validation** for runtime type safety
47
+ - **Multiple config sources**: Files (JSON/YAML), environment variables, defaults
48
+ - **Hierarchical precedence**: CLI args > env vars > config files > defaults
49
+ - **Backward compatibility** with v1.0 environment variables
50
+
51
+ **Key Design Decisions**:
52
+ - Use Zod for both compile-time (TypeScript) and runtime validation
53
+ - Support both JSON and YAML for user preference
54
+ - Environment variable inheritance for smooth v1.0 → v2.0 migration
55
+
56
+ ```typescript
57
+ const ConfigSchema = z.object({
58
+ cacheTTL: z.number().default(300),
59
+ noEmoji: z.boolean().default(false),
60
+ // ... other config fields
61
+ });
62
+ ```
63
+
64
+ ### Security Module (`core/security.ts`)
65
+
66
+ **Purpose**: Input validation and sanitization
67
+
68
+ **Features**:
69
+ - **JSON input validation** with structure and length checks
70
+ - **Path traversal prevention** with comprehensive pattern matching
71
+ - **Command injection protection** for all shell interactions
72
+ - **String sanitization** for safe display
73
+
74
+ **Security Layers**:
75
+ 1. **TypeScript compile-time** type checking
76
+ 2. **Zod runtime** validation
77
+ 3. **Custom validation** functions for security-critical inputs
78
+ 4. **Sanitization** before display or processing
79
+
80
+ ### Caching System (`core/cache.ts`)
81
+
82
+ **Purpose**: Performance optimization with TTL-based caching
83
+
84
+ **Features**:
85
+ - **File-based caching** with automatic cleanup
86
+ - **TTL support** per cache entry
87
+ - **Parallel operations** for performance
88
+ - **Cache statistics** for monitoring
89
+
90
+ **Cache Strategy**:
91
+ - **Tool versions**: 5-minute TTL (Node.js, Python)
92
+ - **Docker version**: 30-minute TTL (less frequent changes)
93
+ - **Git information**: 1-minute TTL (branch can change frequently)
94
+
95
+ ### Git Operations (`git/status.ts`)
96
+
97
+ **Purpose**: Git repository status parsing and indicator generation
98
+
99
+ **Dependencies**: `simple-git` library for cross-platform git operations
100
+
101
+ **Features**:
102
+ - **Comprehensive status parsing**: staged, unstaged, untracked, conflicts
103
+ - **Remote tracking**: ahead/behind status detection
104
+ - **Multiple git methods**: fallbacks for different git versions
105
+ - **Cross-platform compatibility**: Windows, macOS, Linux
106
+
107
+ **Status Parsing Logic**:
108
+ ```typescript
109
+ // Parse git --porcelain format
110
+ // XY PATH where X=staged, Y=unstaged
111
+ if (stagedChar === 'M') indicators.staged++;
112
+ if (unstagedChar === 'M') indicators.modified++;
113
+ // ... handle all cases
114
+ ```
115
+
116
+ ### Symbol Management (`ui/symbols.ts`)
117
+
118
+ **Purpose**: Terminal font detection and symbol selection
119
+
120
+ **Features**:
121
+ - **Nerd Font auto-detection** with multiple methods
122
+ - **ASCII fallback** symbol sets
123
+ - **Terminal-specific detection** (VSCode, iTerm, etc.)
124
+ - **Platform-specific font detection**
125
+
126
+ **Detection Methods**:
127
+ 1. **Environment variables**: `NERD_FONT=1`, `TERM_PROGRAM`
128
+ 2. **Font list analysis**: `fc-list`, `system_profiler`
129
+ 3. **Installation patterns**: Common Nerd Font locations
130
+ 4. **Terminal heuristics**: Known Nerd Font-capable terminals
131
+
132
+ ### Width Management (`ui/width.ts`)
133
+
134
+ **Purpose**: Terminal width detection and text truncation
135
+
136
+ **Features**:
137
+ - **Multiple width detection methods** with fallbacks
138
+ - **Smart truncation** with branch prioritization
139
+ - **Soft wrapping** support for long content
140
+ - **Responsive design** for different terminal sizes
141
+
142
+ **Width Detection Priority**:
143
+ 1. **Manual override**: `CLAUDE_CODE_STATUSLINE_FORCE_WIDTH`
144
+ 2. **Environment**: `COLUMNS`, `CLAUDE_CODE_TERMINAL_WIDTH`
145
+ 3. **Node.js**: `process.stdout.columns`
146
+ 4. **System commands**: `tput cols`, `stty size`
147
+ 5. **Terminal defaults**: Based on `TERM_PROGRAM`, `TERM`
148
+
149
+ ### Environment Detection (`env/context.ts`)
150
+
151
+ **Purpose**: Development tool version detection and caching
152
+
153
+ **Features**:
154
+ - **Parallel version detection** for performance
155
+ - **Cross-platform command execution**
156
+ - **Intelligent caching** with different TTL per tool
157
+ - **Graceful fallbacks** for missing tools
158
+
159
+ **Supported Tools**:
160
+ - **Node.js**: `node --version`
161
+ - **Python**: `python3 --version` → `python --version`
162
+ - **Docker**: `docker --version`
163
+
164
+ ## Data Flow
165
+
166
+ ```
167
+ Claude Code Input
168
+
169
+ Security Validation
170
+
171
+ Configuration Loading
172
+
173
+ ┌─────────────────────────┐
174
+ │ Parallel Operations │
175
+ ├─────────┬───────────────┤
176
+ │ Git │ Environment │
177
+ │ Status │ Detection │
178
+ └─────────┴───────────────┘
179
+
180
+ Symbol Selection
181
+
182
+ Width Detection
183
+
184
+ Statusline Assembly
185
+
186
+ Output to Claude Code
187
+ ```
188
+
189
+ ## Performance Considerations
190
+
191
+ ### Native JavaScript Optimizations
192
+
193
+ **v2.0 vs v1.0 Performance Gains**:
194
+ - **JSON parsing**: Native `JSON.parse()` vs bash regex
195
+ - **Parallel execution**: `Promise.all()` vs sequential bash commands
196
+ - **Caching**: Built-in Node.js caching vs file operations
197
+ - **String operations**: Optimized V8 engine vs bash string manipulation
198
+
199
+ ### Caching Strategy
200
+
201
+ **Cache Hierarchy**:
202
+ 1. **In-memory**: Process-level caching during execution
203
+ 2. **File-based**: Persistent cache across executions
204
+ 3. **TTL-based**: Automatic cache invalidation
205
+
206
+ **Cache Keys**:
207
+ - Environment versions: `node_version`, `python3_version`
208
+ - Git information: `git_branch_<base64_dir>`, `git_remote_<base64_dir>`
209
+
210
+ ### Memory Management
211
+
212
+ - **Minimal memory footprint**: Stream processing where possible
213
+ - **Efficient data structures**: Use appropriate TypeScript types
214
+ - **Cache cleanup**: Automatic TTL-based expiration
215
+
216
+ ## Security Architecture
217
+
218
+ ### Input Validation Layers
219
+
220
+ 1. **TypeScript**: Compile-time type checking
221
+ 2. **Zod**: Runtime schema validation
222
+ 3. **Custom validation**: Security-specific checks
223
+ 4. **Sanitization**: Output sanitization
224
+
225
+ ### Threat Model
226
+
227
+ **Protected Against**:
228
+ - **Command injection**: All shell commands use parameterized execution
229
+ - **Path traversal**: Comprehensive path validation
230
+ - **Buffer overflow**: Length limits on all inputs
231
+ - **Code injection**: JSON parsing with structure validation
232
+
233
+ **Assumptions**:
234
+ - **Claude Code input is trusted** but validated
235
+ - **File system access is limited** to user directories
236
+ - **Network access is not required** for core functionality
237
+
238
+ ## Cross-Platform Compatibility
239
+
240
+ ### Platform-Specific Considerations
241
+
242
+ **Windows**:
243
+ - **Path handling**: Backward/forward slashes
244
+ - **Command execution**: `cmd.exe` vs `powershell`
245
+ - **Font detection**: Windows-specific font locations
246
+ - **Terminal detection**: Windows Terminal, ConHost
247
+
248
+ **macOS**:
249
+ - **Font detection**: Homebrew Nerd Font installations
250
+ - **Command availability**: BSD vs GNU command variants
251
+ - **File permissions**: Executable bit handling
252
+
253
+ **Linux**:
254
+ - **Font detection**: Fontconfig, system fonts
255
+ - **Terminal diversity**: Wide range of terminal emulators
256
+ - **Package managers**: Different font installation methods
257
+
258
+ ### Compatibility Strategy
259
+
260
+ 1. **Node.js API**: Use cross-platform Node.js modules
261
+ 2. **Conditional logic**: Platform-specific code paths where needed
262
+ 3. **Fallbacks**: Multiple methods for critical operations
263
+ 4. **Testing**: Multi-platform testing in CI/CD
264
+
265
+ ## Testing Strategy
266
+
267
+ ### Test Categories
268
+
269
+ 1. **Unit Tests**: Individual module functionality
270
+ 2. **Integration Tests**: Module interaction testing
271
+ 3. **Security Tests**: Input validation and attack prevention
272
+ 4. **Performance Tests**: Benchmarking against baseline
273
+ 5. **Cross-Platform Tests**: Compatibility verification
274
+
275
+ ### Test Structure
276
+
277
+ ```
278
+ tests/
279
+ ├── security.test.ts # Security validation tests
280
+ ├── runner.test.ts # Main functionality tests
281
+ ├── git/ # Git operation tests
282
+ ├── core/ # Core module tests
283
+ ├── ui/ # UI component tests
284
+ └── env/ # Environment detection tests
285
+ ```
286
+
287
+ ## Future Extensibility
288
+
289
+ ### Plugin Architecture (Planned)
290
+
291
+ **Design Goals**:
292
+ - **Modular plugins**: Easy to add new indicators
293
+ - **Configuration-driven**: Plugin enable/disable via config
294
+ - **Performance isolation**: Plugin failures don't affect core
295
+ - **Type safety**: Plugin interface definitions
296
+
297
+ **Plugin Interface Sketch**:
298
+ ```typescript
299
+ interface StatuslinePlugin {
300
+ name: string;
301
+ version: string;
302
+ execute(context: PluginContext): Promise<string | null>;
303
+ }
304
+ ```
305
+
306
+ ### Configuration Schema Evolution
307
+
308
+ **Backward Compatibility**:
309
+ - **Schema versioning**: Config format versioning
310
+ - **Migration paths**: Automatic config upgrades
311
+ - **Fallback handling**: Graceful degradation for old configs
312
+
313
+ ## Dependencies
314
+
315
+ ### Runtime Dependencies
316
+
317
+ - **simple-git**: Git operations with cross-platform support
318
+ - **zod**: Runtime type validation and schema definition
319
+ - **yaml**: YAML configuration file support
320
+
321
+ ### Development Dependencies
322
+
323
+ - **TypeScript**: Type safety and modern JavaScript features
324
+ - **ESLint + Prettier**: Code quality and formatting
325
+ - **Node.js test runner**: Native testing framework
326
+
327
+ ### Dependency Strategy
328
+
329
+ - **Minimal dependencies**: Only essential runtime dependencies
330
+ - **Well-maintained packages**: Active development and security
331
+ - **Alternative options**: Multiple packages considered for each need
332
+ - **Security scanning**: Regular dependency vulnerability scans
333
+
334
+ ---
335
+
336
+ This architecture is designed to balance performance, security, and maintainability while providing a solid foundation for future enhancements.
@@ -0,0 +1,178 @@
1
+ # Feature Comparison: TypeScript v2.0 vs Bash v1.0
2
+
3
+ Comprehensive comparison between Bash v1.0 and TypeScript v2.0 implementations.
4
+
5
+ **Ready to upgrade?** See the [Migration Guide](./MIGRATION.md) for step-by-step instructions.
6
+
7
+ ## Performance Overview
8
+
9
+ | Version | Execution Time | Performance | Notes |
10
+ |---------|----------------|-------------|-------|
11
+ | **TypeScript v2.0** | **~5ms (Bun) / ~28ms (Node.js)** | ✅ Excellent | Native JS optimizations |
12
+ | Bash v1.0 | ~99ms | ✅ Good | Optimized bash implementation |
13
+ | Bash v1.0 (first run) | ~888ms | ⚠️ Slow | One-time cache population |
14
+
15
+ ## Feature Matrix
16
+
17
+ | Feature | Bash v1.0 | TypeScript v2.0 | Notes |
18
+ |---------|-----------|------------------|-------|
19
+ | **Core Functionality** |
20
+ | Git status indicators | ✅ | ✅ | Branch, staged, modified, untracked, etc. |
21
+ | Environment context | ✅ | ✅ | Node.js, Python, Docker versions |
22
+ | Smart truncation | ✅ | ✅ | Prevents statusline overflow |
23
+ | ASCII/Nerd Font detection | ✅ | ✅ | Auto-detects terminal capabilities |
24
+ | Security validation | ✅ | ✅ | Input validation, path sanitization |
25
+ | Soft-wrapping | ✅ | ✅ | Advanced text wrapping options |
26
+ | **Configuration** |
27
+ | Environment variables | ✅ | ✅ | Legacy support in both |
28
+ | Configuration files | ❌ | ✅ | `.claude-statusline.json/.yaml` |
29
+ | JSON Schema validation | ❌ | ✅ | Editor autocompletion & validation |
30
+ | Project-specific configs | ❌ | ✅ | Override global settings |
31
+ | **Platform Support** |
32
+ | Linux/macOS | ✅ | ✅ | Full support |
33
+ | Windows | ❌ | ✅ | Native Node.js support |
34
+ | Cross-platform caching | ✅ | ✅ | Both have caching systems |
35
+ | **Distribution** |
36
+ | Manual download | ✅ | ✅ | Download from releases |
37
+ | npm distribution | ❌ | ✅ | `npm install -g claude-statusline` |
38
+ | bun distribution | ❌ | ✅ | `bun install -g claude-statusline` |
39
+ | **Development Experience** |
40
+ | TypeScript types | ❌ | ✅ | Full type safety |
41
+ | Editor integration | ❌ | ✅ | JSON Schema support |
42
+ | Debug options | ✅ | ✅ | Enhanced debugging in v2.0 |
43
+ | Unit tests | ✅ | ✅ | Both have test suites |
44
+ | **Advanced Features** |
45
+ | Width debugging | ❌ | ✅ | `debugWidth` option |
46
+ | Force width override | ❌ | ✅ | `forceWidth` option |
47
+ | Configurable symbols | ❌ | ✅ | Custom Nerd Font/ASCII symbols |
48
+ | YAML config support | ❌ | ✅ | Alternative config format |
49
+ | Cache management | ✅ | ✅ | TTL-based caching |
50
+
51
+ ## Detailed Feature Breakdown
52
+
53
+ ### Core Git Status Features
54
+
55
+ Both versions provide comprehensive git status:
56
+
57
+ | Indicator | Bash v1.0 | TypeScript v2.0 | Symbol |
58
+ |-----------|-----------|------------------|--------|
59
+ | Stashed changes | ✅ | ✅ | ⚑ / $ |
60
+ | Staged files | ✅ | ✅ | + |
61
+ | Modified files | ✅ | ✅ | ! |
62
+ | Untracked files | ✅ | ✅ | ? |
63
+ | Renamed files | ✅ | ✅ | » / > |
64
+ | Deleted files | ✅ | ✅ | ✘ / X |
65
+ | Merge conflicts | ✅ | ✅ | × / C |
66
+ | Ahead of upstream | ✅ | ✅ | ↑ / A |
67
+ | Behind upstream | ✅ | ✅ | ↓ / B |
68
+ | Diverged branches | ✅ | ✅ | ⇕ / D |
69
+
70
+ ### Configuration Capabilities
71
+
72
+ #### Bash v1.0
73
+ - Environment variables only
74
+ - Limited customization options
75
+ - No persistent configuration storage
76
+
77
+ #### TypeScript v2.0
78
+ - Configuration files with JSON Schema validation
79
+ - Project-specific overrides
80
+ - Rich customization options
81
+ - Multiple config formats (JSON/YAML)
82
+
83
+ ### Platform Compatibility
84
+
85
+ #### Bash v1.0
86
+ - ✅ Linux
87
+ - ✅ macOS
88
+ - ❌ Windows (requires WSL)
89
+ - ❌ Limited Windows Subsystem support
90
+
91
+ #### TypeScript v2.0
92
+ - ✅ Linux
93
+ - ✅ macOS
94
+ - ✅ Windows (native)
95
+ - ✅ Cross-platform Node.js runtime
96
+
97
+ ### Distribution Methods
98
+
99
+ #### Bash v1.0
100
+ - Manual download from GitHub releases
101
+ - Direct script execution
102
+ - Self-contained bash script
103
+
104
+ #### TypeScript v2.0
105
+ - npm registry (`npm install -g claude-statusline`)
106
+ - bun package manager (`bun install -g claude-statusline`)
107
+ - GitHub releases (compiled binaries)
108
+
109
+ ### Development & Debugging
110
+
111
+ #### Bash v1.0
112
+ - Manual debugging with `bash -x`
113
+ - Basic logging capabilities
114
+ - Limited tooling support
115
+
116
+ #### TypeScript v2.0
117
+ - Built-in debugging options (`debugWidth`)
118
+ - Comprehensive test suite
119
+ - VS Code integration via JSON Schema
120
+ - TypeScript development experience
121
+
122
+ ## Migration Decision Guide
123
+
124
+ ### Stay with Bash v1.0 if:
125
+ - ✅ You need maximum stability
126
+ - ✅ You prefer bash-only solutions
127
+ - ✅ You're on Linux/macOS only
128
+ - ✅ You want minimal dependencies
129
+ - ✅ You're comfortable with environment variables
130
+
131
+ ### Upgrade to TypeScript v2.0 if:
132
+ - ✅ You need Windows support
133
+ - ✅ You want configuration files
134
+ - ✅ You prefer npm package management
135
+ - ✅ You want better performance
136
+ - ✅ You need advanced customization
137
+ - ✅ You want TypeScript development tools
138
+
139
+ ### Gradual Migration Path:
140
+ 1. **Install TypeScript v2.0** alongside bash v1.0
141
+ 2. **Copy your environment variables** to a config file
142
+ 3. **Test with your current workflow**
143
+ 4. **Switch when ready**
144
+
145
+ ## Performance Benchmarks
146
+
147
+ Based on typical usage scenarios:
148
+
149
+ | Scenario | Bash v1.0 | TypeScript v2.0 | Improvement |
150
+ |----------|-----------|------------------|-------------|
151
+ | **Cold start** | 888ms | 45ms | **19.5x faster** |
152
+ | **Warm start** | 99ms | 30ms | **3.3x faster** |
153
+ | **No git status** | 37ms | 15ms | **2.5x faster** |
154
+ | **Environment context** | 77ms | 25ms | **3.1x faster** |
155
+
156
+ ## Compatibility Matrix
157
+
158
+ | Use Case | Bash v1.0 | TypeScript v2.0 | Recommendation |
159
+ |---------|-----------|------------------|----------------|
160
+ | **Linux CLI user** | ✅ Perfect | ✅ Perfect | Either works |
161
+ | **macOS CLI user** | ✅ Perfect | ✅ Perfect | Either works |
162
+ | **Windows user** | ❌ No support | ✅ Perfect | **Use v2.0** |
163
+ | **npm/bun user** | ❌ Manual install | ✅ Native install | **Use v2.0** |
164
+ | **Configuration files** | ❌ Not supported | ✅ Full support | **Use v2.0** |
165
+ | **Minimal dependencies** | ✅ Bash only | ✅ Node.js only | Either works |
166
+ | **Maximum performance** | ✅ Good | ✅ Excellent | **Prefer v2.0** |
167
+
168
+ ## Summary
169
+
170
+ **TypeScript v2.0 represents a significant evolution** while maintaining full backward compatibility with the core features that made bash v1.0 successful. The main advantages are:
171
+
172
+ - **19.5x performance improvement** on cold start
173
+ - **Native Windows support**
174
+ - **Modern configuration system**
175
+ - **Package manager integration**
176
+ - **Enhanced development experience**
177
+
178
+ **Bash v1.0 remains viable** for users who prefer maximum stability and minimal dependencies on Unix-like systems.