heddle-cli-args 0.28.6

Heddle's command-line argument surface.
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
// SPDX-License-Identifier: Apache-2.0
//! Context annotation subcommands.

#[cfg(all(feature = "git-overlay", feature = "ingest"))]
use super::DryRunArgs;
use super::{AuthoredMessageArgs, CodeScopeArgs, HistoricalRevisionArgs};

/// Context subcommands.
#[derive(Clone, Debug, clap::Subcommand)]
pub enum ContextCommands {
    /// Attach a context annotation to a file, symbol, line range, or state.
    Set(ContextSetArgs),

    /// Show current context annotations for a file or state target.
    Get(ContextGetArgs),

    /// List all active context targets.
    List(ContextListArgs),

    /// Show full revision history for one logical annotation.
    History(ContextHistoryArgs),

    /// Add a new revision to an existing logical annotation.
    Edit(ContextEditArgs),

    /// Create a replacement logical annotation and supersede an older one.
    Supersede(ContextSupersedeArgs),

    /// Remove context annotations.
    Rm(ContextRmArgs),

    /// Check annotation staleness against current code.
    Check(ContextCheckArgs),

    /// Suggest low-noise targets that may benefit from context.
    Suggest(ContextSuggestArgs),

    /// Audit stale, superseded, and duplicate context.
    Audit(ContextAuditArgs),

    /// Mine external sources for context annotations.
    #[cfg(all(feature = "git-overlay", feature = "ingest"))]
    Reason {
        #[command(subcommand)]
        command: ContextReasonCommands,
    },
}

#[cfg(all(feature = "git-overlay", feature = "ingest"))]
#[derive(Clone, Debug, clap::Subcommand)]
pub enum ContextReasonCommands {
    /// Mine Git-agent transcripts and attach reasoning as context annotations.
    Git(ContextReasonGitArgs),
}

#[cfg(all(feature = "git-overlay", feature = "ingest"))]
#[derive(Clone, Debug, clap::Args)]
pub struct ContextReasonGitArgs {
    /// Source git repository the transcripts are about.
    #[arg(long)]
    pub path: std::path::PathBuf,

    /// Cap candidates per commit. Higher = more coverage at the cost of cross-attribution.
    #[arg(long, default_value_t = 5)]
    pub max_sessions_per_commit: usize,

    /// Drop sessions below this confidence.
    #[arg(long, default_value_t = 0.20)]
    pub min_match_confidence: f32,

    /// Limit how many commits the reason pass walks.
    #[arg(long)]
    pub limit: Option<usize>,

    /// Override the Claude transcript store. Empty string disables.
    #[arg(long = "claude-home")]
    pub claude_home: Option<String>,

    /// Override the Codex transcript store. Empty string disables.
    #[arg(long = "codex-home")]
    pub codex_home: Option<String>,

    /// Override the OpenCode data dir. Empty string disables.
    #[arg(long = "opencode-home")]
    pub opencode_home: Option<String>,

    #[command(flatten)]
    pub dry_run: DryRunArgs,
}

/// Arguments for `heddle context set`.
#[derive(Clone, Debug, clap::Args)]
pub struct ContextSetArgs {
    /// File path to annotate (alternative to `--path`).
    #[arg(value_name = "PATH", conflicts_with = "path")]
    pub path_positional: Option<String>,

    #[command(flatten)]
    pub scope: CodeScopeArgs,

    /// State-level target when `--path` is omitted. Writes always land on HEAD.
    #[command(flatten)]
    pub revision: HistoricalRevisionArgs,

    /// Primary annotation kind: constraint, invariant, or rationale.
    #[arg(
        long,
        default_value = "rationale",
        value_parser = ["constraint", "invariant", "rationale"]
    )]
    pub kind: String,

    /// Explicit tags for categorization (can be repeated).
    #[arg(long)]
    pub tag: Vec<String>,

    #[command(flatten)]
    pub message: AuthoredMessageArgs,
}

impl ContextSetArgs {
    /// Effective file path from positional PATH or `--path`.
    pub fn resolved_path(&self) -> Option<&str> {
        self.path_positional
            .as_deref()
            .or(self.scope.path.as_deref())
    }
}

/// Arguments for `heddle context get`.
#[derive(Clone, Debug, clap::Args)]
pub struct ContextGetArgs {
    #[command(flatten)]
    pub scope: CodeScopeArgs,

    #[command(flatten)]
    pub revision: HistoricalRevisionArgs,

    /// Filter by tag.
    #[arg(long)]
    pub tag: Option<String>,
}

/// Arguments for `heddle context list`.
#[derive(Clone, Debug, clap::Args)]
pub struct ContextListArgs {
    /// Optional path prefix to filter file targets by.
    #[arg(long)]
    pub prefix: Option<String>,

    /// Filter by tag.
    #[arg(long)]
    pub tag: Option<String>,

    #[command(flatten)]
    pub revision: HistoricalRevisionArgs,

    /// Include superseded logical annotations in listings.
    #[arg(long)]
    pub include_superseded: bool,
}

#[derive(Clone, Debug, clap::Args)]
pub struct ContextHistoryArgs {
    /// Stable logical annotation ID. Omit when using `--path` / `--state`.
    #[arg(required_unless_present_any = ["path", "state"])]
    pub annotation_id: Option<String>,

    #[command(flatten)]
    pub scope: CodeScopeArgs,

    #[command(flatten)]
    pub revision: HistoricalRevisionArgs,
}

#[derive(Clone, Debug, clap::Args)]
pub struct ContextEditArgs {
    /// Stable logical annotation ID. Omit when using `--path` / `--state`.
    #[arg(required_unless_present_any = ["path", "state"])]
    pub annotation_id: Option<String>,

    #[command(flatten)]
    pub scope: CodeScopeArgs,

    #[command(flatten)]
    pub revision: HistoricalRevisionArgs,

    /// Override the annotation kind for the new revision.
    #[arg(long, value_parser = ["constraint", "invariant", "rationale"])]
    pub kind: Option<String>,

    /// Explicit tags for the new revision (can be repeated).
    #[arg(long)]
    pub tag: Vec<String>,

    #[command(flatten)]
    pub message: AuthoredMessageArgs,
}

#[derive(Clone, Debug, clap::Args)]
pub struct ContextSupersedeArgs {
    /// Stable logical annotation ID to supersede.
    pub annotation_id: String,

    #[command(flatten)]
    pub scope: CodeScopeArgs,

    #[command(flatten)]
    pub revision: HistoricalRevisionArgs,

    /// Replacement annotation kind: constraint, invariant, or rationale.
    #[arg(
        long,
        default_value = "rationale",
        value_parser = ["constraint", "invariant", "rationale"]
    )]
    pub kind: String,

    /// Explicit tags for the replacement annotation.
    #[arg(long)]
    pub tag: Vec<String>,

    #[command(flatten)]
    pub message: AuthoredMessageArgs,
}

/// Arguments for `heddle context rm`.
#[derive(Clone, Debug, clap::Args)]
pub struct ContextRmArgs {
    #[command(flatten)]
    pub scope: CodeScopeArgs,

    #[command(flatten)]
    pub revision: HistoricalRevisionArgs,

    /// Remove all annotations for this target.
    #[arg(long)]
    pub all: bool,
}

/// Arguments for `heddle context check`.
#[derive(Clone, Debug, clap::Args)]
pub struct ContextCheckArgs {
    #[command(flatten)]
    pub scope: CodeScopeArgs,

    #[command(flatten)]
    pub revision: HistoricalRevisionArgs,

    /// Filter by tag.
    #[arg(long)]
    pub tag: Option<String>,
}

#[derive(Clone, Debug, clap::Args)]
pub struct ContextSuggestArgs {
    #[command(flatten)]
    pub revision: HistoricalRevisionArgs,

    /// Maximum suggestions to print.
    #[arg(short = 'n', long, default_value = "10")]
    pub limit: usize,
}

#[derive(Clone, Debug, clap::Args)]
pub struct ContextAuditArgs {
    #[command(flatten)]
    pub revision: HistoricalRevisionArgs,
}

#[cfg(test)]
mod tests {
    use clap::Parser;

    use crate::cli::{Cli, Commands, ContextCommands};

    #[test]
    fn history_and_edit_accept_path_or_id() {
        match Cli::try_parse_from(["heddle", "context", "history", "ann-1"])
            .expect("history id")
            .command
        {
            Commands::Context {
                for_thread: None,
                command: Some(ContextCommands::History(args)),
            } => {
                assert_eq!(args.annotation_id.as_deref(), Some("ann-1"));
                assert!(args.scope.path.is_none());
            }
            _ => panic!("expected context history"),
        }
        match Cli::try_parse_from(["heddle", "context", "history", "--path", "src/auth.rs"])
            .expect("history path")
            .command
        {
            Commands::Context {
                for_thread: None,
                command: Some(ContextCommands::History(args)),
            } => {
                assert!(args.annotation_id.is_none());
                assert_eq!(args.scope.path.as_deref(), Some("src/auth.rs"));
            }
            _ => panic!("expected context history"),
        }
        match Cli::try_parse_from([
            "heddle",
            "context",
            "edit",
            "--path",
            "src/auth.rs",
            "-m",
            "revised",
        ])
        .expect("edit path")
        .command
        {
            Commands::Context {
                for_thread: None,
                command: Some(ContextCommands::Edit(args)),
            } => {
                assert!(args.annotation_id.is_none());
                assert_eq!(args.scope.path.as_deref(), Some("src/auth.rs"));
                assert_eq!(args.message.body.as_deref(), Some("revised"));
            }
            _ => panic!("expected context edit"),
        }
    }

    #[test]
    fn context_set_accepts_positional_path_body_and_file() {
        match Cli::try_parse_from([
            "heddle",
            "context",
            "set",
            "src/auth.rs",
            "--body",
            "keep timing constant",
        ])
        .expect("positional path + body")
        .command
        {
            Commands::Context {
                for_thread: None,
                command: Some(ContextCommands::Set(args)),
            } => {
                assert_eq!(args.resolved_path(), Some("src/auth.rs"));
                assert_eq!(args.message.body.as_deref(), Some("keep timing constant"));
            }
            _ => panic!("expected context set"),
        }
        match Cli::try_parse_from([
            "heddle",
            "context",
            "set",
            "--path",
            "src/auth.rs",
            "--file",
            "note.md",
        ])
        .expect("file body")
        .command
        {
            Commands::Context {
                for_thread: None,
                command: Some(ContextCommands::Set(args)),
            } => {
                assert_eq!(args.resolved_path(), Some("src/auth.rs"));
                assert_eq!(
                    args.message.file.as_deref(),
                    Some(std::path::Path::new("note.md"))
                );
            }
            _ => panic!("expected context set"),
        }
        assert!(
            Cli::try_parse_from([
                "heddle",
                "context",
                "set",
                "--path",
                "src/auth.rs",
                "--from-file",
                "note.md",
            ])
            .is_err(),
            "--from-file is not an alias of --file"
        );
    }

    #[test]
    fn context_set_accepts_path_symbol_and_line_together() {
        match Cli::try_parse_from([
            "heddle",
            "context",
            "set",
            "--path",
            "src/auth.rs",
            "--symbol",
            "verify",
            "-m",
            "keep timing constant",
        ])
        .expect("set --path --symbol")
        .command
        {
            Commands::Context {
                for_thread: None,
                command: Some(ContextCommands::Set(args)),
            } => {
                assert_eq!(args.resolved_path(), Some("src/auth.rs"));
                assert_eq!(args.scope.symbol.as_deref(), Some("verify"));
                assert!(args.scope.line.is_none());
            }
            _ => panic!("expected context set"),
        }
        match Cli::try_parse_from([
            "heddle",
            "context",
            "set",
            "--path",
            "src/auth.rs",
            "--line",
            "12",
            "-m",
            "guard this row",
        ])
        .expect("set --path --line")
        .command
        {
            Commands::Context {
                for_thread: None,
                command: Some(ContextCommands::Set(args)),
            } => {
                assert_eq!(args.scope.line, Some(12));
                assert!(args.scope.symbol.is_none());
            }
            _ => panic!("expected context set"),
        }
        match Cli::try_parse_from([
            "heddle",
            "context",
            "set",
            "--path",
            "src/auth.rs",
            "--symbol",
            "verify",
            "--line",
            "12",
            "-m",
            "both",
        ])
        .expect("symbol and line together")
        .command
        {
            Commands::Context {
                for_thread: None,
                command: Some(ContextCommands::Set(args)),
            } => {
                assert_eq!(args.scope.symbol.as_deref(), Some("verify"));
                assert_eq!(args.scope.line, Some(12));
            }
            _ => panic!("expected context set"),
        }
        assert!(
            Cli::try_parse_from([
                "heddle",
                "context",
                "set",
                "--path",
                "src/auth.rs",
                "--scope",
                "symbol:verify",
                "-m",
                "legacy",
            ])
            .is_err(),
            "hidden --scope alias is removed"
        );
    }
}