Skip to content

Commit 121ce6a

Browse files
authored
add an AGENTS.md and skills to the project (#183)
1 parent 719c1cd commit 121ce6a

5 files changed

Lines changed: 100 additions & 15 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
name: add-command-spec
3+
description: Guide for adding new command completion specs to warp-command-signatures. Use when creating a new JSON spec for shell command completions, adding generators for dynamic suggestions, or extending existing command specs.
4+
---
5+
6+
# Adding a New Command Spec
7+
8+
## Steps
9+
10+
1. **Create JSON spec**: `command-signatures/json/<command>.json` following the [Fig completion spec schema](https://fig.io/docs/reference)
11+
2. **Create generator** (if needed): Add `command-signatures/src/generators/<command>.rs`, define a `generator()` function returning `CommandSignatureGenerators`, and register it in `generators/mod.rs`
12+
13+
## Style Guideline
14+
15+
Match the formatting conventions used in the command's `--help` output. For example, if the help text uses `UPPER_CASE` for positional argument names, use the same casing in the spec's argument `name` field.
16+
17+
## Validation
18+
19+
Run `cargo test` to verify the spec deserializes correctly and any referenced `generatorName`s exist.
20+
21+
## Reference Examples
22+
23+
- **Simple spec with generator**: `json/kill.json` + `src/generators/kill.rs` — minimal example showing `generatorName` usage for process and signal completions
24+
- **Complex spec with multiple generators**: `json/brew.json` + `src/generators/brew.rs` — shows subcommands, options, and multiple generators (`formulae_generator`, `services`, etc.)

.github/workflows/CI.yml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,12 @@ jobs:
1313
steps:
1414
- uses: actions/checkout@v3
1515
- name: Run cargo fmt
16-
uses: actions-rs/cargo@v1
17-
with:
18-
command: fmt
19-
args: -p warp-command-signatures -p warp-completion-metadata
16+
run: cargo fmt -p warp-command-signatures -p warp-completion-metadata --check
2017
- name: Run cargo clippy
21-
uses: actions-rs/cargo@v1
22-
with:
23-
command: clippy
24-
args: -p warp-command-signatures -p warp-completion-metadata --all-targets --all-features -- -D warnings
18+
run: cargo clippy -p warp-command-signatures -p warp-completion-metadata --all-targets --all-features -- -D warnings
2519
test:
2620
runs-on: ubuntu-latest
2721
steps:
2822
- uses: actions/checkout@v3
2923
- name: Run tests
30-
uses: actions-rs/cargo@v1
31-
with:
32-
command: test
33-
args: --verbose
24+
run: cargo test --verbose

AGENTS.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# AGENTS.md
2+
3+
This file provides guidance to agents when working with code in this repository.
4+
5+
## Overview
6+
7+
This repository provides command completion signatures ("specs") for Warp terminal. It contains two Rust crates:
8+
9+
- **`warp-command-signatures`**: The main library that embeds and exposes command specs. Used as a dependency by `warp-internal`.
10+
- **`warp-completion-metadata`**: Core types for signatures, arguments, options, generators, and the Fig-compatible JSON schema.
11+
12+
## Architecture
13+
14+
### Command Specs (JSON)
15+
16+
Specs are JSON files based on the [Fig completion spec schema](https://fig.io/docs/reference), but **Warp does not use Fig's JavaScript generators**. Instead:
17+
18+
- The `generatorName` field references Rust-based generators (see below)
19+
- Fig's `generateSpec` JavaScript field is present in some imported specs but is **ignored** by Warp
20+
- Static suggestions, templates (`filepaths`, `folders`), and subcommand/option definitions work as documented
21+
22+
| Location | Description |
23+
|----------|-------------|
24+
| `command-signatures/json/*.json` | Hand-written specs |
25+
| `command-signatures/json/autogenerated/powershell/*.json` | Auto-generated PowerShell cmdlet specs |
26+
| `command-signatures/json/overrides/powershell/*.json` | Hand-written overrides for autogenerated specs |
27+
28+
The `assets.rs` module uses `rust-embed` to flatten these directories into a single namespace at compile time, so callers just use `signature_by_name("git")`.
29+
30+
### Generators (Rust)
31+
32+
Generators produce dynamic completions by running shell commands. They are defined in `command-signatures/src/generators/` (one file per command or command family).
33+
34+
A generator consists of:
35+
1. A `GeneratorProcess` (either a static `CommandBuilder` or a function that builds a command from tokens)
36+
2. An `on_complete_callback` that parses the command output into `Suggestion`s
37+
38+
JSON specs reference generators via the `generatorName` field (e.g. `"generatorName": "branches"`). The mapping from name → Rust code is established in `generators/mod.rs` via `dynamic_command_signature_data()`.
39+
40+
Example from `brew.rs`:
41+
```rust
42+
CommandSignatureGenerators::new("brew")
43+
.add_generator(
44+
"formulae_generator", // Referenced in JSON as "generatorName": "formulae_generator"
45+
Generator::script(CommandBuilder::single_command("brew list -1"), |output| {
46+
output.trim().lines()
47+
.map(|line| Suggestion::with_description(line, "Installed formula"))
48+
.collect_unordered_results()
49+
}),
50+
)
51+
```
52+
53+
### Override System
54+
55+
For autogenerated specs (currently PowerShell only), hand-written augmentations live in `json/overrides/`. Overrides are matched by option name or argument index and merged at generation time. Only `template` and `generatorName` fields are currently supported for overrides.
56+
57+
## Key Types
58+
59+
- `Signature`: Defines a command/subcommand (name, options, arguments, subcommands)
60+
- `Argument`: A positional parameter with types (Template, Generator, or literal Suggestion)
61+
- `Opt`: A flag/option with optional arguments
62+
- `Generator`: Produces dynamic suggestions by running shell commands
63+
- `Template`: Built-in generators for files/folders
64+
65+
## Testing Invariants
66+
67+
Tests in `lib.rs` verify:
68+
- All `GeneratorName`s referenced in specs exist in `dynamic_command_signature_data()`
69+
- All JSON specs deserialize without error
70+
- Generator commands contain no unsafe (unquoted) newlines (required for TMUX control mode)

completion-metadata/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ pub enum Shell {
253253
/// A shell that can assume POSIX-compliant syntax.
254254
Posix,
255255
Powershell,
256-
CmdExe
256+
CmdExe,
257257
}
258258

259259
impl Shell {
@@ -262,7 +262,7 @@ impl Shell {
262262
match self {
263263
Shell::Posix => "2>/dev/null",
264264
Shell::Powershell => "2> $null",
265-
Shell::CmdExe => "2> NUL"
265+
Shell::CmdExe => "2> NUL",
266266
}
267267
}
268268
}

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[toolchain]
2-
channel = "1.82"
2+
channel = "1.85"
33
components = ["rustfmt", "clippy"]
44
targets = ["aarch64-apple-darwin", "x86_64-apple-darwin"]
55
profile = "minimal"

0 commit comments

Comments
 (0)