Enhance threat inference with business context - #77
Merged
Merged
Conversation
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.
This pull request introduces first-class support for injecting business context documents into the threat modeling prompt, both in the CLI and API. It enables users to provide PDF, Markdown, or text files containing business context (such as scope, actors, assets, and assumptions), which are injected as full text into the prompt for more domain-specific threat analysis. The changes also add a
--prompt-token-limitoption to control prompt size and ensure the LLM input does not exceed token budgets. Documentation is updated to clarify the distinction between required business context (--context) and optional reference retrieval (--rag).Business Context Injection Support:
Added a new
--contextCLI flag and corresponding API support to inject business context documents (PDF, Markdown, or text) into the threat prompt, ensuring the LLM considers domain-specific information for threat analysis. (src/threat_thinker/main.py,src/threat_thinker/context_loader.py,docs/cli.md,docs/rag.md,docs/serve_config.md) [1] [2] [3] [4] [5] [6] [7] [8] [9]Introduced the
ContextDocumentdataclass and supporting functions to load, validate, and format business context documents, including PDF extraction and token counting. (src/threat_thinker/context_loader.py)Prompt Token Limit Enforcement:
--prompt-token-limitCLI argument and corresponding validation logic to fail early if the assembled prompt (including graph, context, RAG, and instructions) exceeds the specified token budget. Default limits are set per LLM provider. (src/threat_thinker/main.py,src/threat_thinker/llm/inference.py) [1] [2] [3] [4] [5] [6] [7] [8]Threat Analysis Improvements:
src/threat_thinker/constants.py) [1] [2]Documentation Updates:
--context(for always-included business context) and--rag(for optional, retrieved references), with usage examples and API schema updates. (docs/cli.md,docs/rag.md,docs/serve_config.md) [1] [2] [3] [4]User Experience and Progress Tracking:
src/threat_thinker/main.py)These changes ensure that business context is treated as a first-class input, improving the relevance and specificity of generated threat models, while providing robust controls over prompt size and clear user guidance.