dsh-plugin-chuhai 0.2.3 → 0.3.0
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.
- package/CHANGELOG.md +12 -0
- package/README.md +2 -2
- package/books/ai-global-media/BOOK.md +23 -23
- package/books/ai-global-media/expert/SOURCE.json +41 -0
- package/books/ai-global-media/expert/agents/ilang-wechat-awesome.md +267 -0
- package/books/ai-global-media/expert/skills/remote-dispatch/SKILL.md +101 -0
- package/books/ai-global-media/expert/skills/remote-dispatch/references/gateway-api.md +58 -0
- package/books/ai-global-media/expert/skills/remote-dispatch/scripts/dispatch.py +299 -0
- package/books/ai-global-media/expert/skills/remote-dispatch/scripts/setup-gateway.ps1 +74 -0
- package/books/ai-global-media/expert/skills/remote-dispatch/scripts/setup-gateway.sh +94 -0
- package/books/ai-global-media/expert/skills/wechat-article/SKILL.md +80 -0
- package/books/ai-global-media/expert/skills/wechat-article/references/algorithm-and-rhythm.md +54 -0
- package/books/ai-global-media/expert/skills/wechat-article/references/compliance.md +68 -0
- package/books/ai-global-media/expert/skills/wechat-article/references/cover-prompt.md +19 -0
- package/books/ai-global-media/expert/skills/wechat-article/references/deai.md +64 -0
- package/books/ai-global-media/expert/skills/wechat-article/references/genes.md +168 -0
- package/books/ai-global-media/expert/skills/wechat-article/references/other-platforms.md +47 -0
- package/books/ai-global-media/expert/skills/wechat-article/references/self-check.md +32 -0
- package/books/ai-global-media/expert/skills/wechat-article/references/structures-and-titles.md +77 -0
- package/books/ai-global-media/expert/skills/wechat-article/references/wechat-format-and-api.md +61 -0
- package/books/ai-global-media/expert/skills/wechat-draft-push/SKILL.md +129 -0
- package/books/ai-global-media/expert/skills/wechat-draft-push/references/api-notes.md +168 -0
- package/books/ai-global-media/expert/skills/wechat-draft-push/references/html-rules.md +62 -0
- package/books/ai-global-media/expert/skills/wechat-draft-push/scripts/cards.html +75 -0
- package/books/ai-global-media/expert/skills/wechat-draft-push/scripts/newspic_cards.py +345 -0
- package/books/ai-global-media/expert/skills/wechat-draft-push/scripts/wechat_draft.py +1023 -0
- package/books/ai-global-media/expert/skills/wechat-topic-hunter/SKILL.md +92 -0
- package/books/ai-global-media/expert/skills/wechat-topic-hunter/references/method.md +49 -0
- package/books/ai-global-media/expert/skills/wechat-topic-hunter/references/wxrank-api.md +51 -0
- package/books/ai-global-media/expert/skills/wechat-topic-hunter/scripts/hot_sources.py +553 -0
- package/books/ai-global-media/expert/skills/wechat-topic-hunter/scripts/sources.json +714 -0
- package/books/ai-global-media/expert/skills/wechat-topic-hunter/scripts/wxrank_topics.py +466 -0
- package/lib/index.js +142 -9
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -4,11 +4,16 @@
|
|
|
4
4
|
* One skill, `zimeiti-chuhai`, loaded when the user says 自媒体出海 / AI全球自媒体.
|
|
5
5
|
* Two tools that hand the model a book one part at a time (DSH trims tool results
|
|
6
6
|
* past 8192 characters, both books are longer than that):
|
|
7
|
-
* - `chuhai_main_book`: the first half
|
|
7
|
+
* - `chuhai_main_book`: the first half (public). A copy ships inside this package;
|
|
8
|
+
* when the machine is online the tool first takes the latest edition from the
|
|
9
|
+
* toolkit repository, checks it against the digest in the toolkit's registry,
|
|
10
|
+
* and falls back to the shipped copy on any doubt. A wording fix in the book
|
|
11
|
+
* therefore needs no new release of this package.
|
|
8
12
|
* - `chuhai_book`: the second half, fetched from dsh.chuhai.express with the key
|
|
9
13
|
* this plugin carries; no network traffic unless it is called.
|
|
10
14
|
* No keys of the user's, nothing collected, nothing written outside the workspace.
|
|
11
15
|
*/
|
|
16
|
+
import { createHash } from 'node:crypto';
|
|
12
17
|
import fs from 'node:fs';
|
|
13
18
|
import path from 'node:path';
|
|
14
19
|
import { fileURLToPath } from 'node:url';
|
|
@@ -21,6 +26,23 @@ const DEFAULT_BOOK_URL = 'https://dsh.chuhai.express/book';
|
|
|
21
26
|
const MARKER = '::ILANG::v5.0::ENGINEERING_BOOK';
|
|
22
27
|
const PART_LIMIT = 8000; // stay under the 8192-character tool-result trim
|
|
23
28
|
const CACHE_MS = 10 * 60 * 1000; // the remote book is fetched once per ten minutes
|
|
29
|
+
const MAIN_BOOK_NAME = 'ai-global-media';
|
|
30
|
+
const MAIN_LIVE_MS = 6 * 60 * 60 * 1000; // a verified latest edition is kept for six hours
|
|
31
|
+
const MAIN_RETRY_MS = 10 * 60 * 1000; // after a miss the shipped copy is used for ten minutes
|
|
32
|
+
const MAIN_TIMEOUT_MS = 8_000; // per source; both sources are asked at once
|
|
33
|
+
/** Where the latest main book lives: the toolkit repository and its mirror. Each has the registry and the book. */
|
|
34
|
+
const MAIN_BOOK_SOURCES = [
|
|
35
|
+
{
|
|
36
|
+
name: 'GitHub',
|
|
37
|
+
registry: 'https://raw.githubusercontent.com/adsorgcn/DeepSeekHarness/main/docs/market/registry.json',
|
|
38
|
+
book: 'https://raw.githubusercontent.com/adsorgcn/DeepSeekHarness/main/.dsh/books/ai-global-media/BOOK.md',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: 'Gitee',
|
|
42
|
+
registry: 'https://gitee.com/monetize/DeepSeekHarness/raw/main/docs/market/registry.json',
|
|
43
|
+
book: 'https://gitee.com/monetize/DeepSeekHarness/raw/main/.dsh/books/ai-global-media/BOOK.md',
|
|
44
|
+
},
|
|
45
|
+
];
|
|
24
46
|
const VERSION = readVersion();
|
|
25
47
|
|
|
26
48
|
function here() {
|
|
@@ -62,7 +84,16 @@ export function normalize(config = {}) {
|
|
|
62
84
|
if (!/^https:\/\//.test(bookUrl)) throw new Error('chuhai: bookUrl must be https');
|
|
63
85
|
const pass = typeof config.pass === 'string' ? config.pass : '';
|
|
64
86
|
const timeoutMs = Number(config.timeoutMs ?? 30_000);
|
|
65
|
-
|
|
87
|
+
const liveMainBook = config.liveMainBook !== false;
|
|
88
|
+
const mainBookSources = Array.isArray(config.mainBookSources) && config.mainBookSources.length ? config.mainBookSources : MAIN_BOOK_SOURCES;
|
|
89
|
+
for (const s of mainBookSources) {
|
|
90
|
+
if (!/^https:\/\//.test(String(s?.registry)) || !/^https:\/\//.test(String(s?.book))) throw new Error('chuhai: mainBookSources must be https');
|
|
91
|
+
}
|
|
92
|
+
const mainTimeoutMs = Number(config.mainTimeoutMs ?? MAIN_TIMEOUT_MS);
|
|
93
|
+
return {
|
|
94
|
+
bookUrl, pass, timeoutMs: Number.isFinite(timeoutMs) && timeoutMs > 0 ? timeoutMs : 30_000,
|
|
95
|
+
liveMainBook, mainBookSources, mainTimeoutMs: Number.isFinite(mainTimeoutMs) && mainTimeoutMs > 0 ? mainTimeoutMs : MAIN_TIMEOUT_MS,
|
|
96
|
+
};
|
|
66
97
|
}
|
|
67
98
|
|
|
68
99
|
/* ---------- book splitting ---------- */
|
|
@@ -186,8 +217,10 @@ export function part(book, which) {
|
|
|
186
217
|
return ps[0];
|
|
187
218
|
}
|
|
188
219
|
|
|
220
|
+
/** Last line of defence. A page is at most PART_LIMIT and may carry a one-line pointer to the next page, so the cut sits a little above PART_LIMIT and still under the 8192 trim. */
|
|
189
221
|
function render(text, name) {
|
|
190
|
-
|
|
222
|
+
const limit = PART_LIMIT + 100;
|
|
223
|
+
if (text.length > limit) {
|
|
191
224
|
return text.slice(0, PART_LIMIT) + `\n\n[chuhai: ${name} 超过 ${PART_LIMIT} 字符,这里截断了;请按 toc 一段一段取]`;
|
|
192
225
|
}
|
|
193
226
|
return text;
|
|
@@ -199,10 +232,107 @@ export function mainBookText() {
|
|
|
199
232
|
return fs.readFileSync(mainBookPath(), 'utf8');
|
|
200
233
|
}
|
|
201
234
|
|
|
202
|
-
|
|
235
|
+
/** sha256 of the text with CRLF folded to LF: the digest the toolkit's registry records for a book. */
|
|
236
|
+
export function sha256Lf(text) {
|
|
237
|
+
return createHash('sha256').update(String(text).replace(/\r\n/g, '\n'), 'utf8').digest('hex');
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function bookVersion(text) {
|
|
241
|
+
return (/^\[VERSION:([^\]\n]+)\]/m.exec(text) || [])[1]?.trim() || '';
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** Compare dotted numeric versions; anything that is not a number counts as 0. */
|
|
245
|
+
export function compareVersions(a, b) {
|
|
246
|
+
const pa = String(a).split('.').map((x) => parseInt(x, 10) || 0);
|
|
247
|
+
const pb = String(b).split('.').map((x) => parseInt(x, 10) || 0);
|
|
248
|
+
for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
|
|
249
|
+
const d = (pa[i] || 0) - (pb[i] || 0);
|
|
250
|
+
if (d !== 0) return d < 0 ? -1 : 1;
|
|
251
|
+
}
|
|
252
|
+
return 0;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
async function getText(url, fetchImpl, timeoutMs, signal) {
|
|
256
|
+
const controller = new AbortController();
|
|
257
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
258
|
+
if (signal) signal.addEventListener('abort', () => controller.abort(), { once: true });
|
|
259
|
+
try {
|
|
260
|
+
const res = await fetchImpl(url, {
|
|
261
|
+
method: 'GET',
|
|
262
|
+
headers: { 'Accept': 'text/plain, application/json;q=0.9, */*;q=0.1', 'User-Agent': 'dsh-plugin-chuhai/' + VERSION },
|
|
263
|
+
redirect: 'follow',
|
|
264
|
+
signal: controller.signal,
|
|
265
|
+
});
|
|
266
|
+
if (!res.ok) throw new Error('HTTP ' + res.status);
|
|
267
|
+
return await res.text();
|
|
268
|
+
} catch (err) {
|
|
269
|
+
const cause = err?.cause?.code ?? err?.code ?? (err?.name === 'AbortError' ? '超时' : err?.message ?? String(err));
|
|
270
|
+
throw new Error(String(cause));
|
|
271
|
+
} finally {
|
|
272
|
+
clearTimeout(timer);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** One source: its registry row and its book, accepted only when the book matches the row's version and digest. */
|
|
277
|
+
async function mainBookFrom(source, fetchImpl, timeoutMs, signal) {
|
|
278
|
+
let row;
|
|
279
|
+
try {
|
|
280
|
+
const reg = JSON.parse(await getText(source.registry, fetchImpl, timeoutMs, signal));
|
|
281
|
+
row = (Array.isArray(reg?.entries) ? reg.entries : []).find((e) => e?.kind === 'book' && e?.name === MAIN_BOOK_NAME);
|
|
282
|
+
} catch (err) {
|
|
283
|
+
throw new Error(`${source.name} 清单没取到(${err.message})`);
|
|
284
|
+
}
|
|
285
|
+
if (!row || typeof row.sha256_lf !== 'string' || typeof row.version !== 'string') throw new Error(`${source.name} 清单里没有这本书`);
|
|
286
|
+
let text;
|
|
287
|
+
try {
|
|
288
|
+
text = await getText(source.book, fetchImpl, timeoutMs, signal);
|
|
289
|
+
} catch (err) {
|
|
290
|
+
throw new Error(`${source.name} 书没取到(${err.message})`);
|
|
291
|
+
}
|
|
292
|
+
const t = text.replace(/\r\n/g, '\n');
|
|
293
|
+
if (!t.startsWith(MARKER) || !t.trimEnd().endsWith(MARKER)) throw new Error(`${source.name} 取回的不是完整的工程书`);
|
|
294
|
+
if (bookVersion(t) !== row.version) throw new Error(`${source.name} 书和清单的版本对不上`);
|
|
295
|
+
if (sha256Lf(t) !== row.sha256_lf) throw new Error(`${source.name} 书的摘要和清单对不上`);
|
|
296
|
+
return { text: t, version: row.version, source: source.name };
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/** The latest main book from whichever source verifies first. Rejects with every source's reason when none does. */
|
|
300
|
+
export async function fetchLatestMainBook(options, fetchImpl = globalThis.fetch, signal) {
|
|
301
|
+
const tries = options.mainBookSources.map((s) => mainBookFrom(s, fetchImpl, options.mainTimeoutMs, signal));
|
|
302
|
+
try {
|
|
303
|
+
return await Promise.any(tries);
|
|
304
|
+
} catch (err) {
|
|
305
|
+
const reasons = (err?.errors ?? [err]).map((e) => e?.message ?? String(e));
|
|
306
|
+
throw new Error(reasons.join(';'));
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
export function mainBookDefinition(options = normalize({}), fetchImpl) {
|
|
311
|
+
let cached = null; // { at, ttl, text, note }
|
|
312
|
+
/** The book this session works from: the verified latest edition when it is not older than the shipped copy, else the shipped copy. */
|
|
313
|
+
async function current(signal) {
|
|
314
|
+
if (cached && Date.now() - cached.at < cached.ttl) return cached;
|
|
315
|
+
const shipped = mainBookText();
|
|
316
|
+
const shippedVersion = bookVersion(shipped);
|
|
317
|
+
let pick = { ttl: MAIN_LIVE_MS, text: shipped, note: `- 这本书用的是插件里带的 ${shippedVersion} 版。` };
|
|
318
|
+
if (options.liveMainBook) {
|
|
319
|
+
try {
|
|
320
|
+
const live = await fetchLatestMainBook(options, fetchImpl ?? globalThis.fetch, signal);
|
|
321
|
+
if (compareVersions(live.version, shippedVersion) >= 0) {
|
|
322
|
+
pick = { ttl: MAIN_LIVE_MS, text: live.text, note: `- 这本书是刚从 ${live.source} 取的最新版 ${live.version},摘要核对过;插件里带的是 ${shippedVersion}。` };
|
|
323
|
+
} else {
|
|
324
|
+
pick.note = `- 这本书用的是插件里带的 ${shippedVersion} 版(在线的 ${live.version} 比它旧)。`;
|
|
325
|
+
}
|
|
326
|
+
} catch (err) {
|
|
327
|
+
pick = { ttl: MAIN_RETRY_MS, text: shipped, note: `- 这本书用的是插件里带的 ${shippedVersion} 版;在线的最新版这次没取到(${err.message}),不影响照着做。` };
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
cached = { at: Date.now(), ...pick };
|
|
331
|
+
return cached;
|
|
332
|
+
}
|
|
203
333
|
return {
|
|
204
334
|
name: 'chuhai_main_book',
|
|
205
|
-
description: '取「自媒体出海」前半段的工程书(AI
|
|
335
|
+
description: '取「自媒体出海」前半段的工程书(AI全球自媒体:装写作专家、接内容源、建知识库、出文章、公众号走通)。书随插件带着;联网时先取最新版并核对摘要,取不到就用带着的那份。先 part=toc 看目录,再按段取:head、各模块、tail。只在 zimeiti-chuhai 技能让你取的时候调用。',
|
|
206
336
|
parameters: {
|
|
207
337
|
type: 'object',
|
|
208
338
|
properties: { part: { type: 'string', description: 'toc(目录,默认)、head、tail,或模块名(如 PERSONA);多页时写 段名#页号' } },
|
|
@@ -212,14 +342,17 @@ export function mainBookDefinition() {
|
|
|
212
342
|
schema: { type: 'object', properties: { content: { type: 'array', items: {} } }, required: ['content'], additionalProperties: false },
|
|
213
343
|
render(_args, value) { return value.content; },
|
|
214
344
|
},
|
|
215
|
-
async execute(args) {
|
|
216
|
-
const
|
|
345
|
+
async execute(args, exec) {
|
|
346
|
+
const cur = await current(exec?.signal);
|
|
347
|
+
const book = splitBook(cur.text);
|
|
217
348
|
const which = args?.part;
|
|
218
349
|
const extra = [
|
|
350
|
+
cur.note,
|
|
351
|
+
`- 写作专家包(第一环用:人格正文在 agents 下,四个技能在 skills 下,来源与哈希在 SOURCE.json)在:${companionPath('expert')}`,
|
|
219
352
|
`- 海报(第二环 生财三天体验卡)在:${posterPath()}`,
|
|
220
353
|
`- 海报(第二环 破局七天会员)在:${companionPath('poster-poju.jpg')}`,
|
|
221
354
|
`- 易洋那张视角卡(第四环立视角卡选了易洋时照它写)在:${companionPath('lens-yiyang.md')}`,
|
|
222
|
-
'- 书里写的 .dsh/books/ai-global-media/
|
|
355
|
+
'- 书里写的 .dsh/books/ai-global-media/ 下的这四样,工作区里没有就用上面这四个位置的。',
|
|
223
356
|
];
|
|
224
357
|
const text = part(book, which);
|
|
225
358
|
return { content: [{ type: 'text', text: text === null ? toc(book, extra) : render(text, String(which)) }] };
|
|
@@ -305,7 +438,7 @@ export function apply(ctx, config = {}) {
|
|
|
305
438
|
const disposers = [];
|
|
306
439
|
try {
|
|
307
440
|
disposers.push(ctx.skills.register(skillDefinition()));
|
|
308
|
-
disposers.push(ctx.tools.register(mainBookDefinition()));
|
|
441
|
+
disposers.push(ctx.tools.register(mainBookDefinition(options)));
|
|
309
442
|
disposers.push(ctx.tools.register(toolDefinition(options)));
|
|
310
443
|
ctx.logger?.info?.('chuhai: skill ' + SKILL_NAME + ', tools chuhai_main_book and chuhai_book registered');
|
|
311
444
|
} catch (err) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-chuhai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "自媒体出海 for DeepSeek Harness — 说一句「自媒体出海」,DSH 从零带你做到海外平台:写作人格、内容源、知识库、出文章、公众号走通,再到 X 开蓝 V。前半段的书随插件带着,能单独用;iLang DSH 工具包的第一个官方插件。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|