Class DestructiveCommandDetector
- All Implemented Interfaces:
com.tnsai.agents.execution.ToolCallFilter
ToolCallFilter that scans tool arguments for
destructive shell / git / filesystem commands hidden inside generic
tools like terminal_execute("rm -rf /") (issue #36).
Complements Tool.requiresConfirmation()
which is a tool-identity flag — this detector inspects the
argument payload of any tool call. Both are intended to be
chained: tool-identity confirmation gates shells in general; this
detector spots specific dangerous payloads regardless of which
shell-like tool dispatches them.
The default pattern set covers the common destructive families:
rm -rf, git reset --hard / git clean -fd,
dd-to-device, mkfs, world-permissive chmod, force-kill broadcasts,
and writes to system / SSH config locations. Each pattern carries a
DestructiveCommandDetector.Severity; the detector returns ToolCallAction.block()
for DestructiveCommandDetector.Severity.CRITICAL matches and ToolCallAction.guide(java.lang.String)
(with corrective feedback) for DestructiveCommandDetector.Severity.HIGH matches by
default. The mapping is configurable via
DestructiveCommandDetector.Builder.severityAction(Severity, java.util.function.Function).
Default patterns load from
tnsai-quality/src/main/resources/security/destructive-patterns.txt
— operators ship custom patterns by passing additional resources to
DestructiveCommandDetector.Builder.additionalPatternsResource(String) or registering
inline via DestructiveCommandDetector.Builder.pattern(DestructivePattern).
Performance: per-call overhead is dominated by a small number of
compiled regexes evaluated against concatenated argument strings.
Patterns are compiled once at builder time. Target < 1ms
for a typical payload of a few hundred chars on commodity hardware.
- Since:
- 0.5.0 (issue #36)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classstatic final recordA single named pattern with its severity classification.static enumSeverity tier of a destructive-command match. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionbuilder()com.tnsai.agents.execution.ToolCallActionbooleanpatterns()Visible for inspection / testing.static DestructiveCommandDetectorConvenience: a detector loaded with the bundled default pattern catalogue.
-
Field Details
-
DEFAULT_PATTERNS_RESOURCE
Bundled default-patterns resource. Format: one pattern per line, blank lines and lines starting with#are ignored. Each non-comment line has 3 tab-separated fields:<name>\t<severity>\t<regex>.- See Also:
-
-
Method Details
-
withDefaults
Convenience: a detector loaded with the bundled default pattern catalogue. Equivalent tobuilder().build(). -
builder
-
patterns
Visible for inspection / testing. -
isAllowed
- Specified by:
isAllowedin interfacecom.tnsai.agents.execution.ToolCallFilter
-
evaluate
public com.tnsai.agents.execution.ToolCallAction evaluate(String toolName, Map<String, Object> arguments) - Specified by:
evaluatein interfacecom.tnsai.agents.execution.ToolCallFilter
-