@@ -56,16 +56,19 @@ export function validateMechanics(
5656 const virtualFiles = new Map < string , string > ( ) ;
5757 virtualFiles . set ( INTERFACES_FILE , stateInterfaces ) ;
5858
59+ // Count lines in stateInterfaces so error line numbers can be offset back to
60+ // 1-based lines within the mechanic source (used in the diagnostic loop below).
61+ const stateInterfaceLineCount = stateInterfaces . split ( '\n' ) . length ;
62+
5963 const mechanicFileNames : string [ ] = [ ] ;
6064 for ( const [ transitionId , source ] of Object . entries ( mechanicSources ) ) {
6165 const fileName = mechanicFileName ( transitionId ) ;
62- // Prepend the import so mechanic code can reference state types.
63- // Include GameState and PlayerState so mechanics can use them in type annotations
64- // (e.g. `getPlayer('p', 'field') as PlayerState['field']`). The mechanic generator
65- // prompt documents these patterns — they must be in scope for tsc to accept them.
66- const fullSource =
67- `import { GameState, PlayerState, MechanicState, CallLLM, RollDice, MechanicResult, setGame, getGame, setPlayer, getPlayer, setPublicMessage, setPrivateMessage, rejectAction, buildResult } from './state-interfaces';\n` +
68- source ;
66+ // Concatenate stateInterfaces directly into each mechanic compilation unit so
67+ // all generated types — including sub-interfaces like GameState_LastRoundChoices
68+ // produced from 'object'-typed schema fields — are in scope without needing an
69+ // explicit named import. A named import can only list statically-known symbols;
70+ // concatenation makes every exported declaration available automatically.
71+ const fullSource = stateInterfaces + '\n' + source ;
6972 virtualFiles . set ( fileName , fullSource ) ;
7073 mechanicFileNames . push ( fileName ) ;
7174 }
@@ -151,9 +154,12 @@ export function validateMechanics(
151154
152155 if ( diag . file && diag . start !== undefined ) {
153156 const pos = diag . file . getLineAndCharacterOfPosition ( diag . start ) ;
154- // Adjust for the prepended import line (line 0 in the virtual file
155- // is our synthetic import, so subtract 1 from the reported line)
156- line = pos . line ; // 0-based, but line 0 is the import → mechanic starts at line 1
157+ // Convert the 0-based position in the concatenated virtual file back to
158+ // a 1-based line number within the mechanic source itself.
159+ // The mechanic starts at line index `stateInterfaceLineCount` (0-based)
160+ // because stateInterfaces occupies lines 0..stateInterfaceLineCount-1,
161+ // followed by a blank separator line, then the mechanic source.
162+ line = pos . line - stateInterfaceLineCount + 1 ;
157163 column = pos . character ;
158164 }
159165
0 commit comments