@wildo-ai/dev-companion 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (224) hide show
  1. package/dist/esm/.tsbuildinfo +1 -1
  2. package/dist/esm/claude-cli/models/coding-agent-dispatch.models.d.ts +12 -1
  3. package/dist/esm/claude-cli/models/coding-agent-dispatch.models.d.ts.map +1 -1
  4. package/dist/esm/claude-cli/models/coding-agent-dispatch.models.js +11 -0
  5. package/dist/esm/claude-cli/models/coding-agent-dispatch.models.js.map +1 -1
  6. package/dist/esm/claude-cli/services/coding-agent-dispatch.companion.service.d.ts +153 -1
  7. package/dist/esm/claude-cli/services/coding-agent-dispatch.companion.service.d.ts.map +1 -1
  8. package/dist/esm/claude-cli/services/coding-agent-dispatch.companion.service.js +419 -41
  9. package/dist/esm/claude-cli/services/coding-agent-dispatch.companion.service.js.map +1 -1
  10. package/dist/esm/claude-cli/services/research-agent-dispatch.companion.service.d.ts +25 -10
  11. package/dist/esm/claude-cli/services/research-agent-dispatch.companion.service.d.ts.map +1 -1
  12. package/dist/esm/claude-cli/services/research-agent-dispatch.companion.service.js +65 -24
  13. package/dist/esm/claude-cli/services/research-agent-dispatch.companion.service.js.map +1 -1
  14. package/dist/esm/claude-cli/services/research-evidence-store.companion.d.ts +86 -0
  15. package/dist/esm/claude-cli/services/research-evidence-store.companion.d.ts.map +1 -0
  16. package/dist/esm/claude-cli/services/research-evidence-store.companion.js +127 -0
  17. package/dist/esm/claude-cli/services/research-evidence-store.companion.js.map +1 -0
  18. package/dist/esm/companion-api/companion-api.schemas.d.ts +59 -2
  19. package/dist/esm/companion-api/companion-api.schemas.d.ts.map +1 -1
  20. package/dist/esm/companion-api/companion-api.schemas.js +60 -0
  21. package/dist/esm/companion-api/companion-api.schemas.js.map +1 -1
  22. package/dist/esm/companion-api/controllers/companion.controller.d.ts +63 -1
  23. package/dist/esm/companion-api/controllers/companion.controller.d.ts.map +1 -1
  24. package/dist/esm/companion-api/controllers/companion.controller.js +322 -21
  25. package/dist/esm/companion-api/controllers/companion.controller.js.map +1 -1
  26. package/dist/esm/core/inject/models/container.d.ts.map +1 -1
  27. package/dist/esm/core/inject/models/container.js +11 -0
  28. package/dist/esm/core/inject/models/container.js.map +1 -1
  29. package/dist/esm/core/inject/models/service-types.d.ts +5 -0
  30. package/dist/esm/core/inject/models/service-types.d.ts.map +1 -1
  31. package/dist/esm/core/inject/models/service-types.js +5 -0
  32. package/dist/esm/core/inject/models/service-types.js.map +1 -1
  33. package/dist/esm/core/introspection/behaviors/companion-introspection-behavior-definitions.d.ts.map +1 -1
  34. package/dist/esm/core/introspection/behaviors/companion-introspection-behavior-definitions.js +81 -0
  35. package/dist/esm/core/introspection/behaviors/companion-introspection-behavior-definitions.js.map +1 -1
  36. package/dist/esm/core/introspection/models/companion-introspection.models.d.ts +11 -1
  37. package/dist/esm/core/introspection/models/companion-introspection.models.d.ts.map +1 -1
  38. package/dist/esm/core/introspection/models/companion-introspection.models.js +39 -0
  39. package/dist/esm/core/introspection/models/companion-introspection.models.js.map +1 -1
  40. package/dist/esm/core/introspection/resources/creation-plane-dispatch.custom-impl.companion.service.d.ts +8 -0
  41. package/dist/esm/core/introspection/resources/creation-plane-dispatch.custom-impl.companion.service.d.ts.map +1 -0
  42. package/dist/esm/core/introspection/resources/creation-plane-dispatch.custom-impl.companion.service.js +317 -0
  43. package/dist/esm/core/introspection/resources/creation-plane-dispatch.custom-impl.companion.service.js.map +1 -0
  44. package/dist/esm/core/introspection/resources/creation-plane-projection.companion.service.d.ts +45 -0
  45. package/dist/esm/core/introspection/resources/creation-plane-projection.companion.service.d.ts.map +1 -0
  46. package/dist/esm/core/introspection/resources/creation-plane-projection.companion.service.js +250 -0
  47. package/dist/esm/core/introspection/resources/creation-plane-projection.companion.service.js.map +1 -0
  48. package/dist/esm/core/introspection/resources/introspection-resource-notifier.companion.service.d.ts +123 -0
  49. package/dist/esm/core/introspection/resources/introspection-resource-notifier.companion.service.d.ts.map +1 -0
  50. package/dist/esm/core/introspection/resources/introspection-resource-notifier.companion.service.js +298 -0
  51. package/dist/esm/core/introspection/resources/introspection-resource-notifier.companion.service.js.map +1 -0
  52. package/dist/esm/core/introspection/resources/introspection-resource-source.companion.service.d.ts +78 -1
  53. package/dist/esm/core/introspection/resources/introspection-resource-source.companion.service.d.ts.map +1 -1
  54. package/dist/esm/core/introspection/resources/introspection-resource-source.companion.service.js +155 -6
  55. package/dist/esm/core/introspection/resources/introspection-resource-source.companion.service.js.map +1 -1
  56. package/dist/esm/core/introspection/services/companion-introspection.companion.service.d.ts +131 -2
  57. package/dist/esm/core/introspection/services/companion-introspection.companion.service.d.ts.map +1 -1
  58. package/dist/esm/core/introspection/services/companion-introspection.companion.service.js +259 -9
  59. package/dist/esm/core/introspection/services/companion-introspection.companion.service.js.map +1 -1
  60. package/dist/esm/core/introspection/services/introspection-derivation-state.companion.service.d.ts +243 -0
  61. package/dist/esm/core/introspection/services/introspection-derivation-state.companion.service.d.ts.map +1 -0
  62. package/dist/esm/core/introspection/services/introspection-derivation-state.companion.service.js +417 -0
  63. package/dist/esm/core/introspection/services/introspection-derivation-state.companion.service.js.map +1 -0
  64. package/dist/esm/core/introspection/services/introspection-source-state.companion.service.d.ts +186 -0
  65. package/dist/esm/core/introspection/services/introspection-source-state.companion.service.d.ts.map +1 -0
  66. package/dist/esm/core/introspection/services/introspection-source-state.companion.service.js +368 -0
  67. package/dist/esm/core/introspection/services/introspection-source-state.companion.service.js.map +1 -0
  68. package/dist/esm/core/introspection/services/introspection-source-watcher.companion.service.d.ts +101 -0
  69. package/dist/esm/core/introspection/services/introspection-source-watcher.companion.service.d.ts.map +1 -0
  70. package/dist/esm/core/introspection/services/introspection-source-watcher.companion.service.js +278 -0
  71. package/dist/esm/core/introspection/services/introspection-source-watcher.companion.service.js.map +1 -0
  72. package/dist/esm/core/introspection/subprocess/application-domain-model.behavior.d.ts +365 -0
  73. package/dist/esm/core/introspection/subprocess/application-domain-model.behavior.d.ts.map +1 -0
  74. package/dist/esm/core/introspection/subprocess/application-domain-model.behavior.js +167 -0
  75. package/dist/esm/core/introspection/subprocess/application-domain-model.behavior.js.map +1 -0
  76. package/dist/esm/core/introspection/subprocess/companion-introspection-behavior-handlers.d.ts.map +1 -1
  77. package/dist/esm/core/introspection/subprocess/companion-introspection-behavior-handlers.js +332 -3
  78. package/dist/esm/core/introspection/subprocess/companion-introspection-behavior-handlers.js.map +1 -1
  79. package/dist/esm/core/introspection/subprocess/family-aspects.behavior.d.ts +19 -0
  80. package/dist/esm/core/introspection/subprocess/family-aspects.behavior.d.ts.map +1 -0
  81. package/dist/esm/core/introspection/subprocess/family-aspects.behavior.js +164 -0
  82. package/dist/esm/core/introspection/subprocess/family-aspects.behavior.js.map +1 -0
  83. package/dist/esm/core/introspection/subprocess/openapi-generation-input.behavior.d.ts +3 -1
  84. package/dist/esm/core/introspection/subprocess/openapi-generation-input.behavior.d.ts.map +1 -1
  85. package/dist/esm/core/introspection/subprocess/openapi-generation-input.behavior.js +36 -23
  86. package/dist/esm/core/introspection/subprocess/openapi-generation-input.behavior.js.map +1 -1
  87. package/dist/esm/core/introspection/subprocess/specification-artifacts.behavior.d.ts +51 -0
  88. package/dist/esm/core/introspection/subprocess/specification-artifacts.behavior.d.ts.map +1 -0
  89. package/dist/esm/core/introspection/subprocess/specification-artifacts.behavior.js +391 -0
  90. package/dist/esm/core/introspection/subprocess/specification-artifacts.behavior.js.map +1 -0
  91. package/dist/esm/core/runtime/companion-startup-assembly.d.ts.map +1 -1
  92. package/dist/esm/core/runtime/companion-startup-assembly.js +5 -0
  93. package/dist/esm/core/runtime/companion-startup-assembly.js.map +1 -1
  94. package/dist/esm/core/runtime/dev-compile-quiet.companion.d.ts +103 -0
  95. package/dist/esm/core/runtime/dev-compile-quiet.companion.d.ts.map +1 -0
  96. package/dist/esm/core/runtime/dev-compile-quiet.companion.js +124 -0
  97. package/dist/esm/core/runtime/dev-compile-quiet.companion.js.map +1 -0
  98. package/dist/esm/core/runtime/services/start-companion-application.service.d.ts +39 -2
  99. package/dist/esm/core/runtime/services/start-companion-application.service.d.ts.map +1 -1
  100. package/dist/esm/core/runtime/services/start-companion-application.service.js +122 -11
  101. package/dist/esm/core/runtime/services/start-companion-application.service.js.map +1 -1
  102. package/dist/esm/core/specifications/non-composite-view-specification-context.shared.d.ts +6 -0
  103. package/dist/esm/core/specifications/non-composite-view-specification-context.shared.d.ts.map +1 -1
  104. package/dist/esm/core/specifications/non-composite-view-specification-context.shared.js.map +1 -1
  105. package/dist/esm/core/specifications/specification-context-factory.shared.d.ts +23 -0
  106. package/dist/esm/core/specifications/specification-context-factory.shared.d.ts.map +1 -1
  107. package/dist/esm/core/specifications/specification-context-factory.shared.js +26 -4
  108. package/dist/esm/core/specifications/specification-context-factory.shared.js.map +1 -1
  109. package/dist/esm/executions/services/companion-executions.companion.service.d.ts +82 -3
  110. package/dist/esm/executions/services/companion-executions.companion.service.d.ts.map +1 -1
  111. package/dist/esm/executions/services/companion-executions.companion.service.js +126 -12
  112. package/dist/esm/executions/services/companion-executions.companion.service.js.map +1 -1
  113. package/dist/esm/i18n/components/APP_LAYOUTS_MAIN_CONTAINER.en.d.ts +12 -0
  114. package/dist/esm/i18n/components/APP_LAYOUTS_MAIN_CONTAINER.en.d.ts.map +1 -0
  115. package/dist/esm/i18n/components/APP_LAYOUTS_MAIN_CONTAINER.en.js +12 -0
  116. package/dist/esm/i18n/components/APP_LAYOUTS_MAIN_CONTAINER.en.js.map +1 -0
  117. package/dist/esm/i18n/components/LOW_LEVEL_FORM_FIELD.en.d.ts +1 -1
  118. package/dist/esm/i18n/components/LOW_LEVEL_FORM_FIELD.en.js +1 -1
  119. package/dist/esm/i18n/components/LOW_LEVEL_FORM_FIELD.en.js.map +1 -1
  120. package/dist/esm/i18n/composite_views/app.creation-board.en.d.ts +13 -0
  121. package/dist/esm/i18n/composite_views/app.creation-board.en.d.ts.map +1 -0
  122. package/dist/esm/i18n/composite_views/app.creation-board.en.js +91 -0
  123. package/dist/esm/i18n/composite_views/app.creation-board.en.js.map +1 -0
  124. package/dist/esm/i18n/composite_views/app.domain-model.en.d.ts +38 -0
  125. package/dist/esm/i18n/composite_views/app.domain-model.en.d.ts.map +1 -0
  126. package/dist/esm/i18n/composite_views/app.domain-model.en.js +41 -0
  127. package/dist/esm/i18n/composite_views/app.domain-model.en.js.map +1 -0
  128. package/dist/esm/i18n/index.d.ts +3 -3
  129. package/dist/esm/i18n/index.js +3 -3
  130. package/dist/esm/i18n/index.js.map +1 -1
  131. package/dist/esm/i18n/resources/wildoApplicationActorSystemExecutions.en.d.ts +24 -0
  132. package/dist/esm/i18n/resources/wildoApplicationActorSystemExecutions.en.d.ts.map +1 -0
  133. package/dist/esm/i18n/resources/wildoApplicationActorSystemExecutions.en.js +20 -0
  134. package/dist/esm/i18n/resources/wildoApplicationActorSystemExecutions.en.js.map +1 -0
  135. package/dist/esm/i18n/resources/wildoApplicationActorTasks.en.d.ts +31 -0
  136. package/dist/esm/i18n/resources/wildoApplicationActorTasks.en.d.ts.map +1 -0
  137. package/dist/esm/i18n/resources/wildoApplicationActorTasks.en.js +27 -0
  138. package/dist/esm/i18n/resources/wildoApplicationActorTasks.en.js.map +1 -0
  139. package/dist/esm/i18n/resources/wildoApplicationFlowSystemExecutions.en.d.ts +24 -0
  140. package/dist/esm/i18n/resources/wildoApplicationFlowSystemExecutions.en.d.ts.map +1 -0
  141. package/dist/esm/i18n/resources/wildoApplicationFlowSystemExecutions.en.js +20 -0
  142. package/dist/esm/i18n/resources/wildoApplicationFlowSystemExecutions.en.js.map +1 -0
  143. package/dist/esm/i18n/resources/workbenchBuildPlanTasks.en.d.ts +28 -0
  144. package/dist/esm/i18n/resources/workbenchBuildPlanTasks.en.d.ts.map +1 -0
  145. package/dist/esm/i18n/resources/workbenchBuildPlanTasks.en.js +24 -0
  146. package/dist/esm/i18n/resources/workbenchBuildPlanTasks.en.js.map +1 -0
  147. package/dist/esm/i18n/resources/workbenchDomainResources.en.d.ts +138 -0
  148. package/dist/esm/i18n/resources/workbenchDomainResources.en.d.ts.map +1 -0
  149. package/dist/esm/i18n/resources/workbenchDomainResources.en.js +100 -0
  150. package/dist/esm/i18n/resources/workbenchDomainResources.en.js.map +1 -0
  151. package/dist/esm/i18n/resources/workbenchPlaybooks.en.d.ts +29 -0
  152. package/dist/esm/i18n/resources/workbenchPlaybooks.en.d.ts.map +1 -0
  153. package/dist/esm/i18n/resources/workbenchPlaybooks.en.js +25 -0
  154. package/dist/esm/i18n/resources/workbenchPlaybooks.en.js.map +1 -0
  155. package/dist/esm/i18n/resources/workbenchRunWriteRecords.en.d.ts +27 -0
  156. package/dist/esm/i18n/resources/workbenchRunWriteRecords.en.d.ts.map +1 -0
  157. package/dist/esm/i18n/resources/workbenchRunWriteRecords.en.js +23 -0
  158. package/dist/esm/i18n/resources/workbenchRunWriteRecords.en.js.map +1 -0
  159. package/dist/esm/i18n/resources/workbenchSpecificationArtifacts.en.d.ts +806 -0
  160. package/dist/esm/i18n/resources/workbenchSpecificationArtifacts.en.d.ts.map +1 -0
  161. package/dist/esm/i18n/resources/workbenchSpecificationArtifacts.en.js +326 -0
  162. package/dist/esm/i18n/resources/workbenchSpecificationArtifacts.en.js.map +1 -0
  163. package/dist/esm/i18n/resources/workbenchTraceSessions.en.d.ts +26 -0
  164. package/dist/esm/i18n/resources/workbenchTraceSessions.en.d.ts.map +1 -0
  165. package/dist/esm/i18n/resources/workbenchTraceSessions.en.js +22 -0
  166. package/dist/esm/i18n/resources/workbenchTraceSessions.en.js.map +1 -0
  167. package/dist/esm/i18n/system_enums/market.en.d.ts +202 -0
  168. package/dist/esm/i18n/system_enums/market.en.d.ts.map +1 -0
  169. package/dist/esm/i18n/system_enums/market.en.js +209 -0
  170. package/dist/esm/i18n/system_enums/market.en.js.map +1 -0
  171. package/dist/esm/meta-workflows/models/application-coding-agent.actors-system.definitions.d.ts +112 -2
  172. package/dist/esm/meta-workflows/models/application-coding-agent.actors-system.definitions.d.ts.map +1 -1
  173. package/dist/esm/meta-workflows/models/application-coding-agent.actors-system.definitions.js +201 -34
  174. package/dist/esm/meta-workflows/models/application-coding-agent.actors-system.definitions.js.map +1 -1
  175. package/dist/esm/meta-workflows/models/application-research-agent.actors-system.definitions.d.ts +31 -3
  176. package/dist/esm/meta-workflows/models/application-research-agent.actors-system.definitions.d.ts.map +1 -1
  177. package/dist/esm/meta-workflows/models/application-research-agent.actors-system.definitions.js +48 -12
  178. package/dist/esm/meta-workflows/models/application-research-agent.actors-system.definitions.js.map +1 -1
  179. package/dist/esm/meta-workflows/models/brief-adequacy.actors-system.definitions.d.ts +36 -0
  180. package/dist/esm/meta-workflows/models/brief-adequacy.actors-system.definitions.d.ts.map +1 -0
  181. package/dist/esm/meta-workflows/models/brief-adequacy.actors-system.definitions.js +75 -0
  182. package/dist/esm/meta-workflows/models/brief-adequacy.actors-system.definitions.js.map +1 -0
  183. package/dist/esm/meta-workflows/services/application-build-dispatch.companion.service.d.ts +105 -7
  184. package/dist/esm/meta-workflows/services/application-build-dispatch.companion.service.d.ts.map +1 -1
  185. package/dist/esm/meta-workflows/services/application-build-dispatch.companion.service.js +298 -24
  186. package/dist/esm/meta-workflows/services/application-build-dispatch.companion.service.js.map +1 -1
  187. package/dist/esm/meta-workflows/services/application-build-generation-step.companion.service.d.ts +46 -3
  188. package/dist/esm/meta-workflows/services/application-build-generation-step.companion.service.d.ts.map +1 -1
  189. package/dist/esm/meta-workflows/services/application-build-generation-step.companion.service.js +95 -2
  190. package/dist/esm/meta-workflows/services/application-build-generation-step.companion.service.js.map +1 -1
  191. package/dist/esm/meta-workflows/services/execution-trace-read.companion.service.d.ts +9 -0
  192. package/dist/esm/meta-workflows/services/execution-trace-read.companion.service.d.ts.map +1 -1
  193. package/dist/esm/meta-workflows/services/execution-trace-read.companion.service.js +13 -0
  194. package/dist/esm/meta-workflows/services/execution-trace-read.companion.service.js.map +1 -1
  195. package/dist/esm/meta-workflows/services/playbook-run-write-register.companion.service.d.ts +12 -0
  196. package/dist/esm/meta-workflows/services/playbook-run-write-register.companion.service.d.ts.map +1 -1
  197. package/dist/esm/meta-workflows/services/playbook-run-write-register.companion.service.js +23 -0
  198. package/dist/esm/meta-workflows/services/playbook-run-write-register.companion.service.js.map +1 -1
  199. package/dist/esm/meta-workflows/services/playbook-run.companion.service.d.ts +120 -3
  200. package/dist/esm/meta-workflows/services/playbook-run.companion.service.d.ts.map +1 -1
  201. package/dist/esm/meta-workflows/services/playbook-run.companion.service.js +636 -81
  202. package/dist/esm/meta-workflows/services/playbook-run.companion.service.js.map +1 -1
  203. package/dist/esm/meta-workflows/services/playbook-suspended-run.companion.service.d.ts +40 -0
  204. package/dist/esm/meta-workflows/services/playbook-suspended-run.companion.service.d.ts.map +1 -1
  205. package/dist/esm/meta-workflows/services/playbook-suspended-run.companion.service.js +63 -1
  206. package/dist/esm/meta-workflows/services/playbook-suspended-run.companion.service.js.map +1 -1
  207. package/dist/esm/technical-doc/services/technical-doc.companion.service.d.ts +21 -0
  208. package/dist/esm/technical-doc/services/technical-doc.companion.service.d.ts.map +1 -1
  209. package/dist/esm/technical-doc/services/technical-doc.companion.service.js +86 -2
  210. package/dist/esm/technical-doc/services/technical-doc.companion.service.js.map +1 -1
  211. package/dist/esm/technical-doc/services/technical-documentation-application-derivation.companion.service.d.ts +12 -1
  212. package/dist/esm/technical-doc/services/technical-documentation-application-derivation.companion.service.d.ts.map +1 -1
  213. package/dist/esm/technical-doc/services/technical-documentation-application-derivation.companion.service.js +47 -1
  214. package/dist/esm/technical-doc/services/technical-documentation-application-derivation.companion.service.js.map +1 -1
  215. package/package.json +17 -17
  216. package/dist/esm/.builder.pid +0 -9
  217. package/dist/esm/i18n/resources/workbenchApplicationModules.en.d.ts +0 -36
  218. package/dist/esm/i18n/resources/workbenchApplicationModules.en.d.ts.map +0 -1
  219. package/dist/esm/i18n/resources/workbenchApplicationModules.en.js +0 -32
  220. package/dist/esm/i18n/resources/workbenchApplicationModules.en.js.map +0 -1
  221. package/dist/esm/i18n/resources/workbenchResourceRelationships.en.d.ts +0 -29
  222. package/dist/esm/i18n/resources/workbenchResourceRelationships.en.d.ts.map +0 -1
  223. package/dist/esm/i18n/resources/workbenchResourceRelationships.en.js +0 -25
  224. package/dist/esm/i18n/resources/workbenchResourceRelationships.en.js.map +0 -1
@@ -12,7 +12,9 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
12
  };
13
13
  import { inject, injectable } from 'inversify';
14
14
  import { SAAS_SERVICE_TYPES, } from '@wildo-ai/saas-backend-lib';
15
+ import { ResourcePrimaryScope } from '@wildo-ai/saas-models';
15
16
  import { COMPANION_SERVICE_TYPES } from '../../inject/models/service-types.js';
17
+ import { CreationPlaneProjectionCompanionService } from './creation-plane-projection.companion.service.js';
16
18
  /**
17
19
  * The companion's implementation of the engine's `PersistenceAdapter.INTROSPECTION` port.
18
20
  *
@@ -59,10 +61,12 @@ let IntrospectionResourceSourceCompanionService = class IntrospectionResourceSou
59
61
  introspectionService;
60
62
  companionContext;
61
63
  resourcesRegistry;
62
- constructor(introspectionService, companionContext, resourcesRegistry) {
64
+ creationPlane;
65
+ constructor(introspectionService, companionContext, resourcesRegistry, creationPlane) {
63
66
  this.introspectionService = introspectionService;
64
67
  this.companionContext = companionContext;
65
68
  this.resourcesRegistry = resourcesRegistry;
69
+ this.creationPlane = creationPlane;
66
70
  }
67
71
  supports(resourceType) {
68
72
  return this.resolveBinding(resourceType) !== undefined;
@@ -73,6 +77,19 @@ let IntrospectionResourceSourceCompanionService = class IntrospectionResourceSou
73
77
  throw new Error(`Resource '${query.resourceType}' is INTROSPECTION-backed but declares no 'introspectionBinding'. `
74
78
  + 'The binding names the companion behavior whose output becomes its rows.');
75
79
  }
80
+ /*
81
+ * TWO materialization lanes behind one binding vocabulary (Phase 2 of
82
+ * `workbench-creation-board-resources.md`): a creation-plane behavior id is served IN-PROCESS
83
+ * from the companion's own runtime services — no subprocess, no app-dist import, and the rows
84
+ * arrive with their identity fields already emitted (their business keys carry characters the
85
+ * composed-identity charset refuses). Everything else flows to the subprocess lane below,
86
+ * untouched. The membership test is owned by the same package that writes the ids into the
87
+ * bindings, so the two ends cannot drift.
88
+ */
89
+ if (this.creationPlane.supports(binding.behavior)) {
90
+ const rows = await this.creationPlane.deriveRows(binding.behavior);
91
+ return { rows: this.selectRows(rows, query) };
92
+ }
76
93
  const serviceKey = this.resolveServiceKey();
77
94
  const result = await this.introspectionService.requestInfo({
78
95
  serviceKey,
@@ -85,6 +102,91 @@ let IntrospectionResourceSourceCompanionService = class IntrospectionResourceSou
85
102
  const rows = this.projectRows(result.data, binding, query.resourceType);
86
103
  return { rows: this.selectRows(rows, query) };
87
104
  }
105
+ /**
106
+ * Compile every introspection behavior the registry declares, before anyone reads one.
107
+ *
108
+ * A supervised restart empties the compiled state, and restarts are frequent — 26 self-sent
109
+ * SIGTERMs were logged in one wonder-crm session on 2026-09-02. Without this, the first operator
110
+ * to open the workbench after any restart pays a full cold derivation, measured at 8.8 s.
111
+ *
112
+ * One request per BEHAVIOR rather than per resource: two resources projecting one behavior are one
113
+ * derivation, so asking once keeps the count honest about how much work was actually done.
114
+ * Creation-plane behaviors are skipped — they are served in-process from the companion's own
115
+ * runtime state, carry their own cache, and have no subprocess to warm.
116
+ *
117
+ * Never throws. Warming is a latency improvement over a path that already works, and the caller
118
+ * treats a failure as a warning: a companion that refused to finish booting because an
119
+ * application's `dist` was mid-build would need the companion this failure just prevented from
120
+ * starting in order to be repaired.
121
+ */
122
+ async warmDeclaredDerivations() {
123
+ const behaviors = [...this.resolveResourceTypesByBehavior().keys()]
124
+ .filter((behavior) => !this.creationPlane.supports(behavior));
125
+ if (behaviors.length === 0)
126
+ return { attempted: 0, failed: 0 };
127
+ const serviceKey = this.resolveServiceKey();
128
+ const outcomes = await Promise.allSettled(behaviors.map((behavior) => this.introspectionService.requestInfo({ serviceKey, behavior: behavior })));
129
+ const failed = outcomes.filter((outcome) => outcome.status === 'rejected'
130
+ || (outcome.status === 'fulfilled' && !outcome.value.success)).length;
131
+ return { attempted: behaviors.length, failed };
132
+ }
133
+ /**
134
+ * Every INTROSPECTION-backed resource in the registry, grouped by the behavior it projects.
135
+ *
136
+ * The notifier needs the reverse of what a read needs: a read has a resource and wants its
137
+ * behavior, while a recompilation has a behavior and wants every resource whose rows just moved.
138
+ * Derived from the SAME registry declarations rather than from a table, for the reason the class
139
+ * docstring already gives — a second enumeration of a population the resource configurations
140
+ * define would agree only until one side gained an entry.
141
+ */
142
+ resolveResourceTypesByBehavior() {
143
+ const configurations = this.resourcesRegistry.getResourcesRegistry().resourceConfigurations;
144
+ const byBehavior = new Map();
145
+ for (const [resourceType, configuration] of Object.entries(configurations)) {
146
+ const behavior = configuration?.introspectionBinding?.behavior;
147
+ if (!behavior)
148
+ continue;
149
+ const existing = byBehavior.get(behavior);
150
+ if (existing)
151
+ existing.push(resourceType);
152
+ else
153
+ byBehavior.set(behavior, [resourceType]);
154
+ }
155
+ return byBehavior;
156
+ }
157
+ /**
158
+ * Project a raw behavior payload into this resource's rows, exactly as a read would.
159
+ *
160
+ * Public because a recompilation has to produce the same rows a read would have produced, and
161
+ * projecting them a second way is how a pushed row and a fetched row come to disagree about the
162
+ * same source.
163
+ */
164
+ projectRowsForResource(resourceType, data) {
165
+ const binding = this.resolveBinding(resourceType);
166
+ if (!binding)
167
+ return undefined;
168
+ return this.projectRows(data, binding, resourceType);
169
+ }
170
+ /** The resource's primary-key field name, for a caller keying rows it did not read. */
171
+ resolveRowIdentityField(resourceType) {
172
+ return this.resolveFieldIdentifier(resourceType);
173
+ }
174
+ /**
175
+ * Whether this resource's rows belong to the APPLICATION rather than to a tenant.
176
+ *
177
+ * Asked by the notifier before it addresses a collection event to the application room. Every
178
+ * introspection resource is APPLICATION-anchored today — all four `isPrimaryScope: true` anchors
179
+ * in the workbench resolve to `CoreResourceType.APPLICATION` — but that set is OPEN, and the day
180
+ * a tenant-scoped one is added, an application-room broadcast would carry one tenant's row ids to
181
+ * every user of the application. Asking the registry keeps the answer with the declaration
182
+ * instead of with a comment that has to stay true.
183
+ */
184
+ isApplicationScoped(resourceType) {
185
+ const configuration = this.resourcesRegistry
186
+ .getResourcesRegistry()
187
+ .resourceConfigurations[resourceType];
188
+ return configuration?.resourcePrimaryScope === ResourcePrimaryScope.APPLICATION;
189
+ }
88
190
  resolveBinding(resourceType) {
89
191
  const configuration = this.resourcesRegistry
90
192
  .getResourcesRegistry()
@@ -207,10 +309,11 @@ let IntrospectionResourceSourceCompanionService = class IntrospectionResourceSou
207
309
  */
208
310
  selectRows(rows, query) {
209
311
  const requestedId = this.extractRequestedId(query.filter, query.resourceType);
210
- if (requestedId === undefined)
211
- return rows;
212
- const fieldIdentifier = this.resolveFieldIdentifier(query.resourceType);
213
- return rows.filter((row) => row[fieldIdentifier] === requestedId);
312
+ if (requestedId !== undefined) {
313
+ const fieldIdentifier = this.resolveFieldIdentifier(query.resourceType);
314
+ return rows.filter((row) => row[fieldIdentifier] === requestedId);
315
+ }
316
+ return applyScalarRowFilters(rows, query.filter, query.resourceType);
214
317
  }
215
318
  /**
216
319
  * The id a READ is asking for, from either shape the repository passes.
@@ -260,7 +363,53 @@ IntrospectionResourceSourceCompanionService = __decorate([
260
363
  __param(0, inject(COMPANION_SERVICE_TYPES.IntrospectionService)),
261
364
  __param(1, inject(COMPANION_SERVICE_TYPES.CompanionContext)),
262
365
  __param(2, inject(SAAS_SERVICE_TYPES.ResourceRegistryService)),
263
- __metadata("design:paramtypes", [Function, Object, Function])
366
+ __param(3, inject(COMPANION_SERVICE_TYPES.CreationPlaneProjectionService)),
367
+ __metadata("design:paramtypes", [Function, Object, Function, CreationPlaneProjectionCompanionService])
264
368
  ], IntrospectionResourceSourceCompanionService);
265
369
  export { IntrospectionResourceSourceCompanionService };
370
+ /**
371
+ * Honor the filters a LIST actually carried — or REFUSE the ones this source cannot apply.
372
+ *
373
+ * Filters reach an introspection LIST only when the operation DECLARES `filterFields` (the
374
+ * controller's `extractCollectionFilters` allow-lists on those keys), so until the first workbench
375
+ * resource declared any, this function's absence was coherent. The moment one is declared, silence
376
+ * stops being an option: a declared filter that is quietly dropped returns the UNFILTERED set
377
+ * wearing a filtered label — the caller's quick-filter tab selects `intent` and the page shows all
378
+ * fifteen rows, with nothing anywhere reporting the lie. That is the `--state ready` defect class,
379
+ * and it is worse than a refusal.
380
+ *
381
+ * What is honored is deliberately NARROW: scalar equality, and an array of scalars as IN — the two
382
+ * shapes an enum quick-filter and a filters panel emit. A shape outside that (a range object, a
383
+ * nested operator) throws naming the field, because "I cannot apply your filter" must never be
384
+ * indistinguishable from "your filter matched everything".
385
+ *
386
+ * `createdAt`/`updatedAt` are allow-listed by the controller UNIVERSALLY, but these derived rows
387
+ * carry no timestamps — the same refusal covers them the day something sends one.
388
+ *
389
+ * A pure exported function rather than a private method, so the refusal and both honored shapes are
390
+ * pinnable without constructing the service's three-injection DI surface.
391
+ */
392
+ export function applyScalarRowFilters(rows, filter, resourceType) {
393
+ if (!filter || typeof filter !== 'object' || Array.isArray(filter))
394
+ return rows;
395
+ const isScalar = (value) => typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean';
396
+ let selected = rows;
397
+ for (const [field, expected] of Object.entries(filter)) {
398
+ if (expected === undefined)
399
+ continue;
400
+ if (isScalar(expected)) {
401
+ selected = selected.filter((row) => row[field] === expected);
402
+ }
403
+ else if (Array.isArray(expected) && expected.every(isScalar)) {
404
+ const admitted = new Set(expected);
405
+ selected = selected.filter((row) => admitted.has(row[field]));
406
+ }
407
+ else {
408
+ throw new Error(`Introspected resource '${resourceType}' received a filter on '${field}' whose shape this source `
409
+ + 'cannot apply (only scalar equality and arrays-of-scalars are supported). Refused rather than ignored: '
410
+ + 'a dropped filter returns the unfiltered set wearing a filtered label.');
411
+ }
412
+ }
413
+ return selected;
414
+ }
266
415
  //# sourceMappingURL=introspection-resource-source.companion.service.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"introspection-resource-source.companion.service.js","sourceRoot":"","sources":["../../../../../../src/core/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mC,8DAA8D;kBAC7G,+CAA+C,CAClD,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAA;AAlPY,2CAA2C;IADvD,UAAU,EAAE;IAGR,WAAA,MAAM,CAAC,uBAAuB,CAAC,oBAAoB,CAAC,CAAA;IAEpD,WAAA,MAAM,CAAC,uBAAuB,CAAC,gBAAgB,CAAC,CAAA;IAEhD,WAAA,MAAM,CAAC,kBAAkB,CAAC,uBAAuB,CAAC,CAAA;;GAN1C,2CAA2C,CAkPvD","sourcesContent":["import { inject, injectable } from 'inversify';\nimport {\n SAAS_SERVICE_TYPES,\n type IntrospectionResourceQuery,\n type IntrospectionResourceRows,\n type IntrospectionResourceSourceBackendPort,\n type ResourcesRegistryBackendService,\n} from '@wildo-ai/saas-backend-lib';\nimport type { IntrospectionResourceBinding } from '@wildo-ai/saas-models';\n\nimport { COMPANION_SERVICE_TYPES } from '../../inject/models/service-types';\nimport type { CompanionContext } from '../../context/companion-context';\nimport type { CompanionIntrospectionService } from '../services/companion-introspection.companion.service';\n\n/**\n * The companion's implementation of the engine's `PersistenceAdapter.INTROSPECTION` port.\n *\n * The engine declares the contract and cannot implement it: deriving a row means running a named\n * introspection behavior, which spawns a subprocess importing the TARGET application's built\n * modules. Only this process knows where that application is and which behaviors exist.\n *\n * ## No mapping table lives here, deliberately\n *\n * Which behavior a resource projects is declared on the RESOURCE\n * (`introspectionBinding`), not in a lookup table keyed by resource type. A table here would be a\n * second enumeration of a population the resource configurations already define, and the two would\n * agree only until one side gained an entry.\n *\n * ## Failures are reported, not flattened\n *\n * `requestInfo` answers a discriminated result; a failed behavior becomes a thrown error carrying\n * the behavior id and the underlying message. The repository above turns that into a refusal rather\n * than an empty row set — \"no rows\" and \"could not look\" are different answers, and the most common\n * cause here is an application whose `dist` has not been built.\n */\n/**\n * Separator joining the identity fields before hashing.\n *\n * Only has to be a character the joined values cannot contain, so the composition is unambiguous:\n * `['a', 'b__c']` and `['a__b', 'c']` must not hash to the same id. Resource types and field\n * identifiers are camelCase and carry no underscores, so a doubled one is safe.\n */\nconst COMPOSED_IDENTITY_SEPARATOR = '__';\n\n/**\n * The charset an INTROSPECTION-backed id must satisfy.\n *\n * The INTERSECTION of the two gates a READ passes through, which are not the same rule:\n * `ResourceIdFormat.INTROSPECTION_SYNTHESIZED` admits `[A-Za-z0-9._~-]`, while\n * `validateParameterFormat` admits only `[a-zA-Z0-9_-]` for a parameter whose field name ends in\n * `id`. A key using `.` or `~` would pass the id validator and be refused as a path parameter — so\n * the narrower rule is the real one, and stating it here keeps the failure at composition time\n * rather than on someone's first READ.\n */\nconst ADDRESSABLE_IDENTITY_PATTERN = /^[a-zA-Z0-9_-]+$/;\n\n/** The framework's own path-parameter length limit. */\nconst MAXIMUM_ADDRESSABLE_IDENTITY_LENGTH = 255;\n\n\n@injectable()\nexport class IntrospectionResourceSourceCompanionService implements IntrospectionResourceSourceBackendPort {\n constructor(\n @inject(COMPANION_SERVICE_TYPES.IntrospectionService)\n private readonly introspectionService: CompanionIntrospectionService,\n @inject(COMPANION_SERVICE_TYPES.CompanionContext)\n private readonly companionContext: CompanionContext,\n @inject(SAAS_SERVICE_TYPES.ResourceRegistryService)\n private readonly resourcesRegistry: ResourcesRegistryBackendService,\n ) {}\n\n public supports(resourceType: string): boolean {\n return this.resolveBinding(resourceType) !== undefined;\n }\n\n public async deriveRows(query: IntrospectionResourceQuery): Promise<IntrospectionResourceRows> {\n const binding = this.resolveBinding(query.resourceType);\n if (!binding) {\n throw new Error(\n `Resource '${query.resourceType}' is INTROSPECTION-backed but declares no 'introspectionBinding'. `\n + 'The binding names the companion behavior whose output becomes its rows.',\n );\n }\n\n const serviceKey = this.resolveServiceKey();\n const result = await this.introspectionService.requestInfo({\n serviceKey,\n behavior: binding.behavior as never,\n });\n\n if (!result.success) {\n const message = 'error' in result ? result.error.message : 'unknown error';\n throw new Error(\n `Introspection behavior '${binding.behavior}' failed for resource '${query.resourceType}': ${message}`,\n );\n }\n\n const rows = this.projectRows(result.data, binding, query.resourceType);\n return { rows: this.selectRows(rows, query) };\n }\n\n private resolveBinding(resourceType: string): IntrospectionResourceBinding | undefined {\n const configuration = this.resourcesRegistry\n .getResourcesRegistry()\n .resourceConfigurations[resourceType as never] as { introspectionBinding?: IntrospectionResourceBinding } | undefined;\n return configuration?.introspectionBinding;\n }\n\n /**\n * The resource's OWN primary-key field name, which composed identity is written to.\n *\n * Read from the registry rather than taken from the binding: the field identifier is already\n * declared once on the resource configuration, and a second copy on the binding could disagree\n * with the schema the response DTO validates against.\n */\n private resolveFieldIdentifier(resourceType: string): string {\n const configuration = this.resourcesRegistry\n .getResourcesRegistry()\n .resourceConfigurations[resourceType as never] as { resourceFieldIdentifier?: string } | undefined;\n const fieldIdentifier = configuration?.resourceFieldIdentifier;\n if (!fieldIdentifier) {\n throw new Error(\n `Resource '${resourceType}' declares identityFields but the registry reports no `\n + 'resourceFieldIdentifier to write the composed key to.',\n );\n }\n return fieldIdentifier;\n }\n\n /**\n * Which service the behavior is run against.\n *\n * One target for now — the application this companion serves. A behavior declares its own\n * `supportedServiceKinds`, and routing a resource at a specific service is a later refinement\n * that belongs on the binding rather than here.\n */\n private resolveServiceKey(): string {\n const [firstServiceKey] = Object.keys(this.companionContext.servicesByKey);\n if (!firstServiceKey) {\n throw new Error('No service is registered with this companion, so no introspection behavior can be run.');\n }\n return firstServiceKey;\n }\n\n /**\n * Pull the row collection out of the behavior's own result shape.\n *\n * Behaviors answer what is natural to them (`{ frontendChartRegistrationRefs: [...] }`), and the\n * binding says where to look. Teaching 23 working behaviors to answer a uniform envelope to suit\n * a consumer that arrived later would be the wrong direction.\n *\n * A path that resolves to a non-array is an authoring error and says so, rather than yielding one\n * row shaped like an object or an empty list that reads as \"nothing there\".\n */\n private projectRows(data: unknown, binding: IntrospectionResourceBinding, resourceType: string): readonly Record<string, unknown>[] {\n const resolved = binding.rowsPath\n ? binding.rowsPath.split('.').reduce<unknown>((value, key) => (value as Record<string, unknown>)?.[key], data)\n : data;\n\n if (!Array.isArray(resolved)) {\n throw new Error(\n `Introspection behavior '${binding.behavior}' did not yield an array at `\n + `${binding.rowsPath ? `'${binding.rowsPath}'` : 'its result root'}; got ${typeof resolved}. `\n + \"Set 'rowsPath' on the resource's introspectionBinding to the property holding the rows.\",\n );\n }\n const rows = resolved as readonly Record<string, unknown>[];\n return binding.identityFields ? this.stampComposedIdentity(rows, binding, resourceType) : rows;\n }\n\n /**\n * Give each row the primary key its behavior does not carry, composed from the binding's declared\n * `identityFields`.\n *\n * ## Why this refuses instead of de-duplicating\n *\n * Two rows composing the same key is an authoring error — the declared fields are not jointly\n * unique for this behavior — and every quiet response to it is worse than a refusal. Dropping the\n * second row loses data silently; keeping both makes READ return an arbitrary one; appending an\n * index makes the key unstable across derivations, so a link to a row would resolve to a different\n * row after an unrelated edit. Refusing names the resource, the key and the fields, and is fixed\n * by declaring a field that discriminates.\n *\n * The check runs on EVERY derivation rather than once, because these rows are derived from the\n * application's live source: a pair that is unique today stops being unique the moment an author\n * adds a second edge between the same two resources, and that is exactly when someone needs to be\n * told.\n */\n private stampComposedIdentity(\n rows: readonly Record<string, unknown>[],\n binding: IntrospectionResourceBinding,\n resourceType: string,\n ): readonly Record<string, unknown>[] {\n const identityFields = binding.identityFields ?? [];\n const fieldIdentifier = this.resolveFieldIdentifier(resourceType);\n const seen = new Map<string, number>();\n\n return rows.map((row, index) => {\n const parts = identityFields.map((field) => {\n const value = row[field];\n if (value === undefined || value === null) {\n throw new Error(\n `Introspection behavior '${binding.behavior}' produced a row missing identity field '${field}' `\n + `(row ${index}). Every field named in the binding's identityFields must be present on every row.`,\n );\n }\n return String(value);\n });\n const composed = parts.join(COMPOSED_IDENTITY_SEPARATOR);\n this.assertAddressable(composed, binding, identityFields, index);\n\n const firstIndex = seen.get(composed);\n if (firstIndex !== undefined) {\n throw new Error(\n `Introspection behavior '${binding.behavior}' produced two rows (${firstIndex} and ${index}) with the same `\n + `composed identity '${composed}' from identityFields [${identityFields.join(', ')}]. `\n + 'Those fields are not jointly unique for this behavior, so one row would be unreachable by READ. '\n + 'Add a field that discriminates them to the binding\\'s identityFields.',\n );\n }\n seen.set(composed, index);\n\n return { ...row, [fieldIdentifier]: composed };\n });\n }\n\n /**\n * Apply the READ/LIST filter to the derived rows.\n *\n * ## Why this exists, stated plainly\n *\n * The repository's `read()` derives rows and returns `rows[0]`. Without this, a READ for ANY id\n * returned the FIRST row — a resource that answered every request with the same record. It was\n * invisible while only LIST was exercised, and it is what actually blocked READ; the id-format\n * refusal in front of it merely hid it.\n *\n * Filtering here rather than in the repository is deliberate: the repository is engine code with\n * no idea which field carries a given resource's identity, while the source resolved that field\n * to stamp it. An introspection behavior computes its whole answer in one subprocess run, so\n * there is nothing cheaper to push down — filtering after derivation costs one pass over an\n * already-materialized array.\n */\n private selectRows(\n rows: readonly Record<string, unknown>[],\n query: IntrospectionResourceQuery,\n ): readonly Record<string, unknown>[] {\n const requestedId = this.extractRequestedId(query.filter, query.resourceType);\n if (requestedId === undefined) return rows;\n\n const fieldIdentifier = this.resolveFieldIdentifier(query.resourceType);\n return rows.filter((row) => row[fieldIdentifier] === requestedId);\n }\n\n /**\n * The id a READ is asking for, from either shape the repository passes.\n *\n * `read(executionContext, id_or_filter)` genuinely carries both: a bare string for an addressed\n * read, or an object keyed by the resource's identity field. Anything else — a rich query filter —\n * returns `undefined` and the whole set is served, which is the honest answer for a LIST.\n */\n private extractRequestedId(filter: unknown, resourceType: string): string | undefined {\n if (typeof filter === 'string') return filter;\n if (filter && typeof filter === 'object') {\n const candidate = (filter as Record<string, unknown>)[this.resolveFieldIdentifier(resourceType)];\n if (typeof candidate === 'string') return candidate;\n }\n return undefined;\n }\n\n /**\n * Refuse a composed key the framework cannot carry in a URL.\n *\n * A key violating {@link ADDRESSABLE_IDENTITY_PATTERN} LISTS perfectly and is refused on every\n * READ — the same shows-but-cannot-be-reached failure the duplicate check exists to prevent,\n * arriving by a different route. Measured: `'::'` as a separator produced exactly that, a 200 list\n * of 16 rows and `api_call_initiator_parameter_unsupported` on each one.\n *\n * Checked per row rather than trusted, because the offending character usually comes from the\n * DATA — a resource type or field name in the observed application — not from the separator an\n * author chose, so it can appear long after the binding was written.\n */\n private assertAddressable(\n composed: string,\n binding: IntrospectionResourceBinding,\n identityFields: readonly string[],\n index: number,\n ): void {\n if (!ADDRESSABLE_IDENTITY_PATTERN.test(composed)) {\n throw new Error(\n `Introspection behavior '${binding.behavior}' composed the identity '${composed}' (row ${index}) from `\n + `identityFields [${identityFields.join(', ')}], which cannot be used as a URL path parameter: the `\n + `framework requires ${ADDRESSABLE_IDENTITY_PATTERN.source}. The row would be listable and unreadable. `\n + 'Choose identity fields whose values are alphanumeric.',\n );\n }\n if (composed.length > MAXIMUM_ADDRESSABLE_IDENTITY_LENGTH) {\n throw new Error(\n `Introspection behavior '${binding.behavior}' composed a ${composed.length}-character identity (row ${index}), `\n + `over the ${MAXIMUM_ADDRESSABLE_IDENTITY_LENGTH}-character limit the framework enforces on path parameters. `\n + 'Compose the key from fewer or shorter fields.',\n );\n }\n }\n}\n"]}
1
+ {"version":3,"file":"introspection-resource-source.companion.service.js","sourceRoot":"","sources":["../../../../../../src/core/introspection/resources/introspection-resource-source.companion.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EACL,kBAAkB,GAKnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,oBAAoB,EAAqC,MAAM,uBAAuB,CAAC;AAEhG,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAG5E,OAAO,EAAE,uCAAuC,EAAE,MAAM,+CAA+C,CAAC;AAExG;;;;;;;;;;;;;;;;;;;;GAoBG;AACH;;;;;;GAMG;AACH,MAAM,2BAA2B,GAAG,IAAI,CAAC;AAEzC;;;;;;;;;GASG;AACH,MAAM,4BAA4B,GAAG,kBAAkB,CAAC;AAExD,uDAAuD;AACvD,MAAM,mCAAmC,G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,CAAC;YACN,MAAM,IAAI,KAAK,CACb,0BAA0B,YAAY,2BAA2B,KAAK,4BAA4B;kBAChG,wGAAwG;kBACxG,uEAAuE,CAC1E,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import { inject, injectable } from 'inversify';\nimport {\n SAAS_SERVICE_TYPES,\n type IntrospectionResourceQuery,\n type IntrospectionResourceRows,\n type IntrospectionResourceSourceBackendPort,\n type ResourcesRegistryBackendService,\n} from '@wildo-ai/saas-backend-lib';\nimport { ResourcePrimaryScope, type IntrospectionResourceBinding } from '@wildo-ai/saas-models';\n\nimport { COMPANION_SERVICE_TYPES } from '../../inject/models/service-types';\nimport type { CompanionContext } from '../../context/companion-context';\nimport type { CompanionIntrospectionService } from '../services/companion-introspection.companion.service';\nimport { CreationPlaneProjectionCompanionService } from './creation-plane-projection.companion.service';\n\n/**\n * The companion's implementation of the engine's `PersistenceAdapter.INTROSPECTION` port.\n *\n * The engine declares the contract and cannot implement it: deriving a row means running a named\n * introspection behavior, which spawns a subprocess importing the TARGET application's built\n * modules. Only this process knows where that application is and which behaviors exist.\n *\n * ## No mapping table lives here, deliberately\n *\n * Which behavior a resource projects is declared on the RESOURCE\n * (`introspectionBinding`), not in a lookup table keyed by resource type. A table here would be a\n * second enumeration of a population the resource configurations already define, and the two would\n * agree only until one side gained an entry.\n *\n * ## Failures are reported, not flattened\n *\n * `requestInfo` answers a discriminated result; a failed behavior becomes a thrown error carrying\n * the behavior id and the underlying message. The repository above turns that into a refusal rather\n * than an empty row set — \"no rows\" and \"could not look\" are different answers, and the most common\n * cause here is an application whose `dist` has not been built.\n */\n/**\n * Separator joining the identity fields before hashing.\n *\n * Only has to be a character the joined values cannot contain, so the composition is unambiguous:\n * `['a', 'b__c']` and `['a__b', 'c']` must not hash to the same id. Resource types and field\n * identifiers are camelCase and carry no underscores, so a doubled one is safe.\n */\nconst COMPOSED_IDENTITY_SEPARATOR = '__';\n\n/**\n * The charset an INTROSPECTION-backed id must satisfy.\n *\n * The INTERSECTION of the two gates a READ passes through, which are not the same rule:\n * `ResourceIdFormat.INTROSPECTION_SYNTHESIZED` admits `[A-Za-z0-9._~-]`, while\n * `validateParameterFormat` admits only `[a-zA-Z0-9_-]` for a parameter whose field name ends in\n * `id`. A key using `.` or `~` would pass the id validator and be refused as a path parameter — so\n * the narrower rule is the real one, and stating it here keeps the failure at composition time\n * rather than on someone's first READ.\n */\nconst ADDRESSABLE_IDENTITY_PATTERN = /^[a-zA-Z0-9_-]+$/;\n\n/** The framework's own path-parameter length limit. */\nconst MAXIMUM_ADDRESSABLE_IDENTITY_LENGTH = 255;\n\n\n@injectable()\nexport class IntrospectionResourceSourceCompanionService implements IntrospectionResourceSourceBackendPort {\n constructor(\n @inject(COMPANION_SERVICE_TYPES.IntrospectionService)\n private readonly introspectionService: CompanionIntrospectionService,\n @inject(COMPANION_SERVICE_TYPES.CompanionContext)\n private readonly companionContext: CompanionContext,\n @inject(SAAS_SERVICE_TYPES.ResourceRegistryService)\n private readonly resourcesRegistry: ResourcesRegistryBackendService,\n @inject(COMPANION_SERVICE_TYPES.CreationPlaneProjectionService)\n private readonly creationPlane: CreationPlaneProjectionCompanionService,\n ) {}\n\n public supports(resourceType: string): boolean {\n return this.resolveBinding(resourceType) !== undefined;\n }\n\n public async deriveRows(query: IntrospectionResourceQuery): Promise<IntrospectionResourceRows> {\n const binding = this.resolveBinding(query.resourceType);\n if (!binding) {\n throw new Error(\n `Resource '${query.resourceType}' is INTROSPECTION-backed but declares no 'introspectionBinding'. `\n + 'The binding names the companion behavior whose output becomes its rows.',\n );\n }\n\n /*\n * TWO materialization lanes behind one binding vocabulary (Phase 2 of\n * `workbench-creation-board-resources.md`): a creation-plane behavior id is served IN-PROCESS\n * from the companion's own runtime services — no subprocess, no app-dist import, and the rows\n * arrive with their identity fields already emitted (their business keys carry characters the\n * composed-identity charset refuses). Everything else flows to the subprocess lane below,\n * untouched. The membership test is owned by the same package that writes the ids into the\n * bindings, so the two ends cannot drift.\n */\n if (this.creationPlane.supports(binding.behavior)) {\n const rows = await this.creationPlane.deriveRows(binding.behavior);\n return { rows: this.selectRows(rows, query) };\n }\n\n const serviceKey = this.resolveServiceKey();\n const result = await this.introspectionService.requestInfo({\n serviceKey,\n behavior: binding.behavior as never,\n });\n\n if (!result.success) {\n const message = 'error' in result ? result.error.message : 'unknown error';\n throw new Error(\n `Introspection behavior '${binding.behavior}' failed for resource '${query.resourceType}': ${message}`,\n );\n }\n\n const rows = this.projectRows(result.data, binding, query.resourceType);\n return { rows: this.selectRows(rows, query) };\n }\n\n /**\n * Compile every introspection behavior the registry declares, before anyone reads one.\n *\n * A supervised restart empties the compiled state, and restarts are frequent — 26 self-sent\n * SIGTERMs were logged in one wonder-crm session on 2026-09-02. Without this, the first operator\n * to open the workbench after any restart pays a full cold derivation, measured at 8.8 s.\n *\n * One request per BEHAVIOR rather than per resource: two resources projecting one behavior are one\n * derivation, so asking once keeps the count honest about how much work was actually done.\n * Creation-plane behaviors are skipped — they are served in-process from the companion's own\n * runtime state, carry their own cache, and have no subprocess to warm.\n *\n * Never throws. Warming is a latency improvement over a path that already works, and the caller\n * treats a failure as a warning: a companion that refused to finish booting because an\n * application's `dist` was mid-build would need the companion this failure just prevented from\n * starting in order to be repaired.\n */\n public async warmDeclaredDerivations(): Promise<{\n readonly attempted: number;\n readonly failed: number;\n }> {\n const behaviors = [...this.resolveResourceTypesByBehavior().keys()]\n .filter((behavior) => !this.creationPlane.supports(behavior));\n if (behaviors.length === 0) return { attempted: 0, failed: 0 };\n\n const serviceKey = this.resolveServiceKey();\n const outcomes = await Promise.allSettled(behaviors.map(\n (behavior) => this.introspectionService.requestInfo({ serviceKey, behavior: behavior as never }),\n ));\n\n const failed = outcomes.filter(\n (outcome) => outcome.status === 'rejected'\n || (outcome.status === 'fulfilled' && !outcome.value.success),\n ).length;\n return { attempted: behaviors.length, failed };\n }\n\n /**\n * Every INTROSPECTION-backed resource in the registry, grouped by the behavior it projects.\n *\n * The notifier needs the reverse of what a read needs: a read has a resource and wants its\n * behavior, while a recompilation has a behavior and wants every resource whose rows just moved.\n * Derived from the SAME registry declarations rather than from a table, for the reason the class\n * docstring already gives — a second enumeration of a population the resource configurations\n * define would agree only until one side gained an entry.\n */\n public resolveResourceTypesByBehavior(): ReadonlyMap<string, readonly string[]> {\n const configurations = this.resourcesRegistry.getResourcesRegistry().resourceConfigurations as Record<\n string,\n { introspectionBinding?: IntrospectionResourceBinding } | undefined\n >;\n const byBehavior = new Map<string, string[]>();\n for (const [resourceType, configuration] of Object.entries(configurations)) {\n const behavior = configuration?.introspectionBinding?.behavior;\n if (!behavior) continue;\n const existing = byBehavior.get(behavior);\n if (existing) existing.push(resourceType);\n else byBehavior.set(behavior, [resourceType]);\n }\n return byBehavior;\n }\n\n /**\n * Project a raw behavior payload into this resource's rows, exactly as a read would.\n *\n * Public because a recompilation has to produce the same rows a read would have produced, and\n * projecting them a second way is how a pushed row and a fetched row come to disagree about the\n * same source.\n */\n public projectRowsForResource(\n resourceType: string,\n data: unknown,\n ): readonly Record<string, unknown>[] | undefined {\n const binding = this.resolveBinding(resourceType);\n if (!binding) return undefined;\n return this.projectRows(data, binding, resourceType);\n }\n\n /** The resource's primary-key field name, for a caller keying rows it did not read. */\n public resolveRowIdentityField(resourceType: string): string {\n return this.resolveFieldIdentifier(resourceType);\n }\n\n /**\n * Whether this resource's rows belong to the APPLICATION rather than to a tenant.\n *\n * Asked by the notifier before it addresses a collection event to the application room. Every\n * introspection resource is APPLICATION-anchored today — all four `isPrimaryScope: true` anchors\n * in the workbench resolve to `CoreResourceType.APPLICATION` — but that set is OPEN, and the day\n * a tenant-scoped one is added, an application-room broadcast would carry one tenant's row ids to\n * every user of the application. Asking the registry keeps the answer with the declaration\n * instead of with a comment that has to stay true.\n */\n public isApplicationScoped(resourceType: string): boolean {\n const configuration = this.resourcesRegistry\n .getResourcesRegistry()\n .resourceConfigurations[resourceType as never] as { resourcePrimaryScope?: string } | undefined;\n return configuration?.resourcePrimaryScope === ResourcePrimaryScope.APPLICATION;\n }\n\n private resolveBinding(resourceType: string): IntrospectionResourceBinding | undefined {\n const configuration = this.resourcesRegistry\n .getResourcesRegistry()\n .resourceConfigurations[resourceType as never] as { introspectionBinding?: IntrospectionResourceBinding } | undefined;\n return configuration?.introspectionBinding;\n }\n\n /**\n * The resource's OWN primary-key field name, which composed identity is written to.\n *\n * Read from the registry rather than taken from the binding: the field identifier is already\n * declared once on the resource configuration, and a second copy on the binding could disagree\n * with the schema the response DTO validates against.\n */\n private resolveFieldIdentifier(resourceType: string): string {\n const configuration = this.resourcesRegistry\n .getResourcesRegistry()\n .resourceConfigurations[resourceType as never] as { resourceFieldIdentifier?: string } | undefined;\n const fieldIdentifier = configuration?.resourceFieldIdentifier;\n if (!fieldIdentifier) {\n throw new Error(\n `Resource '${resourceType}' declares identityFields but the registry reports no `\n + 'resourceFieldIdentifier to write the composed key to.',\n );\n }\n return fieldIdentifier;\n }\n\n /**\n * Which service the behavior is run against.\n *\n * One target for now — the application this companion serves. A behavior declares its own\n * `supportedServiceKinds`, and routing a resource at a specific service is a later refinement\n * that belongs on the binding rather than here.\n */\n private resolveServiceKey(): string {\n const [firstServiceKey] = Object.keys(this.companionContext.servicesByKey);\n if (!firstServiceKey) {\n throw new Error('No service is registered with this companion, so no introspection behavior can be run.');\n }\n return firstServiceKey;\n }\n\n /**\n * Pull the row collection out of the behavior's own result shape.\n *\n * Behaviors answer what is natural to them (`{ frontendChartRegistrationRefs: [...] }`), and the\n * binding says where to look. Teaching 23 working behaviors to answer a uniform envelope to suit\n * a consumer that arrived later would be the wrong direction.\n *\n * A path that resolves to a non-array is an authoring error and says so, rather than yielding one\n * row shaped like an object or an empty list that reads as \"nothing there\".\n */\n private projectRows(data: unknown, binding: IntrospectionResourceBinding, resourceType: string): readonly Record<string, unknown>[] {\n const resolved = binding.rowsPath\n ? binding.rowsPath.split('.').reduce<unknown>((value, key) => (value as Record<string, unknown>)?.[key], data)\n : data;\n\n if (!Array.isArray(resolved)) {\n throw new Error(\n `Introspection behavior '${binding.behavior}' did not yield an array at `\n + `${binding.rowsPath ? `'${binding.rowsPath}'` : 'its result root'}; got ${typeof resolved}. `\n + \"Set 'rowsPath' on the resource's introspectionBinding to the property holding the rows.\",\n );\n }\n const rows = resolved as readonly Record<string, unknown>[];\n return binding.identityFields ? this.stampComposedIdentity(rows, binding, resourceType) : rows;\n }\n\n /**\n * Give each row the primary key its behavior does not carry, composed from the binding's declared\n * `identityFields`.\n *\n * ## Why this refuses instead of de-duplicating\n *\n * Two rows composing the same key is an authoring error — the declared fields are not jointly\n * unique for this behavior — and every quiet response to it is worse than a refusal. Dropping the\n * second row loses data silently; keeping both makes READ return an arbitrary one; appending an\n * index makes the key unstable across derivations, so a link to a row would resolve to a different\n * row after an unrelated edit. Refusing names the resource, the key and the fields, and is fixed\n * by declaring a field that discriminates.\n *\n * The check runs on EVERY derivation rather than once, because these rows are derived from the\n * application's live source: a pair that is unique today stops being unique the moment an author\n * adds a second edge between the same two resources, and that is exactly when someone needs to be\n * told.\n */\n private stampComposedIdentity(\n rows: readonly Record<string, unknown>[],\n binding: IntrospectionResourceBinding,\n resourceType: string,\n ): readonly Record<string, unknown>[] {\n const identityFields = binding.identityFields ?? [];\n const fieldIdentifier = this.resolveFieldIdentifier(resourceType);\n const seen = new Map<string, number>();\n\n return rows.map((row, index) => {\n const parts = identityFields.map((field) => {\n const value = row[field];\n if (value === undefined || value === null) {\n throw new Error(\n `Introspection behavior '${binding.behavior}' produced a row missing identity field '${field}' `\n + `(row ${index}). Every field named in the binding's identityFields must be present on every row.`,\n );\n }\n return String(value);\n });\n const composed = parts.join(COMPOSED_IDENTITY_SEPARATOR);\n this.assertAddressable(composed, binding, identityFields, index);\n\n const firstIndex = seen.get(composed);\n if (firstIndex !== undefined) {\n throw new Error(\n `Introspection behavior '${binding.behavior}' produced two rows (${firstIndex} and ${index}) with the same `\n + `composed identity '${composed}' from identityFields [${identityFields.join(', ')}]. `\n + 'Those fields are not jointly unique for this behavior, so one row would be unreachable by READ. '\n + 'Add a field that discriminates them to the binding\\'s identityFields.',\n );\n }\n seen.set(composed, index);\n\n return { ...row, [fieldIdentifier]: composed };\n });\n }\n\n /**\n * Apply the READ/LIST filter to the derived rows.\n *\n * ## Why this exists, stated plainly\n *\n * The repository's `read()` derives rows and returns `rows[0]`. Without this, a READ for ANY id\n * returned the FIRST row — a resource that answered every request with the same record. It was\n * invisible while only LIST was exercised, and it is what actually blocked READ; the id-format\n * refusal in front of it merely hid it.\n *\n * Filtering here rather than in the repository is deliberate: the repository is engine code with\n * no idea which field carries a given resource's identity, while the source resolved that field\n * to stamp it. An introspection behavior computes its whole answer in one subprocess run, so\n * there is nothing cheaper to push down — filtering after derivation costs one pass over an\n * already-materialized array.\n */\n private selectRows(\n rows: readonly Record<string, unknown>[],\n query: IntrospectionResourceQuery,\n ): readonly Record<string, unknown>[] {\n const requestedId = this.extractRequestedId(query.filter, query.resourceType);\n if (requestedId !== undefined) {\n const fieldIdentifier = this.resolveFieldIdentifier(query.resourceType);\n return rows.filter((row) => row[fieldIdentifier] === requestedId);\n }\n return applyScalarRowFilters(rows, query.filter, query.resourceType);\n }\n\n /**\n * The id a READ is asking for, from either shape the repository passes.\n *\n * `read(executionContext, id_or_filter)` genuinely carries both: a bare string for an addressed\n * read, or an object keyed by the resource's identity field. Anything else — a rich query filter —\n * returns `undefined` and the whole set is served, which is the honest answer for a LIST.\n */\n private extractRequestedId(filter: unknown, resourceType: string): string | undefined {\n if (typeof filter === 'string') return filter;\n if (filter && typeof filter === 'object') {\n const candidate = (filter as Record<string, unknown>)[this.resolveFieldIdentifier(resourceType)];\n if (typeof candidate === 'string') return candidate;\n }\n return undefined;\n }\n\n /**\n * Refuse a composed key the framework cannot carry in a URL.\n *\n * A key violating {@link ADDRESSABLE_IDENTITY_PATTERN} LISTS perfectly and is refused on every\n * READ — the same shows-but-cannot-be-reached failure the duplicate check exists to prevent,\n * arriving by a different route. Measured: `'::'` as a separator produced exactly that, a 200 list\n * of 16 rows and `api_call_initiator_parameter_unsupported` on each one.\n *\n * Checked per row rather than trusted, because the offending character usually comes from the\n * DATA — a resource type or field name in the observed application — not from the separator an\n * author chose, so it can appear long after the binding was written.\n */\n private assertAddressable(\n composed: string,\n binding: IntrospectionResourceBinding,\n identityFields: readonly string[],\n index: number,\n ): void {\n if (!ADDRESSABLE_IDENTITY_PATTERN.test(composed)) {\n throw new Error(\n `Introspection behavior '${binding.behavior}' composed the identity '${composed}' (row ${index}) from `\n + `identityFields [${identityFields.join(', ')}], which cannot be used as a URL path parameter: the `\n + `framework requires ${ADDRESSABLE_IDENTITY_PATTERN.source}. The row would be listable and unreadable. `\n + 'Choose identity fields whose values are alphanumeric.',\n );\n }\n if (composed.length > MAXIMUM_ADDRESSABLE_IDENTITY_LENGTH) {\n throw new Error(\n `Introspection behavior '${binding.behavior}' composed a ${composed.length}-character identity (row ${index}), `\n + `over the ${MAXIMUM_ADDRESSABLE_IDENTITY_LENGTH}-character limit the framework enforces on path parameters. `\n + 'Compose the key from fewer or shorter fields.',\n );\n }\n }\n}\n\n/**\n * Honor the filters a LIST actually carried — or REFUSE the ones this source cannot apply.\n *\n * Filters reach an introspection LIST only when the operation DECLARES `filterFields` (the\n * controller's `extractCollectionFilters` allow-lists on those keys), so until the first workbench\n * resource declared any, this function's absence was coherent. The moment one is declared, silence\n * stops being an option: a declared filter that is quietly dropped returns the UNFILTERED set\n * wearing a filtered label — the caller's quick-filter tab selects `intent` and the page shows all\n * fifteen rows, with nothing anywhere reporting the lie. That is the `--state ready` defect class,\n * and it is worse than a refusal.\n *\n * What is honored is deliberately NARROW: scalar equality, and an array of scalars as IN — the two\n * shapes an enum quick-filter and a filters panel emit. A shape outside that (a range object, a\n * nested operator) throws naming the field, because \"I cannot apply your filter\" must never be\n * indistinguishable from \"your filter matched everything\".\n *\n * `createdAt`/`updatedAt` are allow-listed by the controller UNIVERSALLY, but these derived rows\n * carry no timestamps — the same refusal covers them the day something sends one.\n *\n * A pure exported function rather than a private method, so the refusal and both honored shapes are\n * pinnable without constructing the service's three-injection DI surface.\n */\nexport function applyScalarRowFilters(\n rows: readonly Record<string, unknown>[],\n filter: unknown,\n resourceType: string,\n): readonly Record<string, unknown>[] {\n if (!filter || typeof filter !== 'object' || Array.isArray(filter)) return rows;\n\n const isScalar = (value: unknown): value is string | number | boolean =>\n typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean';\n\n let selected = rows;\n for (const [field, expected] of Object.entries(filter as Record<string, unknown>)) {\n if (expected === undefined) continue;\n if (isScalar(expected)) {\n selected = selected.filter((row) => row[field] === expected);\n } else if (Array.isArray(expected) && expected.every(isScalar)) {\n const admitted = new Set<unknown>(expected);\n selected = selected.filter((row) => admitted.has(row[field]));\n } else {\n throw new Error(\n `Introspected resource '${resourceType}' received a filter on '${field}' whose shape this source `\n + 'cannot apply (only scalar equality and arrays-of-scalars are supported). Refused rather than ignored: '\n + 'a dropped filter returns the unfiltered set wearing a filtered label.',\n );\n }\n }\n return selected;\n}\n"]}
@@ -1,7 +1,28 @@
1
1
  import type { LoggerService } from '@wildo-ai/saas-backend-lib';
2
2
  import type { CompanionContext } from '../../context/companion-context';
3
3
  import { CompanionIntrospectionBehaviorRegistryService } from './companion-introspection-behavior-registry.companion.service';
4
- import type { CompanionIntrospectionRequest, CompanionIntrospectionResult } from '../models/companion-introspection.models';
4
+ import { IntrospectionDerivationStateCompanionService } from './introspection-derivation-state.companion.service';
5
+ import type { CompanionIntrospectionRequest, CompanionIntrospectionResult, CompanionIntrospectionServiceKind } from '../models/companion-introspection.models';
6
+ /**
7
+ * Whether a dead introspection child was killed by SOMEONE OTHER than this service.
8
+ *
9
+ * Exported because it is the whole decision — the call site is one branch — and because it is the
10
+ * part worth pinning: the plumbing around it needs a real subprocess and a real signal, while the
11
+ * reasoning is three booleans.
12
+ *
13
+ * The inference rests on an invariant of this file: every termination this service performs goes
14
+ * through `requestTermination`, which sets a pending failure BEFORE killing, and the exit handler
15
+ * returns that failure without consulting this. So a termination signal arriving with no pending
16
+ * failure and no parsed result means nobody here asked — the child died because its PARENT did,
17
+ * taking the process group with it. If a future kill path forgets to set the pending failure first,
18
+ * this starts misreporting a local kill as an external one, which is why the invariant is stated
19
+ * here rather than left implicit at the call site.
20
+ */
21
+ export declare function wasTerminatedFromOutside(input: {
22
+ readonly signal: string | null;
23
+ readonly hasPendingFailure: boolean;
24
+ readonly hasParsedResult: boolean;
25
+ }): boolean;
5
26
  /**
6
27
  * Env-var namespaces stripped from the spawned introspection child's
7
28
  * environment so pre-bootstrap reads surface `undefined` instead of inheriting
@@ -20,6 +41,19 @@ import type { CompanionIntrospectionRequest, CompanionIntrospectionResult } from
20
41
  * and is re-injected fresh for every spawn.
21
42
  */
22
43
  export declare const SCRUBBED_CHILD_ENV_NAMES: readonly ["COMPANION_WORKSPACE_ROOT", "COMPANION_RUNTIME_HOME", "COMPANION_PACKAGE_ROOT", "COMPANION_FRAMEWORK_ROOT", "WILDO_COMPANION_INTROSPECTION_CHILD"];
44
+ /**
45
+ * Render an arbitrary behavior `input` so that two structurally equal inputs produce one key.
46
+ *
47
+ * `JSON.stringify` alone would not: `{a:1,b:2}` and `{b:2,a:1}` are the same question and would
48
+ * occupy two cache entries, so the second phrasing of a question would always miss. Object keys are
49
+ * therefore sorted at every depth. Arrays keep their order, because in an input an array's order is
50
+ * part of the question.
51
+ *
52
+ * A value that cannot be rendered — a cycle, a `BigInt` — yields `null`, which the caller reads as
53
+ * "this question is not cacheable" rather than as an error. Nothing in the current behavior surface
54
+ * sends such an input; treating it as uncacheable rather than throwing keeps a future one working.
55
+ */
56
+ export declare function renderStableCacheableInput(input: unknown): string | null;
23
57
  /**
24
58
  * Build the `env` object handed to the spawned introspection child process.
25
59
  *
@@ -48,6 +82,7 @@ export declare class CompanionIntrospectionService {
48
82
  private readonly logger;
49
83
  private readonly companionContext;
50
84
  private readonly behaviorRegistryService;
85
+ private readonly derivationState;
51
86
  private readonly logDebug;
52
87
  private readonly maxConcurrency;
53
88
  private readonly timeoutMs;
@@ -55,8 +90,102 @@ export declare class CompanionIntrospectionService {
55
90
  private readonly queue;
56
91
  /** Test seam only; production always retains Node's real child-process spawn. */
57
92
  private spawnSubprocess;
58
- constructor(logger: LoggerService, companionContext: CompanionContext, behaviorRegistryService: CompanionIntrospectionBehaviorRegistryService);
93
+ /**
94
+ * Whether compiled state may be retained at all.
95
+ *
96
+ * `COMPANION_INTROSPECTION_CACHE=off` still means what it always meant — every read compiles, and
97
+ * no state is consulted or written. The flag is read here rather than inside the state service
98
+ * because this is the door every consumer already comes through, so switching it off cannot be
99
+ * bypassed by a caller that reaches the state service directly.
100
+ */
101
+ private readonly derivationCacheEnabled;
102
+ constructor(logger: LoggerService, companionContext: CompanionContext, behaviorRegistryService: CompanionIntrospectionBehaviorRegistryService, derivationState: IntrospectionDerivationStateCompanionService);
103
+ /**
104
+ * Answer an introspection request, re-deriving only when the application's source has moved.
105
+ *
106
+ * ## The three tiers, in order
107
+ *
108
+ * 1. **Cache hit** — a previous derivation of this exact question, taken against a source tree
109
+ * whose observation token still matches. No subprocess, no import, no registry materialization.
110
+ * 2. **In-flight join** — the identical question is already being derived against the identical
111
+ * token. The caller waits on that one rather than spawning a second child.
112
+ * 3. **Derive** — spawn, under the existing concurrency queue.
113
+ *
114
+ * ## What is cached, and what deliberately is not
115
+ *
116
+ * Only SUCCESS. A failure is not memoized, for two separate reasons and either is sufficient: the
117
+ * common failure here is an application whose `dist` is not built, whose remedy moves the source
118
+ * and would invalidate anyway; and a transient failure — a timeout on a loaded machine — would
119
+ * otherwise stick to an unchanged tree and be served as the answer forever. In-flight JOINING
120
+ * still covers failures, because two concurrent identical questions should cost one subprocess
121
+ * whatever the outcome.
122
+ *
123
+ * ## Where the source reading happens
124
+ *
125
+ * Outside the concurrency queue. The observation is ~125 ms of filesystem work with no subprocess
126
+ * behind it; holding one of the four queue slots for it would make a cache HIT contend with real
127
+ * derivations, which is the opposite of the point.
128
+ */
129
+ /**
130
+ * The introspection MENU — what this running companion can answer, for a caller that has to choose.
131
+ *
132
+ * Serves `wildo context list` (issue #252): the door's tier-1 progressive-disclosure catalog. It is a
133
+ * COMPANION answer rather than a CLI-side copy of the behavior definitions on purpose — the CLI and a
134
+ * running companion can be different builds, and a menu describing behaviors the serving side does not
135
+ * have is the staleness class `.claude/rules/staleness-presents-as-a-logic-defect.md` records. Runtime
136
+ * truth, one hop.
137
+ *
138
+ * `defaultBackendServiceKey` is here for the same one-authority reason: `POST /_meta/introspect`
139
+ * REQUIRES a `serviceKey`, and the "first backend service" default already exists in the playbook
140
+ * composer (`composeWorkspaceTruthSection`). Publishing the resolved default lets a CLI caller pass it
141
+ * explicitly instead of re-deriving the rule, so the POST contract stays strict and the rule stays in
142
+ * companion code.
143
+ */
144
+ describeCatalog(): {
145
+ readonly behaviors: ReadonlyArray<{
146
+ readonly behaviorId: string;
147
+ readonly description: string;
148
+ readonly category: string;
149
+ readonly supportedServiceKinds: readonly CompanionIntrospectionServiceKind[];
150
+ }>;
151
+ readonly serviceKeys: ReadonlyArray<{
152
+ readonly key: string;
153
+ readonly kind: CompanionIntrospectionServiceKind;
154
+ }>;
155
+ readonly defaultBackendServiceKey: string | null;
156
+ };
59
157
  requestInfo(request: CompanionIntrospectionRequest): Promise<CompanionIntrospectionResult>;
158
+ /**
159
+ * Compile a derivation without consulting or writing compiled state.
160
+ *
161
+ * The COMPILE primitive, exposed so the state service can drive a recompilation that no read
162
+ * asked for. It is the same path a cache miss took before, minus the memo: the concurrency queue,
163
+ * the subprocess, the IPC result. Nothing here decides freshness, which is the separation this
164
+ * whole change exists to make — a caller that wants the current answer asks the state service, and
165
+ * a caller that wants a NEW answer asks this.
166
+ */
167
+ compileNow(request: CompanionIntrospectionRequest): Promise<CompanionIntrospectionResult>;
168
+ /**
169
+ * The cache key a request resolves to, for a caller that needs to talk about a derivation's
170
+ * identity — to warm it, to stamp a notification with its generation — without running it.
171
+ *
172
+ * `null` means the request's input cannot be stably rendered, which every caller reads as
173
+ * "compile, do not remember".
174
+ */
175
+ resolveDerivationIdentity(request: CompanionIntrospectionRequest): Promise<{
176
+ readonly cacheKey: string;
177
+ readonly behavior: string;
178
+ readonly serviceKey: string;
179
+ } | null>;
180
+ /**
181
+ * Drop every compiled derivation.
182
+ *
183
+ * Costs a recompilation and changes no answer — the property that makes this state per-run runtime
184
+ * state rather than a second source of truth. Kept on this service because it is the door every
185
+ * consumer already holds; the state itself lives one layer down.
186
+ */
187
+ clearDerivationCache(): void;
188
+ private deriveThroughQueue;
60
189
  private enqueue;
61
190
  private runQueuedTask;
62
191
  private resolveTarget;
@@ -1 +1 @@
1
- {"version":3,"file":"companion-introspection.companion.service.d.ts","sourceRoot":"","sources":["../../../../../../src/core/introspection/services/companion-introspection.companion.service.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAIhE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAE,6CAA6C,EAAE,MAAM,+DAA+D,CAAC;AAC9H,OAAO,KAAK,EAKV,6BAA6B,EAG7B,4BAA4B,EAG7B,MAAM,0CAA0C,CAAC;AAMlD;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,wBAAwB,8JAM3B,CAAC;AAEX;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAAC,UAAU,CAOtD;AAED,qBACa,6BAA6B;IAUH,OAAO,CAAC,QAAQ,CAAC,MAAM;IACR,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IAEnF,OAAO,CAAC,QAAQ,CAAC,uBAAuB;IAZ1C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA+D;IACxF,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,WAAW,CAAK;IACxB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAyB;IAC/C,iFAAiF;IACjF,OAAO,CAAC,eAAe,CAAuB;gBAGQ,MAAM,EAAE,aAAa,EACN,gBAAgB,EAAE,gBAAgB,EAEpF,uBAAuB,EAAE,6CAA6C;IAgB5E,WAAW,CAAC,OAAO,EAAE,6BAA6B,GAAG,OAAO,CAAC,4BAA4B,CAAC;YAczF,OAAO;YAYP,aAAa;YAcb,aAAa;IA4C3B,OAAO,CAAC,kBAAkB;YAMZ,aAAa;IAgP3B,OAAO,CAAC,iBAAiB;IAkBzB;;;;;;;;;;OAUG;IACH,OAAO,CAAC,8BAA8B;IActC,OAAO,CAAC,uBAAuB;IAc/B,OAAO,CAAC,uBAAuB;IA2B/B,OAAO,CAAC,yBAAyB;IAkBjC,OAAO,CAAC,kBAAkB;CAiB3B"}
1
+ {"version":3,"file":"companion-introspection.companion.service.d.ts","sourceRoot":"","sources":["../../../../../../src/core/introspection/services/companion-introspection.companion.service.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAIhE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAE,6CAA6C,EAAE,MAAM,+DAA+D,CAAC;AAC9H,OAAO,EAAE,4CAA4C,EAAE,MAAM,oDAAoD,CAAC;AAClH,OAAO,KAAK,EAKV,6BAA6B,EAG7B,4BAA4B,EAE5B,iCAAiC,EAClC,MAAM,0CAA0C,CAAC;AAgBlD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE;IAC9C,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,QAAQ,CAAC,iBAAiB,EAAE,OAAO,CAAC;IACpC,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC;CACnC,GAAG,OAAO,CAGV;AAYD;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,wBAA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