@@ -22,6 +22,12 @@ export function contractsImplementationAuthorityViolations(
2222 for ( const file of sources ) {
2323 if ( ! isContractsProduction ( file . path ) ) continue ;
2424 const parsed = parseSync ( file . path , file . source ) ;
25+ const networkTrafficViolation = networkTrafficImplementationViolation (
26+ file . path ,
27+ file . source ,
28+ parsed . program . body ,
29+ ) ;
30+ if ( networkTrafficViolation ) violations . push ( networkTrafficViolation ) ;
2531 for ( const site of moduleSpecifiers ( parsed . module , file . source ) ) {
2632 if ( ! FORBIDDEN_HOST_MODULES . test ( site . spec ) ) continue ;
2733 violations . push (
@@ -48,6 +54,43 @@ export function contractsImplementationAuthorityViolations(
4854 return violations ;
4955}
5056
57+ function networkTrafficImplementationViolation (
58+ file : string ,
59+ source : string ,
60+ body : readonly unknown [ ] ,
61+ ) : LayeringViolation | undefined {
62+ if ( ! file . startsWith ( 'packages/contracts/src/network-traffic' ) ) return undefined ;
63+ if ( file !== 'packages/contracts/src/network-traffic.ts' ) {
64+ return violation (
65+ file ,
66+ 1 ,
67+ 'contracts may own only the neutral network-traffic vocabulary; parser modules belong in @agent-device/capture-kit' ,
68+ ) ;
69+ }
70+ const implementation = body . find ( ( statement ) => ! isTypeOnlyStatement ( statement ) ) ;
71+ if ( ! implementation || typeof implementation !== 'object' ) return undefined ;
72+ return violation (
73+ file ,
74+ lineAt ( source , Number ( ( implementation as Record < string , unknown > ) . start ?? 0 ) ) ,
75+ 'contracts network-traffic vocabulary contains runtime implementation; move parser mechanics to @agent-device/capture-kit' ,
76+ ) ;
77+ }
78+
79+ function isTypeOnlyStatement ( value : unknown ) : boolean {
80+ if ( value === null || typeof value !== 'object' ) return false ;
81+ const statement = value as Record < string , unknown > ;
82+ if ( statement . type === 'ImportDeclaration' ) return statement . importKind === 'type' ;
83+ if ( statement . type === 'TSTypeAliasDeclaration' || statement . type === 'TSInterfaceDeclaration' ) {
84+ return true ;
85+ }
86+ if ( statement . type !== 'ExportNamedDeclaration' ) return false ;
87+ if ( statement . exportKind === 'type' ) return true ;
88+ const declaration = statement . declaration as Record < string , unknown > | undefined ;
89+ return (
90+ declaration ?. type === 'TSTypeAliasDeclaration' || declaration ?. type === 'TSInterfaceDeclaration'
91+ ) ;
92+ }
93+
5194function moduleSpecifiers (
5295 module : ReturnType < typeof parseSync > [ 'module' ] ,
5396 source : string ,
0 commit comments