dp-worker 0.1.30 → 0.1.34

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 (66) 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/workspace-lock.js +64 -3
  13. package/dist/browser/workspace-lock.js.map +1 -1
  14. package/dist/center/center-frontend.d.ts +10 -0
  15. package/dist/center/center-frontend.js +13 -3
  16. package/dist/center/center-frontend.js.map +1 -1
  17. package/dist/chrome-extension/omni-flow/manifest.json +1 -1
  18. package/node_modules/dp-shared/dist/bird-contracts.d.ts +8 -0
  19. package/node_modules/dp-shared/dist/bird-contracts.d.ts.map +1 -1
  20. package/node_modules/dp-shared/dist/bird-contracts.js +19 -0
  21. package/node_modules/dp-shared/dist/bird-contracts.js.map +1 -1
  22. package/node_modules/dp-shared/dist/desk-contracts.d.ts +478 -0
  23. package/node_modules/dp-shared/dist/desk-contracts.d.ts.map +1 -0
  24. package/node_modules/dp-shared/dist/desk-contracts.js +397 -0
  25. package/node_modules/dp-shared/dist/desk-contracts.js.map +1 -0
  26. package/node_modules/dp-shared/dist/identities.d.ts +2 -1
  27. package/node_modules/dp-shared/dist/identities.d.ts.map +1 -1
  28. package/node_modules/dp-shared/dist/identities.js +13 -1
  29. package/node_modules/dp-shared/dist/identities.js.map +1 -1
  30. package/node_modules/dp-shared/dist/index.d.ts +2 -0
  31. package/node_modules/dp-shared/dist/index.d.ts.map +1 -1
  32. package/node_modules/dp-shared/dist/index.js +2 -0
  33. package/node_modules/dp-shared/dist/index.js.map +1 -1
  34. package/node_modules/dp-shared/dist/post-drafts-contracts.d.ts +223 -6
  35. package/node_modules/dp-shared/dist/post-drafts-contracts.d.ts.map +1 -1
  36. package/node_modules/dp-shared/dist/post-drafts-contracts.js +133 -0
  37. package/node_modules/dp-shared/dist/post-drafts-contracts.js.map +1 -1
  38. package/node_modules/dp-shared/dist/promo-contracts.d.ts +183 -23
  39. package/node_modules/dp-shared/dist/promo-contracts.d.ts.map +1 -1
  40. package/node_modules/dp-shared/dist/promo-contracts.js +368 -16
  41. package/node_modules/dp-shared/dist/promo-contracts.js.map +1 -1
  42. package/node_modules/dp-shared/dist/relay-contracts.d.ts +439 -0
  43. package/node_modules/dp-shared/dist/relay-contracts.d.ts.map +1 -0
  44. package/node_modules/dp-shared/dist/relay-contracts.js +362 -0
  45. package/node_modules/dp-shared/dist/relay-contracts.js.map +1 -0
  46. package/node_modules/dp-shared/dist/signal/draft-rules.d.ts +169 -0
  47. package/node_modules/dp-shared/dist/signal/draft-rules.d.ts.map +1 -0
  48. package/node_modules/dp-shared/dist/signal/draft-rules.js +261 -0
  49. package/node_modules/dp-shared/dist/signal/draft-rules.js.map +1 -0
  50. package/node_modules/dp-shared/dist/signal/normalize-metric.d.ts +121 -0
  51. package/node_modules/dp-shared/dist/signal/normalize-metric.d.ts.map +1 -0
  52. package/node_modules/dp-shared/dist/signal/normalize-metric.js +373 -0
  53. package/node_modules/dp-shared/dist/signal/normalize-metric.js.map +1 -0
  54. package/node_modules/dp-shared/dist/signal/signal-score.d.ts +445 -0
  55. package/node_modules/dp-shared/dist/signal/signal-score.d.ts.map +1 -0
  56. package/node_modules/dp-shared/dist/signal/signal-score.js +1922 -0
  57. package/node_modules/dp-shared/dist/signal/signal-score.js.map +1 -0
  58. package/node_modules/dp-shared/dist/signal/validate-draft.d.ts +718 -0
  59. package/node_modules/dp-shared/dist/signal/validate-draft.d.ts.map +1 -0
  60. package/node_modules/dp-shared/dist/signal/validate-draft.js +433 -0
  61. package/node_modules/dp-shared/dist/signal/validate-draft.js.map +1 -0
  62. package/node_modules/dp-shared/dist/signal/weighted-length.d.ts +87 -0
  63. package/node_modules/dp-shared/dist/signal/weighted-length.d.ts.map +1 -0
  64. package/node_modules/dp-shared/dist/signal/weighted-length.js +195 -0
  65. package/node_modules/dp-shared/dist/signal/weighted-length.js.map +1 -0
  66. package/package.json +1 -1
@@ -0,0 +1,195 @@
1
+ /**
2
+ * X (Twitter) official **weighted character count** — CONTRACT-FREEZE §C-15.
3
+ *
4
+ * docB P-11 / Q-12 / X-05 all reduce to one number, and that number is NOT
5
+ * `String.prototype.length`. The three traps, verbatim from P-11's hiddenTrap:
6
+ *
7
+ * 1. X counts **weighted** characters. CJK / emoji weigh 2, Latin weighs 1.
8
+ * 2. **Any** URL counts as exactly 23 (t.co), regardless of its real length.
9
+ * 3. The document says "reserve space for a link or tags" but gives no
10
+ * number — so half the rule is untestable until we pick one.
11
+ *
12
+ * dp-center's `rewrite.ts` uses `.length` everywhere (`shortBodyBudget:694`,
13
+ * `capShortCombinedBody:699`, `enforceCharLimit:1059`). For pure ASCII the two
14
+ * agree, which is exactly why the bug survives review: a ZWJ family emoji is 11
15
+ * to JS and 2 to X, and `.length` has no idea a URL is 23. The verified
16
+ * `SHORT_LINK_RESERVE = 25` at `rewrite.ts:688` is 23 (t.co) + 2 (newline), and
17
+ * that already-shipped constant is what fills the X-05 hole: `reserve_chars`
18
+ * defaults to 25 and lives in `signal_settings`, with 25 kept here as the
19
+ * fallback for when config injection fails. So X-05 is closed with a number the
20
+ * repo already agreed to, not a fresh guess.
21
+ *
22
+ * Why vendored rather than `npm i twitter-text`: we need one function and one
23
+ * table of ranges. twitter-text drags three transitive deps for the rest of its
24
+ * surface (extractors, autolinkers, HTML escapers) that we never call.
25
+ *
26
+ * Configuration below is twitter-text v3 `config/v3.json`, verbatim.
27
+ */
28
+ /** twitter-text v3 `config/v3.json`. Do not "tidy" these numbers. */
29
+ export const WEIGHTED_RANGES = [
30
+ [0, 4351],
31
+ [8192, 8205],
32
+ [8208, 8223],
33
+ [8242, 8247],
34
+ ];
35
+ /** Weight of a code point inside one of the ranges above, before scaling. */
36
+ const RANGE_WEIGHT = 100;
37
+ /** Weight of every other code point (CJK, most emoji, …), before scaling. */
38
+ const DEFAULT_WEIGHT = 200;
39
+ /** twitter-text divides the accumulated weight by this. */
40
+ const SCALE = 100;
41
+ /** `transformedURLLength`. Every URL is this, long or short, http or https. */
42
+ export const TCO_URL_LENGTH = 23;
43
+ /** `maxWeightedTweetLength`. */
44
+ export const X_MAX_WEIGHTED_LENGTH = 280;
45
+ /**
46
+ * Default reserve for the trailing link/tags (X-05).
47
+ *
48
+ * 23 (t.co) + 2 (the separating newline pair) — byte-identical to the verified
49
+ * `SHORT_LINK_RESERVE = 25` at `dp-center-worker/src/lib/content/rewrite.ts:688`.
50
+ * `signal_settings.reserve_chars` overrides it; this is the fallback used when
51
+ * settings cannot be read, so a settings outage cannot silently raise the cap.
52
+ */
53
+ export const DEFAULT_RESERVE_CHARS = 25;
54
+ /**
55
+ * URL matcher.
56
+ *
57
+ * Deliberately narrower than twitter-text's `extractUrls` (which also matches
58
+ * bare `example.com`). A false negative here counts the URL by its real
59
+ * characters, which for anything longer than 23 **over**-estimates the tweet —
60
+ * the safe direction. A false positive would under-estimate, so we require an
61
+ * explicit scheme.
62
+ */
63
+ const URL_RE = /\bhttps?:\/\/[^\s<>"'`\])】]+/gi;
64
+ /** Stand-in for an extracted URL. U+0000 cannot survive any upstream extractor. */
65
+ const URL_SENTINEL = "\u0000";
66
+ /** Regional indicators — flag sequences. Not Extended_Pictographic. */
67
+ const REGIONAL_INDICATOR_RE = /[\u{1F1E6}-\u{1F1FF}]/u;
68
+ /** COMBINING ENCLOSING KEYCAP — `1️⃣` is a keycap sequence, not a pictograph. */
69
+ const KEYCAP = "⃣";
70
+ /** VARIATION SELECTOR-16 — forces emoji presentation. */
71
+ const VS16 = "️";
72
+ function codePointWeight(codePoint) {
73
+ for (const [start, end] of WEIGHTED_RANGES) {
74
+ if (codePoint >= start && codePoint <= end)
75
+ return RANGE_WEIGHT;
76
+ }
77
+ return DEFAULT_WEIGHT;
78
+ }
79
+ /**
80
+ * Is this grapheme cluster an emoji as far as X is concerned?
81
+ *
82
+ * twitter-text runs an emoji regex and charges the whole match one
83
+ * `defaultWeight` (= 2). Extended_Pictographic alone misses two families that
84
+ * really do appear in posts: flags (two regional indicators) and keycaps
85
+ * (`1️⃣` = digit + VS16 + U+20E3). Missing either costs us 2 per flag, which is
86
+ * how a "280" post ships at 286.
87
+ */
88
+ function isEmojiCluster(cluster) {
89
+ if (/\p{Extended_Pictographic}/u.test(cluster))
90
+ return true;
91
+ if (REGIONAL_INDICATOR_RE.test(cluster))
92
+ return true;
93
+ if (cluster.includes(KEYCAP))
94
+ return true;
95
+ return cluster.length > 1 && cluster.includes(VS16);
96
+ }
97
+ let segmenter;
98
+ /**
99
+ * Grapheme segmentation, with a documented degradation.
100
+ *
101
+ * `Intl.Segmenter` availability in workerd is undocumented (CONTRACT-FREEZE §6
102
+ * item 2 has it as an open spike). Without it we fall back to code points,
103
+ * which splits a ZWJ family into 4 pictographs + 3 joiners and charges 2 for
104
+ * each pictograph — an **over**-estimate. That direction is deliberate: the
105
+ * degraded path can flag a legal post as over-limit (a human sees it), but can
106
+ * never let an over-limit post through (X truncates it, nobody sees it).
107
+ */
108
+ function graphemes(text) {
109
+ if (segmenter === undefined) {
110
+ const ctor = Intl
111
+ .Segmenter;
112
+ segmenter = typeof ctor === "function" ? new ctor("en", { granularity: "grapheme" }) : null;
113
+ }
114
+ if (segmenter) {
115
+ const out = [];
116
+ for (const piece of segmenter.segment(text))
117
+ out.push(piece.segment);
118
+ return out;
119
+ }
120
+ return Array.from(text);
121
+ }
122
+ /** Every `https?://…` run in `text`, in order of appearance. */
123
+ export function extractUrls(text) {
124
+ URL_RE.lastIndex = 0;
125
+ return text.match(URL_RE) ?? [];
126
+ }
127
+ /**
128
+ * X weighted length of `text`.
129
+ *
130
+ * NFC-normalizes first, exactly as twitter-text does: `é` typed as `e` + U+0301
131
+ * is 2 un-normalized and 1 after NFC, and users paste both forms.
132
+ */
133
+ export function weightedLength(text) {
134
+ const normalized = text.normalize("NFC");
135
+ // Replace each URL with a sentinel that cannot occur in user text, so URL
136
+ // characters never reach the per-grapheme loop. U+0000 is not producible by
137
+ // any keyboard and is stripped by every upstream extractor we run.
138
+ let urlCount = 0;
139
+ const withoutUrls = normalized.replace(URL_RE, () => {
140
+ urlCount += 1;
141
+ return URL_SENTINEL;
142
+ });
143
+ let weight = urlCount * TCO_URL_LENGTH * SCALE;
144
+ for (const cluster of graphemes(withoutUrls)) {
145
+ // Skipping the sentinel, not a space: a space is a real weight-1 character
146
+ // and charging 0 for it would make every post read ~15 characters shorter.
147
+ if (cluster === URL_SENTINEL)
148
+ continue;
149
+ if (isEmojiCluster(cluster)) {
150
+ weight += DEFAULT_WEIGHT;
151
+ continue;
152
+ }
153
+ // Non-emoji cluster: charge each code point, matching twitter-text. A base
154
+ // letter plus a combining mark is 2 there, and must be 2 here.
155
+ for (const character of cluster) {
156
+ weight += codePointWeight(character.codePointAt(0));
157
+ }
158
+ }
159
+ return Math.floor(weight / SCALE);
160
+ }
161
+ /**
162
+ * Reserve budget (X-05).
163
+ *
164
+ * `base` is `signal_settings.reserve_chars`. Hashtags are charged their own
165
+ * weighted length plus one separating space each, because a tag is not a URL
166
+ * and does not collapse to 23.
167
+ */
168
+ export function reserveChars(options) {
169
+ const base = options.base ?? DEFAULT_RESERVE_CHARS;
170
+ const tags = options.hashtags ?? [];
171
+ if (tags.length === 0)
172
+ return base;
173
+ return base + tags.reduce((total, tag) => total + weightedLength(tag) + 1, 0);
174
+ }
175
+ /**
176
+ * The single P-11 / Q-12 verdict input.
177
+ *
178
+ * Note the cap is `280 - reserve`, not 280: X-05's whole point is that a post
179
+ * measured at exactly 280 becomes 303 the moment the campaign link is appended,
180
+ * and the human who then deletes words to fit is editing text that already
181
+ * passed fact-checking.
182
+ */
183
+ export function measureWeighted(text, options = {}) {
184
+ const reserve = reserveChars({ hashtags: options.hashtags, base: options.reserveBase });
185
+ const weighted = weightedLength(text);
186
+ const budget = X_MAX_WEIGHTED_LENGTH - reserve;
187
+ return {
188
+ weighted,
189
+ limit: X_MAX_WEIGHTED_LENGTH,
190
+ reserve,
191
+ over_by: Math.max(0, weighted - budget),
192
+ url_count: extractUrls(text).length,
193
+ };
194
+ }
195
+ //# sourceMappingURL=weighted-length.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"weighted-length.js","sourceRoot":"","sources":["../../src/signal/weighted-length.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,qEAAqE;AACrE,MAAM,CAAC,MAAM,eAAe,GAA2C;IACrE,CAAC,CAAC,EAAE,IAAI,CAAC;IACT,CAAC,IAAI,EAAE,IAAI,CAAC;IACZ,CAAC,IAAI,EAAE,IAAI,CAAC;IACZ,CAAC,IAAI,EAAE,IAAI,CAAC;CACJ,CAAC;AAEX,6EAA6E;AAC7E,MAAM,YAAY,GAAG,GAAG,CAAC;AACzB,6EAA6E;AAC7E,MAAM,cAAc,GAAG,GAAG,CAAC;AAC3B,2DAA2D;AAC3D,MAAM,KAAK,GAAG,GAAG,CAAC;AAElB,+EAA+E;AAC/E,MAAM,CAAC,MAAM,cAAc,GAAG,EAAE,CAAC;AAEjC,gCAAgC;AAChC,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAEzC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,CAAC;AAExC;;;;;;;;GAQG;AACH,MAAM,MAAM,GAAG,gCAAgC,CAAC;AAEhD,mFAAmF;AACnF,MAAM,YAAY,GAAG,QAAQ,CAAC;AAE9B,uEAAuE;AACvE,MAAM,qBAAqB,GAAG,wBAAwB,CAAC;AACvD,iFAAiF;AACjF,MAAM,MAAM,GAAG,GAAG,CAAC;AACnB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BAAqB,CAAC;IACnD,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC;IACpC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACnC,OAAO,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,KAAK,GAAG,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;AAChF,CAAC;AAeD;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAC7B,IAAY,EACZ,UAAkE,EAAE;IAEpE,MAAM,OAAO,GAAG,YAAY,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IACxF,MAAM,QAAQ,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;IACtC,MAAM,MAAM,GAAG,qBAAqB,GAAG,OAAO,CAAC;IAC/C,OAAO;QACL,QAAQ;QACR,KAAK,EAAE,qBAAqB;QAC5B,OAAO;QACP,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC;QACvC,SAAS,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC,MAAM;KACpC,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dp-worker",
3
- "version": "0.1.30",
3
+ "version": "0.1.34",
4
4
  "description": "Dipclaw Worker (worker) — browser automation agent with scheduling, skills, and LLM integration. Connects to dp-center via center mode or runs standalone.",
5
5
  "type": "module",
6
6
  "bin": {