Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
5b5f153
Work out once whether a person, a coding agent or CI runs string
asavor Nov 20, 2026
f1aa517
Show update notices only to a person at a terminal
asavor Nov 20, 2026
2965b31
Say in the help and README how string finds a coding agent
asavor Nov 20, 2026
0a7ced0
Say in each request to String how string runs and which agent runs it
asavor Nov 20, 2026
5821244
Say in the help and README what each request tells String
asavor Nov 20, 2026
c43831d
Send the download host the same User-Agent as requests to String
asavor Nov 20, 2026
a6e36d4
Open a sign-in link in the browser only for a person at a terminal
asavor Nov 20, 2026
bd8003c
Wait for a person only when one is at the terminal
asavor Nov 20, 2026
744b748
Test that switches before update start no update check
asavor Nov 20, 2026
30068ae
Give each request to String a time limit
asavor Nov 20, 2026
6dd38e5
Bound sitemap --wait and say how to resume it
asavor Nov 20, 2026
4800d6b
Keep a sign-in's code when its server doesn't answer in time
asavor Nov 20, 2026
7c7b02c
Merge branch 'request-time-limits' into bounded-sitemap-wait
asavor Nov 20, 2026
e80c467
Bound login --poll and trial claim --poll and say how to resume them
asavor Nov 20, 2026
0c5815a
Say in the help and README how --poll waits and resumes
asavor Nov 20, 2026
60bea10
Say what Ctrl-C leaves behind, then end as an interrupted program
asavor Nov 20, 2026
b47aa9a
Say in the help and README what Ctrl-C does
asavor Nov 20, 2026
87502af
Give every command its own help, and take -h anywhere
asavor Nov 20, 2026
c13eb52
Say in the help and README how to get a command's help and the version
asavor Nov 20, 2026
5389a48
Suggest the command or flag meant, and take every spelling of a flag
asavor Nov 20, 2026
5ee2bc3
Say in the help and README which spellings work and what a typo gets
asavor Nov 20, 2026
534cf9b
Fetch a bare domain over https, and say when https:// was added
asavor Nov 20, 2026
aa7a92c
Say in the help and README that a bare domain works
asavor Nov 20, 2026
c147556
Add help topics, and start the help for all of string with lines for …
asavor Nov 20, 2026
f63fcff
Say in the help and README which help topics there are
asavor Nov 20, 2026
20d9042
Say in every JSON error its exit code, whether to retry, and the step…
asavor Nov 20, 2026
9798023
Say in the help and README what each JSON error field means
asavor Nov 20, 2026
7e0bb83
Write each error as error: and a sentence, without raw bodies
asavor Nov 20, 2026
5231315
Say in the help and README how an error reads
asavor Nov 20, 2026
952b5fb
Add --errors json, and say ahead what changes for fetch in 0.4
asavor Nov 20, 2026
7ceeaaa
Say in the help and README what --errors json does and what changes i…
asavor Nov 20, 2026
755cda4
Say a large page's size first, and what -o saved, with an outline
asavor Nov 20, 2026
e65ca51
Say in the help and README what -o says, what a large page says, and -q
asavor Nov 20, 2026
767931a
Read a long page in parts with --max-tokens, from one fetch
asavor Nov 20, 2026
69d23c2
Say in the help and README how to read a page in parts
asavor Nov 20, 2026
35d20ad
Check the key with String in whoami, and keep --offline local
asavor Nov 20, 2026
ef1f7a7
Say in the help and README that whoami checks the key
asavor Nov 20, 2026
8050af1
Refuse a JSON-only field with another format, and read --body-file - …
asavor Nov 20, 2026
2d88cfe
Say in the help and README how --body-file - and JSON-only fields work
asavor Nov 20, 2026
52ed9b1
Merge main into input-fixes
asavor Nov 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ part 1 of 13 (tokens 0–6,000 of ~75,000). next: string fetch https://en.wikipe

The parts after the first come from a local copy that the first part saves for 15 minutes, under `$XDG_CACHE_HOME/string/fetch` or `~/.cache/string/fetch`. They send no request and cost nothing, keyless allowance included.

A field that only comes back in JSON, such as `--jsonSchema` or `--screenshot`, needs JSON output. With `--format markdown` or `--format raw` it exits 2 and says so, where the field used to be dropped without a word. For `request`, `--body-file -` reads the body from stdin. `--body` sends its text as written, so `--body @order.json` warns when `order.json` is a file, since `--body-file order.json` was likely meant.

A bare domain works too: `string example.com` fetches `https://example.com`. When `fetch`, `request` or `sitemap submit` gets a URL with no scheme, it uses `https://` and says so on stderr.

**Every API field is a flag of the same name.** A field from the [API reference](https://docs.usestring.ai/api-reference/fetch) works on the command line as written: `executeJS` is `--executeJS`, and `countryCode` is `--countryCode DE`. A boolean flag alone is true, and `=false` turns it off (`--solveCaptcha=false`). An object or array field takes JSON, or `@` and a file path (`--jsonSchema @./schema.json`). `string fetch --help`, `string search --help` and `string sitemap --help` list each command's fields. Every flag of more than one word also takes its kebab-case and snake_case spellings, so `--main-content-only` and `--main_content_only` are `--mainContentOnly`, and `--envFile` is `--env-file`. A near miss of a flag, such as `--mainContentOnyl`, gets the right name back, and so does a near miss of a command, or a word other tools use for one: `string scrape URL` answers `Did you mean fetch?` with `string fetch URL` as the next step, and exits 2 without running it.
Expand Down
4 changes: 2 additions & 2 deletions cmd/string/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ var commandDocs = map[string]commandDoc{
},
returns: append([]string{"stdout the response as JSON"}, exitsOfARequest...),
cost: "Needs a key. Prices: https://docs.usestring.ai/get-started/pricing",
flags: ` --body TEXT the request body, as written
--body-file FILE the request body, read from FILE
flags: ` --body TEXT the request body, as written, @ included
--body-file FILE the request body, read from FILE, or - for stdin
` + outputFlags,
fields: " The same as string fetch: string fetch --help.\n",
more: "https://docs.usestring.ai/api-reference/fetch",
Expand Down
72 changes: 72 additions & 0 deletions cmd/string/input_fixes_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package main

import (
"bytes"
"encoding/json"
"io"
"net/http"
"os"
"path/filepath"
"strings"
"sync"
"testing"
)

// A field only JSON carries, asked for with another format, exits 2 with the
// fix, where it used to be dropped without a word.
func TestAJSONOnlyFieldNeedsJSON(t *testing.T) {
for list, want := range map[string]string{
`fetch https://example.com --jsonSchema {} --format markdown`: "error: --jsonSchema comes back only in JSON, so --format markdown would lose it; drop --format, or use --format json\n",
`fetch https://example.com --screenshot --format raw`: "error: --screenshot comes back only in JSON, so --format raw would lose it; drop --format, or use --format json\n",
`request POST https://example.com --captureCookies --format markdown`: "error: --captureCookies comes back only in JSON, so --format markdown would lose it; drop --format, or use --format json\n",
} {
if got := runOffline(t, strings.Fields(list)...); got.status != exitUsage || got.errors != want {
t.Errorf("string %s: %+v, want %q", list, got, want)
}
}
base, _ := fetchAPI(t, `{"statusCode":200}`)
if got := runAs(base, execCtx{}, "fetch", "https://example.com", "--jsonSchema", "{}", "--format", "json"); got.status != 0 {
t.Errorf("--jsonSchema --format json: %+v", got)
}
}

// --body-file - reads the body from stdin, and --body @FILE warns when FILE
// exists, since --body sends its text as written.
func TestRequestBodiesFromStdinAndTheAtWarning(t *testing.T) {
var mu sync.Mutex
var sent []string
base := api(t, func(w http.ResponseWriter, r *http.Request) {
var body struct {
Body string `json:"body"`
}
json.NewDecoder(r.Body).Decode(&body)
mu.Lock()
sent = append(sent, body.Body)
mu.Unlock()
io.WriteString(w, `{"statusCode":200}`)
})
request := func(stdin string, list ...string) result {
var stdout, stderr bytes.Buffer
status := run(append([]string{"request", "POST", "https://example.com/orders"}, list...), runtime{env: envOf(map[string]string{"STRING_API_KEY": "test-key", "STRING_API_BASE_URL": base}), client: http.DefaultClient, stdin: strings.NewReader(stdin), stdout: &stdout, stderr: &stderr})
return result{status, stdout.String(), stderr.String()}
}
if got := request(`{"sku":"A1"}`, "--body-file", "-"); got.status != 0 || got.errors != "" || len(sent) != 1 || sent[0] != `{"sku":"A1"}` {
t.Errorf("--body-file -: %+v, sent %q", got, sent)
}
if got := request("{}", "--input", "-", "--body-file", "-"); got.status != exitUsage || got.errors != "error: Only one of --input - and --body-file - can read stdin\n" {
t.Errorf("--input - --body-file -: %+v", got)
}

dir := t.TempDir()
order := filepath.Join(dir, "order.json")
if err := os.WriteFile(order, []byte(`{"sku":"A1"}`), 0o600); err != nil {
t.Fatal(err)
}
sent = nil
if got := request("", "--body", "@"+order); got.status != 0 || got.errors != "warning: --body @"+order+" sends the text @"+order+"; did you mean --body-file "+order+"?\n" || sent[0] != "@"+order {
t.Errorf("--body @FILE: %+v, sent %q", got, sent)
}
if got := request("", "--body", "@"+filepath.Join(dir, "missing.json")); got.status != 0 || got.errors != "" {
t.Errorf("--body @MISSING: %+v", got)
}
}
37 changes: 33 additions & 4 deletions cmd/string/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,10 +650,21 @@ func fetchFormat(value string) (string, error) {
}

func formatFor(body map[string]any, fallback string) (string, error) {
if format := field(body, "format"); format != nil {
return fetchFormat(jsString(format))
format := field(body, "format")
if format == nil {
return fallback, nil
}
return fallback, nil
chosen, err := fetchFormat(jsString(format))
if err != nil || chosen == "json" {
return chosen, err
}
// A field that only JSON carries would be dropped from any other format.
for _, name := range jsonOnlyFields {
if jsTruthy(field(body, name)) {
return "", fmt.Errorf("--%s comes back only in JSON, so --format %s would lose it; drop --format, or use --format json", name, chosen)
}
}
return chosen, nil
}

// jsonOnlyFields come back only in a JSON response.
Expand Down Expand Up @@ -881,12 +892,28 @@ func requestCommand(list []string, stdin io.Reader) (*operation, error) {
if hasText && hasFile {
return nil, errors.New("Use only one of --body and --body-file")
}
if input, _ := parsed.value("input"); input == "-" && file == "-" {
return nil, errors.New("Only one of --input - and --body-file - can read stdin")
}
// --body is sent as written, even when it starts with @, but @ and a
// file that exists most likely meant --body-file.
var warning string
if name, ok := strings.CutPrefix(text, "@"); hasText && ok && name != "" {
if info, err := os.Stat(name); err == nil && !info.IsDir() {
warning = fmt.Sprintf("warning: --body %s sends the text %s; did you mean --body-file %s?", text, text, name)
}
}
body, err := requestFields(parsed, stdin)
if err != nil {
return nil, err
}
if hasFile {
contents, err := os.ReadFile(file)
var contents []byte
if file == "-" {
contents, err = io.ReadAll(stdin)
} else {
contents, err = os.ReadFile(file)
}
if err != nil {
return nil, err
}
Expand All @@ -900,6 +927,8 @@ func requestCommand(list []string, stdin io.Reader) (*operation, error) {
if err != nil {
return nil, err
}
note = strings.TrimPrefix(note+"\n"+warning, "\n")
note = strings.TrimSuffix(note, "\n")
body["url"], body["method"], body["format"] = target, method, format
if hasText {
body["body"] = text
Expand Down
Loading