
Deadlatch
io.github.Diabloluo由 GitHub 帳號 Diabloluo 發布v0.1.2更新於 Oct 28, 2026
Local advisory pre-trade risk gate for agents. Never places orders.
概覽
本機、僅供建議的盤前風控閘門,讓助理在下單前依 YAML 策略判斷某筆訂單是否被允許。
- 可以做什麼
- 依 12 條規則評估單筆訂單,回傳 PASS、WARN 或 BLOCK 結論及退出碼、命中規則與證據
- 讀取帳戶狀態:快照新鮮度、權益、現金、損益、回撤與曝險使用率
- 唯讀檢視目前生效的策略與熔斷開關模式
- 列出本機稽核日誌中的近期決策,可依時間或筆數篩選
- 也可透過 Python 函式庫或命令列執行相同檢查,並離線遷移舊版訂單、策略與持倉文件
- 適用情境
- 適合已有訂單意圖或模擬執行流程、希望多加一道獨立且確定性的盤前閘門並保留本機稽核紀錄的團隊。也適合想用自己掌控的純 YAML 策略檢核訂單,而非依賴券商自身規則的人。
- 執行需求
- 以本機 stdio 程序執行,透過 uvx 或 pip 安裝 PyPI 上的 deadlatch 套件啟動。啟動時必須提供策略 YAML 與持倉 JSON 檔案,稽核路徑與熔斷開關路徑為選用。持久化稽核寫入僅支援 Linux 與 macOS。不需要帳戶憑證、API 金鑰或網路存取。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 Deadlatch,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
Deadlatch
The pre-trade latch for your trading agent. Advisory-only.
Three things you need to know before anything else:
- You need an independent, cross-broker gate that you control. If an agent can place orders on your account, the last check between the agent and the broker should not be the agent itself — and it should not be locked to one broker's UI or rules.
- Deadlatch does not predict, does not recommend, and does not place orders. It answers one question only: is this order allowed right now? It is not a signal generator and it is not a broker.
- Every answer comes with reasons, evidence, and a local audit record on Linux/macOS. PASS / WARN / BLOCK is never a bare verdict — you can see which rule hit, why, and what was evaluated. Durable audit writes (
init/append/repair/prune/ shadow report) are supported on Linux and macOS only. On Windows the package still imports, and the rule engine / Guard / CLI / MCP still compute decisions; those write paths fail closed withaudit_platform_unsupported. Offlineverify/readof a stopped snapshot remain available. Windows MCP is a limited integration path, not a full trusted audit chain.
Honest boundary (please read): Deadlatch is advisory. It cannot force an agent that never calls it to call it, and it cannot stop an agent that ignores a BLOCK from submitting the order somewhere else. Whether the agent calls the guard and honors the result is the integrator's decision. Do not rely on this tool as a guarantee against loss — it is a gate, not an insurance policy.
- License: MIT — see LICENSE.
- 中文文档: README.zh-CN.md
- Security: SECURITY.md · Contributing: CONTRIBUTING.md · Disclaimer: DISCLAIMER.md
Start here
The current install path is the verified
PyPI deadlatch==0.1.2,
published on 2026-09-22. The stable GitHub v0.1.2 Release
targets b072e8a4d4b053e1d5a428dbb9c47e06652fbf4c; its wheel/sdist assets match the PyPI originals.
The published MCP Registry name is io.github.Diabloluo/deadlatch at version 0.1.2,
verified active/latest on 2026-09-22. The local server.json matches that published version.
The command below starts the verified PyPI package directly.
MCP-first start:
--policy and --portfolio are required local files. --audit-path and --kill-switch-path are optional. Use fictional or your own simulated inputs only. Deadlatch is advisory-only: it never places orders and cannot stop an agent that never calls it. Option orders must use the broker's unique full contract code as symbol. A historical GitHub pre-release remains at v0.1.0.dev1; it is not the current install path.
Then:
- Run a fictional-data Quick Start below (Python, CLI, or MCP) on Linux or macOS. Confirm
PASS→BLOCK→ local audit. Windows can import the package and run rule computation; it is not the audit-write Quick Start. - Request a 20-minute integration assessment only if you already have an order-intent or simulated execution path: open the assessment form.
That GitHub issue is public. Do not paste accounts, positions, orders, API keys, tokens, customer names, or private paths. Security defects must go through GitHub Security Advisories, not a public issue.
Quick Start (60 seconds each)
All three quick starts use fictional data and a temporary audit path. They are executed from the same source scripts by the test suite, so they cannot drift from the documentation. Full audit-write / MCP Quick Start requires Linux or macOS. Windows may import the library and evaluate rules; it will not initialize or append a durable audit collection.
1. Python API
Shows Guard.from_policy(...) → Order / Portfolio → guard.check(...):
a valid order returns PASS / 0; an oversized order returns BLOCK / 3 with the
hit rules; on BLOCK the example caller stops — no broker call is ever made.
2. CLI
Creates fresh inputs in a temp directory (dynamic timestamps — never goes stale),
then runs deadlatch check for PASS (exit 0), BLOCK (exit 3), an input
error (exit 4), and a --json check, plus shadow report --json over the audit.
3. MCP (stdio)
Starts deadlatch-mcp as a real subprocess over stdio, lists the five tools,
and calls check_order once for PASS and once for BLOCK. policy / portfolio /
audit paths are server startup configuration — an agent cannot swap them as
tool arguments. BLOCK is a constraint the caller must honor; technically the guard
cannot force a fully bypassing agent to call it.
What it is / is not
Who should use it
- Teams that already have an order-intent or simulated execution path and want an independent, deterministic pre-trade gate with a local audit trail.
- Developers who want a small, dependency-light, fail-closed building block they can integrate into their own execution pipeline.
- Anyone who wants to evaluate orders against a policy they control, expressed as plain YAML.
Who should not use it: anyone expecting a profit guarantee, a backtest engine, a portfolio manager, or a tool that enforces itself. If the agent never calls the guard, or ignores a BLOCK, nothing in this repository can stop it.
Core security boundary
- Local: everything runs on your machine; no account credentials are ever stored, read, or transmitted.
- No network core path: the library, CLI, and MCP server never open a socket, never register an HTTP/SSE route, and never call out for quotes or anything else (the MCP SDK's HTTP stack is a transitive dependency that business code never imports).
- Never places orders: the core package (library, CLI, MCP server) has no broker connectivity and never submits orders. Experimental read-only mapping examples exist only in the development workspace; they are not included in the public candidate or the wheel, and they are not live-verified integrations.
- Fail-closed: missing or malformed data → BLOCK (
exit 3); input/config errors →exit 4; internal errors →exit 5. An uncertain state is never reported as PASS. - Direction is snapshot-derived: order-side text is never accepted as proof of a
close. Stock and option closing intent is recognized only when a fresh portfolio
snapshot contains a matching, opposite-side position with sufficient quantity.
For options,
symbolmust be the broker's unique full contract code; never reuse an underlying ticker across different expiries, strikes, or rights. - USD-only (v0.1): any currency mismatch (order, portfolio, positions) is an
input error (
exit 4); the MCP account-status tool fail-closes on mismatch.
Write surface: the tool never modifies policy, portfolio, or
kill-switch state, never connects to a broker, and never places an order.
Two kinds of intentional local file writes exist:
- Audit subsystem:
Guard.check()/check_orderappend one sanitized v2 record to a UTC day shard next to the logical audit path (30-day retention). Append is a bounded tail write under a shared lock; it does not rewrite history. A new collection needs one explicitdeadlatch audit init(orinitialize_audit_state) before append; Guard/MCP never auto-migrate.deadlatch shadow reportanddeadlatch audit prunedelete whole shard files that fall outside the 30-calendar-day window.deadlatch audit repair --quarantinestill uses lock/tmp files andos.replacewhen it isolates a truncated tail. Ordinary append is not crash-atomic across files. POSIX locks are cross-process. v0.1.2 durable audit writes are Linux/macOS only; Windows writers receiveaudit_platform_unsupportedand do not skip directory fsync to report success. - Explicit migration output:
deadlatch migrate --output <file>writes the migrated document only when you explicitly pass--output.
The public contract for these rules, Decimal thresholds, exit codes, and option-symbol requirements is docs/rules-spec.md.
The 12 rules (v0.1)
Optional rules (R3–R7) are toggled by their config keys in policy.yaml; a missing
optional key must be declared in acknowledged_disabled or the policy is rejected
(exit 4). Mandatory rules (R1, R2, R8–R12) can never be disabled.
Exit codes
In shadow mode the internal verdict is recorded (shadow_verdict) while the
external projection is PASS / 0; kill-switch hits and exit 4/5 are never
projected away.
Data contracts & migration
Schemas are versioned JSON Schema 2020-12 files shipped inside the package:
order, portfolio, policy, result, audit-record, shadow-report,
audit-maintenance-result, audit-prune-result, audit-write-state,
audit-state-result.
Explicit offline migration is available for legacy documents:
Migration converts only adjudicated fields (e.g. policy v1 boolean kill switch →
off/full); it never guesses business fields. Normal evaluation entries reject
old versions (exit 4) rather than silently migrating.
Audit log
Every Guard.check() appends one v2 record to a UTC day shard beside the
logical path (default ~/.deadlatch/audit.jsonl, overridable via
--audit-path / DEADLATCH_AUDIT_PATH). A new collection must be initialized
once with deadlatch audit init / initialize_audit_state before append;
missing state refuses the write and does not scan the directory to rebuild it.
Pre-v0.1.2 single files remain readable as legacy v1. Records are
schema-validated and sanitized (no credentials, cookies, or absolute paths in
plaintext). Retention is 30 calendar days of shards; append no longer
rewrites history. The UTC shard date is decided after the collection lock is
held (default clock or explicit now). A durable write-date watermark
(audit.jsonl.state.json) refuses any earlier UTC day after a later day has
been reserved, including gaps of 30/365 days; original log and state bytes
stay unchanged. The watermark is sequential control, not a signature.
evaluated_at is not rewritten. Use deadlatch shadow report or
deadlatch audit prune to delete expired shards. Legacy files are not
auto-deleted. If the audit write fails, the returned result is degraded
severity-only-up: PASS/0 → WARN/2; BLOCK/3/4/5 keeps its decision and
just attaches an audit_write_failed warning — the disk and the returned
Result never contradict each other. See
docs/audit-write-state.md.
v0.1.2 records carry a local SHA-256 hash chain (prev_hash /
record_hash). The chain is tamper-evident, not a digital signature and
not tamper-proof. An attacker who can rewrite the whole directory and
recompute hashes is out of scope. Without an external immutable anchor,
deleting the current last record or the whole visible set is not reliably
detectable from the chain alone.
deadlatch audit verify scans the visible collection (legacy plus UTC
shards in the 30-calendar-day window and any future shards prune keeps)
without changing contents or writing quarantine. Expired shards may remain
unpruned and are not part of that chain check. For an existing collection
it may create a .lock sidecar so it can share the same lock as
append/repair/prune. Damaged legacy v1 lines can still be isolated with
deadlatch audit repair --quarantine. v2 repair only isolates a truncated
last line of the last shard; hash mismatches, duplicate IDs, version
downgrades, and mid-chain damage refuse automatic relink (exit 3, no
writes). Shadow report and MCP recent_decisions read the same snapshot
under the same lock and verify hashes, chain links, duplicate IDs, and
version location before returning records; a tampered or downgraded chain
is not presented as trusted history. v1 compatibility is limited to the
legacy baseline file and only before any v2 record — a v1 line in a UTC
day shard is refused. See
docs/postmortem-option-direction.md
for a fictional explanation of the G1 option-direction fix.
MCP server
deadlatch-mcp is a stdio-only MCP server (no TCP listener, no
HTTP/SSE routes). The five tools are read-only: none of them can modify
policy, portfolio, or kill-switch state (those paths are startup
configuration, not tool arguments). Policy changes are validated and loaded
automatically on the next tool call. An optional independent kill-switch file is
read on every call and can only make the policy more restrictive. Note the server still appends each
check_order evaluation to the local audit log — that is by design, not a
tool capability. Five tools:
Start it with:
The path arguments are startup configuration only; their file contents remain
live local state. A configured kill-switch file must contain exactly off,
reduce_only, or full. It cannot weaken a stricter mode already present in the
policy. A missing, malformed, or concurrently unstable live policy/switch fails
closed: tool errors are isError=true + fail_closed, and configuration errors
carry input_error=true + exit_code=4.
Demo
An agent calls check_order with an oversized order; the guard returns
BLOCK / 3 with the hit rules; the agent stops instead of calling any broker
tool. Generated from a real local MCP stdio run with fictional data
(tools/make_demo_gif.py):
Known limitations (v0.1)
- Naked short-call upside risk is unlimited. v0.1 uses a strike-based exposure approximation and does not model that unlimited tail; do not treat it as a conservative bound for short calls.
- Short-sell cash outflow is modeled as
0(documented simplification). - No Greeks, IV, multi-leg strategies, or multi-currency books.
- Audit cross-process locking relies on POSIX
fcntl; on non-POSIX platforms the lock degrades to a process-local lock (no cross-process guarantee). - Durable audit writes in v0.1.2 are supported on Linux and macOS only. Windows
and other platforms refuse
init/append/repair/prune/ shadow report withaudit_platform_unsupportedbefore creating locks or writing state. File and directoryfsyncfailures on supported platforms stay fail-closed; they are not treated as “capability missing”. Offline verify/read of a stopped snapshot remains available. Concurrent Windows writers are out of scope. - The guard cannot prevent complete bypass: an agent that never calls it, or that ignores a BLOCK and calls the broker directly, cannot be stopped by this tool.
- Examples in the repository use fictional tickers and data only.
Governance
- SECURITY.md — supported versions, vulnerability scope, reporting.
- docs/rules-spec.md — public 12-rule contract.
- CONTRIBUTING.md — environment, test/schema/scan/coverage commands, rule discipline.
- DISCLAIMER.md — full legal/risk disclaimer (summary below).
- README.zh-CN.md — 中文文档.
Disclaimer (summary): not investment advice; no guarantee against losses; verify inputs and rules yourself; the guard never places orders; all examples are fictional; test before trading real capital; no SLA. See DISCLAIMER.md in full.
來源:README.md,提交 505e976
工具
0版本歷史
2- v0.1.2最新Sep 22, 2026
- v0.1.1Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分