Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions crates/braid/src/agents-info.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ braid create "Fix the frobnicator" \
--deps discovered-from:<current-strand-id>
```

Prose your shell might mangle (a leading `/`, doubled backslashes, several
lines) can come from a file instead: `--description-file`, `--design-file`,
`--acceptance-criteria-file`, `--notes-file`, `--reason-file`, and
`comment -F`. `-` reads stdin. The text is stored byte for byte.

```sh
braid comment <id> -F note.md
braid close <id> --reason-file - < reason.txt
```

## Command reference

| command | purpose |
Expand All @@ -73,14 +83,14 @@ braid create "Fix the frobnicator" \
| `braid list [--status S] [--all] [--label L]... [--assignee A] [--type T] [--priority N]... [--json]` | open (non-closed) strands; `--all` includes closed. Same field filters as `ready` |
| `braid show <id> [--json]` | one strand (unique id fragments work: `braid show 6j42`) |
| `braid search <text> [--json]` | case-insensitive substring over titles, prose, labels, comments |
| `braid create <title> [flags]` | new strand; prints its id. Flags: `--description --type --priority --label --slug --assignee --deps --json`. `--deps <type>:<target-id>` attaches dependencies atomically (repeatable and comma-separated; the new strand depends on each target). A missing target fails the create, like `dep add` |
| `braid update <id> [flags]` | change fields: `--title --description --design --acceptance-criteria --notes --status --priority --type --assignee --external-ref --add-label --remove-label`; empty string clears |
| `braid close <id>... [--reason R] [--force]` | close; refuses if open children unless `--force` |
| `braid create <title> [flags]` | new strand; prints its id. Flags: `--description --description-file --type --priority --label --slug --assignee --deps --json`. `--deps <type>:<target-id>` attaches dependencies atomically (repeatable and comma-separated; the new strand depends on each target). A missing target fails the create, like `dep add` |
| `braid update <id> [flags]` | change fields: `--title --description --design --acceptance-criteria --notes` (each prose field also takes `--<field>-file PATH`), `--status --priority --type --assignee --external-ref --add-label --remove-label`; empty string clears |
| `braid close <id>... [--reason R \| --reason-file PATH] [--force]` | close; refuses if open children unless `--force` |
| `braid reopen <id>...` | reopen closed strands |
| `braid defer <id>... [--until W]` | park strands. `--until` takes RFC 3339 (`2026-07-01T09:00:00Z`), a date (`2026-07-01`), or a duration (`36h`, `7d`, `2w`); once it passes, the strand counts as ready again (no daemon — readers compute the wake). Without `--until` it sleeps until `undefer` |
| `braid undefer <id>...` | wake deferred strands now (status back to `open`) |
| `braid delete <id>... [--force]` | remove strands entirely. Prefer `close` — a delete wins over concurrent edits and cannot be undone; `--force` needed if other strands reference the target |
| `braid comment <id> <text>` | append a comment |
| `braid comment <id> (<text> \| -F PATH)` | append a comment; `-F`/`--file` reads it from a file |
| `braid dep add <id> <target> [--type T]` | `<id>` depends on `<target>`; default type `blocks` |
| `braid dep remove <id> <target> [--type T]` | remove dependency |
| `braid dep list <id>` | dependencies in both directions |
Expand Down
177 changes: 136 additions & 41 deletions crates/braid/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
use std::io::Read;
use std::path::{Path, PathBuf};

use anyhow::{Context, bail};
use clap::{Parser, Subcommand};

use braid::commands;
Expand All @@ -10,6 +14,8 @@ struct Cli {
}

#[derive(Subcommand)]
// parsed once per process, so the variant size difference costs nothing
#[allow(clippy::large_enum_variant)]
enum Cmd {
/// Create a new skein (or join an existing one) and write .braid.toml
Init {
Expand All @@ -34,6 +40,9 @@ enum Cmd {
title: String,
#[arg(short, long)]
description: Option<String>,
/// Read the description from a file (`-` for stdin), byte for byte
#[arg(long, value_name = "PATH", conflicts_with = "description")]
description_file: Option<PathBuf>,
/// Issue type: task|bug|feature|epic|chore|docs|question
#[arg(short = 't', long = "type", default_value = "task")]
issue_type: String,
Expand Down Expand Up @@ -94,12 +103,24 @@ enum Cmd {
title: Option<String>,
#[arg(short, long)]
description: Option<String>,
/// Read the description from a file (`-` for stdin), byte for byte
#[arg(long, value_name = "PATH", conflicts_with = "description")]
description_file: Option<PathBuf>,
#[arg(long)]
design: Option<String>,
/// Read the design from a file (`-` for stdin), byte for byte
#[arg(long, value_name = "PATH", conflicts_with = "design")]
design_file: Option<PathBuf>,
#[arg(long)]
acceptance_criteria: Option<String>,
/// Read the acceptance criteria from a file (`-` for stdin), byte for byte
#[arg(long, value_name = "PATH", conflicts_with = "acceptance_criteria")]
acceptance_criteria_file: Option<PathBuf>,
#[arg(long)]
notes: Option<String>,
/// Read the notes from a file (`-` for stdin), byte for byte
#[arg(long, value_name = "PATH", conflicts_with = "notes")]
notes_file: Option<PathBuf>,
/// open|in_progress|blocked|deferred|closed
#[arg(long)]
status: Option<String>,
Expand All @@ -126,6 +147,9 @@ enum Cmd {
ids: Vec<String>,
#[arg(long)]
reason: Option<String>,
/// Read the reason from a file (`-` for stdin), byte for byte
#[arg(long, value_name = "PATH", conflicts_with = "reason")]
reason_file: Option<PathBuf>,
/// Close even if the strand still has open children
#[arg(long)]
force: bool,
Expand Down Expand Up @@ -160,7 +184,19 @@ enum Cmd {
force: bool,
},
/// Add a comment to a strand; prints the comment id
Comment { id: String, text: String },
Comment {
id: String,
text: Option<String>,
/// Read the comment from a file (`-` for stdin), byte for byte
#[arg(
short = 'F',
long,
value_name = "PATH",
conflicts_with = "text",
required_unless_present = "text"
)]
file: Option<PathBuf>,
},
/// Manage dependencies between strands
Dep {
#[command(subcommand)]
Expand Down Expand Up @@ -291,6 +327,33 @@ enum DepCmd {
Cycles,
}

/// Fill each prose field from its `--<field>-file` PATH, if given. `-` reads
/// stdin, which only one field per command can use. Text is kept byte for
/// byte (no trimming, no newline translation) but must be UTF-8.
fn read_text_files(fields: Vec<(&mut Option<String>, Option<PathBuf>)>) -> anyhow::Result<()> {
let stdin = Path::new("-");
if fields.iter().filter(|(_, file)| file.as_deref() == Some(stdin)).count() > 1 {
bail!("only one --*-file flag can read from stdin (-)");
}
for (field, file) in fields {
let Some(path) = file else { continue };
let (bytes, source) = if path == stdin {
let mut buf = Vec::new();
std::io::stdin().read_to_end(&mut buf).context("cannot read stdin")?;
(buf, "stdin".to_string())
} else {
let bytes =
std::fs::read(&path).with_context(|| format!("cannot read {}", path.display()))?;
(bytes, path.display().to_string())
};
*field = Some(
String::from_utf8(bytes)
.map_err(|e| anyhow::anyhow!("{source} is not valid UTF-8: {e}"))?,
);
}
Ok(())
}

#[tokio::main]
async fn main() {
let cli = Cli::parse();
Expand All @@ -309,7 +372,8 @@ async fn main() {
}
Cmd::Create {
title,
description,
mut description,
description_file,
issue_type,
priority,
label,
Expand All @@ -318,20 +382,24 @@ async fn main() {
deps,
json,
} => {
commands::create(
&cwd,
commands::CreateOpts {
title,
description,
issue_type,
priority,
labels: label,
slug,
assignee,
deps,
json,
},
)
async {
read_text_files(vec![(&mut description, description_file)])?;
commands::create(
&cwd,
commands::CreateOpts {
title,
description,
issue_type,
priority,
labels: label,
slug,
assignee,
deps,
json,
},
)
.await
}
.await
}
Cmd::Show { id, json } => commands::show(&cwd, &id, json).await,
Expand All @@ -343,10 +411,14 @@ async fn main() {
Cmd::Update {
id,
title,
description,
design,
acceptance_criteria,
notes,
mut description,
description_file,
mut design,
design_file,
mut acceptance_criteria,
acceptance_criteria_file,
mut notes,
notes_file,
status,
priority,
issue_type,
Expand All @@ -356,33 +428,56 @@ async fn main() {
remove_label,
json,
} => {
commands::update(
&cwd,
&id,
commands::UpdateOpts {
title,
description,
design,
acceptance_criteria,
notes,
status,
priority,
issue_type,
assignee,
external_ref,
add_labels: add_label,
remove_labels: remove_label,
json,
},
)
async {
read_text_files(vec![
(&mut description, description_file),
(&mut design, design_file),
(&mut acceptance_criteria, acceptance_criteria_file),
(&mut notes, notes_file),
])?;
commands::update(
&cwd,
&id,
commands::UpdateOpts {
title,
description,
design,
acceptance_criteria,
notes,
status,
priority,
issue_type,
assignee,
external_ref,
add_labels: add_label,
remove_labels: remove_label,
json,
},
)
.await
}
.await
}
Cmd::Close { ids, mut reason, reason_file, force } => {
async {
read_text_files(vec![(&mut reason, reason_file)])?;
commands::close(&cwd, &ids, reason, force).await
}
.await
}
Cmd::Close { ids, reason, force } => commands::close(&cwd, &ids, reason, force).await,
Cmd::Reopen { ids } => commands::reopen(&cwd, &ids).await,
Cmd::Defer { ids, until } => commands::defer(&cwd, &ids, until).await,
Cmd::Undefer { ids } => commands::undefer(&cwd, &ids).await,
Cmd::Delete { ids, force } => commands::delete(&cwd, &ids, force).await,
Cmd::Comment { id, text } => commands::comment(&cwd, &id, &text).await,
Cmd::Comment { id, mut text, file } => {
async {
read_text_files(vec![(&mut text, file)])?;
// clap requires TEXT or --file, so one of them filled `text`
let text = text.unwrap_or_default();
commands::comment(&cwd, &id, &text).await
}
.await
}
Cmd::Dep { cmd } => match cmd {
DepCmd::Add { issue, target, dep_type } => {
commands::dep_add(&cwd, &issue, &target, &dep_type).await
Expand Down
Loading
Loading