zam 0.8.0

Enhanced shell history manager with sensitive data redaction
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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
//! Command-line argument structures for zam

use clap::Args;
use std::path::PathBuf;

#[derive(Args)]
pub struct LogArgs {
    /// Command to log
    #[arg(value_name = "COMMAND")]
    pub command: String,

    /// Timestamp in Unix format (optional)
    #[arg(short = 'T', long)]
    pub timestamp: Option<i64>,

    /// Directory where command was executed (optional)
    #[arg(short = 'D', long)]
    pub directory: Option<String>,

    /// Skip redaction for this command
    #[arg(long)]
    pub no_redact: bool,

    /// Exit code of the command (optional)
    #[arg(short = 'E', long)]
    pub exit_code: Option<i32>,

    /// Use a static session ID (e.g. for non-interactive tools like Claude Code)
    #[arg(short = 'S', long)]
    pub session_id: Option<String>,
}

#[derive(Args)]
pub struct EndSessionArgs {
    /// Session ID to close
    #[arg(value_name = "SESSION_ID")]
    pub session_id: String,
}

#[derive(Args)]
pub struct AuthArgs {
    /// 1Password item name to load secrets from
    #[arg(value_name = "ITEM")]
    pub item: Option<String>,

    /// List keys loaded for the current session
    #[arg(short = 'L', long)]
    pub list: bool,

    /// Output export statements (used by zam-auth wrapper)
    #[arg(long)]
    pub export: bool,

    /// Clear all session secrets (outputs unset lines)
    #[arg(long)]
    pub clear: bool,

    /// Store a secret in the 1Password item (format: KEY:VALUE)
    #[arg(long, value_name = "KEY:VALUE")]
    pub set: Option<String>,

    /// Session ID to associate secrets with
    #[arg(short = 'S', long)]
    pub session_id: Option<String>,
}

#[derive(Args)]
pub struct SearchArgs {
    /// Search term
    #[arg(value_name = "TERM")]
    pub term: String,

    /// Filter by directory
    #[arg(short = 'D', long)]
    pub directory: Option<String>,

    /// Use exact matching (disable fuzzy search)
    #[arg(short = 'E', long)]
    pub exact: bool,

    /// Case-sensitive search
    #[arg(short = 'C', long)]
    pub case_sensitive: bool,

    /// Use regex matching
    #[arg(short = 'R', long)]
    pub regex: bool,

    /// Search only redacted commands
    #[arg(long)]
    pub redacted_only: bool,

    /// Maximum number of results
    #[arg(short = 'L', long, default_value = "50")]
    pub limit: usize,

    /// Show timestamps
    #[arg(short = 'T', long)]
    pub timestamps: bool,

    /// Show directories
    #[arg(long)]
    pub show_dirs: bool,

    /// Search within specific time range (format: YYYY-MM-DD)
    #[arg(long)]
    pub since: Option<String>,

    /// Search before specific date (format: YYYY-MM-DD)
    #[arg(long)]
    pub before: Option<String>,
}

#[derive(Args)]
pub struct ImportArgs {
    /// Shell type to import from
    #[arg(value_enum, default_value = "zsh")]
    pub shell: ShellType,

    /// Path to history file (optional, auto-detected if not provided)
    #[arg(short = 'F', long)]
    pub file: Option<PathBuf>,

    /// Dry run - show what would be imported without actually importing
    #[arg(long)]
    pub dry_run: bool,

    /// Skip deduplication
    #[arg(long)]
    pub no_dedup: bool,

    /// Import entries from last N days only
    #[arg(long)]
    pub days: Option<u32>,

    /// Show progress during import
    #[arg(long)]
    pub progress: bool,
}

#[derive(Args)]
pub struct ExportArgs {
    /// Export format
    #[arg(value_enum, default_value = "json")]
    pub format: ExportFormat,

    /// Output file (stdout if not specified)
    #[arg(short = 'O', long)]
    pub output: Option<PathBuf>,

    /// Include redacted commands
    #[arg(long)]
    pub include_redacted: bool,

    /// Include original commands (if available)
    #[arg(long)]
    pub include_original: bool,

    /// Export from specific directory only
    #[arg(short = 'D', long)]
    pub directory: Option<String>,

    /// Export entries from last N days only
    #[arg(long)]
    pub days: Option<u32>,
}

#[derive(Args)]
pub struct StatsArgs {
    /// Show detailed statistics
    #[arg(short = 'D', long)]
    pub detailed: bool,

    /// Show redaction statistics
    #[arg(long)]
    pub redaction: bool,

    /// Show directory statistics
    #[arg(long)]
    pub directories: bool,

    /// Show time-based statistics
    #[arg(long)]
    pub time_stats: bool,
}

#[derive(Args)]
pub struct ClearArgs {
    /// Confirm deletion without prompting
    #[arg(short = 'F', long)]
    pub force: bool,

    /// Keep last N entries
    #[arg(long)]
    pub keep: Option<usize>,

    /// Clear entries older than N days
    #[arg(long)]
    pub older_than: Option<u32>,
}

#[derive(Args)]
pub struct ConfigArgs {
    /// Show current configuration
    #[arg(long)]
    pub show: bool,

    /// Initialize configuration file with defaults
    #[arg(long)]
    pub init: bool,

    /// Validate configuration file
    #[arg(long)]
    pub validate: bool,

    /// Set configuration value (format: key=value)
    #[arg(long)]
    pub set: Option<String>,

    /// Get configuration value
    #[arg(long)]
    pub get: Option<String>,
}

#[derive(Args)]
pub struct FzfArgs {
    /// Show unique commands only
    #[arg(short = 'U', long)]
    pub unique: bool,

    /// Filter by directory
    #[arg(short = 'D', long)]
    pub directory: Option<String>,

    /// Maximum number of results
    #[arg(short = 'L', long, default_value = "1000")]
    pub limit: usize,

    /// Reverse order (oldest first)
    #[arg(short = 'R', long)]
    pub reverse: bool,
}

#[derive(Args)]
pub struct ShellArgs {
    /// Shell type
    #[arg(value_enum)]
    pub shell: ShellType,

    /// Output file (optional, prints to stdout if not specified)
    #[arg(short = 'O', long)]
    pub output: Option<PathBuf>,

    /// Include custom key bindings
    #[arg(long)]
    pub custom_bindings: bool,
}

#[derive(Args)]
pub struct RecentArgs {
    /// Number of recent commands to show
    #[arg(short = 'n', long, default_value = "20")]
    pub count: usize,

    /// Filter by directory
    #[arg(short = 'D', long)]
    pub directory: Option<String>,

    /// Show timestamps
    #[arg(short = 'T', long)]
    pub timestamps: bool,
}

#[derive(Args)]
pub struct FrequentArgs {
    /// Number of frequent items to show
    #[arg(short = 'n', long, default_value = "10")]
    pub count: usize,

    /// Show frequent directories instead of commands
    #[arg(long)]
    pub directories: bool,

    /// Show counts alongside items
    #[arg(long)]
    pub counts: bool,
}

#[derive(Args)]
pub struct ValidateArgs {
    /// Redaction pattern to validate
    #[arg(value_name = "PATTERN")]
    pub pattern: String,

    /// Test string to validate against the pattern
    #[arg(short = 't', long)]
    pub test: Option<String>,
}

#[derive(Args)]
pub struct MergeArgs {
    /// Path to database file to merge from
    #[arg(value_name = "DB_FILE")]
    pub db_file: PathBuf,

    /// Show what would be merged without actually merging
    #[arg(long)]
    pub dry_run: bool,

    /// Show progress during merge
    #[arg(long)]
    pub progress: bool,
}

#[derive(Args)]
pub struct TokensArgs {
    /// Filter by session ID
    #[arg(short = 'S', long)]
    pub session: Option<String>,

    /// Filter by directory
    #[arg(short = 'D', long)]
    pub directory: Option<String>,

    /// Filter by command ID
    #[arg(short = 'C', long)]
    pub command_id: Option<i64>,

    /// Show token values (use with caution!)
    #[arg(long)]
    pub show_values: bool,

    /// Export tokens to file
    #[arg(short = 'O', long)]
    pub output: Option<PathBuf>,
}

#[derive(Args)]
pub struct HostsArgs {
    /// List all hosts
    #[arg(short = 'L', long)]
    pub list: bool,

    /// Show sessions for a specific host
    #[arg(short = 'S', long)]
    pub show_sessions: Option<i64>,

    /// Show detailed information
    #[arg(short = 'D', long)]
    pub detailed: bool,
}

#[derive(Args)]
pub struct SessionsArgs {
    /// Filter by host ID
    #[arg(short = 'H', long)]
    pub host_id: Option<i64>,

    /// Show active sessions only
    #[arg(short = 'A', long)]
    pub active: bool,

    /// Show commands in session
    #[arg(short = 'C', long)]
    pub show_commands: Option<String>,

    /// Show detailed information
    #[arg(short = 'D', long)]
    pub detailed: bool,
}

#[derive(Args)]
pub struct AliasArgs {
    #[command(subcommand)]
    pub command: AliasCommands,
}

#[derive(clap::Subcommand)]
pub enum AliasCommands {
    /// Add a new alias
    Add(AliasAddArgs),
    /// Update an existing alias
    Update(AliasUpdateArgs),
    /// Remove an alias
    Remove(AliasRemoveArgs),
    /// List all aliases
    List(AliasListArgs),
    /// Export aliases as a shell script
    Export(AliasExportArgs),
    /// Sync aliases from shell (reads alias output from stdin)
    Sync,
}

#[derive(Args)]
pub struct AliasAddArgs {
    /// Alias name
    pub name: String,
    /// Command the alias expands to
    pub command: String,
    /// Description of the alias
    pub description: String,
}

#[derive(Args)]
pub struct AliasUpdateArgs {
    /// Alias name
    pub name: String,
    /// New command the alias expands to
    pub command: String,
    /// New description (optional)
    #[arg(short, long)]
    pub description: Option<String>,
}

#[derive(Args)]
pub struct AliasRemoveArgs {
    /// Alias name to remove
    pub name: String,
}

#[derive(Args)]
pub struct AliasListArgs {
    /// Output in shell eval-ready format (alias name='cmd')
    #[arg(long)]
    pub shell: bool,
}

#[derive(Args)]
pub struct AliasExportArgs {
    /// Output file (stdout if not specified)
    #[arg(short = 'O', long)]
    pub output: Option<std::path::PathBuf>,
}

#[derive(Args)]
pub struct VacuumArgs {
    /// Maximum number of commands to keep (prunes oldest beyond this limit)
    #[arg(long)]
    pub max_entries: Option<usize>,
}

#[derive(clap::ValueEnum, Clone)]
pub enum ShellType {
    Zsh,
    Bash,
    Fish,
}

#[derive(clap::ValueEnum, Clone)]
pub enum ExportFormat {
    Json,
    Csv,
    Tsv,
    Plain,
}