@only-cli/oc 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +94 -82
- package/clis/reddit.com.json +6 -4
- package/package.json +1 -1
- package/skills/web-browsing-cli/SKILL.md +9 -9
- package/src/act.js +4 -2
- package/src/fetch.js +31 -7
- package/src/render.js +10 -4
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ $ oc open news.ycombinator.com
|
|
|
12
12
|
[1] Show HN: I built a tiny CSV toolkit
|
|
13
13
|
[2] 312 comments
|
|
14
14
|
...
|
|
15
|
-
actions: do <n> | read <n> | next | raw
|
|
15
|
+
actions: do <n> | find <query> | read <n> | next | raw
|
|
16
16
|
|
|
17
17
|
$ oc do 1
|
|
18
18
|
```
|
|
@@ -27,36 +27,7 @@ If you are an LLM reading this repository, [llms.txt](llms.txt) is the short ver
|
|
|
27
27
|
npm install -g @only-cli/oc
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
Requires Node 20+. Requests impersonate Chrome via [impers](https://github.com/lexiforest/impers)
|
|
31
|
-
|
|
32
|
-
### Proxies
|
|
33
|
-
|
|
34
|
-
Outbound fetches honor the usual environment variables, in upper or lower case, with nothing to pass on the command line:
|
|
35
|
-
|
|
36
|
-
```
|
|
37
|
-
HTTP_PROXY=http://proxy.example:8080 # http:// targets
|
|
38
|
-
HTTPS_PROXY=http://proxy.example:8080 # https:// targets, tunneled with CONNECT
|
|
39
|
-
NO_PROXY=internal.example,*.corp.example # reached directly instead
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
An `https://` target prefers `HTTPS_PROXY` and falls back to `HTTP_PROXY`; an `http://` target uses `HTTP_PROXY` only. A value with no scheme is read as `http://`, so `proxy.example:8080` works. Only HTTP and HTTPS proxies are supported, and another scheme such as `socks5://` is refused by name rather than silently ignored.
|
|
43
|
-
|
|
44
|
-
Credentials in the proxy URL are sent as `Proxy-Authorization` to the proxy and to nothing else, including across redirects:
|
|
45
|
-
|
|
46
|
-
```
|
|
47
|
-
HTTPS_PROXY=http://user:pass@proxy.example:8080 oc open https://example.com
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
`NO_PROXY` accepts an exact host, a `.suffix` or `*.suffix` pattern, a `host:port` entry, a CIDR block, and `*` for everything.
|
|
51
|
-
|
|
52
|
-
An `https://` page is tunneled with CONNECT and its certificate is verified the same way it would be without a proxy, so a proxy in the path cannot read or rewrite the page.
|
|
53
|
-
|
|
54
|
-
Two limits are worth knowing:
|
|
55
|
-
|
|
56
|
-
- oc does not read `ALL_PROXY`. The impers transport is libcurl underneath and reads it on its own, so a request oc treats as direct can still leave through an `ALL_PROXY`. The same holds for the `*.suffix`, `host:port`, and CIDR forms of `NO_PROXY`, which libcurl does not parse. Set `HTTP_PROXY` and `HTTPS_PROXY` explicitly and keep `NO_PROXY` to plain host and suffix entries when the two need to agree.
|
|
57
|
-
- An IPv6 literal target over HTTPS does not currently work through a proxy.
|
|
58
|
-
|
|
59
|
-
Private and internal addresses are refused whether or not a proxy is set. With a proxy configured, a hostname that does not resolve locally is refused too, because the proxy would otherwise resolve it on a network oc cannot see. A name that resolves publicly for oc and internally for the proxy (split horizon DNS) is not something oc can detect, so a proxy is trusted to enforce its own egress policy.
|
|
30
|
+
Requires Node 20+. Requests impersonate Chrome via [impers](https://github.com/lexiforest/impers). When a site, or the local copy of libcurl-impersonate, refuses the Chrome identity, the request downgrades to Firefox, and to native fetch when impers is unavailable or refuses both.
|
|
60
31
|
|
|
61
32
|
### Agent skill
|
|
62
33
|
|
|
@@ -103,30 +74,6 @@ oc logout [session] forget a session: cookies and saved page
|
|
|
103
74
|
|
|
104
75
|
Flags: `--budget <tokens>` (default 500), `--json`, `--html` (raw as cleaned HTML), `--session <name>`, `--verbose`/`-v` (metrics on stderr, or export `OC_VERBOSE=1`).
|
|
105
76
|
|
|
106
|
-
### Authenticated sessions
|
|
107
|
-
|
|
108
|
-
Pages behind a login need cookies. Seed them once per session, then browse normally:
|
|
109
|
-
|
|
110
|
-
```bash
|
|
111
|
-
printf %s "session=...; auth=..." | oc login --cookie - --domain example.com --expires 2h --session work
|
|
112
|
-
oc open https://example.com/dashboard --session work
|
|
113
|
-
oc logout work
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
Prefer `--cookie -`, which reads the header from stdin. The flag also takes the header inline (`--cookie "session=..."`), but an argument is a live credential in `ps` for as long as `oc` runs and in your shell history afterwards.
|
|
117
|
-
|
|
118
|
-
Copy the `Cookie` header from your browser's devtools (Application → Cookies, or the Network tab on a request); a leading `Cookie:` is stripped for you. `--domain` is the site hostname those cookies belong to, and it has to be a real hostname: a bare TLD like `com` is refused, because the match is a suffix match and those cookies would go to every `.com` host the session ever fetched. Cookie names and values are checked at login too, so a stray control character fails there rather than deep inside the HTTP client.
|
|
119
|
-
|
|
120
|
-
Seeded cookies are https-only. They almost always come from an https browser session, so `oc` marks them secure and never sends them over plain `http`, including on a hop an `https` page redirects into, where you never typed the downgrade. A site that really is http-only needs `--allow-http` at login. Cookies a site sets over https are pinned the same way.
|
|
121
|
-
|
|
122
|
-
Cookies live in a separate sidecar file (`<session>.cookies.json`) under `~/.only-cli/sessions/`, mode `0600`, not in the page-state JSON and never in `--json` output. The default lifetime is one hour (`--expires 1h`), and a jar holds at most 50 cookies so a page cannot bloat it. When cookies expire or the site returns a login page, `oc` says so plainly (exit 2) instead of distilling the login form as content.
|
|
123
|
-
|
|
124
|
-
`oc logout` forgets the whole session, not just its cookies: a page saved under that name can hold the distilled text of something only the login could reach, so the snapshot goes with the jar.
|
|
125
|
-
|
|
126
|
-
`oc open` remembers the page it rendered in a JSON file per session under `~/.only-cli` (override with `OC_HOME`), so `oc do 3` follows `[3]` without the agent ever handling a URL. A result title on a search page is a link, so `oc do` on it opens the result rather than repeating the title. Pages longer than the budget say what they left out; `oc find`, `oc read <n>`, and `oc next` read the rest without refetching the page, and a `find` with a single match prints that region instead of the number to read it with. The budget is a target rather than a hard cap: a page that would only run a little long is printed whole rather than cut, since one extra tool call costs far more than the tokens it would have saved.
|
|
127
|
-
|
|
128
|
-
When a page comes back with no readable text (JavaScript-only, a consent wall, a bot challenge), `oc` says so in one line on stderr and exits 2 instead of printing a title and calling it a render. That is a different exit code from every other failure, and `--json` carries the same verdict as an `empty` field, so an agent can tell "this page has nothing on it" from "oc could not read this page" and pay for a browser only when it is worth it.
|
|
129
|
-
|
|
130
77
|
## Supported websites
|
|
131
78
|
|
|
132
79
|
Works on any mostly-static site with no per-site setup: news sites, blogs, documentation, forums, search engines. A JSON API is a page here too: `oc open` on an endpoint that answers with JSON renders one numbered item per record, keeps the fields that actually differ between items, and says once what every item shares. On top of that, `clis/` ships tuned shortcuts, so `oc hn item 4711` or `oc gh repo only-cli oc` gets there without the agent knowing how that site spells its URLs. Name the site by its short name, its bare name, or its domain (`oc hn`, `oc ycombinator`, `oc news.ycombinator.com`), and `oc sites` prints the whole list with its verbs:
|
|
@@ -134,7 +81,7 @@ Works on any mostly-static site with no per-site setup: news sites, blogs, docum
|
|
|
134
81
|
| website | command | shortcuts |
|
|
135
82
|
| --- | --- | --- |
|
|
136
83
|
| Hacker News | `oc hn` | `top`, `new`, `item <id>`, `user <name>` |
|
|
137
|
-
| Reddit | `oc reddit` (via
|
|
84
|
+
| Reddit | `oc reddit` (via the Atom feeds on www.reddit.com) | `sub <name>`, `new <name>`, `top <name>`, `post <id>`, `user <name>`, `search <query>` |
|
|
138
85
|
| GitHub | `oc gh` | `repo <owner> <name>`, `user <name>`, `search <query>`, `trending`, `issues <owner> <name>` |
|
|
139
86
|
| X | `oc x` | `user <name>`, `post <id>` |
|
|
140
87
|
| LinkedIn | `oc linkedin` | `profile <name>`, `company <name>`, `jobs <query>` (public guest views) |
|
|
@@ -164,36 +111,101 @@ A few of these (X, Stack Overflow, YouTube, Microsoft Learn search) read pages t
|
|
|
164
111
|
|
|
165
112
|
Want a website on that list? Open a pull request, or an issue naming the site; see [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
166
113
|
|
|
114
|
+
## Features
|
|
115
|
+
|
|
116
|
+
### Authenticated sessions
|
|
117
|
+
|
|
118
|
+
Pages behind a login need cookies. Seed them once per session, then browse normally:
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
printf %s "session=...; auth=..." | oc login --cookie - --domain example.com --expires 2h --session work
|
|
122
|
+
oc open https://example.com/dashboard --session work
|
|
123
|
+
oc logout work
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Prefer `--cookie -`, which reads the header from stdin. The flag also takes the header inline (`--cookie "session=..."`), but an argument is a live credential in `ps` for as long as `oc` runs and in your shell history afterwards.
|
|
127
|
+
|
|
128
|
+
Copy the `Cookie` header from your browser's devtools (Application → Cookies, or the Network tab on a request); a leading `Cookie:` is stripped for you. `--domain` is the site hostname those cookies belong to, and it has to be a real hostname: a bare TLD like `com` is refused, because the match is a suffix match and those cookies would go to every `.com` host the session ever fetched. Cookie names and values are checked at login too, so a stray control character fails there rather than deep inside the HTTP client.
|
|
129
|
+
|
|
130
|
+
Seeded cookies are https-only. They almost always come from an https browser session, so `oc` marks them secure and never sends them over plain `http`, including on a hop an `https` page redirects into, where you never typed the downgrade. A site that really is http-only needs `--allow-http` at login. Cookies a site sets over https are pinned the same way.
|
|
131
|
+
|
|
132
|
+
Cookies live in a separate sidecar file (`<session>.cookies.json`) under `~/.only-cli/sessions/`, mode `0600`, not in the page-state JSON and never in `--json` output. The default lifetime is one hour (`--expires 1h`), and a jar holds at most 50 cookies so a page cannot bloat it. When cookies expire or the site returns a login page, `oc` says so plainly (exit 2) instead of distilling the login form as content.
|
|
133
|
+
|
|
134
|
+
`oc logout` forgets the whole session, not just its cookies: a page saved under that name can hold the distilled text of something only the login could reach, so the snapshot goes with the jar.
|
|
135
|
+
|
|
136
|
+
`oc open` remembers the page it rendered in a JSON file per session under `~/.only-cli` (override with `OC_HOME`), so `oc do 3` follows `[3]` without the agent ever handling a URL. A result title on a search page is a link, so `oc do` on it opens the result rather than repeating the title. Pages longer than the budget say what they left out; `oc find`, `oc read <n>`, and `oc next` read the rest without refetching the page, and a `find` with a single match prints that region instead of the number to read it with. The budget is a target rather than a hard cap: a page that would only run a little long is printed whole rather than cut, since one extra tool call costs far more than the tokens it would have saved.
|
|
137
|
+
|
|
138
|
+
When a page comes back with no readable text (JavaScript-only, a consent wall, a bot challenge), `oc` says so in one line on stderr and exits 2 instead of printing a title and calling it a render. That is a different exit code from every other failure, and `--json` carries the same verdict as an `empty` field, so an agent can tell "this page has nothing on it" from "oc could not read this page" and pay for a browser only when it is worth it.
|
|
139
|
+
|
|
140
|
+
### Proxies
|
|
141
|
+
|
|
142
|
+
Outbound fetches honor the usual environment variables, in upper or lower case, with nothing to pass on the command line:
|
|
143
|
+
|
|
144
|
+
```
|
|
145
|
+
HTTP_PROXY=http://proxy.example:8080 # http:// targets
|
|
146
|
+
HTTPS_PROXY=http://proxy.example:8080 # https:// targets, tunneled with CONNECT
|
|
147
|
+
NO_PROXY=internal.example,*.corp.example # reached directly instead
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
An `https://` target prefers `HTTPS_PROXY` and falls back to `HTTP_PROXY`; an `http://` target uses `HTTP_PROXY` only. A value with no scheme is read as `http://`, so `proxy.example:8080` works. Only HTTP and HTTPS proxies are supported, and another scheme such as `socks5://` is refused by name rather than silently ignored.
|
|
151
|
+
|
|
152
|
+
Credentials in the proxy URL are sent as `Proxy-Authorization` to the proxy and to nothing else, including across redirects:
|
|
153
|
+
|
|
154
|
+
```
|
|
155
|
+
HTTPS_PROXY=http://user:pass@proxy.example:8080 oc open https://example.com
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
`NO_PROXY` accepts an exact host, a `.suffix` or `*.suffix` pattern, a `host:port` entry, a CIDR block, and `*` for everything.
|
|
159
|
+
|
|
160
|
+
An `https://` page is tunneled with CONNECT and its certificate is verified the same way it would be without a proxy, so a proxy in the path cannot read or rewrite the page.
|
|
161
|
+
|
|
162
|
+
Two limits are worth knowing:
|
|
163
|
+
|
|
164
|
+
- oc does not read `ALL_PROXY`. The impers transport is libcurl underneath and reads it on its own, so a request oc treats as direct can still leave through an `ALL_PROXY`. The same holds for the `*.suffix`, `host:port`, and CIDR forms of `NO_PROXY`, which libcurl does not parse. Set `HTTP_PROXY` and `HTTPS_PROXY` explicitly and keep `NO_PROXY` to plain host and suffix entries when the two need to agree.
|
|
165
|
+
- An IPv6 literal target over HTTPS does not currently work through a proxy.
|
|
166
|
+
|
|
167
|
+
Private and internal addresses are refused whether or not a proxy is set. With a proxy configured, a hostname that does not resolve locally is refused too, because the proxy would otherwise resolve it on a network oc cannot see. A name that resolves publicly for oc and internally for the proxy (split horizon DNS) is not something oc can detect, so a proxy is trusted to enforce its own egress policy.
|
|
168
|
+
|
|
167
169
|
## Benchmarks
|
|
168
170
|
|
|
169
|
-
Full methodology, per-task
|
|
171
|
+
Full methodology, per-task rows, and the Codex runs live in [only-cli/benchmarks](https://github.com/only-cli/benchmarks). Where things stand (oc 0.5.1, September 2026, live sites):
|
|
172
|
+
|
|
173
|
+
- **125x fewer tokens than raw HTML** across the twelve real pages both could read: 8,519 against 1,064,474. 15x fewer than Jina Reader, 59x fewer than Playwright MCP's accessibility snapshot.
|
|
174
|
+
- **Real content on every page it could reach, and an honest failure on the two it could not.** Reddit now sends logged-out readers to a login wall, and every other tool returned that wall, or a 403 block page, as a success. Yahoo Finance refuses plain fetch outright and DuckDuckGo still blocks lynx; oc's Chrome impersonation read both.
|
|
175
|
+
- **Half the cost of Claude Code's built-in `WebSearch`** on Wikipedia lookups: $0.23 against $0.45 for five questions, both 5/5 correct, on 25x less fresh input.
|
|
176
|
+
- **21% cheaper than `WebFetch` and 34% cheaper than `WebSearch`** on eleven language docs lookups, at equal or better accuracy.
|
|
177
|
+
- **10% cheaper than `WebFetch` and 49% cheaper than `WebSearch`** on twelve dependency lookups across GitHub, npm, PyPI, RubyGems, crates.io, Docker Hub, Stack Overflow and an RFC, 12/12 correct with no tuned shortcut for most of those sites.
|
|
178
|
+
|
|
179
|
+
The tables behind those numbers:
|
|
180
|
+
|
|
181
|
+
**Tokens per page, no model in the loop.** Fifteen real pages: a news front page, a Reddit discussion, search results, a stock quote, three cloud CLI references, the Python, MDN, and Node.js references, and more.
|
|
170
182
|
|
|
171
|
-
| method | tokens for 15
|
|
183
|
+
| method | tokens for 15 pages | notes |
|
|
172
184
|
| --- | ---: | --- |
|
|
173
|
-
| `oc open` |
|
|
174
|
-
| Jina Reader |
|
|
175
|
-
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
run,
|
|
181
|
-
|
|
182
|
-
| tool |
|
|
183
|
-
| --- |
|
|
184
|
-
| `oc wiki` | 5/5 | 5,535 | $0.
|
|
185
|
-
| built-in `WebFetch` | 5/5 |
|
|
186
|
-
| built-in `WebSearch` | 5/5 |
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
page
|
|
195
|
-
|
|
196
|
-
|
|
185
|
+
| `oc open` | 8,971 | real content on 13 of 15 pages; the two Reddit pages are behind a login wall, and oc is the only reader that reported that instead of returning the wall |
|
|
186
|
+
| Jina Reader | 105,198 | both Reddit results are block pages; failed LinkedIn and the Node.js `fs` page outright |
|
|
187
|
+
| Playwright MCP | 531,303 | accessibility snapshots; both Reddit snapshots are the login wall |
|
|
188
|
+
| raw HTML fetch | 1,240,669 | both Reddit results are the login wall, 88,000 tokens of it each; Yahoo Finance refused the connection |
|
|
189
|
+
|
|
190
|
+
oc's budget keeps every page near 500 tokens however much it weighs: the YouTube watch page is 345,487 tokens raw and 688 through oc, Node's `fs` reference 275,425 against 479. On the twelve pages both could read, raw HTML costs 125x what oc does: 1,064,474 against 8,519.
|
|
191
|
+
|
|
192
|
+
**Whole tasks against the agent's built-in web tools.** Read cost is one thing, what an agent actually spends is another, so a second set of suites runs full lookups end to end in Claude Code (`claude-sonnet-5`), one tool per run, and grades every answer. Five Wikipedia lookups, eleven language documentation lookups, and twelve lookups on the pages around a dependency, where oc has shortcuts only for GitHub and Stack Overflow and renders the rest generically:
|
|
193
|
+
|
|
194
|
+
| suite | tool | correct | input tokens | cost | avg time |
|
|
195
|
+
| --- | --- | ---: | ---: | ---: | ---: |
|
|
196
|
+
| Wikipedia | `oc wiki` | 5/5 | 5,535 | $0.23 | 8s |
|
|
197
|
+
| | built-in `WebFetch` | 5/5 | 129,257 | $0.35 | 12s |
|
|
198
|
+
| | built-in `WebSearch` | 5/5 | 136,982 | $0.45 | 16s |
|
|
199
|
+
| Language docs | `oc docs` | 11/11 | 12,967 | $0.56 | 8s |
|
|
200
|
+
| | built-in `WebFetch` | 10/11 | 203,497 | $0.71 | 12s |
|
|
201
|
+
| | built-in `WebSearch` | 11/11 | 215,833 | $0.85 | 14s |
|
|
202
|
+
| Dependency research | `oc open` | 12/12 | 13,261 | $0.63 | 10s |
|
|
203
|
+
| | built-in `WebFetch` | 10/12 | 173,779 | $0.70 | 11s |
|
|
204
|
+
| | built-in `WebSearch` | 12/12 | 326,088 | $1.22 | 19s |
|
|
205
|
+
|
|
206
|
+
Input tokens are the fresh context each tool put in front of the model, which is the number the page size drives; totals including cache reads sit closer together because the agent's own prompt dominates them. oc stays flat at roughly 1,100 to 1,200 tokens per task, while `WebFetch` pays for whatever the page weighs, from 5.9x more on a short Wikipedia stub to 35x more on the German Berlin article. `WebFetch`'s three misses are access results: cppreference, npm, and Stack Overflow all refuse it, while oc's Chrome impersonation reads the same pages. The dependency suite is also where oc's generic renderer pays for hard pages: the JavaScript-only crates.io entry and a support table whose row spans several blocks each cost it eight turns, and on the two tasks that start a link away the built-in tools were cheaper. `WebSearch` was given only the question, never the URL, which is the honest way to use it and part of why it costs the most.
|
|
207
|
+
|
|
208
|
+
The same suites through Codex (`gpt-5.6-sol`, on the 0.4.0 and 0.5.0 runs) split. On Wikipedia, `oc wiki` was cheaper and also right where Codex's own search quoted a stale Berlin population. On the docs lookups Codex's search won by 16%: those facts are already in its snippets, and it answered most tasks in two turns without opening a page.
|
|
197
209
|
|
|
198
210
|
## Status
|
|
199
211
|
|
package/clis/reddit.com.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"domain": "reddit.com",
|
|
3
3
|
"commands": {
|
|
4
|
-
"sub": { "open": "https://
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
4
|
+
"sub": { "open": "https://www.reddit.com/r/{name}/.rss", "args": ["name"] },
|
|
5
|
+
"new": { "open": "https://www.reddit.com/r/{name}/new/.rss", "args": ["name"] },
|
|
6
|
+
"top": { "open": "https://www.reddit.com/r/{name}/top/.rss?t=week", "args": ["name"] },
|
|
7
|
+
"post": { "open": "https://www.reddit.com/comments/{id}/.rss", "args": ["id"] },
|
|
8
|
+
"user": { "open": "https://www.reddit.com/user/{name}/.rss", "args": ["name"] },
|
|
9
|
+
"search": { "open": "https://www.reddit.com/search.rss?q={query}", "args": ["query"] }
|
|
8
10
|
}
|
|
9
11
|
}
|
package/package.json
CHANGED
|
@@ -8,15 +8,15 @@ description: Token-efficient web browsing and web content extraction for AI agen
|
|
|
8
8
|
Renders a web page as a compact, numbered terminal view instead of raw HTML. A typical page is under 500 tokens.
|
|
9
9
|
|
|
10
10
|
```
|
|
11
|
-
npx --yes @only-cli/oc@0.5.
|
|
12
|
-
npx --yes @only-cli/oc@0.5.
|
|
13
|
-
npx --yes @only-cli/oc@0.5.
|
|
11
|
+
npx --yes @only-cli/oc@0.5.2 open <url> compact view, numbered elements
|
|
12
|
+
npx --yes @only-cli/oc@0.5.2 do <n> follow link [n], or read it if [n] is text
|
|
13
|
+
npx --yes @only-cli/oc@0.5.2 find <query> where a string appears, or that place itself
|
|
14
14
|
when only one matches
|
|
15
|
-
npx --yes @only-cli/oc@0.5.
|
|
16
|
-
npx --yes @only-cli/oc@0.5.
|
|
17
|
-
npx --yes @only-cli/oc@0.5.
|
|
18
|
-
npx --yes @only-cli/oc@0.5.
|
|
19
|
-
npx --yes @only-cli/oc@0.5.
|
|
15
|
+
npx --yes @only-cli/oc@0.5.2 next next ~500 tokens of the page already open
|
|
16
|
+
npx --yes @only-cli/oc@0.5.2 read <n> full text of region [n]
|
|
17
|
+
npx --yes @only-cli/oc@0.5.2 raw [url] whole page as markdown (--html for cleaned HTML)
|
|
18
|
+
npx --yes @only-cli/oc@0.5.2 login seed cookies (--cookie, --domain, --expires)
|
|
19
|
+
npx --yes @only-cli/oc@0.5.2 logout [session] forget a session: cookies and saved page
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
None of these except `open`/`do`/`raw <url>` fetch anything; they replay the page `open` already saved.
|
|
@@ -32,7 +32,7 @@ oc ddg search claude code oc so question 231767 oc learn doc azur
|
|
|
32
32
|
oc py library json oc mdn js Array/map oc node api fs
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
Sites: `hn`, `reddit`, `gh`, `x`, `linkedin`, `ddg`, `bing`, `so`, `
|
|
35
|
+
Sites: `hn`, `reddit`, `gh`, `x`, `linkedin`, `ddg`, `bing`, `so`, `yahoo`, `yt`, `aws`, `gcp`, `learn`, `wiki`, `py`, `mdn`, `node`, `ruby`, `go`, `rust`, `java`, `php`, `cpp`, `ts`. Name one by short name, bare name, or domain (`oc hn`, `oc ycombinator`, `oc news.ycombinator.com`). The last argument takes every word after it, so a query or title needs no quoting. `oc sites` lists every site with its verbs, which is cheaper than guessing one.
|
|
36
36
|
|
|
37
37
|
Prefer a shortcut over a hand-built URL when one exists for the site, and prefer `oc wiki article <title>` over a search when you already know the article's name.
|
|
38
38
|
|
package/src/act.js
CHANGED
|
@@ -234,7 +234,7 @@ export function find(query, { session = DEFAULT_SESSION, budget = 500 } = {}) {
|
|
|
234
234
|
return [
|
|
235
235
|
`1 match for "${query}"${separately}, region [${only.n}]`,
|
|
236
236
|
read(only.n, { session, budget: budget * FINISH }),
|
|
237
|
-
`actions: ${follow}read <n> | next | raw`,
|
|
237
|
+
`actions: ${follow}find <query> | read <n> | next | raw`,
|
|
238
238
|
].join('\n');
|
|
239
239
|
}
|
|
240
240
|
|
|
@@ -264,7 +264,9 @@ export function find(query, { session = DEFAULT_SESSION, budget = 500 } = {}) {
|
|
|
264
264
|
if (shown < hits.length) {
|
|
265
265
|
lines.push(`... ${hits.length - shown} more matches, narrow the query or raise --budget`);
|
|
266
266
|
}
|
|
267
|
-
|
|
267
|
+
// Offering find on its own output is what makes "narrow the query" above an
|
|
268
|
+
// action rather than advice.
|
|
269
|
+
lines.push(`actions: ${[hasLinks && 'do <n>', 'find <query>', 'read <n>', 'next', 'raw'].filter(Boolean).join(' | ')}`);
|
|
268
270
|
return lines.join('\n');
|
|
269
271
|
}
|
|
270
272
|
|
package/src/fetch.js
CHANGED
|
@@ -555,9 +555,24 @@ function captureSetCookie(jar, url, res) {
|
|
|
555
555
|
jar.storeFromResponse(url, getSetCookieHeaders(res));
|
|
556
556
|
}
|
|
557
557
|
|
|
558
|
-
|
|
558
|
+
/**
|
|
559
|
+
* Fetch a page through impers, downgrading identity when one is refused.
|
|
560
|
+
* Exported so the downgrade chain can be proven against a fake impers; the
|
|
561
|
+
* real entry point is fetchPage.
|
|
562
|
+
* @param {any} impers - the impers module (or a stand-in with a get method)
|
|
563
|
+
* @param {string} target
|
|
564
|
+
* @param {object} [jar]
|
|
565
|
+
* @returns {Promise<{url: string, html: string, status: number, via: string}>}
|
|
566
|
+
*/
|
|
567
|
+
export async function viaImpers(impers, target, jar) {
|
|
559
568
|
// Some sites (Reddit) 403 the chrome fingerprint but accept firefox, so a
|
|
560
|
-
// blocked first attempt gets one cheap retry with a second identity.
|
|
569
|
+
// blocked first attempt gets one cheap retry with a second identity. An
|
|
570
|
+
// ImpersonateError is the same story one layer down: impers resolves the
|
|
571
|
+
// 'chrome' alias to its newest fingerprint, but the native library it loads
|
|
572
|
+
// can be an older system copy of libcurl-impersonate that predates that
|
|
573
|
+
// fingerprint and refuses it before any request leaves. Firefox aliases to
|
|
574
|
+
// an older target that such a library usually still knows, and when both
|
|
575
|
+
// identities are refused the plain fetch transport still gets the page.
|
|
561
576
|
const asking = (impersonate) => (url) =>
|
|
562
577
|
impers.get(url, {
|
|
563
578
|
impersonate,
|
|
@@ -566,14 +581,23 @@ async function viaImpers(impers, target, jar) {
|
|
|
566
581
|
headers: jarHeaders(jar, url, {}),
|
|
567
582
|
});
|
|
568
583
|
const onResponse = (url, res) => captureSetCookie(jar, url, res);
|
|
584
|
+
const attempt = async (impersonate) => {
|
|
585
|
+
try {
|
|
586
|
+
const { res } = await followRedirects(asking(impersonate), target, { onResponse });
|
|
587
|
+
return { res, status: res.status ?? res.statusCode ?? 0 };
|
|
588
|
+
} catch (err) {
|
|
589
|
+
if (err?.name !== 'ImpersonateError') throw err;
|
|
590
|
+
return null;
|
|
591
|
+
}
|
|
592
|
+
};
|
|
569
593
|
let via = 'impers:chrome';
|
|
570
|
-
let
|
|
571
|
-
|
|
572
|
-
if (status >= 400) {
|
|
594
|
+
let got = await attempt('chrome');
|
|
595
|
+
if (!got || got.status >= 400) {
|
|
573
596
|
via = 'impers:firefox';
|
|
574
|
-
|
|
575
|
-
status = res.status ?? res.statusCode ?? 0;
|
|
597
|
+
got = (await attempt('firefox')) ?? got;
|
|
576
598
|
}
|
|
599
|
+
if (!got) return viaFetch(target, jar);
|
|
600
|
+
const { res, status } = got;
|
|
577
601
|
if (status >= 400) throw new Error(`fetch failed: ${status} for ${target}`);
|
|
578
602
|
assertReadableType(res.headers.get('content-type'));
|
|
579
603
|
assertBodySize(Number(res.headers.get('content-length')) || 0, target);
|
package/src/render.js
CHANGED
|
@@ -101,7 +101,6 @@ export function render(page, { budget = 500, from = 0 } = {}) {
|
|
|
101
101
|
const lines = [...head];
|
|
102
102
|
let spent = estimateTokens(lines.join('\n'));
|
|
103
103
|
let hasLinks = false;
|
|
104
|
-
let hasInputs = false;
|
|
105
104
|
let i = Math.max(0, from);
|
|
106
105
|
|
|
107
106
|
// What the rest of the page would cost if it were all printed. When that is
|
|
@@ -129,7 +128,6 @@ export function render(page, { budget = 500, from = 0 } = {}) {
|
|
|
129
128
|
spent += cost;
|
|
130
129
|
lines.push(line);
|
|
131
130
|
if (block.type === 'link' || block.type === 'button') hasLinks = true;
|
|
132
|
-
if (block.type === 'input') hasInputs = true;
|
|
133
131
|
}
|
|
134
132
|
|
|
135
133
|
const rest = blocks.slice(i);
|
|
@@ -140,10 +138,18 @@ export function render(page, { budget = 500, from = 0 } = {}) {
|
|
|
140
138
|
if (rest.length) {
|
|
141
139
|
lines.push(`... ${num(rest.length)} more blocks (~${num(leftTokens)} tokens): 'oc next' for the next ~${num(budget)}, 'oc raw' for all`);
|
|
142
140
|
}
|
|
141
|
+
// An input on the page adds no action. 'fill' and 'submit' are still stubs
|
|
142
|
+
// that throw, and this footer is the line an agent trusts for what to run
|
|
143
|
+
// next, so naming one of them costs a turn and returns nothing.
|
|
144
|
+
//
|
|
145
|
+
// 'find' comes before 'read' because it is the cheaper way to go deeper: one
|
|
146
|
+
// command lands on the block that matters, where 'read' needs the right
|
|
147
|
+
// number first and 'next' pages toward it. The entry costs about three
|
|
148
|
+
// tokens on every render, and skipping one 'next' on a long page pays for
|
|
149
|
+
// a hundred of them.
|
|
143
150
|
const actions = [
|
|
144
151
|
hasLinks && 'do <n>',
|
|
145
|
-
|
|
146
|
-
hasInputs && 'submit',
|
|
152
|
+
'find <query>',
|
|
147
153
|
'read <n>',
|
|
148
154
|
rest.length && 'next',
|
|
149
155
|
'raw',
|