UNPKG

@vigilbase/cli

Version:

Vigilbase CLI — security scanners, agent tools, and Vigilbase One from the terminal.

371 lines (370 loc) • 16.9 kB
// GENERATED from packages/api-contract/src/tools/v1/operations.ts by scripts/vendor-api-contract.mjs — do not edit import { z } from 'zod'; import { LocalAvailabilityResponseSchema, LocalIdentityBodySchema, LocalRequestBodySchema, LocalRequestResponseSchema, LocalSessionResponseSchema, LocalSnapshotResponseSchema, LocalVerifyBodySchema, LocalVerifyResponseSchema, } from '../../../../local/cloudflare-checkup/contract.js'; import { defineOperation, defineOperations } from '../../core/operation.js'; /** * Tools v1: the public Agent API and the local Cloudflare Checkup routes the * Vigilbase CLI calls, served on https://api.vigilbase.com/tools/v1 and, as * legacy aliases, by the existing route files under vigilbase.com/api. * * v1 paths are the legacy `/api/v1` paths without that prefix, so * `https://vigilbase.com/api/v1` serves every operation too; the document * lists only api.vigilbase.com. Bodies are today's, identical on both hosts: * success bodies keep `success`, and errors keep `success: false` and `error` * (decision 3 of the contract design). The implementations stay in apps/com. * * Kept off the API host on purpose: the "Continue with Cloudflare" OAuth routes * (`/api/v1/tools/cloudflare-checkup/oauth/*`) run on browser cookies and a * redirect URI registered on vigilbase.com, and the deprecated * `POST /api/v1/developer/keys` only ever answers 410 Gone. */ /** * The unversioned `/api/agent/*` aliases were deprecated when `/api/v1` arrived. * Their sunset, first announced as 2027-09-01, was brought forward to the * Tools sunset (LEGACY_ALIAS_DEPRECATION.tools in src/deprecation.ts): no * outside caller in the 2026-11-03 usage study. */ const UNVERSIONED_DEPRECATION = { at: new Date('2026-08-21T00:00:00Z'), sunset: new Date('2027-02-01T00:00:00Z') }; const GRADES = ['A+', 'A', 'B', 'C', 'D', 'F']; /** An absolute https URL on one of our hosts. */ const url = z.string().meta({ format: 'uri' }); /** * Tool names stay open strings in responses: a client built today must keep * reading the catalogue when a tool is added (`security-headers` and * `email-security` today). */ const toolName = z.string().meta({ example: 'security-headers' }); // Responses declare what a client may rely on; the server sends every member // shown in the examples, and v1 may add members. export const AgentTool = z .looseObject({ toolName, name: z.string(), description: z.string(), targetDescription: z.string(), uiUrl: url, skillUrl: url, executeUrl: url.meta({ description: 'Where to POST a scan, on api.vigilbase.com/tools/v1 whichever host served the catalogue.' }), }) .meta({ id: 'AgentTool', description: 'An agent-executable tool.' }); export const AgentToolList = z .looseObject({ success: z.literal(true), apiVersion: z.string().optional(), description: z.string().optional(), openapi: url.optional(), docsUrl: url.optional(), skillsIndex: url.optional(), tools: z.array(AgentTool), // Every member below is optional to a client: v1 servers send them all. auth: z .looseObject({ anonymousScopes: z.array(z.string()).optional(), developerKeyScopes: z.array(z.string()).optional(), header: z.string().optional(), manageKeys: url.optional(), }) .optional(), rateLimit: z .looseObject({ windowSeconds: z.number().int().optional(), maxRequests: z.number().int().optional(), tier: z.string().optional(), scope: z.string().optional(), scanQuota: z .looseObject({ windowSeconds: z.number().int().optional(), maxScansPerClientIp: z.number().int().optional(), maxScansPerTarget: z.number().int().optional(), maxScansOverall: z.number().int().optional(), scope: z.string().optional(), }) .optional(), dailyAllowance: z .looseObject({ tier: z.string().meta({ description: '`anonymous` (per network), `signed_in` (per Vigilbase account, for signed-in Vigilbase MCP users) or `developer` (a developer API key spends none).' }), limit: z.number().int().optional().meta({ description: 'Scans per UTC day: 5 anonymous, 50 signed in; absent for a developer key.' }), used: z.number().int().optional(), remaining: z.number().int().optional(), resetsAt: z.string().optional().meta({ description: 'Next UTC midnight, ISO 8601. Absent with used and remaining when the limiter could not answer.' }), scope: z.string().optional(), }) .optional() .meta({ description: 'The free daily scan allowance executes spend, shared with the vigilbase.com tools.' }), }) .optional(), deprecation: z.looseObject({ legacy: z.literal(true), successor: url, sunset: z.string() }).optional(), }) .meta({ id: 'AgentToolList', description: 'The agent tool catalogue and the caller\'s limits.' }); export const AgentToolResult = z .looseObject({ success: z.literal(true), apiVersion: z.string().optional(), toolName, target: z.string(), grade: z.enum(GRADES).nullable(), gradeScore: z.number().nullable(), result: z.record(z.string(), z.unknown()).nullable().meta({ description: 'What the scanner returned.' }), error: z.null().optional().meta({ description: 'Always null on success; failures are problem details.' }), uiUrl: url.optional(), skillUrl: url.optional(), }) .meta({ id: 'AgentToolResult', description: 'A completed scan.' }); const anonymousOrKey = (scope) => [ { kind: 'anonymous', rateLimit: 'tools-anonymous' }, { kind: 'developerKey', scopes: [scope] }, ]; export const listAgentTools = defineOperation({ id: 'tools.agentTools.list', product: 'tools', version: 'v1', method: 'GET', path: '/agent/tools', summary: 'List agent tools', description: 'Returns the allowlisted non-intrusive tools agents may run, their skill and UI URLs, and the caller\'s rate limits. Anonymous calls get the free tier (10 requests a minute per IP); a developer API key from https://one.vigilbase.com/developers gets 30 a minute.', tags: ['Agent tools'], stability: 'ga', audience: 'public', auth: anonymousOrKey('tools:read'), rateLimit: 'default', request: {}, responses: { 200: AgentToolList }, errors: ['unauthorized', 'forbidden', 'rate_limit_exceeded', 'service_unavailable'], legacy: [ { host: 'com', path: '/api/v1/agent/tools' }, { host: 'com', path: '/api/agent/tools', deprecated: UNVERSIONED_DEPRECATION }, ], expose: { cli: 'list', llms: true }, }); export const executeAgentTool = defineOperation({ id: 'tools.agentTools.execute', product: 'tools', version: 'v1', method: 'POST', path: '/agent/tools/{toolName}/execute', summary: 'Run an agent tool', description: 'Runs a non-intrusive scan: `security-headers` grades a URL\'s HTTP security headers, `email-security` a domain\'s email authentication records. Each client IP and each target gets 20 scans an hour, with or without an API key; anonymous scans also spend the network\'s daily free tool allowance. A scan that ran but reported an error answers 422 with the scanner\'s output and no grade. Other tool names answer 404 with where they run instead.', tags: ['Agent tools'], stability: 'ga', audience: 'public', auth: anonymousOrKey('tools:execute'), rateLimit: 'default', request: { params: z.object({ // Any name is routed: the others answer 404 saying where they run instead. toolName: z .string() .regex(/^[a-z0-9][a-z0-9-]{0,63}$/) .meta({ description: 'The tool to run: `security-headers` or `email-security`.', example: 'security-headers' }), }), body: z.object({ target: z .string() .trim() .min(1) .max(2048) .meta({ description: 'Scan target. For security-headers prefer a full URL; for email-security use an apex domain.', example: 'example.com' }), }), }, responses: { 200: AgentToolResult }, errors: [ 'bad_request', 'unauthorized', 'forbidden', 'not_found', 'payload_too_large', 'unprocessable_entity', 'rate_limit_exceeded', 'service_unavailable', ], examples: [ { name: 'securityHeaders', request: { params: { toolName: 'security-headers' }, body: { target: 'https://example.com' } } }, { name: 'emailSecurity', request: { params: { toolName: 'email-security' }, body: { target: 'example.com' } } }, ], legacy: [ { host: 'com', path: '/api/v1/agent/tools/{toolName}/execute' }, { host: 'com', path: '/api/agent/tools/{toolName}/execute', deprecated: UNVERSIONED_DEPRECATION }, ], // CLI: `vigilbase headers <url>` and `vigilbase email <domain>`, one command per tool. expose: { llms: true }, }); export const getSecurityBadge = defineOperation({ id: 'tools.badges.get', product: 'tools', version: 'v1', method: 'GET', path: '/badge/{domain}', summary: 'Get a security badge', description: 'An SVG badge with the most recent website-security grade for the domain, as produced by https://vigilbase.com/tools/website-security; a question mark when there is none. Cached 24 hours for a grade, 1 hour for a question mark. Errors are plain text: 400 `Invalid domain` for anything but a bare domain name, 429 after 60 badges a minute from one client.', tags: ['Badges'], stability: 'ga', audience: 'public', auth: [{ kind: 'anonymous', rateLimit: 'badges' }], request: { params: z.object({ domain: z .string() .min(3) .max(255) .meta({ description: 'Bare domain name. Letter case, a leading `www.` and a trailing dot are ignored; a scheme, port or path is refused.', example: 'vigilbase.com', }), }), query: z.object({ style: z.enum(['default', 'compact', 'mini']).optional().meta({ description: 'Badge size.' }), }), }, responses: { 200: { schema: z.string(), contentType: 'image/svg+xml', description: 'The SVG badge. `X-Vigilbase-Grade` names the grade shown.' } }, errors: [], // Permanent and announce nothing: badges are embedded on third-party pages, // and an <img> never reads Deprecation or a successor Link. legacy: [ { host: 'com', path: '/api/v1/badge/{domain}', permanent: true, embedded: true }, { host: 'com', path: '/api/badge/{domain}', permanent: true, embedded: true }, ], expose: { cli: 'badge example.com', llms: true }, }); // -------------------------------------------------------------- local Cloudflare Checkup /** * The local Cloudflare Checkup routes the Vigilbase CLI calls. Their bodies * come from the canonical snapshot contract (packages/tools), which the CLI * vendors. Errors are Tools problem details plus the contract's `reason` * (`LocalErrorResponseSchema`). Browser Origins are refused and there is no * CORS: these are for the CLI. */ const CHECKUP_BASE = '/tools/cloudflare-checkup/local-session'; // Permanent: shipped CLIs pin these vigilbase.com paths, so they are never sunset (Q5). const checkupLegacy = (suffix) => [{ host: 'com', path: `/api/v1${CHECKUP_BASE}${suffix}`, permanent: true }]; const CHECKUP_TAGS = ['Cloudflare Checkup (CLI)']; const checkupNote = ' Errors are Tools problem details with a `reason` naming the cause; while local checkups are off every route answers 503 with reason `local_mode_disabled`.'; const sessionCode = [{ kind: 'anonymous', rateLimit: 'checkup-local' }]; /** The codes of apps/com/lib/cloudflare-checkup/local/errors.ts (LOCAL_ERROR_STATUS). */ const CHECKUP_ERRORS = [ 'bad_request', 'unauthorized', 'forbidden', 'conflict', 'gone', 'length_required', 'payload_too_large', 'unsupported_media_type', 'unprocessable_entity', 'rate_limit_exceeded', 'internal_error', 'service_unavailable', ]; export const checkupLocalAvailability = defineOperation({ id: 'tools.checkupLocal.availability', product: 'tools', version: 'v1', method: 'GET', path: `${CHECKUP_BASE}/availability`, summary: 'Check local checkups are available', description: `Before it asks for an email, the CLI checks that local checkups are on, the oldest CLI version they take and what a snapshot may contain. No side effects.${checkupNote}`, tags: CHECKUP_TAGS, stability: 'beta', audience: 'public', auth: sessionCode, request: {}, responses: { 200: LocalAvailabilityResponseSchema }, errors: CHECKUP_ERRORS, legacy: checkupLegacy('/availability'), }); export const checkupLocalRequest = defineOperation({ id: 'tools.checkupLocal.request', product: 'tools', version: 'v1', method: 'POST', path: `${CHECKUP_BASE}/request`, summary: 'Email a verification code', description: `Creates a pending local checkup, emails its six-digit code to a business address and returns a verification token.${checkupNote}`, tags: CHECKUP_TAGS, stability: 'beta', audience: 'public', auth: sessionCode, request: { body: LocalRequestBodySchema }, responses: { 200: LocalRequestResponseSchema }, errors: CHECKUP_ERRORS, legacy: checkupLegacy('/request'), }); export const checkupLocalVerify = defineOperation({ id: 'tools.checkupLocal.verify', product: 'tools', version: 'v1', method: 'POST', path: `${CHECKUP_BASE}/verify`, summary: 'Trade the emailed code for a session code', description: `Exchanges the verification token and the emailed code for a session code (\`vbcs1_…\`). Verifying again mints the next code and revokes the previous one.${checkupNote}`, tags: CHECKUP_TAGS, stability: 'beta', audience: 'public', auth: sessionCode, request: { body: LocalVerifyBodySchema }, responses: { 200: LocalVerifyResponseSchema }, errors: CHECKUP_ERRORS, legacy: checkupLegacy('/verify'), }); export const checkupLocalIdentity = defineOperation({ id: 'tools.checkupLocal.identity', product: 'tools', version: 'v1', method: 'POST', path: `${CHECKUP_BASE}/identity`, summary: 'Trade a One identity proof for a session code', description: `A signed-in CLI exchanges a run-scoped identity proof from Vigilbase One for a session code, instead of an emailed code.${checkupNote}`, tags: CHECKUP_TAGS, stability: 'beta', audience: 'public', auth: sessionCode, request: { body: LocalIdentityBodySchema }, responses: { 200: LocalVerifyResponseSchema }, errors: CHECKUP_ERRORS, legacy: checkupLegacy('/identity'), }); export const checkupLocalSession = defineOperation({ id: 'tools.checkupLocal.session', product: 'tools', version: 'v1', method: 'GET', path: CHECKUP_BASE, summary: 'Look up a checkup session', description: `What the session code (\`Authorization: Bearer vbcs1_…\`) is bound to: the account, the requester, its state and what an upload may contain.${checkupNote}`, tags: CHECKUP_TAGS, stability: 'beta', audience: 'public', auth: sessionCode, request: {}, responses: { 200: LocalSessionResponseSchema }, errors: CHECKUP_ERRORS, legacy: checkupLegacy(''), }); export const checkupLocalSnapshot = defineOperation({ id: 'tools.checkupLocal.snapshot', product: 'tools', version: 'v1', method: 'POST', path: `${CHECKUP_BASE}/snapshot`, summary: 'Upload a checkup snapshot', description: `Uploads the exact bytes of a \`vigilbase.cloudflare-checkup.snapshot/1\` file the CLI collected, with \`Authorization: Bearer vbcs1_…\` and \`X-Vigilbase-Snapshot-Sha256\`, and returns the evaluated report. A repeat of the same bytes is answered from the first upload (\`replayed: true\`).${checkupNote}`, tags: CHECKUP_TAGS, stability: 'beta', audience: 'public', auth: sessionCode, request: { body: z.record(z.string(), z.unknown()).meta({ description: 'The snapshot file, byte for byte (schema `vigilbase.cloudflare-checkup.snapshot/1`).' }) }, responses: { 200: LocalSnapshotResponseSchema }, errors: CHECKUP_ERRORS, legacy: checkupLegacy('/snapshot'), }); /** Every Tools v1 operation, checked at module load. */ export const TOOLS_V1_OPERATIONS = defineOperations('tools', [ listAgentTools, executeAgentTool, getSecurityBadge, checkupLocalAvailability, checkupLocalRequest, checkupLocalVerify, checkupLocalIdentity, checkupLocalSession, checkupLocalSnapshot, ]);