Skip to content

Commit bb23580

Browse files
committed
Enhance CLI documentation to include support for the new cursor-agent provider. Update command options and examples in ai-commands.md, contract-commands.md, and first-contract.md. Modify API key resolution and configuration details to reflect the addition of CURSOR_API_KEY and MODAL_AI_CURSOR_AGENT. Update relevant Rust code to handle cursor-agent interactions and improve error handling for unsupported options.
1 parent 8e15e56 commit bb23580

18 files changed

Lines changed: 456 additions & 36 deletions

File tree

‎docs/cli/ai-commands.md‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ Configure the LLM used by `modal ai suggest-rule`. Config is stored at
1111
## Set Provider
1212

1313
```bash
14-
modal ai set --provider openai|anthropic|grok|bedrock|ollama [--model] [--base-url] [--api-key] [--region] [--save-key]
14+
modal ai set --provider openai|anthropic|grok|bedrock|ollama|cursor-agent [--model] [--base-url] [--api-key] [--region] [--save-key]
1515
```
1616

1717
**Options:**
1818
| Option | Description |
1919
|--------|-------------|
20-
| `--provider <PROVIDER>` | `openai`, `anthropic`, `grok`, `bedrock`, or `ollama` |
20+
| `--provider <PROVIDER>` | `openai`, `anthropic`, `grok`, `bedrock`, `ollama`, or `cursor-agent` |
2121
| `--model <MODEL>` | Model id (provider default if omitted) |
2222
| `--base-url <BASE_URL>` | API base URL (openai, anthropic, grok, ollama) |
2323
| `--region <REGION>` | AWS region (bedrock) |
@@ -30,12 +30,16 @@ modal ai set --provider anthropic
3030
modal ai set --provider grok
3131
modal ai set --provider bedrock --region us-east-1
3232
modal ai set --provider ollama
33+
modal ai set --provider cursor-agent
3334
```
3435

3536
`--save-key` is only for openai, anthropic, and grok. Bedrock uses the AWS
3637
credential chain (`AWS_ACCESS_KEY_ID` / `AWS_SECRET_ACCESS_KEY` /
3738
`AWS_SESSION_TOKEN`, a shared credentials file, or an instance role). Do not
3839
persist AWS secrets in `ai.json`. Ollama needs no API key by default.
40+
`cursor-agent` uses the Cursor CLI (`agent` or `cursor-agent` on `PATH`):
41+
run `agent login`, or set `CURSOR_API_KEY`. Override the binary with
42+
`MODAL_AI_CURSOR_AGENT`.
3943

4044
Defaults:
4145

@@ -46,12 +50,13 @@ Defaults:
4650
| grok | `https://api.x.ai` | `grok-3` |
4751
| bedrock | region `us-east-1` | `anthropic.claude-sonnet-4-20250514-v1:0` |
4852
| ollama | `http://127.0.0.1:11434` | `llama3.2` |
53+
| cursor-agent | Cursor CLI in the contract directory | account default (`auto`) |
4954

5055
API key resolution, first match wins:
5156

5257
1. `--api-key` on `set` / `suggest-rule`
5358
2. `MODAL_AI_API_KEY`
54-
3. Provider env: `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, `XAI_API_KEY`
59+
3. Provider env: `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, `XAI_API_KEY`, `CURSOR_API_KEY`
5560
4. Optional API key saved in `ai.json` only with `--save-key`
5661

5762
## Show
@@ -61,7 +66,7 @@ modal ai show
6166
```
6267

6368
Prints the configured provider, model, and a redacted API key. If nothing is
64-
configured, run `modal ai set --provider openai|anthropic|grok|bedrock|ollama`.
69+
configured, run `modal ai set --provider openai|anthropic|grok|bedrock|ollama|cursor-agent`.
6570

6671
## Unset
6772

@@ -81,8 +86,14 @@ Calls the configured provider and prints one Modality formula for
8186
`modal add-rule`. If no provider is configured, the command fails with a
8287
hint to run `modal ai set`.
8388

89+
With `--provider cursor-agent`, `suggest-rule` runs the Cursor CLI in the
90+
contract directory (`--dir` or the current directory). The default is
91+
`--print`: a one-shot formula on stdout. Pass `--interactive` for an Ask-mode
92+
session so the agent can read `state/`, `rules/`, and `model/`.
93+
8494
```bash
8595
modal ai suggest-rule "after this commit either alice or bob must sign"
96+
modal ai suggest-rule --interactive "after this commit either alice or bob must sign"
8697
```
8798

8899
```

‎docs/cli/contract-commands.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ modal c ai suggest-rule <PROMPT>
197197

198198
Suggest a Modality rule formula from a plain-language prompt. Use the printed
199199
formula with `modal c add-rule`. If no provider is configured, the command
200-
fails with a hint to run `modal ai set --provider openai|anthropic|grok|bedrock|ollama`.
200+
fails with a hint to run `modal ai set --provider openai|anthropic|grok|bedrock|ollama|cursor-agent`.
201201

202202
```bash
203203
modal c ai suggest-rule "after this commit either alice or bob must sign"

‎docs/cli/index.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,5 @@ modal predicate test signed_by --data '{"path":"/alice.id","signature":"..."}'
141141
| `OPENAI_API_KEY` | OpenAI API key | — |
142142
| `ANTHROPIC_API_KEY` | Anthropic API key | — |
143143
| `XAI_API_KEY` | xAI / Grok API key | — |
144+
| `CURSOR_API_KEY` | Cursor Agent API key | — |
145+
| `MODAL_AI_CURSOR_AGENT` | Path to the Cursor `agent` CLI | `agent` or `cursor-agent` on `PATH` |

‎docs/getting-started/first-contract.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ Bob. You still get one bootstrap commit that installs their identities and the
140140
first model. After that, unsigned updates are refused.
141141

142142
You don't need to know Modality syntax yet. Point Modal at your choice of AI
143-
first — OpenAI, Anthropic, Grok, AWS Bedrock, or a local Ollama model. See
143+
first — OpenAI, Anthropic, Grok, AWS Bedrock, a local Ollama model, or the
144+
Cursor Agent CLI in this contract directory. See
144145
[AI Commands](/docs/cli/ai-commands) for `modal ai set`. Then ask the CLI to
145146
suggest a rule:
146147

‎rust/modal-cli-ai/src/complete.rs‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,29 @@ use anyhow::Result;
22
use std::path::Path;
33

44
use crate::config::{self, AiConfig};
5+
use crate::cursor_agent::{self, SuggestPrintMode};
56
use crate::providers::{self, JsonPoster, ReqwestPoster};
67

78
pub async fn suggest_rule(
89
prompt: &str,
910
api_key: Option<&str>,
1011
contract_dir: Option<&Path>,
12+
) -> Result<String> {
13+
suggest_rule_mode(prompt, api_key, contract_dir, SuggestPrintMode::Print).await
14+
}
15+
16+
pub async fn suggest_rule_mode(
17+
prompt: &str,
18+
api_key: Option<&str>,
19+
contract_dir: Option<&Path>,
20+
print_mode: SuggestPrintMode,
1121
) -> Result<String> {
1222
let config = config::load_required()?;
23+
if config.provider()? == crate::config::Provider::CursorAgent {
24+
let ids = contract_dir.map(collect_id_paths).unwrap_or_default();
25+
return cursor_agent::suggest(&config, prompt, api_key, contract_dir, &ids, print_mode)
26+
.await;
27+
}
1328
let poster = ReqwestPoster::new()?;
1429
suggest_rule_with(&config, prompt, api_key, contract_dir, &poster).await
1530
}
@@ -45,7 +60,7 @@ fn build_user_prompt(prompt: &str, contract_dir: Option<&Path>) -> String {
4560
out
4661
}
4762

48-
fn collect_id_paths(contract_dir: &Path) -> Vec<String> {
63+
pub(crate) fn collect_id_paths(contract_dir: &Path) -> Vec<String> {
4964
let state_dir = contract_dir.join("state");
5065
let mut paths = Vec::new();
5166
collect_id_paths_from(&state_dir, &state_dir, &mut paths);

‎rust/modal-cli-ai/src/config.rs‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ pub enum Provider {
1212
Grok,
1313
Bedrock,
1414
Ollama,
15+
#[serde(rename = "cursor-agent")]
16+
#[value(name = "cursor-agent")]
17+
CursorAgent,
1518
}
1619

1720
impl Provider {
@@ -22,6 +25,7 @@ impl Provider {
2225
Provider::Grok => "grok",
2326
Provider::Bedrock => "bedrock",
2427
Provider::Ollama => "ollama",
28+
Provider::CursorAgent => "cursor-agent",
2529
}
2630
}
2731

@@ -32,6 +36,7 @@ impl Provider {
3236
Provider::Grok => "grok-3",
3337
Provider::Bedrock => "anthropic.claude-sonnet-4-20250514-v1:0",
3438
Provider::Ollama => "llama3.2",
39+
Provider::CursorAgent => "auto",
3540
}
3641
}
3742

@@ -42,6 +47,7 @@ impl Provider {
4247
Provider::Grok => Some("https://api.x.ai"),
4348
Provider::Bedrock => None,
4449
Provider::Ollama => Some("http://127.0.0.1:11434"),
50+
Provider::CursorAgent => None,
4551
}
4652
}
4753

@@ -50,11 +56,21 @@ impl Provider {
5056
Provider::Openai => Some("OPENAI_API_KEY"),
5157
Provider::Anthropic => Some("ANTHROPIC_API_KEY"),
5258
Provider::Grok => Some("XAI_API_KEY"),
59+
Provider::CursorAgent => Some("CURSOR_API_KEY"),
5360
Provider::Bedrock | Provider::Ollama => None,
5461
}
5562
}
63+
64+
pub fn requires_api_key(self) -> bool {
65+
!matches!(
66+
self,
67+
Provider::Bedrock | Provider::Ollama | Provider::CursorAgent
68+
)
69+
}
5670
}
5771

72+
pub const PROVIDER_CHOICE_HINT: &str = "openai|anthropic|grok|bedrock|ollama|cursor-agent";
73+
5874
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
5975
pub struct AiConfig {
6076
pub provider: Option<Provider>,
@@ -137,7 +153,7 @@ impl AiConfig {
137153

138154
pub fn unconfigured_error() -> anyhow::Error {
139155
anyhow::anyhow!(
140-
"No AI provider configured. Run `modal ai set --provider openai|anthropic|grok|bedrock|ollama`."
156+
"No AI provider configured. Run `modal ai set --provider {PROVIDER_CHOICE_HINT}`."
141157
)
142158
}
143159

0 commit comments

Comments
 (0)