How do I scan a folder?
Run tomosu scan with a path. Findings come most urgent first: by origin label, then by the rule’s weight.
$ tomosu scan .
1. Critical · [Pre-merge review] Retry repeats payments or other one-time actions (22.retry-repeats-one-time-action)
How: Rule Passed with Code Fix
app.py:72 in checkout
Risk: A POST or PATCH is retried without an idempotency key, so if the first attempt succeeded but its reply was lost, the action happens twice.
Fix (drop-in, unverified until your tests run):
@@ -17,7 +17,8 @@
import pika # noqa: F401 the queue handler below has a pika callback's shape
import requests
from fastapi import FastAPI, HTTPException
from opentelemetry import trace
+import uuid # tomosu: 22.retry-repeats-one-time-action
# Each dependency has its own address, as in a real system; in the demo they
# are all served by the partners container.
@@ -69,9 +70,10 @@
@app.post("/checkout")
def checkout(order: dict):
log.info("checkout started for %s items", len(order.get("items", [])))
+ idempotency_key = str(uuid.uuid4()) # tomosu: 22.retry-repeats-one-time-action
for attempt in range(3):
try:
- resp = requests.post(PAYMENTS + "/charge", json=order)
…
17 findings in 1 file · 218 checks · rules dev/dev-d4ba7cc
Each finding gives:
- the severity and origin label, and the rule with its id in brackets;
- How: how the fix was found, for example Rule Passed with Code Fix;
- the file, line and function, and the risk in production;
- the fix, as a drop-in change or as written guidance, with a note on any behaviour change;
- the finding’s id, which
explain,fix acceptandfix rejecttake.
The last line says how many rules ran and which rules version, so a CI result and a production result can be compared.
How do I check only what my branch changes?
--diff <ref> reports only findings on lines added or changed since the merge base with that branch, including uncommitted and untracked files. Here a branch adds one refund endpoint:
$ tomosu scan . --diff main
1. High · [Pre-merge review] External call timeouts (01.external-call-timeouts)
How: Rule Passed with Code Fix
app.py:229 in refund
Risk: This outbound call can wait forever: requests has no default timeout, and timeout=None turns off the one httpx and aiohttp provide.
Fix (drop-in, unverified until your tests run):
@@ -226,5 +226,5 @@
@app.post("/refund/{order_id}")
def refund(order_id: str):
- resp = requests.post(PAYMENTS + "/refund", json={"order": order_id})
+ resp = requests.post(PAYMENTS + "/refund", json={"order": order_id}, timeout=(3.05, 10)) # tomosu: 01.external-call-timeouts
return {"status": resp.status_code}
Note: Calls slower than the timeout now fail with a timeout error instead of waiting indefinitely.
id f-114d80514568 · weight 0.80
1 finding in 1 file changed since main · 218 checks · rules dev/dev-d4ba7cc
What makes a fix “drop-in”?
Some rules carry a fix template. For those, the scan writes the exact change for your code, without any model, and checks it before showing it:
- it only adds code: nothing is removed or rewritten;
- the file still parses, with any imports the change needs;
- function names, parameters and decorators are unchanged;
- the rule no longer matches the changed code.
Every changed line carries a marker (# tomosu: <rule-id>, or // tomosu: in JavaScript, TypeScript, Go and Rust), and every fix is unverified until your build and tests run with it. Rules whose safe fix would change logic, such as N+1 queries, have written guidance only; for those, Tomosu Agent can draft a fix. To apply a fix, see Accept or reject a fix.
Which output formats are there?
| Flag | Output | For |
|---|---|---|
--format text | The default, shown above | People |
--format json | Every finding with its fix, patch and evidence | Scripts, tomosu publish |
--format sarif | SARIF 2.1.0, with drop-in fixes as standard fixes | GitHub code scanning, IDEs |
--format gitlab | A Code Quality report | GitLab merge requests |
--pdf report.pdf | A PDF report, alongside the chosen format | People who do not open a terminal (PDF reports) |
$ tomosu scan . --format json
{
"findings": [
{
"id": "f-7806d3db5e70",
"check_id": "22.retry-repeats-one-time-action",
"check_version": 1,
"category": "22",
"origin": "pre-merge",
"risk": "A POST or PATCH is retried without an idempotency key, so if the first attempt succeeded but its reply was lost, the action happens twice.",
"location": {
"commit": "4844bbe77b86c266f52273791fa5d9c04b593fdb",
"file": "app.py",
"start_line": 72,
"end_line": 79,
"symbol": "checkout"
},
"fix": {
"kind": "template",
"guidance": "Generate one idempotency key before the loop and send it on every attempt (for example headers={'Idempotency-Key': key}), or only retry errors that prove the request was not processed.",
"before": " for attempt in range(3):\n try:\n resp = requests.post(PAYMENTS + \"/charge\", json=order)",
"after": " idempotency_key = str(uuid.uuid4()) # tomosu: 22.retry-repeats-one-time-action\n for attempt in range(3):\n try:\n resp = requests.post(PAYMENTS + \"/charge\", json=order, headers={\"Idempotency-Key\": idempotency_key}) # tomosu: 22.retry-repeats-one-time-action",
"behavior_note": "The server can now recognise repeats; no change for servers that ignore the header.",
"patch": "--- a/app.py\n+++ b/app.py\n@@ -17,7 +17,8 @@\n import pika # noqa: F401 the queue handler below has a pika callback's shape\n import requests\n from fastapi import FastAPI, HTTPException\n from opentelemetry import trace\n+import uuid # tomosu: 22.retry-repeats-one-time-action\n \n # Each dependency has its own address, as in a real system; in the demo they\n # are all served by the partners container.\n@@ -69,9 +70,10 @@\n @app.post(\"/checkout\")\n def checkout(order: dict):\n log.info(\"checkout started for %s items\", len(order.get(\"items\", [])))\n+ idempotency_key = str(uuid.uuid4()) # tomosu: 22.retry-repeats-one-time-action\n for attempt in range(3):\n try:\n- resp = requests.post(PAYMENTS + \"/charge\", json=order)\n+ resp = requests.post(PAYMENTS + \"/charge\", json=order, headers={\"Idempotency-Key\": idempotency_key}) # tomosu: 22.retry-repeats-one-time-action\n resp.raise_for_status()\n return {\"status\": \"paid\", \"attempts\": attempt + 1}\n except requests.RequestException:\n",
"edits": [
{
"line": 20,
…
$ tomosu scan . --format sarif --out tomosu.sarif
17 findings written to tomosu.sarif (sarif)
How do I fail a CI job on findings?
Add --exit-code: the scan then exits with 1 when it reports findings.
$ tomosu scan . --exit-code > /dev/null; echo "exit $?"
exit 1
| Exit code | Meaning |
|---|---|
0 | The scan ran (with --exit-code: no findings) |
1 | Findings reported and --exit-code given |
2 | The scan could not run: bad rules, an unreadable path, bad flags, or a missing or unusable config |
Which other options matter?
| Option | What it does |
|---|---|
--out FILE | Write the report to a file instead of the terminal. |
--engine URL | Ask a running engine: findings it has seen in production become Pre-merge + Runtime and move to the top. |
--repo NAME | The repository name to record. Use the name the engine knows, so ids and links match. |
--include-tests | Also scan test files, which are skipped by default. |
--exclude DIR | Skip these folders. .git, virtualenvs, node_modules, build, dist and hidden folders are always skipped. |
--exclude-third-party | Leave out vendored and generated files. By default they are scanned and labeled third-party. |
--index FILE | Check a code index from tomosu index instead of the source. |
--rules DIR | Use these rules instead of the installed bundle or the embedded snapshot. |
Instead of flags, put the settings in a config.yaml (tomosu config init) and run tomosu scan with no path; see Settings.
Which rules does a scan use?
The first that exists: --rules (or TOMOSU_RULES_DIR), then a bundle installed in the data folder, then the signed snapshot embedded in the binary, which works offline with no setup. Only rules with status active or trusted are reported; rules in shadow run and are counted but never shown. See The rules catalogue.
A scan runs entirely on your machine. Its reports name files, lines and the flagged code, and never contain a rule’s detection logic.