@lattices/cli 0.4.13 → 0.5.0

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 (180) hide show
  1. package/README.md +5 -7
  2. package/apps/mac/Info.plist +2 -2
  3. package/apps/mac/Lattices.app/Contents/Info.plist +4 -12
  4. package/apps/mac/Lattices.app/Contents/MacOS/Lattices +0 -0
  5. package/bin/lattices-app.ts +110 -17
  6. package/bin/lattices-build +125 -0
  7. package/bin/lattices-dev +89 -16
  8. package/bin/lattices.ts +977 -16
  9. package/docs/agents.md +81 -4
  10. package/docs/ai-chat-ux-review.md +416 -0
  11. package/docs/api.md +135 -3
  12. package/docs/app.md +30 -8
  13. package/docs/config.md +4 -0
  14. package/docs/mouse-gestures.md +191 -63
  15. package/docs/proposals/LAT-004-interactive-overlay-actors.md +1 -1
  16. package/docs/proposals/LAT-005-action-runtime-product-spine.md +914 -0
  17. package/docs/proposals/LAT-006-mira-in-lattices.md +553 -0
  18. package/docs/reference/dewey.config.ts +2 -2
  19. package/docs/release.md +171 -0
  20. package/docs/repo-structure.md +4 -5
  21. package/docs/voice.md +11 -27
  22. package/package.json +9 -10
  23. package/apps/mac/Package.swift +0 -27
  24. package/apps/mac/Sources/AppShell/App.swift +0 -26
  25. package/apps/mac/Sources/AppShell/AppActivationCoordinator.swift +0 -27
  26. package/apps/mac/Sources/AppShell/AppDelegate.swift +0 -189
  27. package/apps/mac/Sources/AppShell/AppServicesBootstrap.swift +0 -25
  28. package/apps/mac/Sources/AppShell/AppShellView.swift +0 -171
  29. package/apps/mac/Sources/AppShell/AppUpdater.swift +0 -305
  30. package/apps/mac/Sources/AppShell/CliActionLauncher.swift +0 -50
  31. package/apps/mac/Sources/AppShell/HomeDashboardView.swift +0 -133
  32. package/apps/mac/Sources/AppShell/HotkeyBootstrap.swift +0 -87
  33. package/apps/mac/Sources/AppShell/KeyRecorderView.swift +0 -210
  34. package/apps/mac/Sources/AppShell/LatticesRuntime.swift +0 -104
  35. package/apps/mac/Sources/AppShell/MainView.swift +0 -847
  36. package/apps/mac/Sources/AppShell/MainWindow.swift +0 -83
  37. package/apps/mac/Sources/AppShell/MenuBarController.swift +0 -177
  38. package/apps/mac/Sources/AppShell/OnboardingView.swift +0 -483
  39. package/apps/mac/Sources/AppShell/PermissionsAssistantView.swift +0 -366
  40. package/apps/mac/Sources/AppShell/PermissionsAssistantWindow.swift +0 -70
  41. package/apps/mac/Sources/AppShell/Preferences.swift +0 -297
  42. package/apps/mac/Sources/AppShell/SettingsView.swift +0 -3163
  43. package/apps/mac/Sources/AppShell/SettingsWindow.swift +0 -34
  44. package/apps/mac/Sources/AppShell/WorkspaceInspectorPresenter.swift +0 -13
  45. package/apps/mac/Sources/Core/Actions/HotkeyManager.swift +0 -256
  46. package/apps/mac/Sources/Core/Actions/HotkeyStore.swift +0 -399
  47. package/apps/mac/Sources/Core/Actions/IntentEngine.swift +0 -988
  48. package/apps/mac/Sources/Core/Actions/IntentSchema.swift +0 -94
  49. package/apps/mac/Sources/Core/Actions/Intents/CreateLayerIntent.swift +0 -54
  50. package/apps/mac/Sources/Core/Actions/Intents/DistributeIntent.swift +0 -56
  51. package/apps/mac/Sources/Core/Actions/Intents/FocusIntent.swift +0 -69
  52. package/apps/mac/Sources/Core/Actions/Intents/HelpIntent.swift +0 -41
  53. package/apps/mac/Sources/Core/Actions/Intents/KillIntent.swift +0 -47
  54. package/apps/mac/Sources/Core/Actions/Intents/LatticeIntent.swift +0 -53
  55. package/apps/mac/Sources/Core/Actions/Intents/LaunchIntent.swift +0 -67
  56. package/apps/mac/Sources/Core/Actions/Intents/ListSessionsIntent.swift +0 -32
  57. package/apps/mac/Sources/Core/Actions/Intents/ListWindowsIntent.swift +0 -30
  58. package/apps/mac/Sources/Core/Actions/Intents/ScanIntent.swift +0 -52
  59. package/apps/mac/Sources/Core/Actions/Intents/SearchIntent.swift +0 -190
  60. package/apps/mac/Sources/Core/Actions/Intents/SwitchLayerIntent.swift +0 -50
  61. package/apps/mac/Sources/Core/Actions/Intents/TileIntent.swift +0 -61
  62. package/apps/mac/Sources/Core/Actions/PaletteCommand.swift +0 -439
  63. package/apps/mac/Sources/Core/Actions/VoiceIntentResolver.swift +0 -713
  64. package/apps/mac/Sources/Core/Companion/CompanionActivityLog.swift +0 -70
  65. package/apps/mac/Sources/Core/Companion/CompanionKeyboardController.swift +0 -141
  66. package/apps/mac/Sources/Core/Companion/LatticesCompanionBridgeServer.swift +0 -454
  67. package/apps/mac/Sources/Core/Companion/LatticesCompanionCockpit.swift +0 -555
  68. package/apps/mac/Sources/Core/Companion/LatticesCompanionSecurityCoordinator.swift +0 -629
  69. package/apps/mac/Sources/Core/Companion/LatticesCompanionTrackpadController.swift +0 -204
  70. package/apps/mac/Sources/Core/Companion/LatticesDeckHost.swift +0 -1463
  71. package/apps/mac/Sources/Core/Daemon/DaemonProtocol.swift +0 -114
  72. package/apps/mac/Sources/Core/Daemon/DaemonServer.swift +0 -427
  73. package/apps/mac/Sources/Core/Daemon/LatticesApi.swift +0 -2965
  74. package/apps/mac/Sources/Core/Desktop/AccessibilityTextExtractor.swift +0 -111
  75. package/apps/mac/Sources/Core/Desktop/AppTypeClassifier.swift +0 -106
  76. package/apps/mac/Sources/Core/Desktop/DesktopModel.swift +0 -331
  77. package/apps/mac/Sources/Core/Desktop/DesktopModelTypes.swift +0 -73
  78. package/apps/mac/Sources/Core/Desktop/InventoryManager.swift +0 -35
  79. package/apps/mac/Sources/Core/Desktop/InventoryPath.swift +0 -43
  80. package/apps/mac/Sources/Core/Desktop/MouseFinder.swift +0 -527
  81. package/apps/mac/Sources/Core/Desktop/OcrModel.swift +0 -467
  82. package/apps/mac/Sources/Core/Desktop/OcrStore.swift +0 -329
  83. package/apps/mac/Sources/Core/Desktop/PlacementSpec.swift +0 -195
  84. package/apps/mac/Sources/Core/Desktop/SessionWindowLocator.swift +0 -139
  85. package/apps/mac/Sources/Core/Desktop/TilePickerView.swift +0 -209
  86. package/apps/mac/Sources/Core/Desktop/WindowCapture.swift +0 -33
  87. package/apps/mac/Sources/Core/Desktop/WindowDragSnapController.swift +0 -429
  88. package/apps/mac/Sources/Core/Desktop/WindowPreviewCard.swift +0 -100
  89. package/apps/mac/Sources/Core/Desktop/WindowPreviewStore.swift +0 -112
  90. package/apps/mac/Sources/Core/Desktop/WindowSelectionStore.swift +0 -76
  91. package/apps/mac/Sources/Core/Desktop/WindowTiler.swift +0 -2222
  92. package/apps/mac/Sources/Core/Input/EventTapBreaker.swift +0 -124
  93. package/apps/mac/Sources/Core/Input/EventTapThread.swift +0 -54
  94. package/apps/mac/Sources/Core/Input/InputCaptureResetCenter.swift +0 -20
  95. package/apps/mac/Sources/Core/Input/KeyboardRemapConfig.swift +0 -69
  96. package/apps/mac/Sources/Core/Input/KeyboardRemapController.swift +0 -346
  97. package/apps/mac/Sources/Core/Input/KeyboardRemapStore.swift +0 -141
  98. package/apps/mac/Sources/Core/Input/MouseGestureConfig.swift +0 -499
  99. package/apps/mac/Sources/Core/Input/MouseGestureController.swift +0 -2271
  100. package/apps/mac/Sources/Core/Input/MouseInputDeviceStore.swift +0 -98
  101. package/apps/mac/Sources/Core/Input/MouseInputEventViewer.swift +0 -272
  102. package/apps/mac/Sources/Core/Input/MouseShortcutStore.swift +0 -170
  103. package/apps/mac/Sources/Core/Input/SecureEventInputMonitor.swift +0 -39
  104. package/apps/mac/Sources/Core/Input/ShapeRecognizer.swift +0 -624
  105. package/apps/mac/Sources/Core/Input/TapBudgetMeter.swift +0 -56
  106. package/apps/mac/Sources/Core/Overlays/AppWindowShell.swift +0 -63
  107. package/apps/mac/Sources/Core/Overlays/CommandMode/CommandModeState.swift +0 -1566
  108. package/apps/mac/Sources/Core/Overlays/CommandMode/CommandModeView.swift +0 -1927
  109. package/apps/mac/Sources/Core/Overlays/CommandMode/CommandModeWindow.swift +0 -196
  110. package/apps/mac/Sources/Core/Overlays/CommandPalette/CommandPaletteView.swift +0 -307
  111. package/apps/mac/Sources/Core/Overlays/CommandPalette/CommandPaletteWindow.swift +0 -67
  112. package/apps/mac/Sources/Core/Overlays/HUD/CheatSheetHUD.swift +0 -576
  113. package/apps/mac/Sources/Core/Overlays/HUD/HUDBottomBar.swift +0 -279
  114. package/apps/mac/Sources/Core/Overlays/HUD/HUDController.swift +0 -1158
  115. package/apps/mac/Sources/Core/Overlays/HUD/HUDLeftBar.swift +0 -849
  116. package/apps/mac/Sources/Core/Overlays/HUD/HUDMinimap.swift +0 -179
  117. package/apps/mac/Sources/Core/Overlays/HUD/HUDRightBar.swift +0 -596
  118. package/apps/mac/Sources/Core/Overlays/HUD/HUDState.swift +0 -367
  119. package/apps/mac/Sources/Core/Overlays/HUD/HUDTopBar.swift +0 -243
  120. package/apps/mac/Sources/Core/Overlays/HUD/LauncherHUD.swift +0 -334
  121. package/apps/mac/Sources/Core/Overlays/HUD/LayerBezel.swift +0 -203
  122. package/apps/mac/Sources/Core/Overlays/OmniSearch/OmniSearchState.swift +0 -280
  123. package/apps/mac/Sources/Core/Overlays/OmniSearch/OmniSearchView.swift +0 -422
  124. package/apps/mac/Sources/Core/Overlays/OmniSearch/OmniSearchWindow.swift +0 -94
  125. package/apps/mac/Sources/Core/Overlays/OverlayPanelShell.swift +0 -241
  126. package/apps/mac/Sources/Core/Overlays/ScreenMap/ScreenMapState.swift +0 -3135
  127. package/apps/mac/Sources/Core/Overlays/ScreenMap/ScreenMapView.swift +0 -3977
  128. package/apps/mac/Sources/Core/Overlays/ScreenMap/ScreenMapWindowController.swift +0 -119
  129. package/apps/mac/Sources/Core/Overlays/ScreenOverlayCanvasController.swift +0 -1217
  130. package/apps/mac/Sources/Core/Overlays/Voice/VoiceCommandWindow.swift +0 -1575
  131. package/apps/mac/Sources/Core/Pi/PiAuthNextStepCard.swift +0 -148
  132. package/apps/mac/Sources/Core/Pi/PiAuthPromptCard.swift +0 -90
  133. package/apps/mac/Sources/Core/Pi/PiChatDock.swift +0 -564
  134. package/apps/mac/Sources/Core/Pi/PiChatSession.swift +0 -1948
  135. package/apps/mac/Sources/Core/Pi/PiInstallCallout.swift +0 -86
  136. package/apps/mac/Sources/Core/Pi/PiProviderSetupCallout.swift +0 -99
  137. package/apps/mac/Sources/Core/Pi/PiWorkspaceView.swift +0 -510
  138. package/apps/mac/Sources/Core/System/Capability.swift +0 -79
  139. package/apps/mac/Sources/Core/System/DiagnosticLog.swift +0 -373
  140. package/apps/mac/Sources/Core/System/EventBus.swift +0 -31
  141. package/apps/mac/Sources/Core/System/PermissionChecker.swift +0 -224
  142. package/apps/mac/Sources/Core/System/ProcessModel.swift +0 -199
  143. package/apps/mac/Sources/Core/System/ProcessQuery.swift +0 -151
  144. package/apps/mac/Sources/Core/System/SystemTelemetryMonitor.swift +0 -273
  145. package/apps/mac/Sources/Core/Voice/AdvisorLearningStore.swift +0 -90
  146. package/apps/mac/Sources/Core/Voice/AgentSession.swift +0 -377
  147. package/apps/mac/Sources/Core/Voice/AudioProvider.swift +0 -555
  148. package/apps/mac/Sources/Core/Voice/HandsOffSession.swift +0 -839
  149. package/apps/mac/Sources/Core/Voice/VoiceChatView.swift +0 -192
  150. package/apps/mac/Sources/Core/Voice/VoxClient.swift +0 -454
  151. package/apps/mac/Sources/Core/Workspace/Project.swift +0 -28
  152. package/apps/mac/Sources/Core/Workspace/ProjectScanner.swift +0 -141
  153. package/apps/mac/Sources/Core/Workspace/SessionLayerStore.swift +0 -285
  154. package/apps/mac/Sources/Core/Workspace/SessionManager.swift +0 -75
  155. package/apps/mac/Sources/Core/Workspace/Terminal/Terminal.swift +0 -259
  156. package/apps/mac/Sources/Core/Workspace/Terminal/TerminalQuery.swift +0 -156
  157. package/apps/mac/Sources/Core/Workspace/Terminal/TerminalSynthesizer.swift +0 -200
  158. package/apps/mac/Sources/Core/Workspace/Tmux/TmuxModel.swift +0 -60
  159. package/apps/mac/Sources/Core/Workspace/Tmux/TmuxQuery.swift +0 -105
  160. package/apps/mac/Sources/Core/Workspace/WorkspaceManager.swift +0 -1027
  161. package/apps/mac/Sources/UI/ActionRow.swift +0 -78
  162. package/apps/mac/Sources/UI/OrphanRow.swift +0 -129
  163. package/apps/mac/Sources/UI/ProjectRow.swift +0 -368
  164. package/apps/mac/Sources/UI/TabGroupRow.swift +0 -178
  165. package/apps/mac/Sources/UI/Theme.swift +0 -164
  166. package/apps/mac/Tests/StageDragTests.swift +0 -333
  167. package/apps/mac/Tests/StageJoinTests.swift +0 -313
  168. package/apps/mac/Tests/StageManagerTests.swift +0 -280
  169. package/apps/mac/Tests/StageTileTests.swift +0 -353
  170. package/swift/Package.swift +0 -20
  171. package/swift/Sources/DeckKit/DeckAction.swift +0 -51
  172. package/swift/Sources/DeckKit/DeckBridgeSecurity.swift +0 -152
  173. package/swift/Sources/DeckKit/DeckCockpit.swift +0 -82
  174. package/swift/Sources/DeckKit/DeckHost.swift +0 -7
  175. package/swift/Sources/DeckKit/DeckManifest.swift +0 -145
  176. package/swift/Sources/DeckKit/DeckRuntimeSnapshot.swift +0 -533
  177. package/swift/Sources/DeckKit/DeckTrackpad.swift +0 -63
  178. package/swift/Sources/DeckKit/DeckValue.swift +0 -93
  179. package/swift/Sources/DeckKit/DeckVoiceError.swift +0 -88
  180. package/swift/Tests/DeckKitTests/DeckKitTests.swift +0 -286
@@ -1,273 +0,0 @@
1
- import DeckKit
2
- import Foundation
3
- import IOKit
4
- import IOKit.ps
5
-
6
- final class SystemTelemetryMonitor {
7
- static let shared = SystemTelemetryMonitor()
8
-
9
- private struct CPUTicks {
10
- var user: UInt64
11
- var system: UInt64
12
- var idle: UInt64
13
- var nice: UInt64
14
-
15
- var total: UInt64 {
16
- user + system + idle + nice
17
- }
18
- }
19
-
20
- private struct BatterySample {
21
- var percent: Double?
22
- var isCharging: Bool?
23
- var powerSource: String?
24
- }
25
-
26
- private struct CoreSample {
27
- var sampledAt: Date
28
- var cpuLoadPercent: Double?
29
- var memoryUsedPercent: Double?
30
- var gpuLoadPercent: Double?
31
- var thermalPressurePercent: Double?
32
- var thermalState: DeckThermalState?
33
- var temperatureCelsius: Double?
34
- var batteryPercent: Double?
35
- var isCharging: Bool?
36
- var powerSource: String?
37
- }
38
-
39
- private let lock = NSLock()
40
- private var previousCPUTicks: [CPUTicks]?
41
- private var cachedSample: CoreSample?
42
- private var cachedAt: Date = .distantPast
43
- private let minSampleInterval: TimeInterval = 0.8
44
-
45
- private init() {}
46
-
47
- func snapshot(windowCount: Int, sessionCount: Int) -> DeckSystemTelemetry {
48
- let core = currentCoreSample()
49
- return DeckSystemTelemetry(
50
- sampledAt: core.sampledAt,
51
- cpuLoadPercent: core.cpuLoadPercent,
52
- memoryUsedPercent: core.memoryUsedPercent,
53
- gpuLoadPercent: core.gpuLoadPercent,
54
- thermalPressurePercent: core.thermalPressurePercent,
55
- thermalState: core.thermalState,
56
- temperatureCelsius: core.temperatureCelsius,
57
- batteryPercent: core.batteryPercent,
58
- isCharging: core.isCharging,
59
- powerSource: core.powerSource,
60
- windowCount: windowCount,
61
- sessionCount: sessionCount
62
- )
63
- }
64
- }
65
-
66
- private extension SystemTelemetryMonitor {
67
- private func currentCoreSample() -> CoreSample {
68
- lock.lock()
69
- defer { lock.unlock() }
70
-
71
- let now = Date()
72
- if let cachedSample, now.timeIntervalSince(cachedAt) < minSampleInterval {
73
- return cachedSample
74
- }
75
-
76
- let thermal = readThermalState()
77
- let battery = readBattery()
78
- let sample = CoreSample(
79
- sampledAt: now,
80
- cpuLoadPercent: readCPULoadPercent(),
81
- memoryUsedPercent: readMemoryUsedPercent(),
82
- gpuLoadPercent: readGPULoadPercent(),
83
- thermalPressurePercent: thermal.pressure,
84
- thermalState: thermal.state,
85
- temperatureCelsius: nil,
86
- batteryPercent: battery.percent,
87
- isCharging: battery.isCharging,
88
- powerSource: battery.powerSource
89
- )
90
- cachedSample = sample
91
- cachedAt = now
92
- return sample
93
- }
94
-
95
- func readCPULoadPercent() -> Double? {
96
- var cpuInfo: processor_info_array_t?
97
- var processorCount: natural_t = 0
98
- var infoCount: mach_msg_type_number_t = 0
99
-
100
- let result = host_processor_info(
101
- mach_host_self(),
102
- PROCESSOR_CPU_LOAD_INFO,
103
- &processorCount,
104
- &cpuInfo,
105
- &infoCount
106
- )
107
- guard result == KERN_SUCCESS, let cpuInfo else {
108
- return nil
109
- }
110
-
111
- defer {
112
- let size = vm_size_t(Int(infoCount) * MemoryLayout<integer_t>.stride)
113
- vm_deallocate(mach_task_self_, vm_address_t(UInt(bitPattern: cpuInfo)), size)
114
- }
115
-
116
- let statesPerCPU = Int(CPU_STATE_MAX)
117
- let info = UnsafeBufferPointer(start: cpuInfo, count: Int(infoCount))
118
- let ticks: [CPUTicks] = (0..<Int(processorCount)).map { index in
119
- let offset = index * statesPerCPU
120
- return CPUTicks(
121
- user: cpuTick(info[offset + Int(CPU_STATE_USER)]),
122
- system: cpuTick(info[offset + Int(CPU_STATE_SYSTEM)]),
123
- idle: cpuTick(info[offset + Int(CPU_STATE_IDLE)]),
124
- nice: cpuTick(info[offset + Int(CPU_STATE_NICE)])
125
- )
126
- }
127
-
128
- guard !ticks.isEmpty else { return nil }
129
-
130
- defer { previousCPUTicks = ticks }
131
-
132
- guard let previousCPUTicks, previousCPUTicks.count == ticks.count else {
133
- let total = ticks.reduce(UInt64(0)) { $0 + $1.total }
134
- let idle = ticks.reduce(UInt64(0)) { $0 + $1.idle }
135
- guard total > 0 else { return nil }
136
- return clampPercent(100.0 * Double(total - idle) / Double(total))
137
- }
138
-
139
- var busyDelta: UInt64 = 0
140
- var totalDelta: UInt64 = 0
141
- for (current, previous) in zip(ticks, previousCPUTicks) {
142
- let total = current.total.saturatingSubtract(previous.total)
143
- let idle = current.idle.saturatingSubtract(previous.idle)
144
- totalDelta += total
145
- busyDelta += total.saturatingSubtract(idle)
146
- }
147
-
148
- guard totalDelta > 0 else { return nil }
149
- return clampPercent(100.0 * Double(busyDelta) / Double(totalDelta))
150
- }
151
-
152
- func readMemoryUsedPercent() -> Double? {
153
- var stats = vm_statistics64()
154
- var count = mach_msg_type_number_t(MemoryLayout<vm_statistics64_data_t>.stride / MemoryLayout<integer_t>.stride)
155
-
156
- let result = withUnsafeMutablePointer(to: &stats) {
157
- $0.withMemoryRebound(to: integer_t.self, capacity: Int(count)) {
158
- host_statistics64(mach_host_self(), HOST_VM_INFO64, $0, &count)
159
- }
160
- }
161
- guard result == KERN_SUCCESS else { return nil }
162
-
163
- var pageSize = vm_size_t()
164
- host_page_size(mach_host_self(), &pageSize)
165
-
166
- let freePages = UInt64(stats.free_count) + UInt64(stats.speculative_count)
167
- let freeBytes = freePages * UInt64(pageSize)
168
- let totalBytes = ProcessInfo.processInfo.physicalMemory
169
- guard totalBytes > 0 else { return nil }
170
-
171
- let usedBytes = totalBytes > freeBytes ? totalBytes - freeBytes : 0
172
- return clampPercent(100.0 * Double(usedBytes) / Double(totalBytes))
173
- }
174
-
175
- func readGPULoadPercent() -> Double? {
176
- guard let matching = IOServiceMatching("IOAccelerator") else {
177
- return nil
178
- }
179
-
180
- var iterator: io_iterator_t = 0
181
- guard IOServiceGetMatchingServices(kIOMainPortDefault, matching, &iterator) == KERN_SUCCESS else {
182
- return nil
183
- }
184
- defer { IOObjectRelease(iterator) }
185
-
186
- var values: [Double] = []
187
- while true {
188
- let service = IOIteratorNext(iterator)
189
- if service == 0 { break }
190
- defer { IOObjectRelease(service) }
191
-
192
- guard let unmanaged = IORegistryEntryCreateCFProperty(
193
- service,
194
- "PerformanceStatistics" as CFString,
195
- kCFAllocatorDefault,
196
- 0
197
- ) else {
198
- continue
199
- }
200
-
201
- guard let stats = unmanaged.takeRetainedValue() as? [String: Any] else {
202
- continue
203
- }
204
-
205
- for key in ["Device Utilization %", "Renderer Utilization %"] {
206
- if let number = stats[key] as? NSNumber {
207
- values.append(number.doubleValue)
208
- }
209
- }
210
- }
211
-
212
- guard !values.isEmpty else { return nil }
213
- return clampPercent(values.reduce(0, +) / Double(values.count))
214
- }
215
-
216
- func readThermalState() -> (state: DeckThermalState, pressure: Double) {
217
- switch ProcessInfo.processInfo.thermalState {
218
- case .nominal:
219
- return (.nominal, 10)
220
- case .fair:
221
- return (.fair, 35)
222
- case .serious:
223
- return (.serious, 70)
224
- case .critical:
225
- return (.critical, 100)
226
- @unknown default:
227
- return (.nominal, 10)
228
- }
229
- }
230
-
231
- private func readBattery() -> BatterySample {
232
- let powerInfo = IOPSCopyPowerSourcesInfo().takeRetainedValue()
233
- let sourceList = IOPSCopyPowerSourcesList(powerInfo).takeRetainedValue() as [CFTypeRef]
234
-
235
- for source in sourceList {
236
- guard let description = IOPSGetPowerSourceDescription(powerInfo, source)?
237
- .takeUnretainedValue() as? [String: Any] else {
238
- continue
239
- }
240
-
241
- let current = description[kIOPSCurrentCapacityKey] as? Int
242
- let max = description[kIOPSMaxCapacityKey] as? Int
243
- let percent = current.flatMap { current in
244
- max.flatMap { maxValue -> Double? in
245
- guard maxValue > 0 else { return nil }
246
- return clampPercent(100.0 * Double(current) / Double(maxValue))
247
- }
248
- }
249
-
250
- return BatterySample(
251
- percent: percent,
252
- isCharging: description[kIOPSIsChargingKey] as? Bool,
253
- powerSource: description[kIOPSPowerSourceStateKey] as? String
254
- )
255
- }
256
-
257
- return BatterySample(percent: nil, isCharging: nil, powerSource: nil)
258
- }
259
-
260
- func clampPercent(_ value: Double) -> Double {
261
- max(0, min(100, value))
262
- }
263
-
264
- func cpuTick(_ value: integer_t) -> UInt64 {
265
- UInt64(UInt32(bitPattern: value))
266
- }
267
- }
268
-
269
- private extension UInt64 {
270
- func saturatingSubtract(_ other: UInt64) -> UInt64 {
271
- self > other ? self - other : 0
272
- }
273
- }
@@ -1,90 +0,0 @@
1
- import Foundation
2
-
3
- /// Captures moments where the Claude advisor resolved something the local matcher couldn't.
4
- /// Each entry records the transcript, what the local system matched (or missed), and what
5
- /// the advisor suggested that the user accepted.
6
- ///
7
- /// For now this is append-only — just growing the dataset. Future work can use it to
8
- /// improve local matching without needing the advisor.
9
-
10
- final class AdvisorLearningStore {
11
- static let shared = AdvisorLearningStore()
12
-
13
- struct Entry: Codable {
14
- let timestamp: String
15
- let transcript: String
16
- let localIntent: String?
17
- let localSlots: [String: String]
18
- let localResultCount: Int
19
- let advisorIntent: String
20
- let advisorSlots: [String: String]
21
- let advisorLabel: String
22
- }
23
-
24
- private let fileURL: URL
25
- private let queue = DispatchQueue(label: "com.lattices.advisor-learning")
26
- private static let isoFmt: ISO8601DateFormatter = {
27
- let f = ISO8601DateFormatter()
28
- f.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
29
- return f
30
- }()
31
-
32
- private init() {
33
- let dir = FileManager.default.homeDirectoryForCurrentUser
34
- .appendingPathComponent(".lattices")
35
- try? FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
36
- fileURL = dir.appendingPathComponent("advisor-learning.jsonl")
37
- }
38
-
39
- /// Record that the user engaged with an advisor suggestion.
40
- func record(
41
- transcript: String,
42
- localIntent: String?,
43
- localSlots: [String: String],
44
- localResultCount: Int,
45
- advisorIntent: String,
46
- advisorSlots: [String: String],
47
- advisorLabel: String
48
- ) {
49
- let entry = Entry(
50
- timestamp: Self.isoFmt.string(from: Date()),
51
- transcript: transcript,
52
- localIntent: localIntent,
53
- localSlots: localSlots,
54
- localResultCount: localResultCount,
55
- advisorIntent: advisorIntent,
56
- advisorSlots: advisorSlots,
57
- advisorLabel: advisorLabel
58
- )
59
-
60
- queue.async {
61
- guard let data = try? JSONEncoder().encode(entry),
62
- var line = String(data: data, encoding: .utf8) else { return }
63
- line += "\n"
64
-
65
- if let handle = try? FileHandle(forWritingTo: self.fileURL) {
66
- handle.seekToEndOfFile()
67
- handle.write(line.data(using: .utf8)!)
68
- handle.closeFile()
69
- } else {
70
- try? line.data(using: .utf8)?.write(to: self.fileURL)
71
- }
72
-
73
- DiagnosticLog.shared.info("AdvisorLearning: captured [\(transcript)] → \(advisorIntent)(\(advisorSlots))")
74
- }
75
- }
76
-
77
- /// Read all entries (for analysis).
78
- func allEntries() -> [Entry] {
79
- guard let data = try? String(contentsOf: fileURL, encoding: .utf8) else { return [] }
80
- return data.components(separatedBy: "\n").compactMap { line in
81
- guard !line.isEmpty, let d = line.data(using: .utf8) else { return nil }
82
- return try? JSONDecoder().decode(Entry.self, from: d)
83
- }
84
- }
85
-
86
- var entryCount: Int {
87
- guard let data = try? String(contentsOf: fileURL, encoding: .utf8) else { return 0 }
88
- return data.components(separatedBy: "\n").filter { !$0.isEmpty }.count
89
- }
90
- }