llman 0.0.30

A tool for managing LLM application rules(prompts) ...
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
use crate::sdd::authoring;
use crate::sdd::change::archive;
use crate::sdd::change::freeze;
use crate::sdd::project::{init, interop};
use crate::sdd::shared::{list, show, validate};
use anyhow::Result;
use clap::{Args, Subcommand};
use std::path::PathBuf;

#[derive(Args)]
pub struct SddArgs {
    #[command(subcommand)]
    pub command: SddCommands,
}

#[derive(Args)]
pub struct SddSpecArgs {
    #[command(subcommand)]
    pub command: SddSpecCommands,
}

#[derive(Subcommand)]
pub enum SddSpecCommands {
    /// Generate a main spec skeleton for a capability
    Skeleton {
        /// Capability / spec id
        capability: String,
        /// Overwrite existing files
        #[arg(long)]
        force: bool,
    },
    /// Add a requirement row to a spec
    AddRequirement {
        /// Capability / spec id
        capability: String,
        /// Requirement id (req_id)
        req_id: String,
        /// Requirement title (human-facing)
        #[arg(long)]
        title: String,
        /// Requirement statement (MUST/SHALL)
        #[arg(long)]
        statement: String,
    },
    /// Add a scenario row to a spec
    AddScenario {
        /// Capability / spec id
        capability: String,
        /// Requirement id (req_id)
        req_id: String,
        /// Scenario id
        scenario_id: String,
        /// GIVEN (optional)
        #[arg(long, default_value = "")]
        given: String,
        /// WHEN (required)
        #[arg(long = "when")]
        when_: String,
        /// THEN (required)
        #[arg(long = "then")]
        then_: String,
    },
}

#[derive(Args)]
pub struct SddDeltaArgs {
    #[command(subcommand)]
    pub command: SddDeltaCommands,
}

#[derive(Subcommand)]
pub enum SddDeltaCommands {
    /// Generate a delta spec skeleton for a change + capability (no YAML frontmatter)
    Skeleton {
        /// Change id
        change_id: String,
        /// Capability / spec id
        capability: String,
        /// Overwrite existing files
        #[arg(long)]
        force: bool,
    },
    /// Add a delta op row
    AddOp {
        /// Change id
        change_id: String,
        /// Capability / spec id
        capability: String,
        /// Op: add_requirement|modify_requirement|remove_requirement|rename_requirement
        op: String,
        /// Requirement id (req_id)
        req_id: String,
        /// Title (required for add/modify)
        #[arg(long)]
        title: Option<String>,
        /// Statement (required for add/modify; MUST/SHALL)
        #[arg(long)]
        statement: Option<String>,
        /// Rename source (required for rename)
        #[arg(long)]
        from: Option<String>,
        /// Rename target (required for rename)
        #[arg(long)]
        to: Option<String>,
        /// Name hint (optional for remove)
        #[arg(long)]
        name: Option<String>,
    },
    /// Add a delta op scenario row (add/modify ops only)
    AddScenario {
        /// Change id
        change_id: String,
        /// Capability / spec id
        capability: String,
        /// Requirement id (req_id)
        req_id: String,
        /// Scenario id
        scenario_id: String,
        /// GIVEN (optional)
        #[arg(long, default_value = "")]
        given: String,
        /// WHEN (required)
        #[arg(long = "when")]
        when_: String,
        /// THEN (required)
        #[arg(long = "then")]
        then_: String,
    },
}

#[derive(Subcommand)]
pub enum SddCommands {
    /// Initialize llmanspec in your project (use --update to refresh existing)
    Init {
        /// Target path (default: current directory)
        path: Option<PathBuf>,
        /// Locale for templates (default: en)
        #[arg(long)]
        lang: Option<String>,
        /// Update existing llmanspec instead of creating new
        #[arg(long)]
        update: bool,
    },
    /// List changes or specs
    List {
        /// List specs instead of changes
        #[arg(long)]
        specs: bool,
        /// List changes explicitly (default)
        #[arg(long)]
        changes: bool,
        /// Sort order: "recent" (default) or "name"
        #[arg(long, default_value = "recent")]
        sort: String,
        /// Output as JSON
        #[arg(long)]
        json: bool,
        /// Emit compact JSON (no pretty whitespace). Requires `--json`.
        #[arg(long, requires = "json")]
        compact_json: bool,
    },
    /// Show a change or spec
    Show {
        /// Item name (change id or spec id)
        item: Option<String>,
        /// Output as JSON
        #[arg(long)]
        json: bool,
        /// Emit compact JSON (no pretty whitespace). Requires `--json`.
        #[arg(long, requires = "json")]
        compact_json: bool,
        /// Spec-only: output metadata only (no `requirements`). Requires `--json`.
        #[arg(long, requires = "json")]
        meta_only: bool,
        /// Specify item type when ambiguous: change|spec
        #[arg(long = "type")]
        item_type: Option<String>,
        /// Disable interactive prompts
        #[arg(long)]
        no_interactive: bool,
        /// Change-only: show only deltas (JSON only)
        #[arg(long)]
        deltas_only: bool,
        /// Change-only: alias for --deltas-only (deprecated)
        #[arg(long)]
        requirements_only: bool,
        /// Spec-only: show only requirements (JSON only)
        #[arg(long)]
        requirements: bool,
        /// Spec-only: exclude scenarios (JSON only)
        #[arg(long)]
        no_scenarios: bool,
        /// Spec-only: show specific requirement by ID (1-based)
        #[arg(short = 'r', long)]
        requirement: Option<usize>,
    },
    /// Validate changes and specs
    Validate {
        /// Item name (change id or spec id)
        item: Option<String>,
        /// Validate all changes and specs
        #[arg(long)]
        all: bool,
        /// Validate all changes
        #[arg(long)]
        changes: bool,
        /// Validate all specs
        #[arg(long)]
        specs: bool,
        /// Specify item type when ambiguous: change|spec
        #[arg(long = "type")]
        item_type: Option<String>,
        /// Enable strict validation mode
        #[arg(long)]
        strict: bool,
        /// Output validation results as JSON
        #[arg(long)]
        json: bool,
        /// Emit compact JSON (no pretty whitespace). Requires `--json`.
        #[arg(long, requires = "json")]
        compact_json: bool,
        /// Disable interactive prompts
        #[arg(long)]
        no_interactive: bool,
    },
    /// Archive workflow commands
    Archive {
        /// Legacy: change id (equivalent to `archive run <change-id>`)
        change: Option<String>,
        /// Legacy: skip updating specs
        #[arg(long)]
        skip_specs: bool,
        /// Legacy: dry run mode
        #[arg(long)]
        dry_run: bool,
        /// Legacy: force archive even if validation fails
        #[arg(long, hide = true)]
        force: bool,
        #[command(subcommand)]
        command: Option<ArchiveSubcommand>,
    },
    /// Import spec workflow content from external style
    Import {
        /// Source/target style (currently only: openspec)
        #[arg(long)]
        style: String,
        /// Project root path (default: current directory)
        path: Option<PathBuf>,
    },
    /// Export spec workflow content to external style
    Export {
        /// Source/target style (currently only: openspec)
        #[arg(long)]
        style: String,
        /// Project root path (default: current directory)
        path: Option<PathBuf>,
    },
    /// Spec authoring helpers
    Spec(SddSpecArgs),
    /// Delta authoring helpers
    Delta(SddDeltaArgs),
}

#[derive(Subcommand)]
pub enum ArchiveSubcommand {
    /// Archive a change and update main specs
    Run {
        /// Change id
        change: Option<String>,
        /// Skip updating specs
        #[arg(long)]
        skip_specs: bool,
        /// Dry run mode
        #[arg(long)]
        dry_run: bool,
        /// Force archive even if validation fails
        #[arg(long, hide = true)]
        force: bool,
    },
    /// Freeze archived change directories into a single cold-backup archive
    Freeze {
        /// Freeze entries older than this date (YYYY-MM-DD)
        #[arg(long)]
        before: Option<String>,
        /// Keep N most recent candidates unfrozen
        #[arg(long, default_value_t = 0)]
        keep_recent: usize,
        /// Dry run mode
        #[arg(long)]
        dry_run: bool,
    },
    /// Thaw archived changes from the cold-backup archive
    Thaw {
        /// Restore only these archived change directories (repeatable)
        #[arg(long)]
        change: Vec<String>,
        /// Override thaw destination path
        #[arg(long)]
        dest: Option<PathBuf>,
    },
}

pub fn run(args: &SddArgs) -> Result<()> {
    match &args.command {
        SddCommands::Init { path, lang, update } => init::run(
            path.as_deref().unwrap_or_else(|| std::path::Path::new(".")),
            lang.as_deref(),
            *update,
        ),
        SddCommands::List {
            specs,
            changes,
            sort,
            json,
            compact_json,
        } => list::run(list::ListArgs {
            specs: *specs,
            changes: *changes,
            sort: sort.clone(),
            json: *json,
            compact_json: *compact_json,
        }),
        SddCommands::Show {
            item,
            json,
            compact_json,
            meta_only,
            item_type,
            no_interactive,
            deltas_only,
            requirements_only,
            requirements,
            no_scenarios,
            requirement,
        } => show::run(show::ShowArgs {
            item: item.clone(),
            json: *json,
            compact_json: *compact_json,
            meta_only: *meta_only,
            item_type: item_type.clone(),
            no_interactive: *no_interactive,
            deltas_only: *deltas_only,
            requirements_only: *requirements_only,
            requirements: *requirements,
            no_scenarios: *no_scenarios,
            requirement: *requirement,
        }),
        SddCommands::Validate {
            item,
            all,
            changes,
            specs,
            item_type,
            strict,
            json,
            compact_json,
            no_interactive,
        } => validate::run(validate::ValidateArgs {
            item: item.clone(),
            all: *all,
            changes: *changes,
            specs: *specs,
            item_type: item_type.clone(),
            strict: *strict,
            json: *json,
            compact_json: *compact_json,
            no_interactive: *no_interactive,
        }),
        SddCommands::Archive {
            change,
            skip_specs,
            dry_run,
            force,
            command,
        } => match command {
            Some(ArchiveSubcommand::Run {
                change,
                skip_specs,
                dry_run,
                force,
            }) => archive::run(archive::ArchiveArgs {
                change: change.clone(),
                skip_specs: *skip_specs,
                dry_run: *dry_run,
                force: *force,
            }),
            Some(ArchiveSubcommand::Freeze {
                before,
                keep_recent,
                dry_run,
            }) => freeze::run_freeze(freeze::FreezeArgs {
                before: before.clone(),
                keep_recent: *keep_recent,
                dry_run: *dry_run,
            }),
            Some(ArchiveSubcommand::Thaw { change, dest }) => freeze::run_thaw(freeze::ThawArgs {
                change: change.clone(),
                dest: dest.clone(),
            }),
            None => archive::run(archive::ArchiveArgs {
                change: change.clone(),
                skip_specs: *skip_specs,
                dry_run: *dry_run,
                force: *force,
            }),
        },
        SddCommands::Import { style, path } => interop::run_import(interop::InteropArgs {
            style: style.clone(),
            path: path.clone(),
        }),
        SddCommands::Export { style, path } => interop::run_export(interop::InteropArgs {
            style: style.clone(),
            path: path.clone(),
        }),
        SddCommands::Spec(args) => match &args.command {
            SddSpecCommands::Skeleton { capability, force } => authoring::spec::run_skeleton(
                std::path::Path::new("."),
                authoring::spec::SpecSkeletonArgs {
                    capability: capability.clone(),
                    force: *force,
                },
            ),
            SddSpecCommands::AddRequirement {
                capability,
                req_id,
                title,
                statement,
            } => authoring::spec::run_add_requirement(
                std::path::Path::new("."),
                authoring::spec::SpecAddRequirementArgs {
                    capability: capability.clone(),
                    req_id: req_id.clone(),
                    title: title.clone(),
                    statement: statement.clone(),
                },
            ),
            SddSpecCommands::AddScenario {
                capability,
                req_id,
                scenario_id,
                given,
                when_,
                then_,
            } => authoring::spec::run_add_scenario(
                std::path::Path::new("."),
                authoring::spec::SpecAddScenarioArgs {
                    capability: capability.clone(),
                    req_id: req_id.clone(),
                    scenario_id: scenario_id.clone(),
                    given: given.clone(),
                    when_: when_.clone(),
                    then_: then_.clone(),
                },
            ),
        },
        SddCommands::Delta(args) => match &args.command {
            SddDeltaCommands::Skeleton {
                change_id,
                capability,
                force,
            } => authoring::delta::run_skeleton(
                std::path::Path::new("."),
                authoring::delta::DeltaSkeletonArgs {
                    change_id: change_id.clone(),
                    capability: capability.clone(),
                    force: *force,
                },
            ),
            SddDeltaCommands::AddOp {
                change_id,
                capability,
                op,
                req_id,
                title,
                statement,
                from,
                to,
                name,
            } => authoring::delta::run_add_op(
                std::path::Path::new("."),
                authoring::delta::DeltaAddOpArgs {
                    change_id: change_id.clone(),
                    capability: capability.clone(),
                    op: op.clone(),
                    req_id: req_id.clone(),
                    title: title.clone(),
                    statement: statement.clone(),
                    from: from.clone(),
                    to: to.clone(),
                    name: name.clone(),
                },
            ),
            SddDeltaCommands::AddScenario {
                change_id,
                capability,
                req_id,
                scenario_id,
                given,
                when_,
                then_,
            } => authoring::delta::run_add_scenario(
                std::path::Path::new("."),
                authoring::delta::DeltaAddScenarioArgs {
                    change_id: change_id.clone(),
                    capability: capability.clone(),
                    req_id: req_id.clone(),
                    scenario_id: scenario_id.clone(),
                    given: given.clone(),
                    when_: when_.clone(),
                    then_: then_.clone(),
                },
            ),
        },
    }
}