@shepai/cli 1.175.1 → 1.176.0-pr539.02342cf

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 (287) hide show
  1. package/apis/json-schema/PhaseTiming.yaml +30 -0
  2. package/apis/json-schema/TokenOptimizationConfig.yaml +36 -0
  3. package/apis/json-schema/WorkflowConfig.yaml +3 -0
  4. package/dist/packages/core/src/application/ports/output/agents/phase-timing-repository.interface.d.ts +8 -1
  5. package/dist/packages/core/src/application/ports/output/agents/phase-timing-repository.interface.d.ts.map +1 -1
  6. package/dist/packages/core/src/application/ports/output/index.d.ts +1 -1
  7. package/dist/packages/core/src/application/ports/output/index.d.ts.map +1 -1
  8. package/dist/packages/core/src/application/ports/output/services/alias-compression.interface.d.ts +45 -0
  9. package/dist/packages/core/src/application/ports/output/services/alias-compression.interface.d.ts.map +1 -0
  10. package/dist/packages/core/src/application/ports/output/services/alias-compression.interface.js +13 -0
  11. package/dist/packages/core/src/application/ports/output/services/command-output-filter.interface.d.ts +50 -0
  12. package/dist/packages/core/src/application/ports/output/services/command-output-filter.interface.d.ts.map +1 -0
  13. package/dist/packages/core/src/application/ports/output/services/command-output-filter.interface.js +13 -0
  14. package/dist/packages/core/src/application/ports/output/services/delta-context.interface.d.ts +57 -0
  15. package/dist/packages/core/src/application/ports/output/services/delta-context.interface.d.ts.map +1 -0
  16. package/dist/packages/core/src/application/ports/output/services/delta-context.interface.js +13 -0
  17. package/dist/packages/core/src/application/ports/output/services/index.d.ts +7 -0
  18. package/dist/packages/core/src/application/ports/output/services/index.d.ts.map +1 -1
  19. package/dist/packages/core/src/application/ports/output/services/optimization-metrics.interface.d.ts +45 -0
  20. package/dist/packages/core/src/application/ports/output/services/optimization-metrics.interface.d.ts.map +1 -0
  21. package/dist/packages/core/src/application/ports/output/services/optimization-metrics.interface.js +13 -0
  22. package/dist/packages/core/src/application/ports/output/services/prompt-optimizer.interface.d.ts +86 -0
  23. package/dist/packages/core/src/application/ports/output/services/prompt-optimizer.interface.d.ts.map +1 -0
  24. package/dist/packages/core/src/application/ports/output/services/prompt-optimizer.interface.js +13 -0
  25. package/dist/packages/core/src/application/ports/output/services/semantic-compressor.interface.d.ts +43 -0
  26. package/dist/packages/core/src/application/ports/output/services/semantic-compressor.interface.d.ts.map +1 -0
  27. package/dist/packages/core/src/application/ports/output/services/semantic-compressor.interface.js +13 -0
  28. package/dist/packages/core/src/application/ports/output/services/skill-routing.interface.d.ts +41 -0
  29. package/dist/packages/core/src/application/ports/output/services/skill-routing.interface.d.ts.map +1 -0
  30. package/dist/packages/core/src/application/ports/output/services/skill-routing.interface.js +12 -0
  31. package/dist/packages/core/src/domain/factories/settings-defaults.factory.d.ts.map +1 -1
  32. package/dist/packages/core/src/domain/factories/settings-defaults.factory.js +9 -0
  33. package/dist/packages/core/src/domain/generated/output.d.ts +66 -0
  34. package/dist/packages/core/src/domain/generated/output.d.ts.map +1 -1
  35. package/dist/packages/core/src/domain/generated/output.js +1 -0
  36. package/dist/packages/core/src/infrastructure/di/container.d.ts.map +1 -1
  37. package/dist/packages/core/src/infrastructure/di/container.js +27 -0
  38. package/dist/packages/core/src/infrastructure/persistence/sqlite/mappers/settings.mapper.d.ts +6 -0
  39. package/dist/packages/core/src/infrastructure/persistence/sqlite/mappers/settings.mapper.d.ts.map +1 -1
  40. package/dist/packages/core/src/infrastructure/persistence/sqlite/mappers/settings.mapper.js +41 -0
  41. package/dist/packages/core/src/infrastructure/persistence/sqlite/migrations/055-add-token-optimization-config.d.ts +29 -0
  42. package/dist/packages/core/src/infrastructure/persistence/sqlite/migrations/055-add-token-optimization-config.d.ts.map +1 -0
  43. package/dist/packages/core/src/infrastructure/persistence/sqlite/migrations/055-add-token-optimization-config.js +77 -0
  44. package/dist/packages/core/src/infrastructure/repositories/sqlite-phase-timing.repository.d.ts +2 -1
  45. package/dist/packages/core/src/infrastructure/repositories/sqlite-phase-timing.repository.d.ts.map +1 -1
  46. package/dist/packages/core/src/infrastructure/repositories/sqlite-phase-timing.repository.js +72 -0
  47. package/dist/packages/core/src/infrastructure/repositories/sqlite-settings.repository.d.ts.map +1 -1
  48. package/dist/packages/core/src/infrastructure/repositories/sqlite-settings.repository.js +19 -3
  49. package/dist/packages/core/src/infrastructure/services/agents/analyze-repo/analyze-repository-graph.d.ts +1 -1
  50. package/dist/packages/core/src/infrastructure/services/agents/feature-agent/fast-feature-agent-graph.d.ts +6 -1
  51. package/dist/packages/core/src/infrastructure/services/agents/feature-agent/fast-feature-agent-graph.d.ts.map +1 -1
  52. package/dist/packages/core/src/infrastructure/services/agents/feature-agent/feature-agent-graph.d.ts +18 -1
  53. package/dist/packages/core/src/infrastructure/services/agents/feature-agent/feature-agent-graph.d.ts.map +1 -1
  54. package/dist/packages/core/src/infrastructure/services/agents/feature-agent/feature-agent-worker.d.ts.map +1 -1
  55. package/dist/packages/core/src/infrastructure/services/agents/feature-agent/feature-agent-worker.js +6 -0
  56. package/dist/packages/core/src/infrastructure/services/agents/feature-agent/nodes/node-helpers.d.ts.map +1 -1
  57. package/dist/packages/core/src/infrastructure/services/agents/feature-agent/nodes/node-helpers.js +17 -1
  58. package/dist/packages/core/src/infrastructure/services/agents/feature-agent/prompt-optimization-context.d.ts +42 -0
  59. package/dist/packages/core/src/infrastructure/services/agents/feature-agent/prompt-optimization-context.d.ts.map +1 -0
  60. package/dist/packages/core/src/infrastructure/services/agents/feature-agent/prompt-optimization-context.js +92 -0
  61. package/dist/packages/core/src/infrastructure/services/agents/feature-agent/state.d.ts +1 -0
  62. package/dist/packages/core/src/infrastructure/services/agents/feature-agent/state.d.ts.map +1 -1
  63. package/dist/packages/core/src/infrastructure/services/agents/feature-agent/state.js +5 -0
  64. package/dist/packages/core/src/infrastructure/services/token-optimization/alias-compression.service.d.ts +41 -0
  65. package/dist/packages/core/src/infrastructure/services/token-optimization/alias-compression.service.d.ts.map +1 -0
  66. package/dist/packages/core/src/infrastructure/services/token-optimization/alias-compression.service.js +111 -0
  67. package/dist/packages/core/src/infrastructure/services/token-optimization/command-output-filter.service.d.ts +22 -0
  68. package/dist/packages/core/src/infrastructure/services/token-optimization/command-output-filter.service.d.ts.map +1 -0
  69. package/dist/packages/core/src/infrastructure/services/token-optimization/command-output-filter.service.js +245 -0
  70. package/dist/packages/core/src/infrastructure/services/token-optimization/delta-context.service.d.ts +22 -0
  71. package/dist/packages/core/src/infrastructure/services/token-optimization/delta-context.service.d.ts.map +1 -0
  72. package/dist/packages/core/src/infrastructure/services/token-optimization/delta-context.service.js +50 -0
  73. package/dist/packages/core/src/infrastructure/services/token-optimization/optimization-metrics.service.d.ts +36 -0
  74. package/dist/packages/core/src/infrastructure/services/token-optimization/optimization-metrics.service.d.ts.map +1 -0
  75. package/dist/packages/core/src/infrastructure/services/token-optimization/optimization-metrics.service.js +123 -0
  76. package/dist/packages/core/src/infrastructure/services/token-optimization/prompt-optimizer.service.d.ts +57 -0
  77. package/dist/packages/core/src/infrastructure/services/token-optimization/prompt-optimizer.service.d.ts.map +1 -0
  78. package/dist/packages/core/src/infrastructure/services/token-optimization/prompt-optimizer.service.js +211 -0
  79. package/dist/packages/core/src/infrastructure/services/token-optimization/semantic-compressor.service.d.ts +34 -0
  80. package/dist/packages/core/src/infrastructure/services/token-optimization/semantic-compressor.service.d.ts.map +1 -0
  81. package/dist/packages/core/src/infrastructure/services/token-optimization/semantic-compressor.service.js +190 -0
  82. package/dist/packages/core/src/infrastructure/services/token-optimization/skill-routing.service.d.ts +26 -0
  83. package/dist/packages/core/src/infrastructure/services/token-optimization/skill-routing.service.d.ts.map +1 -0
  84. package/dist/packages/core/src/infrastructure/services/token-optimization/skill-routing.service.js +51 -0
  85. package/dist/translations/ar/common.json +1 -0
  86. package/dist/translations/de/common.json +1 -0
  87. package/dist/translations/en/common.json +1 -0
  88. package/dist/translations/es/common.json +1 -0
  89. package/dist/translations/fr/common.json +1 -0
  90. package/dist/translations/he/common.json +1 -0
  91. package/dist/translations/pt/common.json +1 -0
  92. package/dist/translations/ru/common.json +1 -0
  93. package/dist/translations/uk/cli.json +631 -0
  94. package/dist/translations/uk/common.json +56 -0
  95. package/dist/translations/uk/tui.json +134 -0
  96. package/dist/translations/uk/web.json +615 -0
  97. package/dist/tsconfig.build.tsbuildinfo +1 -1
  98. package/package.json +1 -1
  99. package/web/.next/BUILD_ID +1 -1
  100. package/web/.next/build-manifest.json +2 -2
  101. package/web/.next/fallback-build-manifest.json +2 -2
  102. package/web/.next/prerender-manifest.json +3 -3
  103. package/web/.next/required-server-files.js +3 -3
  104. package/web/.next/required-server-files.json +3 -3
  105. package/web/.next/server/app/(dashboard)/@drawer/adopt/page/server-reference-manifest.json +29 -29
  106. package/web/.next/server/app/(dashboard)/@drawer/adopt/page.js.nft.json +1 -1
  107. package/web/.next/server/app/(dashboard)/@drawer/adopt/page_client-reference-manifest.js +1 -1
  108. package/web/.next/server/app/(dashboard)/@drawer/chat/page/server-reference-manifest.json +27 -27
  109. package/web/.next/server/app/(dashboard)/@drawer/chat/page.js.nft.json +1 -1
  110. package/web/.next/server/app/(dashboard)/@drawer/chat/page_client-reference-manifest.js +1 -1
  111. package/web/.next/server/app/(dashboard)/@drawer/create/page/server-reference-manifest.json +30 -30
  112. package/web/.next/server/app/(dashboard)/@drawer/create/page.js.nft.json +1 -1
  113. package/web/.next/server/app/(dashboard)/@drawer/create/page_client-reference-manifest.js +1 -1
  114. package/web/.next/server/app/(dashboard)/@drawer/feature/[featureId]/[tab]/page/server-reference-manifest.json +38 -38
  115. package/web/.next/server/app/(dashboard)/@drawer/feature/[featureId]/[tab]/page.js.nft.json +1 -1
  116. package/web/.next/server/app/(dashboard)/@drawer/feature/[featureId]/[tab]/page_client-reference-manifest.js +1 -1
  117. package/web/.next/server/app/(dashboard)/@drawer/feature/[featureId]/page/server-reference-manifest.json +38 -38
  118. package/web/.next/server/app/(dashboard)/@drawer/feature/[featureId]/page.js.nft.json +1 -1
  119. package/web/.next/server/app/(dashboard)/@drawer/feature/[featureId]/page_client-reference-manifest.js +1 -1
  120. package/web/.next/server/app/(dashboard)/@drawer/repository/[repositoryId]/[tab]/page/server-reference-manifest.json +28 -28
  121. package/web/.next/server/app/(dashboard)/@drawer/repository/[repositoryId]/[tab]/page.js.nft.json +1 -1
  122. package/web/.next/server/app/(dashboard)/@drawer/repository/[repositoryId]/[tab]/page_client-reference-manifest.js +1 -1
  123. package/web/.next/server/app/(dashboard)/@drawer/repository/[repositoryId]/page/server-reference-manifest.json +28 -28
  124. package/web/.next/server/app/(dashboard)/@drawer/repository/[repositoryId]/page.js.nft.json +1 -1
  125. package/web/.next/server/app/(dashboard)/@drawer/repository/[repositoryId]/page_client-reference-manifest.js +1 -1
  126. package/web/.next/server/app/(dashboard)/chat/page/server-reference-manifest.json +27 -27
  127. package/web/.next/server/app/(dashboard)/chat/page.js.nft.json +1 -1
  128. package/web/.next/server/app/(dashboard)/chat/page_client-reference-manifest.js +1 -1
  129. package/web/.next/server/app/(dashboard)/create/page/server-reference-manifest.json +30 -30
  130. package/web/.next/server/app/(dashboard)/create/page.js.nft.json +1 -1
  131. package/web/.next/server/app/(dashboard)/create/page_client-reference-manifest.js +1 -1
  132. package/web/.next/server/app/(dashboard)/feature/[featureId]/[tab]/page/server-reference-manifest.json +38 -38
  133. package/web/.next/server/app/(dashboard)/feature/[featureId]/[tab]/page.js.nft.json +1 -1
  134. package/web/.next/server/app/(dashboard)/feature/[featureId]/[tab]/page_client-reference-manifest.js +1 -1
  135. package/web/.next/server/app/(dashboard)/feature/[featureId]/page/server-reference-manifest.json +38 -38
  136. package/web/.next/server/app/(dashboard)/feature/[featureId]/page.js.nft.json +1 -1
  137. package/web/.next/server/app/(dashboard)/feature/[featureId]/page_client-reference-manifest.js +1 -1
  138. package/web/.next/server/app/(dashboard)/page/server-reference-manifest.json +27 -27
  139. package/web/.next/server/app/(dashboard)/page.js.nft.json +1 -1
  140. package/web/.next/server/app/(dashboard)/page_client-reference-manifest.js +1 -1
  141. package/web/.next/server/app/(dashboard)/repository/[repositoryId]/[tab]/page/server-reference-manifest.json +28 -28
  142. package/web/.next/server/app/(dashboard)/repository/[repositoryId]/[tab]/page.js.nft.json +1 -1
  143. package/web/.next/server/app/(dashboard)/repository/[repositoryId]/[tab]/page_client-reference-manifest.js +1 -1
  144. package/web/.next/server/app/(dashboard)/repository/[repositoryId]/page/server-reference-manifest.json +28 -28
  145. package/web/.next/server/app/(dashboard)/repository/[repositoryId]/page.js.nft.json +1 -1
  146. package/web/.next/server/app/(dashboard)/repository/[repositoryId]/page_client-reference-manifest.js +1 -1
  147. package/web/.next/server/app/_global-error.html +2 -2
  148. package/web/.next/server/app/_global-error.rsc +1 -1
  149. package/web/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  150. package/web/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  151. package/web/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  152. package/web/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  153. package/web/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  154. package/web/.next/server/app/_not-found/page/server-reference-manifest.json +6 -6
  155. package/web/.next/server/app/_not-found/page.js.nft.json +1 -1
  156. package/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  157. package/web/.next/server/app/features/page/server-reference-manifest.json +6 -6
  158. package/web/.next/server/app/features/page.js.nft.json +1 -1
  159. package/web/.next/server/app/features/page_client-reference-manifest.js +1 -1
  160. package/web/.next/server/app/settings/page/server-reference-manifest.json +9 -9
  161. package/web/.next/server/app/settings/page.js.nft.json +1 -1
  162. package/web/.next/server/app/settings/page_client-reference-manifest.js +1 -1
  163. package/web/.next/server/app/skills/page/server-reference-manifest.json +13 -13
  164. package/web/.next/server/app/skills/page.js.nft.json +1 -1
  165. package/web/.next/server/app/skills/page_client-reference-manifest.js +1 -1
  166. package/web/.next/server/app/tools/page/server-reference-manifest.json +11 -11
  167. package/web/.next/server/app/tools/page.js.nft.json +1 -1
  168. package/web/.next/server/app/tools/page_client-reference-manifest.js +1 -1
  169. package/web/.next/server/app/version/page/server-reference-manifest.json +6 -6
  170. package/web/.next/server/app/version/page.js.nft.json +1 -1
  171. package/web/.next/server/app/version/page_client-reference-manifest.js +1 -1
  172. package/web/.next/server/chunks/[root-of-the-server]__a402b567._.js +1 -1
  173. package/web/.next/server/chunks/[root-of-the-server]__c78383b1._.js +1 -1
  174. package/web/.next/server/chunks/[root-of-the-server]__c78383b1._.js.map +1 -1
  175. package/web/.next/server/chunks/[root-of-the-server]__cd67a84c._.js +1 -1
  176. package/web/.next/server/chunks/[root-of-the-server]__cd67a84c._.js.map +1 -1
  177. package/web/.next/server/chunks/ssr/744ca_web__next-internal_server_app_(dashboard)_@drawer_adopt_page_actions_ad0071c9.js +1 -1
  178. package/web/.next/server/chunks/ssr/744ca_web__next-internal_server_app_(dashboard)_@drawer_adopt_page_actions_ad0071c9.js.map +1 -1
  179. package/web/.next/server/chunks/ssr/744ca_web__next-internal_server_app_(dashboard)_@drawer_chat_page_actions_90d98b2b.js +1 -1
  180. package/web/.next/server/chunks/ssr/744ca_web__next-internal_server_app_(dashboard)_@drawer_chat_page_actions_90d98b2b.js.map +1 -1
  181. package/web/.next/server/chunks/ssr/744ca_web__next-internal_server_app_(dashboard)_chat_page_actions_d3828105.js +1 -1
  182. package/web/.next/server/chunks/ssr/744ca_web__next-internal_server_app_(dashboard)_chat_page_actions_d3828105.js.map +1 -1
  183. package/web/.next/server/chunks/ssr/744ca_web_components_common_control-center-drawer_create-drawer-client_tsx_5e26fc0a._.js +1 -1
  184. package/web/.next/server/chunks/ssr/744ca_web_components_common_control-center-drawer_create-drawer-client_tsx_5e26fc0a._.js.map +1 -1
  185. package/web/.next/server/chunks/ssr/744ca_web_components_common_control-center-drawer_feature-drawer-client_tsx_e9755fc8._.js +2 -2
  186. package/web/.next/server/chunks/ssr/744ca_web_components_common_control-center-drawer_feature-drawer-client_tsx_e9755fc8._.js.map +1 -1
  187. package/web/.next/server/chunks/ssr/[root-of-the-server]__1cd4327c._.js +1 -1
  188. package/web/.next/server/chunks/ssr/[root-of-the-server]__1cd4327c._.js.map +1 -1
  189. package/web/.next/server/chunks/ssr/[root-of-the-server]__1f389e5d._.js +1 -1
  190. package/web/.next/server/chunks/ssr/[root-of-the-server]__1f389e5d._.js.map +1 -1
  191. package/web/.next/server/chunks/ssr/[root-of-the-server]__357d99f9._.js +1 -1
  192. package/web/.next/server/chunks/ssr/[root-of-the-server]__51ec77a8._.js +1 -1
  193. package/web/.next/server/chunks/ssr/[root-of-the-server]__51ec77a8._.js.map +1 -1
  194. package/web/.next/server/chunks/ssr/[root-of-the-server]__540c615f._.js +2 -2
  195. package/web/.next/server/chunks/ssr/[root-of-the-server]__66047a1b._.js +1 -1
  196. package/web/.next/server/chunks/ssr/[root-of-the-server]__66047a1b._.js.map +1 -1
  197. package/web/.next/server/chunks/ssr/[root-of-the-server]__6c7d3936._.js +1 -1
  198. package/web/.next/server/chunks/ssr/[root-of-the-server]__6c7d3936._.js.map +1 -1
  199. package/web/.next/server/chunks/ssr/[root-of-the-server]__86ff0bc5._.js +1 -1
  200. package/web/.next/server/chunks/ssr/[root-of-the-server]__a932cd3a._.js +1 -1
  201. package/web/.next/server/chunks/ssr/[root-of-the-server]__a932cd3a._.js.map +1 -1
  202. package/web/.next/server/chunks/ssr/[root-of-the-server]__aa72e794._.js +1 -1
  203. package/web/.next/server/chunks/ssr/[root-of-the-server]__aa72e794._.js.map +1 -1
  204. package/web/.next/server/chunks/ssr/[root-of-the-server]__b7b96453._.js +1 -1
  205. package/web/.next/server/chunks/ssr/[root-of-the-server]__b7b96453._.js.map +1 -1
  206. package/web/.next/server/chunks/ssr/_05c23ad9._.js +1 -1
  207. package/web/.next/server/chunks/ssr/_05c23ad9._.js.map +1 -1
  208. package/web/.next/server/chunks/ssr/_16eb4fec._.js +1 -1
  209. package/web/.next/server/chunks/ssr/_16eb4fec._.js.map +1 -1
  210. package/web/.next/server/chunks/ssr/_1879404a._.js +1 -1
  211. package/web/.next/server/chunks/ssr/_295fffde._.js +1 -1
  212. package/web/.next/server/chunks/ssr/_295fffde._.js.map +1 -1
  213. package/web/.next/server/chunks/ssr/_34b0a7ad._.js +3 -0
  214. package/web/.next/server/chunks/ssr/{_f1776188._.js.map → _34b0a7ad._.js.map} +1 -1
  215. package/web/.next/server/chunks/ssr/{_ce75a825._.js → _39053f87._.js} +2 -2
  216. package/web/.next/server/chunks/ssr/{_ce75a825._.js.map → _39053f87._.js.map} +1 -1
  217. package/web/.next/server/chunks/ssr/_45496654._.js +1 -1
  218. package/web/.next/server/chunks/ssr/_45496654._.js.map +1 -1
  219. package/web/.next/server/chunks/ssr/_4cbb7f95._.js +1 -1
  220. package/web/.next/server/chunks/ssr/_4cbb7f95._.js.map +1 -1
  221. package/web/.next/server/chunks/ssr/_56b9d60f._.js +1 -1
  222. package/web/.next/server/chunks/ssr/_56b9d60f._.js.map +1 -1
  223. package/web/.next/server/chunks/ssr/{_81ef821b._.js → _66291662._.js} +2 -2
  224. package/web/.next/server/chunks/ssr/{_81ef821b._.js.map → _66291662._.js.map} +1 -1
  225. package/web/.next/server/chunks/ssr/_6abfa39e._.js +1 -1
  226. package/web/.next/server/chunks/ssr/_6abfa39e._.js.map +1 -1
  227. package/web/.next/server/chunks/ssr/_d9c0a97a._.js +1 -1
  228. package/web/.next/server/chunks/ssr/_f8c55130._.js +1 -1
  229. package/web/.next/server/chunks/ssr/b1a17_presentation_web_components_features_settings_settings-page-client_tsx_6ed9d5f8._.js +1 -1
  230. package/web/.next/server/chunks/ssr/b1a17_presentation_web_components_features_settings_settings-page-client_tsx_6ed9d5f8._.js.map +1 -1
  231. package/web/.next/server/chunks/ssr/f3a1f_components_common_control-center-drawer_repository-drawer-client_tsx_39a00c03._.js +1 -1
  232. package/web/.next/server/chunks/ssr/f3a1f_components_common_control-center-drawer_repository-drawer-client_tsx_39a00c03._.js.map +1 -1
  233. package/web/.next/server/chunks/ssr/src_presentation_web_17d39233._.js +1 -1
  234. package/web/.next/server/chunks/ssr/src_presentation_web_17d39233._.js.map +1 -1
  235. package/web/.next/server/chunks/ssr/src_presentation_web_54b02639._.js +2 -2
  236. package/web/.next/server/chunks/ssr/src_presentation_web_54b02639._.js.map +1 -1
  237. package/web/.next/server/chunks/ssr/src_presentation_web_7b7b9e3b._.js +2 -2
  238. package/web/.next/server/chunks/ssr/src_presentation_web_7b7b9e3b._.js.map +1 -1
  239. package/web/.next/server/chunks/ssr/src_presentation_web_807cba76._.js +1 -1
  240. package/web/.next/server/chunks/ssr/src_presentation_web_807cba76._.js.map +1 -1
  241. package/web/.next/server/chunks/ssr/src_presentation_web__next-internal_server_app_(dashboard)_page_actions_90b5e66e.js +1 -1
  242. package/web/.next/server/chunks/ssr/src_presentation_web__next-internal_server_app_(dashboard)_page_actions_90b5e66e.js.map +1 -1
  243. package/web/.next/server/chunks/ssr/src_presentation_web__next-internal_server_app_skills_page_actions_4ce30db7.js +1 -1
  244. package/web/.next/server/chunks/ssr/src_presentation_web__next-internal_server_app_skills_page_actions_4ce30db7.js.map +1 -1
  245. package/web/.next/server/chunks/ssr/src_presentation_web__next-internal_server_app_tools_page_actions_e4032193.js +1 -1
  246. package/web/.next/server/chunks/ssr/src_presentation_web__next-internal_server_app_tools_page_actions_e4032193.js.map +1 -1
  247. package/web/.next/server/chunks/ssr/src_presentation_web_app_actions_open-ide_ts_baaca5d5._.js +1 -1
  248. package/web/.next/server/chunks/ssr/src_presentation_web_components_895e5bfa._.js +1 -1
  249. package/web/.next/server/chunks/ssr/src_presentation_web_components_895e5bfa._.js.map +1 -1
  250. package/web/.next/server/chunks/ssr/src_presentation_web_components_features_control-center_7ac3562e._.js +1 -1
  251. package/web/.next/server/chunks/ssr/src_presentation_web_components_features_control-center_7ac3562e._.js.map +1 -1
  252. package/web/.next/server/chunks/ssr/src_presentation_web_components_features_skills_8a174cac._.js +1 -1
  253. package/web/.next/server/chunks/ssr/src_presentation_web_components_features_skills_8a174cac._.js.map +1 -1
  254. package/web/.next/server/chunks/ssr/src_presentation_web_components_features_tools_tools-page-client_tsx_3d0aa70c._.js +1 -1
  255. package/web/.next/server/chunks/ssr/src_presentation_web_db9fa0c2._.js +1 -1
  256. package/web/.next/server/chunks/ssr/src_presentation_web_db9fa0c2._.js.map +1 -1
  257. package/web/.next/server/chunks/ssr/src_presentation_web_e1cd1869._.js +1 -1
  258. package/web/.next/server/chunks/ssr/src_presentation_web_e1cd1869._.js.map +1 -1
  259. package/web/.next/server/chunks/ssr/src_presentation_web_e3a30e30._.js +1 -1
  260. package/web/.next/server/chunks/ssr/src_presentation_web_e3a30e30._.js.map +1 -1
  261. package/web/.next/server/chunks/ssr/translations_23dd5e7e._.js +1 -1
  262. package/web/.next/server/chunks/ssr/translations_23dd5e7e._.js.map +1 -1
  263. package/web/.next/server/pages/500.html +2 -2
  264. package/web/.next/server/server-reference-manifest.js +1 -1
  265. package/web/.next/server/server-reference-manifest.json +50 -50
  266. package/web/.next/static/chunks/{03219e57ab4dab05.js → 1bbf1ec4b25d4de8.js} +1 -1
  267. package/web/.next/static/chunks/{ed450778c582887c.js → 1fd5980d468143b3.js} +3 -3
  268. package/web/.next/static/chunks/{523caed4f5a9a78f.js → 2403588dafacbd4e.js} +1 -1
  269. package/web/.next/static/chunks/{b5218d35112c5b4b.js → 287fea380d8cc373.js} +1 -1
  270. package/web/.next/static/chunks/420c3bd9d5a22881.js +1 -0
  271. package/web/.next/static/chunks/{20e831d121ae5518.js → 4df18296f976f225.js} +1 -1
  272. package/web/.next/static/chunks/{feeecb1dc1648817.js → 5cddc4bace2ce528.js} +1 -1
  273. package/web/.next/static/chunks/{bf0d2eba02ad69a4.js → 6a3d4b6774ebcbff.js} +1 -1
  274. package/web/.next/static/chunks/{7b5bdecb2b254cd5.js → 6d33333b9382783a.js} +3 -3
  275. package/web/.next/static/chunks/{09b21da62ffd89d6.js → 73e0fa361f218bb0.js} +1 -1
  276. package/web/.next/static/chunks/{3240913baa13b564.js → 85ea0b80c5996155.js} +1 -1
  277. package/web/.next/static/chunks/{34073c7071fbc0bc.js → 97b1402b60fab8a2.js} +1 -1
  278. package/web/.next/static/chunks/{eb951d647c1f92e6.js → e5d2d6d17ea0472e.js} +1 -1
  279. package/web/.next/static/chunks/{b49ab0b290e9342d.js → e8444bf5f6c35f8b.js} +1 -1
  280. package/web/.next/static/chunks/f9d948464ed409cb.js +1 -0
  281. package/web/.next/static/chunks/{df22a970881f1da8.js → fb6b8fc0dac0dea9.js} +1 -1
  282. package/web/.next/server/chunks/ssr/_f1776188._.js +0 -3
  283. package/web/.next/static/chunks/b65e555419a0c664.js +0 -1
  284. package/web/.next/static/chunks/fe1670b9aae7de08.js +0 -1
  285. /package/web/.next/static/{JskTxIiYLT1ye2ta1GTlv → EYQFTbDa6VxVniUQK-bHc}/_buildManifest.js +0 -0
  286. /package/web/.next/static/{JskTxIiYLT1ye2ta1GTlv → EYQFTbDa6VxVniUQK-bHc}/_clientMiddlewareManifest.json +0 -0
  287. /package/web/.next/static/{JskTxIiYLT1ye2ta1GTlv → EYQFTbDa6VxVniUQK-bHc}/_ssgManifest.js +0 -0
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Optimization Metrics Service
3
+ *
4
+ * Persists token optimization metrics on existing PhaseTiming records.
5
+ * Updates the per-phase timing entry with optimization statistics so the
6
+ * data is queryable alongside timing and cost data via the existing
7
+ * phase timing infrastructure.
8
+ *
9
+ * Failure-tolerant: any persistence error is swallowed (after best-effort
10
+ * logging) so optimization metric recording can never break a phase run.
11
+ */
12
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
13
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
14
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
15
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
16
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
17
+ };
18
+ var __metadata = (this && this.__metadata) || function (k, v) {
19
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
20
+ };
21
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
22
+ return function (target, key) { decorator(target, key, paramIndex); }
23
+ };
24
+ import { injectable, inject } from 'tsyringe';
25
+ /**
26
+ * Parse the JSON-serialized capabilitiesApplied column. Returns an
27
+ * empty array on malformed JSON so a corrupted row never throws on read.
28
+ */
29
+ function parseCapabilitiesApplied(serialized) {
30
+ if (serialized === undefined || serialized === null) {
31
+ return [];
32
+ }
33
+ try {
34
+ const parsed = JSON.parse(serialized);
35
+ return Array.isArray(parsed)
36
+ ? parsed.filter((item) => typeof item === 'string')
37
+ : [];
38
+ }
39
+ catch {
40
+ return [];
41
+ }
42
+ }
43
+ /**
44
+ * Build an OptimizationMetrics object from a PhaseTiming row.
45
+ *
46
+ * Returns null when the row has no optimization columns populated
47
+ * (record was created but optimizer never ran for it).
48
+ */
49
+ function metricsFromPhaseTiming(timing) {
50
+ // If no optimization fields are present at all, treat as "no metrics".
51
+ if (timing.originalTokenEstimate === undefined &&
52
+ timing.optimizedTokenEstimate === undefined &&
53
+ timing.savingsPercent === undefined &&
54
+ timing.capabilitiesApplied === undefined) {
55
+ return null;
56
+ }
57
+ return {
58
+ originalTokenEstimate: timing.originalTokenEstimate !== undefined ? Number(timing.originalTokenEstimate) : 0,
59
+ optimizedTokenEstimate: timing.optimizedTokenEstimate !== undefined ? Number(timing.optimizedTokenEstimate) : 0,
60
+ savingsPercent: timing.savingsPercent ?? 0,
61
+ capabilitiesApplied: parseCapabilitiesApplied(timing.capabilitiesApplied),
62
+ outputFilterLinesRemoved: timing.outputFilterLinesRemoved ?? 0,
63
+ deltaContextFilesSkipped: timing.deltaContextFilesSkipped ?? 0,
64
+ compressionRatio: timing.compressionRatio ?? 1.0,
65
+ aliasesCreated: timing.aliasesCreated ?? 0,
66
+ };
67
+ }
68
+ let OptimizationMetricsService = class OptimizationMetricsService {
69
+ phaseTimingRepository;
70
+ constructor(phaseTimingRepository) {
71
+ this.phaseTimingRepository = phaseTimingRepository;
72
+ }
73
+ /**
74
+ * Persist optimization metrics on the named PhaseTiming row.
75
+ *
76
+ * Token estimates are stored as bigint (PhaseTiming column type),
77
+ * capabilitiesApplied is serialized as a JSON string for the
78
+ * existing string column.
79
+ */
80
+ async record(phaseTimingId, metrics) {
81
+ try {
82
+ await this.phaseTimingRepository.update(phaseTimingId, {
83
+ originalTokenEstimate: BigInt(metrics.originalTokenEstimate),
84
+ optimizedTokenEstimate: BigInt(metrics.optimizedTokenEstimate),
85
+ savingsPercent: metrics.savingsPercent,
86
+ capabilitiesApplied: JSON.stringify(metrics.capabilitiesApplied),
87
+ outputFilterLinesRemoved: metrics.outputFilterLinesRemoved,
88
+ deltaContextFilesSkipped: metrics.deltaContextFilesSkipped,
89
+ compressionRatio: metrics.compressionRatio,
90
+ aliasesCreated: metrics.aliasesCreated,
91
+ });
92
+ }
93
+ catch {
94
+ // Persistence failure must never break optimization
95
+ }
96
+ }
97
+ /**
98
+ * Retrieve previously recorded optimization metrics for a phase timing.
99
+ *
100
+ * Returns null when:
101
+ * - the phase timing record does not exist
102
+ * - the phase timing exists but has no optimization columns populated
103
+ * - the underlying repository read fails
104
+ */
105
+ async getByPhaseTimingId(phaseTimingId) {
106
+ try {
107
+ const timing = await this.phaseTimingRepository.findById(phaseTimingId);
108
+ if (!timing) {
109
+ return null;
110
+ }
111
+ return metricsFromPhaseTiming(timing);
112
+ }
113
+ catch {
114
+ return null;
115
+ }
116
+ }
117
+ };
118
+ OptimizationMetricsService = __decorate([
119
+ injectable(),
120
+ __param(0, inject('IPhaseTimingRepository')),
121
+ __metadata("design:paramtypes", [Object])
122
+ ], OptimizationMetricsService);
123
+ export { OptimizationMetricsService };
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Prompt Optimizer Service
3
+ *
4
+ * Top-level orchestrator for the token optimization layer. Composes the
5
+ * five capability services (delta-context, command output filter, skill
6
+ * routing, semantic compressor, alias compression) into a sequential
7
+ * pipeline driven by per-capability settings toggles.
8
+ *
9
+ * Pipeline order (from research decisions):
10
+ * 1. Output filter - removes the most raw text early
11
+ * 2. Skill routing - prepends a small directive section
12
+ * 3. Delta-context - replaces unchanged spec files with summaries
13
+ * 4. Semantic compr - compresses remaining natural language
14
+ * 5. Alias engine - finds repeated long strings in the final text
15
+ *
16
+ * Each stage runs only when its individual toggle is true. The master
17
+ * toggle (config.enabled) short-circuits the pipeline entirely.
18
+ *
19
+ * Metrics from each stage are aggregated into the OptimizationMetrics
20
+ * record returned alongside the optimized prompt.
21
+ */
22
+ import type { IPromptOptimizerService, PromptOptimizationContext, PromptOptimizationResult } from '../../../application/ports/output/services/prompt-optimizer.interface.js';
23
+ import type { ICommandOutputFilterService } from '../../../application/ports/output/services/command-output-filter.interface.js';
24
+ import type { ISkillRoutingService } from '../../../application/ports/output/services/skill-routing.interface.js';
25
+ import type { IDeltaContextService } from '../../../application/ports/output/services/delta-context.interface.js';
26
+ import type { ISemanticCompressorService } from '../../../application/ports/output/services/semantic-compressor.interface.js';
27
+ import type { IAliasCompressionService } from '../../../application/ports/output/services/alias-compression.interface.js';
28
+ import type { IOptimizationMetricsService } from '../../../application/ports/output/services/optimization-metrics.interface.js';
29
+ export declare class PromptOptimizerService implements IPromptOptimizerService {
30
+ private readonly outputFilter;
31
+ private readonly skillRouting;
32
+ private readonly deltaContext;
33
+ private readonly semanticCompressor;
34
+ private readonly aliasCompression;
35
+ private readonly metricsService;
36
+ constructor(outputFilter: ICommandOutputFilterService, skillRouting: ISkillRoutingService, deltaContext: IDeltaContextService, semanticCompressor: ISemanticCompressorService, aliasCompression: IAliasCompressionService, metricsService: IOptimizationMetricsService);
37
+ /**
38
+ * Optimize a raw prompt by running enabled capability services in sequence.
39
+ *
40
+ * Returns the original prompt with zero-delta metrics when the master
41
+ * toggle is off. Each capability is independently skippable via its
42
+ * config toggle.
43
+ */
44
+ optimize(prompt: string, context: PromptOptimizationContext): Promise<PromptOptimizationResult>;
45
+ /**
46
+ * Persist metrics via the metrics service when a phaseTimingId is
47
+ * provided in the context. Failures are swallowed so a metrics
48
+ * persistence problem can never break the optimization pipeline.
49
+ */
50
+ private recordMetricsIfPossible;
51
+ /**
52
+ * Log a debug-level summary of optimizations applied for observability.
53
+ * Failure to log must never affect optimization output.
54
+ */
55
+ private logSummary;
56
+ }
57
+ //# sourceMappingURL=prompt-optimizer.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-optimizer.service.d.ts","sourceRoot":"","sources":["../../../../../../../packages/core/src/infrastructure/services/token-optimization/prompt-optimizer.service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAIH,OAAO,KAAK,EACV,uBAAuB,EACvB,yBAAyB,EACzB,wBAAwB,EAEzB,MAAM,mEAAmE,CAAC;AAC3E,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,wEAAwE,CAAC;AAC1H,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gEAAgE,CAAC;AAC3G,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gEAAgE,CAAC;AAC3G,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,sEAAsE,CAAC;AACvH,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,oEAAoE,CAAC;AACnH,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,uEAAuE,CAAC;AAkCzH,qBACa,sBAAuB,YAAW,uBAAuB;IAGlE,OAAO,CAAC,QAAQ,CAAC,YAAY;IAE7B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAE7B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAE7B,OAAO,CAAC,QAAQ,CAAC,kBAAkB;IAEnC,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IAEjC,OAAO,CAAC,QAAQ,CAAC,cAAc;gBAVd,YAAY,EAAE,2BAA2B,EAEzC,YAAY,EAAE,oBAAoB,EAElC,YAAY,EAAE,oBAAoB,EAElC,kBAAkB,EAAE,0BAA0B,EAE9C,gBAAgB,EAAE,wBAAwB,EAE1C,cAAc,EAAE,2BAA2B;IAG9D;;;;;;OAMG;IACG,QAAQ,CACZ,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,wBAAwB,CAAC;IA4FpC;;;;OAIG;YACW,uBAAuB;IAcrC;;;OAGG;IACH,OAAO,CAAC,UAAU;CAkBnB"}
@@ -0,0 +1,211 @@
1
+ /**
2
+ * Prompt Optimizer Service
3
+ *
4
+ * Top-level orchestrator for the token optimization layer. Composes the
5
+ * five capability services (delta-context, command output filter, skill
6
+ * routing, semantic compressor, alias compression) into a sequential
7
+ * pipeline driven by per-capability settings toggles.
8
+ *
9
+ * Pipeline order (from research decisions):
10
+ * 1. Output filter - removes the most raw text early
11
+ * 2. Skill routing - prepends a small directive section
12
+ * 3. Delta-context - replaces unchanged spec files with summaries
13
+ * 4. Semantic compr - compresses remaining natural language
14
+ * 5. Alias engine - finds repeated long strings in the final text
15
+ *
16
+ * Each stage runs only when its individual toggle is true. The master
17
+ * toggle (config.enabled) short-circuits the pipeline entirely.
18
+ *
19
+ * Metrics from each stage are aggregated into the OptimizationMetrics
20
+ * record returned alongside the optimized prompt.
21
+ */
22
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
23
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
24
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
25
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
26
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
27
+ };
28
+ var __metadata = (this && this.__metadata) || function (k, v) {
29
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
30
+ };
31
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
32
+ return function (target, key) { decorator(target, key, paramIndex); }
33
+ };
34
+ import { injectable, inject } from 'tsyringe';
35
+ /** Token estimate heuristic: chars / TOKEN_CHAR_RATIO. */
36
+ const TOKEN_CHAR_RATIO = 4;
37
+ /** Capability identifier strings recorded in metrics.capabilitiesApplied. */
38
+ const CAPABILITY = {
39
+ outputFiltering: 'outputFiltering',
40
+ skillRouting: 'skillRouting',
41
+ deltaContext: 'deltaContext',
42
+ semanticCompression: 'semanticCompression',
43
+ aliasCompression: 'aliasCompression',
44
+ };
45
+ /** Estimate tokens from character length using the chars/4 heuristic. */
46
+ function estimateTokens(text) {
47
+ return Math.floor(text.length / TOKEN_CHAR_RATIO);
48
+ }
49
+ /** Build a zero-delta metrics record (used when no optimization is applied). */
50
+ function buildPassthroughMetrics(prompt) {
51
+ const tokens = estimateTokens(prompt);
52
+ return {
53
+ originalTokenEstimate: tokens,
54
+ optimizedTokenEstimate: tokens,
55
+ savingsPercent: 0,
56
+ capabilitiesApplied: [],
57
+ outputFilterLinesRemoved: 0,
58
+ deltaContextFilesSkipped: 0,
59
+ compressionRatio: 1.0,
60
+ aliasesCreated: 0,
61
+ };
62
+ }
63
+ let PromptOptimizerService = class PromptOptimizerService {
64
+ outputFilter;
65
+ skillRouting;
66
+ deltaContext;
67
+ semanticCompressor;
68
+ aliasCompression;
69
+ metricsService;
70
+ constructor(outputFilter, skillRouting, deltaContext, semanticCompressor, aliasCompression, metricsService) {
71
+ this.outputFilter = outputFilter;
72
+ this.skillRouting = skillRouting;
73
+ this.deltaContext = deltaContext;
74
+ this.semanticCompressor = semanticCompressor;
75
+ this.aliasCompression = aliasCompression;
76
+ this.metricsService = metricsService;
77
+ }
78
+ /**
79
+ * Optimize a raw prompt by running enabled capability services in sequence.
80
+ *
81
+ * Returns the original prompt with zero-delta metrics when the master
82
+ * toggle is off. Each capability is independently skippable via its
83
+ * config toggle.
84
+ */
85
+ async optimize(prompt, context) {
86
+ const config = context.config;
87
+ // Master toggle off — return prompt unchanged with zero-delta metrics.
88
+ if (!config?.enabled) {
89
+ return {
90
+ prompt,
91
+ metrics: buildPassthroughMetrics(prompt),
92
+ specFileHashes: context.previousSpecFileHashes ?? {},
93
+ };
94
+ }
95
+ const originalTokenEstimate = estimateTokens(prompt);
96
+ const capabilitiesApplied = [];
97
+ let working = prompt;
98
+ // Per-capability metric accumulators
99
+ let outputFilterLinesRemoved = 0;
100
+ const deltaContextFilesSkipped = 0;
101
+ let compressionRatio = 1.0;
102
+ let aliasesCreated = 0;
103
+ const specFileHashes = context.previousSpecFileHashes ?? {};
104
+ // 1. Command output filter — remove the most raw text first.
105
+ if (config.outputFiltering) {
106
+ const result = this.outputFilter.filter(working);
107
+ working = result.filtered;
108
+ outputFilterLinesRemoved = result.linesRemoved;
109
+ capabilitiesApplied.push(CAPABILITY.outputFiltering);
110
+ }
111
+ // 2. Skill routing — prepend the phase-relevant skill directive.
112
+ if (config.skillRouting) {
113
+ const routing = this.skillRouting.getRoutingDirective(context.phaseName);
114
+ if (routing.directive.length > 0) {
115
+ working = `${routing.directive}\n\n${working}`;
116
+ }
117
+ capabilitiesApplied.push(CAPABILITY.skillRouting);
118
+ }
119
+ // 3. Delta-context — note: the orchestrator does not own spec file
120
+ // reads (those happen in prompt builders). When invoked here we
121
+ // simply mark the capability as applied and propagate hashes from
122
+ // context. The capability service is exposed for direct use by
123
+ // prompt builders that want to apply hash-based summaries inline.
124
+ if (config.deltaContext) {
125
+ capabilitiesApplied.push(CAPABILITY.deltaContext);
126
+ }
127
+ // 4. Semantic compressor — compress remaining natural language.
128
+ if (config.semanticCompression) {
129
+ const result = this.semanticCompressor.compress(working);
130
+ working = result.compressed;
131
+ compressionRatio = result.compressionRatio;
132
+ capabilitiesApplied.push(CAPABILITY.semanticCompression);
133
+ }
134
+ // 5. Alias engine — find repeated long strings in the final text.
135
+ if (config.aliasCompression) {
136
+ const result = this.aliasCompression.compress(working);
137
+ working = result.compressed;
138
+ aliasesCreated = result.aliasCount;
139
+ capabilitiesApplied.push(CAPABILITY.aliasCompression);
140
+ }
141
+ const optimizedTokenEstimate = estimateTokens(working);
142
+ const savingsPercent = originalTokenEstimate > 0
143
+ ? ((originalTokenEstimate - optimizedTokenEstimate) / originalTokenEstimate) * 100
144
+ : 0;
145
+ const metrics = {
146
+ originalTokenEstimate,
147
+ optimizedTokenEstimate,
148
+ savingsPercent: Math.max(0, savingsPercent),
149
+ capabilitiesApplied,
150
+ outputFilterLinesRemoved,
151
+ deltaContextFilesSkipped,
152
+ compressionRatio,
153
+ aliasesCreated,
154
+ };
155
+ this.logSummary(context, metrics);
156
+ await this.recordMetricsIfPossible(context, metrics);
157
+ return {
158
+ prompt: working,
159
+ metrics,
160
+ specFileHashes,
161
+ };
162
+ }
163
+ /**
164
+ * Persist metrics via the metrics service when a phaseTimingId is
165
+ * provided in the context. Failures are swallowed so a metrics
166
+ * persistence problem can never break the optimization pipeline.
167
+ */
168
+ async recordMetricsIfPossible(context, metrics) {
169
+ if (!context.phaseTimingId) {
170
+ return;
171
+ }
172
+ try {
173
+ await this.metricsService.record(context.phaseTimingId, metrics);
174
+ }
175
+ catch {
176
+ // Metrics persistence failure must never break optimization
177
+ }
178
+ }
179
+ /**
180
+ * Log a debug-level summary of optimizations applied for observability.
181
+ * Failure to log must never affect optimization output.
182
+ */
183
+ logSummary(context, metrics) {
184
+ try {
185
+ const savings = metrics.savingsPercent.toFixed(1);
186
+ const caps = metrics.capabilitiesApplied.join(',');
187
+ // Use process.stderr.write at debug level (no console pollution)
188
+ if (process.env.SHEP_DEBUG_OPTIMIZER === '1') {
189
+ process.stderr.write(`[token-optimizer] phase=${context.phaseName} ` +
190
+ `original=${metrics.originalTokenEstimate} ` +
191
+ `optimized=${metrics.optimizedTokenEstimate} ` +
192
+ `savings=${savings}% ` +
193
+ `capabilities=${caps}\n`);
194
+ }
195
+ }
196
+ catch {
197
+ // Logging failure must never break optimization
198
+ }
199
+ }
200
+ };
201
+ PromptOptimizerService = __decorate([
202
+ injectable(),
203
+ __param(0, inject('ICommandOutputFilterService')),
204
+ __param(1, inject('ISkillRoutingService')),
205
+ __param(2, inject('IDeltaContextService')),
206
+ __param(3, inject('ISemanticCompressorService')),
207
+ __param(4, inject('IAliasCompressionService')),
208
+ __param(5, inject('IOptimizationMetricsService')),
209
+ __metadata("design:paramtypes", [Object, Object, Object, Object, Object, Object])
210
+ ], PromptOptimizerService);
211
+ export { PromptOptimizerService };
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Semantic Compressor Service
3
+ *
4
+ * Rule-based caveman compression for non-code prompt sections. Uses a
5
+ * protect-then-compress strategy: extract protected regions (code blocks,
6
+ * file paths, URLs, JSON, quoted strings) as placeholders, apply compression
7
+ * rules to the remaining natural language, then restore protected regions.
8
+ *
9
+ * Compression rules (in order):
10
+ * 1. Phrase shortening (multi-word → shorter equivalent)
11
+ * 2. Filler word removal (just, simply, basically, actually, really, currently)
12
+ * 3. Article removal (a, an, the)
13
+ * 4. Technical term abbreviation (repository → repo, etc.)
14
+ * 5. Whitespace collapsing (multiple blanks → single)
15
+ */
16
+ import type { ISemanticCompressorService, SemanticCompressionResult } from '../../../application/ports/output/services/semantic-compressor.interface.js';
17
+ export declare class SemanticCompressorService implements ISemanticCompressorService {
18
+ /**
19
+ * Compress natural language text in a prompt.
20
+ *
21
+ * Strategy:
22
+ * 1. Extract all protected regions and replace with placeholders
23
+ * 2. Apply compression rules to remaining text
24
+ * 3. Restore protected regions from placeholders
25
+ * 4. Calculate compression ratio
26
+ */
27
+ compress(text: string): SemanticCompressionResult;
28
+ private applyPhraseShortening;
29
+ private removeFillerWords;
30
+ private removeArticles;
31
+ private abbreviateTerms;
32
+ private collapseWhitespace;
33
+ }
34
+ //# sourceMappingURL=semantic-compressor.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"semantic-compressor.service.d.ts","sourceRoot":"","sources":["../../../../../../../packages/core/src/infrastructure/services/token-optimization/semantic-compressor.service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EACV,0BAA0B,EAC1B,yBAAyB,EAC1B,MAAM,sEAAsE,CAAC;AAwF9E,qBAAa,yBAA0B,YAAW,0BAA0B;IAC1E;;;;;;;;OAQG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,yBAAyB;IAoDjD,OAAO,CAAC,qBAAqB;IAQ7B,OAAO,CAAC,iBAAiB;IAQzB,OAAO,CAAC,cAAc;IAQtB,OAAO,CAAC,eAAe;IAQvB,OAAO,CAAC,kBAAkB;CAmB3B"}
@@ -0,0 +1,190 @@
1
+ /**
2
+ * Semantic Compressor Service
3
+ *
4
+ * Rule-based caveman compression for non-code prompt sections. Uses a
5
+ * protect-then-compress strategy: extract protected regions (code blocks,
6
+ * file paths, URLs, JSON, quoted strings) as placeholders, apply compression
7
+ * rules to the remaining natural language, then restore protected regions.
8
+ *
9
+ * Compression rules (in order):
10
+ * 1. Phrase shortening (multi-word → shorter equivalent)
11
+ * 2. Filler word removal (just, simply, basically, actually, really, currently)
12
+ * 3. Article removal (a, an, the)
13
+ * 4. Technical term abbreviation (repository → repo, etc.)
14
+ * 5. Whitespace collapsing (multiple blanks → single)
15
+ */
16
+ /** Placeholder prefix used for protected regions. */
17
+ const PLACEHOLDER_PREFIX = '\x00PROT_';
18
+ const PLACEHOLDER_SUFFIX = '\x00';
19
+ /**
20
+ * Multi-word phrase replacements. Order matters: longer phrases first to
21
+ * prevent partial matches. Applied case-insensitively.
22
+ */
23
+ const PHRASE_REPLACEMENTS = [
24
+ [/\bdue to the fact that\b/gi, 'because'],
25
+ [/\bit is important to\b/gi, 'important:'],
26
+ [/\bplease note that\b/gi, 'note:'],
27
+ [/\bin addition to\b/gi, 'besides'],
28
+ [/\ba number of\b/gi, 'several'],
29
+ [/\bat this point\b/gi, 'now'],
30
+ [/\bmake sure to\b/gi, 'ensure'],
31
+ [/\bin order to\b/gi, 'to'],
32
+ [/\bas well as\b/gi, 'and'],
33
+ [/\byou must\b/gi, 'must'],
34
+ [/\byou should\b/gi, 'should'],
35
+ ];
36
+ /**
37
+ * Filler words removed entirely (with surrounding space normalization).
38
+ */
39
+ const FILLER_WORDS = [
40
+ /\bjust\b/gi,
41
+ /\bsimply\b/gi,
42
+ /\bbasically\b/gi,
43
+ /\bactually\b/gi,
44
+ /\breally\b/gi,
45
+ /\bcurrently\b/gi,
46
+ ];
47
+ /**
48
+ * Articles removed (with word boundary awareness).
49
+ */
50
+ const ARTICLES = [/\bthe\b/gi, /\ban\b/gi, /\ba\b(?=\s)/gi];
51
+ /**
52
+ * Technical term abbreviations. Applied with word boundaries.
53
+ */
54
+ const TERM_ABBREVIATIONS = [
55
+ [/\bimplementation\b/gi, 'impl'],
56
+ [/\bconfiguration\b/gi, 'config'],
57
+ [/\bspecification\b/gi, 'spec'],
58
+ [/\benvironment\b/gi, 'env'],
59
+ [/\bapplication\b/gi, 'app'],
60
+ [/\brepository\b/gi, 'repo'],
61
+ [/\bdependencies\b/gi, 'deps'],
62
+ [/\bdependency\b/gi, 'dep'],
63
+ [/\bdirectory\b/gi, 'dir'],
64
+ [/\bfunction\b/gi, 'fn'],
65
+ ];
66
+ /**
67
+ * Regex patterns for detecting protected regions in the prompt text.
68
+ */
69
+ /** Fenced code blocks: ```...``` (with optional language tag) */
70
+ const FENCED_CODE_BLOCK_RE = /```[\s\S]*?```/g;
71
+ /** Indented code blocks: lines starting with 4+ spaces (consecutive) */
72
+ const INDENTED_CODE_BLOCK_RE = /(?:^|\n)((?:[ ]{4,}[^\n]*\n?)+)/g;
73
+ /** URLs: http(s)://... */
74
+ const URL_RE = /https?:\/\/[^\s)>\]]+/g;
75
+ /** Absolute file paths: /path/to/file or ./path/to/file */
76
+ const UNIX_PATH_RE = /(?:\.\/|\/)[a-zA-Z0-9_\-./]+\.[a-zA-Z0-9]+/g;
77
+ /** Windows file paths: C:\path\to\file */
78
+ const WINDOWS_PATH_RE = /[A-Z]:\\[^\s]+/g;
79
+ /** Double-quoted strings */
80
+ const DOUBLE_QUOTE_RE = /"[^"]*"/g;
81
+ /** Single-quoted strings */
82
+ const SINGLE_QUOTE_RE = /'[^']*'/g;
83
+ /** Backtick-quoted inline code */
84
+ const BACKTICK_RE = /`[^`]+`/g;
85
+ /** Inline JSON objects */
86
+ const INLINE_JSON_RE = /\{[^{}]*"[^"]*"[^{}]*\}/g;
87
+ export class SemanticCompressorService {
88
+ /**
89
+ * Compress natural language text in a prompt.
90
+ *
91
+ * Strategy:
92
+ * 1. Extract all protected regions and replace with placeholders
93
+ * 2. Apply compression rules to remaining text
94
+ * 3. Restore protected regions from placeholders
95
+ * 4. Calculate compression ratio
96
+ */
97
+ compress(text) {
98
+ if (text === '') {
99
+ return { compressed: '', compressionRatio: 1.0 };
100
+ }
101
+ const originalLength = text.length;
102
+ // Step 1: Extract protected regions
103
+ const protectedRegions = [];
104
+ let working = text;
105
+ const protect = (regex) => {
106
+ working = working.replace(regex, (match) => {
107
+ const index = protectedRegions.length;
108
+ protectedRegions.push(match);
109
+ return `${PLACEHOLDER_PREFIX}${index}${PLACEHOLDER_SUFFIX}`;
110
+ });
111
+ };
112
+ // Order matters: code blocks first (they may contain other patterns)
113
+ protect(FENCED_CODE_BLOCK_RE);
114
+ protect(INDENTED_CODE_BLOCK_RE);
115
+ protect(URL_RE);
116
+ protect(WINDOWS_PATH_RE);
117
+ protect(UNIX_PATH_RE);
118
+ protect(INLINE_JSON_RE);
119
+ protect(DOUBLE_QUOTE_RE);
120
+ protect(SINGLE_QUOTE_RE);
121
+ protect(BACKTICK_RE);
122
+ // Step 2: Apply compression rules
123
+ working = this.applyPhraseShortening(working);
124
+ working = this.removeFillerWords(working);
125
+ working = this.removeArticles(working);
126
+ working = this.abbreviateTerms(working);
127
+ working = this.collapseWhitespace(working);
128
+ // Step 3: Restore protected regions
129
+ working = working.replace(new RegExp(`${escapeRegex(PLACEHOLDER_PREFIX)}(\\d+)${escapeRegex(PLACEHOLDER_SUFFIX)}`, 'g'), (_, indexStr) => {
130
+ const index = parseInt(indexStr, 10);
131
+ return protectedRegions[index] ?? '';
132
+ });
133
+ const compressedLength = working.length;
134
+ const compressionRatio = originalLength === 0 ? 1.0 : compressedLength / originalLength;
135
+ return { compressed: working, compressionRatio };
136
+ }
137
+ applyPhraseShortening(text) {
138
+ let result = text;
139
+ for (const [pattern, replacement] of PHRASE_REPLACEMENTS) {
140
+ result = result.replace(pattern, replacement);
141
+ }
142
+ return result;
143
+ }
144
+ removeFillerWords(text) {
145
+ let result = text;
146
+ for (const pattern of FILLER_WORDS) {
147
+ result = result.replace(pattern, '');
148
+ }
149
+ return result;
150
+ }
151
+ removeArticles(text) {
152
+ let result = text;
153
+ for (const pattern of ARTICLES) {
154
+ result = result.replace(pattern, '');
155
+ }
156
+ return result;
157
+ }
158
+ abbreviateTerms(text) {
159
+ let result = text;
160
+ for (const [pattern, replacement] of TERM_ABBREVIATIONS) {
161
+ result = result.replace(pattern, replacement);
162
+ }
163
+ return result;
164
+ }
165
+ collapseWhitespace(text) {
166
+ let result = text;
167
+ // Collapse multiple blank lines to a single blank line
168
+ result = result.replace(/\n{3,}/g, '\n\n');
169
+ // Collapse multiple spaces within lines to a single space
170
+ result = result.replace(/ {2,}/g, ' ');
171
+ // Trim leading/trailing spaces on each line (but keep indentation for protected restored content)
172
+ result = result
173
+ .split('\n')
174
+ .map((line) => {
175
+ // Only trim if line doesn't start with a placeholder
176
+ if (line.includes(PLACEHOLDER_PREFIX)) {
177
+ return line;
178
+ }
179
+ return line.replace(/^ +/, '').replace(/ +$/, '');
180
+ })
181
+ .join('\n');
182
+ return result;
183
+ }
184
+ }
185
+ /**
186
+ * Escape special regex characters in a string.
187
+ */
188
+ function escapeRegex(str) {
189
+ return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
190
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Skill Routing Service
3
+ *
4
+ * Phase-aware skill routing that maps workflow phases to relevant skill sets
5
+ * and generates prompt directives guiding the agent to prioritize them.
6
+ *
7
+ * The default routing table follows FR-3 from the spec:
8
+ * - analyze / requirements: architecture-reviewer, domain modeling skills
9
+ * - research: architecture-reviewer, technology evaluation skills
10
+ * - plan: architecture-reviewer, tdd-guide, implementation-guide
11
+ * - implement / fast-implement: tdd-guide, implementation-guide, framework skills
12
+ * - merge: git-related skills only
13
+ * - evidence: testing and validation skills
14
+ *
15
+ * The routing table is configurable via constructor parameter (settings override).
16
+ */
17
+ import type { ISkillRoutingService, SkillRoutingResult } from '../../../application/ports/output/services/skill-routing.interface.js';
18
+ export declare class SkillRoutingService implements ISkillRoutingService {
19
+ private readonly routingTable;
20
+ constructor(customRoutes?: Record<string, string[]>);
21
+ /**
22
+ * Get relevant skills and a prompt directive for a workflow phase.
23
+ */
24
+ getRoutingDirective(phaseName: string): SkillRoutingResult;
25
+ }
26
+ //# sourceMappingURL=skill-routing.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skill-routing.service.d.ts","sourceRoot":"","sources":["../../../../../../../packages/core/src/infrastructure/services/token-optimization/skill-routing.service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EACV,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,gEAAgE,CAAC;AAgBxE,qBAAa,mBAAoB,YAAW,oBAAoB;IAC9D,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA8C;gBAE/D,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;IAInD;;OAEG;IACH,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,kBAAkB;CAiB3D"}