dsh-web
zhu1090093659/dsh-webDeepSeek Harness(DSH)Web 插件聚合生态包 · 一切皆插件,创意工坊分发(dsh-market.com)
User-controlled policy and personalization runtime for DeepSeek Harness - enforce hard project constraints at the agent lifecycle boundary.
User-controlled policy & personalization runtime for DeepSeek Harness.
A policy-driven runtime extension that lets users define project-level hard constraints (MUST / MUST NOT / BLOCK), manage behavioral guidance and coding preferences, and incrementally build a user-controlled personalization system — without giving the AI autonomous authority over long-term user rules.
The system is not merely telling the Agent what to do. It is enforcing what the Agent is allowed to finish.
dsh-policy hooks into four verified DeepSeek Harness seams and turns your policy file into runtime enforcement:
Agent edits code ──► tools/post-execute ──► normalized evidence (real tool results)
Agent calls a MUST NOT tool ─► tools/pre-execute ───► DENIED before the tool body runs
Agent says "done" ──► agent/turn-stopping ──► evaluate hard rules
violated, budget left ► BLOCK: remediation injected as a user message
(the loop re-opens the turn — the model must act)
budget exhausted ► the turn can only end as an ERROR (never a fake completion)
all rules pass ► the turn completes normally
Subsystems behind that pipeline:
| Subsystem | What it does | Where it hooks |
|---|---|---|
| Policy loader & validator | Reads .dsh-policy/policy.json, fails loudly on anything malformed (including bad regexes) | activation |
| Scope resolver | Merges global / project / task rules; enforces Constraint Monotonicity (specific scopes may ADD rules, never weaken stronger ones) | activation |
| Constraint engine | Pure function evaluate(rules, evidence) → PASS | BLOCK + remediation; fail-closed | agent/turn-stopping |
| MUST NOT gate | Forbidden tools are denied before their body executes | tools/pre-execute |
| Evidence store | Per-session JSONL of real tool results; survives restarts (an unremediated violation keeps blocking) | tools/post-execute |
| Behavior observation | Detects recurring patterns (repeated remediations, denied-tool retries, user corrections) — zero extra LLM calls; candidates NEVER become rules without user review | session/event + enforcement actions |
| Behavior Guard | User-confirmed, contextual, NEVER-blocking reminders (type-isolated from hard rules) | prompt layer 910 + post-execute context |
| User Model + 🧋 Review | Durable personalization with a single write path (ConfirmRequest), full audit trail, interactive review CLI | CLI (the only writer) |
| Context Resolver | Injects only task-relevant preferences/goals under a hard 800-token budget; hard rules are never evicted | prompt layers 920/925 |
| Project lifecycle | Paused/completed/archived projects stop contributing rules | activation (registry) |
Verification baseline: 166/166 tests across 25 files, benchmarked end-to-end (see docs/benchmarks.md), a local web management UI (pnpm ui), and packaging tests that run against the built dist/ bundle.
The bundled web management UI (pnpm ui / dsh-policy ui) — localhost-only, point-and-click instead of config-file editing:
Dashboard — everything at a glance
Behavior review — confirm / edit / reject observed patterns (evidence + confidence shown)
Most "memory plugins" put more user information into a prompt. This project is different: the Agent operates inside a user-controlled policy boundary with three layers:
| Layer | Semantics | Can block the Agent |
|---|---|---|
| 1. Project Policy (hard constraints) | MUST / MUST NOT / BLOCK, machine-verifiable | Yes |
| 2. Behavior Guard (recurring mistakes) | WARNING / GUIDE | No |
| 3. Coding Preference (style/habits) | PREFER / SOFT | No |
Priority: Hard Project Policy > Behavioral Guidance > Coding Preference.
Core invariants:
It is implemented as a native DeepSeek Harness plugin (Cordis), not a second agent framework.
Note: the package is not yet published to npm. Until then, install from GitHub or a local checkout (see below); once published it will be
pnpm add dsh-policy.
# from GitHub (pin a commit/tag for reproducibility)
pnpm add github:x7687315-gif/dsh-policy
# or from a local checkout
pnpm add ./path/to/dsh-policy
Then scaffold your first policy with the bundled CLI (never overwrites an existing file):
npx dsh-policy init # creates .dsh-policy/policy.json with a working starter rule
Requirements: Node ≥ 20, pnpm (or npm/yarn), and a DeepSeek Harness runtime with the Cordis loader.
cordis.yml (recommended)plugins:
# your LLM adapter — the API key comes from the environment, never a file
- name: '@deepseek-ai/dsh-llm-deepseek'
options:
apiKey: ${DEEPSEEK_API_KEY}
model: deepseek-chat
baseURL: https://api.deepseek.com
- name: dsh-policy
options:
policyPath: .dsh-policy/policy.json # your project's hard rules
userModelPath: ~/.dsh-policy/user-model.json
behavior:
enabled: true # opt-in pattern observation
context:
tokenBudget: 800 # prompt budget for guidance/preferences
projectId: my-project # enables the lifecycle registry
A complete production example lives at examples/cordis.yml.
import { dshPolicy } from 'dsh-policy'
await ctx.plugin(dshPolicy, {
policyPath: '.dsh-policy/policy.json',
behavior: { enabled: true },
})
Create .dsh-policy/policy.json in your project:
{
"project": "my-api",
"policy": {
"hard": [
{ "id": "test-after-code-change", "trigger": "code_change", "require": "tests_pass", "enforcement": "hard" },
{ "id": "no-dangerous-commands", "trigger": "always", "denyTools": ["drop_database"], "enforcement": "hard" }
]
}
}
The full schema (tool-pass rules, deny rules, evidence matchers, scopes, remediation text) is documented in docs/policy.md.
| Option | Default | Purpose |
|---|---|---|
policy / policyPath | <cwd>/.dsh-policy/policy.json | Project hard rules (inline wins over path) |
globalPolicy / globalPolicyPath | ~/.dsh-policy/policy.json | Cross-project hard rules |
taskRules | — | Additive-only task-scope rules |
projectId / projectRegistryPath | ~/.dsh-policy/project-registry.json | Lifecycle: paused/archived projects stop enforcing |
maxRemediations | 2 | Injected remediations per turn before hard refusal |
evidenceRoot | in-memory | Directory for durable per-session JSONL evidence |
behavior | disabled | Pattern observation (writes candidates for review, never rules) |
userModelPath | — | Read-only consumption of confirmed guards/preferences |
guards / preferences / goals | — | Inline overrides of the user-model projections |
context.tokenBudget | 800 | Prompt budget for guidance/preferences (hard rules never evicted) |
The unified CLI (installed as dsh-policy via the bin entry, or from the repo):
dsh-policy init # scaffold .dsh-policy/policy.json (never overwrites)
dsh-policy review # interactive/piped candidate review
dsh-policy project # lifecycle: pause | resume | complete | archive
dsh-policy ui # local web management UI -> http://127.0.0.1:5178
From a repo checkout, the same commands work via pnpm scripts (pnpm ui, pnpm review, pnpm project, pnpm init) plus:
pnpm install
pnpm test # 166 tests / 25 files — real Harness stack, scripted LLM (no API key needed)
pnpm bench # full benchmark sweep -> bench/report.json (constraint/personalization/cost)
pnpm demo # end-to-end: BLOCK -> remediation injected -> tests run -> PASS
pnpm typecheck # strict TS, zero errors
pnpm build # tsdown -> dist/ (npm-publishable bundle, verified by packaging tests)
pnpm ui --policy .dsh-policy/policy.json --candidates <behaviorRoot> --model ~/.dsh-policy/user-model.json
# open http://127.0.0.1:5178 (localhost only)
Six tabs, no configuration file editing required:
appliesTo conditionsWrite-path discipline holds in the UI: it is the second legitimate writer (after the Review CLI), every mutation is an explicit user action flowing through ConfirmRequest{via:'review-ui'} + audit; the plugin stays read-only and picks changes up at its next activation.
Observation produces candidates; only you make them durable:
pnpm tsx src/review/cli.ts --candidates <behaviorRoot> --model ~/.dsh-policy/user-model.json
For each candidate it shows the evidence, occurrence counts and confidence, then asks:
[y] confirm / [e <msg>] edit / [n] reject / [s] skip. Confirmed candidates become
Behavior Guards on the next activation; rejected ones are tombstoned and never resurface.
The CLI is the ONLY writer of the user model, and every change is audited.
pnpm project pause <projectId> # rules stop contributing to new sessions
pnpm project resume <projectId>
pnpm project complete <projectId>
pnpm project archive <projectId> # .dsh-policy moved to archive/, history kept
export DEEPSEEK_API_KEY=... (never commit keys),examples/cordis.yml,Agent edits code → tools/post-execute records code_change (real tool result)
Agent says "done" without tests → agent/turn-stopping evaluates the policy
→ BLOCK: remediation injected as a user message
Agent runs tests, tests fail again → BLOCK again (within the remediation budget)
Budget exhausted while still violated → the turn can only end as an error (never a fake completion)
Agent runs tests, tests pass → PASS: the turn may complete
Agent calls a MUST NOT tool → tools/pre-execute denies the call before the body runs
Every step → the model sees the active rules in its prompt (explanation ≠ enforcement)
Stage 0–18 complete — the full project plan (Phase 0–18) plus the web management UI and real-environment hardening. Verification baseline: pnpm test 166/166 across 25 files, pnpm typecheck clean, pnpm build green, pnpm bench full-sweep benchmark green (report, interpretation).
code_change → tests_pass)tools/pre-execute deny) + rule visibility in the promptcordis.yml, scenarios A–E end-to-enddsh-policy init / unified CLI / bin entry)Next: hardening & deployment — npm publish, cloud smoke test (DeepSeek key), registered engineering debts (see docs/PROGRESS.md).
Each stage below has a full report (what was done, how, and where the project stood afterwards). Start with the project plan (the original specification) and the stage table (current status), then dive into any stage:
Foundation
Generalization
Personalization
Composition & verification
dsh-policy initReference documents
dsh-policy is part of the DeepSeek Harness plugin ecosystem ("Everything is a Plugin") — find it (and siblings) via the GitHub topics dsh and dsh-plugin.