Repository navigation
Issues fixed: LangGraph API agent, AI cost tracking, Windows UTF-8 - #11
Merged
Merged
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]>
The conflict resolution kept both sides in several places: - repository.py create_completed_run: two INSERT statements spliced together (unclosed paren -> SyntaxError, every test failed) and a duplicate cost_usd parameter - repository.py complete_run: a leftover SQL line from #10 after the UPDATE string, so execute() received three arguments - schema.sql: cost_usd declared twice (duplicate column name) - cli.py: two `cost` commands and two Cost columns in `list` - overview/project/run_detail templates: both cost renderings; README: interleaved intro sentence and an unclosed code fence Keep one version of each (the one with tokens and "-" for unknown cost), drop the now-unused total_cost_usd from the overview route, and point #10's two `cost` CLI tests at the current command. Both the `secfoo` and `codex` agents from main are kept. Co-Authored-By: Claude Opus 5 <[email protected]>
5 tasks done
AdithKB
added a commit
to AdithKB/secfoo
that referenced
this pull request
Oct 3, 2026
…odel) src/secfoo/agents/secfoo.py was the original Initiative-2 draft (PR secfoo-com#10). PR secfoo-com#11 fixed the exact bug it has -- the agent never reads the target's files, so the model reviews nothing and fabricates a report -- but fixed it in a new, separate file (api.py) and never removed this one. Both have been registered and independently selectable via --agent ever since, with no indication either is broken. Reproduced twice against we45/Vulnerable-Flask-App (SAST and Secret Scanning): --agent secfoo returns "Confirmed" findings at file paths that don't exist anywhere in the target (app/db.py, app/upload.py, deploy/ci.yml), because build_graph's _State/run() never wires the resolved workdir into the model call at all -- collect_files() (the function that actually reads source) is never called from this file. The adapter's own test asserts this as correct behavior (messages == [{"role": "user", "content": "review this target"}]), so CI can't catch it. --agent api is the real, fixed implementation and needs no changes. This just removes the dead duplicate and its now-stale references: registry, AgentId enum, __init__ exports, its test, and two docs spots (README's duplicate "built-in LangGraph agent" section, and config.example.toml's three conflicting `agent =` example lines). Full suite: 700 passed (down from 702 -- exactly the 2 tests removed with the dead file). bandit clean on the touched agent files. Co-Authored-By: Claude Sonnet 5 <[email protected]>
This was referenced Nov 20, 2026
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.
Combines #9 (API-key agent and cost tracking) and #10 (LangGraph agent and cost tracking) into one change, and fixes the bugs found in each. It contains #9's commits plus the fixes, so if this merges, #9 and #10 can both be closed.
Bugs fixed
From #10 (built-in LangGraph agent)
_target_section()puts just the target's local path in that ("Inspect the codebase at:/tmp/..."). An API model can't open that path.messages == [{"role": "user", "content": "review this target"}], so it didn't catch this.collect_files()reads the target (skippingDEFAULT_EXCLUDE_PATHS, binaries and files over 200 KB) and appends each file's path and contents to the message. Targets over 2M characters fail with a clear message.START -> call_model -> END).completion()call.langgraphandlitellmwere added to the core dependencies.apiextra:pip install "secfoo[api]". If they're missing, the run fails with an install hint.$0.0000(the overview'sSUMviaCOALESCE(..., 0)).clauderuns was invisible.api(tokens and cost),claude(total_cost_usdand usage),gemini(tokens).read_text/write_textinsrc/uses UTF-8. Report reads useerrors="replace", so reports written by older versions in cp1252 still render. The test suite now gives the same result with or withoutPYTHONUTF8._kill_process_tree(production code) wrappedsubprocess.runinexcept TypeErrorto suit a test double.From #9 (API-key agent)
prompt-reviewwith OpenAIRateLimitError.completion(..., num_retries=3): LiteLLM backs off and retries on rate limits and transient errors.**Overall risk rating:**line, so no overall rating on the dashboard.--agent apiwas rejected by the CLI.AgentIdenum, separate fromADAPTERS.apiadded to the enum.litellmwas not declared as a dependency.apiextra plus an install hint.Kept from #10
Tokens and cost in the
secfoo cloud syncpayload and increate_completed_run(portal ingestion),secfoo cost --project, the README section and theconfig.example.tomlhint.How LangGraph is used
LiteLLM is still the only model gateway: it's what talks to OpenAI, Anthropic or Gemini. LangGraph runs the agent's workflow as a state graph and calls LiteLLM inside the
assessnode.collect_filesassesslitellm.completion()withnum_retries=3, then adds the call's tokens and cost to the running total in the graph state.**Overall risk rating:**, the line every output contract requires andreport/severity.pyparses? If yes, or afterMAX_ATTEMPTS(2), go to END.request_fixThe graph state carries
attempts,input_tokens,output_tokens,cost_usdandunpriced, so usage from both calls is added together. Cost isNoneif any call couldn't be priced.Why a graph: today it gives the report check and a clear, inspectable workflow.
build_graph(...).get_graph().draw_mermaid()renders the diagram above. It is also the foundation for Tier B, where the model explores large repositories itself withlist_files/read_file/greptools in a loop of unknown length. That becomes a matter of adding tool nodes to this graph rather than rewriting the agent.How a run works end to end
secfoo run --skill sast --agent api --target <repo>: the runner renders the skill prompt as for any other agent.ApiAdapter.run()checks for a key (OPENAI_API_KEY,ANTHROPIC_API_KEYorGEMINI_API_KEY), trims it, and invokes the graph with the model fromSECFOO_API_MODEL(defaultopenai/gpt-4.1-mini).AgentResult.input_tokens,output_tokensandcost_usdon the run.secfoo run,secfoo list,secfoo cost [--by agent|skill|project] [--since] [--project]and the dashboard (overview card, run page, and assessment and project tables). It is also included in cloud sync.Existing databases gain the three new columns automatically through
_RUNS_MIGRATIONS.Testing
mainon Windows: 4 architecture-diagram tests needsecfoo vendor mermaid, one checks POSIX file permissions, andtest_timeout_status_does_not_raisefails because the test double lacks the context-manager protocol. CI (Linux, py3.10 and py3.12) passes.costcommand incl.--project, run output, dashboard, unknown-as-"-", portal ingestion), 5 usage-parsing tests for claude/gemini, and 1 cloud-payload test.gpt-4.1-mini: the SAST run recorded 61,597 input and 3,261 output tokens, costing $0.0299. That matches the formula (61,597 × $0.40/1M + 3,261 × $1.60/1M) using LiteLLM's price table.Known limitations
--excludepaths are listed in the prompt but not yet skipped bycollect_files().🤖 Generated with Claude Code