mirror of
https://github.com/deepseek-ai/deepseek-harness
synced 2026-08-15 21:04:50 +00:00
# Conflicts: # docs/config-catalog.md # scripts/gen-persistence-catalog.ts # scripts/jsdoc.ts # scripts/verify-md-wrap.ts # scripts/verify-package-paths.ts
72 lines
2.4 KiB
TypeScript
72 lines
2.4 KiB
TypeScript
/**
|
|
* Reject Markdown prose paragraphs spanning multiple physical lines. The GFM
|
|
* AST distinguishes paragraphs—including those in lists and blockquotes—from
|
|
* multiline structural nodes. The checker never rewrites; symlinked instruction
|
|
* files are deduped. The owning convention is in `docs/AGENTS.md`.
|
|
*/
|
|
|
|
import { readFileSync } from 'node:fs'
|
|
import { relative, resolve } from 'node:path'
|
|
import type { Nodes } from 'mdast'
|
|
import { parseMarkdown, visitMarkdown } from './markdown.ts'
|
|
import { uniqueRepoFiles } from './repo-files.ts'
|
|
|
|
const root = resolve(import.meta.dirname, '..')
|
|
|
|
/** Files to check: doc-typecheck's scope, prompt goldens, and the AGENTS.md pair. */
|
|
const PATTERNS = [
|
|
'README.md',
|
|
'README.zh.md',
|
|
'docs/**/*.md',
|
|
'packages/*/*.md',
|
|
'packages/*/*/*.md',
|
|
'examples/**/system-prompt.golden.md',
|
|
'packages/**/system-prompt.golden.md',
|
|
'AGENTS.md',
|
|
'packages/AGENTS.md',
|
|
]
|
|
|
|
/** A located hard-wrap: a prose paragraph spanning more than one source line. */
|
|
interface Violation {
|
|
file: string
|
|
/** 1-based line where the hard-wrapped paragraph starts. */
|
|
line: number
|
|
text: string
|
|
}
|
|
|
|
/** Find every hard-wrapped prose paragraph in one Markdown file via its AST. */
|
|
function findViolations(absPath: string): Violation[] {
|
|
const file = relative(root, absPath)
|
|
const source = readFileSync(absPath, 'utf8')
|
|
const tree = parseMarkdown(source)
|
|
const out: Violation[] = []
|
|
|
|
visitMarkdown(tree, (node: Nodes): boolean | void => {
|
|
if (node.type === 'paragraph' && node.position) {
|
|
const { start, end } = node.position
|
|
if (end.line > start.line) {
|
|
const firstLine = source.split('\n')[start.line - 1] ?? ''
|
|
out.push({ file, line: start.line, text: firstLine.trim() })
|
|
}
|
|
// Paragraph children are inline, so no further paragraph can be nested.
|
|
return false
|
|
}
|
|
})
|
|
return out
|
|
}
|
|
|
|
const files = uniqueRepoFiles(root, PATTERNS)
|
|
const all = files.flatMap(file => findViolations(file.abs))
|
|
const checked = files.length
|
|
|
|
if (all.length === 0) {
|
|
console.log(`verify-md-wrap: ${checked} file(s) checked, no hard-wrapped prose paragraphs.`)
|
|
process.exit(0)
|
|
}
|
|
|
|
console.error('verify-md-wrap: hard-wrapped prose paragraphs found (write one physical line per paragraph):')
|
|
for (const v of all) {
|
|
console.error(` ${v.file}:${v.line} ${v.text.slice(0, 80)}${v.text.length > 80 ? '…' : ''}`)
|
|
}
|
|
process.exit(1)
|