@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.
Files changed (173) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +128 -128
  3. package/agents/scrum.md +186 -180
  4. package/agents/sprint.md +121 -118
  5. package/bin/index.js +226 -226
  6. package/commands/fix.md +87 -87
  7. package/commands/git-sync.md +217 -217
  8. package/commands/net-port.md +364 -364
  9. package/commands/pytest.md +10 -10
  10. package/commands/resume.md +104 -104
  11. package/commands/tl.md +11 -11
  12. package/package.json +8 -7
  13. package/plugin.js +19 -19
  14. package/readme/development.md +39 -39
  15. package/readme/publish.md +41 -41
  16. package/readme/testing.md +44 -36
  17. package/scripts/postinstall.js +58 -58
  18. package/skills/better-skill/SKILL.md +124 -124
  19. package/skills/blame-skill/SKILL.md +201 -201
  20. package/skills/extract/SKILL.md +119 -119
  21. package/skills/extract/references/build-xpath.js +30 -30
  22. package/skills/extract/references/clean-html.js +90 -90
  23. package/skills/extract/references/detail.md +54 -54
  24. package/skills/extract/references/detail.schema.json5 +48 -48
  25. package/skills/extract/references/extract-detail.js +71 -71
  26. package/skills/extract/references/extract-regex.js +81 -81
  27. package/skills/extract/references/extract-sample.js +48 -48
  28. package/skills/extract/references/list-rule-gen.md +109 -109
  29. package/skills/extract/references/list.md +134 -134
  30. package/skills/extract/references/list.schema.json5 +33 -33
  31. package/skills/extract/references/navi.md +44 -44
  32. package/skills/extract/references/navi.schema.json5 +23 -23
  33. package/skills/extract/references/text.md +40 -40
  34. package/skills/extract/references/text.schema.json5 +21 -21
  35. package/skills/extract/references/to-text.js +20 -20
  36. package/skills/extract/references/validate-schema.js +39 -39
  37. package/skills/jstest/SKILL.md +561 -561
  38. package/skills/jstest/references/case-create.md +327 -327
  39. package/skills/jstest/references/case-fix.md +273 -273
  40. package/skills/jstest/references/config.md +148 -148
  41. package/skills/jstest/references/coverage-analyze.md +247 -247
  42. package/skills/jstest/references/env-ensure.md +210 -210
  43. package/skills/jstest/references/execute.md +168 -168
  44. package/skills/jstest/references/sample.md +166 -166
  45. package/skills/jstest/references/scoring-rules.md +75 -75
  46. package/skills/jstest/references/src/jstest-sample/Calculator.js +80 -80
  47. package/skills/jstest/references/src/jstest-sample/ConfigManager.js +72 -72
  48. package/skills/jstest/references/src/jstest-sample/FileProcessor.js +57 -57
  49. package/skills/jstest/references/src/jstest-sample/OrderService.js +98 -98
  50. package/skills/jstest/references/src/jstest-sample/TokenGenerator.js +60 -60
  51. package/skills/jstest/references/src/jstest-sample/UserService.js +56 -56
  52. package/skills/jstest/references/src/jstest-sample/index.js +6 -6
  53. package/skills/jstest/references/suitability-check.md +232 -232
  54. package/skills/jstest/references/test-standards.md +288 -288
  55. package/skills/lint/SKILL.md +440 -440
  56. package/skills/lint/references/ai-fix.md +137 -137
  57. package/skills/lint/references/config-setup.md +102 -102
  58. package/skills/lint/references/config.md +65 -65
  59. package/skills/lint/references/detect-language.js +65 -65
  60. package/skills/lint/references/env-ensure.md +88 -88
  61. package/skills/lint/references/language-detect.md +75 -75
  62. package/skills/lint/references/languages/js.md +110 -110
  63. package/skills/lint/references/languages/py.md +89 -89
  64. package/skills/lint/references/rules-analyze.md +125 -125
  65. package/skills/lint/references/suitability-check.md +81 -81
  66. package/skills/lint/references/tool-fix.md +90 -90
  67. package/skills/new-skill/SKILL.md +227 -227
  68. package/skills/new-skill/references/template.md +53 -53
  69. package/skills/new-skill/references/workflow-patterns.md +104 -104
  70. package/skills/pytest/SKILL.md +555 -555
  71. package/skills/pytest/references/case-create.md +324 -324
  72. package/skills/pytest/references/case-fix.md +271 -271
  73. package/skills/pytest/references/config.md +145 -145
  74. package/skills/pytest/references/coverage-analyze.md +223 -223
  75. package/skills/pytest/references/env-ensure.md +195 -195
  76. package/skills/pytest/references/execute.md +152 -152
  77. package/skills/pytest/references/sample.md +159 -159
  78. package/skills/pytest/references/scoring-rules.md +57 -57
  79. package/skills/pytest/references/src/pytest-sample/Calculator.py +67 -67
  80. package/skills/pytest/references/src/pytest-sample/ConfigManager.py +68 -68
  81. package/skills/pytest/references/src/pytest-sample/FileProcessor.py +53 -53
  82. package/skills/pytest/references/src/pytest-sample/OrderService.py +82 -82
  83. package/skills/pytest/references/src/pytest-sample/TokenGenerator.py +50 -50
  84. package/skills/pytest/references/src/pytest-sample/UserService.py +45 -45
  85. package/skills/pytest/references/suitability-check.md +220 -220
  86. package/skills/pytest/references/test-standards.md +244 -244
  87. package/skills/query/SKILL.md +71 -71
  88. package/skills/read-docs/SKILL.md +134 -134
  89. package/skills/read-docs/references/opencode/agents/cases.md +206 -206
  90. package/skills/read-docs/references/opencode/agents/design-pattern.md +47 -47
  91. package/skills/read-docs/references/opencode/agents/detail.md +191 -191
  92. package/skills/read-docs/references/opencode/agents/examples.md +100 -100
  93. package/skills/read-docs/references/opencode/agents/index.md +309 -309
  94. package/skills/read-docs/references/opencode/agents/parallel-dispatch.md +149 -149
  95. package/skills/read-docs/references/opencode/agents/subagent-internals.md +217 -217
  96. package/skills/read-docs/references/opencode/agents/workflow.md +161 -161
  97. package/skills/read-docs/references/opencode/cli/commands/acp.md +31 -31
  98. package/skills/read-docs/references/opencode/cli/commands/agent.md +16 -16
  99. package/skills/read-docs/references/opencode/cli/commands/attach.md +20 -20
  100. package/skills/read-docs/references/opencode/cli/commands/mcp.md +37 -37
  101. package/skills/read-docs/references/opencode/cli/commands/others.md +48 -48
  102. package/skills/read-docs/references/opencode/cli/commands/plugin.md +12 -12
  103. package/skills/read-docs/references/opencode/cli/commands/provider.md +43 -43
  104. package/skills/read-docs/references/opencode/cli/commands/run.md +81 -81
  105. package/skills/read-docs/references/opencode/cli/commands/serve.md +84 -84
  106. package/skills/read-docs/references/opencode/cli/commands/session.md +37 -37
  107. package/skills/read-docs/references/opencode/cli/commands/web.md +14 -14
  108. package/skills/read-docs/references/opencode/cli/env.md +38 -38
  109. package/skills/read-docs/references/opencode/cli/index.md +18 -18
  110. package/skills/read-docs/references/opencode/cli/tui.md +35 -35
  111. package/skills/read-docs/references/opencode/commands/examples.md +42 -42
  112. package/skills/read-docs/references/opencode/commands/index.md +185 -185
  113. package/skills/read-docs/references/opencode/config/provider.md +151 -151
  114. package/skills/read-docs/references/opencode/formatter/index.md +70 -70
  115. package/skills/read-docs/references/opencode/guide/config.md +419 -419
  116. package/skills/read-docs/references/opencode/guide/formatters.md +70 -70
  117. package/skills/read-docs/references/opencode/guide/index.md +37 -37
  118. package/skills/read-docs/references/opencode/guide/providers.md +31 -31
  119. package/skills/read-docs/references/opencode/guide/rules.md +63 -63
  120. package/skills/read-docs/references/opencode/plugins/examples.md +75 -75
  121. package/skills/read-docs/references/opencode/plugins/index.md +188 -188
  122. package/skills/read-docs/references/opencode/reference/index.md +118 -118
  123. package/skills/read-docs/references/opencode/rule/index.md +77 -77
  124. package/skills/read-docs/references/opencode/skills/detail.md +113 -113
  125. package/skills/read-docs/references/opencode/skills/examples.md +141 -141
  126. package/skills/read-docs/references/opencode/skills/index.md +126 -126
  127. package/skills/read-docs/references/opencode/skills/workflow.md +146 -146
  128. package/skills/read-docs/references/opencode/tests/agent.md +9 -9
  129. package/skills/read-docs/references/opencode/tests/config.md +59 -59
  130. package/skills/read-docs/references/opencode/tests/file.md +11 -11
  131. package/skills/read-docs/references/opencode/tests/serve.md +17 -17
  132. package/skills/read-docs/references/opencode/tests/session.md +30 -30
  133. package/skills/read-docs/references/opencode/tests/web.md +16 -16
  134. package/skills/read-docs/references/opencode/tools/arguments.md +305 -305
  135. package/skills/read-docs/references/opencode/tools/context.md +17 -17
  136. package/skills/read-docs/references/opencode/tools/custom.md +110 -110
  137. package/skills/read-docs/references/opencode/tools/detail.md +104 -104
  138. package/skills/read-docs/references/opencode/tools/examples.md +71 -71
  139. package/skills/read-docs/references/opencode/tools/index.md +56 -56
  140. package/skills/read-docs/references/opencode/tools/lsp.md +25 -25
  141. package/skills/read-docs/references/opencode/tools/mcp.md +132 -132
  142. package/skills/read-docs/references/opencode/train/README.md +134 -134
  143. package/skills/read-docs/references/opencode/train/agent-basic.md +771 -771
  144. package/skills/read-docs/references/opencode/train/command-basic.md +667 -667
  145. package/skills/read-docs/references/opencode/train/config-basic.md +508 -508
  146. package/skills/read-docs/references/opencode/train/index.md +163 -163
  147. package/skills/read-docs/references/opencode/train/practice.md +872 -872
  148. package/skills/read-docs/references/opencode/train/skill-basic.md +607 -607
  149. package/skills/read-docs/references/opencode/tui/commands/config.md +31 -31
  150. package/skills/read-docs/references/opencode/tui/commands/editor.md +46 -46
  151. package/skills/read-docs/references/opencode/tui/commands/index.md +124 -124
  152. package/skills/read-docs/references/opencode/tui/commands/init.md +4 -4
  153. package/skills/read-docs/references/opencode/tui/index.md +26 -26
  154. package/skills/read-docs/references/superpowers/bootstrap.md +107 -107
  155. package/skills/read-docs/references/superpowers/comparison.md +77 -77
  156. package/skills/read-docs/references/superpowers/context.md +71 -71
  157. package/skills/read-docs/references/superpowers/index.md +58 -58
  158. package/skills/read-docs/references/superpowers/parallel.md +49 -49
  159. package/skills/read-docs/references/superpowers/sdd.md +183 -183
  160. package/skills/read-docs/references/superpowers/skills.md +68 -68
  161. package/skills/read-docs/references/superpowers/workflow.md +83 -83
  162. package/skills/revise/SKILL.md +121 -121
  163. package/skills/revise/references/article.md +36 -36
  164. package/skills/revise/references/article.schema.json5 +40 -40
  165. package/skills/revise/references/gallery.md +34 -34
  166. package/skills/revise/references/gallery.schema.json5 +40 -40
  167. package/skills/revise/references/question.md +32 -32
  168. package/skills/revise/references/question.schema.json5 +31 -31
  169. package/skills/revise/references/status.md +31 -31
  170. package/skills/revise/references/status.schema.json5 +27 -27
  171. package/skills/revise/references/validate-schema.js +39 -39
  172. package/src/config.js +29 -29
  173. package/src/config.json5 +19 -19
@@ -1,82 +1,82 @@
1
- import { fileURLToPath } from 'url';
2
-
3
- export function extractRegex(html, rules) {
4
- if (!html || !rules) return [];
5
-
6
- const { container_regex, fields } = rules;
7
- if (!container_regex || !fields) return [];
8
-
9
- const containerPattern = new RegExp(container_regex, 'gs');
10
- const items = [];
11
- let match;
12
-
13
- while ((match = containerPattern.exec(html)) !== null) {
14
- const block = match[1] !== undefined ? match[1] : match[0];
15
- const item = {};
16
-
17
- for (const [fieldName, fieldPattern] of Object.entries(fields)) {
18
- if (fieldPattern) {
19
- const fm = new RegExp(fieldPattern, 's').exec(block);
20
- if (fm) {
21
- item[fieldName] = (fm[1] !== undefined ? fm[1] : fm[0]).trim();
22
- } else {
23
- item[fieldName] = '';
24
- }
25
- } else {
26
- item[fieldName] = '';
27
- }
28
- }
29
-
30
- item.selector = makeSelector(item.title || '');
31
- items.push(item);
32
- }
33
-
34
- return items;
35
- }
36
-
37
- const CURLY_CHARS = '\u201c\u201d\u2018\u2019';
38
- const EXCLUDE = ' and not(ancestor::script)';
39
-
40
- function makeSelector(title) {
41
- if (!title) return '';
42
- const hasCurly = [...CURLY_CHARS].some(c => title.includes(c));
43
-
44
- if (!hasCurly) {
45
- if (!title.includes("'")) return `//text()[contains(.,'${title}')${EXCLUDE}]/..`;
46
- if (!title.includes('"')) return `//text()[contains(.,"${title}")${EXCLUDE}]/..`;
47
- const parts = title.split("'");
48
- const inner = parts.map(p => `'${p}'`).join(",\"'\",");
49
- return `//text()[contains(.,concat(${inner}))${EXCLUDE}]/..`;
50
- }
51
-
52
- const allQuotes = CURLY_CHARS + '"\'';
53
- const segs = title.split(new RegExp(`[${allQuotes}]+`)).filter(Boolean);
54
- if (!segs.length) return '';
55
-
56
- const clauses = segs.map(s => {
57
- if (!s.includes("'")) return `contains(.,'${s}')`;
58
- if (!s.includes('"')) return `contains(.,"${s}")`;
59
- const sub = s.split("'");
60
- const inner = sub.map(p => `'${p}'`).join(",\"'\",");
61
- return `contains(.,concat(${inner}))`;
62
- });
63
-
64
- return `//text()[${clauses.join(' and ')}${EXCLUDE}]/..`;
65
- }
66
-
67
- function main() {
68
- const chunks = [];
69
- process.stdin.on('data', chunk => chunks.push(chunk));
70
- process.stdin.on('end', () => {
71
- try {
72
- const input = JSON.parse(Buffer.concat(chunks).toString());
73
- const result = extractRegex(input.html, input.rules);
74
- process.stdout.write(JSON.stringify(result, null, 2));
75
- } catch (e) {
76
- process.stdout.write('[]');
77
- }
78
- });
79
- }
80
-
81
- export { makeSelector };
1
+ import { fileURLToPath } from 'url';
2
+
3
+ export function extractRegex(html, rules) {
4
+ if (!html || !rules) return [];
5
+
6
+ const { container_regex, fields } = rules;
7
+ if (!container_regex || !fields) return [];
8
+
9
+ const containerPattern = new RegExp(container_regex, 'gs');
10
+ const items = [];
11
+ let match;
12
+
13
+ while ((match = containerPattern.exec(html)) !== null) {
14
+ const block = match[1] !== undefined ? match[1] : match[0];
15
+ const item = {};
16
+
17
+ for (const [fieldName, fieldPattern] of Object.entries(fields)) {
18
+ if (fieldPattern) {
19
+ const fm = new RegExp(fieldPattern, 's').exec(block);
20
+ if (fm) {
21
+ item[fieldName] = (fm[1] !== undefined ? fm[1] : fm[0]).trim();
22
+ } else {
23
+ item[fieldName] = '';
24
+ }
25
+ } else {
26
+ item[fieldName] = '';
27
+ }
28
+ }
29
+
30
+ item.selector = makeSelector(item.title || '');
31
+ items.push(item);
32
+ }
33
+
34
+ return items;
35
+ }
36
+
37
+ const CURLY_CHARS = '\u201c\u201d\u2018\u2019';
38
+ const EXCLUDE = ' and not(ancestor::script)';
39
+
40
+ function makeSelector(title) {
41
+ if (!title) return '';
42
+ const hasCurly = [...CURLY_CHARS].some(c => title.includes(c));
43
+
44
+ if (!hasCurly) {
45
+ if (!title.includes("'")) return `//text()[contains(.,'${title}')${EXCLUDE}]/..`;
46
+ if (!title.includes('"')) return `//text()[contains(.,"${title}")${EXCLUDE}]/..`;
47
+ const parts = title.split("'");
48
+ const inner = parts.map(p => `'${p}'`).join(",\"'\",");
49
+ return `//text()[contains(.,concat(${inner}))${EXCLUDE}]/..`;
50
+ }
51
+
52
+ const allQuotes = CURLY_CHARS + '"\'';
53
+ const segs = title.split(new RegExp(`[${allQuotes}]+`)).filter(Boolean);
54
+ if (!segs.length) return '';
55
+
56
+ const clauses = segs.map(s => {
57
+ if (!s.includes("'")) return `contains(.,'${s}')`;
58
+ if (!s.includes('"')) return `contains(.,"${s}")`;
59
+ const sub = s.split("'");
60
+ const inner = sub.map(p => `'${p}'`).join(",\"'\",");
61
+ return `contains(.,concat(${inner}))`;
62
+ });
63
+
64
+ return `//text()[${clauses.join(' and ')}${EXCLUDE}]/..`;
65
+ }
66
+
67
+ function main() {
68
+ const chunks = [];
69
+ process.stdin.on('data', chunk => chunks.push(chunk));
70
+ process.stdin.on('end', () => {
71
+ try {
72
+ const input = JSON.parse(Buffer.concat(chunks).toString());
73
+ const result = extractRegex(input.html, input.rules);
74
+ process.stdout.write(JSON.stringify(result, null, 2));
75
+ } catch (e) {
76
+ process.stdout.write('[]');
77
+ }
78
+ });
79
+ }
80
+
81
+ export { makeSelector };
82
82
  if (process.argv[1] === fileURLToPath(import.meta.url)) main();
@@ -1,49 +1,49 @@
1
- import { fileURLToPath } from 'url';
2
- import * as cheerio from 'cheerio';
3
- import { cleanHtml } from './clean-html.js';
4
-
5
- export function extractSample(html, keepItems = 3) {
6
- const cleaned = cleanHtml(html);
7
- const $ = cheerio.load(cleaned);
8
-
9
- // Find content items: look for list items or repeated block elements
10
- const items = [];
11
-
12
- // Try <li> first
13
- $('li').each((i, el) => {
14
- if (items.length < keepItems) items.push($(el).html() || '');
15
- });
16
-
17
- if (items.length > 0) {
18
- return `<ul>${items.map(item => `<li>${item}</li>`).join('')}</ul>`;
19
- }
20
-
21
- // Fallback: look for repeated block elements
22
- const blockTags = ['p', 'div', 'section', 'article', 'tr', 'td'];
23
- for (const tag of blockTags) {
24
- items.length = 0;
25
- $(tag).each((i, el) => {
26
- if (items.length < keepItems) items.push($.html(el));
27
- });
28
- if (items.length > 0) break;
29
- }
30
-
31
- return items.join('\n');
32
- }
33
-
34
- function main() {
35
- const chunks = [];
36
- process.stdin.on('data', chunk => chunks.push(chunk));
37
- process.stdin.on('end', () => {
38
- try {
39
- const input = JSON.parse(Buffer.concat(chunks).toString());
40
- const result = extractSample(input.html, input.keep_items || 3);
41
- process.stdout.write(result);
42
- } catch (e) {
43
- process.stdout.write('');
44
- }
45
- });
46
- }
47
-
48
- export default extractSample;
1
+ import { fileURLToPath } from 'url';
2
+ import * as cheerio from 'cheerio';
3
+ import { cleanHtml } from './clean-html.js';
4
+
5
+ export function extractSample(html, keepItems = 3) {
6
+ const cleaned = cleanHtml(html);
7
+ const $ = cheerio.load(cleaned);
8
+
9
+ // Find content items: look for list items or repeated block elements
10
+ const items = [];
11
+
12
+ // Try <li> first
13
+ $('li').each((i, el) => {
14
+ if (items.length < keepItems) items.push($(el).html() || '');
15
+ });
16
+
17
+ if (items.length > 0) {
18
+ return `<ul>${items.map(item => `<li>${item}</li>`).join('')}</ul>`;
19
+ }
20
+
21
+ // Fallback: look for repeated block elements
22
+ const blockTags = ['p', 'div', 'section', 'article', 'tr', 'td'];
23
+ for (const tag of blockTags) {
24
+ items.length = 0;
25
+ $(tag).each((i, el) => {
26
+ if (items.length < keepItems) items.push($.html(el));
27
+ });
28
+ if (items.length > 0) break;
29
+ }
30
+
31
+ return items.join('\n');
32
+ }
33
+
34
+ function main() {
35
+ const chunks = [];
36
+ process.stdin.on('data', chunk => chunks.push(chunk));
37
+ process.stdin.on('end', () => {
38
+ try {
39
+ const input = JSON.parse(Buffer.concat(chunks).toString());
40
+ const result = extractSample(input.html, input.keep_items || 3);
41
+ process.stdout.write(result);
42
+ } catch (e) {
43
+ process.stdout.write('');
44
+ }
45
+ });
46
+ }
47
+
48
+ export default extractSample;
49
49
  if (process.argv[1] === fileURLToPath(import.meta.url)) main();
@@ -1,109 +1,109 @@
1
- # 规则生成指导
2
-
3
- ## 你的角色
4
-
5
- 你是一个 HTML 结构分析专家。给你一段(仅前几项的)HTML 样本,你需要分析其重复结构并生成正则提取规则。
6
-
7
- ## 输入数据
8
-
9
- - **source**:干净的 HTML 片段(移除了 script/style/注释,仅含前若干条记录)。≥ 2 条时通过对比识别容器边界最准确;仅 1 条时需基于标签结构的层级关系推断容器模式
10
- - **fields**:需要提取的字段及其语义说明,例如 `{"title": "新闻标题", "author": "作者名"}`。LLM 据此在 HTML 中定位对应内容并编写正则
11
- - **path**(可选,框架级参数,LLM 无需处理):指定时将规则写入该文件,否则直接输出
12
-
13
- ## 输出格式
14
-
15
- 必须是严格 JSON,不含任何其他内容。`fields` 的 key 与输入 `fields` 的 key 完全一致:
16
-
17
- ```json
18
- {
19
- "container_regex": "用于匹配每条容器的正则表达式,必须包含至少一个捕获组(group 1)",
20
- "fields": {
21
- "<field_name_1>": "对应输入字段的正则提取规则",
22
- "<field_name_2>": "..."
23
- }
24
- }
25
- ```
26
-
27
- ## 正则编写规则
28
-
29
- ### 容器正则(container_regex)
30
-
31
- - 必须匹配列表中**每一条完整记录**的 HTML 块
32
- - 必须包含**一个捕获组 `(.*?)`**,代表单条记录的内部内容
33
- - 使用 `.*?`(非贪婪)避免跨记录匹配
34
- - 示例:
35
- - `<li class="item">(.*?)</li>`
36
- - `<div class="card"[^>]*>(.*?)</div>\s*`
37
- - `<tr[^>]*>(.*?)</tr>`
38
-
39
- ### 字段正则(fields)
40
-
41
- - 基于容器捕获组的内部内容编写
42
- - 使用具体标签名和 CSS 类名定位
43
- - 优先用 `<h1~6>`、`<a>` 提取标题
44
- - 用 `<time[datetime]>`、`<span[class~=date]>` 提取日期
45
- - 用 `<a[href]>` 提取链接
46
- - 用 `<img[src]>` 提取图片
47
- - 字段不存在时值留空字符串 `""`
48
- - **捕获组规则**:字段正则若有捕获组,提取值取 `group(1)`;建议每个字段正则只含 **1 个捕获组**。
49
- > 反例:`<a href="(.*?)"[^>]*>(.*?)</a>` 含 2 个捕获组(href、文本),代码会静默取 `group(1)`(href)而非标题文本,与预期不符。应写为 `<a[^>]*>(.*?)</a>` 只捕获标签文本。
50
-
51
- ### 常见模式(参考示例,非固定字段集)
52
-
53
- > **重要**:以下仅为正则写法范式。实际 class 名、标签层级必须**基于输入样本的真实结构**编写,禁止照搬表中的 class 名。
54
-
55
- | 字段语义 | 典型正则 |
56
- |---------|---------|
57
- | 标题类 | `<h3[^>]*class="title"[^>]*>(.*?)</h3>` |
58
- | 作者类 | `<span[^>]*class="author"[^>]*>(.*?)</span>` |
59
- | 日期类 | `<time[^>]*datetime="(.*?)"` 或 `<span[^>]*class="date"[^>]*>(.*?)</span>` |
60
- | 链接类 | `<a[^>]*href="(.*?)"` |
61
- | 图片类 | `<img[^>]*src="(.*?)"` |
62
-
63
- ## 完整示例(以新闻列表字段为例)
64
-
65
- ### 输入
66
-
67
- `fields` = `{"title": "新闻标题", "author": "作者名", "date": "发布日期", "url": "文章链接", "thumb": "缩略图地址"}`
68
-
69
- ### 输入样本
70
-
71
- ```html
72
- <li class="news-item">
73
- <h3 class="title"><a href="/article/1">Title One</a></h3>
74
- <span class="author">Alice</span>
75
- <time datetime="2024-01-15">2024-01-15</time>
76
- <img src="/thumb/1.jpg" alt="thumb1">
77
- </li>
78
- <li class="news-item">
79
- <h3 class="title"><a href="/article/2">Title Two</a></h3>
80
- <span class="author">Bob</span>
81
- <time datetime="2024-01-16">2024-01-16</time>
82
- <img src="/thumb/2.jpg" alt="thumb2">
83
- </li>
84
- ```
85
-
86
- ### 输出规则
87
-
88
- ```json
89
- {
90
- "container_regex": "<li[^>]*class=\"news-item\"[^>]*>(.*?)</li>",
91
- "fields": {
92
- "title": "<h3[^>]*class=\"title\"[^>]*><a[^>]*>(.*?)</a></h3>",
93
- "author": "<span[^>]*class=\"author\"[^>]*>(.*?)</span>",
94
- "date": "<time[^>]*datetime=\"(.*?)\"",
95
- "url": "<a[^>]*href=\"(.*?)\"",
96
- "thumb": "<img[^>]*src=\"(.*?)\""
97
- }
98
- }
99
- ```
100
-
101
- ## 注意事项
102
-
103
- - **正则必须匹配清洗后 HTML**(等同 Step 3 中 `HtmlCleaner.clean()` 的输出口径),包括属性中的引号和空格
104
- - **自我验证**:产出规则后,在输入的样本上跑一遍——`container_regex` 至少匹配 1 条、每个字段至少有一条非空命中。不满足则调整规则
105
- - `container_regex` 的捕获组数量必须 >= 1
106
- - 字段正则可能匹配到空值(如空 `<span></span>`),此时提取为空字符串
107
- - 日期保留原始格式即可,规范化由下游处理
108
- - 链接和图片如果相对路径,保留原始值
109
- - **嵌套容器陷阱**:如果容器标签可能自嵌套(如 `<div>` 内嵌 `<div>`),`.*?` 非贪婪会在第一个闭合标签处提前闭合,导致匹配截断。优先选择不会自嵌套的标签(如 `<li>` 罕见包 `<li>`),或对容器用更具体的 class 锚定
1
+ # 规则生成指导
2
+
3
+ ## 你的角色
4
+
5
+ 你是一个 HTML 结构分析专家。给你一段(仅前几项的)HTML 样本,你需要分析其重复结构并生成正则提取规则。
6
+
7
+ ## 输入数据
8
+
9
+ - **source**:干净的 HTML 片段(移除了 script/style/注释,仅含前若干条记录)。≥ 2 条时通过对比识别容器边界最准确;仅 1 条时需基于标签结构的层级关系推断容器模式
10
+ - **fields**:需要提取的字段及其语义说明,例如 `{"title": "新闻标题", "author": "作者名"}`。LLM 据此在 HTML 中定位对应内容并编写正则
11
+ - **path**(可选,框架级参数,LLM 无需处理):指定时将规则写入该文件,否则直接输出
12
+
13
+ ## 输出格式
14
+
15
+ 必须是严格 JSON,不含任何其他内容。`fields` 的 key 与输入 `fields` 的 key 完全一致:
16
+
17
+ ```json
18
+ {
19
+ "container_regex": "用于匹配每条容器的正则表达式,必须包含至少一个捕获组(group 1)",
20
+ "fields": {
21
+ "<field_name_1>": "对应输入字段的正则提取规则",
22
+ "<field_name_2>": "..."
23
+ }
24
+ }
25
+ ```
26
+
27
+ ## 正则编写规则
28
+
29
+ ### 容器正则(container_regex)
30
+
31
+ - 必须匹配列表中**每一条完整记录**的 HTML 块
32
+ - 必须包含**一个捕获组 `(.*?)`**,代表单条记录的内部内容
33
+ - 使用 `.*?`(非贪婪)避免跨记录匹配
34
+ - 示例:
35
+ - `<li class="item">(.*?)</li>`
36
+ - `<div class="card"[^>]*>(.*?)</div>\s*`
37
+ - `<tr[^>]*>(.*?)</tr>`
38
+
39
+ ### 字段正则(fields)
40
+
41
+ - 基于容器捕获组的内部内容编写
42
+ - 使用具体标签名和 CSS 类名定位
43
+ - 优先用 `<h1~6>`、`<a>` 提取标题
44
+ - 用 `<time[datetime]>`、`<span[class~=date]>` 提取日期
45
+ - 用 `<a[href]>` 提取链接
46
+ - 用 `<img[src]>` 提取图片
47
+ - 字段不存在时值留空字符串 `""`
48
+ - **捕获组规则**:字段正则若有捕获组,提取值取 `group(1)`;建议每个字段正则只含 **1 个捕获组**。
49
+ > 反例:`<a href="(.*?)"[^>]*>(.*?)</a>` 含 2 个捕获组(href、文本),代码会静默取 `group(1)`(href)而非标题文本,与预期不符。应写为 `<a[^>]*>(.*?)</a>` 只捕获标签文本。
50
+
51
+ ### 常见模式(参考示例,非固定字段集)
52
+
53
+ > **重要**:以下仅为正则写法范式。实际 class 名、标签层级必须**基于输入样本的真实结构**编写,禁止照搬表中的 class 名。
54
+
55
+ | 字段语义 | 典型正则 |
56
+ |---------|---------|
57
+ | 标题类 | `<h3[^>]*class="title"[^>]*>(.*?)</h3>` |
58
+ | 作者类 | `<span[^>]*class="author"[^>]*>(.*?)</span>` |
59
+ | 日期类 | `<time[^>]*datetime="(.*?)"` 或 `<span[^>]*class="date"[^>]*>(.*?)</span>` |
60
+ | 链接类 | `<a[^>]*href="(.*?)"` |
61
+ | 图片类 | `<img[^>]*src="(.*?)"` |
62
+
63
+ ## 完整示例(以新闻列表字段为例)
64
+
65
+ ### 输入
66
+
67
+ `fields` = `{"title": "新闻标题", "author": "作者名", "date": "发布日期", "url": "文章链接", "thumb": "缩略图地址"}`
68
+
69
+ ### 输入样本
70
+
71
+ ```html
72
+ <li class="news-item">
73
+ <h3 class="title"><a href="/article/1">Title One</a></h3>
74
+ <span class="author">Alice</span>
75
+ <time datetime="2024-01-15">2024-01-15</time>
76
+ <img src="/thumb/1.jpg" alt="thumb1">
77
+ </li>
78
+ <li class="news-item">
79
+ <h3 class="title"><a href="/article/2">Title Two</a></h3>
80
+ <span class="author">Bob</span>
81
+ <time datetime="2024-01-16">2024-01-16</time>
82
+ <img src="/thumb/2.jpg" alt="thumb2">
83
+ </li>
84
+ ```
85
+
86
+ ### 输出规则
87
+
88
+ ```json
89
+ {
90
+ "container_regex": "<li[^>]*class=\"news-item\"[^>]*>(.*?)</li>",
91
+ "fields": {
92
+ "title": "<h3[^>]*class=\"title\"[^>]*><a[^>]*>(.*?)</a></h3>",
93
+ "author": "<span[^>]*class=\"author\"[^>]*>(.*?)</span>",
94
+ "date": "<time[^>]*datetime=\"(.*?)\"",
95
+ "url": "<a[^>]*href=\"(.*?)\"",
96
+ "thumb": "<img[^>]*src=\"(.*?)\""
97
+ }
98
+ }
99
+ ```
100
+
101
+ ## 注意事项
102
+
103
+ - **正则必须匹配清洗后 HTML**(等同 Step 3 中 `HtmlCleaner.clean()` 的输出口径),包括属性中的引号和空格
104
+ - **自我验证**:产出规则后,在输入的样本上跑一遍——`container_regex` 至少匹配 1 条、每个字段至少有一条非空命中。不满足则调整规则
105
+ - `container_regex` 的捕获组数量必须 >= 1
106
+ - 字段正则可能匹配到空值(如空 `<span></span>`),此时提取为空字符串
107
+ - 日期保留原始格式即可,规范化由下游处理
108
+ - 链接和图片如果相对路径,保留原始值
109
+ - **嵌套容器陷阱**:如果容器标签可能自嵌套(如 `<div>` 内嵌 `<div>`),`.*?` 非贪婪会在第一个闭合标签处提前闭合,导致匹配截断。优先选择不会自嵌套的标签(如 `<li>` 罕见包 `<li>`),或对容器用更具体的 class 锚定