You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Add assistant prompt contracts with built-in and file-backed validation plus one repair attempt
- Add opt-in JSON error envelopes via `--error-format json` and `KAGI_ERROR_FORMAT=json`
- Resolve `kagi search --lens` exact enabled lens names to the current numeric position
- Add `kagi extract --filter` JSONL mode for stdin URL pipelines
- Update `quinn-proto` in `Cargo.lock` to satisfy the RustSec audit gate
- a Contract is a prompt-mode output shape that the assistant command asks Kagi Assistant to return as JSON and validates before printing
4
+
- an ErrorEnvelope is an opt-in JSON stderr object for command failures with stable code, category, retryable, message, and suggested_commands fields
5
+
6
+
# cli
7
+
8
+
## assistant
9
+
- label: kagi assistant --contract decision validates the final assistant reply as a JSON object containing decision, rationale, and next_actions before printing it
10
+
command: cargo test --test integration-cli assistant_contract_decision_prints_validated_json -- --exact
11
+
tags: [implemented]
12
+
- label: kagi assistant --contract-file accepts a small JSON contract file with required top-level string keys and rejects assistant replies that do not satisfy it
13
+
command: cargo test --test integration-cli assistant_contract_file_rejects_missing_required_key -- --exact
14
+
tags: [implemented]
15
+
16
+
## errors
17
+
- label: runtime command failures can opt into JSON stderr with --error-format json or KAGI_ERROR_FORMAT=json
18
+
command: cargo test --test integration-cli json_error_format_prints_structured_stderr -- --exact
19
+
tags: [implemented]
20
+
21
+
## search
22
+
- label: kagi search --lens accepts an enabled lens exact name, resolves it through the authenticated lens settings page, and sends the current numeric lens position to search
23
+
command: cargo test --test integration-cli search_lens_name_resolves_to_current_position -- --exact
24
+
tags: [implemented]
25
+
26
+
## extract
27
+
- label: kagi extract --filter reads HTTPS URLs from stdin and writes one compact JSONL record per input in order, including per-item errors without corrupting stdout
28
+
command: cargo test --test integration-cli extract_filter_prints_ordered_jsonl_records -- --exact
kagi assistant --format markdown "Write a release summary"
77
79
```
78
80
81
+
#### `--contract <NAME>`
82
+
83
+
Ask Assistant to return only JSON that satisfies a built-in contract, then validate the final reply before printing it. Contract mode supports `--format json` and `--format compact`.
84
+
85
+
Supported built-ins:
86
+
87
+
-`decision` - requires `decision`, `rationale`, and `next_actions`
88
+
-`checklist` - requires `items`
89
+
-`plan` - requires `steps`
90
+
91
+
```bash
92
+
kagi assistant --contract decision "Should we ship this release?"
93
+
```
94
+
95
+
If the first reply is invalid, the CLI sends one repair prompt in the same thread. If the repaired reply still fails validation, the command exits with a contract error.
96
+
97
+
#### `--contract-file <PATH>`
98
+
99
+
Load a small JSON contract file. The supported subset is a top-level object with `required` and optional `properties.<key>.type` fields:
100
+
101
+
```json
102
+
{
103
+
"type": "object",
104
+
"required": ["summary", "verdict"],
105
+
"properties": {
106
+
"summary": { "type": "string" },
107
+
"verdict": { "type": "string" }
108
+
}
109
+
}
110
+
```
111
+
112
+
Required entries default to `string` when `properties` does not specify a type. Supported types are `string`, `number`, `integer`, `boolean`, `object`, and `array`.
113
+
79
114
#### `--no-color`
80
115
81
116
Disable ANSI colors in `--format pretty`.
@@ -289,6 +324,16 @@ Prompt mode returns:
289
324
}
290
325
```
291
326
327
+
Contract mode returns only the validated contract JSON, not the normal Assistant envelope:
@@ -19,6 +20,8 @@ The `kagi extract` command sends one HTTPS URL to Kagi's v1 Extract API and prin
19
20
20
21
The command uses JSON mode internally because that is the stable envelope returned by the API, then prints the first page's `markdown` field. Use `--format json` or `--format compact` to print the full response envelope, including retained link metadata when Kagi returns it. If Kagi returns no page markdown, the CLI reports the Extract API error details and trace id when available.
21
22
23
+
Use `--filter` for pipelines that already have one URL per line. Filter mode ignores the single-URL markdown default and prints one compact JSON record per input line in the same order. Successful records include the Extract API response under `response`. Failed records include an `error` envelope on stdout and the command exits nonzero after all inputs are processed.
{"url":"http://example.com/bad","ok":false,"error":{"code":"configuration_error","category":"configuration","retryable":false,"message":"configuration error: extract URL must use the https scheme","suggested_commands":[],"docs_url":"https://kagi.micr.dev/reference/error-reference"}}
kagi search --snap @map "coffee near london bridge"
94
94
```
95
95
96
-
### `--lens <INDEX>`
96
+
### `--lens <INDEX_OR_NAME>`
97
97
98
-
Scope search to one of your enabled Kagi lenses.
98
+
Scope search to one of your enabled Kagi lenses. Numeric values keep the existing index behavior. Non-numeric values are matched against enabled lens names exactly at runtime, then resolved to the current account-specific numeric position before search.
If a name is missing, disabled, or duplicated, the command fails before search and points you to `kagi lens list` or the numeric index path. Numeric-looking names are treated as numeric indexes.
106
+
104
107
### `--region <REGION>`
105
108
106
109
Restrict results to a Kagi region code such as `us`, `gb`, `jp`, or `no_region`.
Copy file name to clipboardExpand all lines: docs/reference/coverage.mdx
+8-5Lines changed: 8 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ These endpoints come from Kagi's current OpenAPI contract at `https://kagi.com/a
16
16
| Endpoint | Command | Status |
17
17
|----------|---------|--------|
18
18
| Search API (`POST /api/v1/search`) |`kagi search`| ✅ Implemented for query, limit, and `filters.region/after/before`|
19
-
| Extract API |`kagi extract`| ✅ Implemented |
19
+
| Extract API |`kagi extract`| ✅ Implemented, including stdin URL filter mode|
20
20
21
21
Current V1 Search optional fields not exposed by this CLI: `workflow`, API response `format`, `lens_id`, inline `lens`, `timeout`, `page`, search-result `extract`, `safe_search`, and explicit personalization rule objects. Subscriber web-product features cover some adjacent workflows, but they are not represented as V1 OpenAPI request fields.
22
22
@@ -39,12 +39,12 @@ These features use the subscriber web product with `KAGI_SESSION_TOKEN`:
0 commit comments