Skip to content

Commit 807f8a1

Browse files
committed
v0.2.0: feature parity with the official Mozilla-Ocho CLI
- input <request-id> --data: respond to paused automations (human-in-the-loop), with interactive:form_data:request surfaced in the automate stream - status: show key source (flag/env/config), base URL, config path — never the key - output modes: pretty on TTY, JSON when piped; -o/--output to force; streams emit NDJSON (one event per line) in JSON mode; --json kept as alias - color on stderr progress, --no-color and NO_COLOR honored - extract markdown: --metadata, --effort, --nocache, --geo - automate: --max-validation-attempts, range validation on --max-iterations - global --base-url and --timeout (non-streaming) flags - exit codes: 0 ok, 1 runtime/API, 2 usage, 3 task-reported failure - scripts/enrich-post.sh: blog-post enrichment pipeline (extract → generate → parallel live extracts → research → FAQ JSON-LD), used for the June 2026 post - tests: 20 → 33 e2e tests; readStdin fixed for TS 5.7
1 parent 1858095 commit 807f8a1

9 files changed

Lines changed: 562 additions & 109 deletions

File tree

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ node_modules/
22
tabstack
33
*.bun-build
44
.DS_Store
5+
enrichment/

‎README.md‎

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ tabstack research "tabs vs spaces: what do the major style guides actually recom
3434
tabstack automate "find the top 3 trending repos and their star counts" \
3535
--url https://github.com/trending
3636

37-
# Pipe it like any good Unix citizen
38-
tabstack extract markdown https://example.com | wc -w
37+
# Pipe it like any good Unix citizen — piped output is JSON automatically
38+
tabstack extract markdown https://example.com | jq -r .content | wc -w
3939
```
4040

4141
Fun fact: the Product Hunt example above is how this repo checked Tabstack's
@@ -81,11 +81,13 @@ verifies the key with one cheap API call; skip that with `--no-verify`.
8181
```text
8282
tabstack login Open console & store an API key
8383
tabstack logout Remove the stored API key
84-
tabstack extract markdown <url> Page → clean markdown
84+
tabstack status How your key resolves (never prints it)
85+
tabstack extract markdown <url> [--metadata] Page → clean markdown
8586
tabstack extract json <url> --schema S Page → JSON matching a schema
8687
tabstack generate json <url> --schema S --instructions T AI-transform a page → JSON
8788
tabstack research "<query>" Multi-source research (streaming)
8889
tabstack automate "<task>" [--url U] Browser automation (streaming)
90+
tabstack input <request-id> --data D Answer a paused automation
8991
```
9092

9193
Run `tabstack help` for the full flag reference.
@@ -115,12 +117,14 @@ tabstack generate json https://blog.example.com/post \
115117
### Research (streaming)
116118

117119
Progress is printed to **stderr**; the final markdown report goes to **stdout**,
118-
so you can redirect it cleanly. `--json` emits the full `complete` payload.
120+
so you can redirect it cleanly. In JSON mode the stream is NDJSON, one event
121+
per line.
119122

120123
```bash
121124
tabstack research "approaches to browser automation for AI agents" --mode fast
122-
tabstack research "EU vs US AI regulation" --mode balanced > report.md
123-
tabstack research "competitor pricing" --json | jq .metadata.citedPages
125+
tabstack research "EU vs US AI regulation" --mode balanced -o pretty > report.md
126+
tabstack research "competitor pricing" \
127+
| jq -r 'select(.event=="complete") | .data.metadata.citedPages'
124128
```
125129

126130
### Automate (streaming)
@@ -137,12 +141,26 @@ tabstack automate "fill the contact form and submit" \
137141
--data @form.json --allow-actions --max-iterations 30
138142
```
139143

144+
When an automation pauses and asks for input (`interactive:form_data:request`),
145+
the CLI prints the request id and how to answer it:
146+
147+
```bash
148+
tabstack input <request-id> --data '{"fields":[{"ref":"field1","value":"yes"}]}'
149+
tabstack input <request-id> --data '{"cancelled":true}' # decline
150+
```
151+
140152
## Output conventions
141153

142154
- **stdout** — the data (markdown, JSON, report, final answer). Pipeable.
143155
- **stderr** — progress, status, citations, errors.
144-
- **`--json`** — machine-readable JSON on every data command.
145-
- **exit code** — `0` on success, `1` on any error (usage, auth, or API).
156+
- **Output mode** — pretty (human-readable) on a TTY, JSON when piped, so
157+
`tabstack ... | jq .` just works. Force with `-o pretty|json` (`--json` is
158+
shorthand for `-o json`). Streaming commands emit NDJSON in JSON mode.
159+
- **Color** — disabled when piped, with `--no-color`, or via `NO_COLOR`.
160+
- **exit code** — `0` success · `1` runtime/API error · `2` usage error ·
161+
`3` the task itself reported failure.
162+
- **`--base-url <url>`** / `TABSTACK_BASE_URL` for self-hosted or staging;
163+
`--timeout <seconds>` for non-streaming calls.
146164

147165
## Endpoints used
148166

@@ -153,11 +171,12 @@ tabstack automate "fill the contact form and submit" \
153171
| `generate json` | `POST /v1/generate/json` | JSON |
154172
| `research` | `POST /v1/research` | SSE |
155173
| `automate` | `POST /v1/automate` | SSE |
174+
| `input` | `POST /v1/automate/{id}/input` | JSON |
156175

157176
## Develop
158177

159178
```bash
160-
bun test # mock-server end-to-end tests (20 tests)
179+
bun test # mock-server end-to-end tests (33 tests)
161180
bun x -p typescript tsc --noEmit # typecheck
162181
bun run start --help
163182
```
@@ -180,5 +199,7 @@ test/
180199
- `--schema` and `--data` accept `@file`, `-` (stdin), or inline JSON;
181200
`--instructions` accepts `@file`, `-`, or a literal string.
182201
- `balanced` research mode requires a paid Tabstack plan.
183-
- `automate` interactive (human-in-the-loop) form filling is not wired into
184-
this CLI yet; runs are non-interactive.
202+
- Feature parity with the official
203+
[Mozilla-Ocho/tabstack-cli](https://github.com/Mozilla-Ocho/tabstack-cli)
204+
(Go), plus two extras: safe-by-default `automate` guardrails and a
205+
browser-opening `login` that verifies the key before storing it.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tabstack-cli",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "Gold-standard Bun CLI for the Tabstack AI web extraction, generation, research, and automation API",
55
"type": "module",
66
"bin": {

‎scripts/enrich-post.sh‎

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/usr/bin/env bash
2+
#
3+
# enrich-post.sh — dogfood pipeline: enrich a (possibly stale) blog post with
4+
# live data, composing tabstack's extract, generate, and research commands.
5+
#
6+
# 1. extract markdown — pull the post itself
7+
# 2. generate json — structure the post's leaderboard claims (stars, pricing)
8+
# 3. extract json ×N — re-extract LIVE star counts from each GitHub repo page
9+
# 4. research — what changed in the landscape since the post's date
10+
# 5. generate json — FAQ JSON-LD for the post (SEO/GEO enrichment)
11+
#
12+
# Output: enrichment/<slug>/ with raw artifacts + report.md (star-drift table,
13+
# landscape update with citations, ready-to-paste FAQ schema).
14+
#
15+
# Usage: scripts/enrich-post.sh [post-url]
16+
17+
set -euo pipefail
18+
19+
POST_URL="${1:-https://zero8.dev/blog/state-of-agentic-harnesses-march-2026}"
20+
SLUG=$(basename "$POST_URL")
21+
OUT="enrichment/$SLUG"
22+
TAB="bun run src/index.ts"
23+
mkdir -p "$OUT"
24+
25+
echo "→ [1/5] extracting post" >&2
26+
$TAB extract markdown "$POST_URL" --json > "$OUT/post.json"
27+
28+
echo "→ [2/5] structuring the post's leaderboard claims" >&2
29+
$TAB generate json "$POST_URL" \
30+
--instructions "From the leaderboard section, list every coding tool that has a GitHub repo link. For each: tool name, the owner/repo slug from its github.com link, and the star count the article claims (convert 130.7K to 130700). Also record the article's data date." \
31+
--schema '{
32+
"type": "object",
33+
"properties": {
34+
"data_date": {"type": "string"},
35+
"tools": {"type": "array", "items": {"type": "object", "properties": {
36+
"name": {"type": "string"},
37+
"repo": {"type": "string"},
38+
"claimed_stars": {"type": "number"}
39+
}, "required": ["name", "repo", "claimed_stars"]}}
40+
}
41+
}' > "$OUT/claims.json"
42+
43+
echo "→ [3/5] re-extracting live star counts from GitHub (parallel)" >&2
44+
mkdir -p "$OUT/live"
45+
while IFS=$'\t' read -r name repo; do
46+
(
47+
$TAB extract json "https://github.com/$repo" --effort min --nocache \
48+
--schema '{"type":"object","properties":{"stars":{"type":"number","description":"the repository star count as a full number, e.g. 130700 not 130.7K"}},"required":["stars"]}' \
49+
> "$OUT/live/${repo//\//__}.json" 2>/dev/null \
50+
|| echo '{"stars": null}' > "$OUT/live/${repo//\//__}.json"
51+
) &
52+
done < <(jq -r '.tools[] | [.name, .repo] | @tsv' "$OUT/claims.json")
53+
wait
54+
55+
echo "→ [4/5] researching what changed since the post's date" >&2
56+
DATA_DATE=$(jq -r '.data_date // "March 2026"' "$OUT/claims.json")
57+
$TAB research "What has changed in the AI agentic coding tool landscape since $DATA_DATE (today is June 2026)? Cover: major releases or new features in Claude Code, OpenCode, Gemini CLI, Codex CLI, Cursor, Cline, Aider, Goose, and Copilot; any pricing changes; any new credible entrants or notable shutdowns/acquisitions." \
58+
--mode fast --json > "$OUT/research.ndjson"
59+
jq -r 'select(.event=="complete") | .data.report' "$OUT/research.ndjson" > "$OUT/research.md"
60+
jq -c 'select(.event=="complete") | .data.metadata.citedPages // .data.metadata.cited_pages // []' "$OUT/research.ndjson" > "$OUT/citations.json"
61+
62+
echo "→ [5/5] generating FAQ JSON-LD from the post" >&2
63+
$TAB generate json "$POST_URL" \
64+
--instructions "Write 5 FAQ question/answer pairs a developer choosing an agentic coding tool would ask, answered strictly from this article's content. Questions should match real search queries." \
65+
--schema '{
66+
"type": "object",
67+
"properties": {"faq": {"type": "array", "items": {"type": "object", "properties": {
68+
"question": {"type": "string"},
69+
"answer": {"type": "string"}
70+
}, "required": ["question", "answer"]}}}
71+
}' > "$OUT/faq.json"
72+
73+
# ---- stitch the report -----------------------------------------------------
74+
75+
echo "→ assembling $OUT/report.md" >&2
76+
{
77+
echo "# Enrichment report: $SLUG"
78+
echo
79+
echo "Post: $POST_URL · article data date: $DATA_DATE · enriched: $(date +%Y-%m-%d)"
80+
echo
81+
echo "## Star drift (claimed vs live)"
82+
echo
83+
echo "| Tool | Repo | Article | Live now | Δ |"
84+
echo "|------|------|--------:|---------:|--:|"
85+
while IFS=$'\t' read -r name repo claimed; do
86+
live=$(jq -r '.stars // empty' "$OUT/live/${repo//\//__}.json" 2>/dev/null || true)
87+
if [[ -n "$live" && "$live" != "null" ]]; then
88+
delta=$(( ${live%.*} - ${claimed%.*} ))
89+
printf '| %s | %s | %s | %s | %+d |\n' "$name" "$repo" "$claimed" "$live" "$delta"
90+
else
91+
printf '| %s | %s | %s | _extract failed_ | — |\n' "$name" "$repo" "$claimed"
92+
fi
93+
done < <(jq -r '.tools[] | [.name, .repo, .claimed_stars] | @tsv' "$OUT/claims.json")
94+
echo
95+
echo "## What changed since $DATA_DATE (researched, with citations)"
96+
echo
97+
cat "$OUT/research.md"
98+
echo
99+
echo "### Sources"
100+
echo
101+
jq -r '.[] | "- [\(.title // "untitled")](\(.url))"' "$OUT/citations.json"
102+
echo
103+
echo "## FAQ JSON-LD (paste into the post's <head>)"
104+
echo
105+
echo '```html'
106+
echo '<script type="application/ld+json">'
107+
jq '{"@context": "https://schema.org", "@type": "FAQPage", "mainEntity": [.faq[] | {"@type": "Question", "name": .question, "acceptedAnswer": {"@type": "Answer", "text": .answer}}]}' "$OUT/faq.json"
108+
echo '</script>'
109+
echo '```'
110+
} > "$OUT/report.md"
111+
112+
echo "done: $OUT/report.md" >&2

‎src/client.ts‎

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@
99
* with the HTTP status attached, so the CLI can print one clean line to stderr.
1010
*/
1111

12-
import { BASE_URL } from "./config";
12+
import { getBaseUrl } from "./config";
13+
14+
/** Optional timeout (seconds) for non-streaming calls, set by --timeout. */
15+
let requestTimeoutSecs: number | undefined;
16+
17+
export function setRequestTimeout(seconds: number): void {
18+
requestTimeoutSecs = seconds;
19+
}
1320

1421
export class TabstackError extends Error {
1522
status: number;
@@ -46,11 +53,20 @@ export async function postJson<T = unknown>(
4653
body: unknown,
4754
apiKey: string,
4855
): Promise<T> {
49-
const res = await fetch(`${BASE_URL}${path}`, {
50-
method: "POST",
51-
headers: headers(apiKey),
52-
body: JSON.stringify(body),
53-
});
56+
let res: Response;
57+
try {
58+
res = await fetch(`${getBaseUrl()}${path}`, {
59+
method: "POST",
60+
headers: headers(apiKey),
61+
body: JSON.stringify(body),
62+
signal: requestTimeoutSecs ? AbortSignal.timeout(requestTimeoutSecs * 1000) : undefined,
63+
});
64+
} catch (err) {
65+
if (err instanceof Error && err.name === "TimeoutError") {
66+
throw new TabstackError(0, `request timed out after ${requestTimeoutSecs}s`);
67+
}
68+
throw err;
69+
}
5470
if (!res.ok) await raise(res);
5571
return (await res.json()) as T;
5672
}
@@ -75,7 +91,7 @@ export async function* postStream(
7591
body: unknown,
7692
apiKey: string,
7793
): AsyncGenerator<SseEvent> {
78-
const res = await fetch(`${BASE_URL}${path}`, {
94+
const res = await fetch(`${getBaseUrl()}${path}`, {
7995
method: "POST",
8096
headers: headers(apiKey, "text/event-stream"),
8197
body: JSON.stringify(body),

‎src/config.ts‎

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,17 @@ import { homedir } from "os";
99
import { join } from "path";
1010
import { readFileSync, writeFileSync, mkdirSync, rmSync, existsSync, chmodSync } from "fs";
1111

12-
/** API base URL. Override with TABSTACK_BASE_URL for self-hosted/staging. */
13-
export const BASE_URL = (
14-
process.env.TABSTACK_BASE_URL || "https://api.tabstack.ai"
15-
).replace(/\/+$/, "");
12+
/** API base URL: --base-url flag > TABSTACK_BASE_URL env > default. */
13+
let baseUrl = (process.env.TABSTACK_BASE_URL || "https://api.tabstack.ai").replace(/\/+$/, "");
14+
15+
export function getBaseUrl(): string {
16+
return baseUrl;
17+
}
18+
19+
/** Apply a --base-url override (called once from the CLI entry point). */
20+
export function setBaseUrl(url: string): void {
21+
baseUrl = url.replace(/\/+$/, "");
22+
}
1623

1724
/** Where `tabstack login` stores the key. Honors XDG; override for tests. */
1825
export const CONFIG_DIR =
@@ -31,6 +38,7 @@ export const ENDPOINTS = {
3138
generateJson: "/v1/generate/json",
3239
research: "/v1/research",
3340
automate: "/v1/automate",
41+
automateInput: (requestId: string) => `/v1/automate/${encodeURIComponent(requestId)}/input`,
3442
} as const;
3543

3644
/**
@@ -42,14 +50,29 @@ export const ENDPOINTS = {
4250
* Throws a clear, actionable error if none are present.
4351
*/
4452
export function getApiKey(override?: string): string {
45-
const key = override || process.env.TABSTACK_API_KEY || readStoredKey();
46-
if (!key) {
53+
const resolved = resolveKey(override);
54+
if (!resolved) {
4755
throw new Error(
4856
"Not authenticated. Run 'tabstack login', set TABSTACK_API_KEY, or pass --api-key <key>.\n" +
4957
"Create a key at " + CONSOLE_URL + " (API Keys → Create New API Key).",
5058
);
5159
}
52-
return key;
60+
return resolved.key;
61+
}
62+
63+
export type KeySource = "--api-key flag" | "TABSTACK_API_KEY env" | "config file";
64+
65+
/**
66+
* Resolve the key together with where it came from, for `tabstack status`.
67+
* Never returns or prints the key value to the user — only its source.
68+
*/
69+
export function resolveKey(override?: string): { key: string; source: KeySource } | undefined {
70+
if (override) return { key: override, source: "--api-key flag" };
71+
if (process.env.TABSTACK_API_KEY)
72+
return { key: process.env.TABSTACK_API_KEY, source: "TABSTACK_API_KEY env" };
73+
const stored = readStoredKey();
74+
if (stored) return { key: stored, source: "config file" };
75+
return undefined;
5376
}
5477

5578
/** Read the stored API key, or undefined if not logged in / unreadable. */

0 commit comments

Comments
 (0)