VPhone-CLI Manifest Implementation & Code Clarity Review
Historical snapshot. This document describes the earlier shell/Python manifest implementation. Those commands and files have since been replaced by the native Swift workflow. See the current VM guide and research index.
Summary
- Implemented VM manifest system compatible with security-pcc's VMBundle.Config format
- Cleaned up environment variables - removed unused
CFW_INPUT, documented remaining variables - Applied code-clarity framework to review and refactor core files
1. VM Manifest Implementation
Files Created
Sources/VPhoneCore/VPhoneVirtualMachineManifest.swift- Manifest structure (compatible with security-pcc)scripts/vm_manifest.py- Python script to generate config.plist
Changes Made
-
VPhoneVirtualMachineManifest.swift
- Structure mirrors security-pcc's
VMBundle.Config - Adds iPhone-specific configurations (screen, SEP storage)
- Simplified for single-purpose (virtual iPhone vs generic VM)
- Structure mirrors security-pcc's
-
vm_create.sh
- Now calls
vm_manifest.pyto generateconfig.plist - Accepts
CPUandMEMORYenvironment variables - Creates manifest at
[5/4]step
- Now calls
-
Makefile
vm_new: Passes CPU/MEMORY tovm_create.shboot/boot_dfu: Read from--config ./config.plistinstead of CLI args- Removed unused
CFW_INPUTvariable - Added documentation for remaining variables
-
VPhoneCLI.swift
- Added
--configoption to load manifest - CPU/memory/screen parameters now optional (overridden by manifest if provided)
resolveOptions()merges manifest with CLI overrides
- Added
-
VPhoneAppDelegate.swift
- Uses
resolveOptions()to load configuration - Removed direct CLI parameter access
- Uses
Manifest Structure
Compatibility with security-pcc
2. Code Clarity Review
VPhoneVirtualMachine.swift
Current Score: 6/10 → Target: 9/10
Issues Found:
- 200+ line init method - Violates single responsibility
- Mixed abstraction levels - Configuration logic mixed with low-level Dynamic API calls
- Unclear abbreviations:
hwModel→hardwareModelgfx→graphicsConfigurationafg→soundDevice(completely meaningless)net→networkDevice
- Magic numbers:
1=charging, 2=disconnected→ Should be enum - Missing early returns - Disk check should use guard
- Nested conditionals - Serial port configuration
Refactored Version Created
research/VPhoneVirtualMachineRefactored.swift demonstrates:
-
Extracted configuration methods:
-
Better naming:
-
Battery connectivity enum:
-
Clearer method names:
VPhoneCLI.swift
Current Score: 7/10 → Target: 9/10
Issues Fixed:
-
Variable shadowing - Local variables now use distinct names:
-
Manifest loading - Clean separation of concerns
VPhoneVirtualMachineManifest.swift
Current Score: 8/10 → Target: 9/10
Minor Issues:
-
Repetitive error handling - Can be extracted:
-
Method naming -
resolve(path:in:)could be clearer:
3. Environment Variable Cleanup
Removed Variables
Documented Variables
4. Usage Changes
Before
After
Override Manifest (Optional)
5. Next Steps
- Apply refactoring - Review
VPhoneVirtualMachineRefactored.swiftand apply to main file - Extend manifest - Consider adding:
- Kernel boot args configuration
- Debug stub port configuration
- Custom NVRAM variables
- Validate manifest - Add schema validation on load
- Migration path - For existing VMs without config.plist
6. Testing Checklist
-
make vm_newcreates config.plist -
make bootreads from config.plist - CLI overrides work:
vphone-cli --config ... --cpu 16 - Existing VMs without config.plist still work (backward compatibility)
- Manifest is valid plist and can be edited manually
- CPU/Memory/Screen settings are correctly applied from manifest