@wwkit/harness 1.0.44 → 1.0.46

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 (105) hide show
  1. package/package.json +1 -1
  2. package/skills/blame-cleancode/plan.md +1408 -0
  3. package/skills/convert-files/scripts/convert.js +1 -1
  4. package/skills/pea/SKILL.md +15 -9
  5. package/skills/pea/references/tpl-prd/epic.md +10 -0
  6. package/skills/pea/references/tpl-prd/us.md +4 -4
  7. package/skills/peago/SKILL.md +113 -0
  8. package/skills/peago/references/extract/baseline.md +17 -0
  9. package/skills/peago/references/extract/spec.md +117 -0
  10. package/skills/peago/references/res2kb/spec.md +113 -0
  11. package/skills/peago/references/spec-format.md +123 -0
  12. package/skills/peago/references/translate/baseline.md +26 -0
  13. package/skills/peago/references/translate/spec.md +132 -0
  14. package/skills/shared/references/template/pea/spec-agile.md +123 -0
  15. package/skills/shared/references/template/pea/spec-common.md +93 -0
  16. package/skills/shared/scripts/format.md +1 -1
  17. package/skills/extract/SKILL.md +0 -251
  18. package/skills/extract/references/detail_schema.json5 +0 -49
  19. package/skills/extract/references/detail_workflow.md +0 -55
  20. package/skills/extract/references/list_rule_gen.md +0 -109
  21. package/skills/extract/references/list_schema.json5 +0 -34
  22. package/skills/extract/references/list_workflow.md +0 -135
  23. package/skills/extract/references/navi_schema.json5 +0 -23
  24. package/skills/extract/references/navi_workflow.md +0 -45
  25. package/skills/extract/references/planning_template.md +0 -206
  26. package/skills/extract/references/text_schema.json5 +0 -22
  27. package/skills/extract/references/text_workflow.md +0 -41
  28. package/skills/extract/scripts/build_xpath.js +0 -31
  29. package/skills/extract/scripts/clean_html.js +0 -91
  30. package/skills/extract/scripts/extract_detail.js +0 -72
  31. package/skills/extract/scripts/extract_regex.js +0 -82
  32. package/skills/extract/scripts/extract_sample.js +0 -49
  33. package/skills/extract/scripts/to_text.js +0 -21
  34. package/skills/extract/scripts/validate_schema.js +0 -40
  35. package/skills/revise/SKILL.md +0 -66
  36. package/skills/revise/references/article.md +0 -37
  37. package/skills/revise/references/article.schema.json5 +0 -40
  38. package/skills/revise/references/gallery.md +0 -35
  39. package/skills/revise/references/gallery.schema.json5 +0 -40
  40. package/skills/revise/references/question.md +0 -33
  41. package/skills/revise/references/question.schema.json5 +0 -31
  42. package/skills/revise/references/sprint_for_revise.md +0 -46
  43. package/skills/revise/references/status.md +0 -32
  44. package/skills/revise/references/status.schema.json5 +0 -27
  45. package/skills/revise/scripts/check_input_vars.js +0 -127
  46. package/skills/revise/scripts/init.js +0 -84
  47. package/skills/revise/scripts/resolve_run_vars.js +0 -71
  48. package/skills/revise/scripts/validate-schema.js +0 -94
  49. package/skills/translate/SKILL.md +0 -398
  50. package/skills/translate/app.json5 +0 -70
  51. package/skills/translate/package.json +0 -11
  52. package/skills/translate/references/failure-diagnosis.md +0 -43
  53. package/skills/translate/references/format-prompt.md +0 -62
  54. package/skills/translate/references/format-rules.md +0 -39
  55. package/skills/translate/references/global-review-rules.md +0 -23
  56. package/skills/translate/references/glossary-prompt.md +0 -86
  57. package/skills/translate/references/glossary-rules.md +0 -44
  58. package/skills/translate/references/prepare-prompt.md +0 -110
  59. package/skills/translate/references/prepare-rules.md +0 -20
  60. package/skills/translate/references/resume-detection.md +0 -51
  61. package/skills/translate/references/rulings.md +0 -15
  62. package/skills/translate/references/translation-prompt.md +0 -73
  63. package/skills/translate/references/translation-rules.md +0 -51
  64. package/skills/translate/scripts/check-boundaries.js +0 -169
  65. package/skills/translate/scripts/check-paragraphs.js +0 -71
  66. package/skills/translate/scripts/chunk-bilingual.js +0 -123
  67. package/skills/translate/scripts/chunk-text.js +0 -145
  68. package/skills/translate/scripts/clean-text.js +0 -121
  69. package/skills/translate/scripts/count-terms.js +0 -54
  70. package/skills/translate/scripts/extract-pdf.js +0 -94
  71. package/skills/translate/scripts/generate-review.js +0 -179
  72. package/skills/translate/scripts/init-progress.js +0 -144
  73. package/skills/translate/scripts/md-to-docx.js +0 -381
  74. package/skills/translate/scripts/merge-format.js +0 -110
  75. package/skills/translate/scripts/merge-result.js +0 -113
  76. package/skills/translate/scripts/verify-chunk.js +0 -185
  77. package/skills/translate/todos.md +0 -38
  78. package/skills/translate-file/SKILL.md +0 -45
  79. package/skills/translate-file/package.json +0 -10
  80. package/skills/translate-file/references/sprint_for_preprocess.md +0 -14
  81. package/skills/translate-file/references/sprint_for_teardown.md +0 -15
  82. package/skills/translate-file/references/sprint_for_translate.md +0 -74
  83. package/skills/translate-file/references/translation_prompt.md +0 -43
  84. package/skills/translate-file/scripts/check_input_vars.js +0 -53
  85. package/skills/translate-file/scripts/chunk_text.js +0 -167
  86. package/skills/translate-file/scripts/clean_text.js +0 -121
  87. package/skills/translate-file/scripts/extract.js +0 -98
  88. package/skills/translate-file/scripts/generate_review.js +0 -155
  89. package/skills/translate-file/scripts/init.js +0 -86
  90. package/skills/translate-file/scripts/merge_results.js +0 -112
  91. package/skills/translate-file/scripts/resolve_run_vars.js +0 -123
  92. package/skills/translate-file/scripts/verify_chunk.js +0 -144
  93. package/skills/translate-format/SKILL.md +0 -45
  94. package/skills/translate-format/references/format-prompt.md +0 -80
  95. package/skills/translate-format/references/format-rules.md +0 -39
  96. package/skills/translate-format/references/sprint_for_format.md +0 -208
  97. package/skills/translate-format/scripts/check-paragraphs.js +0 -81
  98. package/skills/translate-format/scripts/check_input_vars.js +0 -51
  99. package/skills/translate-format/scripts/chunk-bilingual.js +0 -135
  100. package/skills/translate-format/scripts/count-words.js +0 -38
  101. package/skills/translate-format/scripts/diagnose-failure.js +0 -54
  102. package/skills/translate-format/scripts/init.js +0 -71
  103. package/skills/translate-format/scripts/md-to-docx.js +0 -398
  104. package/skills/translate-format/scripts/merge-format.js +0 -118
  105. package/skills/translate-format/scripts/resolve_run_vars.js +0 -78
@@ -1,71 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * check-paragraphs.js — 段落数对比检查(ESM)
4
- *
5
- * 对比原文件和格式化文件的段落数,差异 > 5% 时报警(可能有内容丢失),但仍输出文件。
6
- * 段落定义与 chunk-bilingual.js 一致:按空行(\n\n+)分隔的非空文本块。
7
- *
8
- * 用法:node check-paragraphs.js <original.md> <formatted.md>
9
- * stdout: `paragraphs: orig=N fmt=M diff=X% OK` 或 `paragraphs: orig=N fmt=M diff=X% WARN`
10
- * 退出码:0(OK 或 WARN),1(参数错误/文件不存在)
11
- */
12
-
13
- import { readFileSync, existsSync } from 'fs';
14
-
15
- /**
16
- * 统计文本的段落数。
17
- * 段落定义与 chunk-bilingual.js 一致:按 \n\n+ 分隔的非空文本块。
18
- * @param {string} content — 文本内容
19
- * @returns {number} 段落数
20
- */
21
- export function countParagraphs(content) {
22
- if (!content || !content.trim()) return 0
23
- return content.split(/\n\n+/).filter(p => p.trim()).length
24
- }
25
-
26
- /**
27
- * 对比原文件和格式化文件的段落数。
28
- * @param {string} origContent — 原文件内容
29
- * @param {string} fmtContent — 格式化文件内容
30
- * @returns {{ origCount: number, fmtCount: number, diffPercent: number, status: 'OK' | 'WARN' }} 检查结果
31
- */
32
- export function checkParagraphs(origContent, fmtContent) {
33
- const origCount = countParagraphs(origContent)
34
- const fmtCount = countParagraphs(fmtContent)
35
-
36
- const diffPercent = origCount === 0
37
- ? (fmtCount === 0 ? 0 : 100)
38
- : Math.abs(fmtCount - origCount) / origCount * 100
39
-
40
- const status = diffPercent > 5 ? 'WARN' : 'OK'
41
-
42
- return { origCount, fmtCount, diffPercent: Math.round(diffPercent * 10) / 10, status }
43
- }
44
-
45
- // --- CLI entry point (only when run directly, not when imported) ---
46
-
47
- const isMain = import.meta.url === `file://${process.argv[1]}`
48
- if (isMain) {
49
- const [,, origPath, fmtPath] = process.argv
50
-
51
- if (!origPath || !fmtPath) {
52
- console.error('Usage: node check-paragraphs.js <original.md> <formatted.md>')
53
- process.exit(1)
54
- }
55
-
56
- if (!existsSync(origPath)) {
57
- console.error(`ERROR: original file not found: ${origPath}`)
58
- process.exit(1)
59
- }
60
-
61
- if (!existsSync(fmtPath)) {
62
- console.error(`ERROR: formatted file not found: ${fmtPath}`)
63
- process.exit(1)
64
- }
65
-
66
- const origContent = readFileSync(origPath, 'utf-8')
67
- const fmtContent = readFileSync(fmtPath, 'utf-8')
68
-
69
- const result = checkParagraphs(origContent, fmtContent)
70
- console.log(`paragraphs: orig=${result.origCount} fmt=${result.fmtCount} diff=${result.diffPercent}% ${result.status}`)
71
- }
@@ -1,123 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * chunk-bilingual.js — 双语文档分块 + 格式重建进度初始化(ESM,纯 JS,无依赖)
4
- *
5
- * 用法:node chunk-bilingual.js <work_dir> <chunk_words> [<input_file>]
6
- * <input_file> 缺省 = <work_dir>/bilingual.md(translate Item 6)
7
- * 显式传入 = 从指定文件分块(translate-format Item 2)
8
- *
9
- * 功能:
10
- * 1. 创建 <work_dir>/fmt/ 目录
11
- * 2. 按段落边界将输入文档分块,写入 fmt/p001.md...
12
- * 3. 创建 fmt/progress.md(身份行 + chunk 状态表)
13
- * 4. stdout 打印总块数
14
- *
15
- * 短路:fmt/progress.md 已存在 → 跳过分块和初始化,仅打印已有块数
16
- */
17
-
18
- import { readFileSync, writeFileSync, mkdirSync, existsSync, readdirSync } from 'fs';
19
- import { join, basename } from 'path';
20
-
21
- /**
22
- * 将文本按段落边界分块。
23
- * @param {string} content — 文本内容
24
- * @param {number} chunkWords — 每块最大词数
25
- * @returns {string[]} 分块数组
26
- */
27
- export function chunkBilingual(content, chunkWords) {
28
- if (!content || !content.trim()) return [];
29
-
30
- const paragraphs = content.split(/\n\n+/);
31
-
32
- const chunks = [];
33
- let currentChunk = [];
34
- let currentWords = 0;
35
-
36
- for (const para of paragraphs) {
37
- const trimmed = para.trim();
38
- if (!trimmed) continue;
39
-
40
- const words = trimmed.split(/\s+/).filter(Boolean).length;
41
-
42
- if (currentWords + words > chunkWords && currentChunk.length > 0) {
43
- chunks.push(currentChunk.join('\n\n'));
44
- currentChunk = [trimmed];
45
- currentWords = words;
46
- } else {
47
- currentChunk.push(trimmed);
48
- currentWords += words;
49
- }
50
- }
51
-
52
- if (currentChunk.length > 0) {
53
- chunks.push(currentChunk.join('\n\n'));
54
- }
55
-
56
- return chunks;
57
- }
58
-
59
- // --- CLI ---
60
-
61
- const isMain = import.meta.url === `file://${process.argv[1]}`;
62
-
63
- if (isMain) {
64
- const args = process.argv.slice(2);
65
-
66
- if (args.length < 2) {
67
- console.error('Usage: node chunk-bilingual.js <work_dir> <chunk_words> [<input_file>]');
68
- process.exit(2);
69
- }
70
-
71
- const [workDir, chunkWordsStr, inputFile] = args;
72
- const chunkWords = parseInt(chunkWordsStr, 10);
73
- const fmtDir = join(workDir, 'fmt');
74
- const progressPath = join(fmtDir, 'progress.md');
75
-
76
- if (isNaN(chunkWords) || chunkWords < 100) {
77
- console.error('ERROR: chunk_words must be a number >= 100');
78
- process.exit(2);
79
- }
80
-
81
- // 短路:progress.md 已存在 → 仅打印已有块数
82
- if (existsSync(progressPath)) {
83
- const existing = readdirSync(fmtDir).filter(f => f.match(/^p\d+\.md$/)).length;
84
- console.log(`chunks: ${existing} (skipped, progress.md exists)`);
85
- process.exit(0);
86
- }
87
-
88
- // 输入源:显式 input_file 优先,缺省 <work_dir>/bilingual.md
89
- const inputPath = inputFile || join(workDir, 'bilingual.md');
90
- if (!existsSync(inputPath)) {
91
- console.error(`ERROR: input file not found: ${inputPath}`);
92
- process.exit(2);
93
- }
94
-
95
- const content = readFileSync(inputPath, 'utf-8');
96
- const chunks = chunkBilingual(content, chunkWords);
97
-
98
- if (chunks.length === 0) {
99
- console.error(`ERROR: input is empty or contains no paragraphs: ${inputPath}`);
100
- process.exit(2);
101
- }
102
-
103
- // 1. 创建 fmt/ 目录
104
- mkdirSync(fmtDir, { recursive: true });
105
-
106
- // 2. 写分块文件
107
- chunks.forEach((chunk, i) => {
108
- const num = String(i + 1).padStart(3, '0');
109
- writeFileSync(join(fmtDir, `p${num}.md`), chunk + '\n', 'utf-8');
110
- });
111
-
112
- // 3. 创建 progress.md
113
- const inputDirBasename = basename(join(workDir, '..', '..'));
114
- const fileBasename = basename(workDir);
115
- const lines = [`# tsl format progress — book: ${inputDirBasename}, file: ${fileBasename}`, '', '| Chunk | 状态 | 重试 |', '|-------|------|------|'];
116
- for (let i = 0; i < chunks.length; i++) {
117
- const num = String(i + 1).padStart(3, '0');
118
- lines.push(`| p${num} | pending | 0 |`);
119
- }
120
- writeFileSync(progressPath, lines.join('\n') + '\n', 'utf-8');
121
-
122
- console.log(`chunks: ${chunks.length}`);
123
- }
@@ -1,145 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * chunk-text.js — 文本分块脚本(ESM,段落感知)
4
- *
5
- * 输入:argv[2] = 工作目录(含 source.txt),argv[3] = 每块最大词数(默认 4000)
6
- * 输出:p001.txt, p002.txt, ... 写入工作目录,stdout 打印总块数
7
- *
8
- * 分块策略:
9
- * - PDF 文本(含 \f):按 \f 切分页面,按 chunk_words 分组
10
- * - 纯文本(无 \f):按段落边界切分,尽量不切断段落;单段落超长时按词数硬切
11
- * - 每块末尾检测段落是否完整(以句末标点结尾),不完整时追加 [CONT] 标记
12
- */
13
-
14
- import { readFileSync, writeFileSync, mkdirSync, existsSync } from 'fs';
15
- import { join } from 'path';
16
-
17
- const args = process.argv.slice(2);
18
-
19
- if (args.length < 1) {
20
- console.error('usage: chunk-text.js <work_dir> [chunk_words=4000]');
21
- process.exit(2);
22
- }
23
-
24
- const workDir = args[0];
25
- const chunkWords = Math.max(100, parseInt(args[1] || '4000', 10));
26
- const sourcePath = join(workDir, 'source.txt');
27
-
28
- if (!existsSync(sourcePath)) {
29
- console.error(`ERROR: source file not found: ${sourcePath}`);
30
- process.exit(2);
31
- }
32
-
33
- const outputDir = workDir;
34
- mkdirSync(outputDir, { recursive: true });
35
-
36
- const content = readFileSync(sourcePath, 'utf-8');
37
-
38
- // Count words (rough: split by whitespace)
39
- function countWords(text) {
40
- return text.trim().split(/\s+/).filter(w => w.length > 0).length;
41
- }
42
-
43
- // Check if text ends with a complete sentence (sentence-ending punctuation)
44
- function isParagraphComplete(text) {
45
- const trimmed = text.trimEnd();
46
- if (trimmed.length === 0) return true;
47
- // Common sentence-ending punctuation in multiple languages
48
- return /[.!?。!?:;;]\s*$/.test(trimmed) ||
49
- /["'」』))\]]\s*$/.test(trimmed) ||
50
- trimmed.endsWith('[CONT]'); // already marked
51
- }
52
-
53
- // Append [CONT] marker if last paragraph is incomplete
54
- function markIncomplete(chunk) {
55
- const trimmed = chunk.trimEnd();
56
- if (trimmed.length === 0) return chunk;
57
- if (isParagraphComplete(trimmed)) return chunk;
58
- // Find last non-empty line
59
- return chunk.replace(/\s*$/, '\n[CONT]\n');
60
- }
61
-
62
- // Split into chunks
63
- let chunks = [];
64
-
65
- if (content.includes('\f')) {
66
- // PDF text with form feed page breaks
67
- const pages = content.split('\f');
68
- let currentChunk = '';
69
-
70
- for (let i = 0; i < pages.length; i++) {
71
- const page = pages[i];
72
- if (page.trim().length === 0) continue;
73
-
74
- const pageWords = countWords(page);
75
- const wouldExceedWords = countWords(currentChunk) + pageWords > chunkWords;
76
-
77
- if (wouldExceedWords && currentChunk.length > 0) {
78
- // Mark incomplete before flushing
79
- chunks.push(markIncomplete(currentChunk));
80
- currentChunk = page;
81
- } else {
82
- currentChunk += (currentChunk ? '\n' : '') + page;
83
- }
84
- }
85
-
86
- // Flush remaining (last chunk — don't mark [CONT], it's the end of document)
87
- if (currentChunk.trim().length > 0) {
88
- chunks.push(currentChunk);
89
- }
90
- } else {
91
- // Plain text without page breaks — split by paragraph boundaries
92
- const paragraphs = content.split(/\n\s*\n/); // Split on double newline (paragraph boundary)
93
-
94
- let currentChunk = '';
95
-
96
- for (const para of paragraphs) {
97
- if (para.trim().length === 0) continue;
98
-
99
- const paraWords = countWords(para);
100
- const chunkWordsNow = countWords(currentChunk);
101
-
102
- // If adding this paragraph exceeds limit and we have content, flush
103
- if (chunkWordsNow + paraWords > chunkWords && currentChunk.length > 0) {
104
- chunks.push(markIncomplete(currentChunk));
105
- currentChunk = para;
106
- } else {
107
- currentChunk += (currentChunk ? '\n\n' : '') + para;
108
- }
109
-
110
- // If single paragraph exceeds chunk_words, hard-split it by words
111
- while (countWords(currentChunk) > chunkWords) {
112
- const words = currentChunk.trim().split(/\s+/);
113
- const firstPart = words.slice(0, chunkWords).join(' ');
114
- const restPart = words.slice(chunkWords).join(' ');
115
- chunks.push(markIncomplete(firstPart));
116
- currentChunk = restPart;
117
- }
118
- }
119
-
120
- // Flush remaining (last chunk — no [CONT])
121
- if (currentChunk.trim().length > 0) {
122
- chunks.push(currentChunk);
123
- }
124
- }
125
-
126
- // Filter empty chunks
127
- chunks = chunks.filter(c => c.trim().length > 0);
128
-
129
- if (chunks.length === 0) {
130
- console.error('ERROR: no content to chunk');
131
- process.exit(3);
132
- }
133
-
134
- // Write chunks
135
- let contCount = 0;
136
- for (let i = 0; i < chunks.length; i++) {
137
- const chunkNum = String(i + 1).padStart(3, '0');
138
- const chunkPath = join(outputDir, `p${chunkNum}.txt`);
139
- writeFileSync(chunkPath, chunks[i], 'utf-8');
140
- if (chunks[i].includes('[CONT]')) contCount++;
141
- }
142
-
143
- // Print summary
144
- const totalWords = chunks.reduce((sum, c) => sum + countWords(c), 0);
145
- console.log(`chunked: ${chunks.length} chunks, ~${totalWords} words, ${contCount} [CONT] markers → ${outputDir}/p001.txt..p${String(chunks.length).padStart(3, '0')}.txt`);
@@ -1,121 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * clean-text.js — PDF 提取文本清洗脚本(ESM,纯 JS,无系统依赖)
4
- *
5
- * 清洗 pdf-parse 提取的 source.txt 中的确定性噪声:
6
- * 1. Tab 字符 → 空格
7
- * 2. 独立 ^ 字符(OCR 噪声)→ 删除(保留 \f 页标记)
8
- * 3. 行中 \f(页中断合并文本)→ 拆分为独立行
9
- * 4. 连续空格 → 单空格
10
- * 5. 行尾空格 → 删除
11
- *
12
- * 输入:argv[2] = source.txt 路径
13
- * 输出:原地清洗,stdout 打印统计
14
- *
15
- * 用法:
16
- * node clean-text.js "<source.txt>"
17
- */
18
-
19
- import { readFileSync, writeFileSync, existsSync } from 'fs';
20
-
21
- /**
22
- * 清洗文本内容,返回清洗后的内容和统计信息。
23
- * @param {string} content — 原始文本
24
- * @returns {{ content: string, stats: { tabs: number, carets: number, formFeeds: number } }}
25
- */
26
- export function cleanText(content) {
27
- let tabCount = 0;
28
- let caretCount = 0;
29
- let formFeedSplitCount = 0;
30
-
31
- // 1. 行中 \f 拆分:将 "text\fmore" 拆为 "text\n\f\nmore"
32
- // \f 独占一行,保留为页标记(chunk-text.js 依赖 \f 分页)
33
- const lines = content.split('\n');
34
- const processedLines = [];
35
-
36
- for (const line of lines) {
37
- // 独占行的 \f 是页标记,不拆分
38
- if (line === '\f') {
39
- processedLines.push(line);
40
- continue;
41
- }
42
- if (line.includes('\f')) {
43
- const parts = line.split('\f');
44
- for (let i = 0; i < parts.length; i++) {
45
- if (i > 0) {
46
- processedLines.push('\f');
47
- formFeedSplitCount++;
48
- }
49
- if (parts[i].length > 0) {
50
- processedLines.push(parts[i]);
51
- }
52
- }
53
- } else {
54
- processedLines.push(line);
55
- }
56
- }
57
-
58
- // 2. 逐行清洗:tab→空格、删除^、折叠空格、去行尾空格
59
- const cleanedLines = processedLines.map((line) => {
60
- // 跳过 \f 独占行,不清洗
61
- if (line === '\f') return line;
62
-
63
- let cleaned = line;
64
-
65
- // Tab → 空格
66
- const tabs = (cleaned.match(/\t/g) || []).length;
67
- if (tabs > 0) {
68
- cleaned = cleaned.replace(/\t/g, ' ');
69
- tabCount += tabs;
70
- }
71
-
72
- // 删除 ^ 字符(OCR 噪声,不删除 \f)
73
- const carets = (cleaned.match(/\^/g) || []).length;
74
- if (carets > 0) {
75
- cleaned = cleaned.replace(/\^/g, '');
76
- caretCount += carets;
77
- }
78
-
79
- // 折叠连续空格 → 单空格
80
- cleaned = cleaned.replace(/ {2,}/g, ' ');
81
-
82
- // 去行尾空格
83
- cleaned = cleaned.replace(/\s+$/, '');
84
-
85
- return cleaned;
86
- });
87
-
88
- return {
89
- content: cleanedLines.join('\n'),
90
- stats: { tabs: tabCount, carets: caretCount, formFeeds: formFeedSplitCount },
91
- };
92
- }
93
-
94
- // --- CLI ---
95
-
96
- const isMain = import.meta.url === `file://${process.argv[1]}`;
97
-
98
- if (isMain) {
99
- const args = process.argv.slice(2);
100
-
101
- if (args.length < 1) {
102
- console.error('usage: clean-text.js <source.txt>');
103
- process.exit(2);
104
- }
105
-
106
- const filePath = args[0];
107
-
108
- if (!existsSync(filePath)) {
109
- console.error(`ERROR: source file not found: ${filePath}`);
110
- process.exit(2);
111
- }
112
-
113
- const raw = readFileSync(filePath, 'utf-8');
114
- const { content, stats } = cleanText(raw);
115
- writeFileSync(filePath, content, 'utf-8');
116
-
117
- console.log(`clean-text: ${filePath}`);
118
- console.log(` tabs replaced: ${stats.tabs}`);
119
- console.log(` carets removed: ${stats.carets}`);
120
- console.log(` form feeds split: ${stats.formFeeds}`);
121
- }
@@ -1,54 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * count-terms.js — 词频统计脚本(ESM)
4
- *
5
- * 输入:argv[2] = 工作目录(.tsl/,含各子目录的 source.txt),argv[3] = 术语列表(逗号分隔)
6
- * 输出:stdout 每行 "次数\t术语",按次数降序
7
- *
8
- * 统计方式:大小写不敏感子串计数,扫描 .tsl/ 下所有子目录的 source.txt 全文。
9
- */
10
-
11
- import { readFileSync, existsSync, readdirSync, statSync } from 'fs';
12
- import { join } from 'path';
13
-
14
- const args = process.argv.slice(2);
15
- const workDir = args[0];
16
- const termsCsv = args[1];
17
-
18
- if (!workDir || !termsCsv) {
19
- console.error('Usage: node count-terms.js <work_dir> <terms_csv>');
20
- process.exit(2);
21
- }
22
-
23
- const terms = termsCsv.split(',').map(t => t.trim()).filter(t => t.length > 0);
24
-
25
- // 扫描所有子目录的 source.txt,合并全文
26
- const subdirs = readdirSync(workDir)
27
- .filter(name => {
28
- const p = join(workDir, name);
29
- return statSync(p).isDirectory() && existsSync(join(p, 'source.txt'));
30
- })
31
- .sort();
32
-
33
- let fullText = '';
34
- for (const name of subdirs) {
35
- fullText += readFileSync(join(workDir, name, 'source.txt'), 'utf-8') + '\n';
36
- }
37
-
38
- const lower = fullText.toLowerCase();
39
- const result = [];
40
- for (const term of terms) {
41
- const tl = term.toLowerCase();
42
- let count = 0;
43
- let idx = lower.indexOf(tl);
44
- while (idx !== -1) {
45
- count++;
46
- idx = lower.indexOf(tl, idx + tl.length);
47
- }
48
- result.push({ term, count });
49
- }
50
-
51
- result.sort((a, b) => b.count - a.count);
52
- for (const r of result) {
53
- console.log(`${r.count}\t${r.term}`);
54
- }
@@ -1,94 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * extract-pdf.js — PDF 文本提取脚本(ESM,纯 JS,无系统依赖)
4
- *
5
- * 依赖:pdf-parse(npm 包,随 skill 安装)
6
- * 输入:argv[2] = PDF 文件路径,argv[3] = 输出文本文件路径
7
- * 或 argv[2] = '--check'(仅检查 pdf-parse 可用性)
8
- * 输出:纯文本(\f 分页符分隔页面),stdout 打印行数和页数
9
- *
10
- * 用法:
11
- * node extract-pdf.js "<pdf路径>" "<output.txt>"
12
- * node extract-pdf.js --check
13
- */
14
-
15
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
16
- import { dirname } from 'path';
17
- import { createRequire } from 'module';
18
-
19
- const require = createRequire(import.meta.url);
20
- const args = process.argv.slice(2);
21
-
22
- // --check 模式
23
- if (args[0] === '--check') {
24
- try {
25
- const { PDFParse } = require('pdf-parse');
26
- if (typeof PDFParse === 'function') {
27
- console.log('pdf-parse: OK');
28
- process.exit(0);
29
- }
30
- } catch {
31
- // fall through to error
32
- }
33
- console.error('ERROR: pdf-parse not available. Run: npm install');
34
- process.exit(3);
35
- }
36
-
37
- if (args.length < 2) {
38
- console.error('usage: extract-pdf.js <pdf-file> <output-txt>');
39
- console.error(' extract-pdf.js --check');
40
- process.exit(2);
41
- }
42
-
43
- const pdfPath = args[0];
44
- const outPath = args[1];
45
-
46
- // 检查 PDF 文件存在
47
- if (!existsSync(pdfPath)) {
48
- console.error(`ERROR: PDF file not found: ${pdfPath}`);
49
- process.exit(2);
50
- }
51
-
52
- // 检查输出目录
53
- const outDir = dirname(outPath);
54
- if (!existsSync(outDir)) {
55
- mkdirSync(outDir, { recursive: true });
56
- }
57
-
58
- // 加载 pdf-parse
59
- let PDFParse;
60
- try {
61
- const mod = require('pdf-parse');
62
- PDFParse = mod.PDFParse;
63
- } catch (e) {
64
- console.error('ERROR: pdf-parse not available. Run: npm install');
65
- console.error(e.message);
66
- process.exit(3);
67
- }
68
-
69
- // 提取文本
70
- try {
71
- const buf = readFileSync(pdfPath);
72
- const parser = new PDFParse({ data: buf });
73
- const result = await parser.getText();
74
-
75
- if (!result || !result.pages) {
76
- console.error('ERROR: pdf-parse returned no pages');
77
- process.exit(4);
78
- }
79
-
80
- // 将每页文本用 \f 连接(与 pdftotext 输出格式一致,chunk-text.js 依赖此格式)
81
- const pages = result.pages.map(p => p.text || '');
82
- const content = pages.join('\f');
83
-
84
- writeFileSync(outPath, content, 'utf-8');
85
-
86
- const lines = content.split('\n').length;
87
- const formFeeds = (content.match(/\f/g) || []).length;
88
- const pageCount = formFeeds + 1;
89
- console.log(`extracted: ${lines} lines, ~${pageCount} pages -> ${outPath}`);
90
- } catch (e) {
91
- console.error(`ERROR: pdf-parse failed on: ${pdfPath}`);
92
- console.error(e.message);
93
- process.exit(4);
94
- }