Files
deepseek-harness/scripts/verify-concrete-terms.ts
T
Turtle e7def469e1 feat(i18n): key translation pairing records by heading section (#5036)
* feat(i18n): key translation pairing records by heading section

Replace the whole-file blob hashes in *.i18n.yaml with one entry per
heading section that still holds language-specific content, keyed by the
English heading-slug path. Blocks identical across the pair (generated
table rows, code blocks, shared regions) stay out of the hash, so edits to
different sections and identical regenerations merge with Git's default
text merge, including on GitHub.

Remove the dsh-translation-pairing merge driver, its resolver command and
installer wiring; gen-translation-brief recovers last-confirmed text from
commit history. Migrate all active records, archive the superseded Agent
Note, and record the replayed conflict reduction in the new one.

* test(i18n): refresh translation prompt snapshot for the terminology note

* feat(i18n): exclude only code blocks and generated regions from pairing records

Replace byte-equality masking with an explicit rule: a record hash skips
fenced code blocks and BEGIN/END GENERATED regions, the two kinds of
content the pairing gate already requires to be identical on both sides.

Move generated data into regions written into both pages:
gen-config-catalog renders both languages and the record with per-package
regions labelled by code identifiers; gen-module-graph keeps its table in a
region; gen-doc-graphs splices the event matrix regions into the Chinese
page. Add a generic region splice beside the region grammar.
2026-09-23 22:32:06 +08:00

106 lines
4.5 KiB
TypeScript

/** Reject one ambiguous origin label from maintained tracked files. */
import { execFileSync } from 'node:child_process'
import { lstatSync, readFileSync, readlinkSync } from 'node:fs'
import { resolve } from 'node:path'
import { pathToFileURL } from 'node:url'
import { historicalSchemaRegion } from './historical-schema-region.ts'
const root = resolve(import.meta.dirname, '..')
const blockedTerm = 'prove' + 'nance'
const excludedPrefixes = ['vendor/', '.agents/notes/archived/'] as const
/** One blocked term occurrence in a tracked path or text line. */
export interface ConcreteTermViolation {
/** Repository-relative tracked path. */
file: string
/** One-based source line, or null when the path contains the term. */
line: number | null
}
function isExcluded(file: string): boolean {
return excludedPrefixes.some(prefix => file.startsWith(prefix))
// Release snapshots retain the identifiers present in their pinned source;
// historical-format pairing records key sections by those identifiers' headings.
|| /^docs\/persistence-changes\/releases\/dsh-v\d+\.\d+\.\d+-(?:alpha|rc)\.\d+\.schema\.json$/u.test(file)
|| /^docs\/persistence-changes\/historical-formats\/v(?:0|[1-9]\d*)\.(?:schema\.json|i18n\.yaml)$/u.test(file)
}
function containsBlockedTerm(value: string): boolean {
return value.normalize('NFKC').toLowerCase().includes(blockedTerm)
}
/**
* Find the blocked term in one maintained tracked file.
* @param file - repository-relative tracked path.
* @param source - text contents or symlink target.
* @returns violations outside vendored sources, frozen Agent Notes, historical schemas and their checked generated regions.
*/
export function findConcreteTermViolations(file: string, source: string): ConcreteTermViolation[] {
if (isExcluded(file)) return []
const violations: ConcreteTermViolation[] = []
if (containsBlockedTerm(file)) violations.push({ file, line: null })
const lines = source.split(/\r?\n/u)
const schemaRegion = historicalSchemaRegion(file, source)
for (const [index, line] of lines.entries()) {
if (schemaRegion !== undefined && index >= schemaRegion[0] && index < schemaRegion[1]) continue
if (containsBlockedTerm(line)) violations.push({ file, line: index + 1 })
}
return violations
}
function trackedFiles(repoRoot: string): string[] {
const files = execFileSync('git', ['ls-files', '-z'], { cwd: repoRoot, encoding: 'utf8' })
.split('\0')
.filter(file => file !== '')
if (!files.includes('AGENTS.md')
|| !files.some(file => file.startsWith('packages/'))
|| !files.some(file => file.startsWith('docs/'))
|| !files.some(file => file.startsWith('vendor/'))
|| !files.some(file => file.startsWith('.agents/notes/archived/'))) {
throw new Error('verify-concrete-terms: tracked-file discovery omitted a required repository area')
}
return files
}
/**
* Read one tracked file without following a symlink to its target.
* @param repoRoot - Repository root containing the tracked path.
* @param file - Repository-relative tracked path.
* @returns File text, the symlink target, or undefined when the path is absent or not a file.
*/
export function readTrackedSource(repoRoot: string, file: string): string | undefined {
const path = resolve(repoRoot, file)
const stat = lstatSync(path, { throwIfNoEntry: false })
if (stat === undefined) return undefined
if (stat.isSymbolicLink()) return readlinkSync(path)
return stat.isFile() ? readFileSync(path, 'utf8') : undefined
}
function scanRepository(repoRoot: string): ConcreteTermViolation[] {
const violations: ConcreteTermViolation[] = []
for (const file of trackedFiles(repoRoot)) {
const source = readTrackedSource(repoRoot, file)
if (source === undefined) continue
violations.push(...findConcreteTermViolations(file, source))
}
return violations
}
const invokedPath = process.argv[1]
const isMain = invokedPath !== undefined && import.meta.url === pathToFileURL(resolve(invokedPath)).href
if (isMain) {
const violations = scanRepository(root)
if (violations.length === 0) {
console.log(`verify-concrete-terms: maintained tracked files contain no ${blockedTerm}.`)
} else {
console.error(`verify-concrete-terms: ${blockedTerm} is forbidden; name the exact source, field, identity, or evidence:`)
for (const violation of violations) {
console.error(violation.line === null
? ` ${violation.file} (path)`
: ` ${violation.file}:${String(violation.line)}`)
}
process.exitCode = 1
}
}