Repository navigation
Conversation
Add an `api` agent that runs skills by calling OpenAI, Anthropic or Gemini directly through LiteLLM, so an assessment no longer needs a coding-agent CLI installed. This is Tier A (context stuffing): the target's source files, minus the default exclusions, binaries and files over 200 KB, are sent in one request. Targets over 2M characters are rejected with a clear message. Install with `pip install "secfoo[api]"`. Record input/output tokens and cost on every run where the agent reports them (api via LiteLLM, claude via total_cost_usd, gemini tokens only), and surface spend in `secfoo run`, `secfoo list`, a new `secfoo cost` command, and the dashboard. Unknown cost renders as "-", never $0.00. Existing databases gain the new columns automatically. Co-Authored-By: Claude Opus 5 <[email protected]>
Rebuild the api agent's run as a LangGraph graph (collect_files -> assess -> report check), with LiteLLM still the only model gateway. If a report comes back without the `**Overall risk rating:**` line every output contract requires, the graph asks the model once to reformat its own draft -- without resending the source, so the retry stays cheap. Tokens and cost add up across both calls. LiteLLM now retries rate limits and transient errors itself (num_retries=3); running several skills at once previously failed on OpenAI's rate limit. Fold in the useful parts of PR #10: - tokens and cost in the cloud-sync payload and create_completed_run - `secfoo cost --project`, a README section, config.example.toml hint - UTF-8 for every text read/write, not just runner's report writes. Report reads use errors="replace" so reports written by older versions in the Windows code page still render instead of crashing. The suite now gives the same result with or without PYTHONUTF8. langgraph joins litellm in the `api` extra, and dev (litellm stays faked in tests, so CI doesn't need it). Co-Authored-By: Claude Opus 5 <[email protected]>
Contributor
Author
|
Superseded by #11 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
API agent (Initiative 2, Tier A). Every existing agent drives an installed coding-agent CLI (Claude Code, Cursor, Antigravity, Gemini CLI). CI runners and many contributors don't have one installed and logged in, so they can't run an assessment at all. The new
apiagent needs only an API key.Cost tracking. Users had no way to see what their AI usage costs. Each run now records tokens and cost where the agent reports them, and spend is visible per run, per agent, per skill and per project.
What changed
--agent api(src/secfoo/agents/api.py)OPENAI_API_KEY,ANTHROPIC_API_KEYorGEMINI_API_KEY; the model is set withSECFOO_API_MODEL(defaultopenai/gpt-4.1-mini).DEFAULT_EXCLUDE_PATHS, are binary, or are over 200 KB. Targets over 2M characters fail with a clear message.run(), since there's no subprocess, and returns the sameAgentResultshape. Registered inregistry.pyand added to the CLI'sAgentIdenum.pip install "secfoo[api]". If it's missing, the run fails with an install hint.Cost tracking
AgentResultgainsinput_tokens,output_tokensandcost_usd, plus anextract_usage()hook onAgentAdapter:api: LiteLLM usage andcompletion_cost(); cost isNonefor models LiteLLM can't price.claude:total_cost_usdandusagefrom--output-format json, with cache tokens counted as input. On a subscription login this is Claude's API-price estimate.gemini: token counts fromstats.models.*.tokens; no cost available.agent(Cursor) andagy: they print plain text, so nothing is recorded.runsgains three nullable columns, added through_RUNS_MIGRATIONSso existing databases upgrade in place.RunRepository.cost_summary()groups by agent, skill or project. Runs with no recorded cost are counted asunpriced_runs, not as $0.runandlist, "AI spend for this run: $X", and a newsecfoo cost [--by agent|skill|project] [--since YYYY-MM-DD]command.Testing
tests/test_agents/test_api.py(9),tests/test_cost.py(11), and usage parsing intest_claude.py/test_gemini.py(5).mainlocally (Windows): 4 architecture-diagram tests needsecfoo vendor mermaid, which CI runs first;test_save_cloud_config_sets_restrictive_permissionschecks POSIX permissions;test_timeout_status_does_not_raisefails becauseos.killpgdoesn't exist on Windows.gpt-4.1-mini:prompt-reviewfailed because running 7 skills at once hit OpenAI's rate limit.Known limitations / follow-ups
apiagent haven't yet been compared against aclauderun or NodeGoat's documented vulnerabilities.--excludepaths are listed in the prompt, butcollect_files()doesn't skip them yet.--skillruns can hit provider rate limits. Retry with backoff, or runapiskills one after another.apiagent.secfoo cloud syncpayload yet.read_text()/write_text()calls needPYTHONUTF8=1.🤖 Generated with Claude Code