@@ -365,6 +365,9 @@ export class ObjectQLPlugin implements Plugin {
365365 * This closes the persistence loop so that user-created schemas survive
366366 * kernel cold starts and redeployments.
367367 *
368+ * Also registers loaded objects with the metadata service so they are
369+ * visible to tools like AI chat that query the metadata service.
370+ *
368371 * Gracefully degrades when:
369372 * - The protocol service is unavailable (e.g., in-memory-only mode).
370373 * - `loadMetaFromDb` is not implemented by the protocol shim.
@@ -387,14 +390,51 @@ export class ObjectQLPlugin implements Plugin {
387390 return ;
388391 }
389392
390- // Phase 2: DB hydration
393+ // Phase 2: DB hydration (loads into SchemaRegistry)
391394 try {
392395 const { loaded, errors } = await protocol . loadMetaFromDb ( ) ;
393396
394397 if ( loaded > 0 || errors > 0 ) {
395- ctx . logger . info ( 'Metadata restored from database' , { loaded, errors } ) ;
398+ ctx . logger . info ( 'Metadata restored from database to SchemaRegistry ' , { loaded, errors } ) ;
396399 } else {
397400 ctx . logger . debug ( 'No persisted metadata found in database' ) ;
401+ return ;
402+ }
403+
404+ // Phase 3: Bridge SchemaRegistry objects to metadata service
405+ // This ensures objects loaded from sys_metadata are visible to AI tools and other
406+ // consumers that query via IMetadataService.listObjects()
407+ if ( loaded > 0 ) {
408+ try {
409+ const metadataService = ctx . getService < any > ( 'metadata' ) ;
410+ if ( metadataService && typeof metadataService . register === 'function' && this . ql ?. registry ) {
411+ const objects = this . ql . registry . getAllObjects ( ) ;
412+ let bridged = 0 ;
413+ for ( const obj of objects ) {
414+ try {
415+ // Check if object is already in metadata service to avoid duplicates
416+ const existing = await metadataService . getObject ( obj . name ) ;
417+ if ( ! existing ) {
418+ // Register object that exists in SchemaRegistry but not in metadata service
419+ await metadataService . register ( 'object' , obj . name , obj ) ;
420+ bridged ++ ;
421+ }
422+ } catch ( e : unknown ) {
423+ ctx . logger . debug ( 'Failed to bridge object to metadata service' , {
424+ object : obj . name ,
425+ error : e instanceof Error ? e . message : String ( e ) ,
426+ } ) ;
427+ }
428+ }
429+ if ( bridged > 0 ) {
430+ ctx . logger . info ( 'Bridged objects from SchemaRegistry to metadata service' , { count : bridged } ) ;
431+ }
432+ }
433+ } catch ( e : unknown ) {
434+ ctx . logger . debug ( 'Metadata service unavailable for bridging, skipping' , {
435+ error : e instanceof Error ? e . message : String ( e ) ,
436+ } ) ;
437+ }
398438 }
399439 } catch ( e : unknown ) {
400440 // Non-fatal: first-run or in-memory driver may not have sys_metadata yet
0 commit comments