nodecode-semgrep
Semgrep static analysis as tools the model calls: scan local code with Semgrep's registry rulesets or your own rule files, and read the findings one line each, worst first. The code a finding matched is never shown, so a scan for secrets does not put the secrets it found into the conversation.
Written for Nodecode from Semgrep's documented command line, JSON and SARIF output. No code of Semgrep's is in this cell and the CLI is not vendored: you install it.
Install
- Install Semgrep so
semgrepis onPATH(quickstart:pipx install semgrep,brew install semgrep, orpython3 -m pip install semgrep), or setcommandto the binary's absolute path. The cell needs a Semgrep that writes--sarif-output(tested with 1.187.0). No account is needed. - Add the cell:
nodecode add nc://semgrep. - Check it with
/semgrep, which answers Semgrep's version and whether a login applies.
Tools
| Tool | What it does |
|---|---|
semgrep_scan |
semgrep scan over absolute paths with registry or local rules; a summary line, then one line per finding: severity, rule id, file:line, the rule's own message, CWE and OWASP class |
semgrep_validate |
semgrep scan --validate over local rule files: valid, or each problem with its rule and message; nothing is scanned |
semgrep_scan arguments:
paths(required): absolute paths of files or folders.~is read against your home.config: registry rulesetsp/NAME(p/default,p/owasp-top-ten,p/secrets,p/python...), registry rulesr/RULE-ID, or absolute paths of local rule files or folders. The section'sdefault_configwhen omitted.severity:low,medium,highorcritical, the floor a finding must reach. Semgrep'sINFOandLOWcount as low,WARNINGandMEDIUMas medium,ERRORandHIGHas high,CRITICALas critical. What the floor leaves out is counted.include,exclude: path globs (--include,--exclude), each value its own flag.exclude_rules: rule ids to skip (--exclude-rule).include_ignored: also scan what.gitignoreleaves out (--no-git-ignore).max_target_bytes,jobs,rule_timeout,max_findings: lower than the section's value, never higher (a section value of 0 forjobs,rule_timeoutormax_target_bytessets no ceiling; a sectionmax_target_bytesof 0 with no call value is passed as--max-target-bytes=0, so Semgrep's own 1 MB default does not apply).
What it refuses and hides
- The matched code.
extra.lines,extra.fixandextra.metavarsare never read, and neither isextra.message: Semgrep fills a rule's$METAVARIABLESinto the message with the matched code, so a rule sayingHard-coded token $Vwould answer with the token. A finding shows the rule's own text instead, read from a SARIF copy of the same run (each rule'sfullDescription), its$METAVARIABLESleft unfilled. A rule whose text does not come back is listed without a message. - Scan errors about a scanned file name the file and line, never the message, which
can quote the code. Errors about a rule or a config (a type naming a rule, pattern,
YAML, schema, language or config) carry their message. An error counts as a file
error when it has a
path, or a first span'sfileand a type that is not about rules, so an unknown type keeps its message out. - Raw output. If Semgrep writes something other than its JSON report (a cut or broken document), the answer says how long it was and does not show it.
config autois refused: it needs metrics on and sends the project's languages to semgrep.dev. URLs and anything other thanp/NAME,r/RULE-IDor an absolute path are refused too.- Flags from the model. Every value rides its flag as one argument
(
--include=VALUE), a value that starts with a dash or holds a control character is refused, and the targets come after--. Relative or missing paths are refused before anything runs. - A login on this machine. Every run gets a folder of its own (mode 0700, removed when
the run ends) holding the SARIF copy and, unless
use_loginis on, a Semgrep settings file of its own, withSEMGREP_APP_TOKENtaken out of the run's environment. Asemgrep loginthen changes nothing a tool does: no Pro rules or Pro engine, registry rules fetched anonymously. Every run also setsSEMGREP_SEND_METRICS=offand drops an inheritedSEMGREP_RULES,SEMGREP_BASELINE_COMMITandSEMGREP_FORCE_COLOR, which would add rules or hide findings behind the call's back. ASEMGREP_APP_TOKENin the environment is scrubbed from every answer either way, in one pass and before any part of the answer is cut tomax_output_chars, so a token the cut would split leaves no prefix behind. - Missing CLI and timeouts are words: exit 127 with how to install Semgrep, or the
run killed past
timeout_secondswith its whole process tree.
Every scan runs with --json --metrics=off --disable-version-check --quiet. A registry
ruleset is downloaded from semgrep.dev on each scan; the scanned code never leaves the
machine.
Settings
The semgrep section of ~/.nodecode/config.jsonc (see config.example.jsonc):
| Setting | Default | Meaning |
|---|---|---|
command |
["semgrep"] |
the argv prefix that runs Semgrep |
default_config |
["p/default"] |
the rules a scan uses when its call names none |
severity |
"low" |
the floor a scan reports when its call names none |
timeout_seconds |
900 |
one run's ceiling; its process tree is killed past it |
max_output_chars |
20000 |
how much one answer carries |
max_findings |
200 |
finding lines one answer lists, and a call's ceiling |
max_target_bytes |
1000000 |
files larger than this are skipped, and a call's ceiling; 0 sets no limit |
jobs |
0 |
rules or files at once, and a call's ceiling; 0 leaves Semgrep's own |
rule_timeout |
5 |
seconds one rule may spend on one file, and a call's ceiling; 0 sets no limit |
use_login |
false |
let a semgrep login or SEMGREP_APP_TOKEN apply to scans |
"enabled": false vetoes the section and installs nothing.
Tests
bash .github/test-cell.sh tools/nodecode-semgrep
The tests run offline against a stubbed CLI: the command lines the tools build, what is refused before anything runs, the run's environment, and the report, above all that a secret planted in the matched lines, the filled message, the fix, a metavariable and a file error reaches no answer.
License
MIT. Semgrep is a trademark of Semgrep, Inc.; this cell is not affiliated with it.