verify-package-readme-model-experience.ts 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. /**
  2. * Doc-sync gate for package README Model Experience sections. It validates
  3. * audited package classifications, context-surface fields, package-owned text
  4. * blocks, generated-catalog links, and final-section order. See the
  5. * [Model Experience RFC](../docs/rfc/implemented/process/2026-07-12-package-model-experience-contract.md).
  6. */
  7. import { existsSync, globSync, readFileSync } from 'node:fs'
  8. import { relative, resolve, sep } from 'node:path'
  9. import { markdownHeadingLines, markdownProseLines, type MarkdownProseLine } from './markdown.ts'
  10. const root = resolve(import.meta.dirname, '..')
  11. const HEADING = '## Model Experience'
  12. const LIMITATIONS_HEADING = '## Known Limitations and Deferred Work'
  13. const MODEL_VIEW_LABEL = '**What the model sees**'
  14. const TOKEN_EFFECT_LABEL = '**Token effect**'
  15. type SentenceKind = 'none' | 'indirect'
  16. interface SentenceContract {
  17. kind: SentenceKind
  18. reason: string
  19. }
  20. /**
  21. * Generic packages whose public contract is model-agnostic. Their READMEs omit
  22. * Model Experience entirely; the reason stays here as reviewable audit evidence
  23. * so an absent section cannot be mistaken for forgotten documentation.
  24. */
  25. const NO_MODEL_EXPERIENCE_SECTION: Readonly<Record<string, string>> = {
  26. 'packages/core/agent-execution': 'The package is model-agnostic ambient control infrastructure; model-facing consumers own any resulting request surface.',
  27. 'packages/core/scope': 'The package is a model-agnostic registration and lifecycle primitive; model-facing consumers own any context selection.',
  28. 'packages/util/brand': 'The package is a type-only primitive erased at compile time.',
  29. 'packages/util/paths': 'The package only resolves harness-owned host paths; model-facing consumers own any rendered use.',
  30. }
  31. /**
  32. * Packages whose Model Experience is simple enough for one gated sentence.
  33. * Every other package must carry canonical context-surface blocks. A package
  34. * moves on or off this list with the change to its context behavior.
  35. */
  36. const SENTENCE_MODEL_EXPERIENCE: Readonly<Record<string, SentenceContract>> = {
  37. 'packages/bash/bash': { kind: 'indirect', reason: 'The service interface delegates all model rendering to dsh-tool-bash.' },
  38. 'packages/bash/bash-local': { kind: 'indirect', reason: 'The executor backend delegates model rendering to dsh-tool-bash.' },
  39. 'packages/code-runtime/code-runtime': { kind: 'indirect', reason: 'The service interface delegates model rendering to Code Mode in dsh-tools.' },
  40. 'packages/code-runtime/code-runtime-worker': { kind: 'indirect', reason: 'The worker backend delegates model rendering to Code Mode in dsh-tools.' },
  41. 'packages/examples/agent-spine-demo': { kind: 'indirect', reason: 'The bundle only mounts model-facing child plugins.' },
  42. 'packages/fs/fs': { kind: 'indirect', reason: 'The service interface delegates model rendering to dsh-tool-fs.' },
  43. 'packages/fs/fs-local': { kind: 'indirect', reason: 'The provider backend delegates model rendering to dsh-tool-fs.' },
  44. 'packages/hooks/hook-protocol': { kind: 'indirect', reason: 'Only the hook bridge plugins render decoded hook output to a model.' },
  45. 'packages/llm/llm': { kind: 'none', reason: 'The adapter registry forwards already-assembled requests unchanged.' },
  46. 'packages/llm/token-meter': { kind: 'indirect', reason: 'The measurement service leaves model-visible changes to its consumers.' },
  47. 'packages/sandbox/sandbox-local': { kind: 'indirect', reason: 'The provider backend delegates model rendering to dsh-bash-sandbox and dsh-tool-bash.' },
  48. 'packages/sdk/create-sdk': { kind: 'indirect', reason: 'The initializer only writes project files; selected runtime plugins provide the generated project model surface.' },
  49. 'packages/sdk/helper': { kind: 'none', reason: 'The project domain edits files and registers no live agent or model surface.' },
  50. 'packages/sdk/scripts': { kind: 'indirect', reason: 'The launcher delegates model context to the loaded project plugin tree.' },
  51. 'packages/session-query/session-query': { kind: 'none', reason: 'The trusted query service exposes cloned records only to callers and registers no model surface.' },
  52. 'packages/skill/skill': { kind: 'indirect', reason: 'The provider registry delegates model rendering to dsh-tool-skill.' },
  53. 'packages/skill/skill-local': { kind: 'indirect', reason: 'The provider backend delegates model rendering to dsh-tool-skill.' },
  54. 'packages/spill/spill': { kind: 'indirect', reason: 'The storage seam delegates model rendering to spill consumers.' },
  55. 'packages/spill/spill-local': { kind: 'indirect', reason: 'The storage backend delegates model rendering to spill consumers.' },
  56. 'packages/subagent/subagent': { kind: 'indirect', reason: 'The provider registry delegates parent-model rendering to dsh-tool-subagent.' },
  57. 'packages/subagent/subagent-subprocess': { kind: 'indirect', reason: 'Only process-based subagent backends compose a child model request.' },
  58. 'packages/support/acp-snapshot': { kind: 'none', reason: 'The test harness observes and normalizes transcripts without changing live requests.' },
  59. 'packages/support/agent-loop-testkit': { kind: 'none', reason: 'The test helper mounts services but neither drives nor modifies model requests.' },
  60. 'packages/support/invariants': { kind: 'none', reason: 'The observer validates requests but never rewrites their context.' },
  61. 'packages/support/loader-smoke': { kind: 'none', reason: 'The test harness observes child-process streams without changing live requests.' },
  62. 'packages/support/llm-replay': { kind: 'none', reason: 'The keyless adapter invokes no provider model.' },
  63. 'packages/support/subagent-mock': { kind: 'indirect', reason: 'Only dsh-tool-subagent renders its configured test outcome.' },
  64. 'packages/tasks/tasks': { kind: 'indirect', reason: 'Producer and control-surface plugins own all model rendering over the task registry.' },
  65. 'packages/examples/acp-demo': { kind: 'indirect', reason: 'The app bundle delegates request composition to dsh-agent-spine-demo and dsh-acp.' },
  66. 'packages/ui/app-boot': { kind: 'indirect', reason: 'Only the loaded plugin tree contributes model context.' },
  67. 'packages/examples/jsonrpc-demo': { kind: 'indirect', reason: 'Only the externally configured plugin tree contributes model context.' },
  68. 'packages/ui/permission': { kind: 'indirect', reason: 'The service writes mechanism events rendered by dsh-user-approval and dsh-tool-bash.' },
  69. 'packages/ui/user-interaction': { kind: 'indirect', reason: 'Model-facing consumers render provider answers and seam errors.' },
  70. 'packages/util/home': { kind: 'indirect', reason: 'Only dsh-tool-bash exposes the resolved home to model commands.' },
  71. 'packages/util/timeout': { kind: 'indirect', reason: 'Only timeout consumers render timeout outcomes.' },
  72. 'packages/util/retention': { kind: 'indirect', reason: 'Only retention consumers render retained content and omission metadata.' },
  73. 'packages/web/web': { kind: 'indirect', reason: 'The provider registry delegates model rendering to dsh-tool-web.' },
  74. 'packages/web/web-fetch-local': { kind: 'indirect', reason: 'The provider backend delegates model rendering to dsh-tool-web.' },
  75. 'packages/web/web-search-exa': { kind: 'indirect', reason: 'The provider backend delegates model rendering to dsh-tool-web.' },
  76. 'packages/workflow/workflow': { kind: 'indirect', reason: 'The service delegates parent and child model rendering to its consumer and engine.' },
  77. }
  78. interface Failure {
  79. path: string
  80. message: string
  81. }
  82. type Line = MarkdownProseLine
  83. interface ContextSurface {
  84. heading: Line
  85. modelView: Line
  86. tokenEffect: Line
  87. title: string
  88. verbatimBlocks: number
  89. }
  90. /** Validate H4-plus-markdown literals nested after one context surface's fields. */
  91. function validateNestedVerbatim(raw: readonly string[]): { blocks: number; error?: string } {
  92. let cursor = 0
  93. while (raw[cursor]?.trim().length === 0) cursor += 1
  94. if (cursor === raw.length) return { blocks: 0 }
  95. let blocks = 0
  96. const fragments = new Set<string>()
  97. while (true) {
  98. while (raw[cursor]?.trim().length === 0) cursor += 1
  99. if (cursor === raw.length) break
  100. if (!/^#### \S/.test(raw[cursor] ?? '')) {
  101. return { blocks, error: 'content after Token effect must be a titled H4 verbatim block' }
  102. }
  103. const title = (raw[cursor] as string).slice('#### '.length)
  104. const fragment = headingFragment(title)
  105. if (fragment.length === 0) return { blocks, error: 'verbatim H4 title must be non-empty' }
  106. if (fragments.has(fragment)) {
  107. return { blocks, error: `verbatim H4 title ${JSON.stringify(title)} is duplicated within its context surface` }
  108. }
  109. fragments.add(fragment)
  110. cursor += 1
  111. while (raw[cursor]?.trim().length === 0) cursor += 1
  112. if (raw[cursor] !== '```markdown') {
  113. return { blocks, error: 'each nested verbatim H4 requires an exact ```markdown fence' }
  114. }
  115. cursor += 1
  116. const contentStart = cursor
  117. while (cursor < raw.length && raw[cursor] !== '```') cursor += 1
  118. if (cursor === raw.length) return { blocks, error: 'unterminated nested ```markdown fence' }
  119. if (cursor === contentStart) return { blocks, error: 'nested ```markdown fence must not be empty' }
  120. cursor += 1
  121. blocks += 1
  122. }
  123. return { blocks }
  124. }
  125. /** GitHub-style fragment for the simple ASCII H4 titles allowed by this contract. */
  126. function headingFragment(title: string): string {
  127. return title.toLowerCase().replaceAll('`', '').replaceAll(/[^a-z0-9 _-]/g, '').trim().replaceAll(/\s+/g, '-')
  128. }
  129. /** A direct stable system-prompt contribution, as named by the README contract. */
  130. function isDirectSystemPromptSurface(title: string): boolean {
  131. return /\bsystem prompt\b/i.test(title)
  132. }
  133. /** Anchored generated-catalog links in one model-view field. */
  134. function toolCatalogLinkFragments(text: string): string[] {
  135. return [...text.matchAll(/\]\(\.\.\/\.\.\/\.\.\/docs\/tool-catalog\.md#([a-z0-9_-]+)\)/g)]
  136. .map(match => match[1] as string)
  137. }
  138. const toolCatalogFragments = new Set<string>()
  139. for (const line of readFileSync(resolve(root, 'docs/tool-catalog.md'), 'utf8').split('\n')) {
  140. const title = /^## (.+)$/.exec(line)?.[1]
  141. if (title !== undefined) toolCatalogFragments.add(headingFragment(title))
  142. }
  143. const failures: Failure[] = []
  144. const packageJsons = globSync('packages/*/*/package.json', { cwd: root }).map(path => path.split(sep).join('/')).sort()
  145. const scannedPackages = new Set(packageJsons.map(path => path.slice(0, -'/package.json'.length)))
  146. let structuredCount = 0
  147. let contextSurfaceCount = 0
  148. let omittedSectionCount = 0
  149. let explainedNoneCount = 0
  150. let indirectCount = 0
  151. let verbatimBlockCount = 0
  152. let systemPromptSurfaceCount = 0
  153. let toolSchemaSurfaceCount = 0
  154. for (const [pkg, reason] of Object.entries(NO_MODEL_EXPERIENCE_SECTION)) {
  155. if (!scannedPackages.has(pkg)) {
  156. failures.push({ path: `${pkg}/README.md`, message: 'no-section allowlist entry does not name a scanned package' })
  157. }
  158. if (reason.trim().length === 0) {
  159. failures.push({ path: `${pkg}/README.md`, message: 'no-section allowlist entry must retain its audit justification' })
  160. }
  161. if (SENTENCE_MODEL_EXPERIENCE[pkg] !== undefined) {
  162. failures.push({ path: `${pkg}/README.md`, message: 'package cannot appear in both Model Experience allowlists' })
  163. }
  164. }
  165. for (const [pkg, contract] of Object.entries(SENTENCE_MODEL_EXPERIENCE)) {
  166. if (!scannedPackages.has(pkg)) {
  167. failures.push({ path: `${pkg}/README.md`, message: 'sentence allowlist entry does not name a scanned package' })
  168. }
  169. if (contract.reason.trim().length === 0) {
  170. failures.push({ path: `${pkg}/README.md`, message: 'sentence allowlist entry must justify why structured context surfaces are unnecessary' })
  171. }
  172. }
  173. for (const packageJson of packageJsons) {
  174. const pkg = packageJson.slice(0, -'/package.json'.length)
  175. const readme = packageJson.replace(/package\.json$/, 'README.md')
  176. const abs = resolve(root, readme)
  177. if (!existsSync(abs)) {
  178. failures.push({ path: readme, message: 'missing package README' })
  179. continue
  180. }
  181. const text = readFileSync(abs, 'utf8')
  182. const rawLines = text.split('\n')
  183. const lines = markdownProseLines(text)
  184. const headings = markdownHeadingLines(text)
  185. const h2Headings = headings.filter(heading => heading.depth === 2)
  186. const modelExperienceHeadings = headings.filter(heading => heading.text
  187. .trim().replaceAll(/\s+/g, ' ').toLowerCase() === 'model experience')
  188. const modelHeadings = modelExperienceHeadings.filter(heading => heading.depth === 2 && heading.raw === HEADING)
  189. if (NO_MODEL_EXPERIENCE_SECTION[pkg] !== undefined) {
  190. if (modelExperienceHeadings.length !== 0) {
  191. for (const heading of modelExperienceHeadings) {
  192. failures.push({ path: readme, message: `line ${heading.index}: audited model-agnostic package must omit every Model Experience heading; found ${JSON.stringify(heading.raw)}` })
  193. }
  194. } else {
  195. omittedSectionCount += 1
  196. }
  197. continue
  198. }
  199. const nonCanonicalModelHeading = modelExperienceHeadings.find(heading => heading.depth !== 2 || heading.raw !== HEADING)
  200. if (nonCanonicalModelHeading !== undefined) {
  201. failures.push({ path: readme, message: `line ${nonCanonicalModelHeading.index}: non-canonical Model Experience heading ${JSON.stringify(nonCanonicalModelHeading.raw)}; use exactly ${JSON.stringify(HEADING)}` })
  202. continue
  203. }
  204. const modelHeading = modelHeadings.at(0)
  205. if (modelHeading === undefined) {
  206. failures.push({
  207. path: readme,
  208. message: `missing ${HEADING}`,
  209. })
  210. continue
  211. }
  212. if (modelHeadings.length !== 1) {
  213. failures.push({ path: readme, message: `contains ${modelHeadings.length} copies of ${HEADING}` })
  214. continue
  215. }
  216. const modelH2Index = h2Headings.indexOf(modelHeading)
  217. const limitationsH2Index = h2Headings.findIndex(heading => heading.depth === 2 && heading.raw === LIMITATIONS_HEADING)
  218. if (limitationsH2Index >= 0) {
  219. if (modelH2Index !== h2Headings.length - 2 || limitationsH2Index !== h2Headings.length - 1) {
  220. failures.push({
  221. path: readme,
  222. message: `${HEADING} and ${LIMITATIONS_HEADING} must be the final two H2 sections, in that order`,
  223. })
  224. continue
  225. }
  226. } else if (modelH2Index !== h2Headings.length - 1) {
  227. failures.push({ path: readme, message: `${HEADING} must be the final H2 when ${LIMITATIONS_HEADING} is absent` })
  228. continue
  229. }
  230. const modelHeadingAt = lines.findIndex(line => line.index === modelHeading.index)
  231. const body = lines.slice(modelHeadingAt + 1)
  232. const h2Lines = new Set(h2Headings.map(heading => heading.index))
  233. const nextH2 = body.findIndex(line => h2Lines.has(line.index))
  234. const section = nextH2 < 0 ? body : body.slice(0, nextH2)
  235. const nextH2Line = nextH2 < 0 ? rawLines.length + 1 : (body[nextH2] as Line).index
  236. const rawSection = rawLines.slice(modelHeading.index, nextH2Line - 1)
  237. const content = section.filter(line => line.raw.trim().length > 0)
  238. const sentenceContract = SENTENCE_MODEL_EXPERIENCE[pkg]
  239. if (sentenceContract !== undefined) {
  240. const pattern = sentenceContract.kind === 'none' ? /^None, as .+\.$/ : /^Indirectly, through .+\.$/
  241. const rawContent = rawSection.filter(line => line.trim().length > 0)
  242. if (content.length !== 1 || rawContent.length !== 1 || !pattern.test(content[0]?.raw ?? '')) {
  243. const prefix = sentenceContract.kind === 'none' ? 'None, as ' : 'Indirectly, through '
  244. failures.push({ path: readme, message: `must contain exactly one sentence beginning ${JSON.stringify(prefix)} and ending with a period` })
  245. continue
  246. }
  247. if (sentenceContract.kind === 'none') explainedNoneCount += 1
  248. else indirectCount += 1
  249. continue
  250. }
  251. const shortSentence = content.find(line => line.raw === 'None.' || /^None, as |^Indirectly, through /.test(line.raw))
  252. if (shortSentence !== undefined) {
  253. failures.push({ path: readme, message: `line ${shortSentence.index}: short Model Experience form requires an audited entry in SENTENCE_MODEL_EXPERIENCE` })
  254. continue
  255. }
  256. const surfaceStarts = content
  257. .map((line, index) => ({ line, index }))
  258. .filter(entry => /^### \S/.test(entry.line.raw))
  259. if (surfaceStarts.length === 0 || surfaceStarts[0]?.index !== 0) {
  260. failures.push({ path: readme, message: 'must contain one or more complete context-surface blocks' })
  261. continue
  262. }
  263. const surfaces: ContextSurface[] = []
  264. const surfaceFragments = new Set<string>()
  265. let surfaceError = false
  266. for (let surfaceIndex = 0; surfaceIndex < surfaceStarts.length; surfaceIndex += 1) {
  267. const start = surfaceStarts[surfaceIndex] as { line: Line; index: number }
  268. const end = surfaceStarts[surfaceIndex + 1]?.index ?? content.length
  269. const entries = content.slice(start.index, end)
  270. const heading = entries[0] as Line
  271. const modelView = entries[1]
  272. const tokenEffect = entries[2]
  273. const title = heading.raw.slice('### '.length)
  274. const fragment = headingFragment(title)
  275. if (fragment.length === 0) {
  276. failures.push({ path: readme, message: `line ${heading.index}: each context surface requires a non-empty H3 heading` })
  277. surfaceError = true
  278. break
  279. }
  280. if (surfaceFragments.has(fragment)) {
  281. failures.push({ path: readme, message: `line ${heading.index}: duplicate context-surface link fragment ${JSON.stringify(fragment)}` })
  282. surfaceError = true
  283. break
  284. }
  285. if (modelView === undefined || !modelView.raw.startsWith(`${MODEL_VIEW_LABEL}: `) || modelView.raw.slice(`${MODEL_VIEW_LABEL}: `.length).trim().length === 0) {
  286. failures.push({ path: readme, message: `line ${modelView?.index ?? heading.index}: context surface requires non-empty ${MODEL_VIEW_LABEL}: text` })
  287. surfaceError = true
  288. break
  289. }
  290. if (tokenEffect === undefined || !tokenEffect.raw.startsWith(`${TOKEN_EFFECT_LABEL}: `) || tokenEffect.raw.slice(`${TOKEN_EFFECT_LABEL}: `.length).trim().length === 0) {
  291. failures.push({ path: readme, message: `line ${tokenEffect?.index ?? heading.index}: context surface requires non-empty ${TOKEN_EFFECT_LABEL}: text` })
  292. surfaceError = true
  293. break
  294. }
  295. if ((surfaceIndex === 0 && heading.index !== modelHeading.index + 2)
  296. || rawLines[heading.index - 2]?.trim().length !== 0
  297. || modelView.index !== heading.index + 2
  298. || tokenEffect.index !== modelView.index + 2) {
  299. failures.push({ path: readme, message: `line ${heading.index}: context-surface heading and fields require one blank line between each element` })
  300. surfaceError = true
  301. break
  302. }
  303. const unexpected = entries.slice(3).find(line => !/^#### \S/.test(line.raw))
  304. if (unexpected !== undefined) {
  305. failures.push({ path: readme, message: `line ${unexpected.index}: content after ${TOKEN_EFFECT_LABEL} must be a titled H4 plus \`markdown\` fence inside this context surface` })
  306. surfaceError = true
  307. break
  308. }
  309. const nextHeadingLine = surfaceStarts[surfaceIndex + 1]?.line.index ?? nextH2Line
  310. const verbatim = validateNestedVerbatim(rawLines.slice(tokenEffect.index, nextHeadingLine - 1))
  311. if (verbatim.error !== undefined) {
  312. failures.push({ path: readme, message: `line ${tokenEffect.index}: ${verbatim.error}` })
  313. surfaceError = true
  314. break
  315. }
  316. if (entries.length - 3 !== verbatim.blocks) {
  317. failures.push({ path: readme, message: `line ${tokenEffect.index}: every nested H4 must own exactly one \`markdown\` fence` })
  318. surfaceError = true
  319. break
  320. }
  321. if (/\]\(#[^)]+\)/.test(modelView.raw) || /\]\(#[^)]+\)/.test(tokenEffect.raw)) {
  322. failures.push({ path: readme, message: `line ${heading.index}: Model Experience fields must not link between local subsections; nest the H4 in its owning H3` })
  323. surfaceError = true
  324. break
  325. }
  326. surfaceFragments.add(fragment)
  327. surfaces.push({ heading, modelView, tokenEffect, title, verbatimBlocks: verbatim.blocks })
  328. }
  329. if (surfaceError) continue
  330. const promptWithoutVerbatim = surfaces.find(surface => isDirectSystemPromptSurface(surface.title)
  331. && surface.verbatimBlocks === 0)
  332. if (promptWithoutVerbatim !== undefined) {
  333. failures.push({ path: readme, message: `line ${promptWithoutVerbatim.heading.index}: system-prompt surface must contain a titled H4 plus verbatim \`markdown\` block` })
  334. continue
  335. }
  336. const hasConcreteLiteral = surfaces.some(surface => surface.verbatimBlocks > 0
  337. || surface.modelView.raw.includes('`')
  338. || surface.tokenEffect.raw.includes('`')
  339. || toolCatalogLinkFragments(surface.modelView.raw).length > 0)
  340. if (!hasConcreteLiteral) {
  341. failures.push({ path: readme, message: 'structured Model Experience must ground at least one surface with inline code, a nested `markdown` block, or an anchored tool-catalog link' })
  342. continue
  343. }
  344. let catalogError = false
  345. for (const surface of surfaces) {
  346. if (!/\bschemas?\b/i.test(surface.title)) continue
  347. const fragments = toolCatalogLinkFragments(surface.modelView.raw)
  348. if (fragments.length === 0) {
  349. failures.push({ path: readme, message: `line ${surface.heading.index}: tool-schema surface must link an anchored section of ../../../docs/tool-catalog.md` })
  350. catalogError = true
  351. break
  352. }
  353. const invalid = fragments.find(fragment => !toolCatalogFragments.has(fragment))
  354. if (invalid !== undefined) {
  355. failures.push({ path: readme, message: `line ${surface.modelView.index}: tool-catalog link fragment ${JSON.stringify(invalid)} does not name an H2 section` })
  356. catalogError = true
  357. break
  358. }
  359. }
  360. if (catalogError) continue
  361. verbatimBlockCount += surfaces.reduce((total, surface) => total + surface.verbatimBlocks, 0)
  362. contextSurfaceCount += surfaces.length
  363. systemPromptSurfaceCount += surfaces.filter(surface => isDirectSystemPromptSurface(surface.title)).length
  364. toolSchemaSurfaceCount += surfaces.filter(surface => /\bschemas?\b/i.test(surface.title)).length
  365. structuredCount += 1
  366. }
  367. if (failures.length === 0) {
  368. console.log(`verify-package-readme-model-experience: ${packageJsons.length} README(s) checked (${omittedSectionCount} audited omissions, ${structuredCount} structured, ${contextSurfaceCount} context surfaces, ${systemPromptSurfaceCount} fenced system-prompt surfaces, ${toolSchemaSurfaceCount} catalog-linked tool-schema surfaces, ${explainedNoneCount} explained none, ${indirectCount} indirect, ${verbatimBlockCount} verbatim markdown blocks), all conform.`)
  369. process.exit(0)
  370. }
  371. console.error('verify-package-readme-model-experience failed:')
  372. for (const failure of failures) {
  373. console.error(` ${relative(root, resolve(root, failure.path))}: ${failure.message}`)
  374. }
  375. process.exit(1)