Skip to content

Latest commit

 

History

History
94 lines (74 loc) · 2.7 KB

File metadata and controls

94 lines (74 loc) · 2.7 KB

CLAUDE.md

This file provides guidance for Claude when working with the JKiller codebase.

Project Overview

JKiller is a macOS menu bar application for managing system resources. It allows users to kill resource-hungry processes and clean up disk space.

Tech Stack

  • Language: Swift 5
  • UI Framework: SwiftUI
  • Platform: macOS 13.0+
  • Architecture: MVVM-like with ObservableObject monitors

Project Structure

JKiller/
├── JKiller/
│   ├── JKillerApp.swift          # App entry point, creates monitors
│   ├── Info.plist                # App configuration
│   ├── Services/
│   │   ├── MemoryMonitor.swift       # System memory tracking
│   │   ├── ProcessMemoryMonitor.swift # Per-process memory tracking
│   │   ├── DiskMonitor.swift         # Disk usage monitoring
│   │   ├── DiskCleaner.swift         # Disk cleanup operations
│   │   └── ProcessKiller.swift       # Process termination
│   └── Views/
│       └── MenuBarView.swift     # Main UI
├── JKillerTests/                 # Unit tests
└── JKiller.xcodeproj/

Build Commands

# Build the app
xcodebuild -scheme JKiller -configuration Debug build

# Run tests
xcodebuild -scheme JKillerTests -destination 'platform=macOS' test

Key Patterns

Monitors (ObservableObject)

All monitors follow the same pattern:

  • Initialize with current values
  • Start a Timer for periodic updates
  • Use @Published properties for SwiftUI binding
  • Heavy work runs on background queue, UI updates on main queue

Process Execution

When running shell commands (ps, du, pkill):

  • Always read pipe data BEFORE calling waitUntilExit() to avoid deadlocks
  • Use DispatchQueue.global(qos:) for background work

Example:

let process = Process()
let pipe = Pipe()
process.standardOutput = pipe
try process.run()
let data = pipe.fileHandleForReading.readDataToEndOfFile()  // Read first!
process.waitUntilExit()  // Then wait

Testing

Tests are in JKillerTests/. Each monitor/service has corresponding tests:

  • MemoryMonitorTests.swift
  • ProcessMemoryMonitorTests.swift
  • DiskMonitorTests.swift
  • DiskCleanerTests.swift

Tests verify:

  • Initial values are valid
  • Formatted output contains expected units (KB/MB/GB)
  • Async updates work correctly

Common Tasks

Adding a new process category to kill

  1. Add pattern to ProcessKiller.swift
  2. Add memory tracking in ProcessMemoryMonitor.swift
  3. Add button in MenuBarView.swift
  4. Add tests

Adding a new disk cleanup target

  1. Add path and methods to DiskCleaner.swift
  2. Add tracking to DiskMonitor.swift
  3. Add button in MenuBarView.swift
  4. Add tests