chasm-cli 2.0.0

Universal chat session manager - harvest, merge, and analyze AI chat history from VS Code, Cursor, and other editors
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
// Copyright (c) 2024-2026 Nervosys LLC
// SPDX-License-Identifier: AGPL-3.0-only
//! Smart Home Integrations
//!
//! Home Assistant, HomeKit, Hue, SmartThings, IoT devices

use super::IntegrationResult;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

// =============================================================================
// Common Types
// =============================================================================

/// Device state
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeviceState {
    pub device_id: String,
    pub name: String,
    pub device_type: DeviceType,
    pub state: String,
    pub attributes: HashMap<String, serde_json::Value>,
    pub last_changed: String,
    pub is_online: bool,
}

/// Device types
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum DeviceType {
    Light,
    Switch,
    Outlet,
    Thermostat,
    Lock,
    Sensor,
    Camera,
    Speaker,
    Fan,
    Blind,
    Garage,
    Vacuum,
    AirPurifier,
    Humidifier,
    MediaPlayer,
    Climate,
    Other,
}

/// Scene/Automation
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Scene {
    pub id: String,
    pub name: String,
    pub description: Option<String>,
    pub actions: Vec<DeviceAction>,
    pub icon: Option<String>,
}

/// Device action
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeviceAction {
    pub device_id: String,
    pub action: String,
    pub parameters: Option<HashMap<String, serde_json::Value>>,
}

// =============================================================================
// Home Assistant
// =============================================================================

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HomeAssistantConfig {
    pub url: String,
    pub access_token: String,
}

/// Home Assistant entity
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HAEntity {
    pub entity_id: String,
    pub state: String,
    pub attributes: HashMap<String, serde_json::Value>,
    pub last_changed: String,
    pub last_updated: String,
}

/// Home Assistant service
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HAService {
    pub domain: String,
    pub service: String,
    pub description: Option<String>,
    pub fields: HashMap<String, HAServiceField>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HAServiceField {
    pub description: String,
    pub required: bool,
    pub example: Option<serde_json::Value>,
}

/// Home Assistant automation
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HAAutomation {
    pub id: String,
    pub alias: String,
    pub description: Option<String>,
    pub trigger: Vec<serde_json::Value>,
    pub condition: Vec<serde_json::Value>,
    pub action: Vec<serde_json::Value>,
    pub mode: String,
}

/// Home Assistant provider trait
#[async_trait::async_trait]
pub trait HomeAssistantProvider: Send + Sync {
    // States
    async fn list_entities(&self, domain: Option<&str>) -> IntegrationResult;
    async fn get_state(&self, entity_id: &str) -> IntegrationResult;
    async fn get_history(&self, entity_id: &str, start: &str, end: &str) -> IntegrationResult;

    // Services
    async fn list_services(&self) -> IntegrationResult;
    async fn call_service(
        &self,
        domain: &str,
        service: &str,
        data: Option<serde_json::Value>,
    ) -> IntegrationResult;

    // Automation
    async fn list_automations(&self) -> IntegrationResult;
    async fn trigger_automation(&self, automation_id: &str) -> IntegrationResult;
    async fn toggle_automation(&self, automation_id: &str, enabled: bool) -> IntegrationResult;

    // Scenes
    async fn list_scenes(&self) -> IntegrationResult;
    async fn activate_scene(&self, scene_id: &str) -> IntegrationResult;

    // Scripts
    async fn run_script(
        &self,
        script_id: &str,
        data: Option<serde_json::Value>,
    ) -> IntegrationResult;

    // Events
    async fn fire_event(
        &self,
        event_type: &str,
        data: Option<serde_json::Value>,
    ) -> IntegrationResult;

    // Companion app
    async fn notify(
        &self,
        message: &str,
        title: Option<&str>,
        data: Option<serde_json::Value>,
    ) -> IntegrationResult;
}

// =============================================================================
// Apple HomeKit
// =============================================================================

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HomeKitAccessory {
    pub id: String,
    pub name: String,
    pub room: Option<String>,
    pub accessory_type: String,
    pub services: Vec<HomeKitService>,
    pub is_reachable: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HomeKitService {
    pub service_type: String,
    pub characteristics: Vec<HomeKitCharacteristic>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HomeKitCharacteristic {
    pub characteristic_type: String,
    pub value: serde_json::Value,
    pub is_readable: bool,
    pub is_writable: bool,
}

/// HomeKit provider trait
#[async_trait::async_trait]
pub trait HomeKitProvider: Send + Sync {
    async fn list_homes(&self) -> IntegrationResult;
    async fn list_rooms(&self, home_id: &str) -> IntegrationResult;
    async fn list_accessories(&self, home_id: &str) -> IntegrationResult;
    async fn get_accessory(&self, accessory_id: &str) -> IntegrationResult;
    async fn set_characteristic(
        &self,
        accessory_id: &str,
        service: &str,
        characteristic: &str,
        value: serde_json::Value,
    ) -> IntegrationResult;
    async fn list_scenes(&self, home_id: &str) -> IntegrationResult;
    async fn run_scene(&self, scene_id: &str) -> IntegrationResult;
}

// =============================================================================
// Philips Hue
// =============================================================================

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HueConfig {
    pub bridge_ip: String,
    pub username: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HueLight {
    pub id: String,
    pub name: String,
    pub is_on: bool,
    pub brightness: u8,          // 1-254
    pub hue: Option<u16>,        // 0-65535
    pub saturation: Option<u8>,  // 0-254
    pub color_temp: Option<u16>, // 153-500 (mirek)
    pub is_reachable: bool,
    pub light_type: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HueGroup {
    pub id: String,
    pub name: String,
    pub lights: Vec<String>,
    pub group_type: String,
    pub is_on: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HueScene {
    pub id: String,
    pub name: String,
    pub group: Option<String>,
    pub lights: Vec<String>,
}

/// Hue provider trait
#[async_trait::async_trait]
pub trait HueProvider: Send + Sync {
    // Lights
    async fn list_lights(&self) -> IntegrationResult;
    async fn get_light(&self, light_id: &str) -> IntegrationResult;
    async fn set_light_state(
        &self,
        light_id: &str,
        on: Option<bool>,
        brightness: Option<u8>,
        color: Option<(u16, u8)>,
    ) -> IntegrationResult;

    // Groups
    async fn list_groups(&self) -> IntegrationResult;
    async fn set_group_state(
        &self,
        group_id: &str,
        on: Option<bool>,
        brightness: Option<u8>,
    ) -> IntegrationResult;

    // Scenes
    async fn list_scenes(&self) -> IntegrationResult;
    async fn activate_scene(&self, scene_id: &str) -> IntegrationResult;

    // Effects
    async fn set_color_loop(&self, light_id: &str, enabled: bool) -> IntegrationResult;
    async fn alert(&self, light_id: &str) -> IntegrationResult;
}

// =============================================================================
// Thermostats (Nest, Ecobee)
// =============================================================================

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ThermostatState {
    pub id: String,
    pub name: String,
    pub current_temperature: f32,
    pub target_temperature: Option<f32>,
    pub target_temperature_low: Option<f32>,
    pub target_temperature_high: Option<f32>,
    pub mode: ThermostatMode,
    pub humidity: Option<u8>,
    pub is_running: bool,
    pub fan_mode: Option<FanMode>,
}

#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ThermostatMode {
    Off,
    Heat,
    Cool,
    HeatCool,
    Auto,
    Eco,
}

#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum FanMode {
    Auto,
    On,
    Circulate,
}

/// Thermostat provider trait
#[async_trait::async_trait]
pub trait ThermostatProvider: Send + Sync {
    async fn get_state(&self, thermostat_id: &str) -> IntegrationResult;
    async fn set_temperature(&self, thermostat_id: &str, temperature: f32) -> IntegrationResult;
    async fn set_mode(&self, thermostat_id: &str, mode: ThermostatMode) -> IntegrationResult;
    async fn set_fan_mode(&self, thermostat_id: &str, fan_mode: FanMode) -> IntegrationResult;
    async fn set_schedule(
        &self,
        thermostat_id: &str,
        schedule: serde_json::Value,
    ) -> IntegrationResult;
}

// =============================================================================
// Locks (August, Schlage)
// =============================================================================

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LockState {
    pub id: String,
    pub name: String,
    pub is_locked: bool,
    pub is_jammed: bool,
    pub battery_level: Option<u8>,
    pub last_activity: Option<String>,
}

/// Lock provider trait
#[async_trait::async_trait]
pub trait LockProvider: Send + Sync {
    async fn get_state(&self, lock_id: &str) -> IntegrationResult;
    async fn lock(&self, lock_id: &str) -> IntegrationResult;
    async fn unlock(&self, lock_id: &str) -> IntegrationResult;
    async fn get_activity(&self, lock_id: &str, limit: u32) -> IntegrationResult;
}

// =============================================================================
// Cameras (Ring, Nest, Wyze)
// =============================================================================

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Camera {
    pub id: String,
    pub name: String,
    pub is_online: bool,
    pub is_recording: bool,
    pub has_motion: bool,
    pub battery_level: Option<u8>,
    pub stream_url: Option<String>,
}

/// Camera provider trait
#[async_trait::async_trait]
pub trait CameraProvider: Send + Sync {
    async fn list_cameras(&self) -> IntegrationResult;
    async fn get_camera(&self, camera_id: &str) -> IntegrationResult;
    async fn get_stream_url(&self, camera_id: &str) -> IntegrationResult;
    async fn get_snapshot(&self, camera_id: &str) -> IntegrationResult;
    async fn get_events(&self, camera_id: &str, limit: u32) -> IntegrationResult;
}

// =============================================================================
// Sensors
// =============================================================================

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Sensor {
    pub id: String,
    pub name: String,
    pub sensor_type: SensorType,
    pub value: serde_json::Value,
    pub unit: Option<String>,
    pub battery_level: Option<u8>,
    pub last_updated: String,
}

#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum SensorType {
    Temperature,
    Humidity,
    Motion,
    Contact,
    Light,
    Smoke,
    CarbonMonoxide,
    Water,
    Vibration,
    Pressure,
    AirQuality,
    Power,
    Energy,
}

/// Sensor provider trait
#[async_trait::async_trait]
pub trait SensorProvider: Send + Sync {
    async fn list_sensors(&self) -> IntegrationResult;
    async fn get_sensor(&self, sensor_id: &str) -> IntegrationResult;
    async fn get_history(&self, sensor_id: &str, start: &str, end: &str) -> IntegrationResult;
}