@wwkit/harness 1.0.45 → 1.0.47
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/pea/SKILL.md +20 -5
- package/skills/pea/references/tpl-prd/epic.md +17 -2
- package/skills/pea/references/tpl-prd/us.md +4 -4
- package/skills/peago/SKILL.md +121 -0
- package/skills/peago/references/cleancode/languages/py-ut.md +88 -0
- package/skills/peago/references/cleancode/languages/py.md +222 -0
- package/skills/{blame-cleancode/references → peago/references/cleancode}/report_template.md +45 -12
- package/skills/peago/references/cleancode/rules-ut.md +133 -0
- package/skills/peago/references/cleancode/rules.md +477 -0
- package/skills/peago/references/cleancode/spec.md +204 -0
- package/skills/peago/references/lint/spec.md +160 -0
- package/skills/peago/references/res2kb/spec.md +113 -0
- package/skills/peago/references/spec-format.md +123 -0
- package/skills/peago/references/test/languages/js.md +74 -0
- package/skills/peago/references/test/languages/py.md +68 -0
- package/skills/peago/references/test/spec.md +201 -0
- package/skills/peago/references/translate/baseline.md +26 -0
- package/skills/peago/references/translate/scripts/check-structure.js +118 -0
- package/skills/{translate → peago/references/translate}/scripts/chunk-text.js +7 -2
- package/skills/peago/references/translate/scripts/extract-vision.js +267 -0
- package/skills/peago/references/translate/scripts/merge-pages.js +202 -0
- package/skills/{translate → peago/references/translate}/scripts/verify-chunk.js +15 -0
- package/skills/peago/references/translate/spec.md +140 -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/better-class/SKILL.md +0 -48
- package/skills/better-class/references/planning_spec.md +0 -91
- package/skills/better-class/references/report-template.md +0 -65
- package/skills/better-class/references/sprint_for_eo.md +0 -83
- package/skills/better-class/references/sprint_for_report.md +0 -22
- package/skills/better-class/references/subagent-prompt.md +0 -47
- package/skills/better-class/references/workflow.md +0 -75
- package/skills/better-class/scripts/check-syntax.js +0 -112
- package/skills/better-class/scripts/check_input_vars.js +0 -52
- package/skills/better-class/scripts/init.js +0 -88
- package/skills/better-class/scripts/resolve_run_vars.js +0 -96
- package/skills/better-class/scripts/run-tests.js +0 -108
- package/skills/better-cleancode/SKILL.md +0 -157
- package/skills/better-ut/SKILL.md +0 -236
- package/skills/blame-class/SKILL.md +0 -78
- package/skills/blame-class/references/report_template.md +0 -98
- package/skills/blame-class/references/rules.md +0 -40
- package/skills/blame-cleancode/SKILL.md +0 -105
- package/skills/blame-cleancode/plan.md +0 -1408
- package/skills/blame-cleancode/references/rules.md +0 -630
- package/skills/blame-ut/SKILL.md +0 -113
- package/skills/blame-ut/references/report_template.md +0 -102
- package/skills/blame-ut/references/rules.md +0 -197
- package/skills/convert-files/SKILL.md +0 -37
- package/skills/convert-files/package.json +0 -11
- package/skills/convert-files/references/sprint_for_conversion.md +0 -17
- package/skills/convert-files/scripts/check_input_vars.js +0 -54
- package/skills/convert-files/scripts/convert.js +0 -331
- package/skills/convert-files/scripts/init.js +0 -75
- package/skills/convert-files/scripts/resolve_run_vars.js +0 -124
- package/skills/create-ppt/SKILL.md +0 -47
- package/skills/create-ppt/package.json +0 -9
- package/skills/create-ppt/references/ppt-styles.md +0 -287
- package/skills/create-ppt/references/sprint_for_ppt_generation.md +0 -81
- package/skills/create-ppt/references/sprint_for_source_discovery.md +0 -18
- package/skills/create-ppt/scripts/check_input_vars.js +0 -57
- package/skills/create-ppt/scripts/find-source-files.js +0 -98
- package/skills/create-ppt/scripts/init.js +0 -96
- package/skills/create-ppt/scripts/md-to-pptx.js +0 -579
- package/skills/create-ppt/scripts/resolve_run_vars.js +0 -91
- 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/jstest/SKILL.md +0 -561
- package/skills/jstest/references/case-create.md +0 -327
- package/skills/jstest/references/case-fix.md +0 -273
- package/skills/jstest/references/config.md +0 -148
- package/skills/jstest/references/coverage-analyze.md +0 -247
- package/skills/jstest/references/env-ensure.md +0 -210
- package/skills/jstest/references/execute.md +0 -168
- package/skills/jstest/references/sample.md +0 -166
- package/skills/jstest/references/scoring-rules.md +0 -75
- package/skills/jstest/references/suitability-check.md +0 -232
- package/skills/jstest/references/test-standards.md +0 -288
- package/skills/lint/SKILL.md +0 -440
- package/skills/lint/references/ai-fix.md +0 -138
- package/skills/lint/references/config-setup.md +0 -103
- package/skills/lint/references/config.md +0 -65
- package/skills/lint/references/env-ensure.md +0 -89
- package/skills/lint/references/language-detect.md +0 -76
- package/skills/lint/references/rules-analyze.md +0 -126
- package/skills/lint/references/suitability-check.md +0 -82
- package/skills/lint/references/tool-fix.md +0 -91
- package/skills/pytest/SKILL.md +0 -556
- package/skills/pytest/references/case-create.md +0 -325
- package/skills/pytest/references/case-fix.md +0 -272
- package/skills/pytest/references/config.md +0 -145
- package/skills/pytest/references/coverage-analyze.md +0 -224
- package/skills/pytest/references/env-ensure.md +0 -196
- package/skills/pytest/references/execute.md +0 -153
- package/skills/pytest/references/sample.md +0 -160
- package/skills/pytest/references/scoring-rules.md +0 -57
- package/skills/pytest/references/suitability-check.md +0 -221
- package/skills/pytest/references/test-standards.md +0 -244
- 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/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/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
- /package/skills/{lint/references → peago/references/lint}/languages/js.md +0 -0
- /package/skills/{lint/references → peago/references/lint}/languages/py.md +0 -0
- /package/skills/{lint/references → peago/references/lint/scripts}/detect-language.js +0 -0
- /package/skills/{jstest/references/src/jstest-sample → peago/references/test/sample-src/js}/Calculator.js +0 -0
- /package/skills/{jstest/references/src/jstest-sample → peago/references/test/sample-src/js}/ConfigManager.js +0 -0
- /package/skills/{jstest/references/src/jstest-sample → peago/references/test/sample-src/js}/FileProcessor.js +0 -0
- /package/skills/{jstest/references/src/jstest-sample → peago/references/test/sample-src/js}/OrderService.js +0 -0
- /package/skills/{jstest/references/src/jstest-sample → peago/references/test/sample-src/js}/TokenGenerator.js +0 -0
- /package/skills/{jstest/references/src/jstest-sample → peago/references/test/sample-src/js}/UserService.js +0 -0
- /package/skills/{jstest/references/src/jstest-sample → peago/references/test/sample-src/js}/index.js +0 -0
- /package/skills/{pytest/references/src/pytest-sample → peago/references/test/sample-src/py}/Calculator.py +0 -0
- /package/skills/{pytest/references/src/pytest-sample → peago/references/test/sample-src/py}/ConfigManager.py +0 -0
- /package/skills/{pytest/references/src/pytest-sample → peago/references/test/sample-src/py}/FileProcessor.py +0 -0
- /package/skills/{pytest/references/src/pytest-sample → peago/references/test/sample-src/py}/OrderService.py +0 -0
- /package/skills/{pytest/references/src/pytest-sample → peago/references/test/sample-src/py}/TokenGenerator.py +0 -0
- /package/skills/{pytest/references/src/pytest-sample → peago/references/test/sample-src/py}/UserService.py +0 -0
- /package/skills/{pytest/references/src/pytest-sample → peago/references/test/sample-src/py}/__init__.py +0 -0
- /package/skills/{translate → peago/references/translate}/scripts/check-paragraphs.js +0 -0
- /package/skills/{translate → peago/references/translate}/scripts/chunk-bilingual.js +0 -0
- /package/skills/{translate → peago/references/translate}/scripts/clean-text.js +0 -0
- /package/skills/{translate → peago/references/translate}/scripts/count-terms.js +0 -0
- /package/skills/{translate → peago/references/translate}/scripts/md-to-docx.js +0 -0
- /package/skills/{translate → peago/references/translate}/scripts/merge-format.js +0 -0
- /package/skills/{translate → peago/references/translate}/scripts/merge-result.js +0 -0
|
@@ -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
|
-
}
|
|
@@ -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
|
-
// ── 输出模板(CLI stdout:status 行)──
|
|
22
|
-
const CLEAN_TEXT_OK = 'OK: clean-text'
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* 清洗文本内容,返回清洗后的内容和统计信息。
|
|
26
|
-
* @param {string} content — 原始文本
|
|
27
|
-
* @returns {{ content: string, stats: { tabs: number, carets: number, formFeeds: number } }}
|
|
28
|
-
*/
|
|
29
|
-
export function cleanText(content) {
|
|
30
|
-
let tabCount = 0
|
|
31
|
-
let caretCount = 0
|
|
32
|
-
let formFeedSplitCount = 0
|
|
33
|
-
|
|
34
|
-
// 1. 行中 \f 拆分:将 "text\fmore" 拆为 "text\n\f\nmore"
|
|
35
|
-
// \f 独占一行,保留为页标记(chunk_text.js 依赖 \f 分页)
|
|
36
|
-
const lines = content.split('\n')
|
|
37
|
-
const processedLines = []
|
|
38
|
-
|
|
39
|
-
for (const line of lines) {
|
|
40
|
-
// 独占行的 \f 是页标记,不拆分
|
|
41
|
-
if (line === '\f') {
|
|
42
|
-
processedLines.push(line)
|
|
43
|
-
continue
|
|
44
|
-
}
|
|
45
|
-
if (line.includes('\f')) {
|
|
46
|
-
const parts = line.split('\f')
|
|
47
|
-
for (let i = 0; i < parts.length; i++) {
|
|
48
|
-
if (i > 0) {
|
|
49
|
-
processedLines.push('\f')
|
|
50
|
-
formFeedSplitCount++
|
|
51
|
-
}
|
|
52
|
-
if (parts[i].length > 0) {
|
|
53
|
-
processedLines.push(parts[i])
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
} else {
|
|
57
|
-
processedLines.push(line)
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// 2. 逐行清洗:tab→空格、删除^、折叠空格、去行尾空格
|
|
62
|
-
const cleanedLines = processedLines.map(line => {
|
|
63
|
-
// 跳过 \f 独占行,不清洗
|
|
64
|
-
if (line === '\f') return line
|
|
65
|
-
|
|
66
|
-
let cleaned = line
|
|
67
|
-
|
|
68
|
-
// Tab → 空格
|
|
69
|
-
const tabs = (cleaned.match(/\t/g) || []).length
|
|
70
|
-
if (tabs > 0) {
|
|
71
|
-
cleaned = cleaned.replace(/\t/g, ' ')
|
|
72
|
-
tabCount += tabs
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// 删除 ^ 字符(OCR 噪声,不删除 \f)
|
|
76
|
-
const carets = (cleaned.match(/\^/g) || []).length
|
|
77
|
-
if (carets > 0) {
|
|
78
|
-
cleaned = cleaned.replace(/\^/g, '')
|
|
79
|
-
caretCount += carets
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// 折叠连续空格 → 单空格
|
|
83
|
-
cleaned = cleaned.replace(/ {2,}/g, ' ')
|
|
84
|
-
|
|
85
|
-
// 去行尾空格
|
|
86
|
-
cleaned = cleaned.replace(/\s+$/, '')
|
|
87
|
-
|
|
88
|
-
return cleaned
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
return {
|
|
92
|
-
content: cleanedLines.join('\n'),
|
|
93
|
-
stats: { tabs: tabCount, carets: caretCount, formFeeds: formFeedSplitCount },
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// --- CLI ---
|
|
98
|
-
|
|
99
|
-
const isMain = import.meta.url === `file://${process.argv[1]}`
|
|
100
|
-
|
|
101
|
-
if (isMain) {
|
|
102
|
-
const args = process.argv.slice(2)
|
|
103
|
-
|
|
104
|
-
if (args.length < 1) {
|
|
105
|
-
console.error('usage: clean_text.js <source.txt>')
|
|
106
|
-
process.exit(2)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const filePath = args[0]
|
|
110
|
-
|
|
111
|
-
if (!existsSync(filePath)) {
|
|
112
|
-
console.error(`ERROR: source file not found: ${filePath}`)
|
|
113
|
-
process.exit(2)
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const raw = readFileSync(filePath, 'utf-8')
|
|
117
|
-
const { content } = cleanText(raw)
|
|
118
|
-
writeFileSync(filePath, content, 'utf-8')
|
|
119
|
-
|
|
120
|
-
console.log(CLEAN_TEXT_OK)
|
|
121
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* extract.js — 源文件文本提取脚本(ESM,纯 JS,无系统依赖)
|
|
4
|
-
*
|
|
5
|
-
* 自动区分源文件类型(由 shared utils.js 工具判断):
|
|
6
|
-
* - .pdf → pdf-parse 提取(\f 分页符分隔页面),依赖由 init.js resolve_dependencies 管理
|
|
7
|
-
* - .txt / .md → 直接复制到输出路径
|
|
8
|
-
*
|
|
9
|
-
* 输入:argv[2] = 源文件路径,argv[3] = 输出文本文件路径
|
|
10
|
-
* 输出:纯文本(.pdf 以 \f 分页符分隔页面),stdout 打印行数(和页数,.pdf 时)
|
|
11
|
-
*
|
|
12
|
-
* 用法:
|
|
13
|
-
* node extract.js "<源文件路径>" "<output.txt>"
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs'
|
|
17
|
-
import { dirname } from 'path'
|
|
18
|
-
import { createRequire } from 'module'
|
|
19
|
-
import { render, isPdf } from '../../shared/scripts/utils.js'
|
|
20
|
-
|
|
21
|
-
const require = createRequire(import.meta.url)
|
|
22
|
-
|
|
23
|
-
// ── 输出模板(CLI stdout:status 行 + data)──
|
|
24
|
-
const EXTRACTED_OUTPUT_TEMPLATE = 'extracted: ${lines} lines, ~${pages} pages -> ${path}'
|
|
25
|
-
const COPIED_OUTPUT_TEMPLATE = 'copied: ${lines} lines -> ${path}'
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* 将 pdf-parse 的页面文本数组连接为纯文本(纯函数,无 IO)。
|
|
29
|
-
* 每页文本用 \f 连接(与 pdftotext 输出格式一致,chunk_text.js 依赖此格式)。
|
|
30
|
-
* @param {Array<{text: string}>} pages — pdf-parse getText() 返回的 pages
|
|
31
|
-
* @returns {string} 以 \f 分页符分隔的全文
|
|
32
|
-
*/
|
|
33
|
-
export function joinPages(pages) {
|
|
34
|
-
return pages.map(p => p.text || '').join('\f')
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// --- CLI ---
|
|
38
|
-
|
|
39
|
-
const isMain = import.meta.url === `file://${process.argv[1]}`
|
|
40
|
-
if (isMain) {
|
|
41
|
-
const args = process.argv.slice(2)
|
|
42
|
-
|
|
43
|
-
if (args.length < 2) {
|
|
44
|
-
console.error('usage: extract.js <source-file> <output-txt>')
|
|
45
|
-
process.exit(2)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const sourcePath = args[0]
|
|
49
|
-
const outPath = args[1]
|
|
50
|
-
|
|
51
|
-
// 检查源文件存在
|
|
52
|
-
if (!existsSync(sourcePath)) {
|
|
53
|
-
console.error(`ERROR: source file not found: ${sourcePath}`)
|
|
54
|
-
process.exit(2)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// 检查输出目录
|
|
58
|
-
const outDir = dirname(outPath)
|
|
59
|
-
if (!existsSync(outDir)) {
|
|
60
|
-
mkdirSync(outDir, { recursive: true })
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (isPdf(sourcePath)) {
|
|
64
|
-
// ── .pdf:pdf-parse 提取(依赖由 init.js resolve_dependencies 管理)──
|
|
65
|
-
const { PDFParse } = require('pdf-parse')
|
|
66
|
-
|
|
67
|
-
try {
|
|
68
|
-
const buf = readFileSync(sourcePath)
|
|
69
|
-
const parser = new PDFParse({ data: buf })
|
|
70
|
-
const result = await parser.getText()
|
|
71
|
-
|
|
72
|
-
if (!result || !result.pages) {
|
|
73
|
-
console.error('ERROR: pdf-parse returned no pages')
|
|
74
|
-
process.exit(4)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// 将每页文本用 \f 连接(与 pdftotext 输出格式一致,chunk_text.js 依赖此格式)
|
|
78
|
-
const content = joinPages(result.pages)
|
|
79
|
-
|
|
80
|
-
writeFileSync(outPath, content, 'utf-8')
|
|
81
|
-
|
|
82
|
-
const lines = content.split('\n').length
|
|
83
|
-
const formFeeds = (content.match(/\f/g) || []).length
|
|
84
|
-
const pageCount = formFeeds + 1
|
|
85
|
-
console.log(render(EXTRACTED_OUTPUT_TEMPLATE, { lines, pages: pageCount, path: outPath }))
|
|
86
|
-
} catch (e) {
|
|
87
|
-
console.error(`ERROR: pdf-parse failed on: ${sourcePath}`)
|
|
88
|
-
console.error(e.message)
|
|
89
|
-
process.exit(4)
|
|
90
|
-
}
|
|
91
|
-
} else {
|
|
92
|
-
// ── .txt / .md:直接复制 ──
|
|
93
|
-
const content = readFileSync(sourcePath, 'utf-8')
|
|
94
|
-
writeFileSync(outPath, content, 'utf-8')
|
|
95
|
-
const lines = content.split('\n').length
|
|
96
|
-
console.log(render(COPIED_OUTPUT_TEMPLATE, { lines, path: outPath }))
|
|
97
|
-
}
|
|
98
|
-
}
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* generate_review.js — 从 batch_progress 生成翻译自检日志(ESM),适配自 translate/generate-review.js
|
|
4
|
-
*
|
|
5
|
-
* 用法:node generate_review.js <batch_progress> [output_path]
|
|
6
|
-
*
|
|
7
|
-
* 功能(纯脚本,不需要 LLM):
|
|
8
|
-
* 1. 读取 {{run_dir}}/batch_progress.csv(CSV:chunk_id,status,retry),解析每 chunk 状态和重试次数
|
|
9
|
-
* 2. 生成 review.md(逐块自检结果 + 统计 + 结构校验 + 结论),写入 output_path(默认 batch_progress 同级 review.md)
|
|
10
|
-
*
|
|
11
|
-
* 自检日志目的:提供人工审计能力,让人确信每个 chunk 都经过了自检。
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'fs'
|
|
15
|
-
import { join, dirname } from 'path'
|
|
16
|
-
import { render } from '../../shared/scripts/utils.js'
|
|
17
|
-
|
|
18
|
-
// ── 输出模板(CLI stdout:status 行 + data)──
|
|
19
|
-
const REVIEW_OUTPUT_TEMPLATE = 'done: ${done}/${total}, failed: ${failed}, conclusion: ${conclusion}'
|
|
20
|
-
|
|
21
|
-
export function generateReview(chunkProgressPath, outputPath) {
|
|
22
|
-
if (!chunkProgressPath) {
|
|
23
|
-
throw new Error('Usage: node generate_review.js <batch_progress> [output_path]')
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (!existsSync(chunkProgressPath)) {
|
|
27
|
-
throw new Error(`batch_progress not found: ${chunkProgressPath}`)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const progress = readFileSync(chunkProgressPath, 'utf-8')
|
|
31
|
-
|
|
32
|
-
// --- Parse batch_progress (CSV: chunk_id,status,retry) ---
|
|
33
|
-
|
|
34
|
-
const chunks = []
|
|
35
|
-
for (const line of progress.split('\n')) {
|
|
36
|
-
const m = line.match(/^(p\d+),(\w+),(\d+)$/)
|
|
37
|
-
if (m) {
|
|
38
|
-
chunks.push({ id: m[1], status: m[2], retry: parseInt(m[3]) })
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (chunks.length === 0) {
|
|
43
|
-
throw new Error(`No chunk rows found in batch_progress: ${chunkProgressPath}`)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// --- Per-chunk rows ---
|
|
47
|
-
|
|
48
|
-
const rows = chunks.map(c => {
|
|
49
|
-
let note
|
|
50
|
-
if (c.status === 'completed' && c.retry === 0) {
|
|
51
|
-
note = '一次通过'
|
|
52
|
-
} else if (c.status === 'completed' && c.retry > 0) {
|
|
53
|
-
note = `重试${c.retry}次后通过`
|
|
54
|
-
} else if (c.status === 'failed' && c.retry >= 3) {
|
|
55
|
-
note = '3次失败,最终失败(原文+失败标注已合并)'
|
|
56
|
-
} else if (c.status === 'failed') {
|
|
57
|
-
note = `重试${c.retry}次,待处理`
|
|
58
|
-
} else {
|
|
59
|
-
note = '待翻译'
|
|
60
|
-
}
|
|
61
|
-
return `| ${c.id} | ${c.status} | ${c.retry} | ${note} |`
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
// --- Statistics ---
|
|
65
|
-
|
|
66
|
-
const total = chunks.length
|
|
67
|
-
const done = chunks.filter(c => c.status === 'completed')
|
|
68
|
-
const failed = chunks.filter(c => c.status === 'failed')
|
|
69
|
-
const pending = chunks.filter(c => c.status === 'pending')
|
|
70
|
-
const firstPass = done.filter(c => c.retry === 0)
|
|
71
|
-
const retryPass = done.filter(c => c.retry > 0)
|
|
72
|
-
|
|
73
|
-
const pct = (n) => (total > 0 ? (n / total * 100).toFixed(1) : '0.0')
|
|
74
|
-
|
|
75
|
-
const completionRate = pct(done.length)
|
|
76
|
-
|
|
77
|
-
// --- Conclusion ---
|
|
78
|
-
|
|
79
|
-
let conclusion
|
|
80
|
-
if (failed.length > 0 && failed.some(c => c.retry >= 3)) {
|
|
81
|
-
conclusion = '合格(含补处理)'
|
|
82
|
-
} else if (failed.length > 0) {
|
|
83
|
-
conclusion = '需修复'
|
|
84
|
-
} else if (pending.length > 0) {
|
|
85
|
-
conclusion = '进行中'
|
|
86
|
-
} else if (retryPass.length > 0) {
|
|
87
|
-
conclusion = '合格(含重试)'
|
|
88
|
-
} else {
|
|
89
|
-
conclusion = '合格'
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// --- Generate markdown ---
|
|
93
|
-
|
|
94
|
-
const now = new Date().toISOString().replace('T', ' ').slice(0, 19)
|
|
95
|
-
|
|
96
|
-
const md = `# 翻译自检日志
|
|
97
|
-
|
|
98
|
-
> 自动生成,请勿手动编辑。
|
|
99
|
-
> 最后更新:${now} UTC
|
|
100
|
-
|
|
101
|
-
## 逐块自检结果
|
|
102
|
-
|
|
103
|
-
| Chunk | 状态 | 重试 | 备注 |
|
|
104
|
-
|---|---|---|---|
|
|
105
|
-
${rows.join('\n')}
|
|
106
|
-
|
|
107
|
-
## 统计
|
|
108
|
-
|
|
109
|
-
- 总块数: ${total}
|
|
110
|
-
- 一次通过: ${firstPass.length} (${pct(firstPass.length)}%)
|
|
111
|
-
- 重试后通过: ${retryPass.length} (${pct(retryPass.length)}%)
|
|
112
|
-
- 最终失败(补处理): ${failed.filter(c => c.retry >= 3).length} (${pct(failed.filter(c => c.retry >= 3).length)}%)
|
|
113
|
-
- 待处理: ${pending.length + failed.filter(c => c.retry < 3).length} (${pct(pending.length + failed.filter(c => c.retry < 3).length)}%)
|
|
114
|
-
|
|
115
|
-
## 结构校验
|
|
116
|
-
|
|
117
|
-
| 校验项 | 结果 | 详情 |
|
|
118
|
-
|---|---|---|
|
|
119
|
-
| chunk 完成率 | ${done.length}/${total} (${completionRate}%) | ${failed.length > 0 ? '有未完成chunk' : pending.length > 0 ? '翻译进行中' : '全部完成'} |
|
|
120
|
-
|
|
121
|
-
## 结论
|
|
122
|
-
|
|
123
|
-
${conclusion}
|
|
124
|
-
`
|
|
125
|
-
|
|
126
|
-
const reviewPath = outputPath || join(dirname(chunkProgressPath), 'review.md')
|
|
127
|
-
const reviewDir = dirname(reviewPath)
|
|
128
|
-
if (!existsSync(reviewDir)) {
|
|
129
|
-
mkdirSync(reviewDir, { recursive: true })
|
|
130
|
-
}
|
|
131
|
-
writeFileSync(reviewPath, md)
|
|
132
|
-
|
|
133
|
-
return {
|
|
134
|
-
total,
|
|
135
|
-
done: done.length,
|
|
136
|
-
failed: failed.length,
|
|
137
|
-
firstPass: firstPass.length,
|
|
138
|
-
retryPass: retryPass.length,
|
|
139
|
-
conclusion,
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// --- CLI entry point ---
|
|
144
|
-
|
|
145
|
-
const isMain = import.meta.url === `file://${process.argv[1]}`
|
|
146
|
-
if (isMain) {
|
|
147
|
-
const [, , chunkProgressPath, outputPath] = process.argv
|
|
148
|
-
try {
|
|
149
|
-
const result = generateReview(chunkProgressPath, outputPath)
|
|
150
|
-
console.log(render(REVIEW_OUTPUT_TEMPLATE, { done: result.done, total: result.total, failed: result.failed, conclusion: result.conclusion }))
|
|
151
|
-
} catch (e) {
|
|
152
|
-
console.error(e.message)
|
|
153
|
-
process.exit(4)
|
|
154
|
-
}
|
|
155
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* init.js — Initialization script: runs a 5-step init flow sequentially.
|
|
3
|
-
*
|
|
4
|
-
* Flow:
|
|
5
|
-
* 1. check_input_vars — validate input variable (input_path)
|
|
6
|
-
* 2. resolve_system_vars — resolve system variables (skill_dir / shared_dir / skill_data_dir / max_parallel)
|
|
7
|
-
* 3. resolve_run_vars — create Run variables (source_file / run_name / run_dir / output_dir)
|
|
8
|
-
* 4. force_clear — when force=true, clear run_dir BEFORE any Sprint inspects it
|
|
9
|
-
* 5. resolve_dependencies — check and install npm dependencies
|
|
10
|
-
*
|
|
11
|
-
* Short-circuit: any step returns INVALID → print error + exit(0), skip remaining steps.
|
|
12
|
-
*
|
|
13
|
-
* Usage: node scripts/init.js <input_path> [force]
|
|
14
|
-
* force: the string "true" clears {{run_dir}}; anything else keeps history (default false).
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import { dirname } from 'path'
|
|
18
|
-
import { fileURLToPath } from 'url'
|
|
19
|
-
import { rmSync, mkdirSync } from 'fs'
|
|
20
|
-
import { render } from '../../shared/scripts/utils.js'
|
|
21
|
-
import { checkInputVars, OK_INPUT_VALID } from './check_input_vars.js'
|
|
22
|
-
import { resolveSystemVars, formatSystemVars } from '../../shared/scripts/resolve_system_vars.js'
|
|
23
|
-
import { resolveRunVars, formatRunVars } from './resolve_run_vars.js'
|
|
24
|
-
import { resolveDependencies, formatDependencies } from '../../shared/scripts/resolve_dependencies.js'
|
|
25
|
-
|
|
26
|
-
const INVALID_OUTPUT_TEMPLATE = 'INVALID: ${error}'
|
|
27
|
-
const OK_FORCE_CLEARED = 'OK: 历史进度已清除'
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Clear run_dir when force is true, then ensure it exists.
|
|
31
|
-
* Runs inside Environment Initialization so no Sprint can inspect stale data first.
|
|
32
|
-
* @param {string} runDir — absolute run data directory
|
|
33
|
-
* @param {boolean} force — parsed force flag
|
|
34
|
-
* @returns {boolean} true when the directory was cleared
|
|
35
|
-
*/
|
|
36
|
-
export function applyForceClear(runDir, force) {
|
|
37
|
-
if (force) {
|
|
38
|
-
rmSync(runDir, { recursive: true, force: true })
|
|
39
|
-
}
|
|
40
|
-
mkdirSync(runDir, { recursive: true })
|
|
41
|
-
return force
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const isMain = import.meta.url === `file://${process.argv[1]}`
|
|
45
|
-
if (isMain) {
|
|
46
|
-
const inputPath = process.argv[2]
|
|
47
|
-
const force = process.argv[3] === 'true'
|
|
48
|
-
const scriptDir = dirname(fileURLToPath(import.meta.url))
|
|
49
|
-
const skillDir = dirname(scriptDir)
|
|
50
|
-
|
|
51
|
-
// Step 1: Input validation (must run first, short-circuit on failure)
|
|
52
|
-
const checkResult = checkInputVars(inputPath)
|
|
53
|
-
if (checkResult.error) {
|
|
54
|
-
console.log(render(INVALID_OUTPUT_TEMPLATE, { error: checkResult.error }))
|
|
55
|
-
process.exit(0)
|
|
56
|
-
}
|
|
57
|
-
console.log(OK_INPUT_VALID)
|
|
58
|
-
console.log()
|
|
59
|
-
|
|
60
|
-
// Step 2: Resolve system variables
|
|
61
|
-
const sysVars = resolveSystemVars(skillDir)
|
|
62
|
-
console.log(formatSystemVars(sysVars))
|
|
63
|
-
console.log()
|
|
64
|
-
|
|
65
|
-
// Step 3: Create Run variables
|
|
66
|
-
const runResult = resolveRunVars(sysVars.skill_data_dir, inputPath, sysVars.skill_name)
|
|
67
|
-
if (runResult.error) {
|
|
68
|
-
console.log(render(INVALID_OUTPUT_TEMPLATE, { error: runResult.error }))
|
|
69
|
-
process.exit(0)
|
|
70
|
-
}
|
|
71
|
-
console.log(formatRunVars(runResult))
|
|
72
|
-
console.log()
|
|
73
|
-
|
|
74
|
-
// Step 4: Force clear run_dir (must precede any Sprint inspection of historical data)
|
|
75
|
-
if (applyForceClear(runResult.run_dir, force)) {
|
|
76
|
-
console.log(OK_FORCE_CLEARED)
|
|
77
|
-
console.log()
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Step 5: Check and install npm dependencies
|
|
81
|
-
const depResult = resolveDependencies(skillDir)
|
|
82
|
-
console.log('OK: 依赖检查完成')
|
|
83
|
-
console.log()
|
|
84
|
-
console.log('## Dependencies')
|
|
85
|
-
console.log(formatDependencies(depResult))
|
|
86
|
-
}
|