@wwkit/harness 1.0.31 → 1.0.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.
- package/LICENSE +21 -21
- package/README.md +128 -128
- package/agents/scrum.md +186 -180
- package/agents/sprint.md +121 -118
- package/bin/index.js +226 -226
- package/commands/fix.md +87 -87
- package/commands/git-sync.md +217 -217
- package/commands/net-port.md +364 -364
- package/commands/pytest.md +10 -10
- package/commands/resume.md +104 -104
- package/commands/tl.md +11 -11
- package/package.json +8 -7
- package/plugin.js +19 -19
- package/readme/development.md +39 -39
- package/readme/publish.md +41 -41
- package/readme/testing.md +44 -36
- package/scripts/postinstall.js +58 -58
- package/skills/better-skill/SKILL.md +124 -124
- package/skills/blame-skill/SKILL.md +201 -201
- package/skills/extract/SKILL.md +119 -119
- package/skills/extract/references/build-xpath.js +30 -30
- package/skills/extract/references/clean-html.js +90 -90
- package/skills/extract/references/detail.md +54 -54
- package/skills/extract/references/detail.schema.json5 +48 -48
- package/skills/extract/references/extract-detail.js +71 -71
- package/skills/extract/references/extract-regex.js +81 -81
- package/skills/extract/references/extract-sample.js +48 -48
- package/skills/extract/references/list-rule-gen.md +109 -109
- package/skills/extract/references/list.md +134 -134
- package/skills/extract/references/list.schema.json5 +33 -33
- package/skills/extract/references/navi.md +44 -44
- package/skills/extract/references/navi.schema.json5 +23 -23
- package/skills/extract/references/text.md +40 -40
- package/skills/extract/references/text.schema.json5 +21 -21
- package/skills/extract/references/to-text.js +20 -20
- package/skills/extract/references/validate-schema.js +39 -39
- package/skills/jstest/SKILL.md +561 -561
- package/skills/jstest/references/case-create.md +327 -327
- package/skills/jstest/references/case-fix.md +273 -273
- package/skills/jstest/references/config.md +148 -148
- package/skills/jstest/references/coverage-analyze.md +247 -247
- package/skills/jstest/references/env-ensure.md +210 -210
- package/skills/jstest/references/execute.md +168 -168
- package/skills/jstest/references/sample.md +166 -166
- package/skills/jstest/references/scoring-rules.md +75 -75
- package/skills/jstest/references/src/jstest-sample/Calculator.js +80 -80
- package/skills/jstest/references/src/jstest-sample/ConfigManager.js +72 -72
- package/skills/jstest/references/src/jstest-sample/FileProcessor.js +57 -57
- package/skills/jstest/references/src/jstest-sample/OrderService.js +98 -98
- package/skills/jstest/references/src/jstest-sample/TokenGenerator.js +60 -60
- package/skills/jstest/references/src/jstest-sample/UserService.js +56 -56
- package/skills/jstest/references/src/jstest-sample/index.js +6 -6
- package/skills/jstest/references/suitability-check.md +232 -232
- package/skills/jstest/references/test-standards.md +288 -288
- package/skills/lint/SKILL.md +440 -440
- package/skills/lint/references/ai-fix.md +137 -137
- package/skills/lint/references/config-setup.md +102 -102
- package/skills/lint/references/config.md +65 -65
- package/skills/lint/references/detect-language.js +65 -65
- package/skills/lint/references/env-ensure.md +88 -88
- package/skills/lint/references/language-detect.md +75 -75
- package/skills/lint/references/languages/js.md +110 -110
- package/skills/lint/references/languages/py.md +89 -89
- package/skills/lint/references/rules-analyze.md +125 -125
- package/skills/lint/references/suitability-check.md +81 -81
- package/skills/lint/references/tool-fix.md +90 -90
- package/skills/new-skill/SKILL.md +227 -227
- package/skills/new-skill/references/template.md +53 -53
- package/skills/new-skill/references/workflow-patterns.md +104 -104
- package/skills/pytest/SKILL.md +555 -555
- package/skills/pytest/references/case-create.md +324 -324
- package/skills/pytest/references/case-fix.md +271 -271
- package/skills/pytest/references/config.md +145 -145
- package/skills/pytest/references/coverage-analyze.md +223 -223
- package/skills/pytest/references/env-ensure.md +195 -195
- package/skills/pytest/references/execute.md +152 -152
- package/skills/pytest/references/sample.md +159 -159
- package/skills/pytest/references/scoring-rules.md +57 -57
- package/skills/pytest/references/src/pytest-sample/Calculator.py +67 -67
- package/skills/pytest/references/src/pytest-sample/ConfigManager.py +68 -68
- package/skills/pytest/references/src/pytest-sample/FileProcessor.py +53 -53
- package/skills/pytest/references/src/pytest-sample/OrderService.py +82 -82
- package/skills/pytest/references/src/pytest-sample/TokenGenerator.py +50 -50
- package/skills/pytest/references/src/pytest-sample/UserService.py +45 -45
- package/skills/pytest/references/suitability-check.md +220 -220
- package/skills/pytest/references/test-standards.md +244 -244
- package/skills/query/SKILL.md +71 -71
- package/skills/read-docs/SKILL.md +134 -134
- package/skills/read-docs/references/opencode/agents/cases.md +206 -206
- package/skills/read-docs/references/opencode/agents/design-pattern.md +47 -47
- package/skills/read-docs/references/opencode/agents/detail.md +191 -191
- package/skills/read-docs/references/opencode/agents/examples.md +100 -100
- package/skills/read-docs/references/opencode/agents/index.md +309 -309
- package/skills/read-docs/references/opencode/agents/parallel-dispatch.md +149 -149
- package/skills/read-docs/references/opencode/agents/subagent-internals.md +217 -217
- package/skills/read-docs/references/opencode/agents/workflow.md +161 -161
- package/skills/read-docs/references/opencode/cli/commands/acp.md +31 -31
- package/skills/read-docs/references/opencode/cli/commands/agent.md +16 -16
- package/skills/read-docs/references/opencode/cli/commands/attach.md +20 -20
- package/skills/read-docs/references/opencode/cli/commands/mcp.md +37 -37
- package/skills/read-docs/references/opencode/cli/commands/others.md +48 -48
- package/skills/read-docs/references/opencode/cli/commands/plugin.md +12 -12
- package/skills/read-docs/references/opencode/cli/commands/provider.md +43 -43
- package/skills/read-docs/references/opencode/cli/commands/run.md +81 -81
- package/skills/read-docs/references/opencode/cli/commands/serve.md +84 -84
- package/skills/read-docs/references/opencode/cli/commands/session.md +37 -37
- package/skills/read-docs/references/opencode/cli/commands/web.md +14 -14
- package/skills/read-docs/references/opencode/cli/env.md +38 -38
- package/skills/read-docs/references/opencode/cli/index.md +18 -18
- package/skills/read-docs/references/opencode/cli/tui.md +35 -35
- package/skills/read-docs/references/opencode/commands/examples.md +42 -42
- package/skills/read-docs/references/opencode/commands/index.md +185 -185
- package/skills/read-docs/references/opencode/config/provider.md +151 -151
- package/skills/read-docs/references/opencode/formatter/index.md +70 -70
- package/skills/read-docs/references/opencode/guide/config.md +419 -419
- package/skills/read-docs/references/opencode/guide/formatters.md +70 -70
- package/skills/read-docs/references/opencode/guide/index.md +37 -37
- package/skills/read-docs/references/opencode/guide/providers.md +31 -31
- package/skills/read-docs/references/opencode/guide/rules.md +63 -63
- package/skills/read-docs/references/opencode/plugins/examples.md +75 -75
- package/skills/read-docs/references/opencode/plugins/index.md +188 -188
- package/skills/read-docs/references/opencode/reference/index.md +118 -118
- package/skills/read-docs/references/opencode/rule/index.md +77 -77
- package/skills/read-docs/references/opencode/skills/detail.md +113 -113
- package/skills/read-docs/references/opencode/skills/examples.md +141 -141
- package/skills/read-docs/references/opencode/skills/index.md +126 -126
- package/skills/read-docs/references/opencode/skills/workflow.md +146 -146
- package/skills/read-docs/references/opencode/tests/agent.md +9 -9
- package/skills/read-docs/references/opencode/tests/config.md +59 -59
- package/skills/read-docs/references/opencode/tests/file.md +11 -11
- package/skills/read-docs/references/opencode/tests/serve.md +17 -17
- package/skills/read-docs/references/opencode/tests/session.md +30 -30
- package/skills/read-docs/references/opencode/tests/web.md +16 -16
- package/skills/read-docs/references/opencode/tools/arguments.md +305 -305
- package/skills/read-docs/references/opencode/tools/context.md +17 -17
- package/skills/read-docs/references/opencode/tools/custom.md +110 -110
- package/skills/read-docs/references/opencode/tools/detail.md +104 -104
- package/skills/read-docs/references/opencode/tools/examples.md +71 -71
- package/skills/read-docs/references/opencode/tools/index.md +56 -56
- package/skills/read-docs/references/opencode/tools/lsp.md +25 -25
- package/skills/read-docs/references/opencode/tools/mcp.md +132 -132
- package/skills/read-docs/references/opencode/train/README.md +134 -134
- package/skills/read-docs/references/opencode/train/agent-basic.md +771 -771
- package/skills/read-docs/references/opencode/train/command-basic.md +667 -667
- package/skills/read-docs/references/opencode/train/config-basic.md +508 -508
- package/skills/read-docs/references/opencode/train/index.md +163 -163
- package/skills/read-docs/references/opencode/train/practice.md +872 -872
- package/skills/read-docs/references/opencode/train/skill-basic.md +607 -607
- package/skills/read-docs/references/opencode/tui/commands/config.md +31 -31
- package/skills/read-docs/references/opencode/tui/commands/editor.md +46 -46
- package/skills/read-docs/references/opencode/tui/commands/index.md +124 -124
- package/skills/read-docs/references/opencode/tui/commands/init.md +4 -4
- package/skills/read-docs/references/opencode/tui/index.md +26 -26
- package/skills/read-docs/references/superpowers/bootstrap.md +107 -107
- package/skills/read-docs/references/superpowers/comparison.md +77 -77
- package/skills/read-docs/references/superpowers/context.md +71 -71
- package/skills/read-docs/references/superpowers/index.md +58 -58
- package/skills/read-docs/references/superpowers/parallel.md +49 -49
- package/skills/read-docs/references/superpowers/sdd.md +183 -183
- package/skills/read-docs/references/superpowers/skills.md +68 -68
- package/skills/read-docs/references/superpowers/workflow.md +83 -83
- package/skills/revise/SKILL.md +121 -121
- package/skills/revise/references/article.md +36 -36
- package/skills/revise/references/article.schema.json5 +40 -40
- package/skills/revise/references/gallery.md +34 -34
- package/skills/revise/references/gallery.schema.json5 +40 -40
- package/skills/revise/references/question.md +32 -32
- package/skills/revise/references/question.schema.json5 +31 -31
- package/skills/revise/references/status.md +31 -31
- package/skills/revise/references/status.schema.json5 +27 -27
- package/skills/revise/references/validate-schema.js +39 -39
- package/src/config.js +29 -29
- package/src/config.json5 +19 -19
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { createInterface } from 'readline';
|
|
2
|
-
import { fileURLToPath } from 'url';
|
|
3
|
-
|
|
4
|
-
const QUOTE_PATTERN = /[\u201c\u201d\u2018\u2019"'"]+/;
|
|
5
|
-
|
|
6
|
-
export function buildXpath(title) {
|
|
7
|
-
const fragments = title.split(QUOTE_PATTERN).map(s => s.trim()).filter(Boolean);
|
|
8
|
-
if (!fragments.length) fragments.push(title);
|
|
9
|
-
const conditions = fragments.map(f =>
|
|
10
|
-
`contains(.,'${f.replace(/'/g, "'")}')`
|
|
11
|
-
).join(' and ');
|
|
12
|
-
return `//text()[${conditions} and not(ancestor::script)]/..`;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function main() {
|
|
16
|
-
const rl = createInterface({ input: process.stdin });
|
|
17
|
-
let raw = '';
|
|
18
|
-
rl.on('line', line => { raw += line; });
|
|
19
|
-
rl.on('close', () => {
|
|
20
|
-
try {
|
|
21
|
-
const items = JSON.parse(raw);
|
|
22
|
-
if (!Array.isArray(items)) { console.log('[]'); return; }
|
|
23
|
-
const result = items
|
|
24
|
-
.filter(item => item.title)
|
|
25
|
-
.map(item => ({ selector: buildXpath(item.title), title: item.title }));
|
|
26
|
-
console.log(JSON.stringify(result, null, 2));
|
|
27
|
-
} catch { console.log('[]'); }
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
1
|
+
import { createInterface } from 'readline';
|
|
2
|
+
import { fileURLToPath } from 'url';
|
|
3
|
+
|
|
4
|
+
const QUOTE_PATTERN = /[\u201c\u201d\u2018\u2019"'"]+/;
|
|
5
|
+
|
|
6
|
+
export function buildXpath(title) {
|
|
7
|
+
const fragments = title.split(QUOTE_PATTERN).map(s => s.trim()).filter(Boolean);
|
|
8
|
+
if (!fragments.length) fragments.push(title);
|
|
9
|
+
const conditions = fragments.map(f =>
|
|
10
|
+
`contains(.,'${f.replace(/'/g, "'")}')`
|
|
11
|
+
).join(' and ');
|
|
12
|
+
return `//text()[${conditions} and not(ancestor::script)]/..`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function main() {
|
|
16
|
+
const rl = createInterface({ input: process.stdin });
|
|
17
|
+
let raw = '';
|
|
18
|
+
rl.on('line', line => { raw += line; });
|
|
19
|
+
rl.on('close', () => {
|
|
20
|
+
try {
|
|
21
|
+
const items = JSON.parse(raw);
|
|
22
|
+
if (!Array.isArray(items)) { console.log('[]'); return; }
|
|
23
|
+
const result = items
|
|
24
|
+
.filter(item => item.title)
|
|
25
|
+
.map(item => ({ selector: buildXpath(item.title), title: item.title }));
|
|
26
|
+
console.log(JSON.stringify(result, null, 2));
|
|
27
|
+
} catch { console.log('[]'); }
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
31
|
if (process.argv[1] === fileURLToPath(import.meta.url)) main();
|
|
@@ -1,91 +1,91 @@
|
|
|
1
|
-
import { fileURLToPath } from 'url';
|
|
2
|
-
import * as cheerio from 'cheerio';
|
|
3
|
-
|
|
4
|
-
const STRIP_TAGS = new Set([
|
|
5
|
-
'script', 'style', 'noscript', 'iframe', 'svg', 'canvas', 'template',
|
|
6
|
-
'form', 'video', 'audio', 'object', 'embed', 'nav', 'footer', 'aside',
|
|
7
|
-
]);
|
|
8
|
-
|
|
9
|
-
const WRAPPER_TAGS = new Set([
|
|
10
|
-
'strong', 'b', 'i', 'em', 'span', 'u', 's', 'strike', 'mark',
|
|
11
|
-
'small', 'sub', 'sup', 'code', 'kbd', 'q', 'abbr', 'cite',
|
|
12
|
-
]);
|
|
13
|
-
|
|
14
|
-
const KEEP_ATTRS = new Set(['href', 'src', 'alt']);
|
|
15
|
-
|
|
16
|
-
export function cleanHtml(html) {
|
|
17
|
-
if (!html) return '';
|
|
18
|
-
let $ = cheerio.load(html);
|
|
19
|
-
|
|
20
|
-
// 1. Strip blocks
|
|
21
|
-
STRIP_TAGS.forEach(tag => { $(tag).remove(); });
|
|
22
|
-
|
|
23
|
-
// 2. Strip comments
|
|
24
|
-
$.root().find('*').contents().filter((i, el) => el.type === 'comment').remove();
|
|
25
|
-
|
|
26
|
-
// 3. Extract body
|
|
27
|
-
const body = $('body').html();
|
|
28
|
-
if (body) {
|
|
29
|
-
$ = cheerio.load(body);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// 4. Strip attributes (keep only href/src/alt)
|
|
33
|
-
$('*').each((i, el) => {
|
|
34
|
-
const attrs = el.attribs;
|
|
35
|
-
Object.keys(attrs).forEach(attr => {
|
|
36
|
-
if (!KEEP_ATTRS.has(attr)) delete attrs[attr];
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
// 5. Strip wrapper tags (unwrap content)
|
|
41
|
-
WRAPPER_TAGS.forEach(tag => {
|
|
42
|
-
$(tag).each((i, el) => {
|
|
43
|
-
const $el = $(el);
|
|
44
|
-
$el.replaceWith($el.contents());
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
// 6. Strip void elements (img, br, hr, etc.) and empty paired elements
|
|
49
|
-
const VOID_TAGS = new Set([
|
|
50
|
-
'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input',
|
|
51
|
-
'link', 'meta', 'param', 'source', 'track', 'wbr',
|
|
52
|
-
]);
|
|
53
|
-
VOID_TAGS.forEach(tag => { $(tag).remove(); });
|
|
54
|
-
|
|
55
|
-
// Remove empty elements repeatedly
|
|
56
|
-
let prev = '';
|
|
57
|
-
let curr = $.html();
|
|
58
|
-
while (curr !== prev) {
|
|
59
|
-
prev = curr;
|
|
60
|
-
$ = cheerio.load(curr);
|
|
61
|
-
$('*').each((i, el) => {
|
|
62
|
-
const $el = $(el);
|
|
63
|
-
if ($el.text().trim() === '' && !$el.children().length) {
|
|
64
|
-
$el.remove();
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
curr = $.html();
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// 7. Strip base64 images
|
|
71
|
-
$ = cheerio.load(curr);
|
|
72
|
-
$('img[src^="data:image/"]').remove();
|
|
73
|
-
|
|
74
|
-
// 8. Minify
|
|
75
|
-
let result = $.html();
|
|
76
|
-
result = result.replace(/\s+/g, ' ');
|
|
77
|
-
result = result.replace(/>\s+</g, '><');
|
|
78
|
-
return result.trim();
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function main() {
|
|
82
|
-
const chunks = [];
|
|
83
|
-
process.stdin.on('data', chunk => chunks.push(chunk));
|
|
84
|
-
process.stdin.on('end', () => {
|
|
85
|
-
const html = Buffer.concat(chunks).toString();
|
|
86
|
-
process.stdout.write(cleanHtml(html));
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export default cleanHtml;
|
|
1
|
+
import { fileURLToPath } from 'url';
|
|
2
|
+
import * as cheerio from 'cheerio';
|
|
3
|
+
|
|
4
|
+
const STRIP_TAGS = new Set([
|
|
5
|
+
'script', 'style', 'noscript', 'iframe', 'svg', 'canvas', 'template',
|
|
6
|
+
'form', 'video', 'audio', 'object', 'embed', 'nav', 'footer', 'aside',
|
|
7
|
+
]);
|
|
8
|
+
|
|
9
|
+
const WRAPPER_TAGS = new Set([
|
|
10
|
+
'strong', 'b', 'i', 'em', 'span', 'u', 's', 'strike', 'mark',
|
|
11
|
+
'small', 'sub', 'sup', 'code', 'kbd', 'q', 'abbr', 'cite',
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
const KEEP_ATTRS = new Set(['href', 'src', 'alt']);
|
|
15
|
+
|
|
16
|
+
export function cleanHtml(html) {
|
|
17
|
+
if (!html) return '';
|
|
18
|
+
let $ = cheerio.load(html);
|
|
19
|
+
|
|
20
|
+
// 1. Strip blocks
|
|
21
|
+
STRIP_TAGS.forEach(tag => { $(tag).remove(); });
|
|
22
|
+
|
|
23
|
+
// 2. Strip comments
|
|
24
|
+
$.root().find('*').contents().filter((i, el) => el.type === 'comment').remove();
|
|
25
|
+
|
|
26
|
+
// 3. Extract body
|
|
27
|
+
const body = $('body').html();
|
|
28
|
+
if (body) {
|
|
29
|
+
$ = cheerio.load(body);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// 4. Strip attributes (keep only href/src/alt)
|
|
33
|
+
$('*').each((i, el) => {
|
|
34
|
+
const attrs = el.attribs;
|
|
35
|
+
Object.keys(attrs).forEach(attr => {
|
|
36
|
+
if (!KEEP_ATTRS.has(attr)) delete attrs[attr];
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// 5. Strip wrapper tags (unwrap content)
|
|
41
|
+
WRAPPER_TAGS.forEach(tag => {
|
|
42
|
+
$(tag).each((i, el) => {
|
|
43
|
+
const $el = $(el);
|
|
44
|
+
$el.replaceWith($el.contents());
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// 6. Strip void elements (img, br, hr, etc.) and empty paired elements
|
|
49
|
+
const VOID_TAGS = new Set([
|
|
50
|
+
'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input',
|
|
51
|
+
'link', 'meta', 'param', 'source', 'track', 'wbr',
|
|
52
|
+
]);
|
|
53
|
+
VOID_TAGS.forEach(tag => { $(tag).remove(); });
|
|
54
|
+
|
|
55
|
+
// Remove empty elements repeatedly
|
|
56
|
+
let prev = '';
|
|
57
|
+
let curr = $.html();
|
|
58
|
+
while (curr !== prev) {
|
|
59
|
+
prev = curr;
|
|
60
|
+
$ = cheerio.load(curr);
|
|
61
|
+
$('*').each((i, el) => {
|
|
62
|
+
const $el = $(el);
|
|
63
|
+
if ($el.text().trim() === '' && !$el.children().length) {
|
|
64
|
+
$el.remove();
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
curr = $.html();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// 7. Strip base64 images
|
|
71
|
+
$ = cheerio.load(curr);
|
|
72
|
+
$('img[src^="data:image/"]').remove();
|
|
73
|
+
|
|
74
|
+
// 8. Minify
|
|
75
|
+
let result = $.html();
|
|
76
|
+
result = result.replace(/\s+/g, ' ');
|
|
77
|
+
result = result.replace(/>\s+</g, '><');
|
|
78
|
+
return result.trim();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function main() {
|
|
82
|
+
const chunks = [];
|
|
83
|
+
process.stdin.on('data', chunk => chunks.push(chunk));
|
|
84
|
+
process.stdin.on('end', () => {
|
|
85
|
+
const html = Buffer.concat(chunks).toString();
|
|
86
|
+
process.stdout.write(cleanHtml(html));
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export default cleanHtml;
|
|
91
91
|
if (process.argv[1] === fileURLToPath(import.meta.url)) main();
|
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
# detail 提取流程
|
|
2
|
-
|
|
3
|
-
从文章详情页的正文容器 HTML 中提取结构化信息(本地提取 + LLM 规范)。
|
|
4
|
-
|
|
5
|
-
## 输出契约
|
|
6
|
-
|
|
7
|
-
符合 `detail.schema.json5` 的 JSON 数组(仅含 1 项):
|
|
8
|
-
|
|
9
|
-
```json
|
|
10
|
-
[
|
|
11
|
-
{
|
|
12
|
-
"title": "文章标题",
|
|
13
|
-
"author": "作者名",
|
|
14
|
-
"date": "2026-06-20",
|
|
15
|
-
"url": "https://example.com/article/123",
|
|
16
|
-
"blocks": [
|
|
17
|
-
{"type": "text", "value": "第一段文本"},
|
|
18
|
-
{"type": "image", "value": "https://example.com/pic1.jpg"},
|
|
19
|
-
{"type": "text", "value": "第二段文本"}
|
|
20
|
-
]
|
|
21
|
-
}
|
|
22
|
-
]
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
字段:`title`(可选,空则基于全文生成 ≤30 字短标题)、`author` / `date`(可选)、`url`(可选,直接用输入 `{{ url }}`)、`blocks`(必填,`type`/`value` 交替数组)。
|
|
26
|
-
|
|
27
|
-
## 步骤
|
|
28
|
-
|
|
29
|
-
### Step 1 — 本地提取(按 img 切分)
|
|
30
|
-
|
|
31
|
-
将正文容器 HTML 写入临时文件,再用 stdin 重定向交给 Node.js 按 `<img>` 标签切分:
|
|
32
|
-
|
|
33
|
-
```bash
|
|
34
|
-
node '<技能目录>/references/extract-detail.js' < <临时 HTML 文件>
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
输出 JSON 包含 `blocks`:按 DOM 序交替排列的 `{"type":"text"/"image", "value":...}`。
|
|
38
|
-
|
|
39
|
-
### Step 2 — LLM 数据规范
|
|
40
|
-
|
|
41
|
-
将 Step 1 输出的 `{blocks}` + `{{ url }}` 交给 LLM 进行规范:
|
|
42
|
-
|
|
43
|
-
1. **提取元数据**:从 `blocks[0]["value"]`(文章首段)中识别并提取 `title`、`author`、`date`
|
|
44
|
-
- 标题通常是首段开头最显著的完整短句
|
|
45
|
-
- 作者通常在标题后或段尾,常见格式:「作者:xxx」「文/xxx」「xxx/文」
|
|
46
|
-
- 日期通常在段首或段尾,格式多样,统一输出 `yyyy-mm-dd`
|
|
47
|
-
2. **无标题时生成**:如果首段无法提取 title,基于全部 `blocks` 中 `type=text` 的内容生成一个不超过 30 字的短标题
|
|
48
|
-
3. **清理 blocks**:从 `blocks` 数组中移除已提取的元数据行、广告引导语、文末推荐、版权声明等无效段(仅移除 `type=text` 的无效段,保留图片段)
|
|
49
|
-
4. 相对路径 URL 基于 `{{ url }}` 转为绝对地址
|
|
50
|
-
|
|
51
|
-
输出:规范后的 JSON 数组(`blocks` 已清理)。
|
|
52
|
-
|
|
53
|
-
### Step 3 — 验证
|
|
54
|
-
|
|
1
|
+
# detail 提取流程
|
|
2
|
+
|
|
3
|
+
从文章详情页的正文容器 HTML 中提取结构化信息(本地提取 + LLM 规范)。
|
|
4
|
+
|
|
5
|
+
## 输出契约
|
|
6
|
+
|
|
7
|
+
符合 `detail.schema.json5` 的 JSON 数组(仅含 1 项):
|
|
8
|
+
|
|
9
|
+
```json
|
|
10
|
+
[
|
|
11
|
+
{
|
|
12
|
+
"title": "文章标题",
|
|
13
|
+
"author": "作者名",
|
|
14
|
+
"date": "2026-06-20",
|
|
15
|
+
"url": "https://example.com/article/123",
|
|
16
|
+
"blocks": [
|
|
17
|
+
{"type": "text", "value": "第一段文本"},
|
|
18
|
+
{"type": "image", "value": "https://example.com/pic1.jpg"},
|
|
19
|
+
{"type": "text", "value": "第二段文本"}
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
字段:`title`(可选,空则基于全文生成 ≤30 字短标题)、`author` / `date`(可选)、`url`(可选,直接用输入 `{{ url }}`)、`blocks`(必填,`type`/`value` 交替数组)。
|
|
26
|
+
|
|
27
|
+
## 步骤
|
|
28
|
+
|
|
29
|
+
### Step 1 — 本地提取(按 img 切分)
|
|
30
|
+
|
|
31
|
+
将正文容器 HTML 写入临时文件,再用 stdin 重定向交给 Node.js 按 `<img>` 标签切分:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
node '<技能目录>/references/extract-detail.js' < <临时 HTML 文件>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
输出 JSON 包含 `blocks`:按 DOM 序交替排列的 `{"type":"text"/"image", "value":...}`。
|
|
38
|
+
|
|
39
|
+
### Step 2 — LLM 数据规范
|
|
40
|
+
|
|
41
|
+
将 Step 1 输出的 `{blocks}` + `{{ url }}` 交给 LLM 进行规范:
|
|
42
|
+
|
|
43
|
+
1. **提取元数据**:从 `blocks[0]["value"]`(文章首段)中识别并提取 `title`、`author`、`date`
|
|
44
|
+
- 标题通常是首段开头最显著的完整短句
|
|
45
|
+
- 作者通常在标题后或段尾,常见格式:「作者:xxx」「文/xxx」「xxx/文」
|
|
46
|
+
- 日期通常在段首或段尾,格式多样,统一输出 `yyyy-mm-dd`
|
|
47
|
+
2. **无标题时生成**:如果首段无法提取 title,基于全部 `blocks` 中 `type=text` 的内容生成一个不超过 30 字的短标题
|
|
48
|
+
3. **清理 blocks**:从 `blocks` 数组中移除已提取的元数据行、广告引导语、文末推荐、版权声明等无效段(仅移除 `type=text` 的无效段,保留图片段)
|
|
49
|
+
4. 相对路径 URL 基于 `{{ url }}` 转为绝对地址
|
|
50
|
+
|
|
51
|
+
输出:规范后的 JSON 数组(`blocks` 已清理)。
|
|
52
|
+
|
|
53
|
+
### Step 3 — 验证
|
|
54
|
+
|
|
55
55
|
检查 `blocks` 非空,输出规范后的 JSON 数组(供 extract 技能校验)。
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
{
|
|
2
|
-
// 省略 $schema 字段,避免 bash -c "" 中 $ 展开问题
|
|
3
|
-
"title": "详情提取格式",
|
|
4
|
-
"description": "详情页提取(detail)输出校验 schema(数组,仅 1 项)",
|
|
5
|
-
"type": "array",
|
|
6
|
-
"items": {
|
|
7
|
-
"type": "object",
|
|
8
|
-
"properties": {
|
|
9
|
-
"title": {
|
|
10
|
-
"type": "string",
|
|
11
|
-
"description": "文章标题,可选;空则生成短标题"
|
|
12
|
-
},
|
|
13
|
-
"author": {
|
|
14
|
-
"type": "string",
|
|
15
|
-
"description": "作者,可选"
|
|
16
|
-
},
|
|
17
|
-
"date": {
|
|
18
|
-
"type": "string",
|
|
19
|
-
"description": "日期,统一 yyyy-mm-dd,可选"
|
|
20
|
-
},
|
|
21
|
-
"url": {
|
|
22
|
-
"type": "string",
|
|
23
|
-
"description": "文章链接,可选"
|
|
24
|
-
},
|
|
25
|
-
"blocks": {
|
|
26
|
-
"type": "array",
|
|
27
|
-
"description": "正文段落,type/value 交替数组",
|
|
28
|
-
"items": {
|
|
29
|
-
"type": "object",
|
|
30
|
-
"properties": {
|
|
31
|
-
"type": {
|
|
32
|
-
"type": "string",
|
|
33
|
-
"enum": ["text", "image"],
|
|
34
|
-
"description": "段落类型:text 文本 / image 图片"
|
|
35
|
-
},
|
|
36
|
-
"value": {
|
|
37
|
-
"type": "string",
|
|
38
|
-
"description": "文本内容或图片地址"
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
"required": ["type", "value"],
|
|
42
|
-
"additionalProperties": false
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
"required": ["blocks"],
|
|
47
|
-
"additionalProperties": false
|
|
48
|
-
}
|
|
1
|
+
{
|
|
2
|
+
// 省略 $schema 字段,避免 bash -c "" 中 $ 展开问题
|
|
3
|
+
"title": "详情提取格式",
|
|
4
|
+
"description": "详情页提取(detail)输出校验 schema(数组,仅 1 项)",
|
|
5
|
+
"type": "array",
|
|
6
|
+
"items": {
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"title": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"description": "文章标题,可选;空则生成短标题"
|
|
12
|
+
},
|
|
13
|
+
"author": {
|
|
14
|
+
"type": "string",
|
|
15
|
+
"description": "作者,可选"
|
|
16
|
+
},
|
|
17
|
+
"date": {
|
|
18
|
+
"type": "string",
|
|
19
|
+
"description": "日期,统一 yyyy-mm-dd,可选"
|
|
20
|
+
},
|
|
21
|
+
"url": {
|
|
22
|
+
"type": "string",
|
|
23
|
+
"description": "文章链接,可选"
|
|
24
|
+
},
|
|
25
|
+
"blocks": {
|
|
26
|
+
"type": "array",
|
|
27
|
+
"description": "正文段落,type/value 交替数组",
|
|
28
|
+
"items": {
|
|
29
|
+
"type": "object",
|
|
30
|
+
"properties": {
|
|
31
|
+
"type": {
|
|
32
|
+
"type": "string",
|
|
33
|
+
"enum": ["text", "image"],
|
|
34
|
+
"description": "段落类型:text 文本 / image 图片"
|
|
35
|
+
},
|
|
36
|
+
"value": {
|
|
37
|
+
"type": "string",
|
|
38
|
+
"description": "文本内容或图片地址"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"required": ["type", "value"],
|
|
42
|
+
"additionalProperties": false
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"required": ["blocks"],
|
|
47
|
+
"additionalProperties": false
|
|
48
|
+
}
|
|
49
49
|
}
|
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
import { fileURLToPath } from 'url';
|
|
2
|
-
import * as cheerio from 'cheerio';
|
|
3
|
-
|
|
4
|
-
const IMG_RE = /<img\s[^>]*src=["'](.*?)["'][^>]*>/gi;
|
|
5
|
-
|
|
6
|
-
export function extractDetail(html, maxLength = -1, maxImageCount = -1) {
|
|
7
|
-
if (!html || !html.trim()) return { paras: [] };
|
|
8
|
-
|
|
9
|
-
const parts = html.split(IMG_RE);
|
|
10
|
-
const rawParas = [];
|
|
11
|
-
|
|
12
|
-
for (let i = 0; i < parts.length; i++) {
|
|
13
|
-
if (i % 2 === 0) {
|
|
14
|
-
const text = cleanText(parts[i]);
|
|
15
|
-
if (text) rawParas.push({ type: 'text', value: text });
|
|
16
|
-
} else {
|
|
17
|
-
const imgUrl = (parts[i] || '').trim();
|
|
18
|
-
if (imgUrl) rawParas.push({ type: 'image', value: imgUrl });
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return { paras: applyLimits(rawParas, maxLength, maxImageCount) };
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function cleanText(raw) {
|
|
26
|
-
const $ = cheerio.load(raw);
|
|
27
|
-
let text = $.text();
|
|
28
|
-
text = text.replace(/\s+/g, ' ').trim();
|
|
29
|
-
return text;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function applyLimits(paras, maxLength, maxImageCount) {
|
|
33
|
-
if (maxLength === -1 && maxImageCount === -1) return paras;
|
|
34
|
-
const result = [];
|
|
35
|
-
let accLen = 0;
|
|
36
|
-
let imgCount = 0;
|
|
37
|
-
|
|
38
|
-
for (const entry of paras) {
|
|
39
|
-
if (entry.type === 'image') {
|
|
40
|
-
if (maxImageCount !== -1 && imgCount >= maxImageCount) break;
|
|
41
|
-
if (maxLength !== -1 && accLen >= maxLength) break;
|
|
42
|
-
imgCount++;
|
|
43
|
-
result.push(entry);
|
|
44
|
-
} else {
|
|
45
|
-
let text = entry.value;
|
|
46
|
-
if (maxLength !== -1) {
|
|
47
|
-
if (accLen >= maxLength) break;
|
|
48
|
-
const remaining = maxLength - accLen;
|
|
49
|
-
if (text.length > remaining) {
|
|
50
|
-
text = text.slice(0, remaining);
|
|
51
|
-
result.push({ type: 'text', value: text });
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
result.push({ type: 'text', value: text });
|
|
56
|
-
accLen += text.length;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return result;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function main() {
|
|
63
|
-
const chunks = [];
|
|
64
|
-
process.stdin.on('data', chunk => chunks.push(chunk));
|
|
65
|
-
process.stdin.on('end', () => {
|
|
66
|
-
const html = Buffer.concat(chunks).toString();
|
|
67
|
-
process.stdout.write(JSON.stringify(extractDetail(html), null, 2));
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export default extractDetail;
|
|
1
|
+
import { fileURLToPath } from 'url';
|
|
2
|
+
import * as cheerio from 'cheerio';
|
|
3
|
+
|
|
4
|
+
const IMG_RE = /<img\s[^>]*src=["'](.*?)["'][^>]*>/gi;
|
|
5
|
+
|
|
6
|
+
export function extractDetail(html, maxLength = -1, maxImageCount = -1) {
|
|
7
|
+
if (!html || !html.trim()) return { paras: [] };
|
|
8
|
+
|
|
9
|
+
const parts = html.split(IMG_RE);
|
|
10
|
+
const rawParas = [];
|
|
11
|
+
|
|
12
|
+
for (let i = 0; i < parts.length; i++) {
|
|
13
|
+
if (i % 2 === 0) {
|
|
14
|
+
const text = cleanText(parts[i]);
|
|
15
|
+
if (text) rawParas.push({ type: 'text', value: text });
|
|
16
|
+
} else {
|
|
17
|
+
const imgUrl = (parts[i] || '').trim();
|
|
18
|
+
if (imgUrl) rawParas.push({ type: 'image', value: imgUrl });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return { paras: applyLimits(rawParas, maxLength, maxImageCount) };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function cleanText(raw) {
|
|
26
|
+
const $ = cheerio.load(raw);
|
|
27
|
+
let text = $.text();
|
|
28
|
+
text = text.replace(/\s+/g, ' ').trim();
|
|
29
|
+
return text;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function applyLimits(paras, maxLength, maxImageCount) {
|
|
33
|
+
if (maxLength === -1 && maxImageCount === -1) return paras;
|
|
34
|
+
const result = [];
|
|
35
|
+
let accLen = 0;
|
|
36
|
+
let imgCount = 0;
|
|
37
|
+
|
|
38
|
+
for (const entry of paras) {
|
|
39
|
+
if (entry.type === 'image') {
|
|
40
|
+
if (maxImageCount !== -1 && imgCount >= maxImageCount) break;
|
|
41
|
+
if (maxLength !== -1 && accLen >= maxLength) break;
|
|
42
|
+
imgCount++;
|
|
43
|
+
result.push(entry);
|
|
44
|
+
} else {
|
|
45
|
+
let text = entry.value;
|
|
46
|
+
if (maxLength !== -1) {
|
|
47
|
+
if (accLen >= maxLength) break;
|
|
48
|
+
const remaining = maxLength - accLen;
|
|
49
|
+
if (text.length > remaining) {
|
|
50
|
+
text = text.slice(0, remaining);
|
|
51
|
+
result.push({ type: 'text', value: text });
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
result.push({ type: 'text', value: text });
|
|
56
|
+
accLen += text.length;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function main() {
|
|
63
|
+
const chunks = [];
|
|
64
|
+
process.stdin.on('data', chunk => chunks.push(chunk));
|
|
65
|
+
process.stdin.on('end', () => {
|
|
66
|
+
const html = Buffer.concat(chunks).toString();
|
|
67
|
+
process.stdout.write(JSON.stringify(extractDetail(html), null, 2));
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export default extractDetail;
|
|
72
72
|
if (process.argv[1] === fileURLToPath(import.meta.url)) main();
|