@only-cli/oc 0.5.7 → 0.5.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@only-cli/oc",
3
- "version": "0.5.7",
3
+ "version": "0.5.8",
4
4
  "description": "Turn websites into a compact CLI so AI agents can browse without burning tokens.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -8,17 +8,17 @@ 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.7 open <url> compact view, numbered elements
12
- npx --yes @only-cli/oc@0.5.7 do <n> follow link [n], or read it if [n] is text
13
- npx --yes @only-cli/oc@0.5.7 find <query> where a string appears, or that place itself
11
+ npx --yes @only-cli/oc@0.5.8 open <url> compact view, numbered elements
12
+ npx --yes @only-cli/oc@0.5.8 do <n> follow link [n], or read it if [n] is text
13
+ npx --yes @only-cli/oc@0.5.8 find <query> where a string appears, or that place itself
14
14
  when only one matches
15
- npx --yes @only-cli/oc@0.5.7 next next ~500 tokens of the page already open
16
- npx --yes @only-cli/oc@0.5.7 read <n> full text of region [n]
17
- npx --yes @only-cli/oc@0.5.7 raw [url] whole page as markdown (--html for cleaned HTML)
18
- npx --yes @only-cli/oc@0.5.7 login seed cookies (--cookie, --domain, --expires)
19
- npx --yes @only-cli/oc@0.5.7 logout [session] forget a session: cookies and saved page
20
- npx --yes @only-cli/oc@0.5.7 session ls list saved sessions (name, url, title)
21
- npx --yes @only-cli/oc@0.5.7 session rm [name] forget a saved session: page and cookies
15
+ npx --yes @only-cli/oc@0.5.8 next next ~500 tokens of the page already open
16
+ npx --yes @only-cli/oc@0.5.8 read <n> full text of region [n]
17
+ npx --yes @only-cli/oc@0.5.8 raw [url] whole page as markdown (--html for cleaned HTML)
18
+ npx --yes @only-cli/oc@0.5.8 login seed cookies (--cookie, --domain, --expires)
19
+ npx --yes @only-cli/oc@0.5.8 logout [session] forget a session: cookies and saved page
20
+ npx --yes @only-cli/oc@0.5.8 session ls list saved sessions (name, url, title)
21
+ npx --yes @only-cli/oc@0.5.8 session rm [name] forget a saved session: page and cookies
22
22
  ```
23
23
 
24
24
  None of these except `open`/`do`/`raw <url>` fetch anything; they replay the page `open` already saved.
package/src/act.js CHANGED
@@ -81,7 +81,8 @@ export function activate(n, { session = DEFAULT_SESSION } = {}) {
81
81
  // and opening it is what `do` was asked for. Reading the title back instead
82
82
  // cost a turn, and then another to find the number that does navigate, so a
83
83
  // heading that has an href falls through to the link below.
84
- if ((handle.type === 'text' || handle.type === 'heading') && !handle.href) {
84
+ // A link with no href, a fragment or mailto:, has nothing to fetch either.
85
+ if (['text', 'heading', 'link'].includes(handle.type) && !handle.href) {
85
86
  // There is nothing to follow, but the agent asked to see what is at [n],
86
87
  // and that is what read prints. Refusing would spend a whole turn to name
87
88
  // the command that should have run, and a turn costs more than the page.
@@ -245,7 +246,7 @@ export function find(query, { session = DEFAULT_SESSION, budget = 500 } = {}) {
245
246
  // the example it names was in the block after it.
246
247
  if (hits.length === 1 && hits[0].n != null) {
247
248
  const only = hits[0];
248
- const follow = only.type === 'link' || only.href ? 'do <n> | ' : '';
249
+ const follow = only.href ? 'do <n> | ' : '';
249
250
  return [
250
251
  `1 match for "${query}"${separately}, region [${only.n}]`,
251
252
  read(only.n, { session, budget: budget * FINISH }),
@@ -273,7 +274,7 @@ export function find(query, { session = DEFAULT_SESSION, budget = 500 } = {}) {
273
274
  if (spent + cost > cap && shown) break;
274
275
  spent += cost;
275
276
  shown++;
276
- if (hit.type === 'link' || hit.href) hasLinks = true;
277
+ if (hit.href) hasLinks = true;
277
278
  lines.push(line);
278
279
  }
279
280
  if (shown < hits.length) {
package/src/distill.js CHANGED
@@ -250,14 +250,13 @@ export function distill(html, url = '') {
250
250
  return;
251
251
  }
252
252
  if (tag === 'a' && node.getAttribute('href')) {
253
- const href = node.getAttribute('href');
254
253
  // Same rule as headingHref: a fragment is this page, mailto: is not a
255
- // page. Walk children so the label stays readable text instead of a
256
- // numbered handle that do cannot fetch.
257
- if (!isFollowableHref(href, base, url)) {
258
- for (const child of node.childNodes) walk(child);
259
- return;
260
- }
254
+ // page. The link keeps its number without the href, because a fragment
255
+ // is often the one handle on a place: rdoc's method signature links to
256
+ // its own id, and as plain text find borrowed the number above it,
257
+ // which read then opened on the method before.
258
+ const raw = node.getAttribute('href');
259
+ const href = isFollowableHref(raw, base, url) ? raw : null;
261
260
  // An icon button already takes aria-label or title because it has no
262
261
  // text. An anchor around an image is the same shape: img alt is the
263
262
  // accessible name and is not a text node, so textContent is empty and
@@ -268,7 +267,7 @@ export function distill(html, url = '') {
268
267
  || clean(node.getAttribute('title') ?? '')
269
268
  || clean(node.querySelector('img')?.getAttribute('alt') ?? '');
270
269
  if (text) {
271
- blocks.push({ type: 'link', text, href });
270
+ blocks.push({ type: 'link', text, ...(href ? { href } : {}) });
272
271
  }
273
272
  return;
274
273
  }
package/src/render.js CHANGED
@@ -128,8 +128,9 @@ export function render(page, { budget = 500, from = 0 } = {}) {
128
128
  spent += cost;
129
129
  lines.push(line);
130
130
  // A heading that is a link (search result titles) is what do follows, so
131
- // it has to count here or the footer omits do on a page of only those.
132
- if (block.type === 'link' || block.type === 'button' || block.href) hasLinks = true;
131
+ // it has to count here or the footer omits do on a page of only those. A
132
+ // link with no href is a fragment or mailto:, which do only reads.
133
+ if (block.type === 'button' || block.href) hasLinks = true;
133
134
  }
134
135
 
135
136
  const rest = blocks.slice(i);