mirror of
https://github.com/jackwener/OpenCLI.git
synced 2026-09-14 18:25:42 +08:00
977105b0f6
* feat(hackernews): add `read <id>` and surface item id on every listing Two related agent-flow gaps in the HN adapters: 1. `top`/`best`/`ask`/`new`/`show`/`jobs`/`search` all carry the HN item id internally (firebase items are fetched by id; algolia hits include `objectID`) but drop it before output. Without an id column the agent can see the title but has no handle to follow up with. 2. There was no way to read a story's discussion. The whole reason an agent looks at HN is the comments — and that capability was missing. This PR adds: - `id` column on every listing adapter (firebase items: numeric id; algolia search hits: `objectID` string). Existing column order is preserved otherwise. - `hackernews read <id>` — public/non-browser adapter that fetches the story plus a tree of top-level comments + inline replies via `https://hacker-news.firebaseio.com/v0/item/<id>.json`. Mirrors the `reddit read` shape (`type/author/score/text`) so agents can use both with one mental model. HTML-only fields (comment text) are converted to plain text with anchor URLs preserved. - Column-contract tests covering all listings + the new read adapter. - Doc entry under `docs/adapters/browser/hackernews.md`. Tested locally via `~/.opencli/clis/hackernews/` overrides: opencli hackernews top --limit 3 # id present opencli hackernews search rust --limit 2 # id (objectID) present opencli hackernews read 47999636 --limit 5 # threaded output * fix(hackernews): typed fail-fast for read
31 lines
1.2 KiB
JavaScript
31 lines
1.2 KiB
JavaScript
import { cli, Strategy } from '@jackwener/opencli/registry';
|
|
cli({
|
|
site: 'hackernews',
|
|
name: 'ask',
|
|
description: 'Hacker News Ask HN posts',
|
|
domain: 'news.ycombinator.com',
|
|
strategy: Strategy.PUBLIC,
|
|
browser: false,
|
|
args: [
|
|
{ name: 'limit', type: 'int', default: 20, help: 'Number of stories' },
|
|
],
|
|
columns: ['rank', 'id', 'title', 'score', 'author', 'comments', 'url'],
|
|
pipeline: [
|
|
{ fetch: { url: 'https://hacker-news.firebaseio.com/v0/askstories.json' } },
|
|
{ limit: '${{ Math.min((args.limit ? args.limit : 20) + 10, 50) }}' },
|
|
{ map: { id: '${{ item }}' } },
|
|
{ fetch: { url: 'https://hacker-news.firebaseio.com/v0/item/${{ item.id }}.json' } },
|
|
{ filter: 'item.title && !item.deleted && !item.dead' },
|
|
{ map: {
|
|
rank: '${{ index + 1 }}',
|
|
id: '${{ item.id }}',
|
|
title: '${{ item.title }}',
|
|
score: '${{ item.score }}',
|
|
author: '${{ item.by }}',
|
|
comments: '${{ item.descendants }}',
|
|
url: '${{ item.url }}',
|
|
} },
|
|
{ limit: '${{ args.limit }}' },
|
|
],
|
|
});
|