Skip to content

bojackli/anything-as-api

Repository files navigation

Anything-as-API

Anything-as-API 是一个面向浏览器场景的最小闭环原型:先录制一次明确的网页操作场景,再从录制结果里提取业务 API,最终基于显式 skill_spec_source.json 生成一个可交付的原生 skill_package。当前主线交付形态是带 SKILL.mdscripts/lib/assets/ 的 skill package。

当前已经打通这条最小链路:

  1. capture:录制场景并输出结构化 session_bundle
  2. extract:从 bundle 提取业务 API artifacts
  3. spec:把 extract 产物编译成 generated_skill_spec.json
  4. builder:基于 spec 生成原生 skill_package
  5. verify:对阶段产物和生成的 skill package 做 smoke 验证

Current Status

当前已经完成的阶段:

  • Plan A:采集入口、事件模型、session_bundle 基础契约
  • Plan B:manifest、分级 network evidence、storage snapshot、action trace
  • Plan C:API 提取、endpoint catalog、OpenAPI 基线
  • Plan D:闭环验证与阶段归因报告
  • Plan E:generated_skill_spec.json 契约与 spec 编译
  • Plan F:原生 skill package 生成器
  • Plan G:生成脚本的 runtime/session loop 基线
  • Plan H:原生 skill package smoke verify

当前不是生产可用版本,而是一个已经可运行、可验证的最小技术闭环。generic_items_api 只是当前回归 fixture,用来验证生成框架的端到端能力,不是框架内置目标;真正的浏览器登录刷新和长期 cookie 持久化仍在后续阶段。

Repository Layout

capture/   Browser capture and session bundle generation
extract/   Bundle-to-API extraction and artifact generation
spec/      Extract artifacts to generated skill spec
builder/   Native skill package generation
verify/    End-to-end verification and stage attribution
tests/     Tests for capture, extract, spec, builder, and verify
docs/      Design notes and implementation plans
output/    Sample outputs generated during local verification

Prerequisites

  • Python 3.11+
  • Poetry
  • Chromium for Playwright

Setup

Install dependencies into a project-local virtualenv:

POETRY_VIRTUALENVS_IN_PROJECT=true poetry install

Install the Playwright Chromium browser:

POETRY_VIRTUALENVS_IN_PROJECT=true poetry run playwright install chromium

Minimal Flow

One-Command Fixture Workflow

For local verification, run the full extract, refine, build, and verify chain with one command:

POETRY_VIRTUALENVS_IN_PROJECT=true poetry run python -m workflow.cli \
  --bundle-dir tests/fixtures/session_bundles/plan_b_with_bodies \
  --output-dir output/workflow-sample \
  --refine-provider fake

Expected output includes:

output/workflow-sample/extract/
output/workflow-sample/refined/
output/workflow-sample/build/skill_package/
output/workflow-sample/verify/verification_report.json
output/workflow-sample/workflow_report.json

workflow_report.json records each stage status, exit code, and compact nested reports from refine, build smoke, and verification stages so failures are diagnosable without opening every output directory.

1. Capture a Scenario Bundle

The capture CLI records one browser entry URL and writes a structured session_bundle.

Example:

POETRY_VIRTUALENVS_IN_PROJECT=true poetry run python -m capture.cli \
  --url https://example.com/login \
  --output-dir output/plan-b-sample \
  --manifest tests/fixtures/manifests/login_submit.json \
  --capture-mode guided \
  --headless

Expected output includes:

output/plan-b-sample/session_meta.json
output/plan-b-sample/network/requests.ndjson
output/plan-b-sample/network/responses.ndjson
output/plan-b-sample/browser/navigation_trace.json
output/plan-b-sample/browser/cookies_timeline.json
output/plan-b-sample/browser/storage_snapshots.json
output/plan-b-sample/user_actions/action_trace.json
output/plan-b-sample/labels/scenario_manifest.json

2. Extract API Artifacts

The extraction CLI consumes a captured bundle and emits API artifacts.

Example:

POETRY_VIRTUALENVS_IN_PROJECT=true poetry run python -m extract.cli \
  --bundle-dir tests/fixtures/session_bundles/plan_b_minimal \
  --output-dir output/plan-c-sample

Expected output includes:

output/plan-c-sample/api_calls.json
output/plan-c-sample/api_catalog.json
output/plan-c-sample/openapi_spec.yaml
output/plan-c-sample/replay_context.json
output/plan-c-sample/skill_spec_source.json

If captured response bodies are available for the selected endpoint, extract also emits:

output/plan-c-sample/recorded_sample.json

3. Optionally Refine The Skill Spec Source

The refine CLI rewrites the baseline skill_spec_source.json through a provider and copies the required runtime assets into a builder-ready output directory. The default fake provider is deterministic and offline-only. The openai provider calls the OpenAI Responses API when OPENAI_API_KEY is set.

Refinement is contract-guarded: providers may improve names, summaries, descriptions, schemas, and parser hints, but they cannot change tool names, tool kinds, execution request templates, runtime asset paths, or build script filenames.

Example:

POETRY_VIRTUALENVS_IN_PROJECT=true poetry run python -m spec.refine \
  --extract-dir tests/fixtures/extracted_scenarios/generic_items_api \
  --output-dir output/refined-skill-source \
  --provider fake

OpenAI-backed refinement:

OPENAI_API_KEY=... POETRY_VIRTUALENVS_IN_PROJECT=true poetry run python -m spec.refine \
  --extract-dir output/plan-c-sample \
  --output-dir output/refined-skill-source \
  --provider openai \
  --model gpt-5.4

Expected output includes:

output/refined-skill-source/skill_spec_source.json
output/refined-skill-source/replay_context.json
output/refined-skill-source/recorded_sample.json
output/refined-skill-source/refine_report.json

4. Build And Verify A Native Skill Package

The builder CLI compiles an explicit skill_spec_source.json, assembles the package, and smoke-verifies it in one command. The Example directory below is a fixture that contains a spec source; it is not a framework special case.

Example:

POETRY_VIRTUALENVS_IN_PROJECT=true poetry run python -m builder.cli \
  --extract-dir output/refined-skill-source \
  --output-dir output/native-skill-sample \
  --verify

Expected output includes:

output/native-skill-sample/generated_skill_spec.json
output/native-skill-sample/skill_package/SKILL.md
output/native-skill-sample/skill_package/scripts/
output/native-skill-sample/skill_package/lib/
output/native-skill-sample/skill_package/assets/
output/native-skill-sample/skill_smoke_report.json

SKILL.md includes skill loader frontmatter (name and description), and agents/openai.yaml includes UI-facing interface metadata so the package can be handed to another agent as a native skill artifact.

The smoke report should include:

{
  "status": "pass",
  "package_type": "native_skill",
  "checks": [
    "assets_complete",
    "scripts_importable",
    "recorded_tool_runs",
    "live_tool_auth_required",
    "refresh_session_runs",
    "live_tool_session_ready",
    "live_tool_request_context"
  ],
  "failures": []
}

The older two-step builder flow still works if a spec has already been generated:

POETRY_VIRTUALENVS_IN_PROJECT=true poetry run python -m spec.cli \
  --extract-dir output/plan-c-sample \
  --output-dir output/spec-sample

POETRY_VIRTUALENVS_IN_PROJECT=true poetry run python -m builder.cli \
  --spec-file output/spec-sample/generated_skill_spec.json \
  --output-dir output/native-skill-sample \
  --verify

4. Verify the End-to-End Flow

The verification CLI checks whether the expected artifacts exist and reports which stage failed if the flow is incomplete.

Example:

POETRY_VIRTUALENVS_IN_PROJECT=true poetry run python -m verify.cli \
  --bundle-dir tests/fixtures/session_bundles/plan_b_minimal \
  --artifact-dir output/plan-c-sample \
  --refined-artifact-dir output/refined-skill-source \
  --package-dir output/native-skill-sample \
  --output-dir output/plan-d-sample

Expected output:

output/plan-d-sample/verification_report.json

The current report shape is:

{
  "overall_status": "pass",
  "stages": {
    "capture": {"status": "pass"},
    "extraction": {"status": "pass"},
    "generation": {"status": "pass"}
  }
}

5. Smoke Test A Generated Skill Package

The skill smoke CLI validates native skill packages.

Example:

POETRY_VIRTUALENVS_IN_PROJECT=true poetry run python -m verify.skill_smoke_cli \
  --package-dir output/native-skill-sample/skill_package \
  --output-dir output/plan-e-sample

Expected output:

output/plan-e-sample/skill_smoke_report.json

Test Commands

Run all current project tests:

POETRY_VIRTUALENVS_IN_PROJECT=true poetry run python -m pytest tests/capture tests/extract tests/spec tests/builder tests/verify tests/workflows -v

Current expected result:

all tests pass

Run by area:

POETRY_VIRTUALENVS_IN_PROJECT=true poetry run python -m pytest tests/capture -v
POETRY_VIRTUALENVS_IN_PROJECT=true poetry run python -m pytest tests/extract -v
POETRY_VIRTUALENVS_IN_PROJECT=true poetry run python -m pytest tests/spec -v
POETRY_VIRTUALENVS_IN_PROJECT=true poetry run python -m pytest tests/builder -v
POETRY_VIRTUALENVS_IN_PROJECT=true poetry run python -m pytest tests/verify -v
POETRY_VIRTUALENVS_IN_PROJECT=true poetry run python -m pytest tests/workflows -v

Example Inputs

Current bundled fixtures:

  • tests/fixtures/manifests/login_submit.json
  • tests/fixtures/session_bundles/plan_b_minimal/

Current generated sample outputs:

  • output/plan-b-sample/
  • output/plan-c-sample/
  • output/plan-d-sample/
  • output/native-skill-sample/

What Is Implemented vs Not Yet Implemented

Implemented now:

  • manifest-aware browser capture
  • graded request / response evidence capture
  • storage snapshots and action traces
  • bundle-to-API extraction baseline
  • endpoint catalog baseline
  • baseline OpenAPI generation
  • response-body-aware recorded sample extraction when body evidence is available
  • baseline input schema inference from captured request body and query values
  • optional fake-provider and OpenAI-provider skill spec refinement stage with builder-ready artifact output
  • refine_report.json success/failure reporting for spec refinement
  • refinement contract guards for runtime assets, request templates, tool identity, and generated script filenames
  • end-to-end verification with stage attribution
  • generated native skill_package output
  • native skill smoke verification
  • recorded sample and session-state runtime script baseline
  • one-command extract-dir -> skill_package -> smoke report builder flow
  • generated session guidance docs and refresh_session.py JSON instructions
  • generated live scripts can build authenticated HTTP request context from replay and session assets
  • generated live scripts can apply simple input overrides to captured request body or query values
  • generated live scripts support dry-run request inspection plus injected/default HTTP execution and baseline response parsing

Not implemented yet:

  • robust schema inference from multiple observations
  • dependency graph generation
  • stronger LLM-assisted field mapping and workflow generation across arbitrary sites
  • browser-driven auth refresh and long-lived session recovery
  • production-ready multi-site skill packaging
  • support for complex real-world multi-step authenticated apps

Design Docs

Project design and plan docs live in docs/:

About

No description, website, or topics provided.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages