check-workspace-constraints.ts 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. /**
  2. * Workspace package invariant checks for package-manager-independent quality
  3. * gates.
  4. *
  5. * Run: `tsx scripts/check-workspace-constraints.ts`.
  6. */
  7. import { existsSync, readdirSync, readFileSync } from 'node:fs'
  8. import { join, relative, resolve } from 'node:path'
  9. import { pathToFileURL } from 'node:url'
  10. import { hasTypertRemoteNavigation, isForbiddenPublicationFile } from './publication-payload.ts'
  11. import { collectProjectReferenceFaceViolations } from './project-reference-faces.ts'
  12. const root = resolve(import.meta.dirname, '..')
  13. // vendor/* is single-level; packages/<group>/<pkg> nests one level deeper
  14. // (the group dirs — core/llm/shell/… — are pure containers with no manifest).
  15. const workspaceGlobs = [
  16. { dir: 'vendor', depth: 1 },
  17. { dir: 'packages', depth: 2 },
  18. { dir: 'native', depth: 1 },
  19. { dir: 'native/landlock-run/packages', depth: 1 },
  20. { dir: 'apps', depth: 1 },
  21. ] as const
  22. const vendoredPackages = new Set([
  23. '@deepseek-ai/cordis',
  24. '@deepseek-ai/cosmokit',
  25. '@deepseek-ai/schemastery',
  26. '@deepseek-ai/cordis-plugin-loader',
  27. '@deepseek-ai/cordis-plugin-include',
  28. '@deepseek-ai/cordis-plugin-group',
  29. '@deepseek-ai/cordis-plugin-timer',
  30. '@deepseek-ai/cordis-plugin-hmr',
  31. '@deepseek-ai/cordis-plugin-logger-console',
  32. ])
  33. const publicLandlockPackages = new Set([
  34. '@deepseek-ai/node-addon-landlock-run',
  35. '@deepseek-ai/node-addon-landlock-run-linux-arm64',
  36. '@deepseek-ai/node-addon-landlock-run-linux-x64',
  37. ])
  38. /** Deliberate source payloads whose exact bytes are part of the package's audit surface. */
  39. const publicationSourceAllowlist: Readonly<Record<string, readonly string[]>> = {
  40. '@deepseek-ai/node-addon-landlock-run': ['src/main.c'],
  41. }
  42. const repositoryUrl = 'git+https://github.com/deepseek-harness/deepseek-harness.git'
  43. /**
  44. * Source home the published packages point consumers at. It differs from
  45. * {@link repositoryUrl}, which the Landlock packages keep because npm resolves
  46. * their trusted publishing against the repository that runs the workflow.
  47. */
  48. const publishedRepositoryUrl = 'git+https://github.com/deepseek-ai/deepseek-harness.git'
  49. /** Private packages that participate in workspace checks but not releases. */
  50. const experimentalPackageDirectory = /^packages\/experimental\/[^/]+$/
  51. /** npm namespace reserved for private experimental packages. */
  52. const experimentalPackageNamePrefix = '@deepseek-ai/dsh-experimental-'
  53. /** Directories whose packages this repository publishes: one release member each. */
  54. const releaseMemberDirectory = /^(?:packages\/(?!experimental\/)[^/]+\/[^/]+|apps\/[^/]+|vendor\/[^/]+)$/
  55. const localArtifactDirs = new Set(['node_modules'])
  56. const appPackageFiles: Readonly<Record<string, readonly string[]>> = {
  57. '@deepseek-ai/dsh': ['lib/*.js', 'config'],
  58. // The Web build emits sourcemaps for browser debugging; publishing them is
  59. // what the payload policy forbids, so the bundle ships without them.
  60. '@deepseek-ai/dsh-web-frontend': ['dist', '!dist/**/*.map'],
  61. }
  62. /** The subset of package.json fields this constraint check cares about. */
  63. export interface PackageManifest {
  64. name?: string
  65. version?: string
  66. private?: boolean
  67. type?: string
  68. main?: string
  69. types?: string
  70. bin?: string | Record<string, string>
  71. exports?: Record<
  72. string,
  73. | string
  74. | {
  75. types?: string
  76. default?: string
  77. }
  78. | null
  79. | undefined
  80. >
  81. files?: string[]
  82. publishConfig?: { access?: string }
  83. repository?: { type?: string; url?: string; directory?: string }
  84. peerDependencies?: Record<string, string>
  85. devDependencies?: Record<string, string>
  86. dependencies?: Record<string, string>
  87. optionalDependencies?: Record<string, string>
  88. dsh?: {
  89. bundle?: {
  90. patch?: string
  91. }
  92. }
  93. }
  94. /** One workspace manifest and its repo-relative path. */
  95. export interface WorkspaceManifest {
  96. dir: string
  97. manifest: PackageManifest
  98. }
  99. function readJson(path: string): PackageManifest {
  100. return JSON.parse(readFileSync(path, 'utf8')) as PackageManifest
  101. }
  102. const rootManifest = readJson(join(root, 'package.json'))
  103. const repositoryVersion = rootManifest.version
  104. const landlockWorkspaceManifest = readJson(join(root, 'native/landlock-run/package.json'))
  105. const landlockVersion = landlockWorkspaceManifest.version
  106. /** Repo-relative dirs holding a package.json, walked to the configured depth. */
  107. function packageDirs(base: string, depth: number): string[] {
  108. if (depth === 1) {
  109. return readdirSync(join(root, base), { withFileTypes: true })
  110. .filter(entry => entry.isDirectory())
  111. .filter(entry => !localArtifactDirs.has(entry.name))
  112. .filter(entry => existsSync(join(root, base, entry.name, 'package.json')))
  113. .map(entry => `${base}/${entry.name}`)
  114. }
  115. return readdirSync(join(root, base), { withFileTypes: true })
  116. .filter(entry => entry.isDirectory())
  117. .filter(entry => !localArtifactDirs.has(entry.name))
  118. .flatMap(group => packageDirs(`${base}/${group.name}`, depth - 1))
  119. }
  120. function workspaceManifests(): WorkspaceManifest[] {
  121. const manifests: WorkspaceManifest[] = [
  122. { dir: '.', manifest: rootManifest },
  123. ]
  124. for (const { dir: base, depth } of workspaceGlobs) {
  125. for (const dir of packageDirs(base, depth)) {
  126. manifests.push({ dir, manifest: readJson(join(root, dir, 'package.json')) })
  127. }
  128. }
  129. return manifests
  130. }
  131. const packageFileExtras: Readonly<Record<string, readonly string[]>> = {
  132. // Statically linked client libraries keep their stylesheets next to the emitted
  133. // JavaScript, which imports them by relative path: the compile shell runs
  134. // them through its own CSS pipeline, so the sheets are published artifacts.
  135. // The glob covers whichever sheets a package emits; sourcemaps stay
  136. // unpublished, as everywhere else in the repository.
  137. '@deepseek-ai/dsh-client-ui-primitives': ['lib/**/*.css'],
  138. '@deepseek-ai/dsh-client-web': ['lib/**/*.css'],
  139. '@deepseek-ai/dsh-client-ui-theme': ['lib/styles'],
  140. // The CPython side ships as source .py files, published as-is rather than built.
  141. '@deepseek-ai/dsh-code-runtime-python': ['py/**/*.py'],
  142. // The Python runtime uses a distinct closed-resolution bin; the public CLI
  143. // keeps config-owned bare-package resolution through lib/bin.js.
  144. '@deepseek-ai/dsh-sdk-jsonrpc-demo': ['lib/packaged-bin.js'],
  145. // The argv-prefix runner entry ships beside the lib as its own bundle;
  146. // sandbox-local resolves it through the package's ./runner export. tsdown
  147. // also shares its generated FFI code through a hashed runtime chunk.
  148. '@deepseek-ai/dsh-sandbox-windows-acl': ['lib/runner.js', 'lib/types-*.js'],
  149. // SQLite loads every statement from immutable package resources at runtime.
  150. '@deepseek-ai/dsh-session-persistence-sqlite': ['resources/sql/**/*.sql'],
  151. '@deepseek-ai/dsh-skill-badge': ['assets'],
  152. '@deepseek-ai/dsh-subprocess-local': ['scripts/ensure-spawn-helper.mjs'],
  153. }
  154. function sameStringList(actual: readonly string[] | undefined, expected: readonly string[]): boolean {
  155. return !!actual && actual.length === expected.length && actual.every((value, index) => value === expected[index])
  156. }
  157. function expectedDshPackageFiles(manifest: PackageManifest): readonly string[] {
  158. const declaredPatch = manifest.dsh?.bundle?.patch
  159. const bundleFiles = declaredPatch === undefined ? [] : [declaredPatch.replace(/^\.\//, '')]
  160. const extras = [
  161. ...bundleFiles,
  162. ...(manifest.name ? packageFileExtras[manifest.name] ?? [] : []),
  163. ]
  164. return [
  165. 'lib/index.js',
  166. // Every package publishes its invariant ownership companion as a separate
  167. // bundle; the package-invariant gate validates the companion itself.
  168. 'lib/invariant.js',
  169. ...manifest.bin ? ['lib/bin.js'] : [],
  170. ...manifest.exports?.['./worker'] ? ['lib/worker.cjs'] : [],
  171. // UI plugin packages ship their browser bundle beside the node lib
  172. // (single-artifact ruling: dist/ retired, ./client resolves lib/client.js).
  173. // Keyed on the artifact path, not the subpath name: apiproxy's ./client is
  174. // a browser-safe source channel, not a bundle.
  175. ...exportDefault(manifest, './client') === './lib/client.js' ? ['lib/client.js'] : [],
  176. // runtime's shell-held loader subpath ships as its own bundle beside the client half.
  177. ...exportDefault(manifest, './loader') === './lib/loader.js' ? ['lib/loader.js'] : [],
  178. // A store subpath ships its own bundle (single-entry builds; no shared chunk).
  179. ...exportDefault(manifest, './store') === './lib/store/index.js' ? ['lib/store/index.js'] : [],
  180. // A surface bundle's startup row is its own bundle: the Loader imports it
  181. // as a row module, so it cannot ride inside the package entry.
  182. ...exportDefault(manifest, './startup') === './lib/startup.js' ? ['lib/startup.js'] : [],
  183. ...extras,
  184. // Subpaths whose runtime default is the tsc-emitted tree (lib/types/*.js —
  185. // browser-safe source channels rehomed off src so plain Node can import
  186. // them without type stripping) publish the emitted JS alongside the
  187. // declarations.
  188. ...usesEmittedTreeDefaults(manifest) ? ['lib/types/**/*.js'] : [],
  189. 'lib/types/**/*.d.ts',
  190. ...hasExportPair(manifest, './typert', './lib/typert.host.d.ts', './lib/typert.host.js')
  191. ? ['lib/typert.host.js', 'lib/typert.host.d.ts']
  192. : [],
  193. ...hasExportPair(manifest, './client/typert', './lib/typert.client.d.ts', './lib/typert.client.js')
  194. ? ['lib/typert.client.js', 'lib/typert.client.d.ts']
  195. : [],
  196. ...hasTypertRemoteNavigation(manifest)
  197. ? ['lib/typert.remote-client.js', 'lib/typert.remote-client.d.ts']
  198. : [],
  199. ]
  200. }
  201. /** Whether one conditional export exactly names the generated runtime and declaration pair. */
  202. function hasExportPair(
  203. manifest: PackageManifest,
  204. subpath: string,
  205. types: string,
  206. runtime: string,
  207. ): boolean {
  208. const entry = manifest.exports?.[subpath]
  209. return typeof entry === 'object'
  210. && entry !== null
  211. && entry.types === types
  212. && entry.default === runtime
  213. }
  214. /** Runtime target of an export entry: conditional `default`, or the bare-string shorthand. */
  215. function exportDefault(manifest: PackageManifest, subpath: string): string | undefined {
  216. const entry = manifest.exports?.[subpath]
  217. if (typeof entry === 'string') return entry
  218. if (typeof entry === 'object' && entry !== null) return entry.default
  219. return undefined
  220. }
  221. /** Whether any export's runtime default points into the tsc-emitted lib/types tree. */
  222. function usesEmittedTreeDefaults(manifest: PackageManifest): boolean {
  223. return Object.keys(manifest.exports ?? {}).some(subpath =>
  224. exportDefault(manifest, subpath)?.startsWith('./lib/types/') === true)
  225. }
  226. /** Experimental manifest requirements enforced independently from release metadata. */
  227. export function checkExperimentalManifest({ dir, manifest }: WorkspaceManifest): string[] {
  228. if (!experimentalPackageDirectory.test(dir)) return []
  229. const label = manifest.name ?? dir
  230. const errors: string[] = []
  231. if (manifest.name?.startsWith(experimentalPackageNamePrefix) !== true) {
  232. errors.push(`${label}: experimental package name must start with ${JSON.stringify(experimentalPackageNamePrefix)}`)
  233. }
  234. if (manifest.private !== true) errors.push(`${label}: experimental package must set "private": true`)
  235. if (manifest.publishConfig !== undefined) errors.push(`${label}: experimental package must omit publishConfig`)
  236. return errors
  237. }
  238. function checkWorkspace({ dir, manifest }: WorkspaceManifest): string[] {
  239. const errors = checkExperimentalManifest({ dir, manifest })
  240. const label = manifest.name ?? dir
  241. const isLandlockPackageDir = dir.startsWith('native/landlock-run/packages/')
  242. const isPublicLandlockPackage = isLandlockPackageDir
  243. && manifest.name !== undefined
  244. && publicLandlockPackages.has(manifest.name)
  245. if (isPublicLandlockPackage) {
  246. if (manifest.private === true) {
  247. errors.push(`${label}: published Landlock package must not set "private": true`)
  248. }
  249. if (manifest.publishConfig?.access !== 'public') {
  250. errors.push(`${label}: published Landlock package must set publishConfig.access to "public"`)
  251. }
  252. const expectedDirectory = dir
  253. if (manifest.repository?.type !== 'git'
  254. || manifest.repository.url !== repositoryUrl
  255. || manifest.repository.directory !== expectedDirectory) {
  256. errors.push(`${label}: published Landlock package repository must use ${repositoryUrl} with directory ${expectedDirectory} for trusted publishing`)
  257. }
  258. } else if (releaseMemberDirectory.test(dir)) {
  259. // Release members state that they are publishable: npm refuses a private
  260. // package, and the repository field is how a consumer finds the source of
  261. // the package it installed.
  262. //
  263. // Access is per release sequence, not per scope: the vendored framework and
  264. // the Landlock packages publish publicly because outside consumers install
  265. // them, while the dsh family stays restricted until its own sequence goes
  266. // public. A mixed scope is why no publish path passes `--access` — one flag
  267. // cannot serve both, so each packed manifest decides
  268. // ([rationale](../.agents/notes/implemented/process/2026-08-13-public-vendor-and-native-sequences.md)).
  269. if (manifest.private === true) {
  270. errors.push(`${label}: release member must not set "private": true`)
  271. }
  272. if (manifest.publishConfig?.access !== 'public') {
  273. errors.push(`${label}: release member must set publishConfig.access to "public"`)
  274. }
  275. if (manifest.repository?.type !== 'git'
  276. || manifest.repository.url !== publishedRepositoryUrl
  277. || manifest.repository.directory !== dir) {
  278. errors.push(`${label}: release member repository must use ${publishedRepositoryUrl} with directory ${dir}`)
  279. }
  280. } else if (!experimentalPackageDirectory.test(dir) && manifest.private !== true) {
  281. errors.push(`${label}: package.json must set "private": true`)
  282. }
  283. if (manifest.name && vendoredPackages.has(manifest.name)) {
  284. return errors
  285. }
  286. if (manifest.name?.startsWith('@deepseek-ai/')) {
  287. const allowedSources = publicationSourceAllowlist[manifest.name] ?? []
  288. for (const file of manifest.files ?? []) {
  289. if (isForbiddenPublicationFile(file) && !allowedSources.includes(file)) {
  290. errors.push(`${label}: package.json files must not publish ${JSON.stringify(file)}`)
  291. }
  292. }
  293. }
  294. if (dir.startsWith('apps/') && manifest.name?.startsWith('@deepseek-ai/')) {
  295. const expectedFiles = appPackageFiles[manifest.name]
  296. if (expectedFiles === undefined) {
  297. errors.push(`${label}: app package has no publication files policy`)
  298. } else if (!sameStringList(manifest.files, expectedFiles)) {
  299. errors.push(`${label}: package.json files must be ${JSON.stringify(expectedFiles)}`)
  300. }
  301. }
  302. if (isLandlockPackageDir) {
  303. if (!isPublicLandlockPackage) {
  304. errors.push(`${label}: unexpected package in the public Landlock package family`)
  305. }
  306. if (manifest.version !== landlockVersion) {
  307. errors.push(`${label}: package.json version must match Landlock workspace version ${landlockVersion ?? '(missing)'}`)
  308. }
  309. }
  310. if (dir.startsWith('packages/') && manifest.name?.startsWith('@deepseek-ai/dsh-')) {
  311. const peer = manifest.peerDependencies?.['@deepseek-ai/cordis']
  312. const dev = manifest.devDependencies?.['@deepseek-ai/cordis']
  313. if (!peer) errors.push(`${label}: @deepseek-ai/cordis must be a peerDependency`)
  314. if (!dev) errors.push(`${label}: @deepseek-ai/cordis must also be a devDependency`)
  315. if (peer && dev && peer !== dev) {
  316. errors.push(`${label}: @deepseek-ai/cordis peer (${peer}) and dev (${dev}) ranges must match`)
  317. }
  318. if (manifest.version !== repositoryVersion) {
  319. errors.push(`${label}: package.json version must match root version ${repositoryVersion ?? '(missing)'}`)
  320. }
  321. if (manifest.type !== 'module') {
  322. errors.push(`${label}: package.json must set "type": "module"`)
  323. }
  324. if (manifest.main !== 'lib/index.js') {
  325. errors.push(`${label}: package.json must set "main": "lib/index.js"`)
  326. }
  327. if (manifest.types !== 'lib/types/index.d.ts') {
  328. errors.push(`${label}: package.json must set "types": "lib/types/index.d.ts"`)
  329. }
  330. const rootExport = manifest.exports?.['.']
  331. const rootEntry = typeof rootExport === 'object' && rootExport !== null ? rootExport : undefined
  332. if (rootEntry?.types !== './lib/types/index.d.ts') {
  333. errors.push(`${label}: package.json exports["."].types must be "./lib/types/index.d.ts"`)
  334. }
  335. if (rootEntry?.default !== './lib/index.js') {
  336. errors.push(`${label}: package.json exports["."].default must be "./lib/index.js"`)
  337. }
  338. const invariantRaw = manifest.exports?.['./invariant']
  339. const invariantExport = typeof invariantRaw === 'object' && invariantRaw !== null ? invariantRaw : undefined
  340. if (invariantExport?.types !== undefined && invariantExport.types !== './lib/types/invariant.d.ts') {
  341. errors.push(`${label}: package.json exports["./invariant"].types must be "./lib/types/invariant.d.ts"`)
  342. }
  343. if (invariantExport?.default !== undefined && invariantExport.default !== './lib/invariant.js') {
  344. errors.push(`${label}: package.json exports["./invariant"].default must be "./lib/invariant.js"`)
  345. }
  346. if (invariantExport && (invariantExport.types === undefined || invariantExport.default === undefined)) {
  347. errors.push(`${label}: package.json exports["./invariant"] must declare both types and default targets`)
  348. }
  349. const expectedFiles = expectedDshPackageFiles(manifest)
  350. if (!sameStringList(manifest.files, expectedFiles)) {
  351. errors.push(`${label}: package.json files must be ${JSON.stringify(expectedFiles)}`)
  352. }
  353. }
  354. return errors.map(error => `${relative(root, join(root, dir, 'package.json'))}: ${error}`)
  355. }
  356. /**
  357. * Enforce `packages/<group>/<pkg>`: groups are open-named containers without a
  358. * package.json, and packages may be neither flat nor more deeply nested.
  359. */
  360. function checkHierarchyShape(): string[] {
  361. const errors: string[] = []
  362. const packagesRoot = join(root, 'packages')
  363. for (const group of readdirSync(packagesRoot, { withFileTypes: true })) {
  364. if (!group.isDirectory()) continue
  365. const groupRel = join('packages', group.name)
  366. if (existsSync(join(packagesRoot, group.name, 'package.json'))) {
  367. errors.push(`${groupRel}: a group dir must not contain a package.json — packages live at packages/<group>/<pkg>, not directly under packages/`)
  368. continue
  369. }
  370. for (const pkg of readdirSync(join(packagesRoot, group.name), { withFileTypes: true })) {
  371. if (!pkg.isDirectory()) continue
  372. if (localArtifactDirs.has(pkg.name)) continue
  373. const pkgRel = join(groupRel, pkg.name)
  374. if (!existsSync(join(packagesRoot, group.name, pkg.name, 'package.json'))) {
  375. errors.push(`${pkgRel}: expected a package here (no package.json found) — the hierarchy is exactly packages/<group>/<pkg>, no deeper nesting`)
  376. }
  377. }
  378. }
  379. return errors
  380. }
  381. function checkRepositoryVersion(): string[] {
  382. // The root carries the dsh release family's version, so a prerelease such as
  383. // 0.0.1-rc.1 is a valid state between `release:dsh` and its publication.
  384. if (repositoryVersion && /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(repositoryVersion)) return []
  385. return ['package.json: version must be X.Y.Z with an optional prerelease segment']
  386. }
  387. /** Dependency sections whose ranges reach a published tarball or a local install. */
  388. const dependencySections = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'] as const
  389. /** Dependency sections present in an installed runtime. */
  390. const runtimeDependencySections = ['dependencies', 'optionalDependencies', 'peerDependencies'] as const
  391. /**
  392. * Prevent an official runtime from requiring a package its release omits.
  393. * @param manifests - release, private experimental, and deployment-root manifests.
  394. * @returns One error for each forbidden runtime dependency.
  395. */
  396. export function checkExperimentalDependencyIsolation(manifests: readonly WorkspaceManifest[]): string[] {
  397. const experimentalNames = new Set(manifests
  398. .filter(entry => experimentalPackageDirectory.test(entry.dir))
  399. .map(entry => entry.manifest.name)
  400. .filter(name => name !== undefined))
  401. const errors: string[] = []
  402. for (const { dir, manifest } of manifests) {
  403. if (!releaseMemberDirectory.test(dir) && dir !== 'python/sdk-runtime') continue
  404. for (const section of runtimeDependencySections) {
  405. for (const name of Object.keys(manifest[section] ?? {})) {
  406. if (!experimentalNames.has(name)) continue
  407. errors.push(`${manifest.name ?? dir}: ${section}.${name} must not reference an experimental package`)
  408. }
  409. }
  410. }
  411. return errors
  412. }
  413. /**
  414. * Require the `workspace:` protocol for every reference to a workspace member.
  415. *
  416. * A hand-written range says nothing about the version the workspace actually
  417. * carries, and `pnpm pack` leaves it alone: `^0.0.1` published from version
  418. * `0.0.2` names a version that does not exist. The protocol makes pack
  419. * substitute the member's real version, so no release step rewrites ranges.
  420. * @param manifests - every workspace manifest.
  421. * @returns One error per reference that names a workspace member without the protocol.
  422. */
  423. function checkWorkspaceProtocol(manifests: readonly WorkspaceManifest[]): string[] {
  424. const members = new Set(manifests.map(entry => entry.manifest.name).filter(name => name !== undefined))
  425. const errors: string[] = []
  426. for (const { dir, manifest } of manifests) {
  427. for (const section of dependencySections) {
  428. for (const [name, range] of Object.entries(manifest[section] ?? {})) {
  429. if (!members.has(name) || range.startsWith('workspace:')) continue
  430. errors.push(`${manifest.name ?? dir}: ${section}.${name} must use the workspace: protocol, got ${range}`)
  431. }
  432. }
  433. }
  434. return errors
  435. }
  436. /** Run the repository constraint gate. */
  437. export function main(): void {
  438. const manifests = workspaceManifests()
  439. const dependencyManifests = [
  440. ...manifests,
  441. { dir: 'python/sdk-runtime', manifest: readJson(join(root, 'python/sdk-runtime/package.json')) },
  442. ]
  443. const errors = [
  444. ...checkRepositoryVersion(),
  445. ...manifests.flatMap(checkWorkspace),
  446. ...checkWorkspaceProtocol(manifests),
  447. ...checkExperimentalDependencyIsolation(dependencyManifests),
  448. ...checkHierarchyShape(),
  449. ...collectProjectReferenceFaceViolations(root),
  450. ]
  451. if (errors.length > 0) {
  452. console.error(errors.join('\n'))
  453. process.exitCode = 1
  454. }
  455. }
  456. if (process.argv[1] !== undefined && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) main()