| description | Hard-isolation protocol for agent tasks plus versioned prompt-policy evolution: exogenous verification, rollback and termination, a gated skill store, and flow/dataset export. |
|---|---|
| kind | package-bundle |
English | 中文
Snapshot note: this repository exports the LCRD package and its tooling from deepseek-harness. Workspace dependencies are not standalone-installable; run the commands from the harness workspace.
LCRD maps a three-symbol protocol — root anchor, stop symbol, rollback symbol — onto the harness extension points. An exogenous verifier checks every tool result; failures roll back and require a different plan; repeated failures terminate for human review. An opt-in second layer turns solved problems into versioned skills and admits a candidate only after a holdout gate, review brief, and approval. The layers are separate: the protocol controls one task, evolution controls which prompt skills later tasks may use. Detailed contracts live in doc/architecture.html.
- Architecture at a glance
- Runtime protocol
- Policy evolution and gate
- Components
- Quick start
- Trust boundaries
- Detailed architecture
- Model Experience
- Known Limitations and Deferred Work
- Dev Note
| Layer | Responsibility | Main entry points |
|---|---|---|
| Runtime protocol | Anchor the task, require a declared plan, verify every tool result, roll back failures, terminate after the retry budget, and offer an optional learning round. | src/anchor.ts, src/plan-tool.ts, src/step-verify.ts, src/verifiers.ts, src/expr.ts, src/state.ts |
| Policy evolution | Turn a solved problem into a skill version; statically scan it; run a paired baseline/candidate gate on a rotating holdout; write a review brief; promote through approval; monitor online behavior and roll back regressions. | src/evolve/propose-tool.ts, static-check.ts, holdout.ts, gate.ts, launch.ts, brief.ts, store.ts, monitor.ts, hardout.ts |
| Evidence and operations | Persist the policy ledger, flow exports, dataset/DPO rows, rejected-edit feedback, notices, and the runtime invariant. | src/flow.ts, src/dataset.ts, src/notice.ts, src/invariant.ts, scripts/lcrd-* |
The invariant: the model authors declarations, skill text, and rationale; it never writes a verifier verdict, a gate result, a pointer, or an approval outcome. Skills are data, not executable code. A promoted change is a pointer swap in the policy store; the current version is read again by the next task.
- Root anchor. The user's first message is the task contract; the model may not expand, redefine, or silently narrow it. The root-anchor text is pinned as a system-prompt section.
- Declare before acting. Before a task tool call, the model calls
lcrd_planwithgoal,stop_condition,feasibility, and averifier. The declaration is data; the engine owns how it is evaluated. - Exogenous verification.
assertevaluates a restricted JS expression list againstresult,content, andisError;pythonevaluates fixed-template checks;llmasks a separate fixed-prompt verification session. A tool error is a failed verification, not a pass. - Rollback and retry. A failed result is blocked and returned with the failure reason; the model must re-plan with a different method. A retry never silently reuses the old plan.
- Termination. Consecutive failures at the configured limit end the task for human review. Learning mode is an optional, bounded pause before termination; it is in-session and does not persist knowledge across sessions.
- File flow. With
fileFlowEnabled, the task directory and its flow files are guarded so a write outside the task-flow contract is caught as a path violation.
The runtime is enforced through registrations, not by trusting the prompt: agent/pre-step and tools/post-execute listeners own the state transitions. A gate child mounts the candidate with evolution disabled, so a measurement run can never propose.
Evolution is off by default and requires evolveBenchmarkDir plus the composed @deepseek-ai/dsh-skill service.
- Propose.
lcrd_proposeaccepts a rationale, the currentparent_version, and 1–8 skills. Static rules reject injection, identity negation, authority escalation, hidden text, forged framing, and holdout leakage before a version directory exists. - Stage. An accepted proposal becomes an immutable
versions/vNNNN/directory with a manifest, parent, rationale, benchmark digest, and skill digests. - Gate. One candidate mount probe, then paired baseline and candidate runs on a rotating holdout subset. Each run gets its own workspace and fixture copy; the reward command runs in that workspace.
- Decide. Admission uses ground-truth reward by default. The gate records paired deltas, a bootstrap interval, token spend, termination, cheat, hook, and path metrics.
detectabilityis the sample's resolution;headroom = 1 - baseline.rewardRateis the effect the benchmark can still show. A gate withheadroom < evolveMinGainwrites a baseline-onlygate-abortedreport before the candidate starts. - Report and review.
report.json,gain-report.md/json, andbrief.md/jsonretain every raw run and the exceptions. The verdict (gain,no-gain,insufficient-evidence) is separate from the gate decision. - Promote and monitor.
evolvePromote: approval(default) asks the approval service;autois for CI only. The next task readscurrent.json; the online monitor folds completed runs and can roll back a regressed version. Sealed hard-out audits can hold promotions. - Feedback. Rejected attempts append a bounded
rejected-edits.jsonlrecord; the next proposal sees the latest rules/lines or gate reasons. Notices ride the existingadditionalContextschannel; no new session event type is added.
| Path | Role |
|---|---|
src/anchor.ts |
Protocol text, PROTOCOL_VERSION, root-anchor section registration |
src/plan-tool.ts, src/step-verify.ts |
lcrd_plan, declaration-time gates, post-execute verification and rollback |
src/verifiers.ts, src/expr.ts |
Assert/Python/LLM verifier implementation; restricted expression grammar |
src/state.ts, src/step-learn.ts, src/learn-tools.ts |
Per-agent retry, learning-round, and termination state |
src/file-flow*.ts |
File-backed task flow and path-violation guard |
src/evolve/ |
Proposal tool, static scan, holdout, gate launcher, store, brief, gain report, significance, monitor, hard-out audit |
src/dataset.ts, src/flow.ts |
Flow export and dataset/DPO row construction |
src/notice.ts, src/invariant.ts |
Best-effort policy notices and durable runtime invariants |
benchmarks/ |
Example fixture benchmark and repo-fix benchmark |
scripts/lcrd-* |
Operator tooling: policy, audit, weight eval, checkpoint registry |
training/ |
Offline DPO/LoRA scaffold and the weight-path control plane |
The package is private and is developed inside this repository. Run the source with the in-package patch:
pnpm dsh --profile headless --patch ./cordis.patch.yml "your task"
pnpm dsh --profile web --patch ./cordis.patch.ymlEnable policy evolution with a benchmark and a dedicated gate profile. The bare headless profile does not mount LCRD, and a generated overlay only targets id: lcrd; create the frozen profile once:
dsh plugin --profile lcrd-gate add @deepseek-ai/dsh-base @deepseek-ai/dsh-headless @deepseek-ai/dsh-experimental-lcrd-gateevolveEnabled: true
evolveBenchmarkDir: benchmarks/example
evolvePolicyDir: .lcrd/policy
evolveGateProfile: lcrd-gate
evolveAdmission: reward
evolvePromote: approval
evolveSignificance: offOperator entry points:
pnpm run lcrd:policy -- show
pnpm run lcrd:policy -- noise --benchmark <dir> --profile lcrd-gate
pnpm run lcrd:audit -- --dataset <corpus> --benchmark <dir>
pnpm run lcrd:weight-eval -- --benchmark <dir> --base-runner <cmd> --candidate-runner <cmd>
pnpm run lcrd:checkpoint -- list- Skills are data. Skill bodies are scanned and mounted as prompt text; they cannot write a gate result, a pointer, or an approval outcome.
- Benchmarks and rewards are operator-trusted. The gate executes the task's reward command with
shell: truein the run workspace. A candidate never sees another run's workspace. - Holdout and hard-out are deployment boundaries. They must sit outside every root the model can read. The plugin validates that they are not inside a skill root, but cannot repair a permissive sandbox.
- Promotion is an authority decision. The default is human approval; auto-promotion is not the default and requires statistical evidence.
- No new session events. Notices and policy transitions use existing tool-result/additional-context surfaces and the durable ledger.
- Prompt-level only. Evolution changes skill text, not model weights. Weight work is a separate pipeline; the repository exposes dataset/DPO export, an evaluation base, and a checkpoint registry, not a trainer that updates an API model.
doc/architecture.html is the full reference: layer diagram, request lifecycle, verifier contracts, gate decision tree, store layout, dataset/DPO pipeline, weight-path status, config table, security model, and quality gates. Use it when changing src/evolve/, the protocol text, or the benchmark/storage contracts.
Every request carries the pinned three-symbol protocol as a system-prompt section, so the contract and verifier rules are present before the first tool call.
Fixed text on every request; it grows only when the protocol wording or PROTOCOL_VERSION changes.
Prefix-stable; the section changes only with the plugin version, so it preserves cache reuse across steps of a session.
The tool exposes goal, stop_condition, feasibility, and a verifier. The verifier expressions are model-authored data; the evaluation program is plugin-owned.
Schema tokens on every request while the tool is registered.
Stable schema; unchanged across steps.
With learningEnabled, the two learning tools join the tool list. lcrd_learn takes problem analysis, needed knowledge, method, and evaluation criteria; lcrd_learn_verify takes learned/evidence. A failed self-evaluation consumes one attempt.
Their parameters ride the tool list while registered; each round adds the declaration, knowledge-acquisition results, and self-evaluation to history.
Append-only; each round follows the reusable prefix and does not invalidate existing cache entries.
On verification failure the result is blocked and a corrective notice names the reason and the required next step: re-declare a different plan, enter learning mode at the threshold, or stop after termination.
One retained context message per failure; the injected reason text is data-dependent.
Append-only; feedback follows the reusable prefix.
The tool exposes rationale, parent_version, and a skills array. Its description states the order (static scan, gate, approval) and asks the model to read returned hints before repeating a rejected idea. The model authors skill text and nothing else.
Schema tokens on every request while evolution is enabled, plus the proposal and its result. Gate children run in separate sessions and never enter this conversation.
Stable schema; the proposal result is appended after the reusable prefix.
- Policy evolution changes skill text only; it does not change weights, so its ceiling is what a better prompt can buy.
- Learning is in-session and is never persisted or reused across sessions; the evaluation criteria are model-authored, and the real verdict is the exogenous re-solve.
- The gate is small-sample by default.
evolveSignificanceis off by default;bootstrapis opt-in and can reject a real gain at small n. Keepapprovaluntillcrd:policy noiseshowsminDetectableGain <= evolveMinGain. - Headroom and detectability are separate:
detectabilityis sample resolution;headroom = 1 - baseline.rewardRateis the maximum possible gain. A gate aborts before the candidate when headroom is belowevolveMinGain. - A missing reward under
evolveAdmission: rewardis incomplete evidence, not a pair to drop; baseline missing writes a baseline-onlygate-abortedreport, candidate missing writes a full abort report. - The termination and speculative-cheat thresholds are zero-tolerance policy rules, not hypothesis tests; a 2-vs-0 count can fail the gate while Fisher's exact test is not significant.
- Static checks are heuristics and can be paraphrased around; the real defenses are "skills are data", the exogenous verifier, and human promotion.
- Holdout and hard-out isolation is a deployment responsibility; the plugin validates only that they are not inside a skill root.
- File sandboxes in
workspace-writemode need the task-flow root inside the writable workspace; setlogDirunder the workspace or allow it in the sandbox. - The
assertverifier uses a restricted expression grammar (src/expr.ts);this, function construction, regex literals, dynamic import, and loops are not expressible. - Rejected-edit feedback is best-effort, bounded to the newest 20 records; an append/read failure never blocks a proposal.
- The online monitor folds runs at agent disposal; a one-shot process that exits without disposing an agent observes nothing.
- The
./invariantcompanion observes the durable policy store and live skill registry; it is not a substitute for deployment-level isolation. - Weight training is not implemented in this package. The DPO export and the
training/scaffold are preparation; an open-weight model and GPU are required for an actual update.
src/anchor.ts owns the protocol wording and PROTOCOL_VERSION; raise the version whenever that wording changes. Policy evolution lives under src/evolve/: store.ts owns the pointer CAS and quarantine, holdout.ts the rotating draw, static-check.ts the pre-gate rules, gate.ts/launch.ts the admission run, brief.ts the review page, monitor.ts the online revert, and invariant.ts the durable relationship checks. The detailed lifecycle and storage contracts are in doc/architecture.html.