DeepSeek Harness Plugin

irisblackwood/focus-guard#core

Stars ★ 1 Downloads (30d) 2,099 Category Security & Permissions Added 2026-10-16 npm focus-guard

Blocks AI coding agents from editing files without evidence and from running unapproved high-risk commands, and tells quoted dangerous strings apart from commands actually being executed.

Install

# from npm (prebuilt)

dsh plugin --profile web add focus-guard

# from GitHub (first run asks for allowBuilds approval — follow the hint, retry)

dsh plugin --profile web add github:irisblackwood/focus-guard#path:/packages/core

Any plugin you install runs third-party code with your own permissions — it can read your files, use your credentials, and reach the network, and tool approvals don’t sandbox it. GitHub-sourced plugins also run build scripts at install time — pnpm blocks those until you allow them, so an install can stop with ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED or ERR_PNPM_IGNORED_BUILDS; dsh prints the exact key to add under allowBuilds in your profile’s pnpm-workspace.yaml, and the install works on the next run. Allowing a build is a trust decision: only install sources you trust, and pin a commit (github:owner/repo#sha).

README

状态:参考 · 适用版本 3.5.3 · 最后核对 2026-11-24

To the AI picking this up: read docs/RULES.md (the law) → docs/ARCH-MAP.md (what is built) → docs/VERSION-PLAN.md (the plan; repo only, on GitHub). Order matters.

Formerly FocusGuard. Renamed in 3.5.0 — the package name focus-guard, the plugin id, the .focus-guard/ state directory and the FG_* environment variables are unchanged.

Chinese · English

Guardrails for AI coding agents, enforced at the hook layer. Three kinds of runaway stop being prompt advice and become mechanically blocked events:

  • Thinking — a conclusion with no [file:line] evidence is pushed back before it ships
  • Resources — whole-file reads and repeated no-op reads burn context; both are gated
  • Permissions — rm -rf / git push -f / npm publish need a grant before they run, not an apology after

Every block is appended to .focus-guard/AUDIT.log (JSONL) with the rule that actually fired. Nothing here asks the model to behave; it changes what the model is allowed to do.

Install

DSH (native plugin, recommended)

dsh plugin --profile <your-profile> add focus-guard

dsh plugin wraps pnpm, so add takes any pnpm spec. Three forms, same package — only the version source differs:

Form Gets you
add focus-guard the last npm release (currently 3.5.2), signed with provenance
add github:irisblackwood/focus-guard#path:/packages/core whatever is on main right now — may be ahead of the release
add <path>/packages/core your local working copy (dev)

The GitHub form needs #path:/packages/core because this is a monorepo: the root package.json is not the plugin.

Restart the session to activate. The bundle patch is declared by this package's package.json (dsh.bundle.patch → src/dsh/cordis.patch.yml), so no manual cordis.patch.yml editing.

Standalone (CLI only, no host): npm install focus-guard — ships the focus-guard-brain binary.

Mutually exclusive with the official bridge (@deepseek-ai/dsh-hooks-claude-code). Both mount the same seams; mounting both double-runs every hook — pick one.

The bridge is maintained by the official repository; this package is only the adapter. Install/confirm the bridge first, then mount this package's hooks/hooks.json. Supported bridge range: >=0.2.1-rc.1 <0.3.0 (verified 0.2.1-rc.1 / 0.2.2-rc.5). Outside the range the session start warns bridge-incompatible with upgrade/rollback commands. Bridge-level bugs or missing features belong to the official repo; this repository only handles adapter defects and compatibility.

ZCode

.zcode-plugin/plugin.json is ready; import this repository through ZCode's plugin flow. The execution shell is sealed — it carries its own version and does not follow the main release.

What it blocks

Situation Mechanism
Editing files or running mutating commands without investigating first L4 precondition: the target must have been read in this session, otherwise one refusal (new files exempt)
High-risk commands (recursive delete, format, force-push, publish, global install, system-path writes) L3 eligibility: apply before execute, denied without a grant; fg_apply is the request channel
Absolute red lines (rm -rf /, DROP DATABASE, git push -f) L2 zero-latency short-circuit denial, no approval prompt
Dangerous strings that are merely quoted (test data, docs, eval fixtures) Context exemption on three criteria (quoted / data marker / read-only command) → downgraded to semantic judgement, never waved through
Wrongly blocked, no appeal path fg_appeal: submit counter-evidence anchors, one human ruling, fully recorded
Whole-file read of a large target Above FG_WHOLE_FILE_MAX_LINES (default 300) without offset/limit → denied, pointed at XERJ
Vague development request, straight to editing One refusal before the first write, requiring brainstorming or writing-plans
One-size-fits-all across models Model profiles (src/profiles/): review intensity follows the model
Writing grep/find when the machine wants rg/fd Environment fingerprint + hard command check, one-line substitution hint

How it decides

Six layers, in order. A profile may skip layers; it may never disable L2 or L3.

Layer Question
L0 Request completeness — empty purpose / scope is denied
L1 State — fuse / downgrade / budget exhausted
L2 Absolute red lines (denied here, never reaches L3)
L3 High-risk eligibility — matches a high-risk signature with no grant in this session → human approval
L4 Preconditions — mutating targets must be evidenced; system paths and .git/node_modules are stricter
L5 Semantic signals — the model probe's mismatch / high-risk score
L6 Grant and record

What else is running

All shipped. Module paths carry no line numbers on purpose — those rot silently.

  • Heartbeat and liveness — src/dsh/heartbeat.mjs, src/dsh/status.mjs: every 10s the plugin atomically rewrites .focus-guard/status.json; node src/dsh/status.mjs reports ALIVE / STALE and exits 0 all-green, 2 module missing, 3 stale, 4 no file.
  • Module self-check — src/dsh/heartbeat.mjs: the ten enforcement seams plus the heartbeat each report at startup; anything missing lands in degraded, is warned to the host log, and is injected to the model as focus-guard-degraded.
  • Cross-session record — src/memory/workspace.mjs: state is keyed by sha256(realpath(cwd)); a hash mismatch injects nothing, so a renamed folder cannot inherit old state.
  • Compaction watch — src/dsh/compactionWatch.mjs: observes compaction/start|end|prune and request-error collisions, and measures how many anchors (paths, line refs, error codes, constants) a summary kept versus the original. Read-only: never writes a surface, never cancels a turn.
  • Prefix stability — src/core/prefixStability.mjs: fingerprints the assembled prompt prefix each turn and records shifts, so a cache-breaking change shows up as an audit event instead of on an invoice.
  • Graded destructive heuristic — src/dsh/guard/risk.mjs: Remove-Item / fs.rmSync weight by target — system path or recursive 0.9 (blocked), TEMP 0.2, other 0.4; redirection 0.15.
  • Denial reasons in the audit — src/dsh/audit.mjs: auditDeny(exec, cmd, {trigger, level}) records the real rule (redline:<name>, env-substitute, gate:fg_apply, evidence-gate, whole-file:lines, risk:<category>) instead of a constant high-risk-rm.
  • Executor detection — src/core/env.mjs, src/dsh/index.js: the master layer honours an explicit FG_SHELL; the DSH adapter declares powershell, ending the three-way mismatch between record, fingerprint and actual executor.
  • Audit isolation guard — tests/audit-isolation.mjs: snapshots the real AUDIT.log before the suites run and fails the run if it grew.

Architecture

src/core/            master layer: zero-dependency, host-agnostic judging logic (26 modules)
src/adapters/dsh/    adapter layer: wires the master into DSH (fg_apply / fg_appeal + eligibility gate)
src/dsh/             host seams: pipeline.mjs orchestrates 8 events; guard/ holds the per-layer gates
src/memory/          cross-session record, tags, workspace hashing
src/profiles/        five pure-parameter model profiles
hooks/guard.mjs      ZCode execution shell (sealed: independent version)

Layering rule: the master layer must not depend back on the adapter layer (locked by an acceptance test). Dependency direction is core → adapters → seams, one way only.

The methodology skill ships with the package: the writing gate asks you to load a methodology skill before touching files on a vague dev task, and the skill it recognises is this package's own skills/focus-plan — no external skill required. If you have superpowers installed, brainstorming / writing-plans are accepted too (compatibility, not a prerequisite); any skill whose name contains plan / brainstorm / design / spec is accepted as well. To drop the layer entirely: FG_WRITING_GATE=off. So "zero-dependency" here is literal: zero npm dependencies and zero external-skill dependencies.

Commands

npm test                    # full suite, run inside an audit sandbox
npm run test:eligibility    # eligibility + red-line exemption + appeal
npm run eval                # threat evaluation (detection rate + benign false-positive rate)
npm run check               # everything the release gate runs

Version

Three numbers, three meanings — do not mix them:

Surface Value Meaning
npm registry 3.5.2 last npm publish (2026-11-18, OIDC trusted publishing + provenance)
GitHub main 3.5.2 PUBLISHED_MAX — what "released" means for this project
This tree 3.5.3 level with released; unpushed work runs ahead, and ahead is not released

Docs

  • Capabilities, code anchors, gaps: docs/ARCH-MAP.md
  • Rule text, and which clauses are machine-enforced: docs/RULES.md
  • Mechanism walkthrough: repository docs/ARCHITECTURE.md
  • Changelog: repository CHANGELOG.md

License

AGPL-3.0-only © 2026 irisblackwood — a commercial license is available as an alternative to the AGPL (e.g. to avoid section 13's source-offer obligation); it is not required in order to comply with the AGPL.

Content from the project README on GitHub ↗

Links

More in this category

View the whole category →

Community comments

Comments are public GitHub Discussions. Loading them connects to GitHub and Giscus; a GitHub account is required to post.