跳过主要内容
P

dsh-diwen

pondsi/dsh-diwen

迪文(Diwen)DeepSeek Harness(dsh)插件:模型自判 + AI↔AI 通讯强制迪文概念坐标(本体↔子代理/多 agent/机械化批处理)。

安装

dsh plugin --profile web add github:pondsi/dsh-diwen

README

dsh-diwen — Diwen (迪文) Concept Coordinate System

Published to npm as diwen. The registry is authoritative — check with npm view diwen version.

中文概要见 说明.md。

What Diwen is: a communication language for machines

Diwen is a machine-verifiable concept coordinate system for agent-to-agent exchange: the deterministic content in natural-language↔machine interaction, and machine-to-machine interaction.

Natural language is ambiguous and drifts; Diwen anchors meaning to discrete concept coordinates (S3a semantic field × S3b construction), so machines can align precisely, and each concept renders back to a unique canonical Chinese definition. Diwen is not a translator and does not generate prose; it is a verifiable semantic intermediate representation above natural language.

The two mapping directions (asymmetric by design)

  • Natural language → Diwen is NOT unique, and may be unreachable. A word can carry several senses (polysemy), so mapping needs model word-sense disambiguation (WSD) — it is not mechanical (Axiom ②). When no concept fits, Diwen does not guess or force a nearby concept: the original text is preserved verbatim (Axiom ④). Unreachable is a first-class, honest outcome.
  • Diwen → natural language IS unique and deterministic. Each concept renders to exactly one canonical Chinese definition (Axiom ①), machine-verifiable, zero drift. Determinism is the invariant.

What's new in 6.15.0 (2026-11-23)

  • Full-lexicon curation completed: 264,723 source words curated; concept inventory grew from 64,166 → 218,419 across 194 semantic fields. All growth enters the bulk / semanticApproval=false tier — passing mechanical validation ≠ semantically approved.
  • Matcher defect fixed (greedy consumption without backtracking): newly added non-word surfaces (e.g. 不退/我身/小女) could consume text, be dropped by the segmentation filter afterwards, and leave the covered word unreachable (worst case: a whole sentence mapping to nothing). Fixed by moving the compound/boundary checks into candidate selection so a rejected candidate falls back to shorter ones. Compound-level accuracy 0.9369 → 0.9660 (same original gold).
  • Simplified/Traditional surface ownership fixed: 22 duplicate concepts created from variant spellings (進入/进入, 歡呼/欢呼, 以微知著/以微知着 …) were removed (Axiom ⑤: spelling variants do not create new concepts); 10 regionally distinct words (社群/社区, 影片/视频, 月台/站台 …) keep two concepts, with surface forms owned by the word itself. Regression invariants now enforce “a newer concept may never take over an existing form” and “simplified/traditional packs must agree”.
  • Field gate tightened from max(100000, 70%) to max(2000, 45%) (documented re-specification, not a silent loosening). abstract1 (the explicit unverified field pool) is 40.5%.
  • Field-provenance tiers are published (see Status) instead of a single “unverified” number.

Use cases — and the measured benefit in each

Benefits are measured, not advertised: token counts use real cl100k_base BPE (npm run benefits); accuracy comes from blind WSD evaluation; semanticApproval=false throughout. Token savings are relative to natural-language definitions / disambiguation, not bare Chinese words.

ScenarioWhat Diwen addsMeasured benefit
Multi-agent collaborationAgents exchange concept coordinates instead of re-describing meanings in ambiguous NLA concept reference costs 2.86 tokens (coordinate) vs 10.98 (NL definition) = −73.9%; by id 1.71 tokens = −84.5% (852 mapped senses, real cl100k_base BPE). Sense alignment: model WSD 0.9923 (qwen4) / 0.9933 (deepseek) concept accuracy (frozen round136 subset)
Sub-agent communicationLead ↔ sub-agents exchange tasks/results as deterministic conceptsSame compact reference; rendering 100% deterministic (full round-trip over the whole inventory, 0 identity / 0 determinism failures)
Deterministic knowledge baseKnowledge anchored to machine-verifiable concepts, not fuzzy textCanonical concept index: id vs lemma −35.3% tokens; coordinate vs definition −73.9%
Context summaries / promptsCompressed meaning carried as concept coordinates, stable across modelsCompact concept references (−78–88% vs definitions); stable canonical rendering across turns/models
Error correction (any NL→Diwen)Model WSD picks the right sense; honest abstention otherwisePolysemous mapped words: mechanical 0.192 → ~0.99 with WSD (≈+80pp); verbatim abstention recall 0.9931 / precision 0.9983 → no fabrication
Real-time / localLocal decision models, sub-second; deterministic render instantd3:4b 0.09s, clef-flash 0.16s, clef 0.45s per example; cloud cascade routes easy cases to a small model

Honest caveats: token savings are vs NL definitions, not raw sentences; coverage is <100% by design (Axiom ④); model accuracies are measured on frozen holdout / pressure subsets, not arbitrary real-world text; most of the 218k inventory is machine-curated and not semantically approved.

Status: Chinese is deliverable (zh + zh-TW)

Scale: roughly 218k concepts across 194 semantic fields, of which 3,200 carry a renderable glyph (visual band s3a ≤ 127, fully filled) and the rest are glyphless, sharing the default glyph (exact counts ship inside the npm package). Surface packs zh (simplified) and zh-TW (traditional) both cover every concept (each concept reachable; the two packs agree on every shared form). Frozen gold: 2889 sentences / 1024 senses; frozen holdout 116. Private Diwen extension supported (user concepts, id ≥ 699051).

Evaluation, stated at its proper strength:

MetricValueBasis
Compound-word mapping accuracy (C1)0.9660206 real-domain compound cases, mechanical longest-match, original gold
Single-character baselinebelow 0.766same cases; gate requires compound − single > 20pp and passes
Full-gold mechanical lower bound0.2111 (610 correct / 407 overMap / 483 underMap)2889-sentence gold; this is the disclosed mechanical lower bound, not the production path; it moved 0.2253 → 0.2125 → 0.2111 across the expansion and the matcher fix (Δ within the ±0.76pp binomial noise; the C1 gain is significant)
Blind WSD (qwen4 / deepseek)0.9923 / 0.9933frozen round136 polysemy subset, zero leakage; unchanged lexicon-independent measurement
Local decision models (d3 / clef-flash / clef)0.9267 / 0.9467 / 0.96same subset, --ask --choice
Dual-source confirmation82.4%curated words ∩ chinese-xinhua dictionary

Current data state (round223 — supersedes older figures elsewhere in this file):

QuantityValueNote
Concepts218,365193 semantic fields; abstract1 is empty
Verified content senses215,450100% of all content senses
Draft-layer senses0fully adjudicated (round225) + three-family review (round226)
Withdrawn (archived) senses875invalid/adjudicated-out

In round225 the entire draft layer (1,480 senses) was adjudicated one by one: 1,038 judged correct, 320 re-glossed from Xinhua, 122 withdrawn. Those recoveries carried confidence: medium. In round226 all 2,761 of them were then put through a three-family blind review (gemma3:12b / qwen3:8b / Qwen3.6-35B): 2,457 reached 2-of-3 endorsement and were promoted to confidence: high, 304 failed (295 withdrawn, 9 kept with completed definitions). The draft layer is empty.

Definition-layer quality — two independent measurements:

BatchnDefect rateCI95Note
round222 pilot (single-sense stratum)1,2504.48%[3.33%, 5.63%]narrowed 5.7× vs the earlier 50-case pilot
round226 standing audit (all strata)3002.67%[0.84%, 4.49%]zero defects in the single-sense stratum (n=198); all 8 defects were sibling-duplicate or leftover meta-comment

The standing audit is codified in docs/AUDIT-CADENCE.md: 300-case stratified sampling on every data change, targeted at keeping the defect-rate CI within ±2pp.

Field-tag provenance — every concept now carries a calibrated precision figure in roots[].field_note, measured either on a held-out split or on a blind adjudication sample:

Precision bandShareSource tiers
≥85%88.7%curated (100%) · inferred_nb_hi (92.1%) · inferred_nb_v1 (85.5%) · ens2_all3 (90.9%) · ens2_def_eq_xin_m4 (89.5%) · ens4_mid_confirm (87.1%)
75–85%5.5%ens_def_xinhua (85.0%) · ens2_nox_def_eq_struct (82.3%) · inferred_nb_std→ens4_std_keep (77.0%)
<75%5.7%12,514 concepts — hard field labels for these are provably unreliable; each carries a conformal candidate set instead (see below)

Why hard labels cannot work for those concepts (round228). By the Bayes error bound, no classifier can beat $R^* = E_X[1 - \max_y P(Y=y|X)]$. Estimating $R^$ from the ensemble posterior (soft-label method, arXiv:2505.20761) gives $\hat R^ = 60.1%$ on the low-confidence pool — i.e. a hard-label accuracy ceiling of 39.9%, versus 62.5% on curated data. So the 65.3% / 57.4% tags there are not a tuning problem; they sit near a mathematical ceiling.

The replacement: conformal candidate sets. Using weighted split conformal prediction (arXiv:2107.07511 + Tibshirani et al. 2019 for covariate shift), calibrated on 68,271 hand-curated concepts with $\alpha=0.10$ and a density-ratio correction (domain classifier: curated vs low-confidence pool):

QuantityValue
Nominal coverage90%
Measured on 146 hand-judged hard cases — unweighted71.9% (95% CI [64.6, 79.2]) — fails the guarantee
Measured on the same 146 — weighted87.0% (95% CI [81.5, 92.5]) — CI contains 90%
Average set size (weighted)8.13 of 20 fields

This is the honest version of the round228 claim. Round228 reported 98.5% coverage measured on a curated holdout; on genuinely hard cases the unweighted method collapses to 71.9% and only the weighted version restores the guarantee. Each low-confidence concept carries fieldSet, fieldSetSize, fieldSetCoverage, and fieldConformal (method, α, q̂, density-ratio record, both coverage measurements). field is the highest-posterior member for single-value lookup only.

Multisense duplicate cleanup (round229). Scanning sibling senses in the Dice 0.35–0.50 band surfaced 84 candidate pairs; 41 were true duplicates and were merged (keeping the more informative definition), 18 were judged genuinely distinct. A standing 300-case audit then found 8 more multisense duplicates, of which 5 were merged and 3 confirmed distinct (爆炸性 property-vs-figurative, 主体 legal-vs-philosophical, 钓鱼 angling-vs-phishing). Multisense defect rate is 12.1% (n=66) and single-sense is 0% (n=198) — the remaining quality gap is concentrated entirely in polysemy, not in definition fabrication. There is no uncalibrated weak tier left. The former inferred_nb_lo/mid/std pool (34,024 concepts at 39.4%/57.4%/77.0%) was re-adjudicated in round223 with a four-source ensemble (Chinese definition / Xinhua gloss / NSM+structural / English lemma); a 150-case blind spot-check on that pool measured 66.7% ±7.5, so adoption was made per tier from measured evidence rather than uniformly — lo fully re-predicted (39.4%→65.3%), mid confirmed only where the ensemble agreed with the existing tag (87.1%) and left untouched otherwise, std left untouched because no new rule beat its 77.0%. Net effect: ≥85% share 84.4% → 88.7%.

Fifth evidence source (round226) — the Harbin Institute of Technology Tongyici Cilin (extended) was added: a hand-curated synonym taxonomy whose codes group words into semantic classes. Its best rule (four-source agreement ∩ Cilin class) measured 86.7% on a curated holdout. It lifted 1,042 low-confidence fields, moving the <75% band from 6.2% → 5.7%. Cilin is used only as a local inference input and is not redistributed with this package.

Multi-family review of recovered senses (round226) — the 2,761 senses recovered in round225 carried only confidence: medium. All 2,761 were re-reviewed blind by three families (gemma3:12b / qwen3:8b / Qwen3.6-35B): 2,457 reached 2-of-3 endorsement and were promoted to confidence: high; 304 failed (295 withdrawn, 9 kept after their truncated definitions were completed).

Field-tag provenance (method history) — abstract1 pool = 88,515 (40.5%) at the time this table was written:

TierCountMeaning
T1 two-family agreement (written)28,208local curator family + independent cloud family agreed (unambiguous)
T2 self-label confirmed by cloud9,606curation-time label confirmed by an independent cloud family re-check — measured agreement 64.3%
2-of-3 majority (third-family vote)2,295two families disagreed, third vote broke the tie
abstract1 = two families say abstract8,174“verified abstract” (kept in the pool, provenance known)
abstract1 = families disagree / no second opinion~81k total poolhonestly marked unverified; not silently promoted

Regression: run-all 720/0 + SELFTEST OK; standalone suites 62/62; MCP selftest 45/45; dsh selftest ALL PASS; Diwen→Chinese round-trip over the full inventory, identityFailures=0 / determinismFailures=0.

Axiom ① (Diwen → unique Chinese definition) is 100% deterministic. When no concept exists, the original text is preserved verbatim (Axiom ④) — nothing is fabricated. semanticApproval=false always holds.

Quick start

This repo is Diwen's open-core public distribution: open loader shell + closed core (minified bundle) + encrypted concept data (AES-256-GCM). npm install diwen pulls whatever version the registry currently publishes.

npm package

npm install diwen
import { mapChinese, describeConcept } from 'diwen';

// Natural language → Diwen fill contract (Axiom ②: model sense selection; Axiom ④: no concept → verbatim)
const r = await mapChinese('我吃饭', { model: 'deterministic' }); // 'auto'|'decision'|'off'
console.log(r.contract.status, r.contract.words, r.semanticApproval); // semanticApproval always false

// Diwen → unique Chinese definition (Axiom ①)
console.log(describeConcept(1223).lemma_zh); // 折

Or use from this repo: cd packages/diwen && npm install, then import locally.

  • model:'decision' uses a local ollama decision model + calibrated abstention; enhance:true enables the enhancement layer.
  • The runtime segmentation dependency @node-rs/jieba is installed automatically.

Private Diwen (add your own concepts)

You can add your own private concepts without touching the public core; they merge into the lexicon and work across mapping / WSD / describe / render. Private concept IDs must be ≥ 699051; glyph coordinates (s3a,s3b) must avoid base concepts (collision-checked at load).

diwen private template -o my-private.json    # scaffold
diwen private free-coords 20                 # list free coordinates
diwen private validate my-private.json       # validate partition / collisions / schema
export DIWEN_PRIVATE_LEXICON=my-private.json  # load

Set DIWEN_PRIVATE_CANDIDATES for private WSD senses. Your private file is your own data (plain JSON, not uploaded/redistributed). See docs/PACKAGE-USAGE.md §5.

Character-level glossary service (L0 meanings)

Per-character meanings, semantic classes, IDS composition and 六书 come from public-domain dictionaries (Kangxi, Shuowen, Jiyun, Longkan), kept physically separate from the concept ontology. Where no gloss exists the field stays empty — nothing is fabricated (semanticApproval=false).

diwen char 水                                  # one character: gloss, class, IDS, liushu, page refs
diwen find --radical 水 --gap --format csv --out gap.csv   # export: tsv / csv / jsonl / json
diwen serve --port 7788                        # HTTP: /health /stats /char/<char> /find?...

find exports never truncate silently: without --limit an export writes all matches, and CSV carries a UTF-8 BOM so Excel opens Chinese correctly (--no-bom to disable). Endpoints page with offset/nextOffset; responses are cached in-process (LRU + ETag, 304 on If-None-Match) and every response carries schemaVersion (body + x-schema-version header) — currently 1.0.0, frozen by shape snapshots in tests/snapshots/api/. JSON is compact by default; pass pretty=1 for indented output. API reference: docs/api/index.html (generated from src/api-spec.mjs). Benchmarks: npm run bench:serve / bench:find / bench:pretty.

Coverage is reported on two scopes, never merged: main table 26,720 chars / 99.57% glossed (BMP + Ext-A), extension scope 28,280 chars / 60.45% (Ext-B and beyond). Semantic anchor rate is 100.00% but as an anchor only — it is the union of gloss and radical class, not a gloss.

find walks a prebuilt inverted index (semantic class / radical / phonetic / composition / 六书 type / 六书 source). A single-axis query costs O(matches) instead of O(55,000): 0.004–0.01 ms per query versus 5–24 ms for the previous full scan, and multi-axis queries are 12–18× faster (docs/bench-find.json, paired in-process sampling). Results are byte-identical to the scan — tests/find-index.mjs diffs 400 random filter combinations against the old implementation.

MCP server (core via npm diwen)

npm install diwen-mcp
npx diwen-mcp

Configure your MCP client with command=node, args=[<absolute path>/diwen-mcp/server.mjs]; 3 tools: diwen_map, diwen_describe, diwen_select. Self-test: node packages/diwen-mcp/selftest.mjs (45/45).

DeepSeek Harness (dsh) plugin

Cordis shell + npm diwen core + deterministic force layer (diwen-dsh@0.3.2): registers diwen_map/diwen_describe + skill diwen; force-layer seams each have settings toggles (forceSystemPrompt/forcePreStep/forcePostExecute). See docs/DSH-FORCE-USAGE.md.

Data artifacts in the private repo

Large data files (ontology OWL, YAML export, roots, bulk candidates — each ≥ 40 MB) exceed GitHub's per-blob API limit, so they are published gzipped with a SHA256 manifest. After cloning the source repo:

node scripts/unpack-data.mjs     # verifies SHA256 and restores data/roots.json etc.

The npm package ships its own encrypted data.enc and needs none of this.

Manuals

Repository layout

packages/diwen/       npm package: index.mjs/env.cjs open shell + dist/core.mjs closed core + dist/data.enc encrypted data
packages/diwen-mcp/   MCP server (open shell, reuses closed core)
packages/diwen-dsh/   dsh plugin (Cordis shell + npm diwen core + force layer)
docs/                 usage manual, integration guide, dsh force layer
说明.md               Chinese overview
LICENSE               license

License

Commercial use permitted (free, no separate authorization), redistribution permitted, attribution required: credit Diwen / 迪文 + author Pondsi + repository link. Full terms in LICENSE.

Limitations

  • Deliverable scripts: Simplified Chinese (zh) + Traditional Chinese (zh-TW) sharing the same concept coordinates. The other 25 languages remain roadmap (Axiom ⑤: language-independent mapping, no pivot).
  • Coverage is not 100% (by Axiom ④ design); words without a concept are preserved verbatim, never fabricated.
  • Most of the 218k concepts are machine-curated (semanticApproval=false): the mechanically enforced invariants (id contiguity, form ownership, cross-pack agreement, field-share gate, round-trip determinism) bound the data’s consistency, not its semantic truth. Semantic approval is a separate, slower process.

Author: Pondsi · https://github.com/Pondsi/dsh-diwen

相关插件