|
| 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) |
0 commit comments