specpi-lancet-guard

Local, CPU-only command guard for Pi: the LANCET classifier scores shell calls on your machine, with no API key and no network after a one-time checksum-verified model download

Packages

Package details

extension

Install specpi-lancet-guard from npm and Pi will load the resources declared by the package manifest.

$ pi install npm:specpi-lancet-guard
Package
specpi-lancet-guard
Version
0.7.0
Published
Nov 29, 2026
Downloads
374/mo · 64/wk
Author
tannermidd
License
MIT
Types
extension
Size
126.2 KB
Dependencies
1 dependency · 2 peers
Pi manifest JSON
{
  "extensions": [
    "./src/index.ts"
  ]
}

Security note

Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.

README

specpi-lancet-guard

A local, CPU-only command guard for Pi. Before a shell command runs, LANCET Nano v0.6.0 scores it on your machine: a 149M-parameter Ettin-150m encoder with a 1,024-token single window, fine-tuned to flag risky Bash, PowerShell and cmd commands, running as GeGLU Hybrid-W8/INT8 ONNX. No API key, no account, and no network once the model is downloaded.

It is off until you turn it on.

Install

pi install npm:specpi-lancet-guard@0.7.0

SpecPi installs it by default. The package carries code only; the model is fetched once, by you:

/lancet-guard setup

Setup downloads the release ZIP (about 153 MB) from the pinned LANCET-model GitHub release, refuses it unless its SHA-256 matches the digest built into this package, extracts only the five model files (the encoder, its pooling head, the Ettin-150m tokenizer and the thresholds; 151 MB on disk) and checks each against its own digest. It then runs two sample commands and asks whether to turn the guard on: for this session, or saved for future ones.

Each package release accepts exactly one model. After updating from an earlier version, run /lancet-guard setup again to fetch v0.6.0: until you do, a guard you saved as on blocks what the local rules leave open, as it does whenever the model is missing. Older models stay in <pi-agent-dir>/lancet-guard/ (for example lancet-nano-v0.4.3-int8/) and are no longer used; you can delete those folders.

Use

Command Effect
/lancet-guard Status: on or off, saved setting, model state
/lancet-guard setup Download and verify the model, self-test, offer to turn it on
/lancet-guard on / off Switch it for this session
/lancet-guard on --global / off --global Switch it and save that as the default for future sessions
/lancet-guard mode <ask|block> Choose what a risky verdict does, saved for future sessions (see Modes)
/lancet-guard check <command> Score a command without running it
/lancet-guard audit <transcript|status|off> Where decisions are shown; every one is still written to the session file

on is refused until the model is installed, because an armed guard with no model blocks every command the rules leave open.

How it decides

For bash, powershell and SpecPi's background tool:

  1. Local rules first, the same ones specpi-jev-guard uses: hard-deny patterns (recursive deletion of /, a home or system directory, mkfs, raw device writes, curl | sh, fork bombs…) block; provably read-only commands (ls, git status, rg with read-only flags…) pass; your safeCommands, allowedCommands and disallowedCommands globs apply. LANCET cannot overrule these.
  2. LANCET scores the rest. risky asks you, or blocks in block mode; review, Nano's band for commands it is unsure about, always asks; not_flagged runs.
  3. What LANCET cannot read or clear asks. It reads Bash, PowerShell and cmd: bash and background calls are scored as Bash, powershell calls as PowerShell. Commands over 8,192 bytes ask. Commands up to 1,024 tokens run in a single native pass; anything longer than one 1,024-token window is scored on its first 1,024 tokens, and LANCET never clears a truncated command (risky and review act as usual, while not_flagged asks).

For write and edit, LANCET is not involved: ordinary project files pass, and protected paths (.env*, keys, .ssh, .git, node_modules) or anything outside the workspace ask.

Modes

/lancet-guard mode chooses between two modes and saves the choice as risky in ~/.pi/lancet-guard.json:

  • ask (the default): risky and review both ask.
  • block: risky is blocked outright and, as with the hard-deny rules, Pi stops the agent once that batch of tool calls finishes; review still asks. Fewer prompts, at the cost of a safe command LANCET misjudges being blocked and stopping the run.

The mode covers LANCET's verdicts only. In both, the local hard-deny rules and your disallowedCommands block, and so does a missing or damaged model (see below). A trusted project's .pi/lancet-guard.json can set its own risky, which wins inside that project; /lancet-guard mode ask or block says so when it does.

With no UI to ask (print or RPC mode without a client), an "ask" becomes a block unless you set "uncertain": "allow".

It fails closed. A missing or damaged model, or ONNX Runtime failing to load, blocks the commands the rules leave open. /lancet-guard off switches it off.

not_flagged means LANCET did not flag it, not that it is safe. The permission system and your own judgement still apply.

Settings

~/.pi/lancet-guard.json, with a trusted project's .pi/lancet-guard.json on top:

{
    "enabled": false,
    "risky": "ask",
    "uncertain": "ask",
    "auditDisplay": "status",
    "safeCommands": [],
    "allowedCommands": [],
    "disallowedCommands": [],
    "protectedPaths": ["**/.env*", "**/*.pem", "**/*.key", "**/id_rsa*", "**/id_ed25519*", "**/.ssh/**", "**/.git/**", "**/node_modules/**"]
}

What to expect

These figures come from LANCET's v0.6.0 release evaluation (the classifier alone, before the local rules, at the shipped thresholds; #1 of 24 local and hosted guards evaluated across four benchmarks):

Benchmark Nano v0.6.0 (this guard) Notes
Overall (4 benchmarks) 77.08 #1 of 24 guards (74.49 strictly unseen without ShellRisk)
Bench 3 Core (strictly unseen) 79.55 79.55% risky caught at 9.00% safe interruption (7/3,423 safe blocks)
Third-party yannelli/cli-command-risk test (14,055 rows, unseen) 75.55 #1 unseen local: 89.3% critical catch, 8.2% safe false alarms, 0/4,758 safe hard blocks
Neutral set (unseen) 52.40 Low false-alarm friction across safe commands
Pooled safe interruption (8,743 unique safe commands) 5.1% Less than half of hosted frontier decision APIs (11.5%–21.0%)
  • Per owner policy, v0.6.0 fitted on ShellRisk-Bench train+test (excluding GPL gtfobins/nl2bash); Bench 3 Core, Neutral, and Yannelli CLI-Risk test remained strictly unseen. No hosted language-model output was used as training data, labels, teacher targets, or selection signal.
  • Typical CPU latency is around 46.5 ms median (335 MB steady-state RSS) in a single 1,024-token pass — 33% faster than v0.5.0. It only loads once the guard is on or you run check.
  • The runtime is a Node port of Nano v0.6.0's Python classify.py (ettin-hybrid-w8-1), verified against the Python reference for exact token ids, truncation handling, bands, and score/logit parity.

ONNX Runtime 1.30.0 ships CPU binaries for Windows x64/arm64, Linux x64/arm64 and macOS arm64. Intel Macs are not supported; there the guard fails closed and should be left off.

LANCET is experimental. It is not a sandbox and does not make running commands safe. SECURITY.md states the full boundary.

License

Package code: MIT. The local rules are copied under MIT from specpi-jev-guard. The model is LANCET Nano v0.6.0, Apache-2.0, fine-tuned from jhu-clsp/ettin-encoder-150m (MIT); its release ZIP carries the full licenses, notices and model card. Third-party details: THIRD_PARTY.md.