Skip to content

feat: report + CLI + examples + umbrella (rolled-up remaining stack → master)#102

Open
aktasbatuhan wants to merge 7 commits into
masterfrom
kai/umbrella
Open

feat: report + CLI + examples + umbrella (rolled-up remaining stack → master)#102
aktasbatuhan wants to merge 7 commits into
masterfrom
kai/umbrella

Conversation

@aktasbatuhan

@aktasbatuhan aktasbatuhan commented Jun 8, 2026

Copy link
Copy Markdown
Member

Retargeted to master to land the rest of the stack in one approval + one merge. Because the branches are linear, this PR's diff is the union of the already-reviewed #99 + #100 + #101 + #102. Merging it puts their exact commits on master, so #99/#100/#101 will auto-close as merged. (#98 — the ra/viewer move — is already merged.)

What's in here

Verified

  • ty / ruff clean; 606 passed; wheel build confirmed to contain kai + ra (incl. ra/viewer).
  • Real audit run rendered through kai view (Findings + Trace) and python -m ra.viewer (Trace only); umbrella dispatch verified against openevolve + a second installed plugin.

All prior review comments (Copilot sort/mkdir on #98, andthattoo params on #100) addressed and threads resolved.

@eren23

eren23 commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

maybe a small change add the docs/umbrella.md it references in code and pyproject.toml but never includes; and document/pin the plugin handler contract (main(argv: list[str]) -> int | None, group kai.plugins, reserved verbs audit/view/report/pipeline/agent). Right now a sibling tool has to reverse-engineer the interface

andthattoo
andthattoo previously approved these changes Jun 9, 2026
The no-browser companion to kai.viewer: same on-disk source
(<run_dir>/exploits.json) rendered as a plain-text Markdown report you
can pipe into CI, paste into a PR, or read over SSH.

- render_markdown(): a sorted summary table (confirmed/critical first)
  plus per-finding sections -- facts, why-exploitable, exploit sketch,
  CVSS 3.1 breakdown table, fenced PoC, and the patch as a ```diff
- render_run(): load a run dir's findings and render
- python -m kai.report <run_dir> [-o OUT] (stdout by default)

Reuses kai.viewer.findings.load_findings; no live state backend.
kai report --format html renders a self-contained, fully-expanded report
document that shares the viewer's design system (kai.viewer.style) -- same
palette, severity dots, CVSS tables, and +/- patch diff as kai view, so the
two surfaces never drift. Markdown stays the default (-f md); --open opens
the rendered file.

Unlike the interactive viewer (master-detail + trace tabs), this is a linear
document meant to be printed, attached, or shared. Static HTML with all
dynamic values escaped server-side. --format scales to sarif/json later.
Match the viewer fix (#98): 'kai report -o some/new/dir/report.md' (and
--format html) now mkdir the parent instead of raising FileNotFoundError.
Add a unified `kai` console entry point that dispatches the friendly verbs
over the existing modules:

  kai audit <repo>     -> setup -> exploit pipeline (kai.main pipeline)
  kai view <run_dir>   -> interactive HTML run viewer (kai.viewer)
  kai report <run_dir> -> findings report, Markdown or --format html (kai.report)

`kai pipeline` / `kai agent` remain as direct aliases into kai.main.

Packaging: publish the distribution as `kai-security` while keeping the import
package and the command named `kai` (uv build-backend module-name override).
The bare `kai` name on PyPI is reserved for the future umbrella dispatcher.

Document the CLI in the README and add dispatcher tests.
- examples/vulnerable-vault: a tiny, self-contained, intentionally-vulnerable
  Solidity target (reentrancy + unchecked ERC-20 return) with a ready-made
  threat_context.yaml and a README documenting the planted bugs, the run
  command, and the expected findings. Lets anyone try the full
  audit -> view/report loop without a private repo or large spend.
- examples/README.md indexes the targets with a responsible-use note.
- README: add a top-of-file Quickstart (install -> audit the example ->
  view/report), an Examples section, and a Benchmarking pointer that makes the
  evaluation/ harness discoverable while keeping it secondary to the product.
…EADME

A real kai audit showed the original withdraw(amount) reentrancy was NOT
exploitable under Solidity 0.8.x: the checked '-= amount' underflows and
reverts during the reentrant unwind, and kai correctly disproved it. Switch
to the canonical drainable form (zero the balance with '= 0' AFTER the
external call) so the bug is real.

Rewrite the example README to match verified output instead of a fabricated
findings table: show the actual confirmed Critical (CVSS 9.8) reentrancy and
its Check-Effects-Interaction patch, and state plainly that kai is
non-deterministic — which bugs are confirmed and their scores vary by run and
model.
Make the kai command plugin-aware: beyond its built-in verbs it discovers
commands registered by other installed packages under the kai.plugins
entry-point group and dispatches 'kai <name> ...' to them. Built-in verbs
always win, so a plugin can't shadow audit/view/report.

Plugins follow the standard console-script convention: kai sets sys.argv to
'kai <name> <args>' and calls the registered zero-arg callable (which reads
sys.argv), exactly as if its own console script were invoked. This means any
package that already ships a [project.scripts] entry can register the SAME
callable as a kai plugin with no code changes -- verified end to end against a
real installed plugin and against openevolve's own openevolve.cli:main.

kai-security registers itself as the 'security' plugin, so 'kai security audit'
re-dispatches to the built-in audit. A sibling tool (e.g. kai-evolve) lights up
'kai evolve ...' just by registering kai.plugins.evolve. Documented in
docs/umbrella.md.

Additive and independently rejectable: nothing in the viewer/report/packaging
work depends on it, and kai audit/view/report are unchanged.
@aktasbatuhan

Copy link
Copy Markdown
Member Author

@eren23 docs/umbrella.md is committed in this PR and pins the contract: entry-point group kai.plugins, reserved built-in verbs audit/view/report/pipeline/agent (a plugin can't shadow them), and the handler interface.

One correction worth flagging: the handler is not main(argv: list[str]) — it's an ordinary console-script callable (zero-arg, reads sys.argv, returns an exit code), the same thing you'd register under [project.scripts]. I changed it from the argv-list form because that TypeErrors against real CLIs (openevolve's main() takes no args); a sibling tool now reuses its existing entry point with zero changes. Verified end-to-end against openevolve + a second installed plugin.

@aktasbatuhan aktasbatuhan changed the base branch from kai/examples to master June 9, 2026 16:24
@aktasbatuhan aktasbatuhan dismissed andthattoo’s stale review June 9, 2026 16:24

The base branch was changed.

@aktasbatuhan aktasbatuhan changed the title feat(cli): umbrella plugin dispatch (kai <tool> …) feat: report + CLI + examples + umbrella (rolled-up remaining stack → master) Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants