Back to Docs

Use the CLI from an Agent Workflow

Give coding agents clear test scope and capture reliable CLI results.

Keep agent requests short and specific. Name the project, target URL, test goal, and any limits. Use Markdown for multi-step prompts.

# Check account sign-in

Project: PROJECT_ID
Target: https://staging.example.com/sign-in

1. Open the sign-in page.
2. Sign in with the project's configured test account.
3. Confirm the account dashboard appears.

Do not change account settings or create data outside this test account.

Save the prompt as prompt.md and pass it to the CLI:

mechasm tests create --project PROJECT_ID --name "Sign-in" --prompt-file prompt.md --json

The command returns test and run IDs while work continues. Store testId, runId and runUrl in workflow state. Use explicit project and test IDs in later commands; the CLI does not choose a default project. --json writes machine-readable output to stdout; errors go to stderr.

Follow execution using the returned run ID. Save the latest cursor and resume from it after a disconnect:

mechasm runs logs RUN_ID --project PROJECT_ID --follow --json
mechasm runs logs RUN_ID --project PROJECT_ID --after CURSOR --follow --json

When the stream finishes, check the final result:

mechasm runs status RUN_ID --project PROJECT_ID --json

Log streaming alone does not report pass/fail through its exit code. Do not infer success from a closed stream or an individual log line.

Let healing finish

Wait for the overall run to reach passed or failed. A failed action, unexpected page or recovery attempt may be corrected by Mechasm’s healer. Do not stop solely because several minutes passed or an individual step failed.

runs status includes terminal, the current progress phase and its startedAt when available, and customer-facing failure details with a suggestedNextStep. Progress may be unavailable; that alone does not prove the run is stuck. A connection heartbeat is not proof that useful work is advancing.

Stop when the user requests it, or when you deliberately need to change the prompt before continuing. A manually stopped run is reported as failed with Stopped by user; it does not establish what the natural result would have been.

Check the evidence before reporting

Review logs alongside available trace screenshots/page snapshots, actions and errors. Use the video as supporting evidence. Check that the expected behavior really happened, including when a reported pass or failure is ambiguous.

Check artifact availability in runs status, then download available evidence:

mechasm runs trace RUN_ID --project PROJECT_ID --out run-trace.zip
mechasm runs video RUN_ID --project PROJECT_ID --out run.webm

Open the trace in a Playwright trace viewer and inspect the page at the relevant action. Uploads can finish after the run result, so check status again if an artifact is not ready. If evidence is unavailable or your environment cannot inspect it, state that limitation instead of guessing.

  • If the evidence shows a genuine failure of the user’s requirement, accept the failure and report what was expected versus observed, with the run URL.
  • If your prompt introduced an unsupported assumption or was ambiguous, clarify the prompt while preserving the user’s requirement. Ask the user if the intended result is unclear.
  • Do not remove checks or weaken the requirement just to obtain a pass. Do not repeatedly rerun the same failure without a reason to expect a different result.

To apply a clarified prompt:

mechasm tests edit --project PROJECT_ID TEST_ID --prompt-file clarified-prompt.md --json

Editing an enabled test’s prompt starts generation and a new run. Save the new run ID, follow its logs and review its result and evidence. Creating an additional run immediately is unnecessary.

Optional silent waiting

For scripts that only need the final result, add the optional --wait to create/edit/run, or use runs wait. It waits silently until completion without displaying live logs. With --json, it returns one final JSON result.

Status/get/wait commands and test commands using --wait exit with code 5 for failed or stopped runs. Invalid arguments exit 2, authentication failures 3, and permission denials 4. The optional npm update notice only runs in interactive non-JSON sessions; CI skips it. See Runs, Logs & Artifacts for artifact downloads and the full exit-code list. Run mechasm --help for command syntax and documentation links.