@@ -364,6 +364,74 @@ export function createPackagePathResolver(packageRoot?: string): (relativePath:
364364 return ( relativePath : string ) => resolveInsidePackageRoot ( packageRoot , relativePath , 'paths' ) ;
365365}
366366
367+ /**
368+ * [#28534] The package-anchored members a connector entry is handed when the
369+ * package that declared it was INSTALLED into this runtime rather than shipped
370+ * in the host's own stack: both {@link ConnectorProviderContext.loadPackageFile}
371+ * and {@link ConnectorProviderContext.resolvePackagePath} refuse every ref.
372+ *
373+ * The contract resolves a relative ref against the root of the package that
374+ * declared the entry. An installed package has no root on this runtime's disk
375+ * — the install keeps its artifact JSON and nothing else — and the only root
376+ * the host holds is its own, so answering would read, or point a launched
377+ * process at, ANOTHER package's files: an install-local app naming
378+ * `./src/system/connectors/status-openapi.json` materialized against the host
379+ * showcase's own document. So the ref is refused, naming the entry, the
380+ * package, the ref and the remedy.
381+ *
382+ * Members, not `undefined`: a factory handed `undefined` takes the
383+ * no-filesystem path, which for `resolvePackagePath` means "keep the
384+ * behaviour without it" (a stdio child inherits the host's working
385+ * directory), the same cross-package reach by another road. A refusal thrown
386+ * from the member is the factory's own failure, handled by the materializer
387+ * like every other configuration fault (fatal at boot, a skipped entry on
388+ * reload); a factory that never dereferences a ref (an inline document, an
389+ * http(s) URL) never meets it.
390+ */
391+ export function createInstalledPackageRefRefusal (
392+ connectorName : string ,
393+ packageId : string ,
394+ member : 'reads' | 'paths' ,
395+ ) : ( relativePath : string ) => Promise < never > {
396+ return async ( relativePath : string ) => {
397+ const head =
398+ `connector instance '${ connectorName } ' is declared by package '${ packageId } ', which was installed into this ` +
399+ `runtime and has no package root on its disk, so its package ${ member === 'reads' ? 'file' : 'path' } ref ` +
400+ `'${ String ( relativePath ) } ' is refused: a relative ref resolves only against the root of the package that ` +
401+ `declared it, never against the host's.` ;
402+ const remedy = member === 'reads'
403+ ? ' Rebuild the package with a current `os build`, which carries an `openapi` spec file into the artifact, ' +
404+ 'or inline the document in the package.'
405+ : ' A provider that needs a location inside the package (a stdio MCP server\'s working directory) cannot ' +
406+ 'serve an installed package\'s entry; declare a transport that needs none, such as an http MCP server.' ;
407+ throw new Error ( head + remedy ) ;
408+ } ;
409+ }
410+
411+ /**
412+ * [#28534] The id of the INSTALLED package that declared a connector entry,
413+ * or `undefined` when the entry is the host's own.
414+ *
415+ * The answer is the package registry's row for the entry's `_packageId`
416+ * stamp — its `source`, which the door that registered the package states and
417+ * the registry records without inferring it (`InstalledPackageSchema.source`,
418+ * #23972): the install-local door registers with `'marketplace'`, at install
419+ * and at every restart's rehydrate, while the host's own stack, each member of
420+ * a multi-package artifact that states no other origin, and every plugin
421+ * package register as `'code'`. Only `'marketplace'` is read as installed. An
422+ * entry with no stamp, a stamp no row answers (a composed stack's residual
423+ * owner), or no registry at all is the host's: a package reaches this runtime
424+ * as installed only through a door that writes that row.
425+ */
426+ export function installedDeclaringPackageOf (
427+ entry : unknown ,
428+ registry : { getPackage ?: ( id : string ) => { source ?: unknown } | undefined } | undefined ,
429+ ) : string | undefined {
430+ const packageId = ( entry as { _packageId ?: unknown } | null | undefined ) ?. _packageId ;
431+ if ( typeof packageId !== 'string' || packageId . length === 0 ) return undefined ;
432+ return registry ?. getPackage ?.( packageId ) ?. source === 'marketplace' ? packageId : undefined ;
433+ }
434+
367435// The credential resolver lives in ./credential-resolver.ts so the engine reads
368436// the same one for an `api` flow's `config.secretRef`; re-exported unchanged.
369437export { defaultEnvCredentialResolver , type CredentialResolver } ;
@@ -2266,6 +2334,25 @@ export class AutomationServicePlugin implements Plugin {
22662334 * down every live connector on a reload. Same rule as the flow re-sync's
22672335 * `null` read: never tear down on an absent answer.
22682336 */
2337+ /**
2338+ * [#28534] The package registry the declared connector items are read
2339+ * from — the ObjectQL registry {@link readDeclaredConnectorItems} lists
2340+ * them out of — for {@link installedDeclaringPackageOf}. `undefined` when
2341+ * no `objectql` service is registered: then no door has registered an
2342+ * installed package in this kernel either.
2343+ */
2344+ private packageRegistryOrNone (
2345+ ctx : PluginContext ,
2346+ ) : { getPackage ?: ( id : string ) => { source ?: unknown } | undefined } | undefined {
2347+ try {
2348+ return ctx . getService < {
2349+ registry ?: { getPackage ?: ( id : string ) => { source ?: unknown } | undefined } ;
2350+ } > ( 'objectql' ) ?. registry ;
2351+ } catch {
2352+ return undefined ; // no registry service
2353+ }
2354+ }
2355+
22692356 private async readDeclaredConnectorItems (
22702357 ctx : PluginContext ,
22712358 opts : { post : boolean } ,
@@ -2558,6 +2645,11 @@ export class AutomationServicePlugin implements Plugin {
25582645 if ( ! desired . has ( name ) ) this . credentialRefusalAttempts . delete ( name ) ;
25592646 }
25602647
2648+ // [#28534] The package registry, read once per run, answers which
2649+ // declaring packages were installed rather than shipped in the host's
2650+ // stack ({@link installedDeclaringPackageOf}).
2651+ const packageRegistry = this . packageRegistryOrNone ( ctx ) ;
2652+
25612653 // 2. Add new instances and re-materialize changed ones (signature diff).
25622654 let changed = 0 ;
25632655 for ( const [ name , { entry, signature } ] of desired ) {
@@ -2788,6 +2880,7 @@ export class AutomationServicePlugin implements Plugin {
27882880 retryConfig = parsed . data ;
27892881 }
27902882
2883+ const installedBy = installedDeclaringPackageOf ( entry , packageRegistry ) ;
27912884 const providerCtx : ConnectorProviderContext = {
27922885 name,
27932886 label : entry . label ?? name ,
@@ -2808,11 +2901,17 @@ export class AutomationServicePlugin implements Plugin {
28082901 requestTimeoutMs : entry . requestTimeoutMs ,
28092902 // #3016 — lets a factory dereference relative file refs (e.g.
28102903 // openapi's `providerConfig.spec: './billing-openapi.json'`),
2811- // confined to the stack/package root.
2812- loadPackageFile : createPackageFileLoader ( this . options . packageRoot ) ,
2904+ // confined to the stack/package root. [#28534] An entry an
2905+ // INSTALLED package declared is handed refusals instead: that
2906+ // package has no root here, and the host's is not its own.
2907+ loadPackageFile : installedBy === undefined
2908+ ? createPackageFileLoader ( this . options . packageRoot )
2909+ : createInstalledPackageRefRefusal ( name , installedBy , 'reads' ) ,
28132910 // #22434 — the same root as a location (e.g. a launched
28142911 // process's working directory), under the same confinement.
2815- resolvePackagePath : createPackagePathResolver ( this . options . packageRoot ) ,
2912+ resolvePackagePath : installedBy === undefined
2913+ ? createPackagePathResolver ( this . options . packageRoot )
2914+ : createInstalledPackageRefRefusal ( name , installedBy , 'paths' ) ,
28162915 } ;
28172916
28182917 let materialization ;
0 commit comments