api-everything 0.5.0__py3-none-any.whl
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.
- api_everything/__init__.py +3 -0
- api_everything/__main__.py +8 -0
- api_everything/check.py +168 -0
- api_everything/chrome_cmd.py +131 -0
- api_everything/cli.py +803 -0
- api_everything/config.py +321 -0
- api_everything/delivery.py +518 -0
- api_everything/delivery_git.py +94 -0
- api_everything/driver/__init__.py +37 -0
- api_everything/driver/attach.py +95 -0
- api_everything/driver/base.py +80 -0
- api_everything/driver/chrome.py +127 -0
- api_everything/driver/profile.py +84 -0
- api_everything/engine.py +381 -0
- api_everything/errors.py +23 -0
- api_everything/hooks.py +52 -0
- api_everything/login.py +95 -0
- api_everything/mcp_bridge.py +249 -0
- api_everything/metrics.py +87 -0
- api_everything/mock_site/__init__.py +5 -0
- api_everything/mock_site/__main__.py +18 -0
- api_everything/mock_site/app.py +262 -0
- api_everything/pipeline.py +934 -0
- api_everything/pool.py +553 -0
- api_everything/ratelimit.py +67 -0
- api_everything/recipe/__init__.py +6 -0
- api_everything/recipe/actions.py +56 -0
- api_everything/recipe/jsonpath.py +22 -0
- api_everything/recipe/loader.py +142 -0
- api_everything/recipe/params.py +120 -0
- api_everything/recipe/schema.py +235 -0
- api_everything/recipes/alignmentforum/feed.yaml +15 -0
- api_everything/recipes/alpine_docs/search.yaml +32 -0
- api_everything/recipes/angular_docs/search.yaml +32 -0
- api_everything/recipes/anthropic_status/summary.yaml +17 -0
- api_everything/recipes/apis_guru/providers.yaml +15 -0
- api_everything/recipes/arbeitnow/jobs.yaml +20 -0
- api_everything/recipes/arin_rdap/ip.yaml +24 -0
- api_everything/recipes/artifacthub/browse.yaml +22 -0
- api_everything/recipes/artifacthub/search.yaml +24 -0
- api_everything/recipes/astro_docs/search.yaml +32 -0
- api_everything/recipes/atlassian_status/summary.yaml +17 -0
- api_everything/recipes/babel_docs/search.yaml +32 -0
- api_everything/recipes/binance/price.yaml +24 -0
- api_everything/recipes/bugzilla/bugs.yaml +24 -0
- api_everything/recipes/bundlephobia/size.yaml +24 -0
- api_everything/recipes/caddy_docs/search.yaml +32 -0
- api_everything/recipes/caniuse/search.yaml +24 -0
- api_everything/recipes/capacitor_docs/search.yaml +32 -0
- api_everything/recipes/cdnjs/library.yaml +22 -0
- api_everything/recipes/cdnjs/search.yaml +27 -0
- api_everything/recipes/certspotter/issuances.yaml +27 -0
- api_everything/recipes/cheerio_docs/search.yaml +32 -0
- api_everything/recipes/circleci_status/summary.yaml +17 -0
- api_everything/recipes/cisa_kev/catalog.yaml +17 -0
- api_everything/recipes/civitai/models.yaml +26 -0
- api_everything/recipes/cloudflare_status/summary.yaml +17 -0
- api_everything/recipes/cncf_landscape/projects.yaml +20 -0
- api_everything/recipes/cncf_landscape/ui.yaml +18 -0
- api_everything/recipes/coinbase/rates.yaml +24 -0
- api_everything/recipes/coingecko/trending.yaml +17 -0
- api_everything/recipes/conda_forge/package.yaml +25 -0
- api_everything/recipes/crates/categories.yaml +15 -0
- api_everything/recipes/crates/downloads.yaml +22 -0
- api_everything/recipes/crates/keywords.yaml +15 -0
- api_everything/recipes/crates/reverse_deps.yaml +22 -0
- api_everything/recipes/crates/search.yaml +24 -0
- api_everything/recipes/crates/summary.yaml +15 -0
- api_everything/recipes/crates/user.yaml +22 -0
- api_everything/recipes/crates/versions.yaml +22 -0
- api_everything/recipes/crossref/works.yaml +24 -0
- api_everything/recipes/cve_org/record.yaml +24 -0
- api_everything/recipes/debian_sources/search.yaml +24 -0
- api_everything/recipes/deps_dev/npm_spa.yaml +22 -0
- api_everything/recipes/deps_dev/package.yaml +23 -0
- api_everything/recipes/devdocs/index.yaml +18 -0
- api_everything/recipes/devto/articles.yaml +26 -0
- api_everything/recipes/devto/latest.yaml +18 -0
- api_everything/recipes/devto/tags.yaml +18 -0
- api_everything/recipes/devto/top.yaml +18 -0
- api_everything/recipes/digitalocean_status/summary.yaml +17 -0
- api_everything/recipes/digitalocean_status/ui.yaml +15 -0
- api_everything/recipes/discord_status/summary.yaml +17 -0
- api_everything/recipes/dns_google/resolve.yaml +24 -0
- api_everything/recipes/drizzle_docs/search.yaml +32 -0
- api_everything/recipes/echojs/latest.yaml +17 -0
- api_everything/recipes/ecosystems/package.yaml +25 -0
- api_everything/recipes/endoflife/product.yaml +24 -0
- api_everything/recipes/epss/score.yaml +24 -0
- api_everything/recipes/exchangerate/latest.yaml +24 -0
- api_everything/recipes/firefox_addons/search.yaml +26 -0
- api_everything/recipes/fly_status/summary.yaml +17 -0
- api_everything/recipes/formik_docs/search.yaml +32 -0
- api_everything/recipes/frankfurter/rates.yaml +24 -0
- api_everything/recipes/gcp_status/incidents.yaml +20 -0
- api_everything/recipes/github/explore.yaml +35 -0
- api_everything/recipes/github/gists.yaml +18 -0
- api_everything/recipes/github/issues.yaml +30 -0
- api_everything/recipes/github/license.yaml +23 -0
- api_everything/recipes/github/org.yaml +22 -0
- api_everything/recipes/github/releases.yaml +30 -0
- api_everything/recipes/github/repo.yaml +28 -0
- api_everything/recipes/github/user.yaml +22 -0
- api_everything/recipes/github_advisories/list.yaml +20 -0
- api_everything/recipes/github_status/summary.yaml +17 -0
- api_everything/recipes/github_status/ui.yaml +15 -0
- api_everything/recipes/gitlab/issues.yaml +24 -0
- api_everything/recipes/gitlab/repo.yaml +21 -0
- api_everything/recipes/gitlab/search.yaml +26 -0
- api_everything/recipes/go_proxy/latest.yaml +24 -0
- api_everything/recipes/grafana_status/summary.yaml +17 -0
- api_everything/recipes/hackage/versions.yaml +24 -0
- api_everything/recipes/hackernews/ask.yaml +18 -0
- api_everything/recipes/hackernews/front_page.yaml +18 -0
- api_everything/recipes/hackernews/item.yaml +21 -0
- api_everything/recipes/hackernews/jobs.yaml +18 -0
- api_everything/recipes/hackernews/latest.yaml +25 -0
- api_everything/recipes/hackernews/search.yaml +34 -0
- api_everything/recipes/hackernews/show.yaml +18 -0
- api_everything/recipes/hashicorp_releases/list.yaml +27 -0
- api_everything/recipes/hashicorp_status/summary.yaml +17 -0
- api_everything/recipes/helm_docs/search.yaml +32 -0
- api_everything/recipes/heroku_status/current.yaml +17 -0
- api_everything/recipes/hexpm/search.yaml +27 -0
- api_everything/recipes/hf_papers/daily.yaml +20 -0
- api_everything/recipes/himalayas/jobs.yaml +17 -0
- api_everything/recipes/homebrew/cask.yaml +22 -0
- api_everything/recipes/homebrew/formula.yaml +26 -0
- api_everything/recipes/hono_docs/search.yaml +32 -0
- api_everything/recipes/httpbin/json.yaml +17 -0
- api_everything/recipes/httpbin/uuid.yaml +15 -0
- api_everything/recipes/huggingface/datasets.yaml +25 -0
- api_everything/recipes/huggingface/model_info.yaml +27 -0
- api_everything/recipes/huggingface/models.yaml +28 -0
- api_everything/recipes/huggingface/spaces.yaml +25 -0
- api_everything/recipes/inspirehep/papers.yaml +24 -0
- api_everything/recipes/ionic_docs/search.yaml +32 -0
- api_everything/recipes/ipify/ipv4.yaml +17 -0
- api_everything/recipes/ipwho/lookup.yaml +24 -0
- api_everything/recipes/jest_docs/search.yaml +32 -0
- api_everything/recipes/jsdelivr/gh.yaml +27 -0
- api_everything/recipes/jsdelivr/npm.yaml +24 -0
- api_everything/recipes/jsr/search.yaml +27 -0
- api_everything/recipes/launchdarkly_status/summary.yaml +17 -0
- api_everything/recipes/lemmy/hot.yaml +17 -0
- api_everything/recipes/lesswrong/feed.yaml +17 -0
- api_everything/recipes/llamaindex_docs/search.yaml +32 -0
- api_everything/recipes/lobsters/hottest.yaml +20 -0
- api_everything/recipes/luma/category.yaml +22 -0
- api_everything/recipes/luma/events.yaml +17 -0
- api_everything/recipes/mastodon/explore.yaml +26 -0
- api_everything/recipes/mastodon/tag.yaml +23 -0
- api_everything/recipes/mastodon/trends_tags.yaml +18 -0
- api_everything/recipes/mdn/search.yaml +24 -0
- api_everything/recipes/metacpan/search.yaml +24 -0
- api_everything/recipes/microlink/preview.yaml +24 -0
- api_everything/recipes/mikro_orm_docs/search.yaml +32 -0
- api_everything/recipes/mock/items.yaml +35 -0
- api_everything/recipes/mongodb_status/summary.yaml +17 -0
- api_everything/recipes/nager_date/holidays.yaml +32 -0
- api_everything/recipes/neon_docs/search.yaml +32 -0
- api_everything/recipes/nestjs_docs/search.yaml +32 -0
- api_everything/recipes/netlify_status/summary.yaml +17 -0
- api_everything/recipes/nextjs_docs/search.yaml +32 -0
- api_everything/recipes/nodejs_dist/releases.yaml +17 -0
- api_everything/recipes/npm/dist_tags.yaml +22 -0
- api_everything/recipes/npm/package.yaml +25 -0
- api_everything/recipes/npm/search.yaml +25 -0
- api_everything/recipes/npm_downloads/weekly.yaml +24 -0
- api_everything/recipes/npm_status/summary.yaml +17 -0
- api_everything/recipes/npmtrends/compare.yaml +22 -0
- api_everything/recipes/nuget/search.yaml +27 -0
- api_everything/recipes/nuxt_docs/search.yaml +32 -0
- api_everything/recipes/nvd/cve.yaml +22 -0
- api_everything/recipes/nvd/cves.yaml +24 -0
- api_everything/recipes/open_elevation/lookup.yaml +29 -0
- api_everything/recipes/openai_status/summary.yaml +17 -0
- api_everything/recipes/opencollective/search.yaml +22 -0
- api_everything/recipes/openfda/events.yaml +17 -0
- api_everything/recipes/openlibrary/search.yaml +24 -0
- api_everything/recipes/openmeteo/forecast.yaml +17 -0
- api_everything/recipes/openrouter/models.yaml +20 -0
- api_everything/recipes/openstreetmap/geocode.yaml +27 -0
- api_everything/recipes/openstreetmap/reverse.yaml +27 -0
- api_everything/recipes/osv/vuln.yaml +24 -0
- api_everything/recipes/packagist/search.yaml +27 -0
- api_everything/recipes/peps/list.yaml +17 -0
- api_everything/recipes/pinia_docs/search.yaml +32 -0
- api_everything/recipes/pkg_go_dev/browse.yaml +15 -0
- api_everything/recipes/pkg_go_dev/package.yaml +25 -0
- api_everything/recipes/playwright_docs/search.yaml +32 -0
- api_everything/recipes/pnpm_docs/search.yaml +32 -0
- api_everything/recipes/pokeapi/pokemon.yaml +24 -0
- api_everything/recipes/posthog_docs/search.yaml +32 -0
- api_everything/recipes/postman_echo/get.yaml +24 -0
- api_everything/recipes/postman_status/summary.yaml +17 -0
- api_everything/recipes/preact_docs/search.yaml +32 -0
- api_everything/recipes/pubdev/search.yaml +24 -0
- api_everything/recipes/pubmed/search.yaml +24 -0
- api_everything/recipes/puppeteer_docs/search.yaml +32 -0
- api_everything/recipes/pypi/package.yaml +24 -0
- api_everything/recipes/pypi/version.yaml +27 -0
- api_everything/recipes/quay/search.yaml +27 -0
- api_everything/recipes/quora/answers.yaml +46 -0
- api_everything/recipes/qwik_docs/search.yaml +32 -0
- api_everything/recipes/ray_docs/search.yaml +32 -0
- api_everything/recipes/rdap/domain.yaml +24 -0
- api_everything/recipes/react_docs/search.yaml +32 -0
- api_everything/recipes/react_hook_form_docs/search.yaml +32 -0
- api_everything/recipes/reactrouter_docs/search.yaml +32 -0
- api_everything/recipes/reddit/search.yaml +48 -0
- api_everything/recipes/reddit_status/summary.yaml +17 -0
- api_everything/recipes/remoteok/jobs.yaml +17 -0
- api_everything/recipes/render_status/summary.yaml +17 -0
- api_everything/recipes/repology/project.yaml +24 -0
- api_everything/recipes/ripe_stat/prefix.yaml +24 -0
- api_everything/recipes/rollup_docs/search.yaml +32 -0
- api_everything/recipes/rsbuild_docs/search.yaml +32 -0
- api_everything/recipes/rubygems/gem.yaml +22 -0
- api_everything/recipes/rubygems/search.yaml +27 -0
- api_everything/recipes/sendgrid_status/summary.yaml +17 -0
- api_everything/recipes/sequelize_docs/search.yaml +32 -0
- api_everything/recipes/shodan_internetdb/host.yaml +24 -0
- api_everything/recipes/shopify_status/summary.yaml +17 -0
- api_everything/recipes/sigstore_rekor/log.yaml +17 -0
- api_everything/recipes/slack_status/current.yaml +17 -0
- api_everything/recipes/spdx/licenses.yaml +17 -0
- api_everything/recipes/stackexchange/sites.yaml +20 -0
- api_everything/recipes/stackoverflow/answers.yaml +15 -0
- api_everything/recipes/stackoverflow/questions.yaml +18 -0
- api_everything/recipes/stackoverflow/search.yaml +27 -0
- api_everything/recipes/stackoverflow/tags.yaml +18 -0
- api_everything/recipes/strapi_docs/search.yaml +32 -0
- api_everything/recipes/strawberry_docs/search.yaml +32 -0
- api_everything/recipes/stripe_status/current.yaml +17 -0
- api_everything/recipes/substack/explore.yaml +22 -0
- api_everything/recipes/substack/search.yaml +31 -0
- api_everything/recipes/sunrise_sunset/times.yaml +29 -0
- api_everything/recipes/supabase_status/summary.yaml +17 -0
- api_everything/recipes/swr_docs/search.yaml +32 -0
- api_everything/recipes/tanstack_docs/search.yaml +32 -0
- api_everything/recipes/tc39/proposals.yaml +20 -0
- api_everything/recipes/techempower/results.yaml +15 -0
- api_everything/recipes/temporal_docs/search.yaml +32 -0
- api_everything/recipes/terraform_registry/browse.yaml +25 -0
- api_everything/recipes/terraform_registry/search.yaml +24 -0
- api_everything/recipes/testing_library_docs/search.yaml +32 -0
- api_everything/recipes/tvmaze/shows.yaml +24 -0
- api_everything/recipes/twilio_status/summary.yaml +17 -0
- api_everything/recipes/upstash_docs/search.yaml +32 -0
- api_everything/recipes/valibot_docs/search.yaml +32 -0
- api_everything/recipes/vercel_status/summary.yaml +17 -0
- api_everything/recipes/vercel_status/ui.yaml +15 -0
- api_everything/recipes/vue_docs/search.yaml +32 -0
- api_everything/recipes/w3c/specs.yaml +17 -0
- api_everything/recipes/wayback/available.yaml +24 -0
- api_everything/recipes/webdriverio_docs/search.yaml +32 -0
- api_everything/recipes/webpack_docs/search.yaml +32 -0
- api_everything/recipes/wikidata/entity.yaml +22 -0
- api_everything/recipes/wikidata/search.yaml +24 -0
- api_everything/recipes/wikimedia_commons/search.yaml +25 -0
- api_everything/recipes/wikipedia/search.yaml +25 -0
- api_everything/recipes/wikipedia/summary.yaml +33 -0
- api_everything/recipes/wordpress_plugins/search.yaml +24 -0
- api_everything/recipes/wordpress_themes/search.yaml +24 -0
- api_everything/recipes/worldbank/indicator.yaml +17 -0
- api_everything/recipes/zenodo/records.yaml +24 -0
- api_everything/recipes/zippopotam/in.yaml +22 -0
- api_everything/recipes/zippopotam/lookup.yaml +29 -0
- api_everything/recipes/zoom_status/summary.yaml +17 -0
- api_everything/record.py +327 -0
- api_everything/record_session.py +364 -0
- api_everything/repair.py +717 -0
- api_everything/repair_ai.py +194 -0
- api_everything/runlog.py +61 -0
- api_everything/server.py +323 -0
- api_everything-0.5.0.dist-info/METADATA +363 -0
- api_everything-0.5.0.dist-info/RECORD +281 -0
- api_everything-0.5.0.dist-info/WHEEL +4 -0
- api_everything-0.5.0.dist-info/entry_points.txt +2 -0
- api_everything-0.5.0.dist-info/licenses/LICENSE +202 -0
api_everything/cli.py
ADDED
|
@@ -0,0 +1,803 @@
|
|
|
1
|
+
"""Command-line entry point.
|
|
2
|
+
|
|
3
|
+
api-everything validate check every recipe, then exit
|
|
4
|
+
api-everything serve run the daemon
|
|
5
|
+
api-everything check NAME... | --all run recipes' live checks
|
|
6
|
+
api-everything login PROFILE sign in by hand once, for `profile:<name>` recipes
|
|
7
|
+
api-everything chrome PROFILE start the Chrome an attached profile connects to
|
|
8
|
+
api-everything mcp expose recipes to an AI agent over MCP (stdio)
|
|
9
|
+
api-everything record URL browse once and generate a recipe
|
|
10
|
+
api-everything recipes pull|diff|apply|remove fetch shared recipes, apply what you approve
|
|
11
|
+
api-everything repair NAME draft a verified fix for a recipe the site broke
|
|
12
|
+
|
|
13
|
+
Exit codes: 0 success, 1 invalid recipes or failed checks, 2 bad usage or configuration,
|
|
14
|
+
3 the browser could not be started or the login could not proceed.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import argparse
|
|
20
|
+
import asyncio
|
|
21
|
+
import json
|
|
22
|
+
import logging
|
|
23
|
+
import shlex
|
|
24
|
+
import socket
|
|
25
|
+
import sys
|
|
26
|
+
from pathlib import Path
|
|
27
|
+
|
|
28
|
+
import httpx
|
|
29
|
+
import uvicorn
|
|
30
|
+
|
|
31
|
+
from api_everything import __version__
|
|
32
|
+
from api_everything.check import (
|
|
33
|
+
CheckSelectionError,
|
|
34
|
+
check_recipes,
|
|
35
|
+
daemon_base_url,
|
|
36
|
+
daemon_is_running,
|
|
37
|
+
daemon_runner,
|
|
38
|
+
notify,
|
|
39
|
+
run_locally,
|
|
40
|
+
select_recipes,
|
|
41
|
+
)
|
|
42
|
+
from api_everything.chrome_cmd import ChromeCommandError, start_chrome
|
|
43
|
+
from api_everything.config import Config, ConfigError, load_config
|
|
44
|
+
from api_everything.delivery_git import DeliveryError
|
|
45
|
+
from api_everything.driver import BrowserNotInstalled, BrowserNotRunning
|
|
46
|
+
from api_everything.errors import RunError
|
|
47
|
+
from api_everything.login import LoginError, run_login
|
|
48
|
+
from api_everything.pipeline import (
|
|
49
|
+
PipelineError,
|
|
50
|
+
default_catalog_path,
|
|
51
|
+
load_catalog,
|
|
52
|
+
parse_kv_params,
|
|
53
|
+
probe_target,
|
|
54
|
+
promote_recipe,
|
|
55
|
+
resolve_probe_url,
|
|
56
|
+
scaffold_recipe,
|
|
57
|
+
)
|
|
58
|
+
from api_everything.pool import Pool
|
|
59
|
+
from api_everything.recipe.loader import (
|
|
60
|
+
LoadedRecipes,
|
|
61
|
+
RecipeLoadError,
|
|
62
|
+
bundled_recipes_dir,
|
|
63
|
+
load_recipes,
|
|
64
|
+
)
|
|
65
|
+
from api_everything.server import create_app
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _add_common(parser: argparse.ArgumentParser, *, recipes: bool = True) -> None:
|
|
69
|
+
parser.add_argument("--config", type=Path, help="path to api-everything.yaml")
|
|
70
|
+
if recipes:
|
|
71
|
+
parser.add_argument(
|
|
72
|
+
"--recipes-dir", type=Path, help="your recipes directory (overrides the config file)"
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
77
|
+
parser = argparse.ArgumentParser(
|
|
78
|
+
prog="api-everything",
|
|
79
|
+
description="Serve a website's own internal JSON as an API using a real browser.",
|
|
80
|
+
)
|
|
81
|
+
parser.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
|
|
82
|
+
commands = parser.add_subparsers(dest="command")
|
|
83
|
+
|
|
84
|
+
validate = commands.add_parser(
|
|
85
|
+
"validate",
|
|
86
|
+
help="check every recipe without starting anything",
|
|
87
|
+
description="Load and validate the bundled recipes plus your own, then exit. "
|
|
88
|
+
"Uses the same checks the daemon runs at startup.",
|
|
89
|
+
)
|
|
90
|
+
_add_common(validate)
|
|
91
|
+
|
|
92
|
+
serve = commands.add_parser(
|
|
93
|
+
"serve",
|
|
94
|
+
help="run the daemon",
|
|
95
|
+
description="Start the HTTP daemon: a warm pool of browsers serving "
|
|
96
|
+
"recipes on /v1. The address and every limit come from the config file.",
|
|
97
|
+
)
|
|
98
|
+
serve.add_argument(
|
|
99
|
+
"--docs",
|
|
100
|
+
action="store_true",
|
|
101
|
+
help="expose interactive Swagger UI (/docs), ReDoc (/redoc), and /openapi.json",
|
|
102
|
+
)
|
|
103
|
+
_add_common(serve)
|
|
104
|
+
|
|
105
|
+
check = commands.add_parser(
|
|
106
|
+
"check",
|
|
107
|
+
help="run recipes' live checks",
|
|
108
|
+
description="Run each recipe with its sample parameters and test the result against "
|
|
109
|
+
"its assertions. Goes through a running daemon if there is one. Exits 1 if any fail.",
|
|
110
|
+
)
|
|
111
|
+
check.add_argument("names", nargs="*", metavar="RECIPE", help="recipes to check")
|
|
112
|
+
check.add_argument("--all", action="store_true", help="check every recipe")
|
|
113
|
+
check.add_argument(
|
|
114
|
+
"--include-local",
|
|
115
|
+
action="store_true",
|
|
116
|
+
help="with --all, also check recipes that point at this machine (the mock-site demo)",
|
|
117
|
+
)
|
|
118
|
+
check.add_argument(
|
|
119
|
+
"--include-experimental",
|
|
120
|
+
action="store_true",
|
|
121
|
+
help="with --all, also check experimental recipes (they may hit sites that block bots)",
|
|
122
|
+
)
|
|
123
|
+
_add_common(check)
|
|
124
|
+
|
|
125
|
+
login = commands.add_parser(
|
|
126
|
+
"login",
|
|
127
|
+
help="sign in by hand once, for a profile",
|
|
128
|
+
description="Open a visible Chrome on a profile so you can sign in yourself. The "
|
|
129
|
+
"daemon never sees your credentials. Stop `serve` first: a profile has one Chrome.",
|
|
130
|
+
)
|
|
131
|
+
login.add_argument("profile", help="profile name (lowercase letters, digits, - and _)")
|
|
132
|
+
login.add_argument("--url", help="a page to open, for example the site's login page")
|
|
133
|
+
_add_common(login, recipes=False)
|
|
134
|
+
|
|
135
|
+
probe = commands.add_parser(
|
|
136
|
+
"probe",
|
|
137
|
+
help="inspect live XHR/fetch JSON calls from a URL or catalog site",
|
|
138
|
+
description="Open a URL (or catalog site ID) in real Chrome and list JSON responses "
|
|
139
|
+
"along with suggested matchers and check assertions.",
|
|
140
|
+
)
|
|
141
|
+
probe.add_argument("target", help="URL or site id from catalog/sites.yaml")
|
|
142
|
+
probe.add_argument("--catalog", type=Path, help="path to sites.yaml")
|
|
143
|
+
probe.add_argument("--wait-ms", type=int, default=2500, help="ms to wait after load")
|
|
144
|
+
probe.add_argument("--param", action="append", default=[], help="KEY=VALUE sample param")
|
|
145
|
+
probe.add_argument("--json", action="store_true", dest="as_json", help="print JSON output")
|
|
146
|
+
probe.add_argument("--out", type=Path, help="write JSON probe report to this file")
|
|
147
|
+
|
|
148
|
+
scaffold = commands.add_parser(
|
|
149
|
+
"scaffold",
|
|
150
|
+
help="generate a draft YAML recipe",
|
|
151
|
+
description="Create a validated draft YAML recipe (status: experimental) from a "
|
|
152
|
+
"catalog site ID or <site>.<endpoint> name, optionally probing live Chrome first.",
|
|
153
|
+
)
|
|
154
|
+
scaffold.add_argument("target", help="<site>.<endpoint> or catalog site id")
|
|
155
|
+
scaffold.add_argument("--catalog", type=Path, help="path to sites.yaml")
|
|
156
|
+
scaffold.add_argument("--url", help="page or JSON endpoint URL")
|
|
157
|
+
scaffold.add_argument("--matcher", help="override matcher.url_regex")
|
|
158
|
+
scaffold.add_argument("--session", help="session mode ('none' or 'profile:<name>')")
|
|
159
|
+
scaffold.add_argument("--param", action="append", default=[], help="KEY=VALUE sample param")
|
|
160
|
+
scaffold.add_argument(
|
|
161
|
+
"--probe", action="store_true", help="probe the URL in Chrome first to infer matcher/expect"
|
|
162
|
+
)
|
|
163
|
+
scaffold.add_argument("--wait-ms", type=int, default=2500, help="probe wait time in ms")
|
|
164
|
+
scaffold.add_argument(
|
|
165
|
+
"--out-dir",
|
|
166
|
+
type=Path,
|
|
167
|
+
default=Path("recipes_staging"),
|
|
168
|
+
help="output recipes directory (default: recipes_staging)",
|
|
169
|
+
)
|
|
170
|
+
scaffold.add_argument("--overwrite", action="store_true", help="overwrite an existing file")
|
|
171
|
+
|
|
172
|
+
promote = commands.add_parser(
|
|
173
|
+
"promote",
|
|
174
|
+
help="run N consecutive live checks and promote a recipe to stable",
|
|
175
|
+
description="Verify a recipe by running its live check N times in a row (default 5); "
|
|
176
|
+
"only if every run passes, mark status: stable (and optionally bundle it).",
|
|
177
|
+
)
|
|
178
|
+
promote.add_argument("name", help="recipe name (<site>.<endpoint>)")
|
|
179
|
+
promote.add_argument(
|
|
180
|
+
"--runs", type=int, default=5, help="consecutive passes required (default 5)"
|
|
181
|
+
)
|
|
182
|
+
promote.add_argument("--dest-dir", type=Path, help="destination recipes directory")
|
|
183
|
+
promote.add_argument(
|
|
184
|
+
"--bundle",
|
|
185
|
+
action="store_true",
|
|
186
|
+
help="install the promoted recipe into the bundled recipes directory",
|
|
187
|
+
)
|
|
188
|
+
promote.add_argument("--catalog", type=Path, help="path to sites.yaml to update status")
|
|
189
|
+
_add_common(promote)
|
|
190
|
+
|
|
191
|
+
chrome = commands.add_parser(
|
|
192
|
+
"chrome",
|
|
193
|
+
help="start the Chrome an attached profile connects to",
|
|
194
|
+
description="Start a visible Chrome on an attached profile's own folder, listening on "
|
|
195
|
+
"this machine only at the port in its `attach` address. Sign in by hand and leave it "
|
|
196
|
+
"open: `serve` attaches to it. Your everyday Chrome cannot be used for this.",
|
|
197
|
+
)
|
|
198
|
+
chrome.add_argument("profile", help="profile name, set up with `attach:` in your config")
|
|
199
|
+
chrome.add_argument("--url", help="a page to open, for example the site's login page")
|
|
200
|
+
_add_common(chrome, recipes=False)
|
|
201
|
+
|
|
202
|
+
mcp = commands.add_parser(
|
|
203
|
+
"mcp",
|
|
204
|
+
help="expose recipes as tools to an AI agent over MCP (stdio)",
|
|
205
|
+
description="Run an MCP server on stdio for agent apps such as Claude. It is a bridge "
|
|
206
|
+
"to a running daemon (`serve`): tool calls go to its /v1 API, so its browsers, rate "
|
|
207
|
+
"limits and token are shared. It never starts a daemon. By default it offers only "
|
|
208
|
+
"stable recipes that need no login.",
|
|
209
|
+
)
|
|
210
|
+
mcp.add_argument("--url", help="the daemon's address (default: from the config file)")
|
|
211
|
+
mcp.add_argument(
|
|
212
|
+
"--include-experimental", action="store_true", help="also offer experimental recipes"
|
|
213
|
+
)
|
|
214
|
+
mcp.add_argument(
|
|
215
|
+
"--include-profiles",
|
|
216
|
+
action="store_true",
|
|
217
|
+
help="also offer logged-in (profile:) recipes, which run as your account",
|
|
218
|
+
)
|
|
219
|
+
_add_common(mcp, recipes=False)
|
|
220
|
+
|
|
221
|
+
recipes = commands.add_parser(
|
|
222
|
+
"recipes",
|
|
223
|
+
help="fetch shared recipes from git and apply the ones you approve",
|
|
224
|
+
description="Recipe delivery. `pull` fetches the configured sources (read-only), `diff` "
|
|
225
|
+
"shows what would change, `apply` installs what you approve into a managed folder "
|
|
226
|
+
"below your own recipes, `remove` undoes one. Risky changes need you to type the recipe's "
|
|
227
|
+
"name; recipes using eval are never applied.",
|
|
228
|
+
)
|
|
229
|
+
actions = recipes.add_subparsers(dest="action", required=True)
|
|
230
|
+
for name, text in (
|
|
231
|
+
("pull", "fetch the sources; changes nothing you use"),
|
|
232
|
+
("diff", "show what applying would change"),
|
|
233
|
+
("apply", "install the recipes you approve"),
|
|
234
|
+
("remove", "remove one applied recipe"),
|
|
235
|
+
):
|
|
236
|
+
sub = actions.add_parser(name, help=text, description=text)
|
|
237
|
+
_add_common(sub, recipes=False)
|
|
238
|
+
if name in ("diff", "apply"):
|
|
239
|
+
sub.add_argument("names", nargs="*", metavar="NAME", help="only these recipes")
|
|
240
|
+
if name == "apply":
|
|
241
|
+
sub.add_argument(
|
|
242
|
+
"--yes",
|
|
243
|
+
action="store_true",
|
|
244
|
+
help="apply routine changes without asking; risky ones are skipped",
|
|
245
|
+
)
|
|
246
|
+
if name == "remove":
|
|
247
|
+
sub.add_argument("name", help="the recipe to remove, site.endpoint")
|
|
248
|
+
|
|
249
|
+
repair = commands.add_parser(
|
|
250
|
+
"repair",
|
|
251
|
+
help="draft a verified fix for a recipe whose live check failed because the site changed",
|
|
252
|
+
description="`repair NAME` re-checks the recipe, loads its page again, and drafts a fix: "
|
|
253
|
+
"the one response that satisfies the old assertions (no AI), or one Claude call with no "
|
|
254
|
+
"tools that sees only structure, never values. The draft is replayed live and saved as a "
|
|
255
|
+
"proposal; nothing is applied. `repair apply NAME` shows the diff and installs it as a "
|
|
256
|
+
"copy in your recipes folder if you approve. Also: `repair list`, `repair discard NAME`. "
|
|
257
|
+
"It never tries to get around a site that blocks you.",
|
|
258
|
+
)
|
|
259
|
+
repair.add_argument(
|
|
260
|
+
"words", nargs="+", metavar="NAME | apply NAME | list | discard NAME",
|
|
261
|
+
help="a recipe name to draft a fix for, or a subcommand",
|
|
262
|
+
)
|
|
263
|
+
repair.add_argument(
|
|
264
|
+
"--include-profiles", action="store_true",
|
|
265
|
+
help="also repair logged-in (profile:) recipes; key names from your account go to Claude",
|
|
266
|
+
)
|
|
267
|
+
repair.add_argument(
|
|
268
|
+
"--no-ai", action="store_true", help="never call Claude (deterministic drafts only)"
|
|
269
|
+
)
|
|
270
|
+
repair.add_argument("--model", help="model for the Claude call (default: your Claude default)")
|
|
271
|
+
repair.add_argument(
|
|
272
|
+
"--force", action="store_true", help="draft again despite a recent proposal"
|
|
273
|
+
)
|
|
274
|
+
repair.add_argument(
|
|
275
|
+
"--yes", action="store_true", help="with apply: approve a routine repair"
|
|
276
|
+
)
|
|
277
|
+
_add_common(repair)
|
|
278
|
+
|
|
279
|
+
record = commands.add_parser(
|
|
280
|
+
"record",
|
|
281
|
+
help="browse a page once and generate a recipe for one of its JSON responses",
|
|
282
|
+
description="Open a visible browser on a page, collect the JSON responses it receives, "
|
|
283
|
+
"pick one, and write a recipe for it. The recipe is replayed once in a fresh browser "
|
|
284
|
+
"and written only if that reproduces the capture. Only structure (key names, types) "
|
|
285
|
+
"is shown or stored, never response values. It does not record clicks or typing.",
|
|
286
|
+
)
|
|
287
|
+
record.add_argument("url", help="the page to open, starting with http:// or https://")
|
|
288
|
+
record.add_argument("--name", help="recipe name, site.endpoint (default: derived)")
|
|
289
|
+
record.add_argument(
|
|
290
|
+
"--param",
|
|
291
|
+
action="append",
|
|
292
|
+
default=[],
|
|
293
|
+
metavar="KEY",
|
|
294
|
+
help="a query value in the page URL that callers may change (repeatable)",
|
|
295
|
+
)
|
|
296
|
+
record.add_argument(
|
|
297
|
+
"--profile",
|
|
298
|
+
help="record in the Chrome you started with `api-everything chrome NAME` "
|
|
299
|
+
"(for logged-in pages); writes session: profile:NAME",
|
|
300
|
+
)
|
|
301
|
+
record.add_argument("--pick", type=int, help="choose response number N without asking")
|
|
302
|
+
record.add_argument(
|
|
303
|
+
"--match", help="choose the one response whose URL contains this text, without asking"
|
|
304
|
+
)
|
|
305
|
+
record.add_argument(
|
|
306
|
+
"--seconds", type=float, help="record for this long instead of waiting for Enter"
|
|
307
|
+
)
|
|
308
|
+
record.add_argument(
|
|
309
|
+
"--keep-unverified",
|
|
310
|
+
action="store_true",
|
|
311
|
+
help="if the replay fails, still write the recipe, marked experimental",
|
|
312
|
+
)
|
|
313
|
+
record.add_argument("--force", action="store_true", help="replace an existing recipe file")
|
|
314
|
+
_add_common(record)
|
|
315
|
+
return parser
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
def _load(args: argparse.Namespace) -> tuple[Config, LoadedRecipes] | int:
|
|
319
|
+
"""Load the config and every recipe, or print the problems and return an exit code."""
|
|
320
|
+
try:
|
|
321
|
+
config = load_config(args.config)
|
|
322
|
+
except ConfigError as exc:
|
|
323
|
+
print(f"configuration error: {exc}", file=sys.stderr)
|
|
324
|
+
return 2
|
|
325
|
+
try:
|
|
326
|
+
community = config.community_dir.expanduser()
|
|
327
|
+
loaded = load_recipes(
|
|
328
|
+
bundled_recipes_dir(),
|
|
329
|
+
community if community.is_dir() else None, # applied with `recipes apply`
|
|
330
|
+
getattr(args, "recipes_dir", None) or config.recipes_dir,
|
|
331
|
+
allow_eval=config.allow_eval,
|
|
332
|
+
eval_in_profiles=config.allow_eval_in_profiles,
|
|
333
|
+
hooks_dir=config.hooks_dir,
|
|
334
|
+
)
|
|
335
|
+
except RecipeLoadError as exc:
|
|
336
|
+
print(f"{len(exc.problems)} problem(s) found:", file=sys.stderr)
|
|
337
|
+
for problem in exc.problems:
|
|
338
|
+
print(f" {problem}", file=sys.stderr)
|
|
339
|
+
return 1
|
|
340
|
+
return config, loaded
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
def _validate(args: argparse.Namespace) -> int:
|
|
344
|
+
loaded_or_code = _load(args)
|
|
345
|
+
if isinstance(loaded_or_code, int):
|
|
346
|
+
return loaded_or_code
|
|
347
|
+
_, loaded = loaded_or_code
|
|
348
|
+
print(f"OK: {len(loaded.recipes)} recipe(s) valid")
|
|
349
|
+
for name in sorted(loaded.recipes):
|
|
350
|
+
recipe = loaded.recipes[name]
|
|
351
|
+
flags = (" [eval]" if recipe.uses_eval else "") + (
|
|
352
|
+
" [experimental]" if recipe.status == "experimental" else ""
|
|
353
|
+
)
|
|
354
|
+
print(f" {name}{flags} ({loaded.sources[name]})")
|
|
355
|
+
return 0
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
def _port_in_use(host: str, port: int) -> bool:
|
|
359
|
+
"""True if something is already listening where the daemon wants to be."""
|
|
360
|
+
family = socket.AF_INET6 if ":" in host else socket.AF_INET
|
|
361
|
+
with socket.socket(family) as sock:
|
|
362
|
+
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
|
363
|
+
try:
|
|
364
|
+
sock.bind((host, port))
|
|
365
|
+
except OSError:
|
|
366
|
+
return True
|
|
367
|
+
return False
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
def _serve(args: argparse.Namespace) -> int:
|
|
371
|
+
loaded_or_code = _load(args)
|
|
372
|
+
if isinstance(loaded_or_code, int):
|
|
373
|
+
return loaded_or_code
|
|
374
|
+
config, loaded = loaded_or_code
|
|
375
|
+
if _port_in_use(config.server.host, config.server.port):
|
|
376
|
+
print(
|
|
377
|
+
f"error: port {config.server.port} on {config.server.host} is already in use by "
|
|
378
|
+
"another program. Set a different server.port in your config file, or "
|
|
379
|
+
"API_EVERYTHING__SERVER__PORT.",
|
|
380
|
+
file=sys.stderr,
|
|
381
|
+
)
|
|
382
|
+
return 3
|
|
383
|
+
|
|
384
|
+
# One JSON line per run goes to stdout. Uvicorn's own access log is off: it prints the
|
|
385
|
+
# full request line, including query strings, which can hold personal search terms.
|
|
386
|
+
handler = logging.StreamHandler(sys.stdout)
|
|
387
|
+
handler.setFormatter(logging.Formatter("%(message)s"))
|
|
388
|
+
runs = logging.getLogger("api_everything.runs")
|
|
389
|
+
runs.addHandler(handler)
|
|
390
|
+
runs.setLevel(logging.INFO)
|
|
391
|
+
|
|
392
|
+
return asyncio.run(_serve_async(config, loaded, docs=args.docs))
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
async def _serve_async(config: Config, loaded: LoadedRecipes, *, docs: bool = False) -> int:
|
|
396
|
+
"""Start the browser first, then the HTTP server, so a missing browser is one clear line.
|
|
397
|
+
|
|
398
|
+
Starting the pool before uvicorn means a browser that cannot launch (for example Chromium
|
|
399
|
+
that was never downloaded) is reported here and the daemon never claims to be listening.
|
|
400
|
+
"""
|
|
401
|
+
pool = Pool(config)
|
|
402
|
+
try:
|
|
403
|
+
await pool.start()
|
|
404
|
+
except RunError as exc:
|
|
405
|
+
print(f"cannot start: {exc.message}", file=sys.stderr)
|
|
406
|
+
return 3
|
|
407
|
+
try:
|
|
408
|
+
profile_recipes = [n for n, r in loaded.recipes.items() if r.profile_name]
|
|
409
|
+
print(
|
|
410
|
+
f"api-everything {__version__}: {len(loaded.recipes)} recipe(s), listening on "
|
|
411
|
+
f"http://{config.server.host}:{config.server.port}",
|
|
412
|
+
flush=True,
|
|
413
|
+
)
|
|
414
|
+
if docs:
|
|
415
|
+
print(
|
|
416
|
+
f"note: interactive API docs enabled at "
|
|
417
|
+
f"http://{config.server.host}:{config.server.port}/docs",
|
|
418
|
+
flush=True,
|
|
419
|
+
)
|
|
420
|
+
if profile_recipes and config.token is None:
|
|
421
|
+
print(
|
|
422
|
+
f"note: no API token is set, so these logged-in recipes will be refused: "
|
|
423
|
+
f"{', '.join(sorted(profile_recipes))}. Set API_EVERYTHING_TOKEN to enable them.",
|
|
424
|
+
flush=True,
|
|
425
|
+
)
|
|
426
|
+
await serve_until_stopped(create_app(config, loaded, pool=pool, docs=docs), config)
|
|
427
|
+
finally:
|
|
428
|
+
await pool.stop()
|
|
429
|
+
return 0
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
async def serve_until_stopped(app, config: Config) -> None:
|
|
433
|
+
"""Run uvicorn until Ctrl-C or a termination signal. Its access log is always off."""
|
|
434
|
+
server = uvicorn.Server(
|
|
435
|
+
uvicorn.Config(
|
|
436
|
+
app,
|
|
437
|
+
host=config.server.host,
|
|
438
|
+
port=config.server.port,
|
|
439
|
+
access_log=False,
|
|
440
|
+
log_level="warning",
|
|
441
|
+
)
|
|
442
|
+
)
|
|
443
|
+
await server.serve()
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
async def _check(config: Config, loaded: LoadedRecipes, recipes) -> list:
|
|
447
|
+
base_url = daemon_base_url(config)
|
|
448
|
+
async with httpx.AsyncClient() as client:
|
|
449
|
+
if await daemon_is_running(client, base_url):
|
|
450
|
+
print(f"running through the daemon at {base_url}", flush=True)
|
|
451
|
+
token = config.token.get_secret_value() if config.token else None
|
|
452
|
+
return await check_recipes(recipes, daemon_runner(client, base_url, token))
|
|
453
|
+
print("no daemon is running; starting a browser just for these checks", flush=True)
|
|
454
|
+
return await run_locally(config, loaded, recipes)
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
def _check_command(args: argparse.Namespace) -> int:
|
|
458
|
+
loaded_or_code = _load(args)
|
|
459
|
+
if isinstance(loaded_or_code, int):
|
|
460
|
+
return loaded_or_code
|
|
461
|
+
config, loaded = loaded_or_code
|
|
462
|
+
try:
|
|
463
|
+
recipes = select_recipes(
|
|
464
|
+
loaded,
|
|
465
|
+
args.names,
|
|
466
|
+
everything=args.all,
|
|
467
|
+
include_local=args.include_local,
|
|
468
|
+
include_experimental=args.include_experimental,
|
|
469
|
+
)
|
|
470
|
+
except CheckSelectionError as exc:
|
|
471
|
+
print(f"error: {exc}", file=sys.stderr)
|
|
472
|
+
return 2
|
|
473
|
+
if not recipes:
|
|
474
|
+
print(
|
|
475
|
+
"nothing to check (--include-local adds recipes for this machine, "
|
|
476
|
+
"--include-experimental adds experimental ones)"
|
|
477
|
+
)
|
|
478
|
+
return 0
|
|
479
|
+
try:
|
|
480
|
+
results = asyncio.run(_check(config, loaded, recipes))
|
|
481
|
+
except RunError as exc:
|
|
482
|
+
print(f"cannot run checks: {exc.message}", file=sys.stderr)
|
|
483
|
+
return 3
|
|
484
|
+
|
|
485
|
+
for result in results:
|
|
486
|
+
mark = "PASS" if result.ok else "FAIL"
|
|
487
|
+
print(f"{mark} {result.recipe} ({result.duration_ms}ms) {result.detail}")
|
|
488
|
+
failed = [r.recipe for r in results if not r.ok]
|
|
489
|
+
print(f"{len(results) - len(failed)} passed, {len(failed)} failed")
|
|
490
|
+
if failed and config.notify_command:
|
|
491
|
+
code = notify(config.notify_command, failed)
|
|
492
|
+
if code != 0:
|
|
493
|
+
print(f"warning: notify_command exited with {code}", file=sys.stderr)
|
|
494
|
+
return 1 if failed else 0
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
def _login_command(args: argparse.Namespace) -> int:
|
|
498
|
+
try:
|
|
499
|
+
config = load_config(args.config)
|
|
500
|
+
except ConfigError as exc:
|
|
501
|
+
print(f"configuration error: {exc}", file=sys.stderr)
|
|
502
|
+
return 2
|
|
503
|
+
try:
|
|
504
|
+
asyncio.run(run_login(config, args.profile, url=args.url))
|
|
505
|
+
except LoginError as exc:
|
|
506
|
+
print(f"error: {exc}", file=sys.stderr)
|
|
507
|
+
return 3
|
|
508
|
+
except KeyboardInterrupt:
|
|
509
|
+
pass
|
|
510
|
+
print(f"Done. Profile {args.profile!r} keeps your login for recipes that use it.")
|
|
511
|
+
return 0
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
def _load_optional_catalog(path: Path | None):
|
|
515
|
+
if path is not None:
|
|
516
|
+
return load_catalog(path)
|
|
517
|
+
default_path = default_catalog_path()
|
|
518
|
+
return load_catalog(default_path) if default_path.is_file() else None
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
def _probe_command(args: argparse.Namespace) -> int:
|
|
522
|
+
try:
|
|
523
|
+
if args.wait_ms < 0:
|
|
524
|
+
raise PipelineError("--wait-ms must be at least 0")
|
|
525
|
+
catalog = _load_optional_catalog(args.catalog)
|
|
526
|
+
params = parse_kv_params(args.param)
|
|
527
|
+
target_url, _ = resolve_probe_url(args.target, catalog=catalog, params=params)
|
|
528
|
+
report = asyncio.run(probe_target(target_url, wait_ms=args.wait_ms))
|
|
529
|
+
except PipelineError as exc:
|
|
530
|
+
code = 3 if "Chrome could not be started" in str(exc) else 2
|
|
531
|
+
print(f"error: {exc}", file=sys.stderr)
|
|
532
|
+
return code
|
|
533
|
+
|
|
534
|
+
payload = report.to_dict()
|
|
535
|
+
if args.out is not None:
|
|
536
|
+
try:
|
|
537
|
+
args.out.parent.mkdir(parents=True, exist_ok=True)
|
|
538
|
+
args.out.write_text(json.dumps(payload, indent=2) + "\n")
|
|
539
|
+
except OSError as exc:
|
|
540
|
+
print(f"error: cannot write {args.out}: {exc}", file=sys.stderr)
|
|
541
|
+
return 2
|
|
542
|
+
if args.as_json:
|
|
543
|
+
print(json.dumps(payload, indent=2))
|
|
544
|
+
return 1 if report.blocked else 0
|
|
545
|
+
|
|
546
|
+
print(
|
|
547
|
+
f"Probed {report.target_url} "
|
|
548
|
+
f"(document_status={report.document_status}, blocked={report.blocked})"
|
|
549
|
+
)
|
|
550
|
+
if not report.candidates:
|
|
551
|
+
print("No non-noise 2xx JSON responses captured.")
|
|
552
|
+
else:
|
|
553
|
+
print(f"Found {len(report.candidates)} candidate JSON response(s):")
|
|
554
|
+
for idx, hit in enumerate(report.candidates, start=1):
|
|
555
|
+
keys = ", ".join(hit.keys[:6]) if hit.keys else "-"
|
|
556
|
+
print(
|
|
557
|
+
f" {idx}. [{hit.status} {hit.resource_type}] {hit.url}\n"
|
|
558
|
+
f" shape={hit.shape} keys=[{keys}]\n"
|
|
559
|
+
f" suggested url_regex: {hit.suggested_regex}"
|
|
560
|
+
)
|
|
561
|
+
return 1 if report.blocked else 0
|
|
562
|
+
|
|
563
|
+
|
|
564
|
+
def _scaffold_command(args: argparse.Namespace) -> int:
|
|
565
|
+
try:
|
|
566
|
+
if args.wait_ms < 0:
|
|
567
|
+
raise PipelineError("--wait-ms must be at least 0")
|
|
568
|
+
catalog = _load_optional_catalog(args.catalog)
|
|
569
|
+
params = parse_kv_params(args.param)
|
|
570
|
+
report = None
|
|
571
|
+
if args.probe:
|
|
572
|
+
probe_url, _ = resolve_probe_url(
|
|
573
|
+
args.target,
|
|
574
|
+
catalog=catalog,
|
|
575
|
+
params=params,
|
|
576
|
+
url_override=args.url,
|
|
577
|
+
)
|
|
578
|
+
report = asyncio.run(probe_target(probe_url, wait_ms=args.wait_ms))
|
|
579
|
+
path, recipe = scaffold_recipe(
|
|
580
|
+
args.target,
|
|
581
|
+
out_dir=args.out_dir,
|
|
582
|
+
catalog=catalog,
|
|
583
|
+
url=args.url,
|
|
584
|
+
url_regex=args.matcher,
|
|
585
|
+
session=args.session,
|
|
586
|
+
params=params,
|
|
587
|
+
probe_report=report,
|
|
588
|
+
overwrite=args.overwrite,
|
|
589
|
+
)
|
|
590
|
+
except PipelineError as exc:
|
|
591
|
+
code = 3 if "Chrome could not be started" in str(exc) else 2
|
|
592
|
+
print(f"error: {exc}", file=sys.stderr)
|
|
593
|
+
return code
|
|
594
|
+
|
|
595
|
+
print(f"Scaffolded {recipe.name} ({recipe.status}) -> {path}")
|
|
596
|
+
print(f" matcher: {recipe.matcher.url_regex}")
|
|
597
|
+
print(
|
|
598
|
+
f" next: uv run api-everything promote {recipe.name} "
|
|
599
|
+
f"--recipes-dir {shlex.quote(str(args.out_dir))}"
|
|
600
|
+
)
|
|
601
|
+
return 0
|
|
602
|
+
|
|
603
|
+
|
|
604
|
+
def _promote_command(args: argparse.Namespace) -> int:
|
|
605
|
+
try:
|
|
606
|
+
config = load_config(args.config)
|
|
607
|
+
except ConfigError as exc:
|
|
608
|
+
print(f"configuration error: {exc}", file=sys.stderr)
|
|
609
|
+
return 2
|
|
610
|
+
dest_dir = bundled_recipes_dir() if args.bundle else args.dest_dir
|
|
611
|
+
default_cat = default_catalog_path()
|
|
612
|
+
catalog_path = args.catalog or (
|
|
613
|
+
default_cat if args.bundle and default_cat.is_file() else None
|
|
614
|
+
)
|
|
615
|
+
try:
|
|
616
|
+
target_path, results = asyncio.run(
|
|
617
|
+
promote_recipe(
|
|
618
|
+
args.name,
|
|
619
|
+
config=config,
|
|
620
|
+
recipes_dir=args.recipes_dir,
|
|
621
|
+
dest_dir=dest_dir,
|
|
622
|
+
runs=args.runs,
|
|
623
|
+
catalog_path=catalog_path,
|
|
624
|
+
)
|
|
625
|
+
)
|
|
626
|
+
except PipelineError as exc:
|
|
627
|
+
print(f"error: {exc}", file=sys.stderr)
|
|
628
|
+
return 2
|
|
629
|
+
except RunError as exc:
|
|
630
|
+
print(f"cannot run checks: {exc.message}", file=sys.stderr)
|
|
631
|
+
return 3
|
|
632
|
+
|
|
633
|
+
for idx, res in enumerate(results, start=1):
|
|
634
|
+
mark = "PASS" if res.ok else "FAIL"
|
|
635
|
+
print(f"[{idx}/{args.runs}] {mark} {res.recipe} ({res.duration_ms}ms) {res.detail}")
|
|
636
|
+
if len(results) < args.runs or any(not r.ok for r in results):
|
|
637
|
+
print(f"Promotion refused for {args.name}: did not pass {args.runs}/{args.runs} runs.")
|
|
638
|
+
return 1
|
|
639
|
+
print(f"Promoted {args.name} -> status: stable ({target_path})")
|
|
640
|
+
return 0
|
|
641
|
+
|
|
642
|
+
|
|
643
|
+
def _chrome_command(args: argparse.Namespace) -> int:
|
|
644
|
+
try:
|
|
645
|
+
config = load_config(args.config)
|
|
646
|
+
except ConfigError as exc:
|
|
647
|
+
print(f"configuration error: {exc}", file=sys.stderr)
|
|
648
|
+
return 2
|
|
649
|
+
try:
|
|
650
|
+
asyncio.run(start_chrome(config, args.profile))
|
|
651
|
+
except ChromeCommandError as exc:
|
|
652
|
+
print(f"error: {exc}", file=sys.stderr)
|
|
653
|
+
return 3
|
|
654
|
+
print(
|
|
655
|
+
"Sign in to the site in that window and leave it open. `api-everything serve` "
|
|
656
|
+
"attaches to it; close the window to detach."
|
|
657
|
+
)
|
|
658
|
+
return 0
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
def _recipes_command(args: argparse.Namespace) -> int:
|
|
662
|
+
from api_everything import delivery
|
|
663
|
+
from api_everything.delivery_git import DeliveryError
|
|
664
|
+
|
|
665
|
+
try:
|
|
666
|
+
config = load_config(args.config)
|
|
667
|
+
except ConfigError as exc:
|
|
668
|
+
print(f"configuration error: {exc}", file=sys.stderr)
|
|
669
|
+
return 2
|
|
670
|
+
try:
|
|
671
|
+
if args.action == "pull":
|
|
672
|
+
return delivery.pull(config, print)
|
|
673
|
+
if args.action == "diff":
|
|
674
|
+
return delivery.diff(config, args.names, print)
|
|
675
|
+
if args.action == "apply":
|
|
676
|
+
return delivery.apply(config, args.names, yes=args.yes, ask=input, say=print)
|
|
677
|
+
return delivery.remove(config, args.name, print)
|
|
678
|
+
except DeliveryError as exc:
|
|
679
|
+
print(f"error: {exc}", file=sys.stderr)
|
|
680
|
+
return 3
|
|
681
|
+
except (KeyboardInterrupt, EOFError):
|
|
682
|
+
print("\ncancelled; nothing further was applied.", file=sys.stderr)
|
|
683
|
+
return 2
|
|
684
|
+
|
|
685
|
+
|
|
686
|
+
def _repair_command(args: argparse.Namespace) -> int:
|
|
687
|
+
from api_everything import repair as repair_mod
|
|
688
|
+
|
|
689
|
+
try:
|
|
690
|
+
config = load_config(args.config)
|
|
691
|
+
except ConfigError as exc:
|
|
692
|
+
print(f"configuration error: {exc}", file=sys.stderr)
|
|
693
|
+
return 2
|
|
694
|
+
if args.recipes_dir:
|
|
695
|
+
config = config.model_copy(update={"recipes_dir": args.recipes_dir})
|
|
696
|
+
words = args.words
|
|
697
|
+
try:
|
|
698
|
+
if words[0] == "list" and len(words) == 1:
|
|
699
|
+
return repair_mod.show_list(config, print)
|
|
700
|
+
if words[0] in ("apply", "discard") and len(words) == 2:
|
|
701
|
+
if words[0] == "discard":
|
|
702
|
+
return repair_mod.discard(config, words[1], print)
|
|
703
|
+
return repair_mod.apply_proposal(config, words[1], yes=args.yes, ask=input, say=print)
|
|
704
|
+
if len(words) != 1:
|
|
705
|
+
print("usage: repair NAME | repair apply NAME | repair list | repair discard NAME",
|
|
706
|
+
file=sys.stderr)
|
|
707
|
+
return 2
|
|
708
|
+
options = repair_mod.DraftOptions(
|
|
709
|
+
include_profiles=args.include_profiles, force=args.force,
|
|
710
|
+
use_ai=not args.no_ai, model=args.model,
|
|
711
|
+
)
|
|
712
|
+
return asyncio.run(repair_mod.draft_repair(config, words[0], options, say=print))
|
|
713
|
+
except repair_mod.RepairError as exc:
|
|
714
|
+
print(f"error: {exc}", file=sys.stderr)
|
|
715
|
+
return exc.code
|
|
716
|
+
except RecipeLoadError as exc:
|
|
717
|
+
print("a recipe is invalid:\n " + "\n ".join(exc.problems), file=sys.stderr)
|
|
718
|
+
return 1
|
|
719
|
+
except DeliveryError as exc:
|
|
720
|
+
print(f"error: {exc}", file=sys.stderr)
|
|
721
|
+
return 3
|
|
722
|
+
except (BrowserNotInstalled, BrowserNotRunning) as exc:
|
|
723
|
+
print(f"error: {exc}", file=sys.stderr)
|
|
724
|
+
return 3
|
|
725
|
+
except (KeyboardInterrupt, EOFError):
|
|
726
|
+
print("\ncancelled; nothing further was changed.", file=sys.stderr)
|
|
727
|
+
return 2
|
|
728
|
+
|
|
729
|
+
|
|
730
|
+
def _record_command(args: argparse.Namespace) -> int:
|
|
731
|
+
from api_everything.record_session import RecordOptions, ask_stdin, run_record
|
|
732
|
+
|
|
733
|
+
try:
|
|
734
|
+
config = load_config(args.config)
|
|
735
|
+
except ConfigError as exc:
|
|
736
|
+
print(f"configuration error: {exc}", file=sys.stderr)
|
|
737
|
+
return 2
|
|
738
|
+
options = RecordOptions(
|
|
739
|
+
url=args.url,
|
|
740
|
+
recipes_dir=args.recipes_dir or config.recipes_dir,
|
|
741
|
+
name=args.name,
|
|
742
|
+
params=args.param,
|
|
743
|
+
profile=args.profile,
|
|
744
|
+
pick=args.pick,
|
|
745
|
+
match=args.match,
|
|
746
|
+
seconds=args.seconds,
|
|
747
|
+
keep_unverified=args.keep_unverified,
|
|
748
|
+
force=args.force,
|
|
749
|
+
)
|
|
750
|
+
|
|
751
|
+
try:
|
|
752
|
+
result = asyncio.run(run_record(config, options, ask=ask_stdin, say=print))
|
|
753
|
+
except (KeyboardInterrupt, EOFError):
|
|
754
|
+
print("\nrecording cancelled; nothing was written.", file=sys.stderr)
|
|
755
|
+
return 2
|
|
756
|
+
return result.code
|
|
757
|
+
|
|
758
|
+
|
|
759
|
+
def _mcp_command(args: argparse.Namespace) -> int:
|
|
760
|
+
# Imported here: the MCP SDK is slow to import and no other command needs it.
|
|
761
|
+
from api_everything.mcp_bridge import Bridge, Exposure, serve_stdio
|
|
762
|
+
|
|
763
|
+
try:
|
|
764
|
+
config = load_config(args.config)
|
|
765
|
+
except ConfigError as exc:
|
|
766
|
+
print(f"configuration error: {exc}", file=sys.stderr)
|
|
767
|
+
return 2
|
|
768
|
+
base_url = args.url or daemon_base_url(config)
|
|
769
|
+
bridge = Bridge(
|
|
770
|
+
base_url,
|
|
771
|
+
token=config.token.get_secret_value() if config.token else None,
|
|
772
|
+
exposure=Exposure(args.include_experimental, args.include_profiles),
|
|
773
|
+
)
|
|
774
|
+
# stdout belongs to the MCP protocol, so anything said to a person goes to stderr.
|
|
775
|
+
print(f"api-everything mcp: bridging to the daemon at {base_url}", file=sys.stderr, flush=True)
|
|
776
|
+
try:
|
|
777
|
+
asyncio.run(serve_stdio(bridge))
|
|
778
|
+
except KeyboardInterrupt:
|
|
779
|
+
pass
|
|
780
|
+
return 0
|
|
781
|
+
|
|
782
|
+
|
|
783
|
+
def main(argv: list[str] | None = None) -> int:
|
|
784
|
+
parser = build_parser()
|
|
785
|
+
args = parser.parse_args(argv)
|
|
786
|
+
handlers = {
|
|
787
|
+
"validate": _validate,
|
|
788
|
+
"serve": _serve,
|
|
789
|
+
"check": _check_command,
|
|
790
|
+
"login": _login_command,
|
|
791
|
+
"probe": _probe_command,
|
|
792
|
+
"scaffold": _scaffold_command,
|
|
793
|
+
"promote": _promote_command,
|
|
794
|
+
"chrome": _chrome_command,
|
|
795
|
+
"mcp": _mcp_command,
|
|
796
|
+
"record": _record_command,
|
|
797
|
+
"recipes": _recipes_command,
|
|
798
|
+
"repair": _repair_command,
|
|
799
|
+
}
|
|
800
|
+
if args.command in handlers:
|
|
801
|
+
return handlers[args.command](args)
|
|
802
|
+
parser.print_help()
|
|
803
|
+
return 0
|