agentleFS
no-todayno-today/aidev-clis/skills/aidev-httpcli/SKILL.md

aidev-httpcli

Skill0 starsChanged 11 days agoMITView on GitHub

Use when managing aidev HTTP session state or making HTTP calls with httpcli login (capture a session via a flow), httpcli whoami (inspect current session), httpcli logout (remove session file), or httpcli call (send HTTP request with injected session). Covers verb-first addressing, auto-login + auto-relogin (call is self-sufficient — no login-first), the {data}/{error} envelope, per-app response predicates, actors (incl. secret:<name>), and flow fidelity — multi-step + cross-step capture, per-step assert, cookie_from_set_cookie, multi-header inject, vars_defaults, extra_headers, trace_field, and binary-safe file transfer in both directions (-F upload, --output-file download).

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 0 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Run httpcli login <app> explicitly only when the app's auth is interactive — it needs a per-login --var that can't live in actors.yaml …

    line 53
  2. Very specific:

    Use for export endpoints — never inline binary into data.body.

    line 157
  3. Very specific:

    Every invocation appends to ~/.aidev-clis/audit/<YYYYMMDD>.jsonl (30-day auto-prune).

    line 235

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

httpcli

httpcli gives an AI agent authenticated HTTP access to internal apps. The CLI holds the session, injects it, runs the request, and returns a minimal JSON envelope. You never see the credential; the remote app's own authorization decides what the agent may do.

httpcli apps                  # list configured apps, environments and actors
httpcli call   <app> <path> [options]
httpcli login  <app>        [--actor <name>] [--env <name>]
httpcli whoami <app>        [--actor <name>] [--env <name>]
httpcli logout <app>        [--actor <name>] [--env <name>]

The subcommand always leads; <app> is its first positional. There is no --app flag and no global --env.

Addressing — three axes

Choose the app after the verb. Its default_actor selects the default account and base_url the default endpoint. See httpcli call -h for addressing options.

--env resolves within the chosen app's own envs: map. --base-url <url> overrides the base URL for a single call (mutually exclusive with --env).

Typical flow — just call, never login-first

httpcli call is self-sufficient: it establishes the session on the first call and re-establishes it on expiry, both non-interactively. Do NOT run httpcli login as a warm-up step — go straight to call.

# Make calls — session is created on first use and injected automatically.
# No prior `httpcli login` needed when creds are in actors.yaml.
httpcli call svc-login /api/me --actor alice
httpcli call svc-login /api/order --actor alice --env pre \
      -X POST -H 'Content-Type: application/json' -d '{"x":1}'

# Debug — print equivalent curl without executing
httpcli call svc-login /api/x --actor alice --curl

# Check / clear
httpcli whoami svc-login --actor alice
httpcli logout svc-login --actor alice

Run httpcli login <app> explicitly only when the app's auth is interactive — it needs a per-login --var that can't live in actors.yaml (OTP, verifyCode). That case surfaces as {error: {code: "SESSION_EXPIRED"}} (see below).

Auto-login + auto-relogin — the key capability

httpcli call owns the whole session lifecycle. You never call login to prime it, and never do a whoami → login dance:

  1. No session yet → call runs the auth flow automatically (non-interactive when every vars_required is in actors.yaml/vars_defaults), saves it, then sends the request.
  2. Stored session stale → expired_when matches + all creds available → re-login once, retry once → {data} with warnings: ["session re-established"]. The retry is evaluated with ok_when and may return ok: false.
  3. Interactive auth needed (a required --var is missing) → {error: {code: "SESSION_EXPIRED"}} → now run httpcli login <app> --var ... explicitly, then resume calling.

So the only reason an agent ever types httpcli login is case 3 — everything else is handled inside call.

Sessions are keyed (app, actor, env) so multiple accounts / envs coexist without collision.

Output contract (parse this)

A reachable response is always {data} — a business failure is a real answer, not an error:

{"data": {"status_code": 200, "ok": false, "headers": {...},
          "body": {"code": 4001, "msg": "余额不足"}}}

{error} only for transport / config / auth faults (no useful body):

{"error": {"code": "SESSION_EXPIRED", "message": "..."}}

ok is set from the app's ok_when predicate — it is not just HTTP 2xx. Exit codes: 0 ok · 1 business-fail (ok:false, body still in data) · 2 config · 3 auth / SESSION_EXPIRED · 4 timeout · 5 remote/transport.

The default JSON envelope is already what an agent wants — don't pass --output. (--output raw returns the bare body text, and --pretty indents — both for humans.)

Response bodies are a PII exit: mask real PII (id numbers, phones, card numbers, names) before quoting a response snippet into docs, tests, or persistent notes — full rules in the aidev-dbcli skill. A -F field value — like a -d body — is also a PII exit: both are recorded verbatim in the audit line's command field (full argv, unredacted) — pass PII/secret values as a file (-F 'name=@path') rather than an inline field when that matters.

call flags

See httpcli call -h for options. A zero --connect-timeout uses the 30s default.

login also takes --var k=v (repeatable) for per-login one-time values (OTP).

Body is always raw passthrough — -d 'a=1&b=2' with a form Content-Type reaches the server unchanged. No implicit JSON re-encoding.

  • -F 'name=value' / -F 'name=@/path/file.png' — multipart upload, repeatable; implies POST. Reads the file from disk, so binary is safe. Never build a multipart body by hand and pass it via -d: command substitution strips trailing newlines and shell variables truncate at NUL, so binary files corrupt silently. Repeat the same name for a list of files (-F 'images=@a.png' -F 'images=@b.png'). Add ;type=image/png to set the part's content type, ;filename=x.png to rename it. Do not pass -H 'Content-Type: ...' alongside -F — httpcli computes the boundary and will reject the combination. --max-upload (default 512MB) bounds the in-memory buffer.

Login-flow fidelity (you CAN model complex legacy auth)

The login flow is not limited to one request + one bearer header:

  • Multi-step — flow is a list; step N's request template sees both the actor vars and every var captured by earlier steps (cross-step). Use it for login → exchange → verify chains.
  • Per-step assert — a predicate (same grammar as ok_when) checked after the step; false → login fails AUTH_FAILED (so a wrong password is caught at login, not on the next call).
  • cookie_from_set_cookie: true — capture that step's Set-Cookie into the session and replay it on later steps + every call (cookie-based legacy auth).
  • Multi-header inject — inject.headers is a map; each value is a template rendered from session vars, all injected on every call (e.g. Client-Id + Authorization + Access-Token together). inject.header (single) still works.
  • vars_defaults — static fallback vars (e.g. client_id, terminalType). Precedence: vars_defaults < actor/--var < captured.
  • extra_headers — per-app constant headers on every request (a per-call -H of the same name overrides).

This covers cookie-replay logins, multi-header APIs, and multi-step OTP flows — do NOT assume httpcli can't express a legacy auth shape; check these first.

File downloads, inline actors, trace, cross-origin

  • --output-file <p> / --headers-file <p> — stream a binary/export body (xlsx/pdf/zip) to disk instead of inlining it; the envelope carries metadata (body_file, body_bytes, content_length, stream_complete, sha256). Use for export endpoints — never inline binary into data.body.
  • --actor-file <p> — a complete one-off actor ({vars:{...}}) inline, instead of an actors.yaml entry. On call/login/whoami/logout.
  • --var k=v (login only) — a per-login one-time value that can't be static config (OTP / verifyCode). Visible in argv → sensitive-arg warning.
  • trace_field → emits data.trace_id; on a not-OK response httpcli prints a stderr pivot hint → logcli sls trace <id> --target <log_env>.
  • Cross-origin guard — a call whose host ≠ the app's base/env host is blocked (API_CROSS_ORIGIN_URL) unless --allow-cross-origin; the session never silently leaks to a foreign host.

Config

# ~/.aidev-clis/httpcli.yaml
apps:
  svc-login:
    base_url: http://uat.example.com
    envs:
      pre:  http://pre.example.com
      prod: https://prod.example.com
    default_actor: alice
    extra_headers:               # constant headers on EVERY call (a per-call -H overrides)
      Client-Id: demo_app_a
    trace_field: header.X-Trace-Id   # surfaced as data.trace_id; header.<canonical-name> | body.<dotpath>
    log_env: log_uat                 # logcli env appended to the failed-call trace hint
    auth:
      kind: flow          # flow | none  (cookie replay is per-step, NOT a kind)
      vars_defaults: { orgId: "999" }   # lowest-precedence fallbacks: vars_defaults < actor/--var < captured
      vars_required: [phoneNo, password]
      flow:
        - request: |
            POST /auth/login
            Content-Type: application/json

            {"phoneNo":"{{phoneNo}}","password":"{{password}}"}
          assert: "body.code == 0"           # per-step: false → login fails AUTH_FAILED
          cookie_from_set_cookie: true        # capture this step's Set-Cookie into the session
          capture:
            token: body.data.token            # later steps' templates ALSO see captured vars (cross-step)
      inject:
        headers:                  # MULTI-header inject; each value rendered from session vars
          Authorization: "Bearer {{token}}"
          Access-Token: "{{token}}"
        # header: "Authorization: Bearer {{token}}"   # single-header shorthand still works
        # cookie: "SESSION={{token}}"                  # OR inject a templated cookie
    response:
      ok_when:      "body.code == 0"
      expired_when: "body.code == 401"

# ~/.aidev-clis/actors.yaml
actors:
  svc-login:
    # plain values work for dev; `secret:<name>` resolves from
    # ~/.aidev-clis/credentials/<name> (0600) instead of storing the secret here.
    alice: { phoneNo: "13800000000", password: "secret:svc_login_alice_pw", orgId: "999" }
    bob: { phoneNo: "13800000001", password: "secret:svc_login_bob_pw", orgId: "999" }

The bundled httpcli.yaml / actors.yaml are reference templates — copy them to ~/.aidev-clis/ and fill in your apps/actors (real configs never leave the machine). You can offer to write them for the user from these samples.

Sessions live at ~/.aidev-clis/sessions/<app>/<actor>/<env> (mode 0600).

For the shared ~/.aidev-clis layout, the credentials model (actors.yaml is shared with tcli), and from-zero setup steps, see the use-aidev skill.

Don't use httpcli for

  • Simple token-auth APIs (a static Authorization header) — use raw curl.
  • Database reads — use dbcli.
  • Jenkins builds / deploys — use jcli.
  • Log reads — use logcli.
  • An assertion you want kept + re-runnable with a PASS/FAIL verdict — a post-deploy gate or a cross-system regression invariant — use tcli.

Audit

Every invocation appends to ~/.aidev-clis/audit/<YYYYMMDD>.jsonl (30-day auto-prune). Calls with methods other than GET and HEAD write a started line before dispatch and a terminal line after, sharing an id. Inline arguments, including --var values, appear in the audit command.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.