meld 0.1.1

Deterministic filesystem state management using Merkle trees
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
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
//! CLI parse: clap types for Merkle. No behavior; definitions only.

use clap::{Parser, Subcommand};
use std::path::PathBuf;

/// Merkle CLI - Deterministic filesystem state management
#[derive(Parser)]
#[command(name = "meld")]
#[command(about = "Deterministic filesystem state management using Merkle trees")]
pub struct Cli {
    #[command(subcommand)]
    pub command: Commands,

    /// Workspace root directory
    #[arg(long, default_value = ".")]
    pub workspace: PathBuf,

    /// Configuration file path (overrides default config loading)
    #[arg(long)]
    pub config: Option<PathBuf>,

    /// Enable verbose logging (default: off)
    #[arg(long, default_value = "false")]
    pub verbose: bool,

    /// Log level (trace, debug, info, warn, error, off)
    #[arg(long)]
    pub log_level: Option<String>,

    /// Log format (json, text)
    #[arg(long)]
    pub log_format: Option<String>,

    /// Log output (stdout, stderr, file, both)
    #[arg(long)]
    pub log_output: Option<String>,

    /// Log file path (if output includes "file")
    #[arg(long)]
    pub log_file: Option<PathBuf>,
}

#[derive(Subcommand)]
pub enum Commands {
    /// Scan filesystem and rebuild tree
    Scan {
        /// Force rebuild even if tree exists
        #[arg(long)]
        force: bool,
    },
    /// Workspace commands (status, validate)
    Workspace {
        #[command(subcommand)]
        command: WorkspaceCommands,
    },
    /// Show unified status (workspace, agents, providers)
    Status {
        /// Output format (text or json)
        #[arg(long, default_value = "text")]
        format: String,
        /// Show only workspace section
        #[arg(long)]
        workspace_only: bool,
        /// Show only agents section
        #[arg(long)]
        agents_only: bool,
        /// Show only providers section
        #[arg(long)]
        providers_only: bool,
        /// Include top-level path breakdown in workspace section
        #[arg(long)]
        breakdown: bool,
        /// Test provider connectivity
        #[arg(long)]
        test_connectivity: bool,
    },
    /// Validate workspace integrity
    Validate,
    /// Start watch mode daemon
    Watch {
        /// Debounce window in milliseconds
        #[arg(long, default_value = "100")]
        debounce_ms: u64,
        /// Batch window in milliseconds
        #[arg(long, default_value = "50")]
        batch_window_ms: u64,
        /// Run in foreground (default: background daemon)
        #[arg(long)]
        foreground: bool,
    },
    /// Manage agents
    Agent {
        #[command(subcommand)]
        command: AgentCommands,
    },
    /// Manage providers
    Provider {
        #[command(subcommand)]
        command: ProviderCommands,
    },
    /// Initialize default agents and prompts
    Init {
        /// Force re-initialization (overwrite existing)
        #[arg(long)]
        force: bool,

        /// List what would be initialized without creating
        #[arg(long)]
        list: bool,
    },
    /// Context operations (generate and retrieve frames)
    Context {
        #[command(subcommand)]
        command: ContextCommands,
    },
}

#[derive(Subcommand)]
pub enum WorkspaceCommands {
    /// Show workspace status (tree, context coverage, top paths)
    Status {
        /// Output format (text or json)
        #[arg(long, default_value = "text")]
        format: String,
        /// Include top-level path breakdown
        #[arg(long)]
        breakdown: bool,
    },
    /// Validate workspace integrity
    Validate {
        /// Output format (text or json)
        #[arg(long, default_value = "text")]
        format: String,
    },
    /// List or add paths to the workspace ignore list
    Ignore {
        /// Path to add (omit to list current ignore list)
        path: Option<PathBuf>,
        /// When adding, report what would be added without writing
        #[arg(long)]
        dry_run: bool,
        /// Output format for list mode (text or json)
        #[arg(long, default_value = "text")]
        format: String,
    },
    /// Tombstone a node and its descendants (logical delete; reversible with restore)
    Delete {
        /// Path to file or directory to delete
        path: Option<PathBuf>,
        /// Node ID (hex) instead of path
        #[arg(long)]
        node: Option<String>,
        /// Report counts without performing the operation
        #[arg(long)]
        dry_run: bool,
        /// Do not add the path to the workspace ignore list
        #[arg(long)]
        no_ignore: bool,
    },
    /// Restore a tombstoned node and its descendants
    Restore {
        /// Path to file or directory to restore
        path: Option<PathBuf>,
        /// Node ID (hex) instead of path
        #[arg(long)]
        node: Option<String>,
        /// Report counts without performing the operation
        #[arg(long)]
        dry_run: bool,
    },
    /// Purge tombstoned records older than TTL
    Compact {
        /// Tombstone age threshold in days (default: 90)
        #[arg(long)]
        ttl: Option<u64>,
        /// Purge all tombstoned records regardless of age
        #[arg(long)]
        all: bool,
        /// Do not purge frame blobs; only purge node and head index records
        #[arg(long)]
        keep_frames: bool,
        /// Report counts without compaction
        #[arg(long)]
        dry_run: bool,
    },
    /// List tombstoned (deleted) nodes
    ListDeleted {
        /// Show only nodes tombstoned longer than this many days
        #[arg(long)]
        older_than: Option<u64>,
        /// Output format (text or json)
        #[arg(long, default_value = "text")]
        format: String,
    },
}

#[derive(Subcommand)]
pub enum AgentCommands {
    /// Show agent status (validation and prompt path)
    Status {
        /// Output format (text or json)
        #[arg(long, default_value = "text")]
        format: String,
    },
    /// List all agents
    List {
        /// Output format (text or json)
        #[arg(long, default_value = "text")]
        format: String,
        /// Filter by role (Reader or Writer)
        #[arg(long)]
        role: Option<String>,
    },
    /// Show agent details
    Show {
        /// Agent ID
        agent_id: String,
        /// Output format (text or json)
        #[arg(long, default_value = "text")]
        format: String,
        /// Include prompt file content in output
        #[arg(long)]
        include_prompt: bool,
    },
    /// Validate agent configuration
    Validate {
        /// Agent ID (required unless --all is used)
        #[arg(required_unless_present = "all")]
        agent_id: Option<String>,
        /// Validate all agents
        #[arg(long, conflicts_with = "agent_id")]
        all: bool,
        /// Show detailed validation results
        #[arg(long)]
        verbose: bool,
    },
    /// Create new agent
    Create {
        /// Agent ID
        agent_id: String,
        /// Agent role (Reader or Writer)
        #[arg(long)]
        role: Option<String>,
        /// Path to prompt file (required for Writer)
        #[arg(long)]
        prompt_path: Option<String>,
        /// Use interactive mode (default)
        #[arg(long)]
        interactive: bool,
        /// Use non-interactive mode (use flags)
        #[arg(long)]
        non_interactive: bool,
    },
    /// Edit agent configuration
    Edit {
        /// Agent ID
        agent_id: String,
        /// Update prompt file path
        #[arg(long)]
        prompt_path: Option<String>,
        /// Update agent role
        #[arg(long)]
        role: Option<String>,
        /// Editor to use (default: $EDITOR)
        #[arg(long)]
        editor: Option<String>,
    },
    /// Edit agent prompt files
    Prompt {
        #[command(subcommand)]
        command: AgentPromptCommands,
    },
    /// Remove agent
    Remove {
        /// Agent ID
        agent_id: String,
        /// Skip confirmation prompt
        #[arg(long)]
        force: bool,
    },
}

#[derive(Subcommand)]
pub enum AgentPromptCommands {
    /// Show the prompt file for an agent
    Show {
        /// Agent ID
        agent_id: String,
    },
    /// Edit the prompt file for an agent
    Edit {
        /// Agent ID
        agent_id: String,
        /// Editor to use (default: $EDITOR)
        #[arg(long)]
        editor: Option<String>,
    },
}

#[derive(Subcommand)]
pub enum ProviderCommands {
    /// Show provider status (optional connectivity)
    Status {
        /// Output format (text or json)
        #[arg(long, default_value = "text")]
        format: String,
        /// Test connectivity per provider (may be slow)
        #[arg(long)]
        test_connectivity: bool,
    },
    /// List all providers
    List {
        /// Output format (text or json)
        #[arg(long, default_value = "text")]
        format: String,
        /// Filter by provider type (openai, anthropic, ollama, local)
        #[arg(long)]
        type_filter: Option<String>,
    },
    /// Show provider details
    Show {
        /// Provider name
        provider_name: String,
        /// Output format (text or json)
        #[arg(long, default_value = "text")]
        format: String,
        /// Show API key status
        #[arg(long)]
        include_credentials: bool,
    },
    /// Validate provider configuration
    Validate {
        /// Provider name
        provider_name: String,
        /// Test provider API connectivity
        #[arg(long)]
        test_connectivity: bool,
        /// Verify model is available
        #[arg(long)]
        check_model: bool,
        /// Show detailed validation results
        #[arg(long)]
        verbose: bool,
    },
    /// Test provider connectivity
    Test {
        /// Provider name
        provider_name: String,
        /// Test specific model (overrides config)
        #[arg(long)]
        model: Option<String>,
        /// Connection timeout in seconds (default: 10)
        #[arg(long, default_value = "10")]
        timeout: u64,
    },
    /// Create new provider
    Create {
        /// Provider name
        provider_name: String,
        /// Provider type (openai, anthropic, ollama, local)
        #[arg(long, name = "type")]
        type_: Option<String>,
        /// Model name
        #[arg(long)]
        model: Option<String>,
        /// Endpoint URL
        #[arg(long)]
        endpoint: Option<String>,
        /// API key
        #[arg(long)]
        api_key: Option<String>,
        /// Use interactive mode (default)
        #[arg(long)]
        interactive: bool,
        /// Use non-interactive mode (use flags)
        #[arg(long)]
        non_interactive: bool,
    },
    /// Edit provider configuration
    Edit {
        /// Provider name
        provider_name: String,
        /// Update model name
        #[arg(long)]
        model: Option<String>,
        /// Update endpoint URL
        #[arg(long)]
        endpoint: Option<String>,
        /// Update API key
        #[arg(long)]
        api_key: Option<String>,
        /// Editor to use (default: $EDITOR)
        #[arg(long)]
        editor: Option<String>,
    },
    /// Remove provider
    Remove {
        /// Provider name
        provider_name: String,
        /// Skip confirmation prompt
        #[arg(long)]
        force: bool,
    },
}

#[derive(Subcommand)]
pub enum ContextCommands {
    /// Generate context frame for a node
    Generate {
        /// Target node by NodeID (hex string)
        #[arg(long, conflicts_with_all = ["path", "path_positional"])]
        node: Option<String>,

        /// Target node by workspace-relative or absolute path
        #[arg(long, value_name = "PATH", conflicts_with = "node")]
        path: Option<PathBuf>,

        /// Target path (positional; same as --path)
        #[arg(value_name = "PATH", index = 1, conflicts_with = "node")]
        path_positional: Option<PathBuf>,

        /// Agent to use for generation
        #[arg(long)]
        agent: Option<String>,

        /// Provider to use for generation (required)
        #[arg(long)]
        provider: Option<String>,

        /// Frame type (defaults to context-<agent_id>)
        #[arg(long)]
        frame_type: Option<String>,

        /// Generate even if head frame exists
        #[arg(long)]
        force: bool,
        /// Disable recursive generation for directory targets
        #[arg(long)]
        no_recursive: bool,
    },
    /// Re generate a context frame for a node and prefer directory only reroll
    Regenerate {
        /// Target node by NodeID (hex string)
        #[arg(long, conflicts_with_all = ["path", "path_positional"])]
        node: Option<String>,

        /// Target node by workspace-relative or absolute path
        #[arg(long, value_name = "PATH", conflicts_with = "node")]
        path: Option<PathBuf>,

        /// Target path (positional; same as --path)
        #[arg(value_name = "PATH", index = 1, conflicts_with = "node")]
        path_positional: Option<PathBuf>,

        /// Agent to use for generation
        #[arg(long)]
        agent: Option<String>,

        /// Provider to use for generation (required)
        #[arg(long)]
        provider: Option<String>,

        /// Frame type (defaults to context-<agent_id>)
        #[arg(long)]
        frame_type: Option<String>,

        /// Regenerate directory target recursively instead of only rerolling the directory frame
        #[arg(long)]
        recursive: bool,
    },
    /// Retrieve context frames for a node
    Get {
        /// Target node by NodeID (hex string)
        #[arg(long, conflicts_with = "path")]
        node: Option<String>,

        /// Target node by workspace-relative or absolute path
        #[arg(long, conflicts_with = "node")]
        path: Option<PathBuf>,

        /// Filter by agent ID
        #[arg(long)]
        agent: Option<String>,

        /// Filter by frame type
        #[arg(long)]
        frame_type: Option<String>,

        /// Maximum frames to return
        #[arg(long, default_value = "10")]
        max_frames: usize,

        /// Ordering policy: recency or deterministic
        #[arg(long, default_value = "recency")]
        ordering: String,

        /// Concatenate frame contents with separator
        #[arg(long)]
        combine: bool,

        /// Separator used with --combine
        #[arg(long, default_value = "\n\n---\n\n")]
        separator: String,

        /// Output format: text or json
        #[arg(long, default_value = "text")]
        format: String,

        /// Include metadata fields in output
        #[arg(long)]
        include_metadata: bool,

        /// Include frames marked deleted (tombstones)
        #[arg(long)]
        include_deleted: bool,
    },
}