sara-tasks 0.3.0

Sara — folder-aware task manager (successor to tk)
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
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
use clap::{Parser, Subcommand};
use clap_complete::engine::ArgValueCandidates;

use crate::completion::{projects, task_ids};

#[derive(Debug, Parser)]
#[command(
    name = "sara",
    about = "Sara — folder-aware task manager (successor to tk)",
    version
)]
pub struct Cli {
    #[command(subcommand)]
    pub command: Command,
}

#[derive(Debug, Subcommand)]
pub enum Command {
    /// Initialize (or update) the project profile for the current folder
    Init {
        /// Override the project name
        #[arg(long)]
        name: Option<String>,
        /// Set the project goal directly (skips prompt)
        #[arg(long)]
        goal: Option<String>,
        /// Accept all detected values non-interactively
        #[arg(short, long)]
        yes: bool,
    },

    /// Git project profile commands (deprecated: use `sara init`)
    #[command(hide = true)]
    Project {
        #[command(subcommand)]
        action: ProjectAction,
    },

    /// Nuke a project: delete all its tasks and profile (run `sara init` to recreate)
    Reset {
        /// Project to reset (defaults to the current project)
        #[arg(long, short, add = ArgValueCandidates::new(projects))]
        project: Option<String>,
        /// Skip the confirmation prompt
        #[arg(short, long)]
        yes: bool,
    },

    /// Add a task
    Add {
        #[arg(trailing_var_arg = true)]
        words: Vec<String>,
        /// Override project
        #[arg(long, short, add = ArgValueCandidates::new(projects))]
        project: Option<String>,
        /// Override priority (H/M/L)
        #[arg(long)]
        priority: Option<String>,
        /// Tag (repeatable)
        #[arg(long, short)]
        tag: Vec<String>,
        /// Accept all values without the TUI review form
        #[arg(short, long)]
        yes: bool,
        /// Recurrence interval: daily, weekly, monthly, 2w, 3d, 1m, etc.
        #[arg(long, visible_alias = "recur")]
        every: Option<String>,
    },

    /// Show full details of a task
    Info {
        /// Task id or uuid prefix
        #[arg(add = ArgValueCandidates::new(task_ids))]
        id: String,
        /// Emit the full guide as JSON (for agents/scripts)
        #[arg(long)]
        json: bool,
    },

    /// Add a comment, note, or anchored feedback to a task
    #[command(visible_alias = "comment")]
    Annotate {
        /// Task id or uuid prefix
        #[arg(add = ArgValueCandidates::new(task_ids))]
        id: String,
        /// The comment / note text or URL
        #[arg(trailing_var_arg = true, required = true)]
        text: Vec<String>,
        /// Note kind: comment|finding|thought|constraint|assumption|open_question|non_goal|decision|risk|pattern
        #[arg(long)]
        kind: Option<String>,
        /// Author of the note: human|ai
        #[arg(long)]
        author: Option<String>,
        /// Anchor the comment to a guide element: step:N, acceptance:N, anchor:ID, note:ID
        #[arg(long)]
        on: Option<String>,
        /// Flag the targeted element for reconsideration
        #[arg(long)]
        reconsider: bool,
    },

    /// Remove a comment by its number (see `sara info`)
    #[command(visible_alias = "uncomment")]
    Denotate {
        /// Comment id (the number shown in the detail view)
        annotation_id: i64,
    },

    /// Attach a file path or URL to a task (URLs become links)
    #[command(visible_alias = "pr")]
    Attach {
        /// Task id or uuid prefix
        #[arg(add = ArgValueCandidates::new(task_ids))]
        id: String,
        /// File path (relative to project) or URL
        path: String,
        /// Why this file matters (turns it into a code anchor)
        #[arg(long)]
        reason: Option<String>,
        /// Specific symbol (function/type) to change
        #[arg(long)]
        symbol: Option<String>,
        /// Line range, e.g. 10:57
        #[arg(long)]
        lines: Option<String>,
        /// Provenance: human (default) or ai (records as a suggestion)
        #[arg(long)]
        source: Option<String>,
    },

    /// Add a link (e.g. a GitHub PR) to a task
    Link {
        /// Task id or uuid prefix
        #[arg(add = ArgValueCandidates::new(task_ids))]
        id: String,
        /// The URL to link
        url: String,
        /// Optional display label (auto-derived for GitHub PRs/issues)
        #[arg(long)]
        label: Option<String>,
    },

    /// Remove a link by its number (see `sara info`)
    Unlink {
        /// Link id (the number shown in the detail view)
        link_id: i64,
    },

    /// Show all tasks for a project as a board (pending + completed with strikethrough)
    Board {
        /// Project name (defaults to current git project)
        #[arg(long, short)]
        project: Option<String>,
    },

    /// List pending tasks
    List {
        /// Show tasks for all projects (default: current project only)
        #[arg(short, long)]
        all: bool,
        /// Filter by project name
        #[arg(long, short, add = ArgValueCandidates::new(projects))]
        project: Option<String>,
        /// Emit the list as JSON
        #[arg(long)]
        json: bool,
    },

    /// Start working on a task (begins time tracking, marks it active)
    Start {
        /// Task id or uuid prefix
        #[arg(add = ArgValueCandidates::new(task_ids))]
        id: String,
    },

    /// Stop working on a task (accumulates time spent)
    Stop {
        /// Task id or uuid prefix
        #[arg(add = ArgValueCandidates::new(task_ids))]
        id: String,
    },

    /// Mark a task as done
    Done {
        /// Task id or uuid prefix
        #[arg(add = ArgValueCandidates::new(task_ids))]
        id: String,
        /// Force-complete even if blocked
        #[arg(long)]
        force: bool,
    },

    /// Modify a task (opens the review form pre-filled)
    Modify {
        /// Task id or uuid prefix
        #[arg(add = ArgValueCandidates::new(task_ids))]
        id: String,
    },

    /// Move a task to another project (non-interactive)
    #[command(visible_alias = "mv")]
    Move {
        /// Task id or uuid prefix
        id: String,
        /// Target project name
        project: String,
    },

    /// Export a task (and its dependency closure) to a portable copy-paste blob
    Export {
        /// Task id or uuid prefix
        #[arg(add = ArgValueCandidates::new(task_ids))]
        id: String,
        /// Write the blob to a file instead of stdout
        #[arg(short, long)]
        output: Option<std::path::PathBuf>,
    },

    /// Import a task bundle from a portable blob (file, argument, or stdin)
    Import {
        /// Path to a blob file, or the blob string itself; omit to read stdin
        source: Option<String>,
        /// Reassign every imported task to this project
        #[arg(long, short, add = ArgValueCandidates::new(projects))]
        project: Option<String>,
    },

    /// Delete a task (soft-delete)
    Delete {
        /// Task id or uuid prefix
        #[arg(add = ArgValueCandidates::new(task_ids))]
        id: String,
        /// Skip confirmation
        #[arg(short, long)]
        yes: bool,
    },

    /// Manage task dependencies
    Dep {
        /// Task id or uuid prefix
        #[arg(add = ArgValueCandidates::new(task_ids))]
        id: String,
        #[command(subcommand)]
        action: DepAction,
    },

    /// Tie the currently active git branch to a task (snapshot on sara stop)
    Addbranch {
        /// Task id or uuid prefix
        #[arg(add = ArgValueCandidates::new(task_ids))]
        id: String,
        /// Remove the tied branch
        #[arg(long)]
        clear: bool,
    },

    /// Revert the most recent command
    Undo,

    /// Add a checklist item / step / acceptance criterion to a task
    #[clap(name = "check")]
    Check {
        /// Task ID
        #[arg(add = ArgValueCandidates::new(task_ids))]
        id: String,
        /// Step / criterion text
        text: String,
        /// Fuller "what this step does" intent
        #[arg(long)]
        intent: Option<String>,
        /// Item kind: step (default) or acceptance
        #[arg(long)]
        kind: Option<String>,
        /// Provenance: human (default) or ai
        #[arg(long)]
        source: Option<String>,
        /// Command that verifies this step / criterion
        #[arg(long)]
        verify: Option<String>,
    },

    /// Show the next not-done step (the execution cursor)
    Next {
        /// Task id or uuid prefix
        id: String,
        /// Emit as JSON
        #[arg(long)]
        json: bool,
    },

    /// Show ordered steps, optionally up to checkmark N ("implement until N")
    Steps {
        /// Task id or uuid prefix
        id: String,
        /// Only show steps 1..=N
        #[arg(long)]
        until: Option<usize>,
        /// Emit as JSON
        #[arg(long)]
        json: bool,
    },

    /// Mark steps done/undone with an execution record
    Step {
        #[command(subcommand)]
        action: StepAction,
    },

    /// Print (and optionally run) verification commands / acceptance criteria
    Verify {
        /// Task id or uuid prefix
        id: String,
        /// Only verify step N
        #[arg(long)]
        step: Option<usize>,
        /// Actually run the verification command(s)
        #[arg(long)]
        run: bool,
    },

    /// Cross-task memory: keyword search across tasks/findings/anchors
    Recall {
        /// Search query
        #[arg(trailing_var_arg = true, required = true)]
        query: Vec<String>,
        /// Max results
        #[arg(long, default_value_t = 20)]
        limit: i64,
        /// Emit as JSON
        #[arg(long)]
        json: bool,
    },

    /// Set the originating assignment/prompt for a task
    Assignment {
        /// Task id or uuid prefix
        id: String,
        /// The assignment text
        #[arg(trailing_var_arg = true, required = true)]
        text: Vec<String>,
    },

    /// Set the rationale (why this task exists)
    Rationale {
        /// Task id or uuid prefix
        id: String,
        /// The rationale text
        #[arg(trailing_var_arg = true, required = true)]
        text: Vec<String>,
    },

    /// Stamp the guide as validated against the current git HEAD
    Validate {
        /// Task id or uuid prefix
        id: String,
    },

    /// List open feedback (human comments) for a task
    Feedback {
        /// Task id or uuid prefix
        id: String,
        /// Emit as JSON
        #[arg(long)]
        json: bool,
    },

    /// Resolve a piece of feedback by its id
    Resolve {
        /// Feedback (annotation) id
        feedback_id: i64,
    },

    /// Atomic plan ingestion and dependency-ordered briefings
    Plan {
        #[command(subcommand)]
        action: PlanAction,
    },

    /// Show a GitHub-style activity heatmap
    #[clap(name = "activity", alias = "heat")]
    Activity {
        /// Limit to a specific project (defaults to current git project)
        #[arg(long, short, add = ArgValueCandidates::new(projects))]
        project: Option<String>,
        /// Show activity across all projects
        #[arg(long, short)]
        all: bool,
    },

    /// Print config and data directory paths
    Paths,

    /// Generate shell completions
    Completions {
        /// Shell type
        #[arg(value_enum)]
        shell: clap_complete::Shell,
    },
}

#[derive(Debug, Subcommand)]
pub enum ProjectAction {
    /// Initialize (or update) the current git project profile
    Init {
        /// Override the project name
        #[arg(long)]
        name: Option<String>,
        /// Set the project goal directly (skips prompt)
        #[arg(long)]
        goal: Option<String>,
        /// Accept all detected values non-interactively
        #[arg(short, long)]
        yes: bool,
    },
}

#[derive(Debug, Subcommand)]
pub enum StepAction {
    /// Mark step N done, recording an execution result + commit
    Done {
        /// Task id or uuid prefix
        id: String,
        /// 1-based step number
        n: usize,
        /// Execution result / note
        #[arg(long)]
        result: Option<String>,
        /// Item kind: step (default) or acceptance
        #[arg(long)]
        kind: Option<String>,
    },
    /// Reopen step N
    Undone {
        /// Task id or uuid prefix
        id: String,
        /// 1-based step number
        n: usize,
        /// Item kind: step (default) or acceptance
        #[arg(long)]
        kind: Option<String>,
    },
}

#[derive(Debug, Subcommand)]
pub enum PlanAction {
    /// Ingest a whole task graph from JSON (file path, or '-' for stdin)
    Import {
        /// Path to the plan JSON file, or '-' to read stdin
        source: String,
    },
    /// Emit a dependency-ordered briefing for a task and its blockers
    Show {
        /// Task id or uuid prefix
        id: String,
        /// Emit as JSON
        #[arg(long)]
        json: bool,
    },
}

#[derive(Debug, Subcommand)]
pub enum DepAction {
    /// Add a dependency: task depends ON another task
    On {
        /// The id or uuid prefix of the task this task depends on
        other: String,
    },
    /// Remove a dependency
    Off {
        /// The id or uuid prefix to remove as a dependency
        other: String,
    },
    /// List dependencies of this task
    List,
}

#[cfg(test)]
mod tests {
    use super::*;
    use clap::{CommandFactory, Parser};

    #[test]
    fn cli_name_is_sara() {
        let cmd = Cli::command();
        assert_eq!(cmd.get_name(), "sara");
    }

    #[test]
    fn cli_has_core_task_commands() {
        let cmd = Cli::command();
        for name in ["add", "list", "info", "done", "undo"] {
            assert!(
                cmd.find_subcommand(name).is_some(),
                "missing subcommand: {name}"
            );
        }
    }

    #[test]
    fn list_accepts_short_and_long_project_flag() {
        for args in [
            ["sara", "list", "-p", "web"],
            ["sara", "list", "--project", "web"],
        ] {
            let cli = Cli::try_parse_from(args).expect("list should parse a project flag");
            match cli.command {
                Command::List { project, .. } => {
                    assert_eq!(project.as_deref(), Some("web"), "{args:?}");
                }
                other => panic!("expected List, got {other:?}"),
            }
        }
    }

    #[test]
    fn project_filter_short_flag_is_consistent_across_commands() {
        // `-p` must mean `--project` on every command exposing a project filter.
        assert!(Cli::try_parse_from(["sara", "list", "-p", "x"]).is_ok());
        assert!(Cli::try_parse_from(["sara", "reset", "-p", "x"]).is_ok());
        assert!(Cli::try_parse_from(["sara", "activity", "-p", "x"]).is_ok());
        // `add` takes `-p` before the trailing description.
        let cli = Cli::try_parse_from(["sara", "add", "-p", "x", "do", "thing"]).unwrap();
        match cli.command {
            Command::Add { project, words, .. } => {
                assert_eq!(project.as_deref(), Some("x"));
                assert_eq!(words, vec!["do".to_string(), "thing".to_string()]);
            }
            other => panic!("expected Add, got {other:?}"),
        }
    }
}