@wwkit/harness 1.0.45 → 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.
- package/package.json +1 -1
- package/skills/convert-files/scripts/convert.js +1 -1
- package/skills/pea/SKILL.md +6 -1
- package/skills/pea/references/tpl-prd/epic.md +10 -0
- package/skills/pea/references/tpl-prd/us.md +4 -4
- package/skills/peago/SKILL.md +113 -0
- package/skills/peago/references/extract/baseline.md +17 -0
- package/skills/peago/references/extract/spec.md +117 -0
- package/skills/peago/references/res2kb/spec.md +113 -0
- package/skills/peago/references/spec-format.md +123 -0
- package/skills/peago/references/translate/baseline.md +26 -0
- package/skills/peago/references/translate/spec.md +132 -0
- package/skills/shared/references/template/pea/spec-agile.md +15 -6
- package/skills/shared/references/template/pea/spec-common.md +12 -2
- package/skills/shared/scripts/format.md +1 -1
- package/skills/extract/SKILL.md +0 -251
- package/skills/extract/references/detail_schema.json5 +0 -49
- package/skills/extract/references/detail_workflow.md +0 -55
- package/skills/extract/references/list_rule_gen.md +0 -109
- package/skills/extract/references/list_schema.json5 +0 -34
- package/skills/extract/references/list_workflow.md +0 -135
- package/skills/extract/references/navi_schema.json5 +0 -23
- package/skills/extract/references/navi_workflow.md +0 -45
- package/skills/extract/references/planning_template.md +0 -206
- package/skills/extract/references/text_schema.json5 +0 -22
- package/skills/extract/references/text_workflow.md +0 -41
- package/skills/extract/scripts/build_xpath.js +0 -31
- package/skills/extract/scripts/clean_html.js +0 -91
- package/skills/extract/scripts/extract_detail.js +0 -72
- package/skills/extract/scripts/extract_regex.js +0 -82
- package/skills/extract/scripts/extract_sample.js +0 -49
- package/skills/extract/scripts/to_text.js +0 -21
- package/skills/extract/scripts/validate_schema.js +0 -40
- package/skills/revise/SKILL.md +0 -66
- package/skills/revise/references/article.md +0 -37
- package/skills/revise/references/article.schema.json5 +0 -40
- package/skills/revise/references/gallery.md +0 -35
- package/skills/revise/references/gallery.schema.json5 +0 -40
- package/skills/revise/references/question.md +0 -33
- package/skills/revise/references/question.schema.json5 +0 -31
- package/skills/revise/references/sprint_for_revise.md +0 -46
- package/skills/revise/references/status.md +0 -32
- package/skills/revise/references/status.schema.json5 +0 -27
- package/skills/revise/scripts/check_input_vars.js +0 -127
- package/skills/revise/scripts/init.js +0 -84
- package/skills/revise/scripts/resolve_run_vars.js +0 -71
- package/skills/revise/scripts/validate-schema.js +0 -94
- package/skills/translate/SKILL.md +0 -398
- package/skills/translate/app.json5 +0 -70
- package/skills/translate/package.json +0 -11
- package/skills/translate/references/failure-diagnosis.md +0 -43
- package/skills/translate/references/format-prompt.md +0 -62
- package/skills/translate/references/format-rules.md +0 -39
- package/skills/translate/references/global-review-rules.md +0 -23
- package/skills/translate/references/glossary-prompt.md +0 -86
- package/skills/translate/references/glossary-rules.md +0 -44
- package/skills/translate/references/prepare-prompt.md +0 -110
- package/skills/translate/references/prepare-rules.md +0 -20
- package/skills/translate/references/resume-detection.md +0 -51
- package/skills/translate/references/rulings.md +0 -15
- package/skills/translate/references/translation-prompt.md +0 -73
- package/skills/translate/references/translation-rules.md +0 -51
- package/skills/translate/scripts/check-boundaries.js +0 -169
- package/skills/translate/scripts/check-paragraphs.js +0 -71
- package/skills/translate/scripts/chunk-bilingual.js +0 -123
- package/skills/translate/scripts/chunk-text.js +0 -145
- package/skills/translate/scripts/clean-text.js +0 -121
- package/skills/translate/scripts/count-terms.js +0 -54
- package/skills/translate/scripts/extract-pdf.js +0 -94
- package/skills/translate/scripts/generate-review.js +0 -179
- package/skills/translate/scripts/init-progress.js +0 -144
- package/skills/translate/scripts/md-to-docx.js +0 -381
- package/skills/translate/scripts/merge-format.js +0 -110
- package/skills/translate/scripts/merge-result.js +0 -113
- package/skills/translate/scripts/verify-chunk.js +0 -185
- package/skills/translate/todos.md +0 -38
- package/skills/translate-file/SKILL.md +0 -45
- package/skills/translate-file/package.json +0 -10
- package/skills/translate-file/references/sprint_for_preprocess.md +0 -14
- package/skills/translate-file/references/sprint_for_teardown.md +0 -15
- package/skills/translate-file/references/sprint_for_translate.md +0 -74
- package/skills/translate-file/references/translation_prompt.md +0 -43
- package/skills/translate-file/scripts/check_input_vars.js +0 -53
- package/skills/translate-file/scripts/chunk_text.js +0 -167
- package/skills/translate-file/scripts/clean_text.js +0 -121
- package/skills/translate-file/scripts/extract.js +0 -98
- package/skills/translate-file/scripts/generate_review.js +0 -155
- package/skills/translate-file/scripts/init.js +0 -86
- package/skills/translate-file/scripts/merge_results.js +0 -112
- package/skills/translate-file/scripts/resolve_run_vars.js +0 -123
- package/skills/translate-file/scripts/verify_chunk.js +0 -144
- package/skills/translate-format/SKILL.md +0 -45
- package/skills/translate-format/references/format-prompt.md +0 -80
- package/skills/translate-format/references/format-rules.md +0 -39
- package/skills/translate-format/references/sprint_for_format.md +0 -208
- package/skills/translate-format/scripts/check-paragraphs.js +0 -81
- package/skills/translate-format/scripts/check_input_vars.js +0 -51
- package/skills/translate-format/scripts/chunk-bilingual.js +0 -135
- package/skills/translate-format/scripts/count-words.js +0 -38
- package/skills/translate-format/scripts/diagnose-failure.js +0 -54
- package/skills/translate-format/scripts/init.js +0 -71
- package/skills/translate-format/scripts/md-to-docx.js +0 -398
- package/skills/translate-format/scripts/merge-format.js +0 -118
- package/skills/translate-format/scripts/resolve_run_vars.js +0 -78
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* verify-chunk.js — 随块自检脚本(ESM)
|
|
4
|
-
*
|
|
5
|
-
* 输入:stdin JSON { "original": "<原文>", "translated": "<译文>" }
|
|
6
|
-
* 可选:stdin JSON 增加字段 "glossary": "<术语表内容>" 启用术语检查
|
|
7
|
-
* 也可用参数传入输入文件:node verify-chunk.js <input.json>(兼容 stdin)
|
|
8
|
-
* 输出:stdout "VALID" 或 "INVALID: <原因>"
|
|
9
|
-
*
|
|
10
|
-
* 校验项(全部通过 = VALID,任一不过 = INVALID):
|
|
11
|
-
* 1. 段落数一致:原文段落数 = 译文段落数 / 2(双语交替格式)
|
|
12
|
-
* 2. 脚注 ID 一致:原文脚注 ID 集合 = 译文脚注 ID 集合
|
|
13
|
-
* 3. [CONT] 标记配对:每个 [CONT] 在原文段 + 译文段各出现一次(偶数配对)
|
|
14
|
-
* 4. 术语一致性:术语表中的术语在译文中使用正确(需传入 glossary 字段)
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import { readFileSync, existsSync } from 'fs';
|
|
18
|
-
|
|
19
|
-
function readStdin() {
|
|
20
|
-
return new Promise((resolve) => {
|
|
21
|
-
let data = '';
|
|
22
|
-
process.stdin.setEncoding('utf-8');
|
|
23
|
-
process.stdin.on('data', (chunk) => { data += chunk; });
|
|
24
|
-
process.stdin.on('end', () => resolve(data));
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Count paragraphs (non-empty lines separated by empty lines)
|
|
29
|
-
function countParagraphs(text) {
|
|
30
|
-
const lines = text.split(/\n/);
|
|
31
|
-
let count = 0;
|
|
32
|
-
let inPara = false;
|
|
33
|
-
for (const line of lines) {
|
|
34
|
-
if (line.trim().length > 0) {
|
|
35
|
-
if (!inPara) {
|
|
36
|
-
count++;
|
|
37
|
-
inPara = true;
|
|
38
|
-
}
|
|
39
|
-
} else {
|
|
40
|
-
inPara = false;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return count;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Extract unique footnote IDs ([^N] patterns)
|
|
47
|
-
function getFootnoteIds(text) {
|
|
48
|
-
const matches = text.match(/\[\^(\d+)\]/g);
|
|
49
|
-
if (!matches) return new Set();
|
|
50
|
-
const ids = new Set();
|
|
51
|
-
for (const m of matches) {
|
|
52
|
-
const num = m.match(/\[\^(\d+)\]/);
|
|
53
|
-
if (num) ids.add(num[1]);
|
|
54
|
-
}
|
|
55
|
-
return ids;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Count [CONT] markers
|
|
59
|
-
function countCont(text) {
|
|
60
|
-
const matches = text.match(/\[CONT\]/g);
|
|
61
|
-
return matches ? matches.length : 0;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Parse glossary and check terminology consistency
|
|
65
|
-
// glossary format: markdown table with | 原文 | 译文 | ... rows
|
|
66
|
-
function checkGlossary(translated, glossary) {
|
|
67
|
-
const errors = [];
|
|
68
|
-
const lines = glossary.split('\n').filter(l => l.trim().startsWith('|') && !l.includes('---') && !l.includes('原文'));
|
|
69
|
-
|
|
70
|
-
for (const line of lines) {
|
|
71
|
-
const cells = line.split('|').map(c => c.trim()).filter(c => c.length > 0);
|
|
72
|
-
if (cells.length >= 2) {
|
|
73
|
-
const original = cells[0];
|
|
74
|
-
const translation = cells[1];
|
|
75
|
-
// Check if the original term appears in the translated text
|
|
76
|
-
// (the translated text includes both original and translation paragraphs)
|
|
77
|
-
if (translated.includes(original)) {
|
|
78
|
-
// Term found in text — check if the translation is used
|
|
79
|
-
if (!translated.includes(translation)) {
|
|
80
|
-
errors.push(`术语不一致: "${original}" 应译为 "${translation}" 但译文中未找到该译法`);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return errors;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
async function main() {
|
|
89
|
-
// argv[2] = 可选输入文件路径(替代 stdin),无参数时保持读 stdin 兼容
|
|
90
|
-
const inputFile = process.argv[2];
|
|
91
|
-
let input;
|
|
92
|
-
if (inputFile) {
|
|
93
|
-
if (!existsSync(inputFile)) {
|
|
94
|
-
console.log('INVALID: input file not found: ' + inputFile);
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
input = readFileSync(inputFile, 'utf-8');
|
|
98
|
-
} else {
|
|
99
|
-
input = await readStdin();
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
let data;
|
|
103
|
-
|
|
104
|
-
try {
|
|
105
|
-
data = JSON.parse(input);
|
|
106
|
-
} catch (e) {
|
|
107
|
-
console.log('INVALID: stdin is not valid JSON');
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (!data.original || !data.translated) {
|
|
112
|
-
console.log('INVALID: missing "original" or "translated" field');
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const original = data.original;
|
|
117
|
-
const translated = data.translated;
|
|
118
|
-
|
|
119
|
-
const origParas = countParagraphs(original);
|
|
120
|
-
const transParas = countParagraphs(translated);
|
|
121
|
-
|
|
122
|
-
// In bilingual format, translated should have ~2x paragraphs (original + translation alternating)
|
|
123
|
-
const expectedTransParas = origParas * 2;
|
|
124
|
-
const paraTolerance = Math.max(2, Math.ceil(origParas * 0.1));
|
|
125
|
-
|
|
126
|
-
// Compare unique footnote ID sets
|
|
127
|
-
const origFnIds = getFootnoteIds(original);
|
|
128
|
-
const transFnIds = getFootnoteIds(translated);
|
|
129
|
-
|
|
130
|
-
// [CONT] check: in bilingual output, [CONT] appears in original para + translation para = even count
|
|
131
|
-
// Original chunk (from chunk-text.js) may have [CONT] at the end (added by chunk-text.js)
|
|
132
|
-
// Translated (bilingual) should have 2x the original's [CONT] count
|
|
133
|
-
const origCont = countCont(original);
|
|
134
|
-
const transCont = countCont(translated);
|
|
135
|
-
|
|
136
|
-
const errors = [];
|
|
137
|
-
|
|
138
|
-
// 1. Check paragraph count (bilingual should have ~2x)
|
|
139
|
-
if (Math.abs(transParas - expectedTransParas) > paraTolerance) {
|
|
140
|
-
errors.push(`段落数不匹配: 原文 ${origParas} 段, 译文 ${transParas} 段 (期望 ~${expectedTransParas} 段, 容差 ${paraTolerance})`);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// 2. Check footnote IDs match (unique set comparison)
|
|
144
|
-
if (origFnIds.size > 0) {
|
|
145
|
-
const missingInTrans = [...origFnIds].filter(id => !transFnIds.has(id));
|
|
146
|
-
const extraInTrans = [...transFnIds].filter(id => !origFnIds.has(id));
|
|
147
|
-
if (missingInTrans.length > 0) {
|
|
148
|
-
errors.push(`脚注缺失: 原文有 [^${missingInTrans.join('], [^')}] 但译文中未找到`);
|
|
149
|
-
}
|
|
150
|
-
if (extraInTrans.length > 0) {
|
|
151
|
-
errors.push(`脚注多余: 译文有 [^${extraInTrans.join('], [^')}] 但原文中未找到`);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// 3. [CONT] check (fixed):
|
|
156
|
-
// If original chunk has [CONT] markers (added by chunk-text.js), bilingual should have 2x
|
|
157
|
-
// If original has no [CONT], bilingual should also have 0 (LLM shouldn't add [CONT] on its own)
|
|
158
|
-
if (origCont > 0) {
|
|
159
|
-
// Original has [CONT] → bilingual should have 2x (original para + translation para)
|
|
160
|
-
if (transCont !== origCont * 2) {
|
|
161
|
-
errors.push(`[CONT] 标记不配对: 原文 ${origCont} 个, 译文 ${transCont} 个 (期望 ${origCont * 2} 个)`);
|
|
162
|
-
}
|
|
163
|
-
} else {
|
|
164
|
-
// Original has no [CONT] → bilingual should have 0
|
|
165
|
-
if (transCont > 0) {
|
|
166
|
-
errors.push(`[CONT] 标记多余: 原文无 [CONT] 但译文有 ${transCont} 个 (LLM 不应自行添加 [CONT])`);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// 4. Terminology check (optional, only if glossary provided)
|
|
171
|
-
if (data.glossary) {
|
|
172
|
-
const glossaryErrors = checkGlossary(translated, data.glossary);
|
|
173
|
-
errors.push(...glossaryErrors);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (errors.length > 0) {
|
|
177
|
-
console.log('INVALID: ' + errors.join('; '));
|
|
178
|
-
} else {
|
|
179
|
-
console.log('VALID');
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
main().catch((e) => {
|
|
184
|
-
console.log('INVALID: ' + e.message);
|
|
185
|
-
});
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
# tsl 技能待办清单(todos)
|
|
2
|
-
|
|
3
|
-
> 记录从规则评审中沉淀的待办事项。完成一项勾一项。
|
|
4
|
-
|
|
5
|
-
## 待办
|
|
6
|
-
|
|
7
|
-
- [ ] **新增词频统计脚本(count-terms.js)**
|
|
8
|
-
- 背景:terminology-rules.md 2.3 数量限制需按出现次数排序,模型感知候选 ≤50 后由脚本统计频次(LLM 无法精确计数)。
|
|
9
|
-
- 待办:实现词频统计脚本(输入:候选术语列表 + source 全文;输出:各术语出现次数);资源准备 subagent 术语表创建步骤调用(prepare-prompt.md 同步)。
|
|
10
|
-
|
|
11
|
-
- [ ] **自定义 `style` 参数规则机制重新设计**
|
|
12
|
-
- 背景:翻译规则转正后,规则中的风格即为直译,暂不支持 `style` 参数覆盖。旧机制(Style 可由 `style` 覆盖)已从 `translation-rules.md` 移除。
|
|
13
|
-
- 待办:重新设计 style 参数机制(如何表达风格、是否允许覆盖直译),设计完成后补回规则。
|
|
14
|
-
|
|
15
|
-
- [ ] **新翻译规则同步到 skill 生效区**
|
|
16
|
-
- 背景:新版 `translation-rules.md`(R1-R7 + V1-V4,纯规则表格)已定稿于 `.opencode-bridge/skills/tsl/references/`。
|
|
17
|
-
- 待办:覆盖同步到生效区 `skills/tsl/references/translation-rules.md`(旧版 46 行:Style + Format 契约 + 8 条细则)。
|
|
18
|
-
|
|
19
|
-
- [x] **`translation-prompt.md` 同步**
|
|
20
|
-
- 脚注格式示例:已与 R4 一致(`原文 | 译文`,去掉"译文:"前缀)。
|
|
21
|
-
- 禁止事项核对:已与转正后规则一致(不分块、不写 bilingual/progress/glossary、不做格式重建)。
|
|
22
|
-
- `{{file_number}}` 变量已从 prompt 移除(来源文件列填写 {{file_work_dir}});SKILL.md 中"替换 {{变量}}(含 {{file_number}}...)"的说明已同步删除。
|
|
23
|
-
|
|
24
|
-
- [ ] **`chunk-text.js` 页眉断裂补 [CONT]**(原 C4,属主 Agent 环节)
|
|
25
|
-
- 背景:抽查发现跨页码页眉断裂的段落无 [CONT] 标记(如 Georges Canguilhem V 行 13968→13974)。
|
|
26
|
-
- 待办:分块时检测页眉行(`### \d+` 模式)打断的未完段落,自动补 [CONT]。
|
|
27
|
-
|
|
28
|
-
- [ ] **N1/N2 语义级自检暂不引入**
|
|
29
|
-
- 背景:原文段污染检测(N1)与未译残留检测(N2)曾作为新增规则候选,因易误判(如英文原文可能引用中文谚语)暂不引入。
|
|
30
|
-
- 待办:如后续需要,先设计白名单与阈值,再评估是否升级为 verify-chunk 检查项。
|
|
31
|
-
|
|
32
|
-
- [ ] **术语表存量治理**
|
|
33
|
-
- 背景:Georges Canguilhem 术语表膨胀至 11,006 行(大量一次性译者人名、个人文章标题滥收),根因已定位——收录标准未注入 subagent、术语识别非独立步骤。prompt/rules 已重构(Backlog 新增「术语识别」步骤 + Item 1 直接读取 terminology-rules.md)。
|
|
34
|
-
- 待办:用 `cleanup-glossary.js` 收敛存量术语表(按排除标准批量删除一次性专名/作品名),并核对 merge-result.js 去重逻辑(规范化匹配)。
|
|
35
|
-
|
|
36
|
-
- [ ] **职责边界约束核对**
|
|
37
|
-
- 背景:subagent 不执行分块/术语表管理/写主产物/格式重建。转正后此约束由 `translation-prompt.md` 禁止事项承载,规则文件已不再重复。
|
|
38
|
-
- 待办:核对 prompt 禁止事项是否完整覆盖上述边界。
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: translate-file
|
|
3
|
-
description: |
|
|
4
|
-
Use when translating a single file (PDF / text / markdown) into bilingual side-by-side format (txt output). Triggers on: file translation, single file translate, 单文件翻译, translate one file.
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
作为 Scrum 开发者,我想要将源文件翻译为双语对照格式,以便输出 .txt 翻译文件。using the **fixed-sequence Sprint workflow** (seq)。
|
|
8
|
-
|
|
9
|
-
# Product Goal
|
|
10
|
-
Translate the source file into bilingual side-by-side format and output to a txt file.
|
|
11
|
-
|
|
12
|
-
# Extract Variables
|
|
13
|
-
|
|
14
|
-
Extract input variables from the context:
|
|
15
|
-
|
|
16
|
-
| Variable | Type | Required | Description |
|
|
17
|
-
|---|---|---|---|
|
|
18
|
-
| `input_path` | string | ✅ | source file or directory path |
|
|
19
|
-
| `language` | string | ❌ | Target language, default: Chinese |
|
|
20
|
-
| `chunk_words` | integer | ❌ | Maximum words per chunk, default: 3000 |
|
|
21
|
-
| `force` | boolean | ❌ | Force execution, ignore historical progress, default: false. Set `true` when the user asks for a retranslation (translate again / force translation / clear history then translate); otherwise `false` |
|
|
22
|
-
|
|
23
|
-
# Environment Initialization
|
|
24
|
-
|
|
25
|
-
1. Run `node scripts/init.js '{{input_path}}' {{force}}` to validate input, resolve variables, clear historical progress when `{{force}}` is true, and check npm dependencies.
|
|
26
|
-
2. Read **Sprint Standards** `{{shared_dir}}/references/sprint_standards.md`.
|
|
27
|
-
|
|
28
|
-
# Product Increment
|
|
29
|
-
|
|
30
|
-
| Product | Type | Description | DoD |
|
|
31
|
-
|---|---|---|---|
|
|
32
|
-
| `{{output_dir}}/{{run_name}}.txt` | file | Bilingual translation txt file | file exists and is not empty |
|
|
33
|
-
| `{{output_dir}}/review.md` | file | translation review file | file exists and is not empty |
|
|
34
|
-
|
|
35
|
-
# Sprint Backlogs
|
|
36
|
-
| Sprint Name | Backlog File | Description |
|
|
37
|
-
|---|---|---|
|
|
38
|
-
| Sprint for progress | `{{shared_dir}}/references/sprint_for_progress.md` | shared skill file |
|
|
39
|
-
| Sprint for preprocess | `{{skill_dir}}/references/sprint_for_preprocess.md` | |
|
|
40
|
-
| Sprint for translate | `{{skill_dir}}/references/sprint_for_translate.md` | |
|
|
41
|
-
| Sprint for teardown | `{{skill_dir}}/references/sprint_for_teardown.md` | |
|
|
42
|
-
|
|
43
|
-
# Sprint Now!
|
|
44
|
-
|
|
45
|
-
Read all **Sprint Backlogs**, follow **Sprint Workflow** `{{shared_dir}}/references/run/run_sprint_loop.md`, then *sprint*.
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
# Sprint Backlog for preprocess
|
|
2
|
-
|
|
3
|
-
## Sprint Goal
|
|
4
|
-
Convert the source file to clean plain text.
|
|
5
|
-
|
|
6
|
-
## Sprint Backlog Items
|
|
7
|
-
|
|
8
|
-
### Item1: Text extraction
|
|
9
|
-
- Implement: run `node '{{skill_dir}}/scripts/extract.js' '{{source_file}}' '{{run_dir}}/source.txt'`
|
|
10
|
-
- DoD check: `source.txt` is generated and not empty
|
|
11
|
-
|
|
12
|
-
### Item2: Text cleaning
|
|
13
|
-
- Implement: run `node '{{skill_dir}}/scripts/clean_text.js' '{{run_dir}}/source.txt'`
|
|
14
|
-
- DoD check: The cleaning script outputs an OK status
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
# Sprint Backlog for teardown
|
|
2
|
-
|
|
3
|
-
## Sprint Goal
|
|
4
|
-
Clean up and finalize after the merged output is generated.
|
|
5
|
-
|
|
6
|
-
## Sprint Backlog Items
|
|
7
|
-
|
|
8
|
-
### Item1: Fix CONT connections
|
|
9
|
-
- Short-circuit: skip when no `[CONT]` marker is found in `{{output_dir}}/{{run_name}}.txt`
|
|
10
|
-
- Implement: Search `[CONT]` markers with 2 lines of context before and after (forbidden to read the full file), fix the translation at splice points to ensure smooth sentences, and remove the `[CONT]` markers
|
|
11
|
-
- DoD check: No `[CONT]` markers remain in `{{output_dir}}/{{run_name}}.txt` and splice points are semantically smooth
|
|
12
|
-
|
|
13
|
-
### Item2: Generate review log
|
|
14
|
-
- Implement: run `node '{{skill_dir}}/scripts/generate_review.js' '{{run_dir}}/batch_progress.csv' '{{output_dir}}/review.md'`
|
|
15
|
-
- DoD check: `{{output_dir}}/review.md` is created
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
# Sprint Backlog for translate
|
|
2
|
-
|
|
3
|
-
## Sprint Goal
|
|
4
|
-
|
|
5
|
-
Chunk the clean text, then translate a batch of chunks in parallel.
|
|
6
|
-
|
|
7
|
-
## Sprint Backlog Items
|
|
8
|
-
|
|
9
|
-
### Item1: Create chunks
|
|
10
|
-
|
|
11
|
-
- Implement: run `node '{{skill_dir}}/scripts/chunk_text.js' '{{run_dir}}/source.txt' '{{run_dir}}/chunks' {{chunk_words}}`
|
|
12
|
-
- DoD check: Chunk files are saved to `{{run_dir}}/chunks`
|
|
13
|
-
|
|
14
|
-
### Item2: Prepare loop resources
|
|
15
|
-
|
|
16
|
-
- Implement:
|
|
17
|
-
1. Create `{{run_dir}}/batch_progress.csv`:
|
|
18
|
-
```
|
|
19
|
-
chunk_id,status,retry
|
|
20
|
-
p001,pending,0
|
|
21
|
-
p002,pending,0
|
|
22
|
-
...
|
|
23
|
-
```
|
|
24
|
-
2. Read subagent prompt from `{{skill_dir}}/references/translation_prompt.md`
|
|
25
|
-
3. Read failure diagnosis guide from `{{shared_dir}}/references/failure_diagnosis.md`
|
|
26
|
-
4. Prepare variable table:
|
|
27
|
-
|
|
28
|
-
| Variable | Value | Description |
|
|
29
|
-
|---|---|---|
|
|
30
|
-
| `chunk_id` | per chunk | from batch_progress.csv |
|
|
31
|
-
| `run_dir` | `{{run_dir}}` | run data directory |
|
|
32
|
-
| `language` | `{{language}}` | target language |
|
|
33
|
-
| `skill_dir` | `{{skill_dir}}` | skill directory |
|
|
34
|
-
|
|
35
|
-
- DoD check: `batch_progress.csv` created with all chunks pending; prompt and variable table ready
|
|
36
|
-
|
|
37
|
-
### Item3: Batch translate loop
|
|
38
|
-
|
|
39
|
-
- Implement:
|
|
40
|
-
```
|
|
41
|
-
# prompt and variable table prepared in Item2
|
|
42
|
-
while true:
|
|
43
|
-
# read up to max_parallel pending/failed(retry<3) chunks
|
|
44
|
-
batch = read from batch_progress.csv where status != completed and retry < 3, up to {{max_parallel}}
|
|
45
|
-
|
|
46
|
-
# exit when no pending chunks
|
|
47
|
-
if batch is empty:
|
|
48
|
-
break
|
|
49
|
-
|
|
50
|
-
print batch N: dispatching subagents for chunks [p00m, p00n, ...]
|
|
51
|
-
|
|
52
|
-
# adjust prompt for failed chunks
|
|
53
|
-
for chunk in batch:
|
|
54
|
-
if chunk.status == failed:
|
|
55
|
-
adjust prompt based on failure_diagnosis.md
|
|
56
|
-
|
|
57
|
-
# dispatch one subagent per chunk, all in a single message
|
|
58
|
-
parallel dispatch_subagent(subagent_type: "general", description: "Translate chunk {{chunk_id}}", prompt: <subagent prompt> \n Variable table: <subagent variable table>)
|
|
59
|
-
|
|
60
|
-
# update status per chunk
|
|
61
|
-
for chunk in batch:
|
|
62
|
-
if {{run_dir}}/results/{{chunk_id}}.md exists and not empty:
|
|
63
|
-
update batch_progress.csv → completed
|
|
64
|
-
else:
|
|
65
|
-
update batch_progress.csv → failed, retry+1
|
|
66
|
-
|
|
67
|
-
print batch N status: [p00m:status, p00n:status, ...]
|
|
68
|
-
```
|
|
69
|
-
- DoD check: All chunks in `batch_progress.csv` are either `completed` or `failed` with `retry >= 3`
|
|
70
|
-
|
|
71
|
-
### Item4: Merge output
|
|
72
|
-
|
|
73
|
-
- Implement: run `node '{{skill_dir}}/scripts/merge_results.js' '{{run_dir}}/chunks' '{{run_dir}}/results' '{{output_dir}}' '{{run_name}}'`
|
|
74
|
-
- DoD check: `{{output_dir}}/{{run_name}}.txt` is generated
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
You are a translator named Paul in the Scrum Team. Please achieve the Sprint Goal within one Sprint.
|
|
2
|
-
|
|
3
|
-
## Translation Rules
|
|
4
|
-
|
|
5
|
-
| ID | Category | Rule |
|
|
6
|
-
|---|---|---|
|
|
7
|
-
| R1 | Style | **Literal translation**: do not add, remove, or alter words and content; do not change sentence order; translate sentence by sentence; do not add explanations not present in the source |
|
|
8
|
-
| R2 | Output contract | **Bilingual layout**: source paragraph first, translation paragraph second, separated by a blank line; headings are laid out the same as paragraphs; no formatting preserved |
|
|
9
|
-
| R3 | Output contract | **Output form**: output bilingual text only, no explanations, no thought process |
|
|
10
|
-
| R4 | Detail | **Footnote translation**: preserve the marker `[^N]`, content format `source \| translation` |
|
|
11
|
-
| R5 | Detail | **Source file error correction**: proactively identify OCR and other source file errors, fix during translation, use the corrected text in the source paragraph |
|
|
12
|
-
| R6 | Detail | **[CONT] marker**: a marker that may appear at the end of a chunk indicating an incomplete sentence. Preserve it in both languages |
|
|
13
|
-
|
|
14
|
-
## Sprint Goal
|
|
15
|
-
Translate 1 chunk into `{{language}}` and write to the result file.
|
|
16
|
-
|
|
17
|
-
## Sprint Increment
|
|
18
|
-
|
|
19
|
-
| Product | Type | Description | DoD |
|
|
20
|
-
|---|---|---|---|
|
|
21
|
-
| `{{run_dir}}/results/{{chunk_id}}.md` | file | Translation result (bilingual) | file exists and is not empty |
|
|
22
|
-
|
|
23
|
-
## Sprint Backlog Items
|
|
24
|
-
|
|
25
|
-
### Item1: Translate
|
|
26
|
-
- Implement: Translate `{{run_dir}}/chunks/{{chunk_id}}.txt` following the **Translation Rules** above and write directly to `{{run_dir}}/results/{{chunk_id}}.md`
|
|
27
|
-
- DoD check: `{{run_dir}}/results/{{chunk_id}}.md` exists and is not empty
|
|
28
|
-
|
|
29
|
-
### Item2: Self-check
|
|
30
|
-
- Implement: run `node '{{skill_dir}}/scripts/verify_chunk.js' '{{run_dir}}/chunks/{{chunk_id}}.txt' '{{run_dir}}/results/{{chunk_id}}.md'`
|
|
31
|
-
- DoD check: Self-check result is obtained (VALID or INVALID with reasons)
|
|
32
|
-
|
|
33
|
-
### Item3: Fix and update
|
|
34
|
-
- Short-circuit: skip when self-check result is VALID
|
|
35
|
-
- Implement: Investigate errors, fix and update `{{run_dir}}/results/{{chunk_id}}.md`. After ≤2 fix attempts, if still INVALID, stop fixing (keep the content)
|
|
36
|
-
- DoD check: Self-check update is complete
|
|
37
|
-
|
|
38
|
-
# Sprint Now!
|
|
39
|
-
|
|
40
|
-
Follow the Sequential workflow to implement:
|
|
41
|
-
1. Sprint: Execute the **Sprint Backlog Items** one by one.
|
|
42
|
-
2. Increment Check: Check that the **Sprint Increment** meets the DoD.
|
|
43
|
-
3. Sprint Review: Present the **Sprint Goal** completion or non-completion process to the team in minimal steps.
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* check_input_vars.js — Validate the input variable (input_path) extracted from context
|
|
3
|
-
*
|
|
4
|
-
* Input: input_path (source file or directory path)
|
|
5
|
-
* Validation: input_path not provided / does not exist / is neither file nor directory
|
|
6
|
-
* Invalid: print specific error + ERR_INPUT_INVALID
|
|
7
|
-
* Valid: print OK_INPUT_VALID
|
|
8
|
-
*
|
|
9
|
-
* Boundary: this script only validates context-extracted input variables;
|
|
10
|
-
* runtime variable validation (skill_data_dir, extension, no supported files in dir, etc.)
|
|
11
|
-
* is handled by resolve_run_vars.js.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import { existsSync, statSync } from 'fs'
|
|
15
|
-
import { render } from '../../shared/scripts/utils.js'
|
|
16
|
-
|
|
17
|
-
const OK_OUTPUT_TEMPLATE = 'OK: 输入校验通过'
|
|
18
|
-
const INVALID_OUTPUT_TEMPLATE = 'INVALID: ${error}'
|
|
19
|
-
const ERR_INPUT_INVALID = '请提示用户输入不合法,任务结束'
|
|
20
|
-
|
|
21
|
-
export const OK_INPUT_VALID = OK_OUTPUT_TEMPLATE
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Validate the context-extracted input variable input_path (pure function, testable).
|
|
25
|
-
* @param {string} inputPath — source file or directory path
|
|
26
|
-
* @returns {{ok: true} | {error: string}}
|
|
27
|
-
*/
|
|
28
|
-
export function checkInputVars(inputPath) {
|
|
29
|
-
if (!inputPath) {
|
|
30
|
-
return { error: `input_path 未提供,${ERR_INPUT_INVALID}` }
|
|
31
|
-
}
|
|
32
|
-
if (!existsSync(inputPath)) {
|
|
33
|
-
return { error: `input_path 不存在:${inputPath},${ERR_INPUT_INVALID}` }
|
|
34
|
-
}
|
|
35
|
-
if (!statSync(inputPath).isFile() && !statSync(inputPath).isDirectory()) {
|
|
36
|
-
return { error: `input_path 不是文件也不是目录:${inputPath},${ERR_INPUT_INVALID}` }
|
|
37
|
-
}
|
|
38
|
-
return { ok: true }
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const isMain = import.meta.url === `file://${process.argv[1]}`
|
|
42
|
-
if (isMain) {
|
|
43
|
-
const inputPath = process.argv[2]
|
|
44
|
-
|
|
45
|
-
const result = checkInputVars(inputPath)
|
|
46
|
-
|
|
47
|
-
if (result.error) {
|
|
48
|
-
console.log(render(INVALID_OUTPUT_TEMPLATE, { error: result.error }))
|
|
49
|
-
process.exit(0)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
console.log(OK_OUTPUT_TEMPLATE)
|
|
53
|
-
}
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* chunk_text.js — 文本分块脚本(ESM,段落感知),适配自 translate/chunk-text.js
|
|
4
|
-
*
|
|
5
|
-
* 输入:argv[2] = 源文本文件路径(source_txt_file),argv[3] = 输出目录(chunks_dir),argv[4] = 每块最大词数(默认 3000)
|
|
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
|
-
import { render } from '../../shared/scripts/utils.js'
|
|
17
|
-
|
|
18
|
-
// ── 输出模板(CLI stdout:status 行 + data)──
|
|
19
|
-
const CHUNKED_OUTPUT_TEMPLATE = 'chunked: ${count} chunks -> ${dir}'
|
|
20
|
-
|
|
21
|
-
// Count words (rough: split by whitespace)
|
|
22
|
-
function countWords(text) {
|
|
23
|
-
return text.trim().split(/\s+/).filter(w => w.length > 0).length
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Check if text ends with a complete sentence (sentence-ending punctuation)
|
|
27
|
-
function isParagraphComplete(text) {
|
|
28
|
-
const trimmed = text.trimEnd()
|
|
29
|
-
if (trimmed.length === 0) return true
|
|
30
|
-
// Common sentence-ending punctuation in multiple languages
|
|
31
|
-
return /[.!?。!?:;;]\s*$/.test(trimmed) ||
|
|
32
|
-
/["'」』))\]]\s*$/.test(trimmed) ||
|
|
33
|
-
trimmed.endsWith('[CONT]') // already marked
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Append [CONT] marker if last paragraph is incomplete
|
|
37
|
-
function markIncomplete(chunk) {
|
|
38
|
-
const trimmed = chunk.trimEnd()
|
|
39
|
-
if (trimmed.length === 0) return chunk
|
|
40
|
-
if (isParagraphComplete(trimmed)) return chunk
|
|
41
|
-
// Find last non-empty line
|
|
42
|
-
return chunk.replace(/\s*$/, '\n[CONT]\n')
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Hard-split within maxWords: prefer nearest sentence boundary (sentence-ending
|
|
46
|
-
// punctuation) to avoid cutting mid-sentence; fall back to word-count cut.
|
|
47
|
-
function splitAtBoundary(text, maxWords) {
|
|
48
|
-
const words = text.trim().split(/\s+/)
|
|
49
|
-
if (words.length <= maxWords) return { first: text.trim(), rest: '' }
|
|
50
|
-
let boundary = maxWords
|
|
51
|
-
for (let i = maxWords; i > 0; i--) {
|
|
52
|
-
if (/[.!?。!?:;;]["'」』))\]]?$/.test(words[i - 1])) {
|
|
53
|
-
boundary = i
|
|
54
|
-
break
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return {
|
|
58
|
-
first: words.slice(0, boundary).join(' '),
|
|
59
|
-
rest: words.slice(boundary).join(' '),
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* 将文本分块(纯函数,无 IO)。
|
|
65
|
-
* @param {string} content — 源文本(含 \f 视为 PDF 分页)
|
|
66
|
-
* @param {number} chunkWords — 每块最大词数(默认 3000)
|
|
67
|
-
* @returns {string[]} chunk 文本数组(顺序即 p001..pNNN)
|
|
68
|
-
*/
|
|
69
|
-
export function chunkText(content, chunkWords = 3000) {
|
|
70
|
-
const maxWords = chunkWords
|
|
71
|
-
let chunks = []
|
|
72
|
-
|
|
73
|
-
if (content.includes('\f')) {
|
|
74
|
-
// PDF text with form feed page breaks
|
|
75
|
-
const pages = content.split('\f')
|
|
76
|
-
let currentChunk = ''
|
|
77
|
-
|
|
78
|
-
for (let i = 0; i < pages.length; i++) {
|
|
79
|
-
const page = pages[i]
|
|
80
|
-
if (page.trim().length === 0) continue
|
|
81
|
-
|
|
82
|
-
const pageWords = countWords(page)
|
|
83
|
-
const wouldExceedWords = countWords(currentChunk) + pageWords > maxWords
|
|
84
|
-
|
|
85
|
-
if (wouldExceedWords && currentChunk.length > 0) {
|
|
86
|
-
// Mark incomplete before flushing
|
|
87
|
-
chunks.push(markIncomplete(currentChunk))
|
|
88
|
-
currentChunk = page
|
|
89
|
-
} else {
|
|
90
|
-
currentChunk += (currentChunk ? '\n' : '') + page
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Flush remaining (last chunk — don't mark [CONT], it's the end of document)
|
|
95
|
-
if (currentChunk.trim().length > 0) {
|
|
96
|
-
chunks.push(currentChunk)
|
|
97
|
-
}
|
|
98
|
-
} else {
|
|
99
|
-
// Plain text without page breaks — split by paragraph boundaries
|
|
100
|
-
const paragraphs = content.split(/\n\s*\n/) // Split on double newline (paragraph boundary)
|
|
101
|
-
|
|
102
|
-
let currentChunk = ''
|
|
103
|
-
|
|
104
|
-
for (const para of paragraphs) {
|
|
105
|
-
if (para.trim().length === 0) continue
|
|
106
|
-
|
|
107
|
-
const paraWords = countWords(para)
|
|
108
|
-
const chunkWordsNow = countWords(currentChunk)
|
|
109
|
-
|
|
110
|
-
// If adding this paragraph exceeds limit and we have content, flush
|
|
111
|
-
if (chunkWordsNow + paraWords > maxWords && currentChunk.length > 0) {
|
|
112
|
-
chunks.push(markIncomplete(currentChunk))
|
|
113
|
-
currentChunk = para
|
|
114
|
-
} else {
|
|
115
|
-
currentChunk += (currentChunk ? '\n\n' : '') + para
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// If single paragraph exceeds chunk_words, hard-split it by words
|
|
119
|
-
while (countWords(currentChunk) > maxWords) {
|
|
120
|
-
const { first, rest } = splitAtBoundary(currentChunk, maxWords)
|
|
121
|
-
chunks.push(markIncomplete(first))
|
|
122
|
-
currentChunk = rest
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// Flush remaining (last chunk — no [CONT])
|
|
127
|
-
if (currentChunk.trim().length > 0) {
|
|
128
|
-
chunks.push(currentChunk)
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return chunks
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// --- CLI ---
|
|
136
|
-
|
|
137
|
-
const isMain = import.meta.url === `file://${process.argv[1]}`
|
|
138
|
-
if (isMain) {
|
|
139
|
-
const args = process.argv.slice(2)
|
|
140
|
-
|
|
141
|
-
if (args.length < 2) {
|
|
142
|
-
console.error('usage: chunk_text.js <source_file> <output_dir> [chunk_words=3000]')
|
|
143
|
-
process.exit(2)
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const sourcePath = args[0]
|
|
147
|
-
const outputDir = args[1]
|
|
148
|
-
const chunkWords = Math.max(100, parseInt(args[2] || '3000', 10)) // CLI 最小 100 词保护
|
|
149
|
-
|
|
150
|
-
if (!existsSync(sourcePath)) {
|
|
151
|
-
console.error(`ERROR: source file not found: ${sourcePath}`)
|
|
152
|
-
process.exit(2)
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
mkdirSync(outputDir, { recursive: true })
|
|
156
|
-
|
|
157
|
-
const content = readFileSync(sourcePath, 'utf-8')
|
|
158
|
-
const chunks = chunkText(content, chunkWords)
|
|
159
|
-
|
|
160
|
-
// Write chunk files
|
|
161
|
-
chunks.forEach((chunk, i) => {
|
|
162
|
-
const id = `p${String(i + 1).padStart(3, '0')}`
|
|
163
|
-
writeFileSync(join(outputDir, `${id}.txt`), chunk, 'utf-8')
|
|
164
|
-
})
|
|
165
|
-
|
|
166
|
-
console.log(render(CHUNKED_OUTPUT_TEMPLATE, { count: chunks.length, dir: outputDir }))
|
|
167
|
-
}
|