@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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"introspection-derivation-state.companion.service.js","sourceRoot":"","sources":["../../../../../../src/core/introspection/services/introspection-derivation-state.companion.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAEhE,OAAO,EAAE,uBAAuB,EAAE,MAAM,mCAAmC,CAAC;AAE5E,OAAO,EAAE,gCAAgC,EAAE,MAAM,gDAAgD,CAAC;AAMlG;;;;;;;;;;;;GAYG;AACH,MAAM,CAAN,IAAY,0BAKX;AALD,WAAY,0BAA0B;IACpC,iFAAiF;IACjF,mEAAqC,CAAA;IACrC,sFAAsF;IACtF,2CAAa,CAAA;AACf,CAAC,EALW,0BAA0B,KAA1B,0BAA0B,QAKrC;AAED,0FAA0F;AAC1F,MAAM,CAAN,IAAY,4BASX;AATD,WAAY,4BAA4B;IACtC,mDAAmD;IACnD,mEAAmC,CAAA;IACnC,sFAAsF;IACtF,iEAAiC,CAAA;IACjC,iDAAiD;IACjD,uDAAuB,CAAA;IACvB,6CAA6C;IAC7C,uDAAuB,CAAA;AACzB,CAAC,EATW,4BAA4B,KAA5B,4BAA4B,QASvC;AAqDD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEI,IAAM,4CAA4C,GAAlD,MAAM,4CAA4C;IAcD;IACe;IAdpD,QAAQ,CAA+D;IACvE,KAAK,GAAG,IAAI,GAAG,EAA2C,CAAC;IAC3D,KAAK,GAAG,IAAI,GAAG,EAA2B,CAAC;IAC5D,gGAAg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;QAC/F,iGAAiG;QACjG,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,cAAc,GAAG,CAAC,CAAC,CAAC;QACpE,MAAM,QAAQ,GAAoC;YAChD,MAAM;YACN,gBAAgB;YAChB,UAAU,EAAE,IAAI,CAAC,cAAc;YAC/B,UAAU;SACX,CAAC;QACF;;;;;;;;;;;;;;;;;;WAkBG;QACH,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QACnC,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF,CAAA;AA/UY,4CAA4C;IADxD,UAAU,EAAE;IAeR,WAAA,MAAM,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAA;IACjC,WAAA,MAAM,CAAC,uBAAuB,CAAC,gBAAgB,CAAC,CAAA;;GAfxC,4CAA4C,CA+UxD;;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,UAAU,0BAA0B,CACxC,IAAqD,EACrD,KAAsD;IAEtD,IAAI,IAAI,KAAK,SAAS,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IAC5D,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAClE,CAAC","sourcesContent":["import { inject, injectable } from 'inversify';\nimport type { LoggerService } from '@wildo-ai/saas-backend-lib';\nimport { SAAS_SERVICE_TYPES } from '@wildo-ai/saas-backend-lib';\n\nimport { COMPANION_SERVICE_TYPES } from '../../inject/models/service-types';\nimport type { CompanionContext } from '../../context/companion-context';\nimport { IntrospectionSourceStateObserver } from './introspection-source-state.companion.service';\nimport type {\n CompanionIntrospectionResult,\n CompanionIntrospectionSuccessResult,\n} from '../models/companion-introspection.models';\n\n/**\n * How a derivation's freshness is currently decided.\n *\n * The two modes are not a preference. `OBSERVE_PER_READ` is exactly the behaviour issue #159 shipped\n * — sweep the source on every read, serve the memo only when the token still matches — and it is the\n * FALLBACK, kept because it is correct without any collaborator. `PUSH` is the mode this service\n * exists for: a freshness authority (the source watcher) tells the state when the source moved, so a\n * read consults nothing but memory.\n *\n * The service starts in `OBSERVE_PER_READ` and is promoted only when an authority registers. That\n * ordering is deliberate: a companion whose watcher failed to start, or a unit test that wires none,\n * degrades to slow-and-correct rather than to fast-and-stale.\n */\nexport enum IntrospectionFreshnessMode {\n /** No authority registered. Every read sweeps, exactly as issue #159 left it. */\n OBSERVE_PER_READ = 'observe-per-read',\n /** An authority is live. Reads consult memory; the authority drives recompilation. */\n PUSH = 'push',\n}\n\n/** Why a recompilation was triggered, carried into the log line and the change report. */\nexport enum IntrospectionRecompileReason {\n /** The freshness authority saw the source move. */\n SOURCE_MUTATION = 'source-mutation',\n /** The periodic reconciliation sweep found a token the authority had not reported. */\n RECONCILIATION = 'reconciliation',\n /** Startup warming, before anybody has asked. */\n BOOT_WARM = 'boot-warm',\n /** A read found no compiled state at all. */\n COLD_READ = 'cold-read',\n}\n\n/**\n * One compiled derivation, and everything a consumer needs to talk about it without recompiling.\n */\nexport interface IntrospectionCompiledDerivation {\n /**\n * The child's answer, exactly as `requestInfo` would have returned it.\n *\n * Typed as the SUCCESS result rather than the union, because only a success is ever retained —\n * see `store`. That is not a narrowing for convenience: `servedFromCache` exists only on the\n * success arm, so a union here would make the flag unassignable, and the type is the place that\n * says a failure is never held.\n */\n readonly result: CompanionIntrospectionSuccessResult;\n /** The source-state token this was compiled against. */\n readonly sourceStateToken: string;\n /**\n * A monotonically increasing stamp for this derivation, used as the WebSocket sync `version`.\n *\n * **It must never go backwards, including across a companion restart.** `ResourceMutationManager`\n * drops any pushed update whose `version <= this._version`, so a counter that resets to zero on\n * restart makes every browser tab that stayed open ignore every later update — silently, with no\n * error and no refetch, leaving a permanently frozen view. Wall-clock milliseconds cannot regress\n * across a restart, which is the whole reason they are used here rather than a counter.\n */\n readonly generation: number;\n /** When this was compiled, for the debug line that explains a lookup's age. */\n readonly compiledAt: number;\n}\n\n/** What one recompilation did, per derivation, so a caller can emit a diff without re-reading. */\nexport interface IntrospectionRecompileOutcome {\n readonly cacheKey: string;\n readonly behavior: string;\n readonly serviceKey: string;\n /** The state before, absent on a first compile. */\n readonly previous: IntrospectionCompiledDerivation | undefined;\n /** The state after. Absent when the recompilation FAILED and the previous state was kept. */\n readonly next: IntrospectionCompiledDerivation | undefined;\n /** `false` when the recompilation produced a byte-identical payload — nothing to notify about. */\n readonly changed: boolean;\n}\n\n/** A registered derivation the state service knows how to recompile without being asked again. */\ninterface KnownDerivation {\n readonly cacheKey: string;\n readonly behavior: string;\n readonly serviceKey: string;\n /** The closure that compiles this exact question. Held so recompilation needs no caller. */\n readonly compile: () => Promise<CompanionIntrospectionResult>;\n}\n\n/**\n * Owns COMPILED introspection state, so that reading one is not the act that compiles it.\n *\n * ## Why this is a separate service rather than a better cache\n *\n * Before this, compilation and retrieval were the same code path: `requestInfo` observed the source,\n * compared a token, and compiled on a miss — all inside the caller's request. That fusion has three\n * consequences that no amount of cache tuning removes.\n *\n * 1. **Every read pays the freshness probe.** Measured on wonder-crm, 2026-09-02: a warm\n * `LIST /api/v1/workbench-domain-resources` answered in 200–270 ms, of which the source sweep is\n * 180–225 ms. The cache was working perfectly and almost all of the remaining latency was the act\n * of asking whether it could be used.\n * 2. **A miss is charged to whoever happened to ask.** Same session: a cold `LIST` cost 8.95 s and an\n * addressed `READ` cost 44.4 s, then 500. In a tree with the engine's `tsc-watch` fleet running,\n * the token moves constantly, so a miss is the NORMAL case rather than the exception.\n * 3. **Nothing can be notified.** A pull-shaped cache learns that the source moved only while\n * somebody is waiting for an answer, so there is no moment at which it could tell a frontend that\n * a row changed. Push requires knowing BEFORE the read.\n *\n * Separating the two makes each answerable on its own terms: compilation is triggered by the source\n * moving, retrieval is a map lookup, and the moment between them is where a notification can exist.\n *\n * ## What this holds is TIME, never TRUTH\n *\n * `one-source-of-truth.md` Rule 5: this is per-run runtime state. Deleting all of it costs a\n * recompilation and changes no answer — {@link clear} is the proof obligation, and the byte-identical\n * payload across it is the test. Nothing here is a ledger, nothing is persisted, and no decision\n * anywhere may be made from the absence of an entry.\n */\n@injectable()\nexport class IntrospectionDerivationStateCompanionService {\n private readonly logDebug: (message: string, context?: Record<string, unknown>) => void;\n private readonly state = new Map<string, IntrospectionCompiledDerivation>();\n private readonly known = new Map<string, KnownDerivation>();\n /** Recompilations currently running, so two triggers cannot compile the same question twice. */\n private readonly inFlight = new Map<string, Promise<CompanionIntrospectionResult>>();\n private readonly observer: IntrospectionSourceStateObserver;\n private freshnessMode: IntrospectionFreshnessMode = IntrospectionFreshnessMode.OBSERVE_PER_READ;\n private freshnessAuthorityName: string | undefined;\n /** The token the state was last compiled against, in `PUSH` mode. */\n private currentToken: string | undefined;\n private lastGeneration = 0;\n\n constructor(\n @inject(SAAS_SERVICE_TYPES.Logger) private readonly logger: LoggerService,\n @inject(COMPANION_SERVICE_TYPES.CompanionContext) private readonly companionContext: CompanionContext,\n ) {\n this.logDebug = this.logger.debugByType('IntrospectionDerivationState');\n this.logger.setDebugTypeLogging('IntrospectionDerivationState', true);\n this.observer = new IntrospectionSourceStateObserver(this.companionContext);\n }\n\n public get mode(): IntrospectionFreshnessMode {\n return this.freshnessMode;\n }\n\n /**\n * Promote the service out of per-read observation.\n *\n * Called by the source watcher once it is actually watching. The name is carried so an operator\n * reading a log line can tell WHICH authority is responsible for freshness, and so a second\n * registration is visible rather than silent.\n */\n public registerFreshnessAuthority(name: string): void {\n this.freshnessAuthorityName = name;\n this.freshnessMode = IntrospectionFreshnessMode.PUSH;\n this.logger.info('Introspection derivation state promoted to push freshness', { authority: name });\n }\n\n /**\n * Demote back to per-read observation.\n *\n * The watcher calls this when it errors or closes. Demoting is always safe and never wrong — it\n * only costs time — whereas staying in `PUSH` with a dead authority serves a tree that has moved.\n */\n public noteFreshnessAuthorityLost(reason: string): void {\n if (this.freshnessMode === IntrospectionFreshnessMode.OBSERVE_PER_READ) return;\n this.freshnessMode = IntrospectionFreshnessMode.OBSERVE_PER_READ;\n this.logger.warn('Introspection freshness authority lost; falling back to per-read source observation', {\n authority: this.freshnessAuthorityName,\n reason,\n });\n this.freshnessAuthorityName = undefined;\n }\n\n /**\n * Read a derivation, compiling only when there is nothing to read.\n *\n * `compile` is retained against the cache key on first sight, which is what lets a later\n * source mutation recompile this question with no caller present. That is the whole mechanism by\n * which retrieval stops driving compilation: the FIRST read teaches the service the question, and\n * every subsequent answer — including the ones nobody asked for yet — is produced by the source\n * moving instead.\n *\n * In `OBSERVE_PER_READ` mode the freshness probe still runs here, because without an authority\n * there is nothing else that could run it.\n */\n public async read(\n identity: { readonly cacheKey: string; readonly behavior: string; readonly serviceKey: string },\n compile: () => Promise<CompanionIntrospectionResult>,\n ): Promise<CompanionIntrospectionResult> {\n if (!this.known.has(identity.cacheKey)) {\n this.known.set(identity.cacheKey, { ...identity, compile });\n }\n\n if (this.freshnessMode === IntrospectionFreshnessMode.OBSERVE_PER_READ) {\n return this.readWithPerReadObservation(identity, compile);\n }\n\n const held = this.state.get(identity.cacheKey);\n if (held) {\n this.logDebug('Introspection derivation served from compiled state', {\n behavior: identity.behavior,\n serviceKey: identity.serviceKey,\n ageMs: Date.now() - held.compiledAt,\n generation: held.generation,\n });\n return { ...held.result, servedFromCache: true };\n }\n\n return (await this.compileInto(identity.cacheKey, IntrospectionRecompileReason.COLD_READ))\n ?? compile();\n }\n\n /**\n * The pre-#159-separation path, kept verbatim in behaviour for the no-authority case.\n *\n * A read observes the source, serves the held derivation when the token still matches, and\n * compiles otherwise. Slower by exactly one sweep per read, and correct with no collaborator.\n */\n private async readWithPerReadObservation(\n identity: { readonly cacheKey: string; readonly behavior: string; readonly serviceKey: string },\n compile: () => Promise<CompanionIntrospectionResult>,\n ): Promise<CompanionIntrospectionResult> {\n const observation = await this.observer.observe(Date.now());\n const held = this.state.get(identity.cacheKey);\n if (held && held.sourceStateToken === observation.token) {\n this.logDebug('Introspection derivation served from compiled state (per-read observation)', {\n behavior: identity.behavior,\n serviceKey: identity.serviceKey,\n sourceObservationMs: observation.durationMs,\n });\n return { ...held.result, servedFromCache: true };\n }\n\n /*\n * Routed through `compileInto` rather than calling the closure here, because that is where the\n * in-flight join lives. `maxConcurrency` caps how many subprocesses run at once; it does not\n * notice that two of them are asking the identical question. Two concurrent reads of one\n * behavior must cost ONE subprocess, and calling the closure directly would silently\n * reintroduce the second child.\n *\n * `bounded: false` means the sweep gave up before seeing the whole tree, so its token says\n * nothing about whether the source moved. Compiling is still correct; RETAINING against that\n * token would not be — which is why the token is handed over only when the sweep completed.\n */\n return (await this.compileInto(\n identity.cacheKey,\n IntrospectionRecompileReason.COLD_READ,\n observation.bounded ? observation.token : undefined,\n )) ?? compile();\n }\n\n /**\n * Recompile everything this service knows about, if the source has actually moved.\n *\n * Returns one outcome per known derivation, with `changed` telling the caller whether anything\n * downstream needs to hear about it. A recompilation that produces a byte-identical payload is\n * reported as unchanged, because an operator saving a file that alters nothing observable must not\n * produce a wave of notifications.\n *\n * A FAILED recompilation keeps the previous state rather than dropping it. The dominant failure\n * here is an application mid-build, and answering \"could not look\" for the seconds a `tsc` takes —\n * when a correct answer from one second ago is in hand — is worse than answering slightly late.\n */\n public async recompileIfSourceMoved(\n reason: IntrospectionRecompileReason,\n ): Promise<{ readonly moved: boolean; readonly outcomes: readonly IntrospectionRecompileOutcome[] }> {\n const observation = await this.observer.observe(Date.now());\n if (!observation.bounded) {\n this.logger.warn('Introspection source observation exceeded its ceiling; recompiling without remembering', {\n reason,\n observedEntryCount: observation.observedEntryCount,\n });\n }\n\n if (this.currentToken === observation.token && observation.bounded) {\n return { moved: false, outcomes: [] };\n }\n this.currentToken = observation.bounded ? observation.token : undefined;\n\n /*\n * Snapshot every previous state BEFORE compiling any of them.\n *\n * `store` prunes entries taken against a superseded token, so the FIRST compilation of this loop\n * deletes every OTHER derivation's previous state — they still carry the old token. Reading\n * `previous` inside the loop therefore returned `undefined` for every derivation after the first,\n * and each one reported its whole row set as CREATED.\n *\n * Measured before the fix on wonder-crm: 180 publications in three minutes, every one of them\n * `created: N, updated: 0, deleted: 0` — a full-repaint storm, the exact opposite of what the\n * diff exists to produce. Found by reading the live log rather than by a test, which is why the\n * regression pin below compares TWO derivations rather than one.\n */\n const previousByKey = new Map<string, IntrospectionCompiledDerivation>();\n for (const entry of this.known.values()) {\n const held = this.state.get(entry.cacheKey);\n if (held) previousByKey.set(entry.cacheKey, held);\n }\n\n const outcomes: IntrospectionRecompileOutcome[] = [];\n for (const entry of this.known.values()) {\n const previous = previousByKey.get(entry.cacheKey);\n await this.compileInto(entry.cacheKey, reason, observation.token);\n const next = this.state.get(entry.cacheKey);\n outcomes.push({\n cacheKey: entry.cacheKey,\n behavior: entry.behavior,\n serviceKey: entry.serviceKey,\n previous,\n next,\n changed: next !== undefined && next !== previous\n && !areDerivationPayloadsEqual(previous?.result, next.result),\n });\n }\n\n this.logDebug('Introspection source moved; recompiled known derivations', {\n reason,\n derivationCount: outcomes.length,\n changedCount: outcomes.filter((outcome) => outcome.changed).length,\n sourceObservationMs: observation.durationMs,\n });\n\n return { moved: true, outcomes };\n }\n\n /**\n * How many derivations are currently held.\n *\n * A diagnostic, and the pin for the pruning invariant: the map is bounded by the distinct\n * questions asked since the last source change, not by every question ever asked.\n */\n public get compiledDerivationCount(): number {\n return this.state.size;\n }\n\n /** The generation currently held for a derivation, for a caller stamping a notification. */\n public generationOf(cacheKey: string): number | undefined {\n return this.state.get(cacheKey)?.generation;\n }\n\n /**\n * Drop every compiled derivation.\n *\n * Costs a recompilation and changes no answer. That property is what makes this state rather than\n * a ledger, so it is exercised by a test rather than merely asserted here.\n */\n public clear(): void {\n this.state.clear();\n this.currentToken = undefined;\n }\n\n /**\n * Test seam: drop ONE compiled entry, to reproduce a single-key compile against a partly-empty\n * state. Production never evicts a single entry — see the note in `store`.\n */\n public clearOneForTesting(cacheKey: string): void {\n this.state.delete(cacheKey);\n }\n\n /** Test seam: replace the source observer with a fake. Production always observes real trees. */\n public setSourceStateObserverForTesting(observer: IntrospectionSourceStateObserver): void {\n (this as unknown as { observer: IntrospectionSourceStateObserver }).observer = observer;\n }\n\n /**\n * Compile one known derivation into the state, joining an identical in-flight compilation.\n *\n * The join matters more here than in a request-shaped cache: a watcher burst and a cold read can\n * arrive within the same millisecond, and a subprocess that imports the whole application is the\n * most expensive thing this process does.\n */\n private async compileInto(\n cacheKey: string,\n reason: IntrospectionRecompileReason,\n tokenOverride?: string,\n ): Promise<CompanionIntrospectionResult | undefined> {\n const existing = this.inFlight.get(cacheKey);\n if (existing) return existing;\n\n const entry = this.known.get(cacheKey);\n if (!entry) return undefined;\n\n const run = (async (): Promise<CompanionIntrospectionResult> => {\n let token = tokenOverride;\n if (token === undefined) {\n const observation = await this.observer.observe(Date.now());\n token = observation.bounded ? observation.token : undefined;\n }\n\n const result = await entry.compile();\n if (!result.success || token === undefined) {\n /*\n * A failure is never retained, and the reasoning is the same as before the split: the\n * dominant failure here is an application whose `dist` is not built, whose remedy moves the\n * source and would invalidate anyway; and a transient failure — a timeout on a loaded\n * machine — would otherwise stick to an unchanged tree and be served as the answer forever.\n */\n this.logDebug('Introspection compilation not retained', {\n behavior: entry.behavior,\n serviceKey: entry.serviceKey,\n reason,\n success: result.success,\n hasToken: token !== undefined,\n });\n return result;\n }\n this.store(cacheKey, result, token);\n return result;\n })().finally(() => {\n this.inFlight.delete(cacheKey);\n });\n\n this.inFlight.set(cacheKey, run);\n return run;\n }\n\n /** Write a compiled derivation into the state under a fresh, never-decreasing generation. */\n private store(\n cacheKey: string,\n result: CompanionIntrospectionSuccessResult,\n sourceStateToken: string,\n ): IntrospectionCompiledDerivation {\n const compiledAt = Date.now();\n // Wall-clock is monotone across a restart; the `+1` only breaks a tie between two compilations\n // landing inside the same millisecond, which a browser tab would otherwise read as a stale push.\n this.lastGeneration = Math.max(compiledAt, this.lastGeneration + 1);\n const compiled: IntrospectionCompiledDerivation = {\n result,\n sourceStateToken,\n generation: this.lastGeneration,\n compiledAt,\n };\n /*\n * NOTHING IS PRUNED HERE, and that REVERSES what issue #159's cache did — deliberately.\n *\n * That cache dropped every entry taken against a superseded token, on the reasoning that such an\n * entry \"describes a tree that no longer exists, so it can never be served again\". The first half\n * is still true; the conclusion is not, because an entry now has a SECOND job. It is the basis\n * the next recompilation diffs against, and being unservable as an ANSWER does not make it\n * useless as a BASELINE.\n *\n * Pruning here cost exactly that: compiling ONE derivation evicted every other derivation's\n * baseline, so the next recompile-all saw no previous state for them and reported their whole row\n * sets as CREATED. Measured on wonder-crm before the fix — 180 publications in three minutes,\n * every one a full repaint.\n *\n * The growth the pruning guarded against cannot occur any more either: this map holds ONE entry\n * per cache key, and a recompilation OVERWRITES that key rather than adding a second entry. Its\n * size is bounded by the number of distinct questions in {@link known}, which is the same bound\n * that map already carries.\n */\n this.state.set(cacheKey, compiled);\n return compiled;\n }\n}\n\n/**\n * Whether two derivations carry the same answer.\n *\n * Compared on the DATA the child returned, not on the envelope: a result carries timing and a\n * `servedFromCache` flag that differ between two compilations of an unchanged application, and\n * comparing those would report every recompilation as a change.\n *\n * A stable stringify is deliberately NOT used. The child's payload is produced by one code path from\n * one imported module graph, so key order is stable between two runs of the same bytes; and an\n * ordering difference that did appear would mean the application's own output was non-deterministic,\n * which is a change worth reporting rather than hiding.\n *\n * ## This OVER-reports, deliberately, and the row diff is the real decision\n *\n * Measured on wonder-crm 2026-09-02, by recompiling three times against byte-identical sources: two\n * of three derivations reported `changed` every time. Diffing two payloads leaf by leaf found exactly\n * one differing value — `specification-artifacts` stamps `trace.evaluatedAt` with the wall-clock\n * instant of the derivation, so its payload can never compare equal to its predecessor.\n * (`application-domain-model` differed in **0** leaves, so the volatility is per-behavior, not\n * general.)\n *\n * That is safe, and it is safe for a specific reason rather than by luck: `changed` only decides\n * whether the notifier is INVITED to look. What it publishes is decided by `diffProjectedRows` over\n * the projected ROWS, and `trace` sits outside this behavior's `rowsPath`. The live check confirms\n * it — three touch-only recompilations produced `changedCount: 2` and **zero** publications.\n *\n * The alternative — excluding known-volatile keys here — was rejected: it would be a second, drifting\n * description of what a row contains, when the projection already owns that answer. **But the\n * guarantee rests on volatile fields staying OUT of the projected rows.** A behavior that put a\n * timestamp INSIDE a row would push an update for every row on every recompilation, and nothing here\n * would catch it — the diff would be correct and the data would be noise.\n */\nexport function areDerivationPayloadsEqual(\n left: CompanionIntrospectionSuccessResult | undefined,\n right: CompanionIntrospectionSuccessResult | undefined,\n): boolean {\n if (left === undefined || right === undefined) return false;\n return JSON.stringify(left.data) === JSON.stringify(right.data);\n}\n"]}
@@ -0,0 +1,186 @@
1
+ import type { CompanionContext } from '../../context/companion-context';
2
+ /**
3
+ * What a completed sweep learned about the source that feeds an introspection derivation.
4
+ */
5
+ export interface IntrospectionSourceStateObservation {
6
+ /**
7
+ * The comparable value. Two observations with the same token describe the same source tree; a
8
+ * different token means SOMETHING moved and every cached derivation is void.
9
+ */
10
+ token: string;
11
+ /**
12
+ * `false` when the sweep hit {@link MAXIMUM_OBSERVED_ENTRIES}. The token is then deliberately
13
+ * unique per observation, so a caller that ignores this flag still re-derives rather than serving
14
+ * a stale answer.
15
+ */
16
+ bounded: boolean;
17
+ /** Wall-clock cost of the sweep, for the debug line that explains a cache hit's latency. */
18
+ durationMs: number;
19
+ /** Number of roots actually walked (a root that does not exist yet is not one). */
20
+ observedRootCount: number;
21
+ /** Files plus directories visited. Reported so an operator can see why a sweep is slow. */
22
+ observedEntryCount: number;
23
+ /** The instant the sweep STARTED, which is the instant the token describes. */
24
+ startedAt: number;
25
+ }
26
+ /**
27
+ * Observes the state of every source tree an introspection derivation can read, as one comparable
28
+ * token.
29
+ *
30
+ * ## Why a token rather than a watcher
31
+ *
32
+ * The companion has no file watcher and adding one would mean a new always-on dependency, a new
33
+ * always-on process cost, and a new class of missed-event bug on the platforms this repository does
34
+ * not test on. A sweep answers the same question on demand, costs ~125 ms against the largest
35
+ * dogfood application, and cannot miss an event because it does not observe events at all — it
36
+ * observes the tree.
37
+ *
38
+ * ## Why mtimes rather than content
39
+ *
40
+ * `.claude/rules/application-creation-directive.md` forbids digests, of any kind, for any purpose,
41
+ * and `.claude/rules/one-source-of-truth.md` Rule 0 refuses anything that is not branchable on git.
42
+ * A content hash compared against a stored one is exactly the second-source-of-truth shape both
43
+ * rules exist to keep out. An mtime observation stores nothing about the application: it is a
44
+ * reading taken now, compared against a reading taken earlier in the same process, and deleting it
45
+ * costs a re-derivation and nothing else.
46
+ *
47
+ * ## What the token is made of, and what each part catches
48
+ *
49
+ * | Component | Catches |
50
+ * |---|---|
51
+ * | maximum file/directory mtime | a file written in place (the ordinary edit, and every `tsc` emit) |
52
+ * | file count | a file added or deleted |
53
+ * | directory count | a directory added or deleted |
54
+ * | directory mtimes, in the maximum | a RENAME, which preserves the file's own mtime and would otherwise be invisible while the file count stayed equal |
55
+ *
56
+ * Directory mtimes are the non-obvious member and they are load-bearing: without them,
57
+ * `mv a.ts b.ts` moves neither the count nor any file mtime, and the cache would keep answering
58
+ * from the pre-rename derivation for as long as nothing else in the tree moved.
59
+ *
60
+ * The one mutation this cannot see is an mtime pushed BACKWARD in place on a file that is not the
61
+ * newest in the tree (`touch -t 200001010000 <file>` on an already-old file). Nothing in a dev loop
62
+ * does that; a real editor, `tsc`, `git checkout` and pnpm's hard-link relink all move an mtime
63
+ * forward or move a directory. Recorded rather than papered over, because a reader who assumes the
64
+ * token is total would be assuming something false.
65
+ *
66
+ * ## Which trees, and why the engine ones are in there
67
+ *
68
+ * An application resolving `@wildo-ai/*` through `file:` links — every dogfood app does — changes
69
+ * its derivation when the engine is rebuilt, with no application file touched. The engine bytes the
70
+ * child actually imports are the ones pnpm hard-linked into the app's store, NOT the ones in
71
+ * `engine/<package>/dist`, and the two are reconciled at supervised (re)start rather than continuously. So
72
+ * the framework signal has to be the injected snapshot itself. `.wildo-runtime-signals/dev-compile-status.json`
73
+ * was considered and rejected for exactly this: it is a LEADING indicator, moving when the engine
74
+ * compiles and therefore possibly before the bytes this process would import have changed — which
75
+ * would let a derivation be cached against a token that has already advanced past it, and never
76
+ * re-derived when the injection finally lands.
77
+ *
78
+ * For an application consuming published `@wildo-ai/*` tarballs the same roots are simply immutable
79
+ * between installs, so the sweep costs a little and proves the same thing.
80
+ *
81
+ * ## What it costs, and one narrowing that was measured and REJECTED
82
+ *
83
+ * 176–225 ms against `examples/wonder-crm` (23 roots, 27,050 entries), versus a 3.1–4.2 s cold
84
+ * import of that application's specifications package alone. So a cache hit is ~15x cheaper than
85
+ * the cheapest possible miss.
86
+ *
87
+ * Skipping `*.d.ts` and `*.map` would roughly halve it — they are **55 %** of the swept files
88
+ * (8,830 maps + 4,417 declarations of 24,243) and neither can change a runtime derivation. It was
89
+ * rejected anyway: the saving is ~90 ms nobody can perceive, and it would buy that with an
90
+ * assumption about what a future behavior may read. No behavior under `introspection/subprocess/`
91
+ * imports `node:fs` at all today — every one of them is a pure function of the imported module
92
+ * graph — but that is a fact about today, and the direction to be wrong in here is toward
93
+ * re-deriving. Recorded so the next reader does not re-derive the numbers before reaching the same
94
+ * conclusion.
95
+ */
96
+ export declare class IntrospectionSourceStateObserver {
97
+ private readonly companionContext;
98
+ private observationSequence;
99
+ private inFlight;
100
+ constructor(companionContext: Pick<CompanionContext, 'saasRoot' | 'companionHome' | 'servicesByKey' | 'resolvedLibraries' | 'resolvedSpecifications'>);
101
+ /**
102
+ * Take a reading of the source trees, reusing an in-flight one ONLY when that reading started at
103
+ * or after the caller's own arrival.
104
+ *
105
+ * The condition is the whole point of the coalescing. A sweep takes ~125 ms; a request arriving
106
+ * 100 ms into someone else's sweep and adopting its token would be answered from a picture of the
107
+ * world taken 100 ms before it asked — a window in which the operator could have saved a file. So
108
+ * a late arrival waits for the running sweep to finish and takes a fresh one, which is slower and
109
+ * correct, while genuinely concurrent callers share one walk, which is what the coalescing is for.
110
+ */
111
+ observe(requestedAt?: number): Promise<IntrospectionSourceStateObservation>;
112
+ private runObservation;
113
+ /**
114
+ * The two ROOT populations a derivation reads from, kept apart because a watcher treats them
115
+ * differently.
116
+ *
117
+ * An APPLICATION root is a package the operator edits: its `src` moves first and its `dist` moves
118
+ * second, and only the second changes what a derivation imports —
119
+ * `resolvePackageCompanionEntryPath` resolves the package's `exports['./companion']`, which is
120
+ * `./dist/esm/companion-exports.js` on every application package. A FRAMEWORK root is the injected
121
+ * `@wildo-ai/*` copy in the application's own store: dist-only bytes, hard-linked at supervised
122
+ * (re)start, carrying no runtime-signal files of its own.
123
+ *
124
+ * Exposed so the watcher and the sweep observe one population rather than two enumerations that
125
+ * agree only until one side gains an entry.
126
+ */
127
+ resolveObservedRootPopulations(): Promise<{
128
+ readonly applicationRoots: readonly string[];
129
+ readonly frameworkRoots: readonly string[];
130
+ }>;
131
+ /**
132
+ * Every tree whose bytes can reach a derivation, de-duplicated by resolved real path.
133
+ *
134
+ * Two families, and the second is the one a reader would not think of:
135
+ *
136
+ * 1. The APPLICATION package roots — every declared service, every resolved library, and the
137
+ * specifications package. Whole roots rather than `src/` alone, because
138
+ * `resolvePackageCompanionEntryPath` prefers a package's built `./companion` export when it
139
+ * exists, so the child commonly imports `dist/`, not source. Sweeping both means neither
140
+ * resolution mode has a blind spot.
141
+ * 2. The FRAMEWORK packages, reached by reading each of those roots' (and the companion home's)
142
+ * `node_modules/@wildo-ai` scope directory and resolving each link to its real path. Reading
143
+ * the scope directory rather than listing package names keeps this from becoming a second
144
+ * enumeration of the engine's package set that could drift from the real one.
145
+ *
146
+ * The application root itself is NOT walked recursively — its interesting children are already in
147
+ * family 1, and descending it would pull in `.wildo-saas` (the companion's own dist plus the
148
+ * runtime-signal files that churn on a heartbeat, which would make every token unique and every
149
+ * cache read a miss).
150
+ */
151
+ private resolveObservedRoots;
152
+ /**
153
+ * Fold the application root's own top-level FILES in, without descending it.
154
+ *
155
+ * These are `pnpm-lock.yaml`, `package.json` and `wildo.saas.config.ts` — the manifests that
156
+ * decide which third-party bytes the child imports. Without them there is a narrow but real hole:
157
+ * an install that moves a non-`@wildo-ai` dependency changes a derivation while touching nothing
158
+ * inside a package root, because the walk enters `node_modules` only through the resolved
159
+ * `@wildo-ai` scope. The lockfile moves on every such install, so one shallow read closes it.
160
+ *
161
+ * The root is NOT descended, because doing so would pull in `.wildo-saas` — the companion's own
162
+ * dist and the runtime-signal files that are rewritten on a heartbeat, which would make every
163
+ * token unique and every cache read a miss.
164
+ */
165
+ private observeApplicationRootManifests;
166
+ /**
167
+ * Breadth-of-tree walk with a fixed directory concurrency.
168
+ *
169
+ * A worker-pool built over the ROOT list was written first and was wrong: it sizes its pool from
170
+ * the number of roots, so a single-root application would walk its whole tree one directory at a
171
+ * time, and a worker that finds the queue momentarily empty cannot tell "finished" from "another
172
+ * worker is about to push children". The pump below sizes on IN-FLIGHT directories instead, which
173
+ * is the quantity the concurrency limit is actually about, and terminates on the only condition
174
+ * that means finished: nothing queued and nothing running.
175
+ */
176
+ private walk;
177
+ /**
178
+ * Read one directory: count it, fold its own mtime in, stat its files, and queue its children.
179
+ *
180
+ * Never rejects. A directory that cannot be read (an unbuilt `dist`, a permission) contributes
181
+ * nothing and is not an error — when it appears later it is a new directory, which moves the
182
+ * counts and invalidates every cached derivation.
183
+ */
184
+ private visitDirectory;
185
+ }
186
+ //# sourceMappingURL=introspection-source-state.companion.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"introspection-source-state.companion.service.d.ts","sourceRoot":"","sources":["../../../../../../src/core/introspection/services/introspection-source-state.companion.service.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAsCxE;;GAEG;AACH,MAAM,WAAW,mCAAmC;IAClD;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB,4FAA4F;IAC5F,UAAU,EAAE,MAAM,CAAC;IACnB,mFAAmF;IACnF,iBAAiB,EAAE,MAAM,CAAC;IAC1B,2FAA2F;IAC3F,kBAAkB,EAAE,MAAM,CAAC;IAC3B,+EAA+E;IAC/E,SAAS,EAAE,MAAM,CAAC;CACnB;AASD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqEG;AACH,qBAAa,gCAAgC;IAC3C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAA0H;IAC3J,OAAO,CAAC,mBAAmB,CAAK;IAChC,OAAO,CAAC,QAAQ,CAAiG;gBAG/G,gBAAgB,EAAE,IAAI,CAAC,gBAAgB,EAAE,UAAU,GAAG,eAAe,GAAG,eAAe,GAAG,mBAAmB,GAAG,wBAAwB,CAAC;IAK3I;;;;;;;;;OASG;IACU,OAAO,CAAC,WAAW,GAAE,MAAmB,GAAG,OAAO,CAAC,mCAAmC,CAAC;YAuBtF,cAAc;IA4B5B;;;;;;;;;;;;;OAaG;IACU,8BAA8B,IAAI,OAAO,CAAC;QACrD,QAAQ,CAAC,gBAAgB,EAAE,SAAS,MAAM,EAAE,CAAC;QAC7C,QAAQ,CAAC,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;KAC5C,CAAC;IAuCF;;;;;;;;;;;;;;;;;;;OAmBG;YACW,oBAAoB;IAKlC;;;;;;;;;;;;OAYG;YACW,+BAA+B;IAuB7C;;;;;;;;;OASG;YACW,IAAI;IA4BlB;;;;;;OAMG;YACW,cAAc;CAyD7B"}
@@ -0,0 +1,368 @@
1
+ import { promises as fsPromises } from 'node:fs';
2
+ import { join, resolve } from 'node:path';
3
+ /**
4
+ * How many directories are walked concurrently.
5
+ *
6
+ * Measured on `examples/wonder-crm` (23,758 files + 2,706 directories across the three application
7
+ * package roots and the 19 distinct `@wildo-ai/*` roots they resolve to): 350 ms at concurrency 1,
8
+ * **125 ms at 16**, 142 ms at 64, 134 ms at 128. The curve is flat past 16, so 16 is the point where
9
+ * the walk stops being latency-bound without turning into an open-ended file-descriptor burst.
10
+ *
11
+ * The walk is deliberately ASYNC rather than the ~30 % faster synchronous form. A synchronous sweep
12
+ * measured 175 ms on the same tree, but it holds the event loop for that whole time — and this runs
13
+ * inside a long-lived HTTP server that is also serving the workbench.
14
+ */
15
+ const DIRECTORY_WALK_CONCURRENCY = 16;
16
+ /**
17
+ * Directory names never descended into.
18
+ *
19
+ * `node_modules` is skipped during the walk and reached only through the explicit `@wildo-ai/*`
20
+ * roots below: descending into it from an application package would sweep the app's entire
21
+ * dependency graph (hundreds of thousands of files) to learn nothing the resolved engine roots do
22
+ * not already say.
23
+ */
24
+ const SKIPPED_DIRECTORY_NAMES = new Set(['node_modules', '.git']);
25
+ /**
26
+ * A ceiling on how much this observer will walk before it gives up on caching.
27
+ *
28
+ * Chosen ~10x above the measured 26k-entry dogfood application, so it can only be reached by a
29
+ * pathological root (a `dist` holding a build cache, an application that vendored something large).
30
+ * Crossing it does not disable the walk half-way and report a plausible number — it returns
31
+ * `bounded: false`, which the caller MUST read as "do not cache this derivation". Failing toward
32
+ * re-deriving is the only safe direction here: an under-observed token is a cache key that stops
33
+ * moving when the source does.
34
+ */
35
+ const MAXIMUM_OBSERVED_ENTRIES = 250_000;
36
+ /**
37
+ * Observes the state of every source tree an introspection derivation can read, as one comparable
38
+ * token.
39
+ *
40
+ * ## Why a token rather than a watcher
41
+ *
42
+ * The companion has no file watcher and adding one would mean a new always-on dependency, a new
43
+ * always-on process cost, and a new class of missed-event bug on the platforms this repository does
44
+ * not test on. A sweep answers the same question on demand, costs ~125 ms against the largest
45
+ * dogfood application, and cannot miss an event because it does not observe events at all — it
46
+ * observes the tree.
47
+ *
48
+ * ## Why mtimes rather than content
49
+ *
50
+ * `.claude/rules/application-creation-directive.md` forbids digests, of any kind, for any purpose,
51
+ * and `.claude/rules/one-source-of-truth.md` Rule 0 refuses anything that is not branchable on git.
52
+ * A content hash compared against a stored one is exactly the second-source-of-truth shape both
53
+ * rules exist to keep out. An mtime observation stores nothing about the application: it is a
54
+ * reading taken now, compared against a reading taken earlier in the same process, and deleting it
55
+ * costs a re-derivation and nothing else.
56
+ *
57
+ * ## What the token is made of, and what each part catches
58
+ *
59
+ * | Component | Catches |
60
+ * |---|---|
61
+ * | maximum file/directory mtime | a file written in place (the ordinary edit, and every `tsc` emit) |
62
+ * | file count | a file added or deleted |
63
+ * | directory count | a directory added or deleted |
64
+ * | directory mtimes, in the maximum | a RENAME, which preserves the file's own mtime and would otherwise be invisible while the file count stayed equal |
65
+ *
66
+ * Directory mtimes are the non-obvious member and they are load-bearing: without them,
67
+ * `mv a.ts b.ts` moves neither the count nor any file mtime, and the cache would keep answering
68
+ * from the pre-rename derivation for as long as nothing else in the tree moved.
69
+ *
70
+ * The one mutation this cannot see is an mtime pushed BACKWARD in place on a file that is not the
71
+ * newest in the tree (`touch -t 200001010000 <file>` on an already-old file). Nothing in a dev loop
72
+ * does that; a real editor, `tsc`, `git checkout` and pnpm's hard-link relink all move an mtime
73
+ * forward or move a directory. Recorded rather than papered over, because a reader who assumes the
74
+ * token is total would be assuming something false.
75
+ *
76
+ * ## Which trees, and why the engine ones are in there
77
+ *
78
+ * An application resolving `@wildo-ai/*` through `file:` links — every dogfood app does — changes
79
+ * its derivation when the engine is rebuilt, with no application file touched. The engine bytes the
80
+ * child actually imports are the ones pnpm hard-linked into the app's store, NOT the ones in
81
+ * `engine/<package>/dist`, and the two are reconciled at supervised (re)start rather than continuously. So
82
+ * the framework signal has to be the injected snapshot itself. `.wildo-runtime-signals/dev-compile-status.json`
83
+ * was considered and rejected for exactly this: it is a LEADING indicator, moving when the engine
84
+ * compiles and therefore possibly before the bytes this process would import have changed — which
85
+ * would let a derivation be cached against a token that has already advanced past it, and never
86
+ * re-derived when the injection finally lands.
87
+ *
88
+ * For an application consuming published `@wildo-ai/*` tarballs the same roots are simply immutable
89
+ * between installs, so the sweep costs a little and proves the same thing.
90
+ *
91
+ * ## What it costs, and one narrowing that was measured and REJECTED
92
+ *
93
+ * 176–225 ms against `examples/wonder-crm` (23 roots, 27,050 entries), versus a 3.1–4.2 s cold
94
+ * import of that application's specifications package alone. So a cache hit is ~15x cheaper than
95
+ * the cheapest possible miss.
96
+ *
97
+ * Skipping `*.d.ts` and `*.map` would roughly halve it — they are **55 %** of the swept files
98
+ * (8,830 maps + 4,417 declarations of 24,243) and neither can change a runtime derivation. It was
99
+ * rejected anyway: the saving is ~90 ms nobody can perceive, and it would buy that with an
100
+ * assumption about what a future behavior may read. No behavior under `introspection/subprocess/`
101
+ * imports `node:fs` at all today — every one of them is a pure function of the imported module
102
+ * graph — but that is a fact about today, and the direction to be wrong in here is toward
103
+ * re-deriving. Recorded so the next reader does not re-derive the numbers before reaching the same
104
+ * conclusion.
105
+ */
106
+ export class IntrospectionSourceStateObserver {
107
+ companionContext;
108
+ observationSequence = 0;
109
+ inFlight = null;
110
+ constructor(companionContext) {
111
+ this.companionContext = companionContext;
112
+ }
113
+ /**
114
+ * Take a reading of the source trees, reusing an in-flight one ONLY when that reading started at
115
+ * or after the caller's own arrival.
116
+ *
117
+ * The condition is the whole point of the coalescing. A sweep takes ~125 ms; a request arriving
118
+ * 100 ms into someone else's sweep and adopting its token would be answered from a picture of the
119
+ * world taken 100 ms before it asked — a window in which the operator could have saved a file. So
120
+ * a late arrival waits for the running sweep to finish and takes a fresh one, which is slower and
121
+ * correct, while genuinely concurrent callers share one walk, which is what the coalescing is for.
122
+ */
123
+ async observe(requestedAt = Date.now()) {
124
+ const current = this.inFlight;
125
+ if (current !== null && current.startedAt >= requestedAt) {
126
+ return current.observation;
127
+ }
128
+ if (current !== null) {
129
+ // Let the running sweep finish before starting another; two concurrent walks of the same
130
+ // trees would only contend for the same file descriptors.
131
+ await current.observation.catch(() => undefined);
132
+ return this.observe(requestedAt);
133
+ }
134
+ const startedAt = Date.now();
135
+ const observation = this.runObservation(startedAt).finally(() => {
136
+ if (this.inFlight?.startedAt === startedAt) {
137
+ this.inFlight = null;
138
+ }
139
+ });
140
+ this.inFlight = { startedAt, observation };
141
+ return observation;
142
+ }
143
+ async runObservation(startedAt) {
144
+ const roots = await this.resolveObservedRoots();
145
+ const accumulator = {
146
+ fileCount: 0,
147
+ directoryCount: 0,
148
+ maximumMtimeMs: 0,
149
+ exceededCeiling: false,
150
+ };
151
+ await this.observeApplicationRootManifests(accumulator);
152
+ await this.walk(roots, accumulator);
153
+ this.observationSequence += 1;
154
+ const bounded = !accumulator.exceededCeiling;
155
+ const token = bounded
156
+ ? `roots:${roots.length}|files:${accumulator.fileCount}|dirs:${accumulator.directoryCount}|mtime:${accumulator.maximumMtimeMs}`
157
+ : `unbounded:${this.observationSequence}`;
158
+ return {
159
+ token,
160
+ bounded,
161
+ durationMs: Date.now() - startedAt,
162
+ observedRootCount: roots.length,
163
+ observedEntryCount: accumulator.fileCount + accumulator.directoryCount,
164
+ startedAt,
165
+ };
166
+ }
167
+ /**
168
+ * The two ROOT populations a derivation reads from, kept apart because a watcher treats them
169
+ * differently.
170
+ *
171
+ * An APPLICATION root is a package the operator edits: its `src` moves first and its `dist` moves
172
+ * second, and only the second changes what a derivation imports —
173
+ * `resolvePackageCompanionEntryPath` resolves the package's `exports['./companion']`, which is
174
+ * `./dist/esm/companion-exports.js` on every application package. A FRAMEWORK root is the injected
175
+ * `@wildo-ai/*` copy in the application's own store: dist-only bytes, hard-linked at supervised
176
+ * (re)start, carrying no runtime-signal files of its own.
177
+ *
178
+ * Exposed so the watcher and the sweep observe one population rather than two enumerations that
179
+ * agree only until one side gains an entry.
180
+ */
181
+ async resolveObservedRootPopulations() {
182
+ const applicationRoots = new Set();
183
+ for (const serviceDefinition of Object.values(this.companionContext.servicesByKey)) {
184
+ applicationRoots.add(resolve(this.companionContext.saasRoot, serviceDefinition.path));
185
+ }
186
+ for (const resolvedLibrary of Object.values(this.companionContext.resolvedLibraries)) {
187
+ applicationRoots.add(resolvedLibrary.packageRoot);
188
+ }
189
+ if (this.companionContext.resolvedSpecifications) {
190
+ applicationRoots.add(this.companionContext.resolvedSpecifications.packageRoot);
191
+ }
192
+ const frameworkScopeOwners = [
193
+ ...applicationRoots,
194
+ this.companionContext.saasRoot,
195
+ this.companionContext.companionHome,
196
+ ];
197
+ const frameworkRoots = new Set();
198
+ for (const owner of frameworkScopeOwners) {
199
+ const scopeDirectory = join(owner, 'node_modules', '@wildo-ai');
200
+ let scopeEntries;
201
+ try {
202
+ scopeEntries = await fsPromises.readdir(scopeDirectory);
203
+ }
204
+ catch {
205
+ continue;
206
+ }
207
+ for (const scopeEntry of scopeEntries) {
208
+ try {
209
+ frameworkRoots.add(await fsPromises.realpath(join(scopeDirectory, scopeEntry)));
210
+ }
211
+ catch {
212
+ // A dangling link contributes nothing to observe; its disappearance shows up as a
213
+ // directory-mtime change on the scope directory's owner instead.
214
+ }
215
+ }
216
+ }
217
+ return { applicationRoots: [...applicationRoots], frameworkRoots: [...frameworkRoots] };
218
+ }
219
+ /**
220
+ * Every tree whose bytes can reach a derivation, de-duplicated by resolved real path.
221
+ *
222
+ * Two families, and the second is the one a reader would not think of:
223
+ *
224
+ * 1. The APPLICATION package roots — every declared service, every resolved library, and the
225
+ * specifications package. Whole roots rather than `src/` alone, because
226
+ * `resolvePackageCompanionEntryPath` prefers a package's built `./companion` export when it
227
+ * exists, so the child commonly imports `dist/`, not source. Sweeping both means neither
228
+ * resolution mode has a blind spot.
229
+ * 2. The FRAMEWORK packages, reached by reading each of those roots' (and the companion home's)
230
+ * `node_modules/@wildo-ai` scope directory and resolving each link to its real path. Reading
231
+ * the scope directory rather than listing package names keeps this from becoming a second
232
+ * enumeration of the engine's package set that could drift from the real one.
233
+ *
234
+ * The application root itself is NOT walked recursively — its interesting children are already in
235
+ * family 1, and descending it would pull in `.wildo-saas` (the companion's own dist plus the
236
+ * runtime-signal files that churn on a heartbeat, which would make every token unique and every
237
+ * cache read a miss).
238
+ */
239
+ async resolveObservedRoots() {
240
+ const { applicationRoots, frameworkRoots } = await this.resolveObservedRootPopulations();
241
+ return [...new Set([...applicationRoots, ...frameworkRoots])];
242
+ }
243
+ /**
244
+ * Fold the application root's own top-level FILES in, without descending it.
245
+ *
246
+ * These are `pnpm-lock.yaml`, `package.json` and `wildo.saas.config.ts` — the manifests that
247
+ * decide which third-party bytes the child imports. Without them there is a narrow but real hole:
248
+ * an install that moves a non-`@wildo-ai` dependency changes a derivation while touching nothing
249
+ * inside a package root, because the walk enters `node_modules` only through the resolved
250
+ * `@wildo-ai` scope. The lockfile moves on every such install, so one shallow read closes it.
251
+ *
252
+ * The root is NOT descended, because doing so would pull in `.wildo-saas` — the companion's own
253
+ * dist and the runtime-signal files that are rewritten on a heartbeat, which would make every
254
+ * token unique and every cache read a miss.
255
+ */
256
+ async observeApplicationRootManifests(accumulator) {
257
+ let entries;
258
+ try {
259
+ entries = await fsPromises.readdir(this.companionContext.saasRoot, { withFileTypes: true });
260
+ }
261
+ catch {
262
+ return;
263
+ }
264
+ await Promise.all(entries.map(async (entry) => {
265
+ if (!entry.isFile())
266
+ return;
267
+ accumulator.fileCount += 1;
268
+ try {
269
+ const entryStats = await fsPromises.stat(join(this.companionContext.saasRoot, entry.name));
270
+ if (entryStats.mtimeMs > accumulator.maximumMtimeMs) {
271
+ accumulator.maximumMtimeMs = entryStats.mtimeMs;
272
+ }
273
+ }
274
+ catch {
275
+ // Counted above; a file that vanished between readdir and stat is itself a change, and the
276
+ // count will differ on the next observation.
277
+ }
278
+ }));
279
+ }
280
+ /**
281
+ * Breadth-of-tree walk with a fixed directory concurrency.
282
+ *
283
+ * A worker-pool built over the ROOT list was written first and was wrong: it sizes its pool from
284
+ * the number of roots, so a single-root application would walk its whole tree one directory at a
285
+ * time, and a worker that finds the queue momentarily empty cannot tell "finished" from "another
286
+ * worker is about to push children". The pump below sizes on IN-FLIGHT directories instead, which
287
+ * is the quantity the concurrency limit is actually about, and terminates on the only condition
288
+ * that means finished: nothing queued and nothing running.
289
+ */
290
+ async walk(roots, accumulator) {
291
+ const pending = [...roots];
292
+ let inFlightDirectories = 0;
293
+ return new Promise((resolveWalk) => {
294
+ const pump = () => {
295
+ while (!accumulator.exceededCeiling
296
+ && inFlightDirectories < DIRECTORY_WALK_CONCURRENCY
297
+ && pending.length > 0) {
298
+ const directory = pending.pop();
299
+ inFlightDirectories += 1;
300
+ void this.visitDirectory(directory, accumulator, pending).then(() => {
301
+ inFlightDirectories -= 1;
302
+ pump();
303
+ });
304
+ }
305
+ if (inFlightDirectories === 0 && (pending.length === 0 || accumulator.exceededCeiling)) {
306
+ resolveWalk();
307
+ }
308
+ };
309
+ pump();
310
+ });
311
+ }
312
+ /**
313
+ * Read one directory: count it, fold its own mtime in, stat its files, and queue its children.
314
+ *
315
+ * Never rejects. A directory that cannot be read (an unbuilt `dist`, a permission) contributes
316
+ * nothing and is not an error — when it appears later it is a new directory, which moves the
317
+ * counts and invalidates every cached derivation.
318
+ */
319
+ async visitDirectory(directory, accumulator, pending) {
320
+ let entries;
321
+ try {
322
+ entries = await fsPromises.readdir(directory, { withFileTypes: true });
323
+ }
324
+ catch {
325
+ return;
326
+ }
327
+ accumulator.directoryCount += 1;
328
+ try {
329
+ const directoryStats = await fsPromises.stat(directory);
330
+ if (directoryStats.mtimeMs > accumulator.maximumMtimeMs) {
331
+ accumulator.maximumMtimeMs = directoryStats.mtimeMs;
332
+ }
333
+ }
334
+ catch {
335
+ // Counted above regardless: the directory demonstrably exists, we just read it.
336
+ }
337
+ const fileStats = [];
338
+ for (const entry of entries) {
339
+ if (SKIPPED_DIRECTORY_NAMES.has(entry.name))
340
+ continue;
341
+ const entryPath = join(directory, entry.name);
342
+ if (entry.isDirectory()) {
343
+ pending.push(entryPath);
344
+ continue;
345
+ }
346
+ if (!entry.isFile()) {
347
+ // A symlink is counted but never followed — following one inside a package tree can walk
348
+ // back out into a dependency graph. Retargeting one rewrites its directory entry, which
349
+ // moves the parent directory's mtime, so the change is still observed.
350
+ accumulator.fileCount += 1;
351
+ continue;
352
+ }
353
+ fileStats.push(fsPromises.stat(entryPath).then((entryStats) => {
354
+ accumulator.fileCount += 1;
355
+ if (entryStats.mtimeMs > accumulator.maximumMtimeMs) {
356
+ accumulator.maximumMtimeMs = entryStats.mtimeMs;
357
+ }
358
+ }, () => {
359
+ accumulator.fileCount += 1;
360
+ }));
361
+ }
362
+ await Promise.all(fileStats);
363
+ if (accumulator.fileCount + accumulator.directoryCount > MAXIMUM_OBSERVED_ENTRIES) {
364
+ accumulator.exceededCeiling = true;
365
+ }
366
+ }
367
+ }
368
+ //# sourceMappingURL=introspection-source-state.companion.service.js.map