@lattices/cli 0.4.2 → 0.4.5
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.
- package/README.md +3 -0
- package/app/Info.plist +2 -2
- package/app/Lattices.app/Contents/Info.plist +2 -2
- package/app/Lattices.app/Contents/MacOS/Lattices +0 -0
- package/app/Package.swift +6 -0
- package/app/Sources/App.swift +10 -0
- package/app/Sources/AppDelegate.swift +90 -34
- package/app/Sources/AppShellView.swift +2 -0
- package/app/Sources/AppTypeClassifier.swift +36 -0
- package/app/Sources/AppUpdater.swift +92 -0
- package/app/Sources/CheatSheetHUD.swift +1 -0
- package/app/Sources/CliActionLauncher.swift +50 -0
- package/app/Sources/CommandModeView.swift +4 -24
- package/app/Sources/CompanionActivityLog.swift +70 -0
- package/app/Sources/CompanionKeyboardController.swift +141 -0
- package/app/Sources/DesktopModel.swift +4 -0
- package/app/Sources/HandsOffSession.swift +15 -4
- package/app/Sources/HomeDashboardView.swift +18 -10
- package/app/Sources/HotkeyStore.swift +8 -5
- package/app/Sources/IntentEngine.swift +7 -1
- package/app/Sources/LatticesApi.swift +125 -4
- package/app/Sources/LatticesCompanionBridgeServer.swift +438 -0
- package/app/Sources/LatticesCompanionCockpit.swift +555 -0
- package/app/Sources/LatticesCompanionSecurityCoordinator.swift +594 -0
- package/app/Sources/LatticesCompanionTrackpadController.swift +204 -0
- package/app/Sources/LatticesDeckHost.swift +1463 -0
- package/app/Sources/LatticesRuntime.swift +61 -0
- package/app/Sources/MainView.swift +351 -191
- package/app/Sources/MouseFinder.swift +335 -30
- package/app/Sources/MouseGestureConfig.swift +364 -0
- package/app/Sources/MouseGestureController.swift +1203 -0
- package/app/Sources/MouseInputDeviceStore.swift +98 -0
- package/app/Sources/MouseInputEventViewer.swift +272 -0
- package/app/Sources/MouseShortcutStore.swift +107 -0
- package/app/Sources/OmniSearchView.swift +136 -2
- package/app/Sources/OmniSearchWindow.swift +65 -5
- package/app/Sources/OnboardingView.swift +30 -16
- package/app/Sources/PaletteCommand.swift +26 -6
- package/app/Sources/PermissionChecker.swift +76 -2
- package/app/Sources/PiAuthNextStepCard.swift +148 -0
- package/app/Sources/PiAuthPromptCard.swift +90 -0
- package/app/Sources/PiChatDock.swift +137 -74
- package/app/Sources/PiChatSession.swift +608 -108
- package/app/Sources/PiInstallCallout.swift +86 -0
- package/app/Sources/PiProviderSetupCallout.swift +99 -0
- package/app/Sources/PiWorkspaceView.swift +174 -77
- package/app/Sources/Preferences.swift +78 -0
- package/app/Sources/ScreenMapState.swift +91 -31
- package/app/Sources/ScreenMapView.swift +510 -524
- package/app/Sources/ScreenMapWindowController.swift +12 -4
- package/app/Sources/SettingsView.swift +869 -152
- package/app/Sources/SystemTelemetryMonitor.swift +273 -0
- package/app/Sources/VoiceCommandWindow.swift +23 -2
- package/app/Sources/WindowDragSnapController.swift +628 -0
- package/app/Sources/WindowTiler.swift +328 -65
- package/app/Sources/WorkspaceManager.swift +288 -0
- package/bin/assistant-intelligence.ts +874 -0
- package/bin/handsoff-infer.ts +16 -209
- package/bin/handsoff-worker.ts +45 -258
- package/bin/lattices-app.ts +62 -0
- package/bin/lattices-dev +4 -0
- package/bin/lattices.ts +125 -14
- package/docs/agents.md +14 -0
- package/docs/api.md +55 -0
- package/docs/app.md +3 -0
- package/docs/companion-deck.md +180 -0
- package/docs/config.md +25 -0
- package/docs/tiling-reference.md +55 -0
- package/docs/voice-error-model.md +73 -0
- package/package.json +2 -1
|
@@ -0,0 +1,273 @@
|
|
|
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
|
+
}
|
|
@@ -9,6 +9,19 @@ final class VoicePanel: NSPanel {
|
|
|
9
9
|
var onFlagsChanged: ((NSEvent) -> Void)?
|
|
10
10
|
|
|
11
11
|
override var canBecomeKey: Bool { true }
|
|
12
|
+
override var canBecomeMain: Bool { true }
|
|
13
|
+
|
|
14
|
+
override func sendEvent(_ event: NSEvent) {
|
|
15
|
+
if event.type == .leftMouseDown || event.type == .rightMouseDown {
|
|
16
|
+
if !NSApp.isActive {
|
|
17
|
+
NSApp.activate(ignoringOtherApps: true)
|
|
18
|
+
}
|
|
19
|
+
if !isKeyWindow {
|
|
20
|
+
makeKey()
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
super.sendEvent(event)
|
|
24
|
+
}
|
|
12
25
|
|
|
13
26
|
override func keyDown(with event: NSEvent) {
|
|
14
27
|
if let handler = onKeyDown {
|
|
@@ -27,6 +40,11 @@ final class VoicePanel: NSPanel {
|
|
|
27
40
|
}
|
|
28
41
|
}
|
|
29
42
|
|
|
43
|
+
private final class VoiceHostingView<Content: View>: NSHostingView<Content> {
|
|
44
|
+
override func acceptsFirstMouse(for event: NSEvent?) -> Bool { true }
|
|
45
|
+
override var focusRingType: NSFocusRingType { get { .none } set {} }
|
|
46
|
+
}
|
|
47
|
+
|
|
30
48
|
// MARK: - Window Controller
|
|
31
49
|
|
|
32
50
|
final class VoiceCommandWindow {
|
|
@@ -92,7 +110,9 @@ final class VoiceCommandWindow {
|
|
|
92
110
|
p.hidesOnDeactivate = false
|
|
93
111
|
p.isReleasedWhenClosed = false
|
|
94
112
|
p.isMovableByWindowBackground = true
|
|
95
|
-
|
|
113
|
+
let hosting = VoiceHostingView(rootView: view)
|
|
114
|
+
hosting.translatesAutoresizingMaskIntoConstraints = false
|
|
115
|
+
p.contentView = hosting
|
|
96
116
|
|
|
97
117
|
// Position: top-center of screen
|
|
98
118
|
let x = visible.midX - panelWidth / 2
|
|
@@ -101,6 +121,8 @@ final class VoiceCommandWindow {
|
|
|
101
121
|
|
|
102
122
|
p.alphaValue = 0
|
|
103
123
|
p.orderFrontRegardless()
|
|
124
|
+
p.makeKey()
|
|
125
|
+
NSApp.activate(ignoringOtherApps: true)
|
|
104
126
|
|
|
105
127
|
NSAnimationContext.runAnimationGroup { ctx in
|
|
106
128
|
ctx.duration = 0.15
|
|
@@ -1591,4 +1613,3 @@ final class DragDividerNSView: NSView {
|
|
|
1591
1613
|
return expanded.contains(point) ? self : nil
|
|
1592
1614
|
}
|
|
1593
1615
|
}
|
|
1594
|
-
|