/**
 * idl.ts — verify-proof IDL v1 verb definitions + arg/return shapes.
 *
 * Wire contract per ID-01: workflow prose, the resolver, verification.json,
 * and third-party drivers all refer to IDL verbs (`click`, `screenshot`,
 * `assert_visible`, ...) and NEVER to concrete MCP tool names. The mapping
 * from a verb to a transport (mcp_server_id / local_command / http_endpoint /
 * builtin) lives in the driver's manifest + driver.mjs, not here.
 *
 * Five verb families:
 *   - lifecycle: launch / teardown
 *   - interaction: click / type / key / navigate / select / upload_file /
 *     drag_drop / swipe / switch_context / execute_js / wait_for_event /
 *     wait_for_idle
 *   - evidence: screenshot / record_video / capture_logs / dump_state /
 *     dom_dump
 *   - assertion: assert_visible / assert_text / assert_output /
 *     assert_network
 *   - async: trigger / await_signal
 */
// ---------------------------------------------------------------------------
// Runtime registry — the verb names IDL v1 ships, by family.
// ---------------------------------------------------------------------------
/** Lifecycle verbs. */
export const LIFECYCLE_VERBS = ['launch', 'teardown'];
/** Interaction verbs. */
export const INTERACTION_VERBS = [
    'click',
    'type',
    'key',
    'navigate',
    'select',
    'upload_file',
    'drag_drop',
    'swipe',
    'switch_context',
    'execute_js',
    'wait_for_event',
    'wait_for_idle',
];
/** Evidence verbs. */
export const EVIDENCE_VERBS = [
    'screenshot',
    'record_video',
    'capture_logs',
    'dump_state',
    'dom_dump',
];
/** Assertion verbs. */
export const ASSERTION_VERBS = [
    'assert_visible',
    'assert_text',
    'assert_output',
    'assert_network',
];
/** Async verbs. */
export const ASYNC_VERBS = ['trigger', 'await_signal'];
/** Every IDL v1 verb name, flat array — the canonical list. */
export const IDL_VERB_NAMES = [
    ...LIFECYCLE_VERBS,
    ...INTERACTION_VERBS,
    ...EVIDENCE_VERBS,
    ...ASSERTION_VERBS,
    ...ASYNC_VERBS,
];
/**
 * Per-verb arg metadata. `required` lists keys that MUST be present on the
 * args object; `optional` lists keys that MAY be present. Bundled drivers
 * and third-party drivers both consume this through validateVerbArgs() so
 * the SDK is the single source of truth (ID-04).
 *
 * Frozen so consumers don't mutate the registry by accident.
 */
export const IDL_VERB_ARGS = Object.freeze({
    launch: { required: [], optional: ['entrypoint', 'env', 'cwd'] },
    teardown: { required: ['handle'], optional: [] },
    click: { required: ['target'], optional: ['button'] },
    type: { required: ['target', 'text'], optional: ['clear_first'] },
    key: { required: ['key'], optional: ['target'] },
    navigate: { required: ['url'], optional: [] },
    select: { required: ['target', 'value'], optional: [] },
    upload_file: { required: ['target', 'file_path'], optional: [] },
    drag_drop: { required: ['source', 'destination'], optional: [] },
    swipe: { required: ['target', 'direction'], optional: [] },
    switch_context: { required: ['handle'], optional: [] },
    execute_js: { required: ['script'], optional: ['args'] },
    wait_for_event: { required: ['event'], optional: ['timeout_ms'] },
    wait_for_idle: { required: [], optional: ['timeout_ms'] },
    screenshot: { required: ['output_path'], optional: ['target'] },
    record_video: { required: ['duration_seconds', 'output_path'], optional: ['fps'] },
    capture_logs: { required: ['source'], optional: ['output_path'] },
    dump_state: { required: ['output_path'], optional: [] },
    dom_dump: { required: ['output_path'], optional: [] },
    assert_visible: { required: ['target'], optional: [] },
    assert_text: { required: ['target', 'expected'], optional: ['match'] },
    assert_output: { required: ['source', 'expected'], optional: ['match'] },
    assert_network: { required: ['url_pattern'], optional: ['method', 'expected_status'] },
    trigger: { required: ['event'], optional: ['payload'] },
    await_signal: { required: ['signal'], optional: ['timeout_ms'] },
});
/**
 * VerbResult return-shape predicate. Drivers MUST return an object with
 * `status` ∈ {success,fail,skip}, `evidence_paths` (array), `duration_ms`
 * (number), and `retry_count` (number). The conformance kit + framework
 * resolver call this to validate runtime return shapes.
 */
export function isVerbResult(value) {
    if (value === null || typeof value !== 'object')
        return false;
    const v = value;
    if (v.status !== 'success' && v.status !== 'fail' && v.status !== 'skip')
        return false;
    if (!Array.isArray(v.evidence_paths))
        return false;
    if (typeof v.duration_ms !== 'number')
        return false;
    if (typeof v.retry_count !== 'number')
        return false;
    return true;
}
/**
 * Validate a verb's args object against the IDL_VERB_ARGS registry. Returns
 * `{valid: true}` when every required key is present; otherwise returns
 * `{valid: false, missing: [...keys]}` where `missing` includes the keys
 * that were absent (or `['unknown verb: <name>']` for unknown verbs).
 */
export function validateVerbArgs(verb, args) {
    const meta = IDL_VERB_ARGS[verb];
    if (meta === undefined)
        return { valid: false, missing: [`unknown verb: ${verb}`] };
    if (args === null || typeof args !== 'object' || Array.isArray(args)) {
        return { valid: false, missing: [...meta.required] };
    }
    const obj = args;
    const missing = meta.required.filter((k) => !(k in obj));
    if (missing.length === 0)
        return { valid: true };
    return { valid: false, missing: [...missing] };
}
//# sourceMappingURL=idl.js.map