dp-worker 0.1.29 → 0.1.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/builtin-skills/bilibili.md +57 -0
  2. package/builtin-skills/douyin.md +54 -0
  3. package/builtin-skills/linkedin.md +52 -0
  4. package/builtin-skills/weibo.md +61 -0
  5. package/builtin-skills/xiaohongshu.md +55 -0
  6. package/builtin-skills/zhihu.md +55 -0
  7. package/dist/agent/skill-generator.js +63 -0
  8. package/dist/agent/skill-generator.js.map +1 -1
  9. package/dist/browser/account-health.d.ts +16 -0
  10. package/dist/browser/account-health.js +33 -4
  11. package/dist/browser/account-health.js.map +1 -1
  12. package/dist/browser/dom-helpers.js +31 -3
  13. package/dist/browser/dom-helpers.js.map +1 -1
  14. package/dist/browser/page-outline.js +9 -1
  15. package/dist/browser/page-outline.js.map +1 -1
  16. package/dist/browser/selectors.d.ts +33 -0
  17. package/dist/browser/selectors.js +137 -0
  18. package/dist/browser/selectors.js.map +1 -1
  19. package/dist/browser/workspace-lock.js +64 -3
  20. package/dist/browser/workspace-lock.js.map +1 -1
  21. package/dist/chrome-extension/omni-flow/manifest.json +1 -1
  22. package/node_modules/dp-shared/dist/auto-post-contracts.d.ts +48 -0
  23. package/node_modules/dp-shared/dist/auto-post-contracts.d.ts.map +1 -1
  24. package/node_modules/dp-shared/dist/auto-post-contracts.js +62 -0
  25. package/node_modules/dp-shared/dist/auto-post-contracts.js.map +1 -1
  26. package/node_modules/dp-shared/dist/bird-contracts.d.ts +8 -0
  27. package/node_modules/dp-shared/dist/bird-contracts.d.ts.map +1 -1
  28. package/node_modules/dp-shared/dist/bird-contracts.js +19 -0
  29. package/node_modules/dp-shared/dist/bird-contracts.js.map +1 -1
  30. package/node_modules/dp-shared/dist/configs-contracts.d.ts +4 -0
  31. package/node_modules/dp-shared/dist/configs-contracts.d.ts.map +1 -1
  32. package/node_modules/dp-shared/dist/configs-contracts.js +18 -0
  33. package/node_modules/dp-shared/dist/configs-contracts.js.map +1 -1
  34. package/node_modules/dp-shared/dist/desk-contracts.d.ts +478 -0
  35. package/node_modules/dp-shared/dist/desk-contracts.d.ts.map +1 -0
  36. package/node_modules/dp-shared/dist/desk-contracts.js +397 -0
  37. package/node_modules/dp-shared/dist/desk-contracts.js.map +1 -0
  38. package/node_modules/dp-shared/dist/identities.d.ts +2 -1
  39. package/node_modules/dp-shared/dist/identities.d.ts.map +1 -1
  40. package/node_modules/dp-shared/dist/identities.js +13 -1
  41. package/node_modules/dp-shared/dist/identities.js.map +1 -1
  42. package/node_modules/dp-shared/dist/index.d.ts +2 -0
  43. package/node_modules/dp-shared/dist/index.d.ts.map +1 -1
  44. package/node_modules/dp-shared/dist/index.js +2 -0
  45. package/node_modules/dp-shared/dist/index.js.map +1 -1
  46. package/node_modules/dp-shared/dist/post-drafts-contracts.d.ts +223 -6
  47. package/node_modules/dp-shared/dist/post-drafts-contracts.d.ts.map +1 -1
  48. package/node_modules/dp-shared/dist/post-drafts-contracts.js +133 -0
  49. package/node_modules/dp-shared/dist/post-drafts-contracts.js.map +1 -1
  50. package/node_modules/dp-shared/dist/promo-contracts.d.ts +183 -23
  51. package/node_modules/dp-shared/dist/promo-contracts.d.ts.map +1 -1
  52. package/node_modules/dp-shared/dist/promo-contracts.js +368 -16
  53. package/node_modules/dp-shared/dist/promo-contracts.js.map +1 -1
  54. package/node_modules/dp-shared/dist/relay-contracts.d.ts +439 -0
  55. package/node_modules/dp-shared/dist/relay-contracts.d.ts.map +1 -0
  56. package/node_modules/dp-shared/dist/relay-contracts.js +362 -0
  57. package/node_modules/dp-shared/dist/relay-contracts.js.map +1 -0
  58. package/node_modules/dp-shared/dist/signal/draft-rules.d.ts +169 -0
  59. package/node_modules/dp-shared/dist/signal/draft-rules.d.ts.map +1 -0
  60. package/node_modules/dp-shared/dist/signal/draft-rules.js +261 -0
  61. package/node_modules/dp-shared/dist/signal/draft-rules.js.map +1 -0
  62. package/node_modules/dp-shared/dist/signal/normalize-metric.d.ts +121 -0
  63. package/node_modules/dp-shared/dist/signal/normalize-metric.d.ts.map +1 -0
  64. package/node_modules/dp-shared/dist/signal/normalize-metric.js +373 -0
  65. package/node_modules/dp-shared/dist/signal/normalize-metric.js.map +1 -0
  66. package/node_modules/dp-shared/dist/signal/signal-score.d.ts +445 -0
  67. package/node_modules/dp-shared/dist/signal/signal-score.d.ts.map +1 -0
  68. package/node_modules/dp-shared/dist/signal/signal-score.js +1922 -0
  69. package/node_modules/dp-shared/dist/signal/signal-score.js.map +1 -0
  70. package/node_modules/dp-shared/dist/signal/validate-draft.d.ts +718 -0
  71. package/node_modules/dp-shared/dist/signal/validate-draft.d.ts.map +1 -0
  72. package/node_modules/dp-shared/dist/signal/validate-draft.js +433 -0
  73. package/node_modules/dp-shared/dist/signal/validate-draft.js.map +1 -0
  74. package/node_modules/dp-shared/dist/signal/weighted-length.d.ts +87 -0
  75. package/node_modules/dp-shared/dist/signal/weighted-length.d.ts.map +1 -0
  76. package/node_modules/dp-shared/dist/signal/weighted-length.js +195 -0
  77. package/node_modules/dp-shared/dist/signal/weighted-length.js.map +1 -0
  78. package/package.json +1 -1
@@ -0,0 +1,261 @@
1
+ /**
2
+ * docB chapter 3 (M / N / O / P / Q / R / S — 74 rules) — **the** rule registry.
3
+ *
4
+ * CONTRACT-FREEZE §C-02: this file's `CHECKS` table is the single source of
5
+ * truth for `rule_id` and `check_id`. `docb-checklist.ts` does not exist; there
6
+ * is exactly one route implementation (`dp-signal/src/routes/internal.ts`) and
7
+ * exactly one registry. dp-center imports this file to *render*; it must not
8
+ * evaluate anything.
9
+ *
10
+ * ## The invariant this file exists to make un-breakable
11
+ *
12
+ * docB states the same judgement in four different places — the rewrite rule
13
+ * "Tapbit View must add information" (P-07), the fourth of the five mandatory
14
+ * questions (A-09), gate D's final adjudication (B-D-06), and judgement-check
15
+ * #8 (Q-08). Four teams reading four sections implement four thresholds, and
16
+ * three months later nobody can say which one fired. Here they are four
17
+ * `rule_ids` on **one** `CheckDef` (`VIEW_INCREMENT`) — one id, one prompt, one
18
+ * threshold, enforced by a test that asserts the four resolve to one check.
19
+ *
20
+ * ## Coverage (the CI gate)
21
+ *
22
+ * `DOCB_CH3_RULES` lists all 74 rules. Every one either
23
+ * (a) appears in some `CHECKS[].ruleIds` — it is adjudicated by the engine, or
24
+ * (b) appears in `EXTERNAL_OWNERS` with a named owner — it is a state-machine
25
+ * step, a stored record, or a dashboard metric, adjudicated elsewhere.
26
+ * The two sets must be disjoint and together must cover all 74. Delete a check,
27
+ * rename an id, or forget to wire a rule and the build fails naming the rule.
28
+ * (b) is what stops "coverage" from being achieved by quietly dropping the
29
+ * awkward rules: a rule can leave this engine only by naming its new home.
30
+ *
31
+ * ## Count note
32
+ *
33
+ * CONTRACT-FREEZE §C-01's prose says "33 checks"; the frozen artifact list is
34
+ * 34 (D0 11 + D1 2 + D2 4 + PROBE 1 + J1 12 + J2 1 + J3 1 + H 2). The registry
35
+ * wins: removing one to reach 33 would leave a docB rule with no execution
36
+ * site. Read the count from `CHECKS.length`, never from prose.
37
+ */
38
+ const check = (id, ruleIds, levels, layer, severity, overridable, label) => ({ id, ruleIds, levels, layer, severity, overridable, label });
39
+ export const CHECKS = [
40
+ /* ── D0 · literal text and structured fields. Zero cost, runs first. ────── */
41
+ check("LEN_WEIGHTED", ["P-11", "Q-12", "X-05"], "all", "D0", "block", false, "X weighted characters ≤ 280 minus the reserved link/tag budget"),
42
+ check("BANNED_LITERAL", ["P-10"], "all", "D0", "block", false, "Banned phrasing, normalised for case / hyphens / zero-width / punctuation"),
43
+ // M-07 belongs here and not in the state machine: "the owner reviews and
44
+ // approves" is only meaningful if the approver is authorised and is not the
45
+ // editor, and both of those are decided from the request, not from a
46
+ // transition. The coverage audit is what noticed it was missing.
47
+ check("APPROVER_AUTH", ["Q-15", "S-07", "M-07"], "all", "D0", "block", false, "Approver is on the authorised list, differs from the editor, and approved_at precedes published_at"),
48
+ check("CAMPAIGN_MATCH", ["Q-14"], "all", "D0", "block", false, "Link domains / tags / CTA match this campaign (no campaign = no links, no tags)"),
49
+ check("MARKET_TUPLE", ["Q-05", "C-I-08"], "all", "D0", "block", false, "Every market datum carries (asset, direction, magnitude, window) and matches the body"),
50
+ check("WATCH_VAR_CNT", ["N-W-03"], ["WATCH"], "D0", "block", false, "Watch variables ∈ [1,2] — an upper bound; writing three is a violation"),
51
+ check("QUANT_PRESENT", ["N-I-02"], ["IMPACT"], "D0", "block", false, "quantitative_data ≥ 1 and every item carries an observation window"),
52
+ check("THESIS_STATUS", ["N-I-04"], ["IMPACT"], "D0", "block", false, "thesis_status ∈ {maintained, strengthened, invalidated}"),
53
+ check("INVALIDATION", ["Q-10", "P-08", "B-A-06"], "all", "D0", "block", true, "Invalidation parses to (metric, comparator, threshold, deadline) and is registered for re-check"),
54
+ check("NUM_BUDGET", ["P-04"], "all", "D0", "warn", true, "Number count within the per-level budget (WATCH/FLASH 2, IMPACT 5)"),
55
+ check("TEMPLATE_SHAPE", ["O-04"], "all", "D0", "warn", true, "Uses the four-part template; a deviation must record its reason"),
56
+ /* ── D1 · fact grounding. Deterministic, and it runs before any judge. ──── */
57
+ check("LEDGER_NUMBERS", ["Q-03", "M-05", "N-F-02", "K-09"], "all", "D1", "block", true, "Every number / unit / time in the draft traces back to the ledger with a matching unit"),
58
+ check("TERM_GLOSSARY", ["Q-03"], "all", "D1", "human", true, "Terminology matches the glossary (core vs headline, YoY vs MoM)"),
59
+ /* ── D2 · cross-document diff against what we already published. ───────── */
60
+ check("UPDATE_LEAD", ["F-05", "P-02"], "all", "D2", "block", true, "An update post leads with the increment and overlaps the previous post below threshold"),
61
+ check("FLASH_DIFF", ["R-03", "H-03"], "all", "D2", "block", true, "Text similarity to already-published posts for this event is below threshold"),
62
+ check("IMPACT_DELTA", ["N-I-01", "R-04"], ["IMPACT"], "D2", "block", true, "Adds a data point or window versus the FLASH (baseline degrades; may be n/a)"),
63
+ check("CONTENT_CLASS", ["F-04", "T-05"], "all", "D2", "warn", true, "≥ 6h since the last post of the same content_class, else reason + approver"),
64
+ /* ── PROBE · network, still no LLM. ────────────────────────────────────── */
65
+ check("URL_REACHABLE", ["Q-02"], "all", "PROBE", "block", true, "Every source URL answers 2xx now; paywall / 403 may be overridden with a trace"),
66
+ /* ── J1 · one call returns every sentence label and span. ──────────────── */
67
+ check("LOGIC_CHAIN", ["O-01", "O-02", "O-03"], "all", "J1", "block", false, "All four components present, first-occurrence order What→Why→Impact→View (literal headings ignored)"),
68
+ check("LEAD_IS_FACT", ["P-02"], "all", "J1", "block", true, "The lead sentence is factual and matches no generic-opening pattern"),
69
+ check("SINGLE_THESIS", ["P-03"], "all", "J1", "block", true, "Exactly one standalone core judgement"),
70
+ check("NO_MIXING", ["Q-06", "M-03"], "all", "J1", "block", true, "Fact / inference / scenario are not mixed inside one sentence without a marker word"),
71
+ check("CAUSALITY", ["P-06"], "all", "J1", "block", true, "Causal connectives require mechanism evidence (the template clause 'This matters because' is exempt)"),
72
+ check("ASSET_EVIDENCE", ["P-05", "Q-07"], "all", "J1", "block", false, "Every named asset is in impact_assets with evidence; four-grid template shape warns"),
73
+ check("NO_DIRECTION", ["N-W-00"], ["WATCH"], "J1", "block", true, "No directional prediction (conditional phrasing is exempt)"),
74
+ check("NO_FAKE_MOVE", ["N-F-05"], ["FLASH"], "J1", "block", false, "No market assertion without a bound data point — including qualitative ones like 'markets reacted sharply'"),
75
+ check("CROSS_ASSET", ["N-I-03"], ["IMPACT"], "J1", "block", true, "Cross-asset transmission / divergence has data on both sides"),
76
+ check("WATCH_VAR_QUAL", ["Q-09", "P-08"], "all", "J1", "block", true, "Watch variables name an observable metric and a time point ('watch the market' fails)"),
77
+ check("TONE_CALM", ["Q-11", "P-01"], "all", "J1", "warn", true, "Calm tone; exclamation marks / ALL CAPS / hyperbolic adverbs under threshold"),
78
+ check("MUST_INCLUDE", ["N-W-01", "N-W-02", "N-W-04", "N-F-01", "N-F-03", "N-F-04", "N-I-00"], "all", "J1", "block", false, "Per-level mandatory elements reconciled between the body text and the structured envelope"),
79
+ /* ── J2 · the ONE implementation of P-07 / A-09 / B-D-06 / Q-08. ───────── */
80
+ check("VIEW_INCREMENT", ["P-07", "A-09", "B-D-06", "Q-08"], "all", "J2", "block", false, "Tapbit View adds information over source headlines and prior posts, with ≥1 D-01..D-05 component"),
81
+ /* ── J3 · compliance. ─────────────────────────────────────────────────── */
82
+ check("COMPLIANCE", ["P-09", "P-10", "Q-13"], "all", "J3", "block", false, "No shilling / FOMO (incl. implicit scarcity and time pressure) / return or direction promises"),
83
+ /* ── H · human confirmation. Not blocking by itself, but must be ticked. ─ */
84
+ check("GATE_A_SNAPSHOT", ["Q-01"], "all", "H", "human", false, "gate_A = true and the ledger diff snapshot was shown and ticked by the reviewer"),
85
+ check("CONTESTED", ["Q-04", "B-B-03"], "all", "H", "block", true, "When contested: ≥ 2 independent sources that pass the independence check"),
86
+ ];
87
+ /** Execution order. A blocking `fail` in an earlier layer short-circuits the rest. */
88
+ export const LAYER_ORDER = ["D0", "D1", "D2", "PROBE", "J1", "J2", "J3", "H"];
89
+ /** The three layers that cost a model call. Named so the short-circuit is greppable. */
90
+ export const JUDGE_LAYERS = ["J1", "J2", "J3"];
91
+ export const CHECK_BY_ID = new Map(CHECKS.map((definition) => [definition.id, definition]));
92
+ /**
93
+ * rule_id → the check ids that adjudicate it.
94
+ *
95
+ * A list, not a single value, because docB genuinely asks for two *layers* on
96
+ * some rules: P-10 wants both the literal banned-word table and a judge that
97
+ * catches the synonyms ("sure thing", "can't lose") — "two layers, both required". P-08 is
98
+ * split between the structured field (INVALIDATION) and its quality
99
+ * (WATCH_VAR_QUAL). Those are not drift.
100
+ *
101
+ * Drift is a rule that states **one** judgement landing on two checks with two
102
+ * thresholds. That case is enumerated in `SINGLE_SITE_RULE_IDS` and asserted.
103
+ */
104
+ export const CHECK_IDS_BY_RULE_ID = (() => {
105
+ const map = new Map();
106
+ for (const definition of CHECKS) {
107
+ for (const ruleId of definition.ruleIds) {
108
+ const bucket = map.get(ruleId);
109
+ if (bucket)
110
+ bucket.push(definition.id);
111
+ else
112
+ map.set(ruleId, [definition.id]);
113
+ }
114
+ }
115
+ return map;
116
+ })();
117
+ export const QCHECKLIST = [
118
+ { q: "Q-01", group: "fact", mode: "human", checks: ["GATE_A_SNAPSHOT"], label: "The event really does contain new information" },
119
+ { q: "Q-02", group: "fact", mode: "auto", checks: ["URL_REACHABLE"], label: "The official or primary source opens" },
120
+ { q: "Q-03", group: "fact", mode: "auto", checks: ["LEDGER_NUMBERS", "TERM_GLOSSARY"], label: "Times, numbers, units and definitions are accurate" },
121
+ { q: "Q-04", group: "fact", mode: "human", checks: ["CONTESTED"], label: "A contested event has the independent confirmation it needs" },
122
+ { q: "Q-05", group: "fact", mode: "auto", checks: ["MARKET_TUPLE"], label: "Market data names the asset and the observation window" },
123
+ { q: "Q-06", group: "judgement", mode: "llm", checks: ["NO_MIXING"], label: "Facts, inferences and scenarios are not mixed together" },
124
+ { q: "Q-07", group: "judgement", mode: "llm", checks: ["ASSET_EVIDENCE"], label: "No cross-asset impact was forced in for completeness" },
125
+ { q: "Q-08", group: "judgement", mode: "llm", checks: ["VIEW_INCREMENT"], label: "The Tapbit View adds value beyond the headline" },
126
+ { q: "Q-09", group: "judgement", mode: "llm", checks: ["WATCH_VAR_QUAL"], label: "The next variables to watch are clear" },
127
+ { q: "Q-10", group: "judgement", mode: "auto", checks: ["INVALIDATION"], label: "The invalidation condition is sound and verifiable (re-check registered)" },
128
+ { q: "Q-11", group: "copy", mode: "llm", checks: ["TONE_CALM"], label: "The English is accurate, concise and calm" },
129
+ { q: "Q-12", group: "copy", mode: "auto", checks: ["LEN_WEIGHTED"], label: "No more than 280 X characters" },
130
+ { q: "Q-13", group: "copy", mode: "llm", checks: ["BANNED_LITERAL", "COMPLIANCE"], label: "No shilling, FOMO, return guarantees or absolute-safety claims" },
131
+ { q: "Q-14", group: "copy", mode: "auto", checks: ["CAMPAIGN_MATCH"], label: "Links, tags and CTA match this campaign's requirements" },
132
+ { q: "Q-15", group: "copy", mode: "auto", checks: ["APPROVER_AUTH"], label: "Approved by the designated owner" },
133
+ ];
134
+ /* ============================================================================
135
+ * The frozen docB chapter-3 manifest and its coverage gate
136
+ * ========================================================================== */
137
+ /**
138
+ * Rules adjudicated somewhere other than this engine.
139
+ *
140
+ * Every entry names its owner. This is the only legal way for a chapter-3 rule
141
+ * to leave the registry, and the reason it is a map rather than a blocklist:
142
+ * "not covered here" has to come with an address.
143
+ */
144
+ export const EXTERNAL_OWNERS = {
145
+ // 三.1 — the nine-step state machine lives with the draft, i.e. in dp-center.
146
+ "M-01": "dp-center pipeline.ts TRANSITIONS — gate A∧B∧C∧D is the only entry",
147
+ "M-02": "dp-center pipeline.ts — event card + ≥1 evidence row",
148
+ "M-04": "dp-center generate.ts — immutable ai_draft revision",
149
+ "M-06": "dp-center pipeline.ts — human_edited revision is mandatory (T-11)",
150
+ "M-08": "dp-center UI — there is no publish action; published comes from backfill",
151
+ "M-09": "dp-signal publish-records.ts recordPublish() + dp-center backfill form",
152
+ "M-10": "dp-signal observe lane — +30/+60/+180 snapshots",
153
+ "M-11": "engine emits pending_reason; the state lock is dp-center pipeline.ts",
154
+ // 三.2 — a dependency-graph property, not a property of one draft.
155
+ "N-F-00": "must-include.ts FLASH_REQUIREMENTS carries no market-data item (asserted by test)",
156
+ // 三.6 — cadence belongs to the trigger engine and the rounds table.
157
+ "R-01": "trigger-engine signal_rounds.selected_event_id (structurally ≤1)",
158
+ "R-02": "ops dashboards — post count may appear only as a denominator",
159
+ "R-05": "event-identity merge / signal_event_merges",
160
+ "R-06": "trigger-engine priority override layer above D-02..D-06",
161
+ // 三.7 — the publish record. Ten fields, written here.
162
+ "S-01": "dp-signal publish-records.ts — event_id + level_snapshot",
163
+ "S-02": "dp-signal publish-records.ts — triggered_at + trigger_reason enum",
164
+ "S-03": "dp-signal publish-records.ts — primary/independent sources split",
165
+ "S-04": "dp-signal publish-records.ts — ai_draft_rev_id incl. model + prompt version",
166
+ "S-05": "dp-signal publish-records.ts — human_edited_rev_id (never null)",
167
+ "S-06": "dp-signal publish-records.ts — published_text + published_text_actual + text_match_int",
168
+ "S-08": "dp-signal publish-records.ts — published_at + anchor kind + x_url",
169
+ "S-09": "dp-signal publish-records.ts — escalated_to_impact tri-state + due date",
170
+ "S-10": "dp-signal publish-records.ts — three flags, written by re-check and post-mortem",
171
+ "S-11": "dp-signal publish-records.ts metric queries + ops dashboards",
172
+ };
173
+ /** All 74 chapter-3 rule ids, frozen. Order follows the document. */
174
+ export const DOCB_CH3_RULE_IDS = [
175
+ "M-01", "M-02", "M-03", "M-04", "M-05", "M-06", "M-07", "M-08", "M-09", "M-10", "M-11",
176
+ "N-W-00", "N-W-01", "N-W-02", "N-W-03", "N-W-04",
177
+ "N-F-00", "N-F-01", "N-F-02", "N-F-03", "N-F-04", "N-F-05",
178
+ "N-I-00", "N-I-01", "N-I-02", "N-I-03", "N-I-04",
179
+ "O-01", "O-02", "O-03", "O-04",
180
+ "P-01", "P-02", "P-03", "P-04", "P-05", "P-06", "P-07", "P-08", "P-09", "P-10", "P-11",
181
+ "Q-01", "Q-02", "Q-03", "Q-04", "Q-05",
182
+ "Q-06", "Q-07", "Q-08", "Q-09", "Q-10",
183
+ "Q-11", "Q-12", "Q-13", "Q-14", "Q-15",
184
+ "R-01", "R-02", "R-03", "R-04", "R-05", "R-06",
185
+ "S-01", "S-02", "S-03", "S-04", "S-05", "S-06", "S-07", "S-08", "S-09", "S-10", "S-11",
186
+ ];
187
+ /**
188
+ * The CI gate. Call it from a test; a non-empty `uncovered` or `doubleClaimed`
189
+ * must fail the build, naming the rule. Deleting a `CheckDef` row, renaming a
190
+ * `check_id`, or adding a docB rule without wiring it all land here.
191
+ */
192
+ export function auditDocbCh3Coverage() {
193
+ const frozen = new Set(DOCB_CH3_RULE_IDS);
194
+ const byCheck = new Set();
195
+ for (const definition of CHECKS) {
196
+ for (const ruleId of definition.ruleIds) {
197
+ if (frozen.has(ruleId))
198
+ byCheck.add(ruleId);
199
+ }
200
+ }
201
+ const byOwner = new Set(Object.keys(EXTERNAL_OWNERS).filter((id) => frozen.has(id)));
202
+ return {
203
+ uncovered: DOCB_CH3_RULE_IDS.filter((id) => !byCheck.has(id) && !byOwner.has(id)),
204
+ doubleClaimed: DOCB_CH3_RULE_IDS.filter((id) => byCheck.has(id) && byOwner.has(id)),
205
+ unknownOwners: Object.keys(EXTERNAL_OWNERS).filter((id) => !frozen.has(id)),
206
+ coveredByCheck: [...byCheck],
207
+ coveredByOwner: [...byOwner],
208
+ };
209
+ }
210
+ /**
211
+ * The four statements of "the View must add information", by rule id.
212
+ *
213
+ * Exported so the assertion "these four resolve to one check_id, one threshold"
214
+ * is a named test rather than a comment somebody deletes.
215
+ */
216
+ export const VIEW_INCREMENT_RULE_IDS = ["P-07", "A-09", "B-D-06", "Q-08"];
217
+ /**
218
+ * Rules that state exactly one judgement and must therefore have exactly one
219
+ * adjudication site. Each entry maps a group of rule ids to the single
220
+ * `check_id` they are all required to resolve to.
221
+ *
222
+ * `VIEW_INCREMENT` is the case docB states four times in four chapters; without
223
+ * this assertion, four implementers produce four thresholds and nobody can say
224
+ * afterwards which one rejected a draft.
225
+ */
226
+ export const SINGLE_SITE_RULE_GROUPS = [
227
+ { checkId: "VIEW_INCREMENT", ruleIds: VIEW_INCREMENT_RULE_IDS },
228
+ { checkId: "LEN_WEIGHTED", ruleIds: ["P-11", "Q-12", "X-05"] },
229
+ { checkId: "LOGIC_CHAIN", ruleIds: ["O-01", "O-02", "O-03"] },
230
+ ];
231
+ /** Every rule id that must have exactly one adjudication site. */
232
+ export const SINGLE_SITE_RULE_IDS = SINGLE_SITE_RULE_GROUPS.flatMap((group) => group.ruleIds);
233
+ /**
234
+ * Violations of the single-site rule. Empty array = healthy; anything else must
235
+ * fail the build with the offending rule named.
236
+ */
237
+ export function auditSingleSiteRules() {
238
+ const problems = [];
239
+ for (const group of SINGLE_SITE_RULE_GROUPS) {
240
+ for (const ruleId of group.ruleIds) {
241
+ const actual = [...(CHECK_IDS_BY_RULE_ID.get(ruleId) ?? [])];
242
+ if (actual.length !== 1 || actual[0] !== group.checkId) {
243
+ problems.push({ ruleId, expected: group.checkId, actual });
244
+ }
245
+ }
246
+ }
247
+ return problems;
248
+ }
249
+ /** Per-level number budget (CONTRACT-FREEZE §C-15). P-04's "one number" is level-scoped. */
250
+ export const maxNumbersByLevel = {
251
+ WATCH: 2,
252
+ FLASH: 2,
253
+ IMPACT: 5,
254
+ };
255
+ /** Segment separator for the four-part template (CONTRACT-FREEZE §C-15): one newline. */
256
+ export const TEMPLATE_SEGMENT_SEPARATOR = "\n";
257
+ /** Applicability: a check with a level list only runs for those levels. */
258
+ export function appliesToLevel(definition, level) {
259
+ return definition.levels === "all" || definition.levels.includes(level);
260
+ }
261
+ //# sourceMappingURL=draft-rules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"draft-rules.js","sourceRoot":"","sources":["../../src/signal/draft-rules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAmCH,MAAM,KAAK,GAAG,CACZ,EAAU,EACV,OAA0B,EAC1B,MAAgC,EAChC,KAAY,EACZ,QAAkB,EAClB,WAAoB,EACpB,KAAa,EACH,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,CAAC;AAE9E,MAAM,CAAC,MAAM,MAAM,GAAwB;IACzC,+EAA+E;IAC/E,KAAK,CAAC,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EACzE,gEAAgE,CAAC;IACnE,KAAK,CAAC,gBAAgB,EAAE,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAC3D,2EAA2E,CAAC;IA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-15):dp-signal 用它建事件的事实
5
+ * 台账(docB B-A-02 的「新的关键数字」靠 diff 台账判定),dp-center 的草稿数字
6
+ * 回溯台账用它把帖子里的每一个数字回指到某条事实。两边各写一份的后果不是
7
+ * 「代码重复」,是**同一个数字在两侧归一成两个 key**,于是「帖里这个数字来自
8
+ * 哪条事实」永远查不到,而这个失败是静默的。
9
+ *
10
+ * ## 这里在解决的那个问题
11
+ *
12
+ * docB B-A-02 的 hiddenTrap 原文:「25bp vs 0.25% vs 四分之一个百分点是同一事实,
13
+ * 不归一化会把复述判成增量」。归一层不收敛,B-A-07(不同媒体重复同一标题不算
14
+ * 增量)就永远判不出来——每一家转载都会因为换了个写法而 diff 出「新数字」。
15
+ *
16
+ * ## 相对 Signal-Desk 0.6.1 `feeds/route.ts:129-152` 的四处修复
17
+ *
18
+ * 原实现是一条正则加一串三目运算,四个缺陷全部可复现:
19
+ *
20
+ * 1. **单字母倍率吃掉后随 ticker 的首字母**:`(\d+)\s*(k|m|b|…)?` 让
21
+ * `95,000 BTC` 里的 `B` 被当成 billion,归一成 9.5e13。修法是拉丁倍率词后
22
+ * 必须是非字母边界。
23
+ * 2. **倍率不成立时后随符号被丢弃**:`1,000 BTC` 与 `1,000 billion` 原本都产出
24
+ * `num:1000`(前者倍率没匹配上时 multiplier=1)。修法是把后随的已知资产符号
25
+ * 读成 token_amount。
26
+ * 3. **键里不带单位类与币种**:`num:1e9` 同时代表 10 亿美元、10 亿韩元、10 亿枚
27
+ * 代币。修法是 key 带 unitClass + unit。
28
+ * 4. **只认单字倍率**:`百万`/`千万`/`十亿`/`万亿` 与韩语 `만/억/조` 全部漏掉
29
+ * (韩元金额是 Upbit 一类事件的主数字)。修法是最长匹配的复合倍率表。
30
+ *
31
+ * 纯函数、零依赖、零 I/O —— 阈值是要拿真实数据反复调的东西,一个需要 Worker
32
+ * 才能跑的模块没人会去调它。
33
+ */
34
+ export type UnitClass = "currency" | "count" | "ratio" | "rate_bp" | "token_amount" | "time" | "unknown";
35
+ export interface Quantity {
36
+ /** 原文片段,用于回指与人工核对。 */
37
+ raw: string;
38
+ /** 在**传入文本**里的 UTF-16 码元区间。调用方负责保证文本版本一致。 */
39
+ start: number;
40
+ end: number;
41
+ /** 已乘倍率的原单位数值(未折算币种)。 */
42
+ value: number;
43
+ unitClass: UnitClass;
44
+ /** 'USD' | 'KRW' | 'BTC' | 'pct' | 'bp' | 'count' | 'AMBIGUOUS' */
45
+ unit: string;
46
+ currency?: string;
47
+ assetSymbol?: string;
48
+ /** 裸「元」「¥」这类无法定币种的:记录但永不进硬键。 */
49
+ ambiguous: boolean;
50
+ confidence: number;
51
+ }
52
+ /**
53
+ * 从文本里抽出所有数量。
54
+ *
55
+ * `symbolTable` 是已知资产符号集合(BTC / ETH / …)。传空集合时 `1,000 BTC` 会
56
+ * 退化成裸计数——这是**有意的**:我们宁可少认一个 token_amount,也不愿把
57
+ * 「1,000 IPO」读成一种代币。
58
+ */
59
+ export declare function parseQuantities(text: string, symbolTable?: ReadonlySet<string>): Quantity[];
60
+ /**
61
+ * 聚类用的粗粒度数量键。
62
+ *
63
+ * 缺陷 3 的修复点:键里带 unitClass 与 unit,所以 `currency:USD:1000000000` 永远
64
+ * 不等于 `currency:KRW:1000000000`,也不等于 `token_amount:BTC:1000`。
65
+ */
66
+ export declare function quantityKey(quantity: Quantity): string;
67
+ /**
68
+ * 受控指标词表。
69
+ *
70
+ * metric_slug 由模型给,是一个自由文本面:同一个指标被标成 `etf_net_inflow` 与
71
+ * `net_inflow` 就会 diff 出假增量。模型只能从这份表里选,选不到归 `other`,而
72
+ * `other` **不构成 B-A-02 增量**(只记录、不触发)——宁可漏一次增量,也不要让
73
+ * 词表漂移变成每天几十条假 FLASH。
74
+ *
75
+ * 扩表节奏:每月看一次 `other` 桶的 top-20。
76
+ */
77
+ export declare const SIGNAL_METRIC_VOCAB: readonly string[];
78
+ export declare const OTHER_METRIC_SLUG = "other";
79
+ /** 词表外的一律折成 `other`,由 diff 层决定它不算增量。 */
80
+ export declare function canonicalMetricSlug(raw: string | null | undefined): string;
81
+ export interface NormalizedFact {
82
+ /** `metric|subject|unit_class|as_of_bucket`,台账主键的语义部分。 */
83
+ normalizedKey: string;
84
+ /** 归一到基准单位(货币→USD、bp/%→小数)。无汇率时 null,比较自动跳过。 */
85
+ valueNorm: number | null;
86
+ unitNorm: string;
87
+ unitClass: UnitClass;
88
+ /** 值经过了汇率折算:比较时要放宽容差(各家媒体用各自的汇率)。 */
89
+ converted: boolean;
90
+ }
91
+ export interface NormalizeCtx {
92
+ /** 没有那天的汇率就返回 null。**绝不静默按 1.0 折算**。 */
93
+ fxToUsd(currency: string, asOfDate: string): number | null;
94
+ }
95
+ /**
96
+ * 把一个数量归一成台账里的一条事实。
97
+ *
98
+ * 这就是「25bp = 0.25% = 四分之一个百分点」收敛的地方:三者的 unitClass 分别是
99
+ * rate_bp / ratio / ratio,但 normalizedKey 都是 `<metric>|<subject>|ratio|<日期>`
100
+ * 且 valueNorm 都是 0.0025。台账 diff 因此判不出增量——这正是 B-A-07 要的效果。
101
+ */
102
+ export declare function normalizeMetric(metricSlug: string, subjectEntity: string | null, quantity: Quantity, asOfAt: string | null, ctx: NormalizeCtx): NormalizedFact;
103
+ /**
104
+ * 相对容差。
105
+ *
106
+ * `converted=true` 时放宽到 3%:中文媒体普遍附「约合人民币 X」,各家用的是各家
107
+ * 当天的汇率,0.5% 的带宽会让同一笔金额在三家媒体那里变成三条「新事实」。
108
+ */
109
+ export declare function toleranceFor(unitClass: UnitClass, converted: boolean): number;
110
+ /**
111
+ * 同值判定。
112
+ *
113
+ * - ratio:绝对 1bp。0.25% 与 0.2501% 是同一次降息。
114
+ * - count/votes:**必须精确相等**。票数 48:52 与 47:53 是两个结果。
115
+ * - 其它:相对容差(见 `toleranceFor`)。
116
+ *
117
+ * null 永远不等于 null:没有归一值意味着「无法比较」,不是「相等」。把无法比较
118
+ * 当相等,会让所有缺汇率的跨币种金额静默通过 B-A-02 判成零增量。
119
+ */
120
+ export declare function sameValue(left: number | null, right: number | null, unitClass: UnitClass, converted?: boolean): boolean;
121
+ //# sourceMappingURL=normalize-metric.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize-metric.d.ts","sourceRoot":"","sources":["../../src/signal/normalize-metric.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAMH,MAAM,MAAM,SAAS,GACjB,UAAU,GACV,OAAO,GACP,OAAO,GACP,SAAS,GACT,cAAc,GACd,MAAM,GACN,SAAS,CAAC;AAEd,MAAM,WAAW,QAAQ;IACvB,sBAAsB;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,6CAA6C;IAC7C,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,yBAAyB;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,SAAS,CAAC;IACrB,mEAAmE;IACnE,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gCAAgC;IAChC,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB;AA8FD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,EACZ,WAAW,GAAE,WAAW,CAAC,MAAM,CAAa,GAC3C,QAAQ,EAAE,CA4HZ;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAQtD;AAMD;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,EAAE,SAAS,MAAM,EA0BhD,CAAC;AAEF,eAAO,MAAM,iBAAiB,UAAU,CAAC;AAIzC,wCAAwC;AACxC,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAI1E;AAED,MAAM,WAAW,cAAc;IAC7B,0DAA0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