-
Notifications
You must be signed in to change notification settings - Fork 0
feat(fetch): add --max-chars flag #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -178,7 +178,7 @@ enum Commands { | |
|
|
||
| /// Fetch page content as markdown (outputs YAML by default, use -p for pretty output) | ||
| #[command( | ||
| after_help = "Works without login (free tier). Log in for higher rate limits.\n\nExamples:\n keenable fetch https://example.com YAML output\n keenable fetch https://example.com -p Pretty output\n keenable fetch https://example.com --live Fetch the live page (skip cache)\n keenable fetch https://example.com --prompt \"List all pricing tiers\" Extract with an LLM\n keenable fetch https://example.com --api-key keen_***_***** Use a specific API key" | ||
| after_help = "Works without login (free tier). Log in for higher rate limits.\n\nExamples:\n keenable fetch https://example.com YAML output\n keenable fetch https://example.com -p Pretty output\n keenable fetch https://example.com --live Fetch the live page (skip cache)\n keenable fetch https://example.com --prompt \"List all pricing tiers\" Extract with an LLM\n keenable fetch https://example.com --max-chars 200000 Raise the 50000-char content cap\n keenable fetch https://example.com --api-key keen_***_***** Use a specific API key" | ||
| )] | ||
| Fetch { | ||
| /// URL to fetch | ||
|
|
@@ -193,6 +193,10 @@ enum Commands { | |
| #[arg(long)] | ||
| prompt: Option<String>, | ||
|
|
||
| /// Truncate content at this many characters (default: 50000) | ||
| #[arg(long = "max-chars", value_parser = clap::value_parser!(u64).range(1..))] | ||
| max_chars: Option<u64>, | ||
|
Comment on lines
+196
to
+198
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2. Unbounded max_chars request --max-chars accepts any positive u64, so the CLI/daemon can request extremely large fetch responses. Since fetch responses are fully buffered and parsed as JSON before printing, very large responses can drive high memory usage or OOM when the API honors large max_chars values. Agent Prompt
|
||
|
|
||
| /// Pretty-print output for humans instead of YAML | ||
| #[arg(short = 'p', long = "pretty")] | ||
| pretty: bool, | ||
|
|
@@ -330,10 +334,12 @@ async fn main() { | |
| url, | ||
| live, | ||
| prompt, | ||
| max_chars, | ||
| pretty, | ||
| api_key, | ||
| } => { | ||
| commands::search::fetch(&url, live, prompt, pretty, api_key.as_deref()).await; | ||
| commands::search::fetch(&url, live, prompt, max_chars, pretty, api_key.as_deref()) | ||
| .await; | ||
| } | ||
| Commands::Feedback { | ||
| query, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,21 @@ def test_fetch_prompt(kn): | |
| assert "This domain is for use in illustrative examples" not in data["content"] | ||
|
|
||
|
|
||
| def test_fetch_max_chars(kn): | ||
| res = kn("fetch", "https://example.com", "--max-chars", "50") | ||
| assert res.code == 0 | ||
| data = res.yaml() | ||
| # The truncation disclaimer is the load-bearing assert: a stale daemon | ||
| # that drops `max_chars` returns the full page with exit code 0. | ||
| assert "truncated to stay below 50 characters" in data["content"] | ||
|
|
||
|
Comment on lines
+46
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 3. Brittle truncation assertion The new e2e test hard-depends on a specific backend-generated truncation disclaimer phrase. If the API changes wording while preserving behavior, the test will fail even though --max-chars plumbing still works. Agent Prompt
|
||
|
|
||
| def test_fetch_max_chars_rejects_zero(kn): | ||
| res = kn("fetch", "https://example.com", "--max-chars", "0") | ||
| assert res.code == 2 | ||
| assert "invalid value" in res.err | ||
|
|
||
|
|
||
| def test_pretty_fetch(kn): | ||
| res = kn("fetch", "https://example.com", "-p") | ||
| assert res.code == 0 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. --max-chars error exits 2
📘 Rule violation☼ ReliabilityAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools